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

Public Types

using AsOfHashGroupPtr = unique_ptr<AsOfHashGroup>
using AsOfHashGroups = vector<AsOfHashGroupPtr>
using HashedSourceStatePtr = unique_ptr<GlobalSourceState>
using Task = AsOfSourceTask
using TaskPtr = optional_ptr<Task>
using PartitionBlock = std::pair<idx_t, idx_t>

Public Member Functions

 AsOfGlobalSourceState (ClientContext &client, const PhysicalAsOfJoin &op)
bool HasMoreTasks () const
 Are there any more tasks?
bool HasUnfinishedTasks () const
bool TryNextTask (TaskPtr &task, Task &task_local)
 Assign a new task to the local state.
idx_t MaxThreads () override
Public Member Functions inherited from duckdb::GlobalSourceState
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const
Public Member Functions inherited from duckdb::StateWithBlockableTasks
unique_lock< mutex > Lock ()
void PreventBlocking (const unique_lock< mutex > &guard)
bool BlockTask (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
 Add a task to 'blocked_tasks' before returning SourceResultType::BLOCKED (must hold the lock).
bool CanBlock (const unique_lock< mutex > &guard) const
bool UnblockTasks (const unique_lock< mutex > &guard)
 Unblock all tasks (must hold the lock).
SinkResultType BlockSink (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
SourceResultType BlockSource (const unique_lock< mutex > &guard, const InterruptState &interrupt_state)
void VerifyLock (const unique_lock< mutex > &guard) const

Public Attributes

const PhysicalAsOfJoin & op
 The parent operator.
vector< HashedSourceStatePtr > hashed_sources
 The source states for the hashed sort.
AsOfHashGroups asof_groups
 The hash groups.
vector< PartitionBlock > partition_blocks
 The sorted list of (blocks, group_idx) pairs.
vector< idx_t > active_groups
 The ordered set of active groups.
atomic< idx_t > next_group
 The next group to start.
idx_t total_tasks = 0
 The total number of tasks.
atomic< idx_t > started
 The number of started tasks.
atomic< idx_t > finished
 The number of tasks finished.
atomic< bool > stopped
 Stop producing tasks.

Protected Member Functions

void CreateTaskList (ClientContext &client)
 Build task list.
void FinishTask (TaskPtr task)
 Finish a task.

Constructor & Destructor Documentation

◆ AsOfGlobalSourceState()

duckdb::AsOfGlobalSourceState::AsOfGlobalSourceState ( ClientContext & client,
const PhysicalAsOfJoin & op )
182306 : op(op), next_group(0), started(0), finished(0), stopped(false) {
182307 // Take ownership of the hash groups
182308 auto &gsink = op.sink_state->Cast<AsOfGlobalSinkState>();
182309
182310 using ChunkRow = SortStrategy::ChunkRow;
182311 using ChunkRows = SortStrategy::ChunkRows;
182312 vector<ChunkRows> child_groups(2);
182313 for (idx_t child = 0; child < child_groups.size(); ++child) {
182314 auto &sort_strategy = *gsink.sort_strategies[child];
182315 auto &hashed_sink = *gsink.strategy_sinks[child];
182316 auto hashed_source = sort_strategy.GetGlobalSourceState(client, hashed_sink);
182317 child_groups[child] = sort_strategy.GetHashGroups(*hashed_source);
182318 hashed_sources.emplace_back(std::move(hashed_source));
182319 }
182320
182321 // Pivot into AsOfHashGroups
182322 auto &lhs_groups = child_groups[0];
182323 auto &rhs_groups = child_groups[1];
182324 const auto group_count = MaxValue<idx_t>(lhs_groups.size(), rhs_groups.size());
182325 for (idx_t group_idx = 0; group_idx < group_count; ++group_idx) {
182326 ChunkRow lhs_stats;
182327 if (group_idx < lhs_groups.size()) {
182328 lhs_stats = lhs_groups[group_idx];
182329 }
182330 ChunkRow rhs_stats;
182331 if (group_idx < rhs_groups.size()) {
182332 rhs_stats = rhs_groups[group_idx];
182333 }
182334 auto asof_group = make_uniq<AsOfHashGroup>(op, lhs_stats, rhs_stats, group_idx);
182335 asof_groups.emplace_back(std::move(asof_group));
182336 }
182337
182338 CreateTaskList(client);
182339}
atomic< bool > stopped
Stop producing tasks.
Definition duckdb.cpp:182291
const PhysicalAsOfJoin & op
The parent operator.
Definition duckdb.cpp:182273
vector< HashedSourceStatePtr > hashed_sources
The source states for the hashed sort.
Definition duckdb.cpp:182275
atomic< idx_t > started
The number of started tasks.
Definition duckdb.cpp:182287
AsOfHashGroups asof_groups
The hash groups.
Definition duckdb.cpp:182277
void CreateTaskList(ClientContext &client)
Build task list.
Definition duckdb.cpp:182341
atomic< idx_t > next_group
The next group to start.
Definition duckdb.cpp:182283
atomic< idx_t > finished
The number of tasks finished.
Definition duckdb.cpp:182289
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

Member Function Documentation

◆ HasMoreTasks()

bool duckdb::AsOfGlobalSourceState::HasMoreTasks ( ) const
inline

Are there any more tasks?

182262 {
182263 return !stopped && started < total_tasks;
182264 }
idx_t total_tasks
The total number of tasks.
Definition duckdb.cpp:182285
Here is the caller graph for this function:

◆ HasUnfinishedTasks()

bool duckdb::AsOfGlobalSourceState::HasUnfinishedTasks ( ) const
inline
182265 {
182266 return !stopped && finished < total_tasks;
182267 }

◆ TryNextTask()

bool duckdb::AsOfGlobalSourceState::TryNextTask ( TaskPtr & task,
Task & task_local )

Assign a new task to the local state.

183115 {
183116 auto guard = Lock();
183117 FinishTask(task);
183118
183119 if (!HasMoreTasks()) {
183120 task = nullptr;
183121 return false;
183122 }
183123
183124 // Run through the active groups looking for one that can assign a task
183125 for (const auto &group_idx : active_groups) {
183126 auto &asof_group = asof_groups[group_idx];
183127 if (asof_group->TryPrepareNextStage()) {
183128 UnblockTasks(guard);
183129 }
183130 if (asof_group->TryNextTask(task_local)) {
183131 task = task_local;
183132 ++started;
183133 return true;
183134 }
183135 }
183136
183137 // All active groups are busy or blocked, so start the next one (if any)
183138 while (next_group < partition_blocks.size()) {
183139 const auto group_idx = partition_blocks[next_group++].second;
183140 active_groups.emplace_back(group_idx);
183141
183142 auto &asof_group = asof_groups[group_idx];
183143 if (asof_group->TryPrepareNextStage()) {
183144 UnblockTasks(guard);
183145 }
183146 if (!asof_group->TryNextTask(task_local)) {
183147 // Group has no tasks (empty?)
183148 continue;
183149 }
183150
183151 task = task_local;
183152 ++started;
183153 return true;
183154 }
183155
183156 task = nullptr;
183157
183158 return false;
183159}
vector< PartitionBlock > partition_blocks
The sorted list of (blocks, group_idx) pairs.
Definition duckdb.cpp:182279
bool HasMoreTasks() const
Are there any more tasks?
Definition duckdb.cpp:182262
vector< idx_t > active_groups
The ordered set of active groups.
Definition duckdb.cpp:182281
void FinishTask(TaskPtr task)
Finish a task.
Definition duckdb.cpp:183046
bool UnblockTasks(const unique_lock< mutex > &guard)
Unblock all tasks (must hold the lock).
Definition duckdb.hpp:21906
Here is the call graph for this function:

◆ MaxThreads()

idx_t duckdb::AsOfGlobalSourceState::MaxThreads ( )
inlineoverridevirtual

Reimplemented from duckdb::GlobalSourceState.

182294 {
182295 return total_tasks;
182296 }

◆ CreateTaskList()

void duckdb::AsOfGlobalSourceState::CreateTaskList ( ClientContext & client)
protected

Build task list.

182341 {
182342 // Sort the groups from largest to smallest
182343 if (asof_groups.empty()) {
182344 return;
182345 }
182346
182347 // Count chunks, not rows (otherwise left and right raggedness could give the wrong answer
182348 for (idx_t group_idx = 0; group_idx < asof_groups.size(); ++group_idx) {
182349 auto &asof_hash_group = asof_groups[group_idx];
182350 if (!asof_hash_group) {
182351 continue;
182352 }
182353 partition_blocks.emplace_back(asof_hash_group->MaximumChunks(), group_idx);
182354 }
182355 std::sort(partition_blocks.begin(), partition_blocks.end(), std::greater<PartitionBlock>());
182356 const auto &max_block = partition_blocks.front();
182357
182358 // Schedule the largest group on as many threads as possible
182359 auto &ts = TaskScheduler::GetScheduler(client);
182360 const auto threads = NumericCast<idx_t>(ts.NumberOfThreads());
182361
182362 const auto per_thread = AsOfHashGroup::BinValue(max_block.first, threads);
182363 if (!per_thread) {
182364 throw InternalException("No blocks per AsOf thread! %ld threads, %ld groups, %ld blocks, %ld hash group",
182365 threads, partition_blocks.size(), max_block.first, max_block.second);
182366 }
182367
182368 for (const auto &b : partition_blocks) {
182369 total_tasks += asof_groups[b.second]->InitTasks(per_thread);
182370 }
182371}

◆ FinishTask()

void duckdb::AsOfGlobalSourceState::FinishTask ( TaskPtr task)
protected

Finish a task.

183046 {
183047 // Inside the lock
183048 if (!task) {
183049 return;
183050 }
183051
183052 ++finished;
183053
183054 const auto group_idx = task->group_idx;
183055 auto &finished_hash_group = asof_groups[group_idx];
183056 D_ASSERT(finished_hash_group);
183057
183058 if (finished_hash_group->FinishTask(*task)) {
183059 // Remove it from the active groups
183060 auto &v = active_groups;
183061 v.erase(std::remove(v.begin(), v.end(), group_idx), v.end());
183062 }
183063}
uint32_t v
Here is the caller graph for this function:

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