Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::WriteAheadLogDeserializer Class Reference
Collaboration diagram for duckdb::WriteAheadLogDeserializer:

Public Member Functions

 WriteAheadLogDeserializer (ReplayState &state_p, BufferedFileReader &stream_p, bool deserialize_only=false)
 WriteAheadLogDeserializer (ReplayState &state_p, unique_ptr< data_t[]> data_p, idx_t size, bool deserialize_only=false)
bool ReplayEntry ()
bool DeserializeOnly () const

Static Public Member Functions

static WriteAheadLogDeserializer GetEntryDeserializer (ReplayState &state_p, BufferedFileReader &stream, bool deserialize_only=false)
static void ThrowVersionError (idx_t checkpoint_iteration, idx_t expected_checkpoint_iteration)

Protected Member Functions

void ReplayEntry (WALType wal_type)
void ReplayVersion ()
void ReplayCreateTable ()
void ReplayDropTable ()
void ReplayAlter ()
void ReplayCreateView ()
void ReplayDropView ()
void ReplayCreateSchema ()
void ReplayDropSchema ()
void ReplayCreateType ()
void ReplayDropType ()
void ReplayCreateSequence ()
void ReplayDropSequence ()
void ReplaySequenceValue ()
void ReplayCreateMacro ()
void ReplayDropMacro ()
void ReplayCreateTableMacro ()
void ReplayDropTableMacro ()
void ReplayCreateIndex ()
void ReplayDropIndex ()
void ReplayUseTable ()
void ReplayInsert ()
void ReplayRowGroupData ()
void ReplayDelete ()
void ReplayUpdate ()
void ReplayCheckpoint ()

Private Member Functions

void ReplayIndexData (IndexStorageInfo &info)

Private Attributes

ReplayState & state
AttachedDatabase & db
ClientContext & context
Catalog & catalog
unique_ptr< data_t[]> data
MemoryStream stream
BinaryDeserializer deserializer
bool deserialize_only
optional_idx expected_checkpoint_id

Constructor & Destructor Documentation

◆ WriteAheadLogDeserializer() [1/2]

duckdb::WriteAheadLogDeserializer::WriteAheadLogDeserializer ( ReplayState & state_p,
BufferedFileReader & stream_p,
bool deserialize_only = false )
inline
443866 : state(state_p), db(state.db), context(state.context), catalog(state.catalog), data(nullptr),
443867 stream(nullptr, 0), deserializer(stream_p), deserialize_only(deserialize_only) {
443868 deserializer.Set<Catalog &>(catalog);
443869 }

◆ WriteAheadLogDeserializer() [2/2]

duckdb::WriteAheadLogDeserializer::WriteAheadLogDeserializer ( ReplayState & state_p,
unique_ptr< data_t[]> data_p,
idx_t size,
bool deserialize_only = false )
inline
443872 : state(state_p), db(state.db), context(state.context), catalog(state.catalog), data(std::move(data_p)),
443873 stream(data.get(), size), deserializer(stream), deserialize_only(deserialize_only) {
443874 deserializer.Set<Catalog &>(catalog);
443875 }

Member Function Documentation

◆ GetEntryDeserializer()

WriteAheadLogDeserializer duckdb::WriteAheadLogDeserializer::GetEntryDeserializer ( ReplayState & state_p,
BufferedFileReader & stream,
bool deserialize_only = false )
inlinestatic

Version 3 means that the WAL is encrypted For encryption, the length field remains plaintext After the length field, we store a 12-byte nonce (for GCM) After the nonce, we store the checksum, followed by the actual entry After the stored entry, we store a 16-byte nonce (for GCM).

initialize the decryption

Allocate a decryption buffer

read and verify the stored tag

read the stored checksum

copy the decrypted data to the output buffer

