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

Public Member Functions

 BlockMemory (BufferManager &buffer_manager, block_id_t block_id_p, MemoryTag tag_p, idx_t block_alloc_size)
 
 BlockMemory (BufferManager &buffer_manager, block_id_t block_id_p, MemoryTag tag_p, unique_ptr< FileBuffer > buffer_p, DestroyBufferUpon destroy_buffer_upon_p, idx_t size_p, BufferPoolReservation &&reservation)
 
const BufferManagerGetBufferManager () const
 Returns a const reference to the buffer manager.
 
BufferManagerGetBufferManager ()
 Returns a reference to the buffer manager.
 
block_id_t BlockId () const
 Returns the block ID.
 
BlockLock GetLock ()
 Locks the memory block.
 
void VerifyMutex (BlockLock &l) const
 Verification-only: ensure that the lock matches this memory's lock.
 
BlockState GetState () const
 Returns the block state.
 
void SetState (BlockState state_p)
 Sets the block state.
 
bool IsUnloaded () const
 Returns true, if the block state is BLOCK_UNLOADED.
 
int32_t GetReaders () const
 Returns the number of readers.
 
int32_t IncrementReaders ()
 Increments the number of readers prior to returning it.
 
int32_t DecrementReaders ()
 Decrements the number of readers prior to returning it.
 
void SetReaders (int32_t n)
 Sets the number of readers.
 
MemoryTag GetMemoryTag () const
 Returns the memory tag.
 
FileBufferType GetBufferType () const
 Returns the file buffer type.
 
unique_ptr< FileBuffer > & GetBuffer (BlockLock &l)
 Returns a reference to the unique file buffer pointer while holding the block lock.
 
unique_ptr< FileBuffer > & GetBuffer ()
 Returns a reference to the unique file buffer pointer.
 
void SetBuffer (unique_ptr< FileBuffer > buffer_p)
 Sets the file buffer.
 
idx_t GetEvictionSequenceNumber () const
 Returns the eviction sequence number.
 
idx_t NextEvictionSequenceNumber ()
 Increments the eviction sequence number prior to returning it.
 
int64_t GetLRUTimestamp () const
 Get the LRU timestamp.
 
void SetLRUTimestamp (int64_t timestamp_msec)
 Set the LRU timestamp.
 
void SetDestroyBufferUpon (DestroyBufferUpon destroy_buffer_upon_p)
 Set the buffer destruction policy.
 
bool MustAddToEvictionQueue () const
 Returns true, if the buffer must be added to the eviction queue.
 
bool MustWriteToTemporaryFile () const
 Returns true, if the buffer cannot be destroyed, but must be kept alive in a temporary file.
 
idx_t GetMemoryUsage () const
 Returns the memory usage.
 
void SetMemoryUsage (idx_t usage)
 Sets the memory usage.
 
BufferPoolReservationGetMemoryCharge (BlockLock &l)
 Get the memory charge while holding the block lock.
 
BufferPoolReservationGetMemoryCharge ()
 Get the memory charge.
 
void ResizeMemory (BlockLock &l, idx_t alloc_size)
 Resize the memory charge.
 
void MergeMemoryReservation (BlockLock &l, BufferPoolReservation reservation)
 Merge two memory charges.
 
bool IsSwizzled () const
 Returns true, if there is a swizzled memory pointer, else false.
 
void SetSwizzling (const char *unswizzler)
 Sets the swizzled memory pointer.
 
void SetEvictionQueueIndex (const idx_t index)
 Sets the eviction queue index.
 
idx_t GetEvictionQueueIndex () const
 Returns the eviction queue index.
 
void ChangeMemoryUsage (BlockLock &l, int64_t delta)
 
void ConvertToPersistent (BlockLock &l, BlockHandle &new_block, unique_ptr< FileBuffer > new_buffer)
 
void ResizeBuffer (BlockLock &l, idx_t block_size, idx_t block_header_size, int64_t memory_delta)
 
bool CanUnload () const
 
unique_ptr< FileBufferUnloadAndTakeBlock (BlockLock &l)
 
void Unload (BlockLock &l)
 
