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::BufferingLogStorage Class Referenceabstract

The buffering Log storage implements a buffering mechanism around the Base LogStorage class. It implements some general features that most log storages will need. More...

#include <duckdb.hpp>

Inheritance diagram for duckdb::BufferingLogStorage:
Collaboration diagram for duckdb::BufferingLogStorage:

Public Member Functions

 BufferingLogStorage (DatabaseInstance &db_p, idx_t buffer_size, bool normalize)
void WriteLogEntry (timestamp_t timestamp, LogLevel level, const string &log_type, const string &log_message, const RegisteredLoggingContext &context) final
 (Partially) Implements LogStorage API
void WriteLogEntries (DataChunk &chunk, const RegisteredLoggingContext &context) final
 Write out the chunk to the buffers.
void FlushAll () final
 Flushes buffers for all tables.
void Flush (LoggingTargetTable table) final
 Flushes buffer for a specific table.
void Truncate () override
 Truncates log storage: both buffers and persistent storage (if applicable).
void UpdateConfig (DatabaseInstance &db, case_insensitive_map_t< Value > &config) override
 Apply a new log storage configuration.
bool IsEnabled (LoggingTargetTable table) override
 Returns whether the table is enabled for this storage.
Public Member Functions inherited from duckdb::LogStorage
virtual const string GetStorageName ()=0
virtual DUCKDB_API bool CanScan (LoggingTargetTable table)
 READING (OPTIONAL).
virtual DUCKDB_API unique_ptr< LogStorageScanState > CreateScanState (LoggingTargetTable table) const
virtual DUCKDB_API bool Scan (LogStorageScanState &state, DataChunk &result) const
virtual DUCKDB_API void InitializeScan (LogStorageScanState &state) const
virtual DUCKDB_API unique_ptr< TableRef > BindReplace (ClientContext &context, TableFunctionBindInput &input, LoggingTargetTable table)

Protected Member Functions

virtual void FlushChunk (LoggingTargetTable table, DataChunk &chunk)=0
 Interface to child classes.
virtual void UpdateConfigInternal (DatabaseInstance &db, case_insensitive_map_t< Value > &config)
 This method is called in a chained way down the class hierarchy. This allows each class to interpret its own part of the config. Unhandled config values that are left over will result in an error.
virtual void ResetAllBuffers ()
 ResetAllBuffers will clear all buffered data. To be overridden by child classes to ensure their buffers are flushed too.
void FlushAllInternal ()
 Helper methods.
void FlushInternal (LoggingTargetTable table)
 Flushes one of the tables.
bool IsEnabledInternal (LoggingTargetTable table)
 Whether a specific table is available in the log storage.
idx_t GetBufferLimit () const

Protected Attributes

mutex lock
 lock to be used by this class and child classes to ensure thread safety TODO: maybe remove and delegate thread-safety to LogManager?
bool normalize_contexts = true
 Switches between using false = use LoggingTargetTable::ALL_LOGS, true = use LoggingTargetTable::LOG_ENTIRES + LoggingTargetTable::CONTEXTS.

Private Member Functions

void ResetLogBuffers ()
 Resets the log buffers.
void WriteLoggingContext (const RegisteredLoggingContext &context)
 Write out a logging context.

Private Attributes

unordered_set< idx_t > registered_contexts
 The currently registered RegisteredLoggingContext's.
idx_t buffer_limit = 0
 Configuration for buffering.
bool only_flush_on_full_buffer = false
 Debug option for testing buffering behaviour.
map< LoggingTargetTable, unique_ptr< DataChunk > > buffers
 The buffers used for each table.
bool flush_contexts_on_next_entry_flush = false
 This flag is set whenever a new context_is written to the entry buffer. It means that the next flush of LoggingTargetTable::LOG_ENTRIES also requires a flush of LoggingTargetTable::LOG_CONTEXTS.

Additional Inherited Members

Static Public Member Functions inherited from duckdb::LogStorage
static vector< LogicalType > GetSchema (LoggingTargetTable table)
static vector< string > GetColumnNames (LoggingTargetTable table)

Detailed Description

The buffering Log storage implements a buffering mechanism around the Base LogStorage class. It implements some general features that most log storages will need.

Constructor & Destructor Documentation

◆ BufferingLogStorage()

