Derecho  0.9
Distributed systems toolkit for RDMA
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
persistent::FilePersistLog Class Reference

#include <FilePersistLog.hpp>

Inheritance diagram for persistent::FilePersistLog:
Inheritance graph
[legend]
Collaboration diagram for persistent::FilePersistLog:
Collaboration graph
[legend]

Public Member Functions

 FilePersistLog (const std::string &name, const std::string &dataPath) noexcept(false)
 
 FilePersistLog (const std::string &name) noexcept(false)
 
virtual ~FilePersistLog () noexcept(true)
 
virtual void append (const void *pdata, const uint64_t &size, const int64_t &ver, const HLC &mhlc) noexcept(false)
 Persistent Append. More...
 
virtual void advanceVersion (const int64_t &ver) noexcept(false)
 Advance the version number without appendding a log. More...
 
virtual int64_t getLength () noexcept(false)
 
virtual int64_t getEarliestIndex () noexcept(false)
 
virtual int64_t getLatestIndex () noexcept(false)
 
virtual int64_t getVersionIndex (const version_t &ver) noexcept(false)
 
virtual int64_t getHLCIndex (const HLC &hlc) noexcept(false)
 
virtual version_t getEarliestVersion () noexcept(false)
 
virtual version_t getLatestVersion () noexcept(false)
 
virtual const version_t getLastPersisted () noexcept(false)
 
virtual const void * getEntryByIndex (const int64_t &eno) noexcept(false)
 
virtual const void * getEntry (const version_t &ver) noexcept(false)
 MOVED TO .hpp binary search through the log, return the maximum index of the entries whose key <=. More...
 
virtual const void * getEntry (const HLC &hlc) noexcept(false)
 
virtual const version_t persist (const bool preLocked=false) noexcept(false)
 Persist the log till specified version. More...
 
virtual void trimByIndex (const int64_t &eno) noexcept(false)
 Trim the log till entry number eno, inclusively. More...
 
virtual void trim (const version_t &ver) noexcept(false)
 Trim the log till version, inclusively. More...
 
virtual void trim (const HLC &hlc) noexcept(false)
 Trim the log till HLC clock, inclusively. More...
 
virtual void truncate (const version_t &ver) noexcept(false)
 Truncate the log strictly newer than 'ver'. More...
 
virtual size_t bytes_size (const version_t &ver) noexcept(false)
 Calculate the byte size required for serialization ver - from which version the detal begins(tail log) INVALID_VERSION means to include all of the tail logs. More...
 
virtual size_t to_bytes (char *buf, const version_t &ver) noexcept(false)
 Write the serialized log bytes to the given buffer buf - the buffer to receive serialized bytes ver - from which version the detal begins(tail log) INVALID_VERSION means to include all of the tail logs. More...
 
virtual void post_object (const std::function< void(char const *const, std::size_t)> &f, const version_t &ver) noexcept(false)
 Post the serialized log bytes to a function f - the function to handle the serialzied bytes ver - from which version the detal begins(tail log) INVALID_VERSION means to include all of the tail logs. More...
 
virtual void applyLogTail (char const *v) noexcept(false)
 Check/Merge the LogTail to the existing log. More...
 
template<typename TKey , typename KeyGetter >
void trim (const TKey &key, const KeyGetter &keyGetter) noexcept(false)
 
- Public Member Functions inherited from persistent::PersistLog
 PersistLog (const std::string &name) noexcept(true)
 
virtual ~PersistLog () noexcept(true)
 

Static Public Member Functions

static const uint64_t getMinimumLatestPersistedVersion (const std::string &prefix)
 Get the minimum latest persisted version for a subgroup/shard with prefix prefix the subgroup/shard prefix the minimum latest persisted version. More...
 

Protected Member Functions

virtual void load () noexcept(false)
 
virtual void reset () noexcept(false)
 
virtual void persistMetaHeaderAtomically (MetaHeader *) noexcept(false)
 

Protected Attributes

MetaHeader m_currMetaHeader
 
MetaHeader m_persMetaHeader
 
const std::string m_sDataPath
 
const std::string m_sMetaFile
 
const std::string m_sLogFile
 
const std::string m_sDataFile
 