- Public Member Functions inherited from duckdb::enable_shared_from_this< BlockMemory >
shared_ptr< BlockMemoryshared_from_this ()
 
shared_ptr< BlockMemory constshared_from_this () const
 

Private Attributes

BufferManagerbuffer_manager
 A reference to the buffer manager.
 
const block_id_t block_id
 The block id of the block.
 
mutex lock
 The block-level lock.
 
atomic< BlockState > state
 Whether the block is loaded or unloaded.
 
atomic< int32_treaders
 The number of concurrent readers.
 
const MemoryTag tag
 The memory tag.
 
const FileBufferType buffer_type
 The file buffer type.
 
unique_ptr< FileBufferbuffer
 A pointer to the loaded data, if any.
 
atomic< idx_teviction_seq_num
 The internal eviction sequence number.
 
atomic< int64_tlru_timestamp_msec
 The LRU timestamp for age-based eviction.
 
atomic< DestroyBufferUpondestroy_buffer_upon
 When to destroy the data buffer.
 
atomic< idx_tmemory_usage
 
BufferPoolReservation memory_charge
 The current memory reservation/usage.
 
const charunswizzled
 Swizzled memory pointers.
 
atomic< idx_teviction_queue_idx
 The eviction queue index, currently only FileBufferType::MANAGED_BUFFER.
 

Additional Inherited Members

- Protected Member Functions inherited from duckdb::enable_shared_from_this< BlockMemory >
 enable_shared_from_this (enable_shared_from_this const &) noexcept
 
enable_shared_from_thisoperator= (enable_shared_from_this const &) noexcept
 

Member Function Documentation

◆ GetBufferManager() [1/2]

const BufferManager & duckdb::BlockMemory::GetBufferManager ( ) const
inline

Returns a const reference to the buffer manager.

45662 {
45663 return buffer_manager;
45664 }
BufferManager & buffer_manager
A reference to the buffer manager.
Definition duckdb.hpp:45820

◆ GetBufferManager() [2/2]

BufferManager & duckdb::BlockMemory::GetBufferManager ( )
inline

Returns a reference to the buffer manager.

45666 {
45667 return buffer_manager;
45668 }

◆ BlockId()

block_id_t duckdb::BlockMemory::BlockId ( ) const
inline

Returns the block ID.

45670 {
45671 return block_id;
45672 }
const block_id_t block_id
The block id of the block.
Definition duckdb.hpp:45822

◆ GetLock()

BlockLock duckdb::BlockMemory::GetLock ( )
inline

Locks the memory block.

45674 {
45675 return BlockLock(lock);
45676 }
mutex lock
The block-level lock.
Definition duckdb.hpp:45824

◆ VerifyMutex()

void duckdb::BlockMemory::VerifyMutex ( BlockLock &  l) const
inline

Verification-only: ensure that the lock matches this memory's lock.

45678 {
45679 D_ASSERT(l.owns_lock());
45680 D_ASSERT(l.mutex() == &lock);
45681 }
Here is the caller graph for this function:

◆ GetState()

BlockState duckdb::BlockMemory::GetState ( ) const
inline

Returns the block state.

45683 {
45684 return state;
45685 }
atomic< BlockState > state
Whether the block is loaded or unloaded.
Definition duckdb.hpp:45826

◆ SetState()

void duckdb::BlockMemory::SetState ( BlockState  state_p)
inline

Sets the block state.

45687 {
45688 state = state_p;
45689 }

◆ IsUnloaded()

bool duckdb::BlockMemory::IsUnloaded ( ) const
inline

Returns true, if the block state is BLOCK_UNLOADED.

45691 {
45692 return state == BlockState::BLOCK_UNLOADED;
45693 }

◆ GetReaders()

int32_t duckdb::BlockMemory::GetReaders ( ) const
inline

Returns the number of readers.

45695 {
45696 return readers;
45697 }
atomic< int32_t > readers
The number of concurrent readers.
Definition duckdb.hpp:45828

◆ IncrementReaders()

int32_t duckdb::BlockMemory::IncrementReaders ( )
inline

Increments the number of readers prior to returning it.

45699 {
45700 return ++readers;
45701 }

◆ DecrementReaders()