duckdb::BufferingLogStorage::BufferingLogStorage ( DatabaseInstance & db_p,
idx_t buffer_size,
bool normalize )
explicit
260434 : normalize_contexts(normalize), buffer_limit(buffer_size) {
260435 ResetLogBuffers();
260436}
void ResetLogBuffers()
Resets the log buffers.
Definition duckdb.cpp:260438
idx_t buffer_limit
Configuration for buffering.
Definition duckdb.hpp:39606
bool normalize_contexts
Switches between using false = use LoggingTargetTable::ALL_LOGS, true = use LoggingTargetTable::LOG_E...
Definition duckdb.hpp:39595

◆ ~BufferingLogStorage()

duckdb::BufferingLogStorage::~BufferingLogStorage ( )
override
260490 {
260491}

Member Function Documentation

◆ WriteLogEntry()

void duckdb::BufferingLogStorage::WriteLogEntry ( timestamp_t timestamp,
LogLevel level,
const string & log_type,
const string & log_message,
const RegisteredLoggingContext & context )
finalvirtual

(Partially) Implements LogStorage API

Write out the entry to the buffers

Implements duckdb::LogStorage.

260532 {
260533 unique_lock<mutex> lck(lock);
260534
260535 auto &log_entries_buffer =
260536 normalize_contexts ? buffers[LoggingTargetTable::LOG_ENTRIES] : buffers[LoggingTargetTable::ALL_LOGS];
260537
260538 auto size = log_entries_buffer->size();
260539 if (size >= buffer_limit && buffer_limit != 0) {
260540 throw InternalException("Log buffer limit exceeded: code should have flushed before");
260541 }
260542
260543 if (registered_contexts.find(context.context_id) == registered_contexts.end()) {
260544 WriteLoggingContext(context);
260545 // New context_id: we should flush both contexts and entries next time LOG_ENTRIES gets flushed
260547 }
260548
260549 idx_t col = 0;
260550
260551 if (normalize_contexts) {
260552 auto context_id_data = FlatVector::GetData<idx_t>(log_entries_buffer->data[col++]);
260553 context_id_data[size] = context.context_id;
260554 } else {
260555 WriteLoggingContextsToChunk(*log_entries_buffer, context, col);
260556 }
260557
260558 auto timestamp_data = FlatVector::GetData<timestamp_t>(log_entries_buffer->data[col++]);
260559 timestamp_data[size] = timestamp;
260560
260561 auto type_data = FlatVector::GetData<string_t>(log_entries_buffer->data[col]);
260562 type_data[size] = StringVector::AddString(log_entries_buffer->data[col++], log_type);
260563
260564 auto level_data = FlatVector::GetData<string_t>(log_entries_buffer->data[col]);
260565 level_data[size] = StringVector::AddString(log_entries_buffer->data[col++],
260566 EnumUtil::ToString(level)); // TODO: do cast on write out
260567
260568 auto message_data = FlatVector::GetData<string_t>(log_entries_buffer->data[col]);
260569 message_data[size] = StringVector::AddString(log_entries_buffer->data[col++], log_message);
260570
260571 log_entries_buffer->SetCardinality(size + 1);
260572
260573 if (size + 1 >= buffer_limit) {
260574 if (normalize_contexts) {
260575 // Flush all entries
260576 FlushInternal(LoggingTargetTable::LOG_ENTRIES);
260577 // Flush contexts if required
260579 FlushInternal(LoggingTargetTable::LOG_CONTEXTS);
260581 }
260582 } else {
260583 FlushInternal(LoggingTargetTable::ALL_LOGS);
260584 }
260585 }
260586}
void WriteLoggingContext(const RegisteredLoggingContext &context)
Write out a logging context.
Definition duckdb.cpp:260633
mutex lock
lock to be used by this class and child classes to ensure thread safety TODO: maybe remove and delega...
Definition duckdb.hpp:39592
map< LoggingTargetTable, unique_ptr< DataChunk > > buffers
The buffers used for each table.
Definition duckdb.hpp:39610
bool flush_contexts_on_next_entry_flush
This flag is set whenever a new context_is written to the entry buffer. It means that the next flush ...
Definition duckdb.hpp:39613
void FlushInternal(LoggingTargetTable table)
Flushes one of the tables.
Definition duckdb.cpp:260625
unordered_set< idx_t > registered_contexts
The currently registered RegisteredLoggingContext's.
Definition duckdb.hpp:39604
GOpaque< Size > size(const GMat &src)
cv::GOpaque< int64_t > timestamp(G g)
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
static DUCKDB_API string_t AddString(Vector &vector, const char *data, idx_t len)
Add a string to the string heap of the vector (auxiliary data).
Definition duckdb.cpp:137889
Here is the call graph for this function:

