Signet Forge 0.1.0
C++20 Parquet library with AI-native extensions
DEMO
Loading...
Searching...
No Matches
signet::forge::MappedSegment Class Reference

RAII cross-platform memory-mapped file segment. More...

#include <wal_mapped_segment.hpp>

Public Member Functions

 MappedSegment ()=default
 Default-construct an invalid (unmapped) segment.
 
 ~MappedSegment () noexcept
 
 MappedSegment (const MappedSegment &)=delete
 
MappedSegmentoperator= (const MappedSegment &)=delete
 
 MappedSegment (MappedSegment &&o) noexcept
 
MappedSegmentoperator= (MappedSegment &&o) noexcept
 
uint8_t * data () const noexcept
 Pointer to the start of the mapped memory region.
 
size_t capacity () const noexcept
 Size of the mapped region in bytes.
 
bool is_valid () const noexcept
 Check whether the segment is currently mapped and valid.
 
const std::string & path () const noexcept
 File path of this segment.
 
expected< void > flush_async () noexcept
 Asynchronously flush dirty pages to storage (non-blocking).
 
expected< void > flush_sync () noexcept
 Synchronously flush dirty pages to storage (blocks until complete).
 
void close () noexcept
 Unmap and close all OS handles. Safe to call multiple times.
 
void prefault () noexcept
 Pre-fault every 4 KB page in the mapping by reading one byte per page.
 

Static Public Member Functions

static expected< MappedSegmentcreate (const std::string &path, size_t size) noexcept
 Create (overwrite) and memory-map a new segment file of the given byte size.
 

Detailed Description

RAII cross-platform memory-mapped file segment.

Creates, maps, and manages a file backed by OS-level memory mapping (POSIX mmap / Windows MapViewOfFile). Supports async and sync flush, pre-faulting, and safe close semantics.

Note
Non-copyable but movable. Calling close() multiple times is safe.
See also
WalMmapWriter

Definition at line 139 of file wal_mapped_segment.hpp.

Constructor & Destructor Documentation

◆ MappedSegment() [1/3]

signet::forge::MappedSegment::MappedSegment ( )
default

Default-construct an invalid (unmapped) segment.

◆ ~MappedSegment()

signet::forge::MappedSegment::~MappedSegment ( )
inlinenoexcept

Definition at line 143 of file wal_mapped_segment.hpp.

◆ MappedSegment() [2/3]

signet::forge::MappedSegment::MappedSegment ( const MappedSegment )
delete

◆ MappedSegment() [3/3]

signet::forge::MappedSegment::MappedSegment ( MappedSegment &&  o)
inlinenoexcept

Definition at line 147 of file wal_mapped_segment.hpp.

Member Function Documentation

◆ capacity()

size_t signet::forge::MappedSegment::capacity ( ) const
inlinenoexcept

Size of the mapped region in bytes.

Definition at line 302 of file wal_mapped_segment.hpp.

◆ close()

void signet::forge::MappedSegment::close ( )
inlinenoexcept

Unmap and close all OS handles. Safe to call multiple times.

Definition at line 353 of file wal_mapped_segment.hpp.

◆ create()

static expected< MappedSegment > signet::forge::MappedSegment::create ( const std::string &  path,
size_t  size 
)
inlinestaticnoexcept

Create (overwrite) and memory-map a new segment file of the given byte size.

On POSIX, uses ftruncate + mmap with MADV_SEQUENTIAL. On macOS, attempts contiguous pre-allocation via F_PREALLOCATE. On Windows, uses CreateFileMapping.

Parameters
pathFile path for the new segment (created or overwritten).
sizeSegment size in bytes; must be in [WAL_MMAP_MIN_SEGMENT, WAL_MMAP_MAX_SEGMENT] and a multiple of 65536.
Returns
A mapped segment, or an Error on failure.

Definition at line 191 of file wal_mapped_segment.hpp.

◆ data()

uint8_t * signet::forge::MappedSegment::data ( ) const
inlinenoexcept

Pointer to the start of the mapped memory region.

Definition at line 300 of file wal_mapped_segment.hpp.

◆ flush_async()

expected< void > signet::forge::MappedSegment::flush_async ( )
inlinenoexcept

Asynchronously flush dirty pages to storage (non-blocking).

Uses MS_ASYNC on POSIX, FlushViewOfFile (without FlushFileBuffers) on Windows.

Definition at line 311 of file wal_mapped_segment.hpp.

◆ flush_sync()

expected< void > signet::forge::MappedSegment::flush_sync ( )
inlinenoexcept

Synchronously flush dirty pages to storage (blocks until complete).

Uses MS_SYNC on POSIX, FlushViewOfFile + FlushFileBuffers on Windows.

Definition at line 331 of file wal_mapped_segment.hpp.

◆ is_valid()

bool signet::forge::MappedSegment::is_valid ( ) const
inlinenoexcept

Check whether the segment is currently mapped and valid.

Definition at line 304 of file wal_mapped_segment.hpp.

◆ operator=() [1/2]

MappedSegment & signet::forge::MappedSegment::operator= ( const MappedSegment )
delete

◆ operator=() [2/2]

MappedSegment & signet::forge::MappedSegment::operator= ( MappedSegment &&  o)
inlinenoexcept

Definition at line 166 of file wal_mapped_segment.hpp.

◆ path()

const std::string & signet::forge::MappedSegment::path ( ) const
inlinenoexcept

File path of this segment.

Definition at line 306 of file wal_mapped_segment.hpp.

◆ prefault()

void signet::forge::MappedSegment::prefault ( )
inlinenoexcept

Pre-fault every 4 KB page in the mapping by reading one byte per page.

Uses read-only touch to avoid corrupting data on re-opened segments. Call from a background thread only – this can be expensive for large segments.

Definition at line 382 of file wal_mapped_segment.hpp.


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