const uint64_t m_iMaxLogEntry
 
const uint64_t m_iMaxDataSize
 
int m_iLogFileDesc
 
int m_iDataFileDesc
 
void * m_pLog
 
void * m_pData
 
pthread_rwlock_t m_rwlock
 
pthread_mutex_t m_perslock
 

Private Member Functions

bool checkOrCreateMetaFile () noexcept(false)
 verify the existence of the meta file More...
 
bool checkOrCreateLogFile () noexcept(false)
 verify the existence of the log file More...
 
bool checkOrCreateDataFile () noexcept(false)
 verify the existence of the data file More...
 
int64_t getMinimumIndexBeyondVersion (const int64_t &ver) noexcept(false)
 Get the minimum index greater than a given version Note: no lock protected, use FPL_RDLOCK ver the given version. More...
 
size_t byteSizeOfLogEntry (const LogEntry *ple) noexcept(false)
 get the byte size of log entry Note: no lock protected, use FPL_RDLOCK ple - pointer to the log entry the number of bytes required for the serialized data. More...
 
size_t writeLogEntryToByteArray (const LogEntry *ple, char *ba) noexcept(false)
 serialize the log entry to a byte array Note: no lock protected, use FPL_RDLOCK ple - the pointer to the log entry the number of bytes written to the byte array More...
 
size_t postLogEntry (const std::function< void(char const *const, std::size_t)> &f, const LogEntry *ple) noexcept(false)
 post the log entry to a serialization function accepting a byte array Note: no lock protected, use FPL_RDLOCK f - funciton ple - pointer to the log entry the number of bytes posted. More...
 
size_t mergeLogEntryFromByteArray (const char *ba) noexcept(false)
 merge the log entry to current state. More...
 
template<typename TKey , typename KeyGetter >
int64_t binarySearch (const KeyGetter &keyGetter, const TKey &key, const int64_t &logHead, const int64_t &logTail) noexcept(false)
 binary search through the log, return the maximum index of the entries whose key <= More...
 

Additional Inherited Members

- Public Attributes inherited from persistent::PersistLog
const std::string m_sName
 
std::set< hlc_index_entry, hlc_index_entry_comphidx
 

Detailed Description

Definition at line 88 of file FilePersistLog.hpp.

Constructor & Destructor Documentation

◆ FilePersistLog() [1/2]

persistent::FilePersistLog::FilePersistLog ( const std::string &  name,
const std::string &  dataPath 
)
noexcept

Definition at line 34 of file FilePersistLog.cpp.

◆ FilePersistLog() [2/2]

persistent::FilePersistLog::FilePersistLog ( const std::string &  name)
inlinenoexcept

Definition at line 171 of file FilePersistLog.hpp.

◆ ~FilePersistLog()

persistent::FilePersistLog::~FilePersistLog ( )
virtualnoexcept

Definition at line 194 of file FilePersistLog.cpp.

Member Function Documentation

◆ advanceVersion()

void persistent::FilePersistLog::advanceVersion ( const int64_t &  ver)
virtualnoexcept

Advance the version number without appendding a log.

This is useful to create gap between versions.

Implements persistent::PersistLog.

Definition at line 293 of file FilePersistLog.cpp.

◆ append()

void persistent::FilePersistLog::append ( const void *  pdata,
const uint64_t &  size,
const int64_t &  ver,
const HLC mhlc 
)
virtualnoexcept

Persistent Append.

Parameters
pdata- serialized data to be append
size- length of the data
ver- version of the data, the implementation is responsible for making sure it grows monotonically.
mhlc- the hlc clock of the data, the implementation is responsible for making sure it grows monotonically. Note that the entry appended can only become persistent till the persist() is called on that entry.

Implements persistent::PersistLog.

Definition at line 213 of file FilePersistLog.cpp.

◆ applyLogTail()

void persistent::FilePersistLog::applyLogTail ( char const *  v)
virtualnoexcept

Check/Merge the LogTail to the existing log.

dsm - deserialization manager v - serialized log bytes to be apllied

Implements persistent::PersistLog.

Definition at line 792 of file FilePersistLog.cpp.

◆ binarySearch()

