@@ -169,22 +169,22 @@ void Catalog::BootstrapSystemCatalogs(storage::Database *database,
169
169
// pg_database record is shared across different databases
170
170
system_catalogs->GetTableCatalog ()->InsertTable (
171
171
DATABASE_CATALOG_OID, DATABASE_CATALOG_NAME, CATALOG_SCHEMA_NAME,
172
- CATALOG_DATABASE_OID, pool_.get (), txn);
172
+ CATALOG_DATABASE_OID, ROW_STORE_LAYOUT_OID, pool_.get (), txn);
173
173
system_catalogs->GetTableCatalog ()->InsertTable (
174
174
SCHEMA_CATALOG_OID, SCHEMA_CATALOG_NAME, CATALOG_SCHEMA_NAME,
175
- database_oid, pool_.get (), txn);
175
+ database_oid, ROW_STORE_LAYOUT_OID, pool_.get (), txn);
176
176
system_catalogs->GetTableCatalog ()->InsertTable (
177
177
TABLE_CATALOG_OID, TABLE_CATALOG_NAME, CATALOG_SCHEMA_NAME, database_oid,
178
- pool_.get (), txn);
178
+ ROW_STORE_LAYOUT_OID, pool_.get (), txn);
179
179
system_catalogs->GetTableCatalog ()->InsertTable (
180
180
INDEX_CATALOG_OID, INDEX_CATALOG_NAME, CATALOG_SCHEMA_NAME, database_oid,
181
- pool_.get (), txn);
181
+ ROW_STORE_LAYOUT_OID, pool_.get (), txn);
182
182
system_catalogs->GetTableCatalog ()->InsertTable (
183
183
COLUMN_CATALOG_OID, COLUMN_CATALOG_NAME, CATALOG_SCHEMA_NAME,
184
- database_oid, pool_.get (), txn);
184
+ database_oid, ROW_STORE_LAYOUT_OID, pool_.get (), txn);
185
185
system_catalogs->GetTableCatalog ()->InsertTable (
186
186
LAYOUT_CATALOG_OID, LAYOUT_CATALOG_NAME, CATALOG_SCHEMA_NAME,
187
- database_oid, pool_.get (), txn);
187
+ database_oid, ROW_STORE_LAYOUT_OID, pool_.get (), txn);
188
188
}
189
189
190
190
void Catalog::Bootstrap () {
@@ -208,6 +208,12 @@ void Catalog::Bootstrap() {
208
208
209
209
InitializeLanguages ();
210
210
InitializeFunctions ();
211
+
212
+ // Reset oid of each catalog to avoid collisions between catalog
213
+ // values added by system and users when checkpoint recovery.
214
+ DatabaseCatalog::GetInstance ()->UpdateOid (OID_FOR_USER_OFFSET);
215
+ LanguageCatalog::GetInstance ().UpdateOid (OID_FOR_USER_OFFSET);
216
+ ProcCatalog::GetInstance ().UpdateOid (OID_FOR_USER_OFFSET);
211
217
}
212
218
213
219
// ===----------------------------------------------------------------------===//
@@ -362,13 +368,14 @@ ResultType Catalog::CreateTable(const std::string &database_name,
362
368
363
369
// Update pg_table with table info
364
370
pg_table->InsertTable (table_oid, table_name, schema_name,
365
- database_object->GetDatabaseOid (), pool_.get (), txn);
371
+ database_object->GetDatabaseOid (),
372
+ table->GetDefaultLayout ()->GetOid (), pool_.get (), txn);
366
373
oid_t column_id = 0 ;
367
374
for (const auto &column : table->GetSchema ()->GetColumns ()) {
368
375
pg_attribute->InsertColumn (table_oid, column.GetName (), column_id,
369
376
column.GetOffset (), column.GetType (),
370
- column.IsInlined (), column.GetConstraints (),
371
- pool_.get (), txn);
377
+ column.GetLength (), column.IsInlined (),
378
+ column. GetConstraints (), pool_.get (), txn);
372
379
373
380
// Create index on unique single column
374
381
if (column.IsUnique ()) {
@@ -383,6 +390,15 @@ ResultType Catalog::CreateTable(const std::string &database_name,
383
390
}
384
391
CreatePrimaryIndex (database_object->GetDatabaseOid (), table_oid, schema_name,
385
392
txn);
393
+
394
+ // Create layout as default layout
395
+ auto pg_layout =
396
+ catalog_map_[database_object->GetDatabaseOid ()]->GetLayoutCatalog ();
397
+ auto default_layout = table->GetDefaultLayout ();
398
+ if (!pg_layout->InsertLayout (table_oid, default_layout, pool_.get (), txn))
399
+ throw CatalogException (" Failed to create a new layout for table "
400
+ + table_name);
401
+
386
402
return ResultType::SUCCESS;
387
403
}
388
404
@@ -573,15 +589,15 @@ std::shared_ptr<const storage::Layout> Catalog::CreateLayout(
573
589
// Ensure that the new layout
574
590
PELOTON_ASSERT (layout_oid < INVALID_OID);
575
591
auto new_layout = std::shared_ptr<const storage::Layout>(
576
- new const storage::Layout (column_map, layout_oid));
592
+ new const storage::Layout (column_map, column_map. size (), layout_oid));
577
593
578
594
// Add the layout the pg_layout table
579
595
auto pg_layout = catalog_map_[database_oid]->GetLayoutCatalog ();
580
- bool result =
581
- pg_layout-> InsertLayout (table_oid, new_layout, pool_. get (), txn);
582
- if (!result ) {
583
- LOG_ERROR (" Failed to create a new layout for table %u" , table_oid);
584
- return nullptr ;
596
+ if (pg_layout-> GetLayoutWithOid (table_oid, new_layout-> GetOid (), txn)
597
+ == nullptr &&
598
+ !pg_layout-> InsertLayout (table_oid, new_layout, pool_. get (), txn) ) {
599
+ LOG_ERROR (" Failed to create a new layout for table %u" , table_oid);
600
+ return nullptr ;
585
601
}
586
602
return new_layout;
587
603
}
@@ -596,6 +612,10 @@ std::shared_ptr<const storage::Layout> Catalog::CreateDefaultLayout(
596
612
auto database = storage_manager->GetDatabaseWithOid (database_oid);
597
613
auto table = database->GetTableWithOid (table_oid);
598
614
table->SetDefaultLayout (new_layout);
615
+
616
+ // update table catalog
617
+ catalog_map_[database_oid]->GetTableCatalog ()
618
+ ->UpdateDefaultLayoutOid (new_layout->GetOid (), table_oid, txn);
599
619
}
600
620
return new_layout;
601
621
}
@@ -791,7 +811,7 @@ ResultType Catalog::DropIndex(oid_t database_oid, oid_t index_oid,
791
811
// find index catalog object by looking up pg_index or read from cache using
792
812
// index_oid
793
813
auto pg_index = catalog_map_[database_oid]->GetIndexCatalog ();
794
- auto index_object = pg_index->GetIndexObject (index_oid, txn);
814
+ auto index_object = pg_index->GetIndexObject (database_oid, index_oid, txn);
795
815
if (index_object == nullptr ) {
796
816
throw CatalogException (" Can't find index " + std::to_string (index_oid) +
797
817
" to drop" );
@@ -801,7 +821,7 @@ ResultType Catalog::DropIndex(oid_t database_oid, oid_t index_oid,
801
821
auto table = storage_manager->GetTableWithOid (database_oid,
802
822
index_object->GetTableOid ());
803
823
// drop record in pg_index
804
- pg_index->DeleteIndex (index_oid, txn);
824
+ pg_index->DeleteIndex (database_oid, index_oid, txn);
805
825
LOG_TRACE (" Successfully drop index %d for table %s" , index_oid,
806
826
table->GetName ().c_str ());
807
827
@@ -822,17 +842,29 @@ ResultType Catalog::DropLayout(oid_t database_oid, oid_t table_oid,
822
842
auto table = database->GetTableWithOid (table_oid);
823
843
auto default_layout = table->GetDefaultLayout ();
824
844
825
- if (default_layout.GetOid () == layout_oid) {
826
- table->ResetDefaultLayout ();
827
- }
828
-
829
845
auto pg_layout = catalog_map_[database_oid]->GetLayoutCatalog ();
830
846
if (!pg_layout->DeleteLayout (table_oid, layout_oid, txn)) {
831
847
auto layout = table->GetDefaultLayout ();
832
- LOG_DEBUG (" Layout delete failed. Default layout id: %u" , layout. GetOid ());
848
+ LOG_DEBUG (" Layout delete failed. Default layout id: %u" , layout-> GetOid ());
833
849
return ResultType::FAILURE;
834
850
}
835
851
852
+ if (default_layout->GetOid () == layout_oid) {
853
+ table->ResetDefaultLayout ();
854
+ auto new_default_layout = table->GetDefaultLayout ();
855
+ if (pg_layout->GetLayoutWithOid (table_oid, new_default_layout->GetOid (),
856
+ txn) == nullptr &&
857
+ !pg_layout->InsertLayout (table_oid, new_default_layout,
858
+ pool_.get (), txn)) {
859
+ LOG_DEBUG (" Failed to create a new layout for table %d" , table_oid);
860
+ return ResultType::FAILURE;
861
+ }
862
+
863
+ // update table catalog
864
+ catalog_map_[database_oid]->GetTableCatalog ()
865
+ ->UpdateDefaultLayoutOid (new_default_layout->GetOid (), table_oid, txn);
866
+ }
867
+
836
868
return ResultType::SUCCESS;
837
869
}
838
870
0 commit comments