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

Public Member Functions

 SortGlobalSinkState (ClientContext &context)
void UpdateLocalState (SortLocalSinkState &lstate) const
void TryIncreaseReservation (ClientContext &context, SortLocalSinkState &lstate, bool is_index_sort, const unique_lock< mutex > &guard)
void AddSortedRun (SortLocalSinkState &lstate)
Public Member Functions inherited from duckdb::GlobalSinkState
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const
virtual idx_t MaxThreads (idx_t source_max_threads)
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 idx_t num_threads
 Total number of threads.
unique_ptr< TemporaryMemoryState > temporary_memory_state
 Temporary memory state for managing this sort's memory usage.
vector< unique_ptr< SortedRun > > sorted_runs
 Runs that have been sorted locally before being appended to this global state.
atomic< idx_t > sorted_tuples
 Sorted tuple count (for progress).
bool external
 Whether this is an external sort.
bool any_combined
 Whether any thread has called Combine yet.
idx_t total_count
 Total count (for the source phase).
idx_t partition_size
 Partition size (for the source phase).
Public Attributes inherited from duckdb::GlobalSinkState
SinkFinalizeType state

Constructor & Destructor Documentation

◆ SortGlobalSinkState()

duckdb::SortGlobalSinkState::SortGlobalSinkState ( ClientContext & context)
inlineexplicit
103264 : num_threads(NumericCast<idx_t>(TaskScheduler::GetScheduler(context).NumberOfThreads())),
103265 temporary_memory_state(TemporaryMemoryManager::Get(context).Register(context)), sorted_tuples(0),
103266 external(ClientConfig::GetConfig(context).force_external), any_combined(false), total_count(0),
103267 partition_size(0) {
103268 }
bool external
Whether this is an external sort.
Definition duckdb.cpp:103327
unique_ptr< TemporaryMemoryState > temporary_memory_state
Temporary memory state for managing this sort's memory usage.
Definition duckdb.cpp:103320
const idx_t num_threads
Total number of threads.
Definition duckdb.cpp:103318
idx_t total_count
Total count (for the source phase).
Definition duckdb.cpp:103332
bool any_combined
Whether any thread has called Combine yet.
Definition duckdb.cpp:103329
atomic< idx_t > sorted_tuples
Sorted tuple count (for progress).
Definition duckdb.cpp:103324
idx_t partition_size
Partition size (for the source phase).
Definition duckdb.cpp:103334
static TemporaryMemoryManager & Get(ClientContext &context)
Get the TemporaryMemoryManager.
Definition duckdb.cpp:443547

Member Function Documentation

◆ UpdateLocalState()

void duckdb::SortGlobalSinkState::UpdateLocalState ( SortLocalSinkState & lstate) const
inline
103271 {
103272 lstate.maximum_run_size = temporary_memory_state->GetReservation() / num_threads;
103273 lstate.external = external;
103274 }

◆ TryIncreaseReservation()

void duckdb::SortGlobalSinkState::TryIncreaseReservation ( ClientContext & context,
SortLocalSinkState & lstate,
bool is_index_sort,
const unique_lock< mutex > & guard )
inline
103277 {
103278 VerifyLock(guard);
103279 D_ASSERT(!external);
103280
103281 // If we already got less than we requested last time, have to go external
103282 if (temporary_memory_state->GetReservation() < temporary_memory_state->GetRemainingSize()) {
103283 if (!any_combined) {
103284 external = true;
103285 }
103286 return;
103287 }
103288
103289 // Double until it fits
103290 auto required = num_threads * lstate.sorted_run->SizeInBytes();
103291 if (is_index_sort) {
103292 required *= 4; // Index creation is pretty intense, so we are very conservative here
103293 }
103294 auto request = temporary_memory_state->GetRemainingSize() * 2;
103295 while (request < required) {
103296 request *= 2;
103297 }
103298
103299 // Send the request
103300 temporary_memory_state->SetRemainingSizeAndUpdateReservation(context, request);
103301
103302 // If we got less than we required, we have to go external
103303 if (temporary_memory_state->GetReservation() < required) {
103304 if (!any_combined) {
103305 external = true;
103306 }
103307 }
103308 }

◆ AddSortedRun()

void duckdb::SortGlobalSinkState::AddSortedRun ( SortLocalSinkState & lstate)
inline
103310 {
103311 auto guard = Lock();
103312 sorted_runs.push_back(std::move(lstate.sorted_run));
103313 sorted_tuples += sorted_runs.back()->Count();
103314 }
vector< unique_ptr< SortedRun > > sorted_runs
Runs that have been sorted locally before being appended to this global state.
Definition duckdb.cpp:103322

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