443878 {
443879 if (state_p.wal_version == 1) {
443880 // old WAL versions do not have checksums
443881 return WriteAheadLogDeserializer(state_p, stream, deserialize_only);
443882 }
443883
443884 if (state_p.wal_version == 2) {
443885 // read the size and checksum
443886 auto size = stream.Read<uint64_t>();
443887 auto stored_checksum = stream.Read<uint64_t>();
443888 auto offset = stream.CurrentOffset();
443889 auto file_size = stream.FileSize();
443890
443891 if (offset + size > file_size) {
443892 throw SerializationException(
443893 "Corrupt WAL file: entry size exceeded remaining data in file at byte position %llu "
443894 "(found entry with size %llu bytes, file size %llu bytes)",
443895 offset, size, file_size);
443896 }
443897
443898 // allocate a buffer and read data into the buffer
443899 auto buffer = unique_ptr<data_t[]>(new data_t[size]);
443900 stream.ReadData(buffer.get(), size);
443901
443902 // compute and verify the checksum
443903 auto computed_checksum = Checksum(buffer.get(), size);
443904 if (stored_checksum != computed_checksum) {
443905 throw IOException("Corrupt WAL file: entry at byte position %llu computed checksum %llu does not match "
443906 "stored checksum %llu",
443907 offset, computed_checksum, stored_checksum);
443908 }
443909
443910 return WriteAheadLogDeserializer(state_p, std::move(buffer), size, deserialize_only);
443911 }
443912
443913 if (state_p.wal_version == 3) {
443914 auto &database = state_p.db.GetDatabase();
443920
443921 // read the size (this is excluding the nonce, checksum and tag)
443922 auto size = stream.Read<uint64_t>();
443923 // the ciphertext size is including the checksum
443924 const auto ciphertext_size = size + sizeof(uint64_t);
443925
443926 auto offset = stream.CurrentOffset();
443927 auto file_size = stream.FileSize();
443928
443929 EncryptionNonce nonce(state_p.db.GetStorageManager().GetCipher(),
443930 state_p.db.GetStorageManager().GetEncryptionVersion());
443931 EncryptionTag tag;
443932
443933 stream.ReadData(nonce.data(), nonce.size());
443934
443935 auto &keys = EncryptionKeyManager::Get(state_p.db.GetDatabase());
443936 auto &catalog = state_p.db.GetCatalog().Cast<DuckCatalog>();
443937 auto derived_key = keys.GetKey(catalog.GetEncryptionKeyId());
443938 auto metadata = make_uniq<EncryptionStateMetadata>(state_p.db.GetStorageManager().GetCipher(),
443940 state_p.db.GetStorageManager().GetEncryptionVersion());
443942 auto encryption_state =
443943 database.GetEncryptionUtil(state_p.db.IsReadOnly())->CreateEncryptionState(std::move(metadata));
443944 encryption_state->InitializeDecryption(nonce, derived_key);
443945
443946 if (encryption_state->GetCipher() == EncryptionTypes::CipherType::CTR) {
443947 tag.SetSize(0);
443948 }
443949
443950 if (offset + nonce.size() + ciphertext_size + tag.size() > file_size) {
443951 throw SerializationException(
443952 "Corrupt Encrypted WAL file: entry size exceeded remaining data in file at byte position %llu "
443953 "(found entry with size %llu bytes, file size %llu bytes)",
443954 offset, size, file_size);
443955 }
443956
443958 auto buffer = unique_ptr<data_t[]>(new data_t[ciphertext_size]);
443959 auto out_buffer = unique_ptr<data_t[]>(new data_t[size]);
443960
443961 stream.ReadData(buffer.get(), ciphertext_size);
443962 encryption_state->Process(buffer.get(), ciphertext_size, buffer.get(), ciphertext_size);
443963
443964 if (encryption_state->GetCipher() == EncryptionTypes::CipherType::GCM) {
443966 stream.ReadData(tag.data(), tag.size());
443967 D_ASSERT(!tag.IsAllZeros());
443968 encryption_state->Finalize(buffer.get(), ciphertext_size, tag.data(), tag.size());
443969 } else {
443970 encryption_state->Finalize(buffer.get(), ciphertext_size, nullptr, 0);
443971 }
443972
443974 auto stored_checksum = Load<uint64_t>(buffer.get());
443975
443977 memcpy(out_buffer.get(), buffer.get() + sizeof(stored_checksum), size);
443978
443979 // compute and verify the checksum
443980 auto computed_checksum = Checksum(out_buffer.get(), size);
443981 if (stored_checksum != computed_checksum) {
443982 throw IOException("Corrupt WAL file: entry at byte position %llu computed checksum %llu does not match "
443983 "stored checksum %llu",
443984 offset, computed_checksum, stored_checksum);
443985 }
443986
443987 return WriteAheadLogDeserializer(state_p, std::move(out_buffer), size, deserialize_only);
443988 }
443989
443990 throw IOException("Failed to read WAL of version %llu - can only read version 1, 2 and 3 (encrypted)",
443991 state_p.wal_version);
443992 }
static constexpr uint64_t DEFAULT_ENCRYPTION_KEY_LENGTH
The encryption key length.
Definition duckdb.hpp:9749
GOpaque< Size > size(const GMat &src)
::uint64_t uint64_t
uint8_t data_t
data pointers
Definition duckdb.hpp:246
uint64_t Checksum(uint8_t *buffer, size_t size)
Compute a checksum over a buffer of size size.
Definition duckdb.cpp:49970
Here is the call graph for this function:

◆ ReplayEntry() [1/2]

bool duckdb::WriteAheadLogDeserializer::ReplayEntry ( )
inline
443994 {
443995 deserializer.Begin();
443996 auto wal_type = deserializer.ReadProperty<WALType>(100, "wal_type");
443997 if (wal_type == WALType::WAL_FLUSH) {
443998 deserializer.End();
443999 return true;
444000 }
444001 ReplayEntry(wal_type);
444002 deserializer.End();
444003 return false;
444004 }

