armarx::armem::server::ltm::util::fs Namespace Reference

Namespaces

namespace  detail
 

Enumerations

enum class  WriteMode { Plain , Atomic , AtomicDurable }
 How writeDataToFile() should get the bytes onto disk. More...
 

Functions

bool canCreateFiles (const std::filesystem::path &dir)
 Check if we can create files in this directory.
 
bool directoryExists (const std::filesystem::path &p)
 
void ensureDirectoryExists (const std::filesystem::path &p, bool createIfNotExistent=false)
 
void ensureFileExists (const std::filesystem::path &p, bool createIfNotExistent=false)
 
bool fileExists (const std::filesystem::path &p)
 
std::vector< std::filesystem::path > getAllDirectories (const std::filesystem::path &p)
 
std::vector< std::filesystem::path > getAllFiles (const std::filesystem::path &p)
 
std::vector< unsigned char > gzipCompress (const std::vector< unsigned char > &data, int level=1)
 Compress data into a gzip container (i.e.
 
std::vector< unsigned char > gzipDecompress (const std::vector< unsigned char > &data)
 Inverse of gzipCompress. Throws if the data is not a valid gzip stream.
 
bool hasWritePermission (const std::filesystem::path &p)
 Check if directory has write permission.
 
bool isGzip (const std::vector< unsigned char > &data)
 Gzip magic bytes (0x1f 0x8b) — used to detect compressed content defensively.
 
std::vector< unsigned char > readDataFromFile (const std::filesystem::path &p)
 
std::filesystem::path toPath (const std::filesystem::path &base, const armem::MemoryID &id)
 
void writeDataToFile (const std::filesystem::path &p, const std::vector< unsigned char > &data, WriteMode mode=WriteMode::AtomicDurable)
 

Enumeration Type Documentation

◆ WriteMode

enum class WriteMode
strong

How writeDataToFile() should get the bytes onto disk.

Atomicity and durability are separate concerns and were previously bundled into one flag, which left the batch writer choosing between per-file fsyncs it could not afford and files that a crash could truncate.

Enumerator
Plain 

Truncating write in place.

Cheapest, and a crash mid-write leaves a partial file that later reads will choke on.

Atomic 

Write a temporary file and rename it over the destination.

A reader sees either the old contents or the new, never a partial file. Durability is left to the caller, who is expected to fsync the directory once it is done – which is what makes this the right mode for a batch.

AtomicDurable 

Atomic, plus fdatasync before the rename and an fsync of the directory after it, so the result survives power loss.

Definition at line 48 of file filesystem.h.

Function Documentation

◆ canCreateFiles()

bool canCreateFiles ( const std::filesystem::path & dir)

Check if we can create files in this directory.

+ Here is the caller graph for this function:

◆ directoryExists()

bool directoryExists ( const std::filesystem::path & p)
+ Here is the caller graph for this function:

◆ ensureDirectoryExists()

void ensureDirectoryExists ( const std::filesystem::path & p,
bool createIfNotExistent = false )

◆ ensureFileExists()

void ensureFileExists ( const std::filesystem::path & p,
bool createIfNotExistent = false )

◆ fileExists()

bool fileExists ( const std::filesystem::path & p)

◆ getAllDirectories()

std::vector< std::filesystem::path > getAllDirectories ( const std::filesystem::path & p)
+ Here is the caller graph for this function:

◆ getAllFiles()

std::vector< std::filesystem::path > getAllFiles ( const std::filesystem::path & p)

◆ gzipCompress()

std::vector< unsigned char > gzipCompress ( const std::vector< unsigned char > & data,
int level = 1 )

Compress data into a gzip container (i.e.

what gunzip and Python's gzip module read).

Parameters
levelzlib compression level, 1 (fastest) to 9 (smallest). Level 1 is a good default for the LTM write path: it already gets within ~10% of level 6 on Aron JSON while costing a fraction of the CPU per snapshot.
+ Here is the caller graph for this function:

◆ gzipDecompress()

std::vector< unsigned char > gzipDecompress ( const std::vector< unsigned char > & data)

Inverse of gzipCompress. Throws if the data is not a valid gzip stream.

◆ hasWritePermission()

bool hasWritePermission ( const std::filesystem::path & p)

Check if directory has write permission.

+ Here is the caller graph for this function:

◆ isGzip()

bool isGzip ( const std::vector< unsigned char > & data)

Gzip magic bytes (0x1f 0x8b) — used to detect compressed content defensively.

◆ readDataFromFile()

std::vector< unsigned char > readDataFromFile ( const std::filesystem::path & p)

◆ toPath()

std::filesystem::path toPath ( const std::filesystem::path & base,
const armem::MemoryID & id )

◆ writeDataToFile()

void writeDataToFile ( const std::filesystem::path & p,
const std::vector< unsigned char > & data,
WriteMode mode = WriteMode::AtomicDurable )