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

Public Member Functions

 CommitState (DuckTransaction &transaction, transaction_t commit_id, ActiveTransactionState transaction_state, CommitMode commit_mode)
void CommitEntry (UndoFlags type, data_ptr_t data)
void RevertCommit (UndoFlags type, data_ptr_t data)
void Flush ()
void Verify ()

Static Public Member Functions

static IndexRemovalType GetIndexRemovalType (ActiveTransactionState transaction_state, CommitMode commit_mode)

Private Member Functions

void CommitEntryDrop (CatalogEntry &entry, data_ptr_t extra_data)
void CommitDelete (DeleteInfo &info)

Private Attributes

DuckTransaction & transaction
transaction_t commit_id
IndexDataRemover index_data_remover

Constructor & Destructor Documentation

◆ CommitState()

duckdb::CommitState::CommitState ( DuckTransaction & transaction,
transaction_t commit_id,
ActiveTransactionState transaction_state,
CommitMode commit_mode )
explicit
445852 : transaction(transaction_p), commit_id(commit_id),
445853 index_data_remover(transaction, *transaction.context.lock(),
445854 GetIndexRemovalType(transaction_state, commit_mode)) {
445855}

Member Function Documentation

◆ CommitEntry()

void duckdb::CommitState::CommitEntry ( UndoFlags type,
data_ptr_t data )
445981 {
445982 switch (type) {
445983 case UndoFlags::CATALOG_ENTRY: {
445984 auto &old_entry = *Load<CatalogEntry *>(data);
445985 D_ASSERT(old_entry.HasParent());
445986
445987 auto &catalog = old_entry.ParentCatalog();
445988 D_ASSERT(catalog.IsDuckCatalog());
445989
445990 auto &new_entry = old_entry.Parent();
445991 if (new_entry.type == CatalogType::DEPENDENCY_ENTRY) {
445992 auto &dep = new_entry.Cast<DependencyEntry>();
445993 if (dep.Side() == DependencyEntryType::SUBJECT) {
445994 new_entry.set->VerifyExistenceOfDependency(commit_id, new_entry);
445995 }
445996 } else if (new_entry.type == CatalogType::DELETED_ENTRY && old_entry.set) {
445997 old_entry.set->CommitDrop(commit_id, transaction.start_time, old_entry);
445998 }
445999 // Grab a write lock on the catalog
446000 auto &duck_catalog = catalog.Cast<DuckCatalog>();
446001 lock_guard<mutex> write_lock(duck_catalog.GetWriteLock());
446002 lock_guard<mutex> read_lock(old_entry.set->GetCatalogLock());
446003 // Set the timestamp of the catalog entry to the given commit_id, marking it as committed
446004 CatalogSet::UpdateTimestamp(old_entry.Parent(), commit_id);
446005
446006 // drop any blocks associated with the catalog entry if possible (e.g. in case of a DROP or ALTER)
446007 CommitEntryDrop(old_entry, data + sizeof(CatalogEntry *));
446008 break;
446009 }
446010 case UndoFlags::INSERT_TUPLE: {
446011 // append:
446012 auto info = reinterpret_cast<AppendInfo *>(data);
446013 if (!info->table->IsMainTable()) {
446014 auto table_name = info->table->GetTableName();
446015 auto table_modification = info->table->TableModification();
446016 throw TransactionException("Attempting to modify table %s but another transaction has %s this table",
446017 table_name, table_modification);
446018 }
446019 // mark the tuples as committed
446020 info->table->CommitAppend(commit_id, info->start_row, info->count);
446021 break;
446022 }
446023 case UndoFlags::DELETE_TUPLE: {
446024 // deletion:
446025 auto info = reinterpret_cast<DeleteInfo *>(data);
446026 if (!info->table->IsMainTable()) {
446027 auto table_name = info->table->GetTableName();
446028 auto table_modification = info->table->TableModification();
446029 throw TransactionException("Attempting to modify table %s but another transaction has %s this table",
446030 table_name, table_modification);
446031 }
446032 CommitDelete(*info);
446033 break;
446034 }
446035 case UndoFlags::UPDATE_TUPLE: {
446036 // update:
446037 auto info = reinterpret_cast<UpdateInfo *>(data);
446038 if (!info->table->IsMainTable()) {
446039 auto table_name = info->table->GetTableName();
446040 auto table_modification = info->table->TableModification();
446041 throw TransactionException("Attempting to modify table %s but another transaction has %s this table",
446042 table_name, table_modification);
446043 }
446044 info->version_number = commit_id;
446045 break;
446046 }
446047 case UndoFlags::ATTACHED_DATABASE:
446048 case UndoFlags::SEQUENCE_VALUE: {
446049 break;
446050 }
446051 default:
446052 throw InternalException("UndoBuffer - don't know how to commit this type!");
446053 }
446054}