◆ DeserializeOnly()

bool duckdb::WriteAheadLogDeserializer::DeserializeOnly ( ) const
inline
444006 {
444007 return deserialize_only;
444008 }

◆ ThrowVersionError()

void duckdb::WriteAheadLogDeserializer::ThrowVersionError ( idx_t checkpoint_iteration,
idx_t expected_checkpoint_iteration )
static
444447 {
444448 string relation = checkpoint_iteration < expected_checkpoint_iteration ? "an older" : "a newer";
444449 throw IOException("This WAL was created for this database file, but the WAL checkpoint iteration does not "
444450 "match the database file. "
444451 "That means the WAL was created for %s version of this database. File checkpoint "
444452 "iteration: %d, WAL checkpoint iteration: %d",
444453 relation, expected_checkpoint_iteration, checkpoint_iteration);
444454}

◆ ReplayEntry() [2/2]

void duckdb::WriteAheadLogDeserializer::ReplayEntry ( WALType wal_type)
protected
444362 {
444363 switch (entry_type) {
444364 case WALType::WAL_VERSION:
444365 ReplayVersion();
444366 break;
444367 case WALType::CREATE_TABLE:
444368 ReplayCreateTable();
444369 break;
444370 case WALType::DROP_TABLE:
444371 ReplayDropTable();
444372 break;
444373 case WALType::ALTER_INFO:
444374 ReplayAlter();
444375 break;
444376 case WALType::CREATE_VIEW:
444377 ReplayCreateView();
444378 break;
444379 case WALType::DROP_VIEW:
444380 ReplayDropView();
444381 break;
444382 case WALType::CREATE_SCHEMA:
444383 ReplayCreateSchema();
444384 break;
444385 case WALType::DROP_SCHEMA:
444386 ReplayDropSchema();
444387 break;
444388 case WALType::CREATE_SEQUENCE:
444389 ReplayCreateSequence();
444390 break;
444391 case WALType::DROP_SEQUENCE:
444392 ReplayDropSequence();
444393 break;
444394 case WALType::SEQUENCE_VALUE:
444395 ReplaySequenceValue();
444396 break;
444397 case WALType::CREATE_MACRO:
444398 ReplayCreateMacro();
444399 break;
444400 case WALType::DROP_MACRO:
444401 ReplayDropMacro();
444402 break;
444403 case WALType::CREATE_TABLE_MACRO:
444404 ReplayCreateTableMacro();
444405 break;
444406 case WALType::DROP_TABLE_MACRO:
444407 ReplayDropTableMacro();
444408 break;
444409 case WALType::CREATE_INDEX:
444410 ReplayCreateIndex();
444411 break;
444412 case WALType::DROP_INDEX:
444413 ReplayDropIndex();
444414 break;
444415 case WALType::USE_TABLE:
444416 ReplayUseTable();
444417 break;
444418 case WALType::INSERT_TUPLE:
444419 ReplayInsert();
444420 break;
444421 case WALType::ROW_GROUP_DATA:
444422 ReplayRowGroupData();
444423 break;
444424 case WALType::DELETE_TUPLE:
444425 ReplayDelete();
444426 break;
444427 case WALType::UPDATE_TUPLE:
444428 ReplayUpdate();
444429 break;
444430 case WALType::CHECKPOINT:
444431 ReplayCheckpoint();
444432 break;
444433 case WALType::CREATE_TYPE:
444434 ReplayCreateType();
444435 break;
444436 case WALType::DROP_TYPE:
444437 ReplayDropType();
444438 break;
444439 default:
444440 throw InternalException("Invalid WAL entry type!");
444441 }
444442}

◆ ReplayVersion()