template<typename TKey , typename KeyGetter >
int64_t persistent::FilePersistLog::binarySearch ( const KeyGetter &  keyGetter,
const TKey &  key,
const int64_t &  logHead,
const int64_t &  logTail 
)
inlineprivatenoexcept

binary search through the log, return the maximum index of the entries whose key <=

Parameters
key.Note that indexes used here is 'virtual'.

[ ][ ][ ][ ][X][X][X][X][ ][ ][ ] ^logHead ^logTail

Parameters
keyGetterfunction which get the key from LogEntry
keythe key to be search
logArrlog array
lenlog length
Returns
index of the log entry found or -1 if not found.

Definition at line 308 of file FilePersistLog.hpp.

◆ bytes_size()

size_t persistent::FilePersistLog::bytes_size ( const version_t ver)
virtualnoexcept

Calculate the byte size required for serialization ver - from which version the detal begins(tail log) INVALID_VERSION means to include all of the tail logs.

Implements persistent::PersistLog.

Definition at line 742 of file FilePersistLog.cpp.

◆ byteSizeOfLogEntry()

size_t persistent::FilePersistLog::byteSizeOfLogEntry ( const LogEntry ple)
privatenoexcept

get the byte size of log entry Note: no lock protected, use FPL_RDLOCK ple - pointer to the log entry the number of bytes required for the serialized data.

Definition at line 808 of file FilePersistLog.cpp.

◆ checkOrCreateDataFile()

bool persistent::FilePersistLog::checkOrCreateDataFile ( )
privatenoexcept

verify the existence of the data file

Definition at line 915 of file FilePersistLog.cpp.

◆ checkOrCreateLogFile()

bool persistent::FilePersistLog::checkOrCreateLogFile ( )
privatenoexcept

verify the existence of the log file

Definition at line 911 of file FilePersistLog.cpp.

◆ checkOrCreateMetaFile()

bool persistent::FilePersistLog::checkOrCreateMetaFile ( )
privatenoexcept

verify the existence of the meta file

Definition at line 907 of file FilePersistLog.cpp.

◆ getEarliestIndex()

int64_t persistent::FilePersistLog::getEarliestIndex ( )
virtualnoexcept

Implements persistent::PersistLog.

Definition at line 381 of file FilePersistLog.cpp.

◆ getEarliestVersion()

version_t persistent::FilePersistLog::getEarliestVersion ( )
virtualnoexcept

Implements persistent::PersistLog.

Definition at line 395 of file FilePersistLog.cpp.

◆ getEntry() [1/2]

const void * persistent::FilePersistLog::getEntry ( const version_t ver)
virtualnoexcept

MOVED TO .hpp binary search through the log, return the maximum index of the entries whose key <=.

Parameters
key.Note that indexes used here is 'virtual'.

[ ][ ][ ][ ][X][X][X][X][ ][ ][ ] ^logHead ^logTail

Parameters
keyGetterfunction which get the key from LogEntry
keythe key to be search
logArrlog array
lenlog length
Returns
index of the log entry found or -1 if not found.

Implements persistent::PersistLog.

Definition at line 514 of file FilePersistLog.cpp.

◆ getEntry() [2/2]

const void * persistent::FilePersistLog::getEntry ( const HLC hlc)
virtualnoexcept

Implements persistent::PersistLog.

Definition at line 562 of file FilePersistLog.cpp.

◆ getEntryByIndex()

const void * persistent::FilePersistLog::getEntryByIndex ( const int64_t &  eno)
virtualnoexcept

Implements persistent::PersistLog.

Definition at line 443 of file FilePersistLog.cpp.

◆ getHLCIndex()

int64_t persistent::FilePersistLog::getHLCIndex ( const HLC hlc)
virtualnoexcept

Implements persistent::PersistLog.

Definition at line 543 of file FilePersistLog.cpp.

◆ getLastPersisted()

const version_t persistent::FilePersistLog::getLastPersisted ( )
virtualnoexcept

Implements persistent::PersistLog.

Definition at line 411 of file FilePersistLog.cpp.

◆ getLatestIndex()

int64_t persistent::FilePersistLog::getLatestIndex ( )
virtualnoexcept