◆ RevertCommit()

void duckdb::CommitState::RevertCommit ( UndoFlags type,
data_ptr_t data )
446063 {
446064 transaction_t transaction_id = commit_id;
446065 switch (type) {
446066 case UndoFlags::CATALOG_ENTRY: {
446067 // set the commit timestamp of the catalog entry to the given id
446068 auto catalog_entry = Load<CatalogEntry *>(data);
446069 D_ASSERT(catalog_entry->HasParent());
446070 CatalogSet::UpdateTimestamp(catalog_entry->Parent(), transaction_id);
446071 if (catalog_entry->name != catalog_entry->Parent().name) {
446072 CatalogSet::UpdateTimestamp(*catalog_entry, transaction_id);
446073 }
446074 break;
446075 }
446076 case UndoFlags::INSERT_TUPLE: {
446077 auto info = reinterpret_cast<AppendInfo *>(data);
446078 // revert this append
446079 info->table->RevertAppend(transaction, info->start_row, info->count);
446080 break;
446081 }
446082 case UndoFlags::DELETE_TUPLE: {
446083 // deletion:
446084 auto info = reinterpret_cast<DeleteInfo *>(data);
446085 // revert the commit by writing the (uncommitted) transaction_id back into the version info
446086 CommitDelete(*info);
446087 break;
446088 }
446089 case UndoFlags::UPDATE_TUPLE: {
446090 // update:
446091 auto info = reinterpret_cast<UpdateInfo *>(data);
446092 info->version_number = transaction_id;
446093 break;
446094 }
446095 case UndoFlags::ATTACHED_DATABASE:
446096 case UndoFlags::SEQUENCE_VALUE: {
446097 break;
446098 }
446099 default:
446100 throw InternalException("UndoBuffer - don't know how to revert commit of this type!");
446101 }
446102}
idx_t transaction_t
Type used for transaction timestamps.
Definition duckdb.hpp:253

◆ Verify()

void duckdb::CommitState::Verify ( )
445816 {
445817 index_data_remover.Verify();
445818}

◆ GetIndexRemovalType()

IndexRemovalType duckdb::CommitState::GetIndexRemovalType ( ActiveTransactionState transaction_state,
CommitMode commit_mode )
static
445857 {
445858 if (commit_mode == CommitMode::COMMIT) {
445859 if (transaction_state == ActiveTransactionState::NO_OTHER_TRANSACTIONS) {
445860 // if there are no other active transactions we don't need to store removed rows in deleted_rows_in_use
445862 }
445864 }
445865 // revert the appends to the indexes
445866 if (transaction_state == ActiveTransactionState::NO_OTHER_TRANSACTIONS) {
445868 }
445870}
@ MAIN_INDEX
Remove from main index, insert into deleted_rows_in_use.
Definition duckdb.hpp:50446
@ MAIN_INDEX_ONLY
Remove from main index only.
Definition duckdb.hpp:50448
@ REVERT_MAIN_INDEX_ONLY
Revert MAIN_INDEX_ONLY, i.e. append to main index.
Definition duckdb.hpp:50452
@ REVERT_MAIN_INDEX
Revert MAIN_INDEX, i.e. append to main index and remove from deleted_rows_in_use.
Definition duckdb.hpp:50450

◆ CommitEntryDrop()