void duckdb::WriteAheadLogDeserializer::ReplayVersion ( )
protected
444456 {
444457 state.wal_version = deserializer.ReadProperty<idx_t>(101, "version");
444458
444459 auto &single_file_block_manager = db.GetStorageManager().GetBlockManager().Cast<SingleFileBlockManager>();
444460 data_t db_identifier[MainHeader::DB_IDENTIFIER_LEN];
444461 bool is_set = false;
444462 deserializer.ReadOptionalList(102, "db_identifier", [&](Deserializer::List &list, idx_t i) {
444463 db_identifier[i] = list.ReadElement<uint8_t>();
444464 is_set = true;
444465 });
444466 auto checkpoint_iteration = deserializer.ReadPropertyWithDefault<optional_idx>(103, "checkpoint_iteration");
444467 if (!is_set || !checkpoint_iteration.IsValid()) {
444468 return;
444469 }
444470 auto expected_db_identifier = single_file_block_manager.GetDBIdentifier();
444471 if (!MainHeader::CompareDBIdentifiers(db_identifier, expected_db_identifier)) {
444472 throw IOException("WAL does not match database file.");
444473 }
444474
444475 auto wal_checkpoint_iteration = checkpoint_iteration.GetIndex();
444476 auto expected_checkpoint_iteration = single_file_block_manager.GetCheckpointIteration();
444477 if (expected_checkpoint_iteration != wal_checkpoint_iteration) {
444478 if (wal_checkpoint_iteration + 1 == expected_checkpoint_iteration) {
444479 // this iteration is exactly one lower than the expected iteration
444480 // this can happen if we aborted AFTER checkpointing the file, but BEFORE truncating the WAL
444481 // expect this situation to occur - we will throw an error if it does not later on
444482 state.expected_checkpoint_id = expected_checkpoint_iteration;
444483 return;
444484 }
444485 if (state.replay_state == WALReplayState::CHECKPOINT_WAL &&
444486 wal_checkpoint_iteration == expected_checkpoint_iteration + 1) {
444487 // if we are recovering from a checkpoint WAL, the checkpoint iteration is possibly one higher
444488 // (depending on when the crash happened)
444489 return;
444490 }
444491 ThrowVersionError(wal_checkpoint_iteration, expected_checkpoint_iteration);
444492 }
444493}
static constexpr idx_t DB_IDENTIFIER_LEN
The length of the unique database identifier.
Definition duckdb.hpp:9763
::uint8_t uint8_t
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ ReplayCreateTable()

void duckdb::WriteAheadLogDeserializer::ReplayCreateTable ( )
protected
444498 {
444499 auto info = deserializer.ReadProperty<unique_ptr<CreateInfo>>(101, "table");
444500 if (DeserializeOnly()) {
444501 return;
444502 }
444503 // bind the constraints to the table again
444504 auto binder = Binder::CreateBinder(context);
444505 auto &schema = catalog.GetSchema(context, info->schema);
444506 auto bound_info = Binder::BindCreateTableCheckpoint(std::move(info), schema);
444507
444508 catalog.CreateTable(context, *bound_info);
444509}

◆ ReplayDropTable()

void duckdb::WriteAheadLogDeserializer::ReplayDropTable ( )
protected
444511 {
444512 DropInfo info;
444513
444514 info.type = CatalogType::TABLE_ENTRY;
444515 info.schema = deserializer.ReadProperty<string>(101, "schema");
444516 info.name = deserializer.ReadProperty<string>(102, "name");
444517 if (DeserializeOnly()) {
444518 return;
444519 }
444520
444521 // Remove any replay indexes of this table.
444522 state.replay_index_infos.erase(std::remove_if(state.replay_index_infos.begin(), state.replay_index_infos.end(),
444523 [&info](const ReplayState::ReplayIndexInfo &replay_info) {
444524 return replay_info.table_schema == info.schema &&
444525 replay_info.table_name == info.name;
444526 }),
444527 state.replay_index_infos.end());
444528
444529 catalog.DropEntry(context, info);
444530}

◆ ReplayAlter()

void duckdb::WriteAheadLogDeserializer::ReplayAlter ( )
protected
444569 {
444570 auto info = deserializer.ReadProperty<unique_ptr<ParseInfo>>(101, "info");
444571 auto &alter_info = info->Cast<AlterInfo>();
444572 if (!alter_info.IsAddPrimaryKey()) {
444573 return ReplayWithoutIndex(context, catalog, alter_info, DeserializeOnly());
444574 }
444575
444576 auto index_storage_info = deserializer.ReadProperty<IndexStorageInfo>(102, "index_storage_info");
444577 ReplayIndexData(index_storage_info);
444578 if (DeserializeOnly()) {
444579 return;
444580 }
444581
444582 auto &table_info = alter_info.Cast<AlterTableInfo>();
444583 auto &constraint_info = table_info.Cast<AddConstraintInfo>();
444584 auto &unique_info = constraint_info.constraint->Cast<UniqueConstraint>();
444585
444586 auto &table =
444587 catalog.GetEntry<TableCatalogEntry>(context, table_info.schema, table_info.name).Cast<DuckTableEntry>();
444588 auto &column_list = table.GetColumns();
444589
444590 // Add the table to the bind context to bind the parsed expressions.
444591 auto binder = Binder::CreateBinder(context);
444592 vector<LogicalType> column_types;
444593 vector<string> column_names;
444594 for (auto &col : column_list.Logical()) {
444595 column_types.push_back(col.Type());
444596 column_names.push_back(col.Name());
444597 }
444598
444599 // Create a binder to bind the parsed expressions.
444600 vector<ColumnIndex> column_indexes;
444601 binder->bind_context.AddBaseTable(0, string(), column_names, column_types, column_indexes, table);
444602 IndexBinder idx_binder(*binder, context);
444603
444604 // Bind the parsed expressions to create unbound expressions.
444605 vector<unique_ptr<Expression>> unbound_expressions;
444606 auto logical_indexes = unique_info.GetLogicalIndexes(column_list);
444607 for (const auto &logical_index : logical_indexes) {
444608 auto &col = column_list.GetColumn(logical_index);
444609 unique_ptr<ParsedExpression> parsed = make_uniq<ColumnRefExpression>(col.GetName(), table_info.name);
444610 unbound_expressions.push_back(idx_binder.Bind(parsed));
444611 }
444612
444613 vector<column_t> column_ids;
444614 for (auto &column_index : column_indexes) {
444615 column_ids.push_back(column_index.GetPrimaryIndex());
444616 }
444617
444618 auto &storage = table.GetStorage();
444619 CreateIndexInput input(context, TableIOManager::Get(storage), storage.db, IndexConstraintType::PRIMARY,
444620 index_storage_info.name, column_ids, unbound_expressions, index_storage_info,
444621 index_storage_info.options);
444622
444623 auto index_type = context.db->config.GetIndexTypes().FindByName(ART::TYPE_NAME);
444624 auto index_instance = index_type->create_instance(input);
444625
444626 auto &table_index_list = storage.GetDataTableInfo()->GetIndexes();
444627 state.replay_index_infos.emplace_back(table_index_list, std::move(index_instance), table_info.schema,
444628 table_info.name);
444629
444630 catalog.Alter(context, alter_info);
444631}
static constexpr const char * TYPE_NAME
Index type name for the ART.
Definition duckdb.cpp:12136
static TableIOManager & Get(DataTable &table)
Obtains a reference to the TableIOManager of a specific table.
Definition duckdb.cpp:411568
float index_type

