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

Public Member Functions

 VacuumTask (CollectionCheckpointState &checkpoint_state, VacuumState &vacuum_state, idx_t segment_idx, idx_t merge_count, idx_t target_count, idx_t merge_rows)
void ExecuteTask () override
string TaskType () const override
Public Member Functions inherited from duckdb::BaseCheckpointTask
 BaseCheckpointTask (CollectionCheckpointState &checkpoint_state)
Public Member Functions inherited from duckdb::BaseExecutorTask
 BaseExecutorTask (TaskExecutor &executor)
TaskExecutionResult Execute (TaskExecutionMode mode) override
Public Member Functions inherited from duckdb::Task
virtual void Deschedule ()
virtual void Reschedule ()
 Ensures a task is rescheduled to the correct queue.
virtual bool TaskBlockedOnResult () const
Public Member Functions inherited from duckdb::enable_shared_from_this< Task >
shared_ptr< Task > shared_from_this ()

Private Attributes

VacuumState & vacuum_state
idx_t segment_idx
idx_t merge_count
idx_t target_count
idx_t merge_rows

Additional Inherited Members

Public Attributes inherited from duckdb::Task
optional_ptr< ProducerToken > token
Protected Member Functions inherited from duckdb::enable_shared_from_this< Task >
enable_shared_from_this & operator= (enable_shared_from_this const &) noexcept
Protected Attributes inherited from duckdb::BaseCheckpointTask
CollectionCheckpointState & checkpoint_state
Protected Attributes inherited from duckdb::BaseExecutorTask
TaskExecutor & executor

Constructor & Destructor Documentation

◆ VacuumTask()

duckdb::VacuumTask::VacuumTask ( CollectionCheckpointState & checkpoint_state,
VacuumState & vacuum_state,
idx_t segment_idx,
idx_t merge_count,
idx_t target_count,
idx_t merge_rows )
inline
435654 : BaseCheckpointTask(checkpoint_state), vacuum_state(vacuum_state), segment_idx(segment_idx),
435655 merge_count(merge_count), target_count(target_count), merge_rows(merge_rows) {
435656 }

Member Function Documentation

◆ ExecuteTask()

void duckdb::VacuumTask::ExecuteTask ( )
inlineoverridevirtual

Implements duckdb::BaseExecutorTask.

435658 {
435659 auto &collection = checkpoint_state.collection;
435660 const idx_t row_group_size = collection.GetRowGroupSize();
435661 auto &types = collection.GetTypes();
435662 // create the new set of target row groups (initially empty)
435663 vector<unique_ptr<RowGroup>> new_row_groups;
435664 vector<idx_t> append_counts;
435665 idx_t row_group_rows = merge_rows;
435666 for (idx_t target_idx = 0; target_idx < target_count; target_idx++) {
435667 idx_t current_row_group_rows = MinValue<idx_t>(row_group_rows, row_group_size);
435668 auto new_row_group = make_uniq<RowGroup>(collection, current_row_group_rows);
435669 new_row_group->InitializeEmpty(types, ColumnDataType::MAIN_TABLE);
435670 new_row_groups.push_back(std::move(new_row_group));
435671 append_counts.push_back(0);
435672
435673 row_group_rows -= current_row_group_rows;
435674 }
435675
435676 DataChunk scan_chunk;
435677 scan_chunk.Initialize(Allocator::DefaultAllocator(), types);
435678
435679 vector<StorageIndex> column_ids;
435680 for (idx_t c = 0; c < types.size(); c++) {
435681 column_ids.emplace_back(c);
435682 }
435683
435684 idx_t current_append_idx = 0;
435685
435686 // fill the new row group with the merged rows
435687 TableAppendState append_state;
435688 new_row_groups[current_append_idx]->InitializeAppend(append_state.row_group_append_state);
435689
435690 TableScanState scan_state;
435691 scan_state.Initialize(column_ids);
435692 scan_state.table_state.Initialize(QueryContext(), types);
435693 scan_state.table_state.max_row = idx_t(-1);
435694 idx_t merged_groups = 0;
435695 idx_t total_row_groups = vacuum_state.row_group_counts.size();
435696 optional_idx row_start;
435697 for (idx_t c_idx = segment_idx; merged_groups < merge_count && c_idx < total_row_groups; c_idx++) {
435698 if (vacuum_state.row_group_counts[c_idx] == 0) {
435699 continue;
435700 }
435701 merged_groups++;
435702
435703 auto current_segment = checkpoint_state.GetSegment(c_idx);
435704 if (!row_start.IsValid()) {
435705 row_start = current_segment->GetRowStart();
435706 }
435707 auto &current_row_group = current_segment->GetNode();
435708
435709 current_row_group.InitializeScan(scan_state.table_state, *current_segment);
435710 while (true) {
435711 scan_chunk.Reset();
435712
435713 current_row_group.Scan(scan_state.table_state, scan_chunk, TableScanType::TABLE_SCAN_COMMITTED_ROWS);
435714 if (scan_chunk.size() == 0) {
435715 break;
435716 }
435717 scan_chunk.Flatten();
435718 idx_t remaining = scan_chunk.size();
435719 while (remaining > 0) {
435720 idx_t append_count = MinValue<idx_t>(remaining, row_group_size - append_counts[current_append_idx]);
435721 new_row_groups[current_append_idx]->Append(append_state.row_group_append_state, scan_chunk,
435722 append_count);
435723 append_counts[current_append_idx] += append_count;
435724 remaining -= append_count;
435725 const bool row_group_full = append_counts[current_append_idx] == row_group_size;
435726 const bool last_row_group = current_append_idx + 1 >= new_row_groups.size();
435727 if (remaining > 0 || (row_group_full && !last_row_group)) {
435728 // move to the next row group
435729 current_append_idx++;
435730 new_row_groups[current_append_idx]->InitializeAppend(append_state.row_group_append_state);
435731 // slice chunk for the next append
435732 scan_chunk.Slice(append_count, remaining);
435733 }
435734 }
435735 }
435736 // drop the row group after merging
435737 current_row_group.CommitDrop();
435738 checkpoint_state.DropSegment(c_idx);
435739 }
435740 idx_t total_append_count = 0;
435741 for (idx_t target_idx = 0; target_idx < target_count; target_idx++) {
435742 auto &row_group = new_row_groups[target_idx];
435743 row_group->Verify();
435744
435745 // assign the new row group to the current segment
435746 checkpoint_state.SetSegment(row_start.GetIndex() + total_append_count, segment_idx + target_idx,
435747 std::move(row_group));
435748 total_append_count += append_counts[target_idx];
435749 }
435750 if (total_append_count != merge_rows) {
435751 throw InternalException(
435752 "Mismatch in row group count %d vs verify count %d in RowGroupCollection::Checkpoint", merge_rows,
435753 total_append_count);
435754 }
435755 // merging is complete - execute checkpoint tasks of the target row groups
435756 for (idx_t i = 0; i < target_count; i++) {
435757 auto checkpoint_task = collection.GetCheckpointTask(checkpoint_state, segment_idx + i);
435758 if (!checkpoint_task) {
435759 throw InternalException("Failed to get checkpoint task for row group we just merged");
435760 }
435761 checkpoint_task->ExecuteTask();
435762 }
435763 }
DUCKDB_API void Reset()
Definition duckdb.cpp:116840
DUCKDB_API void Initialize(ClientContext &context, const vector< LogicalType > &types, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:116791
DUCKDB_API void Flatten()
Turn all the vectors from the chunk into flat vectors.
Definition duckdb.cpp:116989
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
@ TABLE_SCAN_COMMITTED_ROWS
Scan the latest committed rows.
Definition duckdb.hpp:22678

◆ TaskType()

string duckdb::VacuumTask::TaskType ( ) const
inlineoverridevirtual

Reimplemented from duckdb::Task.

435765 {
435766 return "VacuumTask";
435767 }

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