ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
MappedRegion Class Reference

#include "MappedRegion.h"

Public Member Functions

 MappedRegion ()=default
 MappedRegion (const MappedRegion &)=delete
MappedRegionoperator= (const MappedRegion &)=delete
std::size_t openFile (const char *filename, bool read_only)
 Open (creating if absent) the backing file.
void resizeFile (std::size_t length)
 Set the backing file's size.
void map (std::size_t length)
 Establish the initial region of length bytes over the file.
void remap (std::size_t new_length)
 Grow the region to new_length, preserving existing content.
void flush ()
 Force the backing file's contents to stable storage.
void replaceContents (const char *path, const void *data, std::size_t length)
 Replace the backing file, atomically, with length bytes of data, and remap onto the result.
void sync ()
 Flush the region to the backing file (no-op when read-only).
void close ()
 Write back (if writable) and release the region and file.
void * base () const
std::size_t length () const

Static Private Member Functions

static void syncDirectoryOf (const char *path)
 Force the directory entry of path to disk, so the rename that created it survives a crash of the machine.

Private Attributes

int fd_ = -1
 Backing file descriptor.
void * base_ = nullptr
 Base of the mapped region / heap buffer.
std::size_t length_ = 0
 Current region length in bytes.
bool read_only_ = false
 Opened read-only (no write-back).

Detailed Description

Definition at line 61 of file MappedRegion.h.

Constructor & Destructor Documentation

◆ MappedRegion() [1/2]

MappedRegion::MappedRegion ( )
default
Here is the caller graph for this function:

◆ MappedRegion() [2/2]

MappedRegion::MappedRegion ( const MappedRegion & )
delete
Here is the call graph for this function:

Member Function Documentation

◆ base()

void * MappedRegion::base ( ) const
inline

Definition at line 267 of file MappedRegion.h.

◆ close()

void MappedRegion::close ( )
inline

Write back (if writable) and release the region and file.

Definition at line 251 of file MappedRegion.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flush()

void MappedRegion::flush ( )
inline

Force the backing file's contents to stable storage.

sync() pushes the region's bytes into the file; this pushes the file's dirty pages out of the kernel's cache, which is what a crash of the machine (as opposed to a crash of PostgreSQL) can otherwise lose. fdatasync on the descriptor rather than msync on the mapping: it flushes the file's dirty pages whoever dirtied them, and does not walk the mapping.

Definition at line 157 of file MappedRegion.h.

Here is the call graph for this function:

◆ length()

std::size_t MappedRegion::length ( ) const
inline

Definition at line 268 of file MappedRegion.h.

Here is the caller graph for this function:

◆ map()

void MappedRegion::map ( std::size_t length)
inline

Establish the initial region of length bytes over the file.

Definition at line 106 of file MappedRegion.h.

Here is the call graph for this function:

◆ openFile()

std::size_t MappedRegion::openFile ( const char * filename,
bool read_only )
inline

Open (creating if absent) the backing file.

Returns
The file's current size in bytes (0 if newly created).

Definition at line 76 of file MappedRegion.h.

◆ operator=()

MappedRegion & MappedRegion::operator= ( const MappedRegion & )
delete
Here is the call graph for this function:

◆ remap()

void MappedRegion::remap ( std::size_t new_length)
inline

Grow the region to new_length, preserving existing content.

Definition at line 126 of file MappedRegion.h.

Here is the call graph for this function:

◆ replaceContents()

void MappedRegion::replaceContents ( const char * path,
const void * data,
std::size_t length )
inline

Replace the backing file, atomically, with length bytes of data, and remap onto the result.

Used to rewrite a region whose new contents cannot be derived from the old ones in place – rehashing the UUID table. The bytes go to a sibling file, are forced to disk, and then rename(2) puts them in place in one step, so a crash at any point leaves either the complete old file or the complete new one.

Parameters
pathPath of the backing file (the same one openFile opened).
dataBytes the region is to hold from now on.
lengthNumber of bytes at data, and the new size of the region.

Definition at line 181 of file MappedRegion.h.

Here is the call graph for this function:

◆ resizeFile()

void MappedRegion::resizeFile ( std::size_t length)
inline

Set the backing file's size.

The shared-mmap backend must pre-size the file (mmap maps file-backed pages). The heap-buffer backend does not: it allocates the buffer and sync() extends the file with pwrite. Crucially, leaving the file unsized until the first sync() means a fresh file that is never synced (e.g. a backend that aborts before write-back) stays empty on disk and is re-initialised cleanly on reopen, rather than persisting as a full-size, never-written file whose zero header fails magic validation.

Definition at line 96 of file MappedRegion.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sync()

void MappedRegion::sync ( )
inline

Flush the region to the backing file (no-op when read-only).

Definition at line 239 of file MappedRegion.h.

Here is the caller graph for this function:

◆ syncDirectoryOf()

void MappedRegion::syncDirectoryOf ( const char * path)
inlinestaticprivate

Force the directory entry of path to disk, so the rename that created it survives a crash of the machine.

Definition at line 274 of file MappedRegion.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ base_

void* MappedRegion::base_ = nullptr
private

Base of the mapped region / heap buffer.

Definition at line 63 of file MappedRegion.h.

◆ fd_

int MappedRegion::fd_ = -1
private

Backing file descriptor.

Definition at line 62 of file MappedRegion.h.

◆ length_

std::size_t MappedRegion::length_ = 0
private

Current region length in bytes.

Definition at line 64 of file MappedRegion.h.

◆ read_only_

bool MappedRegion::read_only_ = false
private

Opened read-only (no write-back).

Definition at line 65 of file MappedRegion.h.


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