◆ ReplayCreateView()

void duckdb::WriteAheadLogDeserializer::ReplayCreateView ( )
protected
444636 {
444637 auto entry = deserializer.ReadProperty<unique_ptr<CreateInfo>>(101, "view");
444638 if (DeserializeOnly()) {
444639 return;
444640 }
444641 catalog.CreateView(context, entry->Cast<CreateViewInfo>());
444642}

◆ ReplayDropView()

void duckdb::WriteAheadLogDeserializer::ReplayDropView ( )
protected
444644 {
444645 DropInfo info;
444646 info.type = CatalogType::VIEW_ENTRY;
444647 info.schema = deserializer.ReadProperty<string>(101, "schema");
444648 info.name = deserializer.ReadProperty<string>(102, "name");
444649 if (DeserializeOnly()) {
444650 return;
444651 }
444652 catalog.DropEntry(context, info);
444653}

◆ ReplayCreateSchema()

void duckdb::WriteAheadLogDeserializer::ReplayCreateSchema ( )
protected
444658 {
444659 CreateSchemaInfo info;
444660 info.schema = deserializer.ReadProperty<string>(101, "schema");
444661 if (DeserializeOnly()) {
444662 return;
444663 }
444664
444665 catalog.CreateSchema(context, info);
444666}

◆ ReplayDropSchema()

void duckdb::WriteAheadLogDeserializer::ReplayDropSchema ( )
protected
444668 {
444669 DropInfo info;
444670
444671 info.type = CatalogType::SCHEMA_ENTRY;
444672 info.name = deserializer.ReadProperty<string>(101, "schema");
444673 if (DeserializeOnly()) {
444674 return;
444675 }
444676
444677 catalog.DropEntry(context, info);
444678}

◆ ReplayCreateType()

void duckdb::WriteAheadLogDeserializer::ReplayCreateType ( )
protected
444683 {
444684 auto info = deserializer.ReadProperty<unique_ptr<CreateInfo>>(101, "type");
444685 info->on_conflict = OnCreateConflict::IGNORE_ON_CONFLICT;
444686 catalog.CreateType(context, info->Cast<CreateTypeInfo>());
444687}

◆ ReplayDropType()

void duckdb::WriteAheadLogDeserializer::ReplayDropType ( )
protected
444689 {
444690 DropInfo info;
444691
444692 info.type = CatalogType::TYPE_ENTRY;
444693 info.schema = deserializer.ReadProperty<string>(101, "schema");
444694 info.name = deserializer.ReadProperty<string>(102, "name");
444695 if (DeserializeOnly()) {
444696 return;
444697 }
444698
444699 catalog.DropEntry(context, info);
444700}

◆ ReplayCreateSequence()

void duckdb::WriteAheadLogDeserializer::ReplayCreateSequence ( )
protected
444705 {
444706 auto entry = deserializer.ReadProperty<unique_ptr<CreateInfo>>(101, "sequence");
444707 if (DeserializeOnly()) {
444708 return;
444709 }
444710
444711 catalog.CreateSequence(context, entry->Cast<CreateSequenceInfo>());
444712}

