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

Public Member Functions

 BatchMemoryManager (ClientContext &context, idx_t initial_memory_request)
void SetMemorySize (idx_t size)
void IncreaseMemory ()
bool OutOfMemory (idx_t batch_index)
void UpdateMinBatchIndex (idx_t current_min_batch_index)
idx_t AvailableMemory () const
idx_t GetUnflushedMemory ()
void IncreaseUnflushedMemory (idx_t memory_increase)
void ReduceUnflushedMemory (idx_t memory_reduction)
bool IsMinimumBatchIndex (idx_t batch_index)
void FinalCheck ()
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

Private Attributes

ClientContext & context
unique_ptr< TemporaryMemoryState > memory_state
 Temporary memory state.
atomic< idx_t > unflushed_memory_usage
 Total memory usage of unflushed rows.
atomic< idx_t > min_batch_index
 Minimum batch size.
atomic< idx_t > available_memory
 The available memory for unflushed rows.
bool can_increase_memory
 Whether or not we can request additional memory.

Constructor & Destructor Documentation

◆ BatchMemoryManager()

duckdb::BatchMemoryManager::BatchMemoryManager ( ClientContext & context,
idx_t initial_memory_request )
inline
191734 : context(context), unflushed_memory_usage(0), min_batch_index(0), available_memory(0),
191735 can_increase_memory(true) {
191737 SetMemorySize(initial_memory_request);
191738 }
atomic< idx_t > min_batch_index
Minimum batch size.
Definition duckdb.cpp:191747
atomic< idx_t > unflushed_memory_usage
Total memory usage of unflushed rows.
Definition duckdb.cpp:191745
atomic< idx_t > available_memory
The available memory for unflushed rows.
Definition duckdb.cpp:191749
bool can_increase_memory
Whether or not we can request additional memory.
Definition duckdb.cpp:191751
unique_ptr< TemporaryMemoryState > memory_state
Temporary memory state.
Definition duckdb.cpp:191743
static TemporaryMemoryManager & Get(ClientContext &context)
Get the TemporaryMemoryManager.
Definition duckdb.cpp:443547
unique_ptr< TemporaryMemoryState > Register(ClientContext &context)
Register a TemporaryMemoryState.
Definition duckdb.cpp:443551

Member Function Documentation

◆ SetMemorySize()

void duckdb::BatchMemoryManager::SetMemorySize ( idx_t size)
inline
191754 {
191755 // request at most 1/4th of all available memory
191756 idx_t total_max_memory = BufferManager::GetBufferManager(context).GetQueryMaxMemory();
191757 idx_t request_cap = total_max_memory / 4;
191758
191759 size = MinValue<idx_t>(size, request_cap);
191760 if (size <= available_memory) {
191761 return;
191762 }
191763
191764 memory_state->SetRemainingSizeAndUpdateReservation(context, size);
191765 auto next_reservation = memory_state->GetReservation();
191766 if (available_memory >= next_reservation) {
191767 // we tried to ask for more memory but were declined
191768 // stop asking for more memory
191769 can_increase_memory = false;
191770 }
191771 available_memory = next_reservation;
191772 }
GOpaque< Size > size(const GMat &src)
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ IncreaseMemory()

void duckdb::BatchMemoryManager::IncreaseMemory ( )
inline
191774 {
191775 if (!can_increase_memory) {
191776 return;
191777 }
191778 SetMemorySize(available_memory * 2);
191779 }

◆ OutOfMemory()

bool duckdb::BatchMemoryManager::OutOfMemory ( idx_t batch_index)
inline
191781 {
191782#ifdef DUCKDB_ALTERNATIVE_VERIFY
191783 // alternative verify - always report that we are out of memory to test this code path
191784 return true;
191785#else
191787 auto guard = Lock();
191788 if (batch_index > min_batch_index) {
191789 // exceeded available memory and we are not the minimum batch index- try to increase it
191790 IncreaseMemory();
191792 // STILL out of memory
191793 return true;
191794 }
191795 }
191796 }
191797 return false;
191798#endif
191799 }

◆ UpdateMinBatchIndex()

void duckdb::BatchMemoryManager::UpdateMinBatchIndex ( idx_t current_min_batch_index)
inline
191801 {
191802 if (min_batch_index >= current_min_batch_index) {
191803 return;
191804 }
191805 auto guard = Lock();
191806 auto new_batch_index = MaxValue<idx_t>(min_batch_index, current_min_batch_index);
191807 if (new_batch_index != min_batch_index) {
191808 // new batch index! unblock all tasks
191809 min_batch_index = new_batch_index;
191810 UnblockTasks(guard);
191811 }
191812 }
bool UnblockTasks(const unique_lock< mutex > &guard)
Unblock all tasks (must hold the lock).
Definition duckdb.hpp:21906

◆ AvailableMemory()

idx_t duckdb::BatchMemoryManager::AvailableMemory ( ) const
inline
191814 {
191815 return available_memory;
191816 }

◆ GetUnflushedMemory()

idx_t duckdb::BatchMemoryManager::GetUnflushedMemory ( )
inline
191818 {
191819 return unflushed_memory_usage;
191820 }

◆ IncreaseUnflushedMemory()

void duckdb::BatchMemoryManager::IncreaseUnflushedMemory ( idx_t memory_increase)
inline
191822 {
191823 unflushed_memory_usage += memory_increase;
191824 }

◆ ReduceUnflushedMemory()

void duckdb::BatchMemoryManager::ReduceUnflushedMemory ( idx_t memory_reduction)
inline
191826 {
191827 if (unflushed_memory_usage < memory_reduction) {
191828 throw InternalException("Reducing unflushed memory usage below zero!?");
191829 } else {
191830 unflushed_memory_usage -= memory_reduction;
191831 }
191832 }

◆ IsMinimumBatchIndex()

bool duckdb::BatchMemoryManager::IsMinimumBatchIndex ( idx_t batch_index)
inline
191834 {
191835 return batch_index <= min_batch_index;
191836 }

◆ FinalCheck()

void duckdb::BatchMemoryManager::FinalCheck ( )
inline
191838 {
191839 if (unflushed_memory_usage != 0) {
191840 throw InternalException("Unflushed memory usage is not zero at finalize but %llu",
191841 unflushed_memory_usage.load());
191842 }
191843 }

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