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

Public Member Functions

 SimpleBufferedData (ClientContext &context)
void Append (const DataChunk &chunk)
void BlockSink (const InterruptState &blocked_sink)
bool BufferIsFull ()
void UnblockSinks () override
StreamExecutionResult ExecuteTaskInternal (StreamQueryResult &result, ClientContextLock &context_lock) override
unique_ptr< DataChunk > Scan () override
idx_t BufferSize () const
Public Member Functions inherited from duckdb::BufferedData
 BufferedData (Type type, ClientContext &context)
StreamExecutionResult ReplenishBuffer (StreamQueryResult &result, ClientContextLock &context_lock)
shared_ptr< ClientContext > GetContext ()
bool Closed () const
void Close ()
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Static Public Attributes

static constexpr const BufferedData::Type TYPE = BufferedData::Type::SIMPLE

Private Attributes

queue< InterruptState > blocked_sinks
 Our handles to reschedule the blocked sink tasks.
queue< unique_ptr< DataChunk > > buffered_chunks
 The queue of chunks.
atomic< idx_t > buffered_count
 The current capacity of the buffer (tuples).
idx_t buffer_size
 The amount of tuples we should buffer.

Additional Inherited Members

Protected Types inherited from duckdb::BufferedData
enum class  Type { SIMPLE , BATCHED }
Protected Attributes inherited from duckdb::BufferedData
Type type
weak_ptr< ClientContext > context
 This is weak to avoid a cyclical reference.
idx_t total_buffer_size
 The maximum amount of memory we should keep buffered.
mutex glock
 Protect against populate/fetch race condition.

Constructor & Destructor Documentation

◆ SimpleBufferedData()

duckdb::SimpleBufferedData::SimpleBufferedData ( ClientContext & context)
explicit
262666 : BufferedData(BufferedData::Type::SIMPLE, context) {
262667 buffered_count = 0;
262669}
idx_t total_buffer_size
The maximum amount of memory we should keep buffered.
Definition duckdb.hpp:41223
weak_ptr< ClientContext > context
This is weak to avoid a cyclical reference.
Definition duckdb.hpp:41221
atomic< idx_t > buffered_count
The current capacity of the buffer (tuples).
Definition duckdb.hpp:41265
idx_t buffer_size
The amount of tuples we should buffer.
Definition duckdb.hpp:41267

◆ ~SimpleBufferedData()

duckdb::SimpleBufferedData::~SimpleBufferedData ( )
override
262671 {
262672}

Member Function Documentation

◆ Append()

void duckdb::SimpleBufferedData::Append ( const DataChunk & chunk)
262771 {
262772 auto chunk = make_uniq<DataChunk>();
262773 chunk->Initialize(Allocator::DefaultAllocator(), to_append.GetTypes());
262774 to_append.Copy(*chunk, 0);
262775 auto allocation_size = chunk->GetAllocationSize();
262776
262777 unique_lock<mutex> lock(glock);
262778 buffered_count += allocation_size;
262779 buffered_chunks.push(std::move(chunk));
262780}
mutex glock
Protect against populate/fetch race condition.
Definition duckdb.hpp:41225
DUCKDB_API void Initialize(ClientContext &context, const vector< LogicalType > &types, idx_t capacity=STANDARD_VECTOR_SIZE)
Definition duckdb.cpp:116791
queue< unique_ptr< DataChunk > > buffered_chunks
The queue of chunks.
Definition duckdb.hpp:41263

◆ BlockSink()

void duckdb::SimpleBufferedData::BlockSink ( const InterruptState & blocked_sink)
262674 {
262675 lock_guard<mutex> lock(glock);
262676 blocked_sinks.push(blocked_sink);
262677}
queue< InterruptState > blocked_sinks
Our handles to reschedule the blocked sink tasks.
Definition duckdb.hpp:41261

◆ BufferIsFull()

bool duckdb::SimpleBufferedData::BufferIsFull ( )
262679 {
262680 return buffered_count >= BufferSize();
262681}

