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

Public Member Functions

 OptimisticDataWriter (ClientContext &context, DataTable &table)
 OptimisticDataWriter (DataTable &table, OptimisticDataWriter &parent)
unique_ptr< OptimisticWriteCollection > CreateCollection (DataTable &storage, const vector< LogicalType > &insert_types, OptimisticWritePartialManagers type=OptimisticWritePartialManagers::PER_COLUMN)
 Creates a collection to write to.
void WriteNewRowGroup (OptimisticWriteCollection &row_groups)
 Write a new row group to disk (if possible).
void WriteUnflushedRowGroups (OptimisticWriteCollection &row_groups)
 Write any unflushed row groups of a collection to disk.
void FinalFlush ()
 Final flush of the optimistic writer - fully flushes the partial block manager.
void Merge (OptimisticDataWriter &other)
 Merge the partially written blocks from one optimistic writer into another.
void Merge (unique_ptr< PartialBlockManager > &other_manager)
void Rollback ()
 Rollback.
ClientContext & GetClientContext ()
 Return the client context.

Private Member Functions

bool PrepareWrite ()
 Prepare a write to disk.
void FlushToDisk (OptimisticWriteCollection &collection, const vector< const_reference< RowGroup > > &row_groups, const vector< int64_t > &segment_indexes)
 Flushes a specific row group to disk.

Private Attributes

ClientContext & context
 The client context in which we're writing the data.
DataTable & table
 The table.
unique_ptr< PartialBlockManager > partial_manager
 The partial block manager, if any.

Constructor & Destructor Documentation

◆ OptimisticDataWriter() [1/2]

duckdb::OptimisticDataWriter::OptimisticDataWriter ( ClientContext & context,
DataTable & table )
415035 : context(context), table(table) {
415036}
DataTable & table
The table.
Definition duckdb.hpp:50759
ClientContext & context
The client context in which we're writing the data.
Definition duckdb.hpp:50757

◆ OptimisticDataWriter() [2/2]

duckdb::OptimisticDataWriter::OptimisticDataWriter ( DataTable & table,
OptimisticDataWriter & parent )
415039 : context(parent.GetClientContext()), table(table) {
415040 if (parent.partial_manager) {
415041 parent.partial_manager->ClearBlocks();
415042 }
415043}

◆ ~OptimisticDataWriter()

duckdb::OptimisticDataWriter::~OptimisticDataWriter ( )
415045 {
415046}

Member Function Documentation

◆ CreateCollection()

unique_ptr< OptimisticWriteCollection > duckdb::OptimisticDataWriter::CreateCollection ( DataTable & storage,
const vector< LogicalType > & insert_types,
OptimisticWritePartialManagers type = OptimisticWritePartialManagers::PER_COLUMN )

Creates a collection to write to.

415066 {
415067 auto table_info = storage.GetDataTableInfo();
415068 auto &io_manager = TableIOManager::Get(storage);
415069
415070 // Create the local row group collection.
415071 auto max_row_id = NumericCast<idx_t>(MAX_ROW_ID);
415072 auto row_groups = make_shared_ptr<RowGroupCollection>(std::move(table_info), io_manager, insert_types, max_row_id);
415073
415074 auto result = make_uniq<OptimisticWriteCollection>();
415075 result->collection = std::move(row_groups);
415076 if (type == OptimisticWritePartialManagers::PER_COLUMN) {
415077 for (idx_t i = 0; i < insert_types.size(); i++) {
415078 auto &block_manager = table.GetTableIOManager().GetBlockManagerForRowData();
415079 result->partial_block_managers.push_back(make_uniq<PartialBlockManager>(
415080 QueryContext(context), block_manager, PartialBlockType::APPEND_TO_TABLE));
415081 }
415082 }
415083 return result;
415084}
static TableIOManager & Get(DataTable &table)
Obtains a reference to the TableIOManager of a specific table.
Definition duckdb.cpp:411568
const row_t MAX_ROW_ID
The maximum row identifier used in tables.
Definition duckdb.cpp:50301
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:

◆ WriteNewRowGroup()

void duckdb::OptimisticDataWriter::WriteNewRowGroup ( OptimisticWriteCollection & row_groups)

Write a new row group to disk (if possible).

415086 {
415087 // we finished writing a complete row group
415088 if (!PrepareWrite()) {
415089 return;
415090 }
415091
415092 row_groups.unflushed_row_groups.insert(row_groups.complete_row_groups);
415093 row_groups.complete_row_groups++;
415094 auto unflushed_row_groups = row_groups.unflushed_row_groups.size();
415095 if (unflushed_row_groups >= Settings::Get<WriteBufferRowGroupCountSetting>(context)) {
415096 // we have crossed our flush threshold - flush any unwritten row groups to disk
415097 vector<const_reference<RowGroup>> to_flush;
415098 vector<int64_t> segment_indexes;
415099 for (auto &unflushed_idx : row_groups.unflushed_row_groups) {
415100 auto segment_index = NumericCast<int64_t>(unflushed_idx);
415101 to_flush.push_back(*row_groups.collection->GetRowGroup(segment_index));
415102 segment_indexes.push_back(segment_index);
415103 }
415104 FlushToDisk(row_groups, to_flush, segment_indexes);
415105 row_groups.unflushed_row_groups.clear();
415106 }
415107}
void FlushToDisk(OptimisticWriteCollection &collection, const vector< const_reference< RowGroup > > &row_groups, const vector< int64_t > &segment_indexes)
Flushes a specific row group to disk.
Definition duckdb.cpp:415176
bool PrepareWrite()
Prepare a write to disk.
Definition duckdb.cpp:415048
Here is the call graph for this function:

◆ WriteUnflushedRowGroups()

void duckdb::OptimisticDataWriter::WriteUnflushedRowGroups ( OptimisticWriteCollection & row_groups)

Write any unflushed row groups of a collection to disk.

415109 {
415110 // we finished writing a complete row group
415111 if (!PrepareWrite()) {
415112 return;
415113 }
415114 // add any incomplete row groups to the set of unflushed row groups
415115 auto total_row_groups = row_groups.collection->GetRowGroupCount();
415116 if (row_groups.complete_row_groups > total_row_groups) {
415117 throw InternalException("WriteUnflushedRowGroups - complete row groups > total_row_groups");
415118 }
415119 for (idx_t i = row_groups.complete_row_groups; i < total_row_groups; i++) {
415120 row_groups.unflushed_row_groups.insert(i);
415121 row_groups.complete_row_groups++;
415122 }
415123 if (!row_groups.unflushed_row_groups.empty()) {
415124 // flush the last batch of row groups
415125 vector<const_reference<RowGroup>> to_flush;
415126 vector<int64_t> segment_indexes;
415127 for (auto &unflushed_idx : row_groups.unflushed_row_groups) {
415128 auto segment_index = NumericCast<int64_t>(unflushed_idx);
415129 to_flush.push_back(*row_groups.collection->GetRowGroup(segment_index));
415130 segment_indexes.push_back(segment_index);
415131 }
415132
415133 FlushToDisk(row_groups, to_flush, segment_indexes);
415134 }
415135
415136 for (auto &partial_manager : row_groups.partial_block_managers) {
415138 }
415139 row_groups.unflushed_row_groups.clear();
415140 row_groups.partial_block_managers.clear();
415141}
unique_ptr< PartialBlockManager > partial_manager
The partial block manager, if any.
Definition duckdb.hpp:50761
void Merge(OptimisticDataWriter &other)
Merge the partially written blocks from one optimistic writer into another.
Definition duckdb.cpp:415205
Here is the call graph for this function:

◆ FinalFlush()

void duckdb::OptimisticDataWriter::FinalFlush ( )

Final flush of the optimistic writer - fully flushes the partial block manager.

415209 {
415210 if (partial_manager) {
415211 partial_manager->FlushPartialBlocks();
415212 partial_manager.reset();
415213 }
415214}

◆ Merge() [1/2]

void duckdb::OptimisticDataWriter::Merge ( OptimisticDataWriter & other)

Merge the partially written blocks from one optimistic writer into another.

415205 {
415206 Merge(other.partial_manager);
415207}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Merge() [2/2]

void duckdb::OptimisticDataWriter::Merge ( unique_ptr< PartialBlockManager > & other_manager)
415193 {
415194 if (!other_manager) {
415195 return;
415196 }
415197 if (!partial_manager) {
415198 partial_manager = std::move(other_manager);
415199 return;
415200 }
415201 partial_manager->Merge(*other_manager);
415202 other_manager.reset();
415203}

◆ Rollback()

void duckdb::OptimisticDataWriter::Rollback ( )

Rollback.

415216 {
415217 if (partial_manager) {
415218 partial_manager->Rollback();
415219 partial_manager.reset();
415220 }
415221}

◆ GetClientContext()

ClientContext & duckdb::OptimisticDataWriter::GetClientContext ( )
inline

Return the client context.

50744 {
50745 return context;
50746 }

◆ PrepareWrite()

bool duckdb::OptimisticDataWriter::PrepareWrite ( )
private

Prepare a write to disk.

415048 {
415049 // check if we should pre-emptively write the table to disk
415050 auto &attached = table.GetAttached();
415051 auto &storage_manager = StorageManager::Get(attached);
415052 if (table.IsTemporary() || storage_manager.InMemory() || attached.IsReadOnly()) {
415053 return false;
415054 }
415055 // we should! write the second-to-last row group to disk
415056 // allocate the partial block-manager if none is allocated yet
415057 if (!partial_manager) {
415058 auto &block_manager = table.GetTableIOManager().GetBlockManagerForRowData();
415059 partial_manager = make_uniq<PartialBlockManager>(context, block_manager, PartialBlockType::APPEND_TO_TABLE);
415060 }
415061 return true;
415062}
Here is the caller graph for this function:

◆ FlushToDisk()

void duckdb::OptimisticDataWriter::FlushToDisk ( OptimisticWriteCollection & collection,
const vector< const_reference< RowGroup > > & row_groups,
const vector< int64_t > & segment_indexes )
private

Flushes a specific row group to disk.

The set of column compression types (if any)

415178 {
415180 vector<CompressionType> compression_types;
415181 D_ASSERT(compression_types.empty());
415182 for (auto &column : table.Columns()) {
415183 compression_types.push_back(column.CompressionType());
415184 }
415185 RowGroupWriteInfo info(*partial_manager, compression_types, collection.partial_block_managers);
415186 auto result = RowGroup::WriteToDisk(info, row_groups);
415187 // move new (checkpointed) row groups to the row group collection
415188 for (idx_t i = 0; i < row_groups.size(); i++) {
415189 collection.collection->SetRowGroup(segment_indexes[i], std::move(result[i].result_row_group));
415190 }
415191}
Here is the caller graph for this function:

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