#include <FilePersistLog.hpp>
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_comp > | hidx |
Definition at line 88 of file FilePersistLog.hpp.
|
noexcept |
Definition at line 34 of file FilePersistLog.cpp.
|
inlinenoexcept |
Definition at line 171 of file FilePersistLog.hpp.
|
virtualnoexcept |
Definition at line 194 of file FilePersistLog.cpp.
|
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.
|
virtualnoexcept |
Persistent Append.
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.
|
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.
|
inlineprivatenoexcept |
binary search through the log, return the maximum index of the entries whose key <=
key. | Note that indexes used here is 'virtual'. |
[ ][ ][ ][ ][X][X][X][X][ ][ ][ ] ^logHead ^logTail
keyGetter | function which get the key from LogEntry |
key | the key to be search |
logArr | log array |
len | log length |
Definition at line 308 of file FilePersistLog.hpp.
|
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.
|
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.
|
privatenoexcept |
verify the existence of the data file
Definition at line 915 of file FilePersistLog.cpp.
|
privatenoexcept |
verify the existence of the log file
Definition at line 911 of file FilePersistLog.cpp.
|
privatenoexcept |
verify the existence of the meta file
Definition at line 907 of file FilePersistLog.cpp.
|
virtualnoexcept |
Implements persistent::PersistLog.
Definition at line 381 of file FilePersistLog.cpp.
|
virtualnoexcept |
Implements persistent::PersistLog.
Definition at line 395 of file FilePersistLog.cpp.
|
virtualnoexcept |
MOVED TO .hpp binary search through the log, return the maximum index of the entries whose key <=.
key. | Note that indexes used here is 'virtual'. |
[ ][ ][ ][ ][X][X][X][X][ ][ ][ ] ^logHead ^logTail
keyGetter | function which get the key from LogEntry |
key | the key to be search |
logArr | log array |
len | log length |
Implements persistent::PersistLog.
Definition at line 514 of file FilePersistLog.cpp.
|
virtualnoexcept |
Implements persistent::PersistLog.
Definition at line 562 of file FilePersistLog.cpp.
|
virtualnoexcept |
Implements persistent::PersistLog.
Definition at line 443 of file FilePersistLog.cpp.
|
virtualnoexcept |
Implements persistent::PersistLog.
Definition at line 543 of file FilePersistLog.cpp.
|
virtualnoexcept |
Implements persistent::PersistLog.
Definition at line 411 of file FilePersistLog.cpp.
|
virtualnoexcept |
Implements persistent::PersistLog.
Definition at line 388 of file FilePersistLog.cpp.
|
virtualnoexcept |
Implements persistent::PersistLog.
Definition at line 403 of file FilePersistLog.cpp.
|
virtualnoexcept |
Implements persistent::PersistLog.
Definition at line 373 of file FilePersistLog.cpp.
|
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.
|
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.
|
virtualnoexcept |
Implements persistent::PersistLog.
Definition at line 422 of file FilePersistLog.cpp.
|
protectedvirtualnoexcept |
Definition at line 78 of file FilePersistLog.cpp.
|
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.
|
virtualnoexcept |
Persist the log till specified version.
Implements persistent::PersistLog.
Definition at line 304 of file FilePersistLog.cpp.
|
protectedvirtualnoexcept |
Definition at line 665 of file FilePersistLog.cpp.
|
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.
|
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.
|
protectedvirtualnoexcept |
Definition at line 59 of file FilePersistLog.cpp.
|
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.
|
virtualnoexcept |
Trim the log till version, inclusively.
ver | - all log entry before ver will be trimmed. |
Implements persistent::PersistLog.
Definition at line 645 of file FilePersistLog.cpp.
|
virtualnoexcept |
Trim the log till HLC clock, inclusively.
hlc | - all log entry before hlc will be trimmed. |
Implements persistent::PersistLog.
Definition at line 652 of file FilePersistLog.cpp.
|
inlinenoexcept |
Definition at line 203 of file FilePersistLog.hpp.
|
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]
eno | - the log number to be trimmed |
Implements persistent::PersistLog.
Definition at line 611 of file FilePersistLog.cpp.
|
virtualnoexcept |
Truncate the log strictly newer than 'ver'.
ver | - all log entry strict after ver will be truncated. |
Implements persistent::PersistLog.
Definition at line 919 of file FilePersistLog.cpp.
|
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.
|
protected |
Definition at line 91 of file FilePersistLog.hpp.
|
protected |
Definition at line 110 of file FilePersistLog.hpp.
|
protected |
Definition at line 108 of file FilePersistLog.hpp.
|
protected |
Definition at line 105 of file FilePersistLog.hpp.
|
protected |
Definition at line 103 of file FilePersistLog.hpp.
|
protected |
Definition at line 115 of file FilePersistLog.hpp.
|
protected |
Definition at line 119 of file FilePersistLog.hpp.
|
protected |
Definition at line 93 of file FilePersistLog.hpp.
|
protected |
Definition at line 113 of file FilePersistLog.hpp.
|
protected |
Definition at line 117 of file FilePersistLog.hpp.
|
protected |
Definition at line 101 of file FilePersistLog.hpp.
|
protected |
Definition at line 95 of file FilePersistLog.hpp.
|
protected |
Definition at line 99 of file FilePersistLog.hpp.
|
protected |
Definition at line 97 of file FilePersistLog.hpp.