◆ WriteLogEntries()

void duckdb::BufferingLogStorage::WriteLogEntries ( DataChunk & chunk,
const RegisteredLoggingContext & context )
finalvirtual

Write out the chunk to the buffers.

Implements duckdb::LogStorage.

260588 {
260589 throw NotImplementedException("BufferingLogStorage::WriteLogEntries(DataChunk &chunk) not implemented");
260590}

◆ FlushAll()

void duckdb::BufferingLogStorage::FlushAll ( )
finalvirtual

Flushes buffers for all tables.

Implements duckdb::LogStorage.

260592 {
260593 unique_lock<mutex> lck(lock);
260596 }
260597}
void FlushAllInternal()
Helper methods.
Definition duckdb.cpp:260616
bool only_flush_on_full_buffer
Debug option for testing buffering behaviour.
Definition duckdb.hpp:39608
Here is the call graph for this function:

◆ Flush()

void duckdb::BufferingLogStorage::Flush ( LoggingTargetTable table)
finalvirtual

Flushes buffer for a specific table.

Implements duckdb::LogStorage.

260599 {
260600 unique_lock<mutex> lck(lock);
260602 FlushInternal(table);
260603 }
260604}
Here is the call graph for this function:

◆ Truncate()

void duckdb::BufferingLogStorage::Truncate ( )
overridevirtual

Truncates log storage: both buffers and persistent storage (if applicable).

Reimplemented from duckdb::LogStorage.

Reimplemented in duckdb::FileLogStorage.

260606 {
260607 unique_lock<mutex> lck(lock);
260608 ResetAllBuffers();
260609}
virtual void ResetAllBuffers()
ResetAllBuffers will clear all buffered data. To be overridden by child classes to ensure their buffe...
Definition duckdb.cpp:260455
Here is the call graph for this function:

◆ UpdateConfig()

void duckdb::BufferingLogStorage::UpdateConfig ( DatabaseInstance & db,
case_insensitive_map_t< Value > & config )
overridevirtual

Apply a new log storage configuration.

Reimplemented from duckdb::LogStorage.

260008 {
260009 lock_guard<mutex> lck(lock);
260010 return UpdateConfigInternal(db, config);
260011}
virtual void UpdateConfigInternal(DatabaseInstance &db, case_insensitive_map_t< Value > &config)
This method is called in a chained way down the class hierarchy. This allows each class to interpret ...
Definition duckdb.cpp:260134
Here is the call graph for this function:

◆ IsEnabled()

bool duckdb::BufferingLogStorage::IsEnabled ( LoggingTargetTable table)
overridevirtual

Returns whether the table is enabled for this storage.

Implements duckdb::LogStorage.

260013 {
260014 lock_guard<mutex> lck(lock);
260015 return IsEnabledInternal(table);
260016}
bool IsEnabledInternal(LoggingTargetTable table)
Whether a specific table is available in the log storage.
Definition duckdb.cpp:260018
Here is the call graph for this function:

◆ FlushChunk()

virtual void duckdb::BufferingLogStorage::FlushChunk ( LoggingTargetTable table,
DataChunk & chunk )
protectedpure virtual

Interface to child classes.

Invoked whenever buffers are full to flush to storage

Implemented in duckdb::CSVLogStorage, and duckdb::InMemoryLogStorage.

Here is the caller graph for this function:

◆ UpdateConfigInternal()

void duckdb::BufferingLogStorage::UpdateConfigInternal ( DatabaseInstance & db,
case_insensitive_map_t< Value > & config )
protectedvirtual

This method is called in a chained way down the class hierarchy. This allows each class to interpret its own part of the config. Unhandled config values that are left over will result in an error.

Reimplemented in duckdb::CSVLogStorage, and duckdb::FileLogStorage.

260134 {
260135 for (const auto &it : config) {
260136 if (StringUtil::Lower(it.first) == "buffer_size") {
260137 buffer_limit = it.second.GetValue<uint64_t>();
260138 ResetAllBuffers();
260139 } else if (StringUtil::Lower(it.first) == "only_flush_on_full_buffer") {
260140 // This is a debug option used during testing. It disables the manual
260141 only_flush_on_full_buffer = it.second.GetValue<bool>();
260142 } else if (StringUtil::Lower(it.first) == "normalize") {
260143 throw InternalException("'normalize' setting should be handled in child class");
260144 } else {
260145 throw InvalidInputException("Unrecognized log storage config option for storage: '%s': '%s'",
260146 GetStorageName(), it.first);
260147 }
260148 }
260149}
static DUCKDB_API string Lower(const string &str)
Convert a string to lowercase.
Definition duckdb.cpp:109630
::uint64_t uint64_t
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetAllBuffers()

