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

Commit 2d3fab8

Browse files
committed
Fixing comments for CatalogCache methods
1 parent f50bf18 commit 2d3fab8

File tree

6 files changed

+194
-146
lines changed

6 files changed

+194
-146
lines changed

src/catalog/catalog_cache.cpp

Lines changed: 10 additions & 57 deletions
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 database_oid, oid_t table_oid) {
129117
auto database_object = GetDatabaseObject(database_oid);
@@ -133,10 +121,6 @@ std::shared_ptr<TableCatalogObject> CatalogCache::GetCachedTableObject(
133121
return nullptr;
134122
}
135123

136-
/*@brief search index catalog object from all cached database objects
137-
* @param index_oid
138-
* @return index catalog object; if not found return null
139-
*/
140124
std::shared_ptr<IndexCatalogObject> CatalogCache::GetCachedIndexObject(
141125
oid_t database_oid, oid_t index_oid) {
142126
auto database_object = GetDatabaseObject(database_oid);
@@ -146,10 +130,6 @@ std::shared_ptr<IndexCatalogObject> CatalogCache::GetCachedIndexObject(
146130
return nullptr;
147131
}
148132

149-
/*@brief search index catalog object from all cached database objects
150-
* @param index_name
151-
* @return index catalog object; if not found return null
152-
*/
153133
std::shared_ptr<IndexCatalogObject> CatalogCache::GetCachedIndexObject(
154134
const std::string &database_name, const std::string &index_name,
155135
const std::string &schema_name) {
@@ -161,43 +141,32 @@ std::shared_ptr<IndexCatalogObject> CatalogCache::GetCachedIndexObject(
161141
return nullptr;
162142
}
163143

164-
/*@brief insert sequence catalog object into cache
165-
* @param sequence_object
166-
* @return false only if sequence already exists in cache or invalid
167-
*/
168144
bool CatalogCache::InsertSequenceObject(
169145
std::shared_ptr<SequenceCatalogObject> sequence_object) {
170-
if (!sequence_object || sequence_object->seq_oid == INVALID_OID) {
146+
if (!sequence_object || sequence_object->GetSequenceOid() == INVALID_OID) {
171147
return false; // invalid object
172148
}
173149

174-
std::size_t hash_key = GetHashKey(sequence_object->seq_name,
175-
sequence_object->db_oid);
150+
std::pair key = std::make_pair(sequence_object->GetDatabaseOid(),
151+
sequence_object->GetName());
176152

177153
// check if already in cache
178-
if (sequence_objects_cache.find(hash_key) !=
154+
if (sequence_objects_cache.find(key) !=
179155
sequence_objects_cache.end()) {
180156
LOG_DEBUG("Sequence %s already exists in cache!",
181-
sequence_object->seq_name.c_str());
157+
sequence_object->GetName().c_str());
182158
return false;
183159
}
184160

185161
sequence_objects_cache.insert(
186-
std::make_pair(hash_key, sequence_object));
162+
std::make_pair(key, sequence_object));
187163
return true;
188164
}
189165

190-
/*@brief evict sequence catalog object from cache
191-
* @param sequence_name
192-
* @param database_oid
193-
* @return true if specified sequence is found and evicted;
194-
* false if not found
195-
*/
196166
bool CatalogCache::EvictSequenceObject(const std::string & sequence_name,
197167
oid_t database_oid) {
198-
std::size_t hash_key = GetHashKey(sequence_name, database_oid);
199-
200-
auto it = sequence_objects_cache.find(hash_key);
168+
std::pair key = std::make_pair(database_oid, sequence_name);
169+
auto it = sequence_objects_cache.find(key);
201170
if (it == sequence_objects_cache.end()) {
202171
return false; // sequence not found in cache
203172
}
@@ -208,32 +177,16 @@ bool CatalogCache::EvictSequenceObject(const std::string & sequence_name,
208177
return true;
209178
}
210179

211-
/*@brief get sequence catalog object from cache
212-
* @param sequence_name
213-
* @param database_oid
214-
* @return sequence catalog object; if not found return object with invalid oid
215-
*/
216180
std::shared_ptr<SequenceCatalogObject> CatalogCache::GetSequenceObject(
217181
const std::string & sequence_name, oid_t database_oid) {
218-
std::size_t hash_key = GetHashKey(sequence_name, database_oid);
219-
auto it = sequence_objects_cache.find(hash_key);
182+
std::pair key = std::make_pair(database_oid, sequence_name);
183+
auto it = sequence_objects_cache.find(key);
220184
if (it == sequence_objects_cache.end()) {
221185
return nullptr;
222186
}
223187
return it->second;
224188
}
225189

226-
/*@brief get the hash key given the sequence information
227-
* @param sequence_name
228-
* @param database_oid
229-
* @return hash key
230-
*/
231-
std::size_t CatalogCache::GetHashKey(const std::string sequence_name,
232-
oid_t database_oid) {
233-
std::tuple<std::string, size_t> key(sequence_name, database_oid);
234-
boost::hash<std::tuple<std::string, size_t>> key_hash;
235-
return key_hash(key);
236-
}
237190

238191
} // namespace catalog
239192
} // namespace peloton

src/catalog/sequence_catalog.cpp

Lines changed: 1 addition & 52 deletions
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) {

src/function/sequence_functions.cpp

Lines changed: 10 additions & 9 deletions
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

src/include/catalog/catalog_cache.h

Lines changed: 51 additions & 3 deletions
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 database_oid, 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 database_oid, 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 &database_name, const std::string &index_name,
6998
const std::string &schema_name);
@@ -74,14 +103,32 @@ class CatalogCache {
74103
bool EvictDatabaseObject(oid_t database_oid);
75104
bool EvictDatabaseObject(const std::string &database_name);
76105

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

86133
// cache for database catalog object
87134
std::unordered_map<oid_t, std::shared_ptr<DatabaseCatalogObject>>
@@ -90,7 +137,8 @@ class CatalogCache {
90137
database_name_cache;
91138

92139
// cache for sequence catalog object
93-
std::unordered_map<std::size_t, std::shared_ptr<SequenceCatalogObject>>
140+
std::unordered_map<std::pair<oid_t, std::string>,
141+
std::shared_ptr<SequenceCatalogObject>>
94142
sequence_objects_cache;
95143

96144
};

0 commit comments

Comments
 (0)