Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit bdda749

Browse files
committed
Fixing comments for CatalogCache methods
1 parent 91d65e3 commit bdda749

File tree

6 files changed

+194
-146
lines changed

6 files changed

+194
-146
lines changed

Diff for: src/catalog/catalog_cache.cpp

+10-57
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ bool CatalogCache::EvictDatabaseObject(const std::string &database_name) {
8686
return true;
8787
}
8888

89-
/*@brief get database catalog object from cache
90-
* @param database_oid
91-
* @return database catalog object; if not found return object with invalid oid
92-
*/
9389
std::shared_ptr<DatabaseCatalogObject> CatalogCache::GetDatabaseObject(
9490
oid_t database_oid) {
9591
auto it = database_objects_cache.find(database_oid);
@@ -99,10 +95,6 @@ std::shared_ptr<DatabaseCatalogObject> CatalogCache::GetDatabaseObject(
9995
return it->second;
10096
}
10197

102-
/*@brief get database catalog object from cache
103-
* @param database_name
104-
* @return database catalog object; if not found return null
105-
*/
10698
std::shared_ptr<DatabaseCatalogObject> CatalogCache::GetDatabaseObject(
10799
const std::string &database_name) {
108100
auto it = database_name_cache.find(database_name);
@@ -120,10 +112,6 @@ std::vector<std::shared_ptr<DatabaseCatalogObject>> CatalogCache::GetAllDatabase
120112
return (databases);
121113
}
122114

123-
/*@brief search table catalog object from all cached database objects
124-
* @param table_oid
125-
* @return table catalog object; if not found return null
126-
*/
127115
std::shared_ptr<TableCatalogObject> CatalogCache::GetCachedTableObject(
128116
oid_t table_oid) {
129117
for (auto it = database_objects_cache.begin();
@@ -135,10 +123,6 @@ std::shared_ptr<TableCatalogObject> CatalogCache::GetCachedTableObject(
135123
return nullptr;
136124
}
137125

138-
/*@brief search index catalog object from all cached database objects
139-
* @param index_oid
140-
* @return index catalog object; if not found return null
141-
*/
142126
std::shared_ptr<IndexCatalogObject> CatalogCache::GetCachedIndexObject(
143127
oid_t index_oid) {
144128
for (auto it = database_objects_cache.begin();
@@ -150,10 +134,6 @@ std::shared_ptr<IndexCatalogObject> CatalogCache::GetCachedIndexObject(
150134
return nullptr;
151135
}
152136

153-
/*@brief search index catalog object from all cached database objects
154-
* @param index_name
155-
* @return index catalog object; if not found return null
156-
*/
157137
std::shared_ptr<IndexCatalogObject> CatalogCache::GetCachedIndexObject(
158138
const std::string &index_name, const std::string &schema_name) {
159139
for (auto it = database_objects_cache.begin();
@@ -166,43 +146,32 @@ std::shared_ptr<IndexCatalogObject> CatalogCache::GetCachedIndexObject(
166146
return nullptr;
167147
}
168148

169-
/*@brief insert sequence catalog object into cache
170-
* @param sequence_object
171-
* @return false only if sequence already exists in cache or invalid
172-
*/
173149
bool CatalogCache::InsertSequenceObject(
174150
std::shared_ptr<SequenceCatalogObject> sequence_object) {
175-
if (!sequence_object || sequence_object->seq_oid == INVALID_OID) {
151+
if (!sequence_object || sequence_object->GetSequenceOid() == INVALID_OID) {
176152
return false; // invalid object
177153
}
178154

179-
std::size_t hash_key = GetHashKey(sequence_object->seq_name,
180-
sequence_object->db_oid);
155+
std::pair key = std::make_pair(sequence_object->GetDatabaseOid(),
156+
sequence_object->GetName());
181157

182158
// check if already in cache
183-
if (sequence_objects_cache.find(hash_key) !=
159+
if (sequence_objects_cache.find(key) !=
184160
sequence_objects_cache.end()) {
185161
LOG_DEBUG("Sequence %s already exists in cache!",
186-
sequence_object->seq_name.c_str());
162+
sequence_object->GetName().c_str());
187163
return false;
188164
}
189165

190166
sequence_objects_cache.insert(
191-
std::make_pair(hash_key, sequence_object));
167+
std::make_pair(key, sequence_object));
192168
return true;
193169
}
194170

195-
/*@brief evict sequence catalog object from cache
196-
* @param sequence_name
197-
* @param database_oid
198-
* @return true if specified sequence is found and evicted;
199-
* false if not found
200-
*/
201171
bool CatalogCache::EvictSequenceObject(const std::string & sequence_name,
202172
oid_t database_oid) {
203-
std::size_t hash_key = GetHashKey(sequence_name, database_oid);
204-
205-
auto it = sequence_objects_cache.find(hash_key);
173+
std::pair key = std::make_pair(database_oid, sequence_name);
174+
auto it = sequence_objects_cache.find(key);
206175
if (it == sequence_objects_cache.end()) {
207176
return false; // sequence not found in cache
208177
}
@@ -213,32 +182,16 @@ bool CatalogCache::EvictSequenceObject(const std::string & sequence_name,
213182
return true;
214183
}
215184

216-
/*@brief get sequence catalog object from cache
217-
* @param sequence_name
218-
* @param database_oid
219-
* @return sequence catalog object; if not found return object with invalid oid
220-
*/
221185
std::shared_ptr<SequenceCatalogObject> CatalogCache::GetSequenceObject(
222186
const std::string & sequence_name, oid_t database_oid) {
223-
std::size_t hash_key = GetHashKey(sequence_name, database_oid);
224-
auto it = sequence_objects_cache.find(hash_key);
187+
std::pair key = std::make_pair(database_oid, sequence_name);
188+
auto it = sequence_objects_cache.find(key);
225189
if (it == sequence_objects_cache.end()) {
226190
return nullptr;
227191
}
228192
return it->second;
229193
}
230194

231-
/*@brief get the hash key given the sequence information
232-
* @param sequence_name
233-
* @param database_oid
234-
* @return hash key
235-
*/
236-
std::size_t CatalogCache::GetHashKey(const std::string sequence_name,
237-
oid_t database_oid) {
238-
std::tuple<std::string, size_t> key(sequence_name, database_oid);
239-
boost::hash<std::tuple<std::string, size_t>> key_hash;
240-
return key_hash(key);
241-
}
242195

243196
} // namespace catalog
244197
} // namespace peloton

Diff for: src/catalog/sequence_catalog.cpp

+1-52
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@
3030
namespace peloton {
3131
namespace catalog {
3232

33-
/* @brief Get the nextval of the sequence
34-
* @return the next value of the sequence.
35-
* @exception throws SequenceException if the sequence exceeds the upper/lower
36-
* limit.
37-
*/
3833
int64_t SequenceCatalogObject::GetNextVal() {
3934
int64_t result = seq_curr_val;
4035
seq_prev_val = result;
@@ -93,20 +88,7 @@ SequenceCatalog::SequenceCatalog(const std::string &database_name,
9388

9489
SequenceCatalog::~SequenceCatalog() {}
9590

96-
/* @brief Insert the sequence by name.
97-
* @param database_oid the databse_oid associated with the sequence
98-
* @param sequence_name the name of the sequence
99-
* @param seq_increment the increment per step of the sequence
100-
* @param seq_max the max value of the sequence
101-
* @param seq_min the min value of the sequence
102-
* @param seq_start the start of the sequence
103-
* @param seq_cycle whether the sequence cycles
104-
* @param pool an instance of abstract pool
105-
* @param txn current transaction
106-
* @return ResultType::SUCCESS if the sequence exists, ResultType::FAILURE
107-
* otherwise.
108-
* @exception throws SequenceException if the sequence already exists.
109-
*/
91+
11092
bool SequenceCatalog::InsertSequence(oid_t database_oid,
11193
std::string sequence_name,
11294
int64_t seq_increment, int64_t seq_max,
@@ -151,13 +133,6 @@ bool SequenceCatalog::InsertSequence(oid_t database_oid,
151133
return InsertTuple(std::move(tuple), txn);
152134
}
153135

154-
/* @brief Delete the sequence by name.
155-
* @param database_name the database name associated with the sequence
156-
* @param sequence_name the name of the sequence
157-
* @param txn current transaction
158-
* @return ResultType::SUCCESS if the sequence exists, throw exception
159-
* otherwise.
160-
*/
161136
ResultType SequenceCatalog::DropSequence(const std::string &database_name,
162137
const std::string &sequence_name,
163138
concurrency::TransactionContext *txn) {
@@ -188,12 +163,6 @@ ResultType SequenceCatalog::DropSequence(const std::string &database_name,
188163
return ResultType::SUCCESS;
189164
}
190165

191-
/* @brief Delete the sequence by name. The sequence is guaranteed to exist.
192-
* @param database_oid the databse_oid associated with the sequence
193-
* @param sequence_name the name of the sequence
194-
* @param txn current transaction
195-
* @return The result of DeleteWithIndexScan.
196-
*/
197166
bool SequenceCatalog::DeleteSequenceByName(
198167
const std::string &sequence_name, oid_t database_oid,
199168
concurrency::TransactionContext *txn) {
@@ -205,12 +174,6 @@ bool SequenceCatalog::DeleteSequenceByName(
205174
return DeleteWithIndexScan(index_offset, values, txn);
206175
}
207176

208-
/* @brief get sequence from pg_sequence table
209-
* @param database_oid the databse_oid associated with the sequence
210-
* @param sequence_name the name of the sequence
211-
* @param txn current transaction
212-
* @return a SequenceCatalogObject if the sequence is found, nullptr otherwise
213-
*/
214177
std::shared_ptr<SequenceCatalogObject> SequenceCatalog::GetSequence(
215178
oid_t database_oid, const std::string &sequence_name,
216179
concurrency::TransactionContext *txn) {
@@ -254,12 +217,6 @@ std::shared_ptr<SequenceCatalogObject> SequenceCatalog::GetSequence(
254217
return new_sequence;
255218
}
256219

257-
/* @brief update the next value of the sequence in the underlying storage
258-
* @param sequence_oid the sequence_oid of the sequence
259-
* @param nextval the nextval of the sequence
260-
* @param txn current transaction
261-
* @return the result of the transaction
262-
*/
263220
bool SequenceCatalog::UpdateNextVal(oid_t sequence_oid, int64_t nextval,
264221
concurrency::TransactionContext *txn){
265222
std::vector<oid_t> update_columns({SequenceCatalog::ColumnId::SEQUENCE_VALUE});
@@ -272,14 +229,6 @@ bool SequenceCatalog::UpdateNextVal(oid_t sequence_oid, int64_t nextval,
272229
return UpdateWithIndexScan(update_columns, update_values, scan_values, index_offset, txn);
273230
}
274231

275-
/* @brief get sequence oid from pg_sequence table given sequence_name and
276-
* database_oid
277-
* @param database_oid the databse_oid associated with the sequence
278-
* @param sequence_name the name of the sequence
279-
* @param txn current transaction
280-
* @return the oid_t of the sequence if the sequence is found, INVALID_OID
281-
* otherwise
282-
*/
283232
oid_t SequenceCatalog::GetSequenceOid(std::string sequence_name,
284233
oid_t database_oid,
285234
concurrency::TransactionContext *txn) {

Diff for: src/function/sequence_functions.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,24 @@ uint32_t SequenceFunctions::Nextval(executor::ExecutorContext &ctx,
4242
auto database_catalog = all_databases[0];
4343
LOG_DEBUG("Get database oid: %u", database_catalog->GetDatabaseOid());
4444

45+
auto sequence_catalog = catalog::Catalog::GetInstance()
46+
->GetSystemCatalogs(database_catalog->GetDatabaseOid())
47+
->GetSequenceCatalog();
48+
4549
// initialize a new transaction for incrementing sequence value
4650
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
4751
auto mini_txn = txn_manager.BeginTransaction();
4852

4953
// evict the old cached copy of sequence
50-
txn->GetCatalogCache()->EvictSequenceObject(sequence_name,
51-
database_catalog->GetDatabaseOid());
52-
auto sequence_object =
53-
catalog::Catalog::GetInstance()
54-
->GetSystemCatalogs(database_catalog->GetDatabaseOid())
55-
->GetSequenceCatalog()
56-
->GetSequence(database_catalog->GetDatabaseOid(),
57-
sequence_name, mini_txn);
54+
// txn->GetCatalogCache()->EvictSequenceObject(sequence_name,
55+
// database_catalog->GetDatabaseOid());
56+
auto sequence_object = sequence_catalog
57+
->GetSequence(database_catalog->GetDatabaseOid(), sequence_name, mini_txn);
5858

5959
if (sequence_object != nullptr) {
60-
uint32_t val = sequence_object->GetNextVal();
60+
int64_t val = sequence_object->GetNextVal();
6161
int64_t curr_val = sequence_object->GetCurrVal();
62+
6263
// insert the new copy of sequence into cache for future currval
6364
txn->GetCatalogCache()->InsertSequenceObject(sequence_object);
6465

Diff for: src/include/catalog/catalog_cache.h

+51-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,19 @@ class CatalogCache {
5252
CatalogCache &operator=(CatalogCache const &) = delete;
5353

5454
private:
55+
56+
/**
57+
* @brief get database catalog object from cache
58+
* @param database_oid
59+
* @return database catalog object; if not found return object with invalid oid
60+
*/
5561
std::shared_ptr<DatabaseCatalogObject> GetDatabaseObject(oid_t database_oid);
62+
63+
/**
64+
* @brief get database catalog object from cache
65+
* @param database_name
66+
* @return database catalog object; if not found return null
67+
*/
5668
std::shared_ptr<DatabaseCatalogObject> GetDatabaseObject(
5769
const std::string &name);
5870

@@ -62,8 +74,25 @@ class CatalogCache {
6274
*/
6375
std::vector<std::shared_ptr<DatabaseCatalogObject>> GetAllDatabaseObjects();
6476

77+
/**
78+
* @brief search table catalog object from all cached database objects
79+
* @param table_oid
80+
* @return table catalog object; if not found return null
81+
*/
6582
std::shared_ptr<TableCatalogObject> GetCachedTableObject(oid_t table_oid);
83+
84+
/**
85+
* @brief search index catalog object from all cached database objects
86+
* @param index_oid
87+
* @return index catalog object; if not found return null
88+
*/
6689
std::shared_ptr<IndexCatalogObject> GetCachedIndexObject(oid_t index_oid);
90+
91+
/**
92+
* @brief search index catalog object from all cached database objects
93+
* @param index_name
94+
* @return index catalog object; if not found return null
95+
*/
6796
std::shared_ptr<IndexCatalogObject> GetCachedIndexObject(
6897
const std::string &index_name, const std::string &schema_name);
6998

@@ -73,14 +102,32 @@ class CatalogCache {
73102
bool EvictDatabaseObject(oid_t database_oid);
74103
bool EvictDatabaseObject(const std::string &database_name);
75104

76-
// sequence catalog cache interface
105+
/**
106+
* @brief insert sequence catalog object into cache
107+
* @param sequence_object
108+
* @return false only if sequence already exists in cache or invalid
109+
*/
77110
bool InsertSequenceObject(
78111
std::shared_ptr<SequenceCatalogObject> sequence_object);
112+
113+
/**
114+
* @brief evict sequence catalog object from cache
115+
* @param sequence_name
116+
* @param database_oid
117+
* @return true if specified sequence is found and evicted;
118+
* false if not found
119+
*/
79120
bool EvictSequenceObject(const std::string &sequence_name,
80121
oid_t database_oid);
122+
123+
/**
124+
* @brief get sequence catalog object from cache
125+
* @param sequence_name
126+
* @param database_oid
127+
* @return sequence catalog object; if not found return object with invalid oid
128+
*/
81129
std::shared_ptr<SequenceCatalogObject> GetSequenceObject(
82130
const std::string &sequence_name, oid_t database_oid);
83-
std::size_t GetHashKey(std::string sequence_name, oid_t database_oid);
84131

85132
// cache for database catalog object
86133
std::unordered_map<oid_t, std::shared_ptr<DatabaseCatalogObject>>
@@ -89,7 +136,8 @@ class CatalogCache {
89136
database_name_cache;
90137

91138
// cache for sequence catalog object
92-
std::unordered_map<std::size_t, std::shared_ptr<SequenceCatalogObject>>
139+
std::unordered_map<std::pair<oid_t, std::string>,
140+
std::shared_ptr<SequenceCatalogObject>>
93141
sequence_objects_cache;
94142

95143
};

0 commit comments

Comments
 (0)