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

Commit 2ecd160

Browse files
Fixed tests after catalog refactor
1 parent 183389a commit 2ecd160

36 files changed

+172
-158
lines changed

src/catalog/catalog.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void Catalog::BootstrapSystemCatalogs(storage::Database *database,
162162
system_catalogs->GetSchemaCatalog()->InsertSchema(
163163
CATALOG_SCHEMA_OID, CATALOG_SCHEMA_NAME, pool_.get(), txn);
164164
system_catalogs->GetSchemaCatalog()->InsertSchema(
165-
DEFUALT_SCHEMA_OID, DEFUALT_SCHEMA_NAME, pool_.get(), txn);
165+
DEFUALT_SCHEMA_OID, DEFAULT_SCHEMA_NAME, pool_.get(), txn);
166166

167167
// Insert catalog tables into pg_table
168168
// pg_database record is shared across different databases
@@ -592,8 +592,11 @@ Catalog::CreateLayout(oid_t database_oid, oid_t table_oid,
592592
PELOTON_ASSERT(layout_oid < INVALID_OID);
593593
auto new_layout = std::shared_ptr<const storage::Layout>(
594594
new const storage::Layout(column_map, layout_oid));
595-
auto layout_catalog = catalog::LayoutCatalog::GetInstance();
596-
bool result = layout_catalog->InsertLayout(table_oid, new_layout,
595+
596+
// Add the layout the pg_layout table
597+
auto pg_layout =
598+
catalog_map_[database_oid]->GetLayoutCatalog();
599+
bool result = pg_layout->InsertLayout(table_oid, new_layout,
597600
pool_.get(), txn);
598601
if (!result) {
599602
LOG_DEBUG("Failed to create a new layout for table %u", table_oid);
@@ -790,6 +793,11 @@ ResultType Catalog::DropTable(oid_t database_oid, oid_t table_oid,
790793
catalog_map_[database_object->GetDatabaseOid()]->GetColumnCatalog();
791794
pg_attribute->DeleteColumns(table_oid, txn);
792795

796+
// delete record in pg_layout
797+
auto pg_layout =
798+
catalog_map_[database_object->GetDatabaseOid()]->GetLayoutCatalog();
799+
pg_layout->DeleteLayouts(table_oid, txn);
800+
793801
// delete record in pg_table
794802
auto pg_table =
795803
catalog_map_[database_object->GetDatabaseOid()]->GetTableCatalog();
@@ -857,8 +865,8 @@ ResultType Catalog::DropLayout(oid_t database_oid, oid_t table_oid,
857865
table->ResetDefaultLayout();
858866
}
859867

860-
auto layout_catalog = LayoutCatalog::GetInstance();
861-
if (!layout_catalog->DeleteLayout(table_oid, layout_oid, txn)) {
868+
auto pg_layout = catalog_map_[database_oid]->GetLayoutCatalog();
869+
if (!pg_layout->DeleteLayout(table_oid, layout_oid, txn)) {
862870
auto layout = table->GetDefaultLayout();
863871
LOG_DEBUG("Layout delete failed. Default layout id: %u",
864872
layout.GetOid());

src/catalog/layout_catalog.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
#include "catalog/layout_catalog.h"
1414

15-
#include "catalog/column_catalog.h"
15+
#include "catalog/catalog.h"
16+
#include "catalog/system_catalogs.h"
1617
#include "catalog/table_catalog.h"
1718
#include "concurrency/transaction_context.h"
1819
#include "storage/data_table.h"
@@ -28,9 +29,10 @@ LayoutCatalog *LayoutCatalog::GetInstance(storage::Database *pg_catalog,
2829
return &layout_catalog;
2930
}
3031

31-
LayoutCatalog::LayoutCatalog(storage::Database *pg_catalog,
32-
type::AbstractPool *pool,
33-
concurrency::TransactionContext *txn)
32+
LayoutCatalog::LayoutCatalog(
33+
storage::Database *pg_catalog,
34+
UNUSED_ATTRIBUTE type::AbstractPool *pool,
35+
UNUSED_ATTRIBUTE concurrency::TransactionContext *txn)
3436
: AbstractCatalog(LAYOUT_CATALOG_OID, LAYOUT_CATALOG_NAME,
3537
InitializeSchema().release(), pg_catalog) {
3638
// Add indexes for pg_attribute
@@ -39,19 +41,6 @@ LayoutCatalog::LayoutCatalog(storage::Database *pg_catalog,
3941
IndexConstraintType::PRIMARY_KEY);
4042
AddIndex({ColumnId::TABLE_OID}, LAYOUT_CATALOG_SKEY0_OID,
4143
LAYOUT_CATALOG_NAME "_skey0", IndexConstraintType::DEFAULT);
42-
43-
// Insert columns into pg_attribute
44-
ColumnCatalog *pg_attribute =
45-
ColumnCatalog::GetInstance(pg_catalog, pool, txn);
46-
47-
oid_t column_id = 0;
48-
for (auto column : catalog_table_->GetSchema()->GetColumns()) {
49-
pg_attribute->InsertColumn(LAYOUT_CATALOG_OID, column.GetName(), column_id,
50-
column.GetOffset(), column.GetType(),
51-
column.IsInlined(), column.GetConstraints(),
52-
pool, txn);
53-
column_id++;
54-
}
5544
}
5645

5746
LayoutCatalog::~LayoutCatalog() {}
@@ -126,9 +115,12 @@ bool LayoutCatalog::DeleteLayout(oid_t table_oid, oid_t layout_id,
126115
values.push_back(type::ValueFactory::GetIntegerValue(table_oid).Copy());
127116
values.push_back(type::ValueFactory::GetIntegerValue(layout_id).Copy());
128117

118+
auto pg_table = Catalog::GetInstance()
119+
->GetSystemCatalogs(database_oid)
120+
->GetTableCatalog();
121+
129122
// delete column from cache
130-
auto table_object =
131-
TableCatalog::GetInstance()->GetTableObject(table_oid, txn);
123+
auto table_object = pg_table->GetTableObject(table_oid, txn);
132124
table_object->EvictLayout(layout_id);
133125

134126
return DeleteWithIndexScan(index_offset, values, txn);
@@ -141,8 +133,10 @@ bool LayoutCatalog::DeleteLayouts(oid_t table_oid,
141133
values.push_back(type::ValueFactory::GetIntegerValue(table_oid).Copy());
142134

143135
// delete layouts from cache
144-
auto table_object =
145-
TableCatalog::GetInstance()->GetTableObject(table_oid, txn);
136+
auto pg_table = Catalog::GetInstance()
137+
->GetSystemCatalogs(database_oid)
138+
->GetTableCatalog();
139+
auto table_object = pg_table->GetTableObject(table_oid, txn);
146140
table_object->EvictAllLayouts();
147141

148142
return DeleteWithIndexScan(index_offset, values, txn);
@@ -152,8 +146,10 @@ const std::unordered_map<oid_t, std::shared_ptr<const storage::Layout>>
152146
LayoutCatalog::GetLayouts(oid_t table_oid,
153147
concurrency::TransactionContext *txn) {
154148
// Try to find the layouts in the cache
155-
auto table_object =
156-
TableCatalog::GetInstance()->GetTableObject(table_oid, txn);
149+
auto pg_table = Catalog::GetInstance()
150+
->GetSystemCatalogs(database_oid)
151+
->GetTableCatalog();
152+
auto table_object = pg_table->GetTableObject(table_oid, txn);
157153
PELOTON_ASSERT(table_object && table_object->GetTableOid() == table_oid);
158154
auto layout_objects = table_object->GetLayouts(true);
159155
if (layout_objects.size() != 0) {

src/catalog/system_catalogs.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "catalog/system_catalogs.h"
1414
#include "catalog/column_catalog.h"
1515
#include "catalog/index_catalog.h"
16+
#include "catalog/layout_catalog.h"
1617
#include "catalog/table_catalog.h"
1718
#include "storage/data_table.h"
1819
#include "storage/database.h"
@@ -38,14 +39,16 @@ SystemCatalogs::SystemCatalogs(storage::Database *database,
3839
pg_namespace_ = new SchemaCatalog(database, pool, txn);
3940
pg_table_ = new TableCatalog(database, pool, txn);
4041
pg_index_ = new IndexCatalog(database, pool, txn);
42+
pg_layout_ = new LayoutCatalog(database, pool, txn);
4143

4244
// TODO: can we move this to BootstrapSystemCatalogs()?
4345
// insert column information into pg_attribute
4446
std::vector<std::pair<oid_t, oid_t>> shared_tables = {
4547
{CATALOG_DATABASE_OID, DATABASE_CATALOG_OID},
4648
{database_oid, TABLE_CATALOG_OID},
4749
{database_oid, SCHEMA_CATALOG_OID},
48-
{database_oid, INDEX_CATALOG_OID}};
50+
{database_oid, INDEX_CATALOG_OID},
51+
{database_oid, LAYOUT_CATALOG_OID}};
4952

5053
for (int i = 0; i < (int)shared_tables.size(); i++) {
5154
oid_t column_id = 0;
@@ -65,6 +68,7 @@ SystemCatalogs::SystemCatalogs(storage::Database *database,
6568

6669
SystemCatalogs::~SystemCatalogs() {
6770
delete pg_index_;
71+
delete pg_layout_;
6872
delete pg_table_;
6973
delete pg_attribute_;
7074
delete pg_namespace_;

src/catalog/table_catalog.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,6 @@ bool TableCatalogObject::EvictLayout(oid_t layout_id) {
412412
return true;
413413
}
414414

415-
TableCatalog *TableCatalog::GetInstance(storage::Database *pg_catalog,
416-
type::AbstractPool *pool,
417-
concurrency::TransactionContext *txn) {
418-
static TableCatalog table_catalog{pg_catalog, pool, txn};
419-
return &table_catalog;
420-
}
421-
422-
423415
TableCatalog::~TableCatalog() {}
424416

425417
/*@brief private function for initialize schema of pg_table

src/include/catalog/catalog_defaults.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace catalog {
3636

3737
// Local oids from START_OID = 0 to START_OID + OID_OFFSET are reserved
3838
#define OID_OFFSET 100
39-
#define CATALOG_TABLES_COUNT 8
39+
#define CATALOG_TABLES_COUNT 9
4040

4141
// Oid mask for each type
4242
#define DATABASE_OID_MASK (static_cast<oid_t>(catalog::CatalogType::DATABASE))
@@ -55,7 +55,7 @@ namespace catalog {
5555
#define CATALOG_SCHEMA_OID (0 | SCHEMA_OID_MASK)
5656
#define DEFUALT_SCHEMA_OID (1 | SCHEMA_OID_MASK)
5757
#define CATALOG_SCHEMA_NAME "pg_catalog"
58-
#define DEFUALT_SCHEMA_NAME "public"
58+
#define DEFAULT_SCHEMA_NAME "public"
5959

6060
// Reserved pg_xxx table oid
6161
#define DATABASE_CATALOG_OID (0 | TABLE_OID_MASK)

src/include/catalog/layout_catalog.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class LayoutCatalog : public AbstractCatalog {
4747
type::AbstractPool *pool = nullptr,
4848
concurrency::TransactionContext *txn = nullptr);
4949

50+
LayoutCatalog(storage::Database *pg_catalog, type::AbstractPool *pool,
51+
concurrency::TransactionContext *txn);
52+
5053
~LayoutCatalog();
5154

5255
//===--------------------------------------------------------------------===//
@@ -70,10 +73,6 @@ class LayoutCatalog : public AbstractCatalog {
7073
const std::unordered_map<oid_t, std::shared_ptr<const storage::Layout>>
7174
GetLayouts(oid_t table_oid, concurrency::TransactionContext *txn);
7275

73-
74-
LayoutCatalog(storage::Database *pg_catalog, type::AbstractPool *pool,
75-
concurrency::TransactionContext *txn);
76-
7776
std::unique_ptr<catalog::Schema> InitializeSchema();
7877

7978
enum ColumnId {

src/include/catalog/system_catalogs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class SchemaCatalog;
3434
class TableCatalog;
3535
class IndexCatalog;
3636
class ColumnCatalog;
37+
class LayoutCatalog;
3738

3839
class SystemCatalogs {
3940
public:
@@ -79,6 +80,13 @@ class SystemCatalogs {
7980
return pg_index_;
8081
}
8182

83+
LayoutCatalog *GetLayoutCatalog() {
84+
if (!pg_layout_) {
85+
throw CatalogException("Layout catalog has not been initialized");
86+
}
87+
return pg_layout_;
88+
}
89+
8290
TriggerCatalog *GetTriggerCatalog() {
8391
if (!pg_trigger_) {
8492
throw CatalogException("Trigger catalog has not been initialized");
@@ -112,6 +120,7 @@ class SystemCatalogs {
112120
SchemaCatalog *pg_namespace_;
113121
TableCatalog *pg_table_;
114122
IndexCatalog *pg_index_;
123+
LayoutCatalog *pg_layout_;
115124

116125
TriggerCatalog *pg_trigger_;
117126
// ProcCatalog *pg_proc;

src/include/parser/sql_statement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class TableRefStatement : public SQLStatement {
7373
table_info_->database_name = default_database_name;
7474
// if schema name is not specified, then it's default value is "public"
7575
if (table_info_->schema_name.empty())
76-
table_info_->schema_name = DEFUALT_SCHEMA_NAME;
76+
table_info_->schema_name = DEFAULT_SCHEMA_NAME;
7777
}
7878

7979
virtual inline std::string GetTableName() const {

src/include/parser/table_ref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct TableRef {
7676
}
7777

7878
if (table_info_->schema_name.empty()) {
79-
table_info_->schema_name = DEFUALT_SCHEMA_NAME;
79+
table_info_->schema_name = DEFAULT_SCHEMA_NAME;
8080
}
8181
}
8282

src/optimizer/stats/tuple_samples_storage.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ void TupleSamplesStorage::AddSamplesTable(
6666
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
6767
auto txn = txn_manager.BeginTransaction();
6868
catalog->CreateTable(std::string(SAMPLES_DB_NAME),
69-
std::string(DEFUALT_SCHEMA_NAME), samples_table_name,
69+
std::string(DEFAULT_SCHEMA_NAME), samples_table_name,
7070
std::move(schema_ptr), txn, is_catalog);
7171

7272
auto samples_table = catalog->GetTableWithName(
73-
std::string(SAMPLES_DB_NAME), std::string(DEFUALT_SCHEMA_NAME),
73+
std::string(SAMPLES_DB_NAME), std::string(DEFAULT_SCHEMA_NAME),
7474
samples_table_name, txn);
7575

7676
for (auto &tuple : sampled_tuples) {
@@ -94,7 +94,7 @@ ResultType TupleSamplesStorage::DeleteSamplesTable(
9494
ResultType result = ResultType::FAILURE;
9595
try {
9696
result = catalog->DropTable(std::string(SAMPLES_DB_NAME),
97-
std::string(DEFUALT_SCHEMA_NAME),
97+
std::string(DEFAULT_SCHEMA_NAME),
9898
samples_table_name, txn);
9999
} catch (CatalogException &e) {
100100
// Samples table does not exist, no need to drop
@@ -187,7 +187,7 @@ TupleSamplesStorage::GetTupleSamples(oid_t database_id, oid_t table_id) {
187187
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
188188
auto txn = txn_manager.BeginTransaction();
189189
auto data_table = catalog->GetTableWithName(std::string(SAMPLES_DB_NAME),
190-
std::string(DEFUALT_SCHEMA_NAME),
190+
std::string(DEFAULT_SCHEMA_NAME),
191191
samples_table_name, txn);
192192

193193
auto col_count = data_table->GetSchema()->GetColumnCount();
@@ -214,7 +214,7 @@ void TupleSamplesStorage::GetColumnSamples(
214214
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
215215
auto txn = txn_manager.BeginTransaction();
216216
auto data_table = catalog->GetTableWithName(std::string(SAMPLES_DB_NAME),
217-
std::string(DEFUALT_SCHEMA_NAME),
217+
std::string(DEFAULT_SCHEMA_NAME),
218218
samples_table_name, txn);
219219

220220
std::vector<oid_t> column_ids({column_id});

0 commit comments

Comments
 (0)