◆ ReplayDropSequence()

void duckdb::WriteAheadLogDeserializer::ReplayDropSequence ( )
protected
444714 {
444715 DropInfo info;
444716 info.type = CatalogType::SEQUENCE_ENTRY;
444717 info.schema = deserializer.ReadProperty<string>(101, "schema");
444718 info.name = deserializer.ReadProperty<string>(102, "name");
444719 if (DeserializeOnly()) {
444720 return;
444721 }
444722
444723 catalog.DropEntry(context, info);
444724}

◆ ReplaySequenceValue()

void duckdb::WriteAheadLogDeserializer::ReplaySequenceValue ( )
protected
444726 {
444727 auto schema = deserializer.ReadProperty<string>(101, "schema");
444728 auto name = deserializer.ReadProperty<string>(102, "name");
444729 auto usage_count = deserializer.ReadProperty<uint64_t>(103, "usage_count");
444730 auto counter = deserializer.ReadProperty<int64_t>(104, "counter");
444731 if (DeserializeOnly()) {
444732 return;
444733 }
444734
444735 // fetch the sequence from the catalog
444736 auto &seq = catalog.GetEntry<SequenceCatalogEntry>(context, schema, name);
444737 seq.ReplayValue(usage_count, counter);
444738}
::int64_t int64_t

◆ ReplayCreateMacro()

void duckdb::WriteAheadLogDeserializer::ReplayCreateMacro ( )
protected
444743 {
444744 auto entry = deserializer.ReadProperty<unique_ptr<CreateInfo>>(101, "macro");
444745 if (DeserializeOnly()) {
444746 return;
444747 }
444748
444749 catalog.CreateFunction(context, entry->Cast<CreateMacroInfo>());
444750}

◆ ReplayDropMacro()

void duckdb::WriteAheadLogDeserializer::ReplayDropMacro ( )
protected
444752 {
444753 DropInfo info;
444754 info.type = CatalogType::MACRO_ENTRY;
444755 info.schema = deserializer.ReadProperty<string>(101, "schema");
444756 info.name = deserializer.ReadProperty<string>(102, "name");
444757 if (DeserializeOnly()) {
444758 return;
444759 }
444760
444761 catalog.DropEntry(context, info);
444762}

◆ ReplayCreateTableMacro()

void duckdb::WriteAheadLogDeserializer::ReplayCreateTableMacro ( )
protected
444767 {
444768 auto entry = deserializer.ReadProperty<unique_ptr<CreateInfo>>(101, "table_macro");
444769 if (DeserializeOnly()) {
444770 return;
444771 }
444772 catalog.CreateFunction(context, entry->Cast<CreateMacroInfo>());
444773}

◆ ReplayDropTableMacro()

void duckdb::WriteAheadLogDeserializer::ReplayDropTableMacro ( )
protected
444775 {
444776 DropInfo info;
444777 info.type = CatalogType::TABLE_MACRO_ENTRY;
444778 info.schema = deserializer.ReadProperty<string>(101, "schema");
444779 info.name = deserializer.ReadProperty<string>(102, "name");
444780 if (DeserializeOnly()) {
444781 return;
444782 }
444783
444784 catalog.DropEntry(context, info);
444785}

◆ ReplayCreateIndex()

void duckdb::WriteAheadLogDeserializer::ReplayCreateIndex ( )
protected
444790 {
444791 auto create_info = deserializer.ReadProperty<unique_ptr<CreateInfo>>(101, "index_catalog_entry");
444792 auto index_info = deserializer.ReadProperty<IndexStorageInfo>(102, "index_storage_info");
444793
444794 ReplayIndexData(index_info);
444795 if (DeserializeOnly()) {
444796 return;
444797 }
444798 auto &info = create_info->Cast<CreateIndexInfo>();
444799
444800 // Ensure that the index type exists.
444801 if (info.index_type.empty()) {
444802 info.index_type = ART::TYPE_NAME;
444803 }
444804
444805 const auto schema_name = create_info->schema;
444806 const auto table_name = info.table;
444807
444808 auto &entry = catalog.GetEntry<TableCatalogEntry>(context, schema_name, table_name);
444809 auto &table = entry.Cast<DuckTableEntry>();
444810 auto &storage = table.GetStorage();
444811 auto &io_manager = TableIOManager::Get(storage);
444812
444813 // Create the index in the catalog.
444814 table.schema.CreateIndex(context, info, table);
444815
444816 // add the index to the storage
444817 auto unbound_index = make_uniq<UnboundIndex>(std::move(create_info), std::move(index_info), io_manager, db);
444818
444819 auto &table_index_list = storage.GetDataTableInfo()->GetIndexes();
444820 state.replay_index_infos.emplace_back(table_index_list, std::move(unbound_index), schema_name, table_name);
444821}