Implements persistent::PersistLog.

Definition at line 388 of file FilePersistLog.cpp.

◆ getLatestVersion()

version_t persistent::FilePersistLog::getLatestVersion ( )
virtualnoexcept

Implements persistent::PersistLog.

Definition at line 403 of file FilePersistLog.cpp.

◆ getLength()

int64_t persistent::FilePersistLog::getLength ( )
virtualnoexcept

Implements persistent::PersistLog.

Definition at line 373 of file FilePersistLog.cpp.

◆ getMinimumIndexBeyondVersion()

int64_t persistent::FilePersistLog::getMinimumIndexBeyondVersion ( const int64_t &  ver)
privatenoexcept

Get the minimum index greater than a given version Note: no lock protected, use FPL_RDLOCK ver the given version.

INVALID_VERSION means to return the earliest index. the minimum index since the given version. INVALID_INDEX means that no log entry is available for the requested version.

Definition at line 689 of file FilePersistLog.cpp.

◆ getMinimumLatestPersistedVersion()

const uint64_t persistent::FilePersistLog::getMinimumLatestPersistedVersion ( const std::string &  prefix)
static

Get the minimum latest persisted version for a subgroup/shard with prefix prefix the subgroup/shard prefix the minimum latest persisted version.

Definition at line 959 of file FilePersistLog.cpp.

◆ getVersionIndex()

int64_t persistent::FilePersistLog::getVersionIndex ( const version_t ver)
virtualnoexcept

Implements persistent::PersistLog.

Definition at line 422 of file FilePersistLog.cpp.

◆ load()

void persistent::FilePersistLog::load ( )
protectedvirtualnoexcept

Definition at line 78 of file FilePersistLog.cpp.

◆ mergeLogEntryFromByteArray()

size_t persistent::FilePersistLog::mergeLogEntryFromByteArray ( const char *  ba)
privatenoexcept

merge the log entry to current state.

Note: no lock protected, use FPL_WRLOCK ba - serialize form of the entry - number of size read from the entry.

Definition at line 834 of file FilePersistLog.cpp.

◆ persist()

const int64_t persistent::FilePersistLog::persist ( const bool  preLocked = false)
virtualnoexcept

Persist the log till specified version.

Returns
- the version till which has been persisted. Note that the return value could be higher than the the version asked is lower than the log that has been actually persisted.

Implements persistent::PersistLog.

Definition at line 304 of file FilePersistLog.cpp.

◆ persistMetaHeaderAtomically()

void persistent::FilePersistLog::persistMetaHeaderAtomically ( MetaHeader pShadowHeader)
protectedvirtualnoexcept

Definition at line 665 of file FilePersistLog.cpp.

◆ post_object()

void persistent::FilePersistLog::post_object ( const std::function< void(char const *const, std::size_t)> &  f,
const version_t ver 
)
virtualnoexcept

Post the serialized log bytes to a function f - the function to handle the serialzied bytes ver - from which version the detal begins(tail log) INVALID_VERSION means to include all of the tail logs.

Implements persistent::PersistLog.

Definition at line 774 of file FilePersistLog.cpp.

◆ postLogEntry()

size_t persistent::FilePersistLog::postLogEntry ( const std::function< void(char const *const, std::size_t)> &  f,
const LogEntry ple 
)
privatenoexcept

post the log entry to a serialization function accepting a byte array Note: no lock protected, use FPL_RDLOCK f - funciton ple - pointer to the log entry the number of bytes posted.

Definition at line 823 of file FilePersistLog.cpp.

◆ reset()

void persistent::FilePersistLog::reset ( )
protectedvirtualnoexcept

Definition at line 59 of file FilePersistLog.cpp.

◆ to_bytes()

size_t persistent::FilePersistLog::to_bytes ( char *  buf,
const version_t ver 
)
virtualnoexcept

Write the serialized log bytes to the given buffer buf - the buffer to receive serialized bytes ver - from which version the detal begins(tail log) INVALID_VERSION means to include all of the tail logs.

Implements persistent::PersistLog.

Definition at line 754 of file FilePersistLog.cpp.

◆ trim() [1/3]

void persistent::FilePersistLog::trim ( const version_t ver)
virtualnoexcept