◆ UnblockSinks()

void duckdb::SimpleBufferedData::UnblockSinks ( )
overridevirtual

Implements duckdb::BufferedData.

262683 {
262684 auto cc = context.lock();
262685 if (!cc) {
262686 return;
262687 }
262688 (void)cc;
262689
262690 if (buffered_count >= BufferSize()) {
262691 return;
262692 }
262693 // Reschedule enough blocked sinks to populate the buffer
262694 lock_guard<mutex> lock(glock);
262695 while (!blocked_sinks.empty()) {
262696 auto &blocked_sink = blocked_sinks.front();
262697 if (buffered_count >= BufferSize()) {
262698 // We have unblocked enough sinks already
262699 break;
262700 }
262701 blocked_sink.Callback();
262702 blocked_sinks.pop();
262703 }
262704}

◆ ExecuteTaskInternal()

StreamExecutionResult duckdb::SimpleBufferedData::ExecuteTaskInternal ( StreamQueryResult & result,
ClientContextLock & context_lock )
overridevirtual

Implements duckdb::BufferedData.

262707 {
262708 auto cc = context.lock();
262709 if (!cc) {
262710 return StreamExecutionResult::EXECUTION_CANCELLED;
262711 }
262712 if (!cc->IsActiveResult(context_lock, result)) {
262713 return StreamExecutionResult::EXECUTION_CANCELLED;
262714 }
262715 // Check for interrupt even if the buffer is full.
262716 // Without this check, cancel requests would not be detected until the buffer is drained.
262717 if (cc->interrupted.load(std::memory_order_relaxed)) {
262718 throw InterruptException();
262719 }
262720 if (BufferIsFull()) {
262721 // The buffer isn't empty yet, just return
262722 return StreamExecutionResult::CHUNK_READY;
262723 }
262724 UnblockSinks();
262725 // Let the executor run until the buffer is no longer empty
262726 auto execution_result = cc->ExecuteTaskInternal(context_lock, result);
262727 if (buffered_count >= BufferSize()) {
262728 return StreamExecutionResult::CHUNK_READY;
262729 }
262730 if (execution_result == PendingExecutionResult::BLOCKED ||
262731 execution_result == PendingExecutionResult::RESULT_READY) {
262732 return StreamExecutionResult::BLOCKED;
262733 }
262734 if (result.HasError()) {
262735 Close();
262736 }
262737 switch (execution_result) {
262738 case PendingExecutionResult::NO_TASKS_AVAILABLE:
262739 case PendingExecutionResult::RESULT_NOT_READY:
262740 return StreamExecutionResult::CHUNK_NOT_READY;
262741 case PendingExecutionResult::EXECUTION_FINISHED:
262742 return StreamExecutionResult::EXECUTION_FINISHED;
262743 case PendingExecutionResult::EXECUTION_ERROR:
262744 return StreamExecutionResult::EXECUTION_ERROR;
262745 default:
262746 throw InternalException("No conversion from PendingExecutionResult (%s) -> StreamExecutionResult",
262747 EnumUtil::ToString(execution_result));
262748 }
262749}

◆ Scan()

unique_ptr< DataChunk > duckdb::SimpleBufferedData::Scan ( )
overridevirtual

Implements duckdb::BufferedData.

262751 {
262752 if (Closed()) {
262753 return nullptr;
262754 }
262755
262756 lock_guard<mutex> lock(glock);
262757 if (buffered_chunks.empty()) {
262758 Close();
262759 return nullptr;
262760 }
262761 auto chunk = std::move(buffered_chunks.front());
262762 buffered_chunks.pop();
262763
262764 if (chunk) {
262765 auto allocation_size = chunk->GetAllocationSize();
262766 buffered_count -= allocation_size;
262767 }
262768 return chunk;
262769}

◆ BufferSize()

idx_t duckdb::SimpleBufferedData::BufferSize ( ) const
inline
41255 {
41256 return buffer_size;
41257 }

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