◆ ReplayDropIndex()

void duckdb::WriteAheadLogDeserializer::ReplayDropIndex ( )
protected
444823 {
444824 DropInfo info;
444825 info.type = CatalogType::INDEX_ENTRY;
444826 info.schema = deserializer.ReadProperty<string>(101, "schema");
444827 info.name = deserializer.ReadProperty<string>(102, "name");
444828 if (DeserializeOnly()) {
444829 return;
444830 }
444831
444832 // Remove the replay index, if any.
444833 state.replay_index_infos.erase(std::remove_if(state.replay_index_infos.begin(), state.replay_index_infos.end(),
444834 [&info](const ReplayState::ReplayIndexInfo &replay_info) {
444835 return replay_info.table_schema == info.schema &&
444836 replay_info.index->GetIndexName() == info.name;
444837 }),
444838 state.replay_index_infos.end());
444839
444840 catalog.DropEntry(context, info);
444841}

◆ ReplayUseTable()

void duckdb::WriteAheadLogDeserializer::ReplayUseTable ( )
protected
444846 {
444847 auto schema_name = deserializer.ReadProperty<string>(101, "schema");
444848 auto table_name = deserializer.ReadProperty<string>(102, "table");
444849 if (DeserializeOnly()) {
444850 return;
444851 }
444852 state.current_table = &catalog.GetEntry<TableCatalogEntry>(context, schema_name, table_name);
444853}

◆ ReplayInsert()

void duckdb::WriteAheadLogDeserializer::ReplayInsert ( )
protected
444855 {
444856 DataChunk chunk;
444857 deserializer.ReadObject(101, "chunk", [&](Deserializer &object) { chunk.Deserialize(object); });
444858 if (DeserializeOnly()) {
444859 return;
444860 }
444861 if (!state.current_table) {
444862 throw InternalException("Corrupt WAL: insert without table");
444863 }
444864
444865 // Append to the current table without constraint verification.
444866 vector<unique_ptr<BoundConstraint>> bound_constraints;
444867 auto &storage = state.current_table->GetStorage();
444868 storage.LocalWALAppend(*state.current_table, context, chunk, bound_constraints);
444869}

◆ ReplayRowGroupData()

void duckdb::WriteAheadLogDeserializer::ReplayRowGroupData ( )
protected
444871 {
444872 auto &block_manager = db.GetStorageManager().GetBlockManager();
444873 PersistentCollectionData data;
444874 deserializer.Set<DatabaseInstance &>(db.GetDatabase());
444875 CompressionInfo compression_info(block_manager);
444876 deserializer.Set<const CompressionInfo &>(compression_info);
444877 deserializer.ReadProperty(101, "row_group_data", data);
444878 deserializer.Unset<const CompressionInfo>();
444879 deserializer.Unset<DatabaseInstance>();
444880 if (DeserializeOnly()) {
444881 // label blocks in data as used - they will be used after the WAL replay is finished
444882 // we need to do this during the deserialization phase to ensure the blocks will not be overwritten
444883 // by previous deserialization steps
444884 for (auto &block_id : data.GetBlockIds()) {
444885 block_manager.MarkBlockAsUsed(block_id);
444886 }
444887 return;
444888 }
444889 if (!state.current_table) {
444890 throw InternalException("Corrupt WAL: insert without table");
444891 }
444892 auto &storage = state.current_table->GetStorage();
444893 auto &table_info = storage.GetDataTableInfo();
444894 auto base_row = storage.GetTotalRows();
444895 RowGroupCollection new_row_groups(table_info, table_info->GetIOManager(), storage.GetTypes(), base_row);
444896 new_row_groups.Initialize(data);
444897
444898 // if we have any indexes - scan the row groups and add data to the indexes
444899 auto &indexes = table_info->GetIndexes();
444900 if (!indexes.Empty()) {
444901 auto &transaction = DuckTransaction::Get(context, db);
444902 // we have indexes - append
444903 vector<StorageIndex> column_ids;
444904 for (auto &col : state.current_table->GetColumns().Physical()) {
444905 column_ids.emplace_back(col.StorageOid());
444906 }
444907 Vector row_id_vector(LogicalType::ROW_TYPE, STANDARD_VECTOR_SIZE);
444908 auto row_ids = FlatVector::GetData<row_t>(row_id_vector);
444909 auto current_row_id = storage.GetTotalRows();
444910 for (auto &chunk : new_row_groups.Chunks(transaction, column_ids)) {
444911 for (idx_t r = 0; r < chunk.size(); r++) {
444912 row_ids[r] = NumericCast<row_t>(current_row_id + r);
444913 }
444914 current_row_id += chunk.size();
444915 for (auto &index : indexes.Indexes()) {
444916 if (!index.IsBound()) {
444917 auto &unbound_index = index.Cast<UnboundIndex>();
444918 unbound_index.BufferChunk(chunk, row_id_vector, column_ids, BufferedIndexReplay::INSERT_ENTRY);
444919 continue;
444920 }
444921 auto &bound_index = index.Cast<BoundIndex>();
444922 bound_index.Append(chunk, row_id_vector);
444923 }
444924 }
444925 }
444926 storage.MergeStorage(new_row_groups, nullptr);
444927}
index

◆ ReplayDelete()

void duckdb::WriteAheadLogDeserializer::ReplayDelete ( )
protected
444929 {
444930 DataChunk chunk;
444931 deserializer.ReadObject(101, "chunk", [&](Deserializer &object) { chunk.Deserialize(object); });
444932 if (DeserializeOnly()) {
444933 return;
444934 }
444935 if (!state.current_table) {
444936 throw SerializationException("delete without a table");
444937 }
444938
444939 D_ASSERT(chunk.ColumnCount() == 1 && chunk.data[0].GetType() == LogicalType::ROW_TYPE);
444940 auto &row_identifiers = chunk.data[0];
444941 row_identifiers.Flatten(chunk.size());
444942 auto source_ids = FlatVector::GetData<row_t>(row_identifiers);
444943
444944 // Delete the row IDs from the current table.
444945 auto &storage = state.current_table->GetStorage();
444946 auto total_rows = storage.GetTotalRows();
444947 for (idx_t i = 0; i < chunk.size(); i++) {
444948 if (source_ids[i] >= UnsafeNumericCast<row_t>(total_rows)) {
444949 throw SerializationException("invalid row ID delete in WAL");
444950 }
444951 }
444952 TableDeleteState delete_state;
444953 storage.Delete(delete_state, context, row_identifiers, chunk.size());
444954}
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445

◆ ReplayUpdate()

void duckdb::WriteAheadLogDeserializer::ReplayUpdate ( )
protected
444956 {
444957 auto column_path = deserializer.ReadProperty<vector<column_t>>(101, "column_indexes");
444958
444959 DataChunk chunk;
444960 deserializer.ReadObject(102, "chunk", [&](Deserializer &object) { chunk.Deserialize(object); });
444961
444962 if (DeserializeOnly()) {
444963 return;
444964 }
444965 if (!state.current_table) {
444966 throw InternalException("Corrupt WAL: update without table");
444967 }
444968
444969 if (column_path[0] >= state.current_table->GetColumns().PhysicalColumnCount()) {
444970 throw InternalException("Corrupt WAL: column index for update out of bounds");
444971 }
444972
444973 // remove the row id vector from the chunk
444974 auto row_ids = std::move(chunk.data.back());
444975 chunk.data.pop_back();
444976
444977 // now perform the update
444978 state.current_table->GetStorage().UpdateColumn(*state.current_table, context, row_ids, column_path, chunk);
444979}

◆ ReplayCheckpoint()

void duckdb::WriteAheadLogDeserializer::ReplayCheckpoint ( )
protected
444981 {
444982 state.checkpoint_id = deserializer.ReadProperty<MetaBlockPointer>(101, "meta_block");
444983 state.checkpoint_position = state.current_position;
444984}

◆ ReplayIndexData()

void duckdb::WriteAheadLogDeserializer::ReplayIndexData ( IndexStorageInfo & info)
private
444539 {
444540 D_ASSERT(info.IsValid() && !info.name.empty());
444541
444542 auto &single_file_sm = db.GetStorageManager().Cast<SingleFileStorageManager>();
444543 auto &block_manager = single_file_sm.block_manager;
444544 auto &buffer_manager = block_manager->buffer_manager;
444545
444546 deserializer.ReadList(103, "index_storage", [&](Deserializer::List &list, idx_t i) {
444547 auto &data_info = info.allocator_infos[i];
444548
444549 // Read the data into buffer handles and convert them to blocks on disk.
444550 for (idx_t j = 0; j < data_info.allocation_sizes.size(); j++) {
444551 // Read the data into a buffer handle.
444552 auto buffer_handle = buffer_manager.Allocate(MemoryTag::ART_INDEX, block_manager.get(), false);
444553 auto block_handle = buffer_handle.GetBlockHandle();
444554 auto data_ptr = buffer_handle.Ptr();
444555
444556 list.ReadElement<bool>(data_ptr, data_info.allocation_sizes[j]);
444557
444558 // Convert the buffer handle to a persistent block and store the block id.
444559 if (!deserialize_only) {
444560 auto block_id = block_manager->GetFreeBlockIdForCheckpoint();
444561 block_manager->ConvertToPersistent(context, block_id, std::move(block_handle),
444562 std::move(buffer_handle));
444563 data_info.block_pointers[j].block_id = block_id;
444564 }
444565 }
444566 });
444567}

The documentation for this class was generated from the following file: