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::BlockIndexManager Struct Reference
Collaboration diagram for duckdb::BlockIndexManager:

Public Member Functions

 BlockIndexManager (TemporaryFileManager &manager)
idx_t GetNewBlockIndex (TemporaryBufferSize size)
 Obtains a new block index from the index manager.
bool RemoveIndex (idx_t index, TemporaryBufferSize size)
 Removes an index from the block manager (returns true if the max_index has been altered).
idx_t GetMaxIndex () const
 Get the maximum block index.
bool HasFreeBlocks () const
 Whether there are free blocks available within the file.

Private Member Functions

idx_t GetNewBlockIndexInternal (TemporaryBufferSize size)
 Get/set max block index.
void SetMaxIndex (idx_t new_index, TemporaryBufferSize size)

Private Attributes

idx_t max_index
 The maximum block index.
set< idx_t > free_indexes
 Free indexes within the file.
set< idx_t > indexes_in_use
 Used indexes within the file.
optional_ptr< TemporaryFileManager > manager
 The TemporaryFileManager that "owns" this BlockIndexManager.

Constructor & Destructor Documentation

◆ BlockIndexManager() [1/2]

duckdb::BlockIndexManager::BlockIndexManager ( )
442766 : max_index(0), manager(nullptr) {
442767}
optional_ptr< TemporaryFileManager > manager
The TemporaryFileManager that "owns" this BlockIndexManager.
Definition duckdb.cpp:61603
idx_t max_index
The maximum block index.
Definition duckdb.cpp:61597

◆ BlockIndexManager() [2/2]

duckdb::BlockIndexManager::BlockIndexManager ( TemporaryFileManager & manager)
explicit
442769 : max_index(0), manager(&manager) {
442770}

Member Function Documentation

◆ GetNewBlockIndex()

idx_t duckdb::BlockIndexManager::GetNewBlockIndex ( TemporaryBufferSize size)

Obtains a new block index from the index manager.

442772 {
442773 auto index = GetNewBlockIndexInternal(size);
442774 indexes_in_use.insert(index);
442775 return index;
442776}
index
set< idx_t > indexes_in_use
Used indexes within the file.
Definition duckdb.cpp:61601
idx_t GetNewBlockIndexInternal(TemporaryBufferSize size)
Get/set max block index.
Definition duckdb.cpp:442815
Here is the call graph for this function:

◆ RemoveIndex()

bool duckdb::BlockIndexManager::RemoveIndex ( idx_t index,
TemporaryBufferSize size )

Removes an index from the block manager (returns true if the max_index has been altered).

442778 {
442779 // remove this block from the set of blocks
442780 auto entry = indexes_in_use.find(index);
442781 if (entry == indexes_in_use.end()) {
442782 throw InternalException("RemoveIndex - index %llu not found in indexes_in_use", index);
442783 }
442784 indexes_in_use.erase(entry);
442785 free_indexes.insert(index);
442786 // check if we can truncate the file
442787
442788 // get the max_index in use right now
442789 auto max_index_in_use = indexes_in_use.empty() ? 0 : *indexes_in_use.rbegin() + 1;
442790 if (max_index_in_use < max_index) {
442791 // max index in use is lower than the max_index
442792 // reduce the max_index
442793 SetMaxIndex(max_index_in_use, size);
442794 // we can remove any free_indexes that are larger than the current max_index
442795 while (HasFreeBlocks()) {
442796 auto max_entry = *free_indexes.rbegin();
442797 if (max_entry < max_index) {
442798 break;
442799 }
442800 free_indexes.erase(max_entry);
442801 }
442802 return true;
442803 }
442804 return false;
442805}
bool HasFreeBlocks() const
Whether there are free blocks available within the file.
Definition duckdb.cpp:442811
set< idx_t > free_indexes
Free indexes within the file.
Definition duckdb.cpp:61599
Here is the call graph for this function:

◆ GetMaxIndex()

idx_t duckdb::BlockIndexManager::GetMaxIndex ( ) const

Get the maximum block index.

442807 {
442808 return max_index;
442809}

◆ HasFreeBlocks()

bool duckdb::BlockIndexManager::HasFreeBlocks ( ) const

Whether there are free blocks available within the file.

442811 {
442812 return !free_indexes.empty();
442813}
Here is the caller graph for this function:

◆ GetNewBlockIndexInternal()

idx_t duckdb::BlockIndexManager::GetNewBlockIndexInternal ( TemporaryBufferSize size)
private

Get/set max block index.

442815 {
442816 if (!HasFreeBlocks()) {
442817 auto new_index = max_index;
442818 SetMaxIndex(max_index + 1, size);
442819 return new_index;
442820 }
442821 auto entry = free_indexes.begin();
442822 auto index = *entry;
442823 free_indexes.erase(entry);
442824 return index;
442825}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetMaxIndex()

void duckdb::BlockIndexManager::SetMaxIndex ( idx_t new_index,
TemporaryBufferSize size )
private
442827 {
442828 const auto temp_file_block_size =
442829 size == TemporaryBufferSize::DEFAULT ? DEFAULT_BLOCK_ALLOC_SIZE : TemporaryBufferSizeToSize(size);
442830 if (!manager) {
442831 max_index = new_index;
442832 } else {
442833 auto old = max_index;
442834 if (new_index < old) {
442835 max_index = new_index;
442836 const auto difference = old - new_index;
442837 const auto size_on_disk = difference * temp_file_block_size;
442838 manager->DecreaseSizeOnDisk(size_on_disk);
442839 } else if (new_index > old) {
442840 const auto difference = new_index - old;
442841 const auto size_on_disk = difference * temp_file_block_size;
442842 manager->IncreaseSizeOnDisk(size_on_disk);
442843 // Increase can throw, so this is only updated after it was successfully updated
442844 max_index = new_index;
442845 }
442846 }
442847}
GOpaque< Size > size(const GMat &src)

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