void duckdb::CommitState::CommitEntryDrop ( CatalogEntry & entry,
data_ptr_t extra_data )
private
445872 {
445873 if (entry.temporary || entry.Parent().temporary) {
445874 return;
445875 }
445876
445877 // look at the type of the parent entry
445878 auto &parent = entry.Parent();
445879
445880 switch (parent.type) {
445881 case CatalogType::TABLE_ENTRY:
445882 case CatalogType::VIEW_ENTRY:
445883 case CatalogType::INDEX_ENTRY:
445884 case CatalogType::SEQUENCE_ENTRY:
445885 case CatalogType::TYPE_ENTRY:
445886 case CatalogType::MACRO_ENTRY:
445887 case CatalogType::TABLE_MACRO_ENTRY:
445888 if (entry.type == CatalogType::RENAMED_ENTRY || entry.type == parent.type) {
445889 // ALTER statement, read the extra data after the entry
445890 auto extra_data_size = Load<idx_t>(dataptr);
445891 auto extra_data = data_ptr_cast(dataptr + sizeof(idx_t));
445892
445893 MemoryStream source(extra_data, extra_data_size);
445894 BinaryDeserializer deserializer(source);
445895 deserializer.Begin();
445896 auto column_name = deserializer.ReadProperty<string>(100, "column_name");
445897 auto parse_info = deserializer.ReadProperty<unique_ptr<ParseInfo>>(101, "alter_info");
445898 deserializer.End();
445899
445900 switch (parent.type) {
445901 case CatalogType::TABLE_ENTRY:
445902 if (!column_name.empty()) {
445903 D_ASSERT(entry.type != CatalogType::RENAMED_ENTRY);
445904 auto &table_entry = entry.Cast<DuckTableEntry>();
445905 D_ASSERT(table_entry.IsDuckTable());
445906 // write the alter table in the log
445907 table_entry.CommitAlter(column_name);
445908 }
445909 break;
445910 case CatalogType::VIEW_ENTRY:
445911 case CatalogType::INDEX_ENTRY:
445912 case CatalogType::SEQUENCE_ENTRY:
445913 case CatalogType::TYPE_ENTRY:
445914 case CatalogType::MACRO_ENTRY:
445915 case CatalogType::TABLE_MACRO_ENTRY:
445916 (void)column_name;
445917 break;
445918 default:
445919 throw InternalException("Don't know how to alter this type!");
445920 }
445921 } else {
445922 switch (parent.type) {
445923 case CatalogType::TABLE_ENTRY:
445924 case CatalogType::VIEW_ENTRY:
445925 case CatalogType::INDEX_ENTRY:
445926 case CatalogType::SEQUENCE_ENTRY:
445927 case CatalogType::TYPE_ENTRY:
445928 case CatalogType::MACRO_ENTRY:
445929 case CatalogType::TABLE_MACRO_ENTRY:
445930 break;
445931 default:
445932 throw InternalException("Don't know how to create this type!");
445933 }
445934 }
445935 break;
445936 case CatalogType::SCHEMA_ENTRY:
445937 break;
445938 case CatalogType::RENAMED_ENTRY:
445939 // This is a rename, nothing needs to be done for this
445940 break;
445941 case CatalogType::DELETED_ENTRY:
445942 switch (entry.type) {
445943 case CatalogType::TABLE_ENTRY: {
445944 auto &table_entry = entry.Cast<DuckTableEntry>();
445945 D_ASSERT(table_entry.IsDuckTable());
445946
445947 // If the table was renamed, we do not need to drop the DataTable.
445948 table_entry.CommitDrop();
445949 break;
445950 }
445951 case CatalogType::INDEX_ENTRY: {
445952 auto &index_entry = entry.Cast<DuckIndexEntry>();
445953 index_entry.CommitDrop();
445954 break;
445955 }
445956 default:
445957 // no action required
445958 break;
445959 }
445960 break;
445961 case CatalogType::DATABASE_ENTRY:
445962 case CatalogType::PREPARED_STATEMENT:
445963 case CatalogType::AGGREGATE_FUNCTION_ENTRY:
445964 case CatalogType::SCALAR_FUNCTION_ENTRY:
445965 case CatalogType::TABLE_FUNCTION_ENTRY:
445966 case CatalogType::COPY_FUNCTION_ENTRY:
445967 case CatalogType::PRAGMA_FUNCTION_ENTRY:
445968 case CatalogType::COLLATION_ENTRY:
445969 case CatalogType::COORDINATE_SYSTEM_ENTRY:
445970 case CatalogType::DEPENDENCY_ENTRY:
445971 case CatalogType::SECRET_ENTRY:
445972 case CatalogType::SECRET_TYPE_ENTRY:
445973 case CatalogType::SECRET_FUNCTION_ENTRY:
445974 // do nothing, these entries are not persisted to disk
445975 break;
445976 default:
445977 throw InternalException("UndoBuffer - don't know how to write this entry to the WAL");
445978 }
445979}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ CommitDelete()

void duckdb::CommitState::CommitDelete ( DeleteInfo & info)
private
446056 {
446057 // mark the tuples as committed
446058 info.version_info->CommitDelete(info.vector_idx, commit_id, info);
446059 // delete from indexes
446060 index_data_remover.PushDelete(info);
446061}

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