void duckdb::BufferingLogStorage::ResetAllBuffers ( )
protectedvirtual

ResetAllBuffers will clear all buffered data. To be overridden by child classes to ensure their buffers are flushed too.

Reimplemented in duckdb::CSVLogStorage, and duckdb::InMemoryLogStorage.

260455 {
260456 ResetLogBuffers();
260457}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FlushAllInternal()

void duckdb::BufferingLogStorage::FlushAllInternal ( )
protected

Helper methods.

Flushes all tables

260616 {
260617 if (normalize_contexts) {
260618 FlushInternal(LoggingTargetTable::LOG_ENTRIES);
260619 FlushInternal(LoggingTargetTable::LOG_CONTEXTS);
260620 } else {
260621 FlushInternal(LoggingTargetTable::ALL_LOGS);
260622 }
260623}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FlushInternal()

void duckdb::BufferingLogStorage::FlushInternal ( LoggingTargetTable table)
protected

Flushes one of the tables.

260625 {
260626 if (!IsEnabledInternal(table)) {
260627 throw InvalidConfigurationException("Cannot flush disabled logging target");
260628 }
260629 FlushChunk(table, *buffers[table]);
260630 buffers[table]->Reset();
260631}
virtual void FlushChunk(LoggingTargetTable table, DataChunk &chunk)=0
Interface to child classes.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsEnabledInternal()

bool duckdb::BufferingLogStorage::IsEnabledInternal ( LoggingTargetTable table)
protected

Whether a specific table is available in the log storage.

260018 {
260019 if (normalize_contexts) {
260020 return table == LoggingTargetTable::LOG_CONTEXTS || table == LoggingTargetTable::LOG_ENTRIES;
260021 }
260022
260023 return table == LoggingTargetTable::ALL_LOGS;
260024}
Here is the caller graph for this function:

◆ GetBufferLimit()

idx_t duckdb::BufferingLogStorage::GetBufferLimit ( ) const
protected
260026 {
260027 return buffer_limit;
260028}

◆ ResetLogBuffers()

void duckdb::BufferingLogStorage::ResetLogBuffers ( )
private

Resets the log buffers.

260438 {
260439 idx_t buffer_size = MaxValue<idx_t>(buffer_limit, 1);
260440 if (normalize_contexts) {
260441 buffers[LoggingTargetTable::LOG_ENTRIES] = make_uniq<DataChunk>();
260442 buffers[LoggingTargetTable::LOG_CONTEXTS] = make_uniq<DataChunk>();
260443 buffers[LoggingTargetTable::LOG_ENTRIES]->Initialize(Allocator::DefaultAllocator(),
260444 GetSchema(LoggingTargetTable::LOG_ENTRIES), buffer_size);
260445 buffers[LoggingTargetTable::LOG_CONTEXTS]->Initialize(Allocator::DefaultAllocator(),
260446 GetSchema(LoggingTargetTable::LOG_CONTEXTS), buffer_size);
260447
260448 } else {
260449 buffers[LoggingTargetTable::ALL_LOGS] = make_uniq<DataChunk>();
260450 buffers[LoggingTargetTable::ALL_LOGS]->Initialize(Allocator::DefaultAllocator(),
260451 GetSchema(LoggingTargetTable::ALL_LOGS), buffer_size);
260452 }
260453}
Here is the caller graph for this function:

◆ WriteLoggingContext()

void duckdb::BufferingLogStorage::WriteLoggingContext ( const RegisteredLoggingContext & context)
private

Write out a logging context.

260633 {
260634 registered_contexts.insert(context.context_id);
260635
260636 // If we don't normalize the contexts they are written out on every log entry
260637 if (!normalize_contexts) {
260638 return;
260639 }
260640
260641 idx_t col = 0;
260642
260643 auto &log_contexts_buffer = buffers[LoggingTargetTable::LOG_CONTEXTS];
260644
260645 if (log_contexts_buffer->size() + 1 > buffer_limit) {
260646 FlushInternal(LoggingTargetTable::LOG_CONTEXTS);
260647 }
260648
260649 WriteLoggingContextsToChunk(*log_contexts_buffer, context, col);
260650}
Here is the call graph for this function:
Here is the caller graph for this function:

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