int32_t duckdb::BlockMemory::DecrementReaders ( )
inline

Decrements the number of readers prior to returning it.

45703 {
45704 return --readers;
45705 }

◆ SetReaders()

void duckdb::BlockMemory::SetReaders ( int32_t  n)
inline

Sets the number of readers.

45707 {
45708 readers = n;
45709 }

◆ GetMemoryTag()

MemoryTag duckdb::BlockMemory::GetMemoryTag ( ) const
inline

Returns the memory tag.

45711 {
45712 return tag;
45713 }
const MemoryTag tag
The memory tag.
Definition duckdb.hpp:45830

◆ GetBufferType()

FileBufferType duckdb::BlockMemory::GetBufferType ( ) const
inline

Returns the file buffer type.

45715 {
45716 return buffer_type;
45717 }
const FileBufferType buffer_type
The file buffer type.
Definition duckdb.hpp:45832
Here is the caller graph for this function:

◆ GetBuffer() [1/2]

unique_ptr< FileBuffer > & duckdb::BlockMemory::GetBuffer ( BlockLock &  l)
inline

Returns a reference to the unique file buffer pointer while holding the block lock.

45719 {
45720 VerifyMutex(l);
45721 return GetBuffer();
45722 }
unique_ptr< FileBuffer > & GetBuffer()
Returns a reference to the unique file buffer pointer.
Definition duckdb.hpp:45724
void VerifyMutex(BlockLock &l) const
Verification-only: ensure that the lock matches this memory's lock.
Definition duckdb.hpp:45678
Here is the call graph for this function:

◆ GetBuffer() [2/2]

unique_ptr< FileBuffer > & duckdb::BlockMemory::GetBuffer ( )
inline

Returns a reference to the unique file buffer pointer.

45724 {
45725 return buffer;
45726 }
unique_ptr< FileBuffer > buffer
A pointer to the loaded data, if any.
Definition duckdb.hpp:45834
Here is the caller graph for this function:

◆ SetBuffer()

void duckdb::BlockMemory::SetBuffer ( unique_ptr< FileBuffer buffer_p)
inline

Sets the file buffer.

45728 {
45729 buffer = std::move(buffer_p);
45730 }

◆ GetEvictionSequenceNumber()

idx_t duckdb::BlockMemory::GetEvictionSequenceNumber ( ) const
inline

Returns the eviction sequence number.

45732 {
45733 return eviction_seq_num;
45734 }
atomic< idx_t > eviction_seq_num
The internal eviction sequence number.
Definition duckdb.hpp:45836

◆ NextEvictionSequenceNumber()

idx_t duckdb::BlockMemory::NextEvictionSequenceNumber ( )
inline

Increments the eviction sequence number prior to returning it.

45736 {
45737 return ++eviction_seq_num;
45738 }

◆ GetLRUTimestamp()

int64_t duckdb::BlockMemory::GetLRUTimestamp ( ) const
inline

Get the LRU timestamp.

45740 {
45741 return lru_timestamp_msec;
45742 }
atomic< int64_t > lru_timestamp_msec
The LRU timestamp for age-based eviction.
Definition duckdb.hpp:45838

◆ SetLRUTimestamp()

void duckdb::BlockMemory::SetLRUTimestamp ( int64_t  timestamp_msec)
inline

Set the LRU timestamp.

45744 {
45745 lru_timestamp_msec = timestamp_msec;
45746 }

◆ SetDestroyBufferUpon()

void duckdb::BlockMemory::SetDestroyBufferUpon ( DestroyBufferUpon  destroy_buffer_upon_p)
inline

Set the buffer destruction policy.

45748 {
45749 destroy_buffer_upon = destroy_buffer_upon_p;
45750 }
atomic< DestroyBufferUpon > destroy_buffer_upon
When to destroy the data buffer.
Definition duckdb.hpp:45840

◆ MustAddToEvictionQueue()

bool duckdb::BlockMemory::MustAddToEvictionQueue ( ) const
inline

Returns true, if the buffer must be added to the eviction queue.

45752 {
45754 }
@ UNPIN
Destroy the data buffer upon eviction to storage (destroy instead of evict)

