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::FileBuffer Class Reference

The FileBuffer represents a buffer that can be read or written to a Direct IO FileHandle. More...

#include <duckdb.hpp>

Inheritance diagram for duckdb::FileBuffer:
Collaboration diagram for duckdb::FileBuffer:

Classes

struct  MemoryRequirement
 

Public Member Functions

 FileBuffer (BlockAllocator &allocator, FileBufferType type, uint64_t user_size, idx_t block_header_size)
 
 FileBuffer (BlockAllocator &allocator, FileBufferType type, BlockManager &block_manager)
 
 FileBuffer (FileBuffer &source, FileBufferType type, idx_t block_header_size)
 
void Read (QueryContext context, FileHandle &handle, uint64_t location)
 Read into the FileBuffer from the location.
 
void Write (QueryContext context, FileHandle &handle, const uint64_t location)
 Write the FileBuffer to the location.
 
void Clear ()
 
FileBufferType GetBufferType () const
 
void Resize (uint64_t user_size, idx_t block_header_size)
 
void Resize (BlockManager &block_manager)
 
idx_t GetHeaderSize () const
 
uint64_t AllocSize () const
 
uint64_t Size () const
 
data_ptr_t InternalBuffer ()
 
MemoryRequirement CalculateMemory (uint64_t user_size, uint64_t block_header_size) const
 
void Initialize (DebugInitialize info)
 

Public Attributes

BlockAllocatorallocator
 
data_ptr_t buffer
 The buffer that users can write to.
 
uint64_t size
 

Protected Member Functions

void ReallocBuffer (idx_t new_size)
 
void Init ()
 

Protected Attributes

FileBufferType type
 The type of the buffer.
 
data_ptr_t internal_buffer
 
uint64_t internal_size
 

Private Member Functions

void ResizeInternal (uint64_t user_size, uint64_t block_header_size)
 

Detailed Description

The FileBuffer represents a buffer that can be read or written to a Direct IO FileHandle.

Constructor & Destructor Documentation

◆ FileBuffer() [1/3]

duckdb::FileBuffer::FileBuffer ( BlockAllocator allocator,
FileBufferType  type,
uint64_t  user_size,
idx_t  block_header_size 
)

Allocates a buffer of the specified size, with room for additional header bytes (typically 8 bytes). On return, this->AllocSize() >= this->size >= user_size. Our allocation size will always be page-aligned, which is necessary to support DIRECT_IO

72798 : allocator(allocator), type(type) {
72799 Init();
72800 if (user_size) {
72801 ResizeInternal(user_size, block_header_size);
72802 }
72803}
FileBufferType type
The type of the buffer.
Definition duckdb.hpp:7659

◆ FileBuffer() [2/3]

duckdb::FileBuffer::FileBuffer ( BlockAllocator allocator,
FileBufferType  type,
BlockManager block_manager 
)
72806 : allocator(allocator), type(type) {
72807 Init();
72808 Resize(block_manager);
72809}

◆ FileBuffer() [3/3]

duckdb::FileBuffer::FileBuffer ( FileBuffer source,
FileBufferType  type,
idx_t  block_header_size 
)
72819 : allocator(source.allocator), type(type_p) {
72820 // take over the structures of the source buffer
72821 buffer = source.internal_buffer + block_header_size;
72822 size = source.internal_size - block_header_size;
72823 internal_buffer = source.internal_buffer;
72824 internal_size = source.internal_size;
72825
72826 source.Init();
72827}
data_ptr_t buffer
The buffer that users can write to.
Definition duckdb.hpp:7613
uint64_t size
Definition duckdb.hpp:7616
data_ptr_t internal_buffer
Definition duckdb.hpp:7662
uint64_t internal_size
Definition duckdb.hpp:7665

◆ ~FileBuffer()

duckdb::FileBuffer::~FileBuffer ( )
virtual
72829 {
72830 if (!internal_buffer) {
72831 return;
72832 }
72833 allocator.FreeData(internal_buffer, internal_size);
72834}

Member Function Documentation

◆ Read()

void duckdb::FileBuffer::Read ( QueryContext  context,
FileHandle handle,
uint64_t  location 
)

Read into the FileBuffer from the location.

72888 {
72889 D_ASSERT(type != FileBufferType::TINY_BUFFER);
72890 handle.Read(context, internal_buffer, internal_size, location);
72891}

◆ Write()

void duckdb::FileBuffer::Write ( QueryContext  context,
FileHandle handle,
const uint64_t  location 
)

Write the FileBuffer to the location.

