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::WALWriteState Class Reference
Collaboration diagram for duckdb::WALWriteState:

Public Member Functions

 WALWriteState (DuckTransaction &transaction, WriteAheadLog &log, optional_ptr< StorageCommitState > commit_state)
void CommitEntry (UndoFlags type, data_ptr_t data)

Private Member Functions

void SwitchTable (DataTableInfo &table, UndoFlags new_op)
void WriteCatalogEntry (CatalogEntry &entry, data_ptr_t extra_data)
void WriteDelete (DeleteInfo &info)
void WriteUpdate (UpdateInfo &info)

Private Attributes

DuckTransaction & transaction
WriteAheadLog & log
optional_ptr< StorageCommitState > commit_state
optional_ptr< DataTableInfo > current_table_info
unique_ptr< DataChunk > delete_chunk
unique_ptr< DataChunk > update_chunk

Constructor & Destructor Documentation

◆ WALWriteState()

duckdb::WALWriteState::WALWriteState ( DuckTransaction & transaction,
WriteAheadLog & log,
optional_ptr< StorageCommitState > commit_state )
explicit
447950 : transaction(transaction_p), log(log), commit_state(commit_state), current_table_info(nullptr) {
447951}

Member Function Documentation

◆ CommitEntry()

void duckdb::WALWriteState::CommitEntry ( UndoFlags type,
data_ptr_t data )
448174 {
448175 switch (type) {
448176 case UndoFlags::CATALOG_ENTRY: {
448177 // set the commit timestamp of the catalog entry to the given id
448178 auto catalog_entry = Load<CatalogEntry *>(data);
448179 D_ASSERT(catalog_entry->HasParent());
448180 // push the catalog update to the WAL
448181 WriteCatalogEntry(*catalog_entry, data + sizeof(CatalogEntry *));
448182 break;
448183 }
448184 case UndoFlags::INSERT_TUPLE: {
448185 // append:
448186 auto info = reinterpret_cast<AppendInfo *>(data);
448187 if (!info->table->IsTemporary()) {
448188 info->table->WriteToLog(transaction, log, info->start_row, info->count, commit_state.get());
448189 }
448190 break;
448191 }
448192 case UndoFlags::DELETE_TUPLE: {
448193 // deletion:
448194 auto info = reinterpret_cast<DeleteInfo *>(data);
448195 if (!info->table->IsTemporary()) {
448196 WriteDelete(*info);
448197 }
448198 break;
448199 }
448200 case UndoFlags::UPDATE_TUPLE: {
448201 // update:
448202 auto info = reinterpret_cast<UpdateInfo *>(data);
448203 if (!info->segment->column_data.GetTableInfo().IsTemporary()) {
448204 WriteUpdate(*info);
448205 }
448206 break;
448207 }
448208 case UndoFlags::ATTACHED_DATABASE:
448209 break;
448210 case UndoFlags::SEQUENCE_VALUE: {
448211 auto info = reinterpret_cast<SequenceValue *>(data);
448212 log.WriteSequenceValue(*info);
448213 break;
448214 }
448215 default:
448216 throw InternalException("UndoBuffer - don't know how to commit this type!");
448217 }
448218}

◆ SwitchTable()

void duckdb::WALWriteState::SwitchTable ( DataTableInfo & table,
UndoFlags new_op )
private
447953 {
447954 if (current_table_info != &table_info) {
447955 // write the current table to the log
447956 log.WriteSetTable(table_info.GetSchemaName(), table_info.GetTableName());
447957 current_table_info = table_info;
447958 }
447959}

◆ WriteCatalogEntry()