Trim the log till version, inclusively.

Parameters
ver- all log entry before ver will be trimmed.

Implements persistent::PersistLog.

Definition at line 645 of file FilePersistLog.cpp.

◆ trim() [2/3]

void persistent::FilePersistLog::trim ( const HLC hlc)
virtualnoexcept

Trim the log till HLC clock, inclusively.

Parameters
hlc- all log entry before hlc will be trimmed.

Implements persistent::PersistLog.

Definition at line 652 of file FilePersistLog.cpp.

◆ trim() [3/3]

template<typename TKey , typename KeyGetter >
void persistent::FilePersistLog::trim ( const TKey &  key,
const KeyGetter &  keyGetter 
)
inlinenoexcept

Definition at line 203 of file FilePersistLog.hpp.

◆ trimByIndex()

void persistent::FilePersistLog::trimByIndex ( const int64_t &  idx)
virtualnoexcept

Trim the log till entry number eno, inclusively.

For exmaple, there is a log: [7,8,9,4,5,6]. After trim(3), it becomes [5,6]

Parameters
eno- the log number to be trimmed

Implements persistent::PersistLog.

Definition at line 611 of file FilePersistLog.cpp.

◆ truncate()

void persistent::FilePersistLog::truncate ( const version_t ver)
virtualnoexcept

Truncate the log strictly newer than 'ver'.

Parameters
ver- all log entry strict after ver will be truncated.

Implements persistent::PersistLog.

Definition at line 919 of file FilePersistLog.cpp.

◆ writeLogEntryToByteArray()

size_t persistent::FilePersistLog::writeLogEntryToByteArray ( const LogEntry ple,
char *  ba 
)
privatenoexcept

serialize the log entry to a byte array Note: no lock protected, use FPL_RDLOCK ple - the pointer to the log entry the number of bytes written to the byte array

Definition at line 812 of file FilePersistLog.cpp.

Member Data Documentation

◆ m_currMetaHeader

MetaHeader persistent::FilePersistLog::m_currMetaHeader
protected

Definition at line 91 of file FilePersistLog.hpp.

◆ m_iDataFileDesc

int persistent::FilePersistLog::m_iDataFileDesc
protected

Definition at line 110 of file FilePersistLog.hpp.

◆ m_iLogFileDesc

int persistent::FilePersistLog::m_iLogFileDesc
protected

Definition at line 108 of file FilePersistLog.hpp.

◆ m_iMaxDataSize

const uint64_t persistent::FilePersistLog::m_iMaxDataSize
protected

Definition at line 105 of file FilePersistLog.hpp.

◆ m_iMaxLogEntry

const uint64_t persistent::FilePersistLog::m_iMaxLogEntry
protected

Definition at line 103 of file FilePersistLog.hpp.

◆ m_pData

void* persistent::FilePersistLog::m_pData
protected

Definition at line 115 of file FilePersistLog.hpp.

◆ m_perslock

pthread_mutex_t persistent::FilePersistLog::m_perslock
protected

Definition at line 119 of file FilePersistLog.hpp.

◆ m_persMetaHeader

MetaHeader persistent::FilePersistLog::m_persMetaHeader
protected

Definition at line 93 of file FilePersistLog.hpp.

◆ m_pLog

void* persistent::FilePersistLog::m_pLog
protected

Definition at line 113 of file FilePersistLog.hpp.

◆ m_rwlock

pthread_rwlock_t persistent::FilePersistLog::m_rwlock
protected

Definition at line 117 of file FilePersistLog.hpp.

◆ m_sDataFile

const std::string persistent::FilePersistLog::m_sDataFile
protected

Definition at line 101 of file FilePersistLog.hpp.

◆ m_sDataPath

const std::string persistent::FilePersistLog::m_sDataPath
protected

Definition at line 95 of file FilePersistLog.hpp.

◆ m_sLogFile

const std::string persistent::FilePersistLog::m_sLogFile
protected

Definition at line 99 of file FilePersistLog.hpp.

◆ m_sMetaFile

const std::string persistent::FilePersistLog::m_sMetaFile
protected

Definition at line 97 of file FilePersistLog.hpp.


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