72893 {
72894 D_ASSERT(type != FileBufferType::TINY_BUFFER);
72895 handle.Write(context, internal_buffer, internal_size, location);
72896}

◆ Clear()

void duckdb::FileBuffer::Clear ( )
72898 {
72899 memset(internal_buffer, 0, internal_size);
72900}

◆ GetBufferType()

FileBufferType duckdb::FileBuffer::GetBufferType ( ) const
inline
7626 {
7627 return type;
7628 }

◆ Resize() [1/2]

void duckdb::FileBuffer::Resize ( uint64_t  user_size,
idx_t  block_header_size 
)
72880 {
72881 ResizeInternal(new_size, block_header_size);
72882}

◆ Resize() [2/2]

void duckdb::FileBuffer::Resize ( BlockManager block_manager)
72884 {
72885 ResizeInternal(block_manager.GetBlockSize(), block_manager.GetBlockHeaderSize());
72886}

◆ GetHeaderSize()

idx_t duckdb::FileBuffer::GetHeaderSize ( ) const
inline
7635 {
7636 return internal_size - size;
7637 }

◆ AllocSize()

uint64_t duckdb::FileBuffer::AllocSize ( ) const
inline
7639 {
7640 return internal_size;
7641 }

◆ Size()

uint64_t duckdb::FileBuffer::Size ( ) const
inline
7642 {
7643 return size;
7644 }

◆ InternalBuffer()

data_ptr_t duckdb::FileBuffer::InternalBuffer ( )
inline
7645 {
7646 return internal_buffer;
7647 }

◆ CalculateMemory()

FileBuffer::MemoryRequirement duckdb::FileBuffer::CalculateMemory ( uint64_t  user_size,
uint64_t  block_header_size 
) const
72857 {
72858 FileBuffer::MemoryRequirement result;
72859 if (type == FileBufferType::TINY_BUFFER) {
72860 // We never do IO on tiny buffers, so there's no need to add a header or sector-align.
72861 result.header_size = 0;
72862 result.alloc_size = user_size;
72863 } else {
72864 result.header_size = block_header_size;
72865 result.alloc_size = AlignValue<idx_t, Storage::SECTOR_SIZE>(result.header_size + user_size);
72866 }
72867 return result;
72868}

◆ Initialize()

void duckdb::FileBuffer::Initialize ( DebugInitialize  info)
72902 {
72903 if (initialize == DebugInitialize::NO_INITIALIZE) {
72904 return;
72905 }
72906 uint8_t value = initialize == DebugInitialize::DEBUG_ZERO_INITIALIZE ? 0 : 0xFF;
72907 memset(internal_buffer, value, internal_size);
72908}
::uint8_t uint8_t

◆ ReallocBuffer()

void duckdb::FileBuffer::ReallocBuffer ( idx_t  new_size)
protected
72836 {
72837 data_ptr_t new_buffer;
72838 if (internal_buffer) {
72839 new_buffer = allocator.ReallocateData(internal_buffer, internal_size, new_size);
72840 } else {
72841 new_buffer = allocator.AllocateData(new_size);
72842 }
72843
72844 // FIXME: should we throw one of our exceptions here?
72845 if (!new_buffer) {
72846 throw std::bad_alloc();
72847 }
72848
72849 internal_buffer = new_buffer;
72850 internal_size = new_size;
72851
72852 // The caller must update these.
72853 buffer = nullptr;
72854 size = 0;
72855}
data_ptr_t AllocateData(idx_t size) const
Allocation functions (same API as Allocator)

◆ Init()

void duckdb::FileBuffer::Init ( )
protected
72811 {
72812 buffer = nullptr;
72813 size = 0;
72814 internal_buffer = nullptr;
72815 internal_size = 0;
72816}

◆ ResizeInternal()

void duckdb::FileBuffer::ResizeInternal ( uint64_t  user_size,
uint64_t  block_header_size 
)
private
72870 {
72871 auto req = CalculateMemory(new_size, block_header_size);
72872 ReallocBuffer(req.alloc_size);
72873
72874 if (new_size > 0) {
72875 buffer = internal_buffer + req.header_size;
72876 size = internal_size - req.header_size;
72877 }
72878}

Member Data Documentation

◆ size

uint64_t duckdb::FileBuffer::size

The user-facing size of the buffer. This is equivalent to internal_size - block_header_size.

◆ internal_buffer

data_ptr_t duckdb::FileBuffer::internal_buffer
protected

The pointer to the internal buffer that will be read from or written to. This includes the buffer header.

◆ internal_size

uint64_t duckdb::FileBuffer::internal_size
protected

The aligned size as passed to the constructor. This is the size that is read from or written to disk.


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