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

Checkpointing #1310

Open
wants to merge 118 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
eb73c4e
implement checkpointing
ksaito7 Mar 6, 2018
84f4bb3
add database count for checkpointing catalog
ksaito7 Mar 6, 2018
a050273
add checkpointing test
ksaito7 Mar 6, 2018
6e3fdcf
modify checkpointing catalog data
ksaito7 Mar 6, 2018
d0cfa6e
change to use oid for checkpoint file name
ksaito7 Mar 6, 2018
094da29
modify oid_t serialization from long to int
ksaito7 Mar 6, 2018
cfc25b3
clean up checkpointing catalog
ksaito7 Mar 6, 2018
88197c1
implement catalog recovery
ksaito7 Mar 9, 2018
203f0e0
implement checkpoint recovery
ksaito7 Mar 20, 2018
9bb3aef
cleaning some checkpoint stuffs
ksaito7 Mar 20, 2018
58f8adb
cleaning some checkpoint stuffs
ksaito7 Mar 20, 2018
8df22b7
Merge branch 'master' into checkpoint
ksaito7 Mar 20, 2018
f75bbf6
Merge branch 'master' into checkpoint
ksaito7 Mar 21, 2018
2a74961
merge latest version
ksaito7 Mar 21, 2018
21100fd
implement checkpoints keeping tile group structure
ksaito7 Mar 26, 2018
a4ac0a9
Merge branch 'master' into checkpoint
ksaito7 Mar 27, 2018
246ac2c
modify and add for checkpoints
ksaito7 Mar 28, 2018
2fb7e8f
modify and add for checkpoints
ksaito7 Mar 28, 2018
a71329d
modify and add for checkpoints
ksaito7 Mar 29, 2018
7680d8d
implement catalog checkpointing & recovery
ksaito7 Apr 2, 2018
101d822
add low level test for checkpoint recovery
ksaito7 Apr 3, 2018
9daa33e
fix debug log level
ksaito7 Apr 3, 2018
e50223f
fix the function ResultTypeToString
ksaito7 Apr 10, 2018
b856af3
add functions for checkpoints
ksaito7 Apr 10, 2018
2522216
implement checkpoints for foreign key and trigger
ksaito7 Apr 10, 2018
02e73ed
add low level test and constraint test
ksaito7 Apr 10, 2018
ff4163e
disable foreign key checkpoint recovery
ksaito7 Apr 11, 2018
ab8d53c
implement catalog recovery and foreign key recovery
ksaito7 Apr 18, 2018
0a1c0d0
merge the master
ksaito7 Apr 18, 2018
83f348c
modify bugs by merge
ksaito7 Apr 18, 2018
56202b1
change log level from debug to trace
ksaito7 Apr 18, 2018
3150584
fix bugs and format
ksaito7 Apr 19, 2018
4ad205a
change %lu to PRIu64 in LOG print
ksaito7 Apr 20, 2018
55ce729
fix checkpoint type test
ksaito7 Apr 20, 2018
0d858a2
fix checkpoint config value
ksaito7 Apr 20, 2018
c2225b2
for checking Jenkins error
ksaito7 Apr 23, 2018
80ee7d3
modify where the stack over flow might be occurred
ksaito7 Apr 23, 2018
a6c9ab5
fix the order of Columns in Schema
ksaito7 Apr 24, 2018
277d01b
fix where the stack over flow might be occurred
ksaito7 Apr 24, 2018
6d30720
fix where the stack over flow might be occurred
ksaito7 Apr 25, 2018
298fa95
fix where the stack over flow might be occurred
ksaito7 Apr 24, 2018
6ee48b1
Merge remote-tracking branch 'origin/checkpoint' into checkpoint
ksaito7 Apr 25, 2018
175636c
add output logs for debug
ksaito7 Apr 26, 2018
e7472ec
Add debug info
ksaito7 Apr 26, 2018
36c951b
Merge branch 'master' into checkpoint
ksaito7 Apr 26, 2018
39246bd
Add debug info
ksaito7 Apr 26, 2018
b4de859
Delete array data
ksaito7 Apr 26, 2018
c6927f7
Fix memory leaks
ksaito7 Apr 27, 2018
44bc5b9
Modify scandir to readdir
ksaito7 Apr 27, 2018
c441c2c
Add debug info
ksaito7 Apr 27, 2018
fcbdb48
Add debug info
ksaito7 Apr 27, 2018
76d4c83
Modify debug info
ksaito7 Apr 27, 2018
090fba7
Merge branch 'master' into checkpoint
Apr 29, 2018
ca5f2f6
Merge branch 'master' into checkpoint
May 3, 2018
3f6a1b1
add checkpointing test stuff
ksaito7 May 7, 2018
0a84921
Merge branch 'master' into checkpoint
ksaito7 May 7, 2018
2a0471b
follow up to catalog refactoring
ksaito7 May 8, 2018
7e22b88
fix related to review comments
ksaito7 May 9, 2018
bf6bce7
merge with remote branch
ksaito7 May 9, 2018
d32c9e4
clean up
ksaito7 May 9, 2018
5d4c7da
modify test for divided tile groups
ksaito7 May 9, 2018
d3f0125
change beginning transaction place
ksaito7 May 9, 2018
93b6907
check the primary key error
ksaito7 May 10, 2018
678890d
for debug in tile_group.h
ksaito7 May 10, 2018
81aaf65
Fix bugs in recreating database
ksaito7 May 11, 2018
b2ea9f5
Add commit into each constraint test & clean debug output
ksaito7 May 11, 2018
1f8aeaa
Add clearing active_tile_groups_ in DropTileGroup
ksaito7 May 11, 2018
2756302
Fix active tile group stuff
ksaito7 May 11, 2018
f9a7372
Rollback settings for debug
ksaito7 May 11, 2018
be6d111
change vector access method from [] to at
ksaito7 May 12, 2018
a61f470
Formmatting
ksaito7 May 12, 2018
f72d6be
Check where the travis error occurs
ksaito7 May 12, 2018
e110bc8
Check where the travis error occurs
ksaito7 May 12, 2018
4d9d9b6
Check where the travis error occurs
ksaito7 May 12, 2018
f827335
Check where the travis error occurs
ksaito7 May 12, 2018
1eba948
Check where the travis error occurs
ksaito7 May 13, 2018
4c49698
Check where the travis error occurs
ksaito7 May 13, 2018
a068a97
Check where the travis error occurs
ksaito7 May 13, 2018
e602de9
Check where the travis error occurs
ksaito7 May 14, 2018
c6984d8
Check where the travis error occurs
ksaito7 May 14, 2018
05a464e
Merge branch 'master' into checkpoint
ksaito7 May 15, 2018
40259ac
Update tile_group.h
ksaito7 May 15, 2018
59ee7ed
Add layout catalog support
ksaito7 May 16, 2018
437e01c
Remove same name variables
ksaito7 May 17, 2018
c13f179
Simplify column insert
ksaito7 May 18, 2018
bf202c6
Add check of array access
ksaito7 May 18, 2018
e08ad76
Delete unnecessary debug info
ksaito7 May 20, 2018
91636c8
Change variable name
ksaito7 May 21, 2018
46c04a2
Rollback to commit 437e01c
ksaito7 May 21, 2018
3493632
Check where the travis error occurs
ksaito7 May 21, 2018
727d2d6
Check where the travis error occurs
ksaito7 May 21, 2018
f4409bc
Check where the travis error occurs
ksaito7 May 21, 2018
ef93c4b
Modify variable declarations for reference return
ksaito7 May 21, 2018
7abbe07
Modify variable declarations for reference return
ksaito7 May 22, 2018
735d33f
Merge branch 'master' into checkpoint
ksaito7 May 22, 2018
0037a25
Check where the travis error occurs
ksaito7 May 22, 2018
1d335d8
Check where the travis error occurs
ksaito7 May 22, 2018
714e193
Check where the travis error occurs
ksaito7 May 22, 2018
b6ef41f
Check where the travis error occurs
ksaito7 May 22, 2018
839a6c4
Check where the travis error occurs
ksaito7 May 22, 2018
bf77d5a
Merge branch 'master' into checkpoint
ksaito7 Jun 19, 2018
b4adf09
Replace tab with spaces
ksaito7 Jun 19, 2018
d6c93fc
Remove column length from metadata file
ksaito7 Jun 20, 2018
c6c84ea
Update oid recovery logic
ksaito7 Jun 20, 2018
8e32619
Merge transaction beginning point
ksaito7 Jun 20, 2018
3ddfbc8
Add layout recovery from catalog
ksaito7 Jun 20, 2018
0446bc7
Modify recovering layout in tile group
ksaito7 Jun 20, 2018
916833a
Clean up unnecessary functions
ksaito7 Jun 20, 2018
4870ada
Fix a bug in LOG_TRACE
ksaito7 Jun 21, 2018
ff167d8
Add SettingCatalog recovery
ksaito7 Jun 22, 2018
b5e0383
Merge branch 'master' into checkpoint
tli2 Jun 26, 2018
ae826cf
Merge branch 'master' into checkpoint
ksaito7 Jun 29, 2018
5902ee8
Merge branch 'checkpoint' of https://github.com/aaron-tian/peloton in…
ksaito7 Jun 29, 2018
5ae9fd8
Merge branch 'master' into checkpoint
ksaito7 Jul 2, 2018
2ad4c0b
Merge branch 'master' into checkpoint
ksaito7 Jul 4, 2018
c4b3611
Modify checkpoint recovery to create all storage objects from catalog
ksaito7 Jul 5, 2018
b2a881e
Change function names
ksaito7 Jul 5, 2018
af92a66
Add comments and fix unused variables
ksaito7 Jul 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,8 @@ ResultType Catalog::AddUniqueConstraint(concurrency::TransactionContext *txn,
->GetSchema();

// Create index
std::stringstream index_name(table_object->GetTableName());
std::stringstream index_name;
index_name << table_object->GetTableName();
for (auto column_id : column_ids)
index_name << "_" + schema->GetColumn(column_id).GetName();
index_name << "_UNIQ";
Expand Down Expand Up @@ -1033,7 +1034,8 @@ ResultType Catalog::AddForeignKeyConstraint(concurrency::TransactionContext *txn
->GetTableCatalogEntry(txn, src_table_oid);
auto src_schema = src_table->GetSchema();

std::stringstream index_name(src_table_object->GetTableName());
std::stringstream index_name;
index_name << src_table_object->GetTableName();
for (auto col_id : src_col_ids)
index_name << "_" << src_schema->GetColumn(col_id).GetName();
index_name << "_fkey";
Expand Down Expand Up @@ -1660,6 +1662,26 @@ std::shared_ptr<DatabaseCatalogEntry> Catalog::GetDatabaseCatalogEntry(
return database_object;
}

/* Get database catalog object from cache (cached_only == true),
* or all the way from storage (cached_only == false)
* throw exception and abort txn if not exists/invisible
* */
std::unordered_map<oid_t, std::shared_ptr<DatabaseCatalogEntry>>
Catalog::GetDatabaseCatalogEntries(concurrency::TransactionContext *txn,
bool cached_only) {
if (txn == nullptr) {
throw CatalogException("Do not have transaction to get database objects");
}

if (!cached_only && !txn->catalog_cache.valid_database_catalog_entry_) {
// cache miss get from pg_table
return DatabaseCatalog::GetInstance()->GetDatabaseCatalogEntries(txn);
}
// make sure to check IsValidTableObjects() before getting table objects
PELOTON_ASSERT(txn->catalog_cache.valid_database_catalog_entry_);
return txn->catalog_cache.database_catalog_entries_cache_;
}

/* Check table from pg_table with table_name & schema_name using txn,
* get it from storage layer using table_oid,
* throw exception and abort txn if not exists/invisible
Expand Down
93 changes: 57 additions & 36 deletions src/catalog/catalog_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "catalog/database_catalog.h"
#include "common/logger.h"
#include "concurrency/transaction_context.h"

namespace peloton {
namespace catalog {
Expand All @@ -24,27 +25,27 @@ namespace catalog {
* @param database_object
* @return false only if database_oid already exists in cache
*/
bool CatalogCache::InsertDatabaseObject(
bool CatalogCache::InsertDatabaseCatalogEntry(
std::shared_ptr<DatabaseCatalogEntry> database_object) {
if (!database_object || database_object->GetDatabaseOid() == INVALID_OID) {
return false; // invalid object
}

// check if already in cache
if (database_objects_cache_.find(database_object->GetDatabaseOid()) !=
database_objects_cache_.end()) {
LOG_DEBUG("Database %u already exists in cache!",
if (database_catalog_entries_cache_.find(database_object->GetDatabaseOid()) !=
database_catalog_entries_cache_.end()) {
LOG_TRACE("Database %u already exists in cache!",
database_object->GetDatabaseOid());
return false;
}
if (database_name_cache_.find(database_object->GetDatabaseName()) !=
database_name_cache_.end()) {
LOG_DEBUG("Database %s already exists in cache!",
LOG_TRACE("Database %s already exists in cache!",
database_object->GetDatabaseName().c_str());
return false;
}

database_objects_cache_.insert(
database_catalog_entries_cache_.insert(
std::make_pair(database_object->GetDatabaseOid(), database_object));
database_name_cache_.insert(
std::make_pair(database_object->GetDatabaseName(), database_object));
Expand All @@ -55,15 +56,15 @@ bool CatalogCache::InsertDatabaseObject(
* @param database_oid
* @return true if database_oid is found and evicted; false if not found
*/
bool CatalogCache::EvictDatabaseObject(oid_t database_oid) {
auto it = database_objects_cache_.find(database_oid);
if (it == database_objects_cache_.end()) {
bool CatalogCache::EvictDatabaseCatalogEntry(oid_t database_oid) {
auto it = database_catalog_entries_cache_.find(database_oid);
if (it == database_catalog_entries_cache_.end()) {
return false; // database oid not found in cache
}

auto database_object = it->second;
PELOTON_ASSERT(database_object);
database_objects_cache_.erase(it);
database_catalog_entries_cache_.erase(it);
database_name_cache_.erase(database_object->GetDatabaseName());
return true;
}
Expand All @@ -72,7 +73,7 @@ bool CatalogCache::EvictDatabaseObject(oid_t database_oid) {
* @param database_name
* @return true if database_name is found and evicted; false if not found
*/
bool CatalogCache::EvictDatabaseObject(const std::string &database_name) {
bool CatalogCache::EvictDatabaseCatalogEntry(const std::string &database_name) {
auto it = database_name_cache_.find(database_name);
if (it == database_name_cache_.end()) {
return false; // database name not found in cache
Expand All @@ -81,18 +82,18 @@ bool CatalogCache::EvictDatabaseObject(const std::string &database_name) {
auto database_object = it->second;
PELOTON_ASSERT(database_object);
database_name_cache_.erase(it);
database_objects_cache_.erase(database_object->GetDatabaseOid());
database_catalog_entries_cache_.erase(database_object->GetDatabaseOid());
return true;
}

/*@brief get database catalog object from cache
* @param database_oid
* @return database catalog object; if not found return object with invalid oid
*/
std::shared_ptr<DatabaseCatalogEntry> CatalogCache::GetDatabaseObject(
oid_t database_oid) {
auto it = database_objects_cache_.find(database_oid);
if (it == database_objects_cache_.end()) {
std::shared_ptr<DatabaseCatalogEntry>
CatalogCache::GetDatabaseCatalogEntry(oid_t database_oid) {
auto it = database_catalog_entries_cache_.find(database_oid);
if (it == database_catalog_entries_cache_.end()) {
return nullptr;
}
return it->second;
Expand All @@ -102,23 +103,40 @@ std::shared_ptr<DatabaseCatalogEntry> CatalogCache::GetDatabaseObject(
* @param database_name
* @return database catalog object; if not found return null
*/
std::shared_ptr<DatabaseCatalogEntry> CatalogCache::GetDatabaseObject(
const std::string &database_name) {
std::shared_ptr<DatabaseCatalogEntry>
CatalogCache::GetDatabaseCatalogEntry(const std::string &database_name) {
auto it = database_name_cache_.find(database_name);
if (it == database_name_cache_.end()) {
return nullptr;
}
return it->second;
}

/* @brief Get database catalog object from cache,
or all the way from storage
* @param txn if nullptr, return nullptr on a cache miss
* @return Shared pointer to the requested database catalog object
*/
std::unordered_map<oid_t, std::shared_ptr<DatabaseCatalogEntry>>
CatalogCache::GetDatabaseCatalogEntries(concurrency::TransactionContext *txn) {
if (!valid_database_catalog_entry_ && txn != nullptr) {
// cache miss get from pg_database
return DatabaseCatalog::GetInstance()->GetDatabaseCatalogEntries(txn);
}
// make sure to check IsValidTableObjects() before getting table objects
PELOTON_ASSERT(valid_database_catalog_entry_);
return database_catalog_entries_cache_;
}

/*@brief search table catalog object from all cached database objects
* @param table_oid
* @return table catalog object; if not found return null
*/
std::shared_ptr<TableCatalogEntry> CatalogCache::GetCachedTableObject(
oid_t database_oid, oid_t table_oid) {
auto database_object = GetDatabaseObject(database_oid);
if (database_object == nullptr) return nullptr;
std::shared_ptr<TableCatalogEntry>
CatalogCache::GetCachedTableCatalogEntry(oid_t database_oid,
oid_t table_oid) {
auto database_object = GetDatabaseCatalogEntry(database_oid);
if (database_object == nullptr) return nullptr;
auto table_object = database_object->GetTableCatalogEntry(table_oid, true);
if (table_object) return table_object;
return nullptr;
Expand All @@ -128,27 +146,30 @@ std::shared_ptr<TableCatalogEntry> CatalogCache::GetCachedTableObject(
* @param index_oid
* @return index catalog object; if not found return null
*/
std::shared_ptr<IndexCatalogEntry> CatalogCache::GetCachedIndexObject(
oid_t database_oid, oid_t index_oid) {
auto database_object = GetDatabaseObject(database_oid);
if (database_object == nullptr) return nullptr;
auto index_object = database_object->GetCachedIndexCatalogEntry(index_oid);
if (index_object) return index_object;
std::shared_ptr<IndexCatalogEntry>
CatalogCache::GetCachedIndexCatalogEntry(oid_t database_oid,
oid_t index_oid) {
auto database_object = GetDatabaseCatalogEntry(database_oid);
if (database_object == nullptr) return nullptr;
auto index_object = database_object->GetCachedIndexCatalogEntry(index_oid);
if (index_object) return index_object;
return nullptr;
}

/*@brief search index catalog object from all cached database objects
* @param index_name
* @return index catalog object; if not found return null
*/
std::shared_ptr<IndexCatalogEntry> CatalogCache::GetCachedIndexObject(const std::string &database_name,
const std::string &schema_name,
const std::string &index_name) {
auto database_object = GetDatabaseObject(database_name);
if (database_object == nullptr) return nullptr;
auto index_object =
database_object->GetCachedIndexCatalogEntry(index_name, schema_name);
if (index_object) return index_object;
std::shared_ptr<IndexCatalogEntry>
CatalogCache::GetCachedIndexCatalogEntry(const std::string &database_name,
const std::string &index_name,
const std::string &schema_name) {
auto database_object = GetDatabaseCatalogEntry(database_name);
if (database_object == nullptr) return nullptr;
auto index_object =
database_object->GetCachedIndexCatalogEntry(index_name, schema_name);
if (index_object) return index_object;

return nullptr;
}

Expand Down
57 changes: 45 additions & 12 deletions src/catalog/database_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ namespace peloton {
namespace catalog {

DatabaseCatalogEntry::DatabaseCatalogEntry(concurrency::TransactionContext *txn,
executor::LogicalTile *tile)
: database_oid_(tile->GetValue(0, DatabaseCatalog::ColumnId::DATABASE_OID)
.GetAs<oid_t>()),
database_name_(tile->GetValue(0, DatabaseCatalog::ColumnId::DATABASE_NAME)
.ToString()),
executor::LogicalTile *tile,
int tupleId)
: database_oid_(
tile->GetValue(tupleId, DatabaseCatalog::ColumnId::DATABASE_OID)
.GetAs<oid_t>()),
database_name_(
tile->GetValue(tupleId, DatabaseCatalog::ColumnId::DATABASE_NAME)
.ToString()),
table_catalog_entries_cache_(),
table_catalog_entries_cache_by_name(),
valid_table_catalog_entries(false),
Expand Down Expand Up @@ -180,7 +183,7 @@ DatabaseCatalogEntry::GetTableCatalogEntries(const std::string &schema_name) {
// insert every table object into cache
pg_table->GetTableCatalogEntries(txn_);
}
// make sure to check IsValidTableObjects() before getting table objects
// make sure to check IsValidTableCatalogEntries() before getting table objects
PELOTON_ASSERT(valid_table_catalog_entries);
std::vector<std::shared_ptr<TableCatalogEntry>> result;
for (auto it : table_catalog_entries_cache_) {
Expand All @@ -206,7 +209,7 @@ DatabaseCatalogEntry::GetTableCatalogEntries(bool cached_only) {
->GetTableCatalog();
return pg_table->GetTableCatalogEntries(txn_);
}
// make sure to check IsValidTableObjects() before getting table objects
// make sure to check IsValidTableCatalogEntries() before getting table objects
PELOTON_ASSERT(valid_table_catalog_entries);
return table_catalog_entries_cache_;
}
Expand Down Expand Up @@ -324,7 +327,7 @@ bool DatabaseCatalog::DeleteDatabase(concurrency::TransactionContext *txn, oid_t
values.push_back(type::ValueFactory::GetIntegerValue(database_oid).Copy());

// evict cache
txn->catalog_cache.EvictDatabaseObject(database_oid);
txn->catalog_cache.EvictDatabaseCatalogEntry(database_oid);

return DeleteWithIndexScan(txn, index_offset, values);
}
Expand All @@ -336,7 +339,7 @@ std::shared_ptr<DatabaseCatalogEntry> DatabaseCatalog::GetDatabaseCatalogEntry(
throw CatalogException("Transaction is invalid!");
}
// try get from cache
auto database_object = txn->catalog_cache.GetDatabaseObject(database_oid);
auto database_object = txn->catalog_cache.GetDatabaseCatalogEntry(database_oid);
if (database_object) return database_object;

// cache miss, get from pg_database
Expand All @@ -355,7 +358,7 @@ std::shared_ptr<DatabaseCatalogEntry> DatabaseCatalog::GetDatabaseCatalogEntry(
auto database_object =
std::make_shared<DatabaseCatalogEntry>(txn, (*result_tiles)[0].get());
// insert into cache
bool success = txn->catalog_cache.InsertDatabaseObject(database_object);
bool success = txn->catalog_cache.InsertDatabaseCatalogEntry(database_object);
PELOTON_ASSERT(success == true);
(void)success;
return database_object;
Expand All @@ -379,7 +382,7 @@ std::shared_ptr<DatabaseCatalogEntry> DatabaseCatalog::GetDatabaseCatalogEntry(
throw CatalogException("Transaction is invalid!");
}
// try get from cache
auto database_object = txn->catalog_cache.GetDatabaseObject(database_name);
auto database_object = txn->catalog_cache.GetDatabaseCatalogEntry(database_name);
if (database_object) return database_object;

// cache miss, get from pg_database
Expand All @@ -400,7 +403,7 @@ std::shared_ptr<DatabaseCatalogEntry> DatabaseCatalog::GetDatabaseCatalogEntry(
std::make_shared<DatabaseCatalogEntry>(txn, (*result_tiles)[0].get());
if (database_object) {
// insert into cache
bool success = txn->catalog_cache.InsertDatabaseObject(database_object);
bool success = txn->catalog_cache.InsertDatabaseCatalogEntry(database_object);
PELOTON_ASSERT(success == true);
(void)success;
}
Expand All @@ -411,5 +414,35 @@ std::shared_ptr<DatabaseCatalogEntry> DatabaseCatalog::GetDatabaseCatalogEntry(
return nullptr;
}

std::unordered_map<oid_t, std::shared_ptr<DatabaseCatalogEntry>>
DatabaseCatalog::GetDatabaseCatalogEntries(concurrency::TransactionContext *txn) {
if (txn == nullptr) {
throw CatalogException("Transaction is invalid!");
}

// try get from cache
if (txn->catalog_cache.IsValidDatabaseCatalogEntries()) {
return txn->catalog_cache.GetDatabaseCatalogEntries();
}

// get from pg_database
std::vector<oid_t> column_ids(all_column_ids_);
auto result_tiles = this->GetResultWithSeqScan(txn, nullptr, column_ids);

for (auto &tile : (*result_tiles)) {
for (auto tuple_id : *tile) {
auto database_object =
std::make_shared<DatabaseCatalogEntry>(txn, tile.get(), tuple_id);
if (database_object) {
// insert into cache
txn->catalog_cache.InsertDatabaseCatalogEntry(database_object);
}
}
}

txn->catalog_cache.SetValidDatabaseCatalogEntries(true);
return txn->catalog_cache.GetDatabaseCatalogEntries();
}

} // namespace catalog
} // namespace peloton
18 changes: 9 additions & 9 deletions src/catalog/index_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ bool IndexCatalog::DeleteIndex(concurrency::TransactionContext *txn,
std::vector<type::Value> values;
values.push_back(type::ValueFactory::GetIntegerValue(index_oid).Copy());

auto index_object = txn->catalog_cache.GetCachedIndexObject(database_oid,
index_oid);
auto index_object = txn->catalog_cache.GetCachedIndexCatalogEntry(database_oid,
index_oid);
if (index_object) {
auto table_object =
txn->catalog_cache.GetCachedTableObject(database_oid,
index_object->GetTableOid());
txn->catalog_cache.GetCachedTableCatalogEntry(database_oid,
index_object->GetTableOid());
table_object->EvictAllIndexCatalogEntries();
}

Expand All @@ -206,8 +206,8 @@ std::shared_ptr<IndexCatalogEntry> IndexCatalog::GetIndexCatalogEntry(
throw CatalogException("Transaction is invalid!");
}
// try get from cache
auto index_object = txn->catalog_cache.GetCachedIndexObject(database_oid,
index_oid);
auto index_object = txn->catalog_cache.GetCachedIndexCatalogEntry(database_oid,
index_oid);
if (index_object) {
return index_object;
}
Expand Down Expand Up @@ -254,9 +254,9 @@ std::shared_ptr<IndexCatalogEntry> IndexCatalog::GetIndexCatalogEntry(
}
// try get from cache
auto index_object =
txn->catalog_cache.GetCachedIndexObject(database_name,
schema_name,
index_name);
txn->catalog_cache.GetCachedIndexCatalogEntry(database_name,
schema_name,
index_name);
if (index_object) {
return index_object;
}
Expand Down
Loading