◆ MustWriteToTemporaryFile()

bool duckdb::BlockMemory::MustWriteToTemporaryFile ( ) const
inline

Returns true, if the buffer cannot be destroyed, but must be kept alive in a temporary file.

45756 {
45757 return destroy_buffer_upon == DestroyBufferUpon::BLOCK;
45758 }

◆ GetMemoryUsage()

idx_t duckdb::BlockMemory::GetMemoryUsage ( ) const
inline

Returns the memory usage.

45760 {
45761 return memory_usage;
45762 }
atomic< idx_t > memory_usage
Definition duckdb.hpp:45843

◆ SetMemoryUsage()

void duckdb::BlockMemory::SetMemoryUsage ( idx_t  usage)
inline

Sets the memory usage.

45764 {
45765 memory_usage = usage;
45766 }

◆ GetMemoryCharge() [1/2]

BufferPoolReservation & duckdb::BlockMemory::GetMemoryCharge ( BlockLock &  l)
inline

Get the memory charge while holding the block lock.

45768 {
45769 VerifyMutex(l);
45770 return GetMemoryCharge();
45771 }
BufferPoolReservation & GetMemoryCharge()
Get the memory charge.
Definition duckdb.hpp:45773
Here is the call graph for this function:

◆ GetMemoryCharge() [2/2]

BufferPoolReservation & duckdb::BlockMemory::GetMemoryCharge ( )
inline

Get the memory charge.

45773 {
45774 return memory_charge;
45775 }
BufferPoolReservation memory_charge
The current memory reservation/usage.
Definition duckdb.hpp:45845
Here is the caller graph for this function:

◆ ResizeMemory()

void duckdb::BlockMemory::ResizeMemory ( BlockLock &  l,
idx_t  alloc_size 
)
inline

Resize the memory charge.

45777 {
45778 VerifyMutex(l);
45779 memory_charge.Resize(alloc_size);
45780 }
Here is the call graph for this function:

◆ MergeMemoryReservation()

void duckdb::BlockMemory::MergeMemoryReservation ( BlockLock &  l,
BufferPoolReservation  reservation 
)
inline

Merge two memory charges.

45782 {
45783 VerifyMutex(l);
45784 memory_charge.Merge(std::move(reservation));
45785 }
Here is the call graph for this function:

◆ IsSwizzled()

bool duckdb::BlockMemory::IsSwizzled ( ) const
inline

Returns true, if there is a swizzled memory pointer, else false.

45787 {
45788 return !unswizzled;
45789 }
const char * unswizzled
Swizzled memory pointers.
Definition duckdb.hpp:45847

◆ SetSwizzling()

void duckdb::BlockMemory::SetSwizzling ( const char unswizzler)
inline

Sets the swizzled memory pointer.

45791 {
45792 unswizzled = unswizzler;
45793 }

◆ SetEvictionQueueIndex()

void duckdb::BlockMemory::SetEvictionQueueIndex ( const idx_t  index)
inline

Sets the eviction queue index.

45795 {
45796 // The index can only be set once.
45798 // It can only be set for managed buffers (for now).
45799 D_ASSERT(GetBufferType() == FileBufferType::MANAGED_BUFFER);
45801 }
FileBufferType GetBufferType() const
Returns the file buffer type.
Definition duckdb.hpp:45715
atomic< idx_t > eviction_queue_idx
The eviction queue index, currently only FileBufferType::MANAGED_BUFFER.
Definition duckdb.hpp:45849
index
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117
Here is the call graph for this function:

◆ GetEvictionQueueIndex()

idx_t duckdb::BlockMemory::GetEvictionQueueIndex ( ) const
inline

Returns the eviction queue index.

45803 {
45804 return eviction_queue_idx;
45805 }

◆ CanUnload()

bool duckdb::BlockMemory::CanUnload ( ) const

Returns whether the block can be unloaded or not. The state here can change if the block lock is held. However, this method does not hold the block lock.

Member Data Documentation

◆ memory_usage

atomic<idx_t> duckdb::BlockMemory::memory_usage
private

The memory usage of the block when loaded. Determines the memory to reserve when pinning/loading an unloaded block.


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