void duckdb::WALWriteState::WriteCatalogEntry ( CatalogEntry & entry,
data_ptr_t extra_data )
private
447961 {
447962 if (entry.temporary || entry.Parent().temporary) {
447963 return;
447964 }
447965
447966 // look at the type of the parent entry
447967 auto &parent = entry.Parent();
447968
447969 switch (parent.type) {
447970 case CatalogType::TABLE_ENTRY:
447971 case CatalogType::VIEW_ENTRY:
447972 case CatalogType::INDEX_ENTRY:
447973 case CatalogType::SEQUENCE_ENTRY:
447974 case CatalogType::TYPE_ENTRY:
447975 case CatalogType::MACRO_ENTRY:
447976 case CatalogType::TABLE_MACRO_ENTRY:
447977 if (entry.type == CatalogType::RENAMED_ENTRY || entry.type == parent.type) {
447978 // ALTER statement, read the extra data after the entry
447979 auto extra_data_size = Load<idx_t>(dataptr);
447980 auto extra_data = data_ptr_cast(dataptr + sizeof(idx_t));
447981
447982 MemoryStream source(extra_data, extra_data_size);
447983 BinaryDeserializer deserializer(source);
447984 deserializer.Begin();
447985 auto column_name = deserializer.ReadProperty<string>(100, "column_name");
447986 auto parse_info = deserializer.ReadProperty<unique_ptr<ParseInfo>>(101, "alter_info");
447987 deserializer.End();
447988
447989 auto &alter_info = parse_info->Cast<AlterInfo>();
447990 log.WriteAlter(entry, alter_info);
447991 } else {
447992 switch (parent.type) {
447993 case CatalogType::TABLE_ENTRY:
447994 // CREATE TABLE statement
447995 log.WriteCreateTable(parent.Cast<TableCatalogEntry>());
447996 break;
447997 case CatalogType::VIEW_ENTRY:
447998 // CREATE VIEW statement
447999 log.WriteCreateView(parent.Cast<ViewCatalogEntry>());
448000 break;
448001 case CatalogType::INDEX_ENTRY:
448002 // CREATE INDEX statement
448003 log.WriteCreateIndex(parent.Cast<IndexCatalogEntry>());
448004 break;
448005 case CatalogType::SEQUENCE_ENTRY:
448006 // CREATE SEQUENCE statement
448007 log.WriteCreateSequence(parent.Cast<SequenceCatalogEntry>());
448008 break;
448009 case CatalogType::TYPE_ENTRY:
448010 // CREATE TYPE statement
448011 log.WriteCreateType(parent.Cast<TypeCatalogEntry>());
448012 break;
448013 case CatalogType::MACRO_ENTRY:
448014 log.WriteCreateMacro(parent.Cast<ScalarMacroCatalogEntry>());
448015 break;
448016 case CatalogType::TABLE_MACRO_ENTRY:
448017 log.WriteCreateTableMacro(parent.Cast<TableMacroCatalogEntry>());
448018 break;
448019 default:
448020 throw InternalException("Don't know how to create this type!");
448021 }
448022 }
448023 break;
448024 case CatalogType::SCHEMA_ENTRY:
448025 if (entry.type == CatalogType::RENAMED_ENTRY || entry.type == CatalogType::SCHEMA_ENTRY) {
448026 // ALTER TABLE statement, skip it
448027 return;
448028 }
448029 log.WriteCreateSchema(parent.Cast<SchemaCatalogEntry>());
448030 break;
448031 case CatalogType::RENAMED_ENTRY:
448032 // This is a rename, nothing needs to be done for this
448033 break;
448034 case CatalogType::DELETED_ENTRY:
448035 switch (entry.type) {
448036 case CatalogType::TABLE_ENTRY: {
448037 auto &table_entry = entry.Cast<DuckTableEntry>();
448038 D_ASSERT(table_entry.IsDuckTable());
448039 log.WriteDropTable(table_entry);
448040 break;
448041 }
448042 case CatalogType::SCHEMA_ENTRY:
448043 log.WriteDropSchema(entry.Cast<SchemaCatalogEntry>());
448044 break;
448045 case CatalogType::VIEW_ENTRY:
448046 log.WriteDropView(entry.Cast<ViewCatalogEntry>());
448047 break;
448048 case CatalogType::SEQUENCE_ENTRY:
448049 log.WriteDropSequence(entry.Cast<SequenceCatalogEntry>());
448050 break;
448051 case CatalogType::MACRO_ENTRY:
448052 log.WriteDropMacro(entry.Cast<ScalarMacroCatalogEntry>());
448053 break;
448054 case CatalogType::TABLE_MACRO_ENTRY:
448055 log.WriteDropTableMacro(entry.Cast<TableMacroCatalogEntry>());
448056 break;
448057 case CatalogType::TYPE_ENTRY:
448058 log.WriteDropType(entry.Cast<TypeCatalogEntry>());
448059 break;
448060 case CatalogType::INDEX_ENTRY: {
448061 log.WriteDropIndex(entry.Cast<IndexCatalogEntry>());
448062 break;
448063 }
448064 case CatalogType::RENAMED_ENTRY:
448065 case CatalogType::PREPARED_STATEMENT:
448066 case CatalogType::SCALAR_FUNCTION_ENTRY:
448067 case CatalogType::DEPENDENCY_ENTRY:
448068 case CatalogType::SECRET_ENTRY:
448069 case CatalogType::SECRET_TYPE_ENTRY:
448070 case CatalogType::SECRET_FUNCTION_ENTRY:
448071 // do nothing, prepared statements and scalar functions aren't persisted to disk
448072 break;
448073 default:
448074 throw InternalException("Don't know how to drop this type!");
448075 }
448076 break;
448077 case CatalogType::PREPARED_STATEMENT:
448078 case CatalogType::AGGREGATE_FUNCTION_ENTRY:
448079 case CatalogType::SCALAR_FUNCTION_ENTRY:
448080 case CatalogType::TABLE_FUNCTION_ENTRY:
448081 case CatalogType::COPY_FUNCTION_ENTRY:
448082 case CatalogType::PRAGMA_FUNCTION_ENTRY:
448083 case CatalogType::COLLATION_ENTRY:
448084 case CatalogType::COORDINATE_SYSTEM_ENTRY:
448085 case CatalogType::DEPENDENCY_ENTRY:
448086 case CatalogType::SECRET_ENTRY:
448087 case CatalogType::SECRET_TYPE_ENTRY:
448088 case CatalogType::SECRET_FUNCTION_ENTRY:
448089 // do nothing, these entries are not persisted to disk
448090 break;
448091 default:
448092 throw InternalException("UndoBuffer - don't know how to write this entry to the WAL");
448093 }
448094}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ WriteDelete()

void duckdb::WALWriteState::WriteDelete ( DeleteInfo & info)
private
448096 {
448097 // switch to the current table, if necessary
448098 SwitchTable(*info.table->GetDataTableInfo(), UndoFlags::DELETE_TUPLE);
448099
448100 if (!delete_chunk) {
448101 delete_chunk = make_uniq<DataChunk>();
448102 vector<LogicalType> delete_types = {LogicalType::ROW_TYPE};
448103 delete_chunk->Initialize(Allocator::DefaultAllocator(), delete_types);
448104 }
448105 auto rows = FlatVector::GetData<row_t>(delete_chunk->data[0]);
448106 if (info.is_consecutive) {
448107 for (idx_t i = 0; i < info.count; i++) {
448108 rows[i] = UnsafeNumericCast<int64_t>(info.base_row + i);
448109 }
448110 } else {
448111 auto delete_rows = info.GetRows();
448112 for (idx_t i = 0; i < info.count; i++) {
448113 rows[i] = UnsafeNumericCast<int64_t>(info.base_row) + delete_rows[i];
448114 }
448115 }
448116 delete_chunk->SetCardinality(info.count);
448117 log.WriteDelete(*delete_chunk);
448118}
int rows

◆ WriteUpdate()

void duckdb::WALWriteState::WriteUpdate ( UpdateInfo & info)
private
448120 {
448121 // switch to the current table, if necessary
448122 auto &column_data = info.segment->column_data;
448123 auto &table_info = column_data.GetTableInfo();
448124
448125 SwitchTable(table_info, UndoFlags::UPDATE_TUPLE);
448126
448127 // initialize the update chunk
448128 vector<LogicalType> update_types;
448129 if (column_data.type.id() == LogicalTypeId::VALIDITY) {
448130 update_types.emplace_back(LogicalType::BOOLEAN);
448131 } else {
448132 update_types.push_back(column_data.type);
448133 }
448134 update_types.emplace_back(LogicalType::ROW_TYPE);
448135
448136 update_chunk = make_uniq<DataChunk>();
448137 update_chunk->Initialize(Allocator::DefaultAllocator(), update_types);
448138
448139 // fetch the updated values from the base segment
448140 info.segment->FetchCommitted(info.vector_index, update_chunk->data[0]);
448141
448142 // write the row ids into the chunk
448143 auto row_ids = FlatVector::GetData<row_t>(update_chunk->data[1]);
448144 idx_t start = info.row_group_start + info.vector_index * STANDARD_VECTOR_SIZE;
448145 auto tuples = info.GetTuples();
448146 for (idx_t i = 0; i < info.N; i++) {
448147 row_ids[tuples[i]] = UnsafeNumericCast<int64_t>(start + tuples[i]);
448148 }
448149 if (column_data.type.id() == LogicalTypeId::VALIDITY) {
448150 // zero-initialize the booleans
448151 // FIXME: this is only required because of NullValue<T> in Vector::Serialize...
448152 auto booleans = FlatVector::GetData<bool>(update_chunk->data[0]);
448153 for (idx_t i = 0; i < info.N; i++) {
448154 auto idx = tuples[i];
448155 booleans[idx] = false;
448156 }
448157 }
448158 SelectionVector sel(tuples);
448159 update_chunk->Slice(sel, info.N);
448160
448161 // construct the column index path
448162 vector<column_t> column_indexes;
448163 reference<const ColumnData> current_column_data = column_data;
448164 while (current_column_data.get().HasParent()) {
448165 column_indexes.push_back(current_column_data.get().column_index);
448166 current_column_data = current_column_data.get().Parent();
448167 }
448168 column_indexes.push_back(info.column_index);
448169 std::reverse(column_indexes.begin(), column_indexes.end());
448170
448171 log.WriteUpdate(*update_chunk, column_indexes);
448172}

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