Derecho  0.9
Distributed systems toolkit for RDMA
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
persistent::Persistent< ObjectType, storageType > Class Template Reference

#include <Persistent.hpp>

Inheritance diagram for persistent::Persistent< ObjectType, storageType >:
Inheritance graph
[legend]
Collaboration diagram for persistent::Persistent< ObjectType, storageType >:
Collaboration graph
[legend]

Public Member Functions

 Persistent (const std::function< std::unique_ptr< ObjectType >(void)> &object_factory, const char *object_name=nullptr, PersistentRegistry *persistent_registry=nullptr, mutils::DeserializationManager dm={{}}) noexcept(false)
 constructor 1 is for building a persistent<T> locally, load/create a log and register itself to a persistent registry. More...
 
 Persistent (Persistent &&other) noexcept(false)
 constructor 2 is move constructor. More...
 
 Persistent (const char *object_name, std::unique_ptr< ObjectType > &wrapped_obj_ptr, const char *log_tail=nullptr, PersistentRegistry *persistent_registry=nullptr, mutils::DeserializationManager dm={{}}) noexcept(false)
 constructor 3 is for deserialization. More...
 
 Persistent (const Persistent &)=delete
 constructor 4, the default copy constructor, is disabled More...
 
virtual ~Persistent () noexcept(true)
 destructor: release the resources More...
 
ObjectType & operator* ()
 
ObjectType * operator-> ()
 overload the '->' operator to access the wrapped object More...
 
const ObjectType & getConstRef () const
 get a const reference to the wrapped object More...
 
const std::string & getObjectName ()
 get object name More...
 
template<typename Func >
auto get (const Func &fun, mutils::DeserializationManager *dm=nullptr) noexcept(false)
 get the latest Value of T. More...
 
std::unique_ptr< ObjectType > get (mutils::DeserializationManager *dm=nullptr)
 get the latest Value of T, returns a unique pointer to the object More...
 
template<typename Func >
auto getByIndex (int64_t idx, const Func &fun, mutils::DeserializationManager *dm=nullptr) noexcept(false)
 get a version of Value T. More...
 
std::unique_ptr< ObjectType > getByIndex (int64_t idx, mutils::DeserializationManager *dm=nullptr) noexcept(false)
 get a version of value T. More...
 
template<typename Func >
auto get (const int64_t &ver, const Func &fun, mutils::DeserializationManager *dm=nullptr) noexcept(false)
 get a version of Value T, specified by version. More...
 
std::unique_ptr< ObjectType > get (const int64_t &ver, mutils::DeserializationManager *dm=nullptr) noexcept(false)
 get a version of value T. More...
 
template<typename TKey >
void trim (const TKey &k) noexcept(false)
 trim by version or index More...
 
void truncate (const int64_t &ver)
 truncate the log More...
 
template<typename Func >
auto get (const HLC &hlc, const Func &fun, mutils::DeserializationManager *dm=nullptr) noexcept(false)
 get a version of Value T, specified by HLC clock. More...
 
std::unique_ptr< ObjectType > get (const HLC &hlc, mutils::DeserializationManager *dm=nullptr) noexcept(false)
 get a version of value T. More...
 
std::unique_ptr< ObjectType > operator[] (const int64_t ver) noexcept(false)
 syntax sugar: get a specified version of T without DSM More...
 
std::unique_ptr< ObjectType > operator[] (const HLC &hlc) noexcept(false)
 syntax sugar: get a specified version of T without DSM More...
 
virtual int64_t getNumOfVersions () noexcept(false)
 get the number of versions excluding trimmed ones. More...
 
virtual int64_t getEarliestIndex () noexcept(false)
 get the earliest index excluding trimmed ones. More...
 
virtual int64_t getEarliestVersion () noexcept(false)
 get the earliest version excluding trimmed ones. More...
 
virtual int64_t getLatestIndex () noexcept(false)
 get the latest index excluding truncated ones. More...
 
virtual int64_t getLatestVersion () noexcept(false)
 get the lastest version excluding truncated ones. More...
 
virtual const int64_t getLastPersisted () noexcept(false)
 get the last persisted index. More...
 
virtual void set (ObjectType &v, const version_t &ver, const HLC &mhlc) noexcept(false)
 make a version with a version number and mhlc clock More...
 
virtual void set (ObjectType &v, const version_t &ver) noexcept(false)
 make a version with only a version number More...
 
virtual void version (const version_t &ver) noexcept(false)
 make a version with only a version number, using the current state. More...
 
virtual const int64_t persist () noexcept(false)
 persist till version More...
 
std::size_t to_bytes (char *ret) const
 Write this class's marshalled representation into the array found at v. More...
 
std::size_t bytes_size () const
 the size of the marshalled representation of this object. More...
 
void post_object (const std::function< void(char const *const, std::size_t)> &f) const
 Pass a pointer to a buffer containing this class's marshalled representation into the function f. More...
 
virtual void ensure_registered (mutils::DeserializationManager &)
 
void applyLogTail (mutils::DeserializationManager *dsm, char const *v)
 
virtual void print_performance_stat ()
 
- Public Member Functions inherited from mutils::ByteRepresentable
virtual ~ByteRepresentable ()
 

Static Public Member Functions

static std::unique_ptr< Persistentfrom_bytes (mutils::DeserializationManager *dsm, char const *v)
 

Public Attributes

std::unique_ptr< ObjectType > m_pWrappedObject
 
uint64_t ns_in_persist = 0ul
 
uint64_t ns_in_set = 0ul
 
uint64_t cnt_in_persist = 0ul
 
uint64_t cnt_in_set = 0ul
 

Protected Member Functions

void initialize_log (const char *object_name) noexcept(false)
 initialize from local state. More...
 
void initialize_object_from_log (const std::function< std::unique_ptr< ObjectType >(void)> &object_factory, mutils::DeserializationManager *dm)
 initialize the object from log More...
 
void register_callbacks () noexcept(false)
 register the callbacks. More...
 
void unregister_callbacks () noexcept(false)
 unregister the callbacks. More...
 

Static Protected Member Functions

static _NameMaker< ObjectType, storageType > & getNameMaker (const std::string &prefix=std::string(""))
 

Protected Attributes

std::unique_ptr< PersistLogm_pLog
 
PersistentRegistrym_pRegistry
 

Detailed Description

template<typename ObjectType, StorageType storageType = ST_FILE>
class persistent::Persistent< ObjectType, storageType >

Definition at line 320 of file Persistent.hpp.

Constructor & Destructor Documentation

◆ Persistent() [1/4]

template<typename ObjectType, StorageType storageType>
persistent::Persistent< ObjectType, storageType >::Persistent ( const std::function< std::unique_ptr< ObjectType >(void)> &  object_factory,
const char *  object_name = nullptr,
PersistentRegistry persistent_registry = nullptr,
mutils::DeserializationManager  dm = {{}} 
)
noexcept

constructor 1 is for building a persistent<T> locally, load/create a log and register itself to a persistent registry.

Parameters
object_factoryA factory to create an empty Object.
object_nameThis name is used for persistent data in file.
persistent_registryA normal pointer to the registry.
dmThe deserialization manager for deserializing local log entries.

Definition at line 146 of file Persistent_impl.hpp.

◆ Persistent() [2/4]

template<typename ObjectType, StorageType storageType>
persistent::Persistent< ObjectType, storageType >::Persistent ( Persistent< ObjectType, storageType > &&  other)
noexcept

constructor 2 is move constructor.

It "steals" the resource from another object.

Parameters
otherThe other object.

Definition at line 162 of file Persistent_impl.hpp.

◆ Persistent() [3/4]

template<typename ObjectType, StorageType storageType>
persistent::Persistent< ObjectType, storageType >::Persistent ( const char *  object_name,
std::unique_ptr< ObjectType > &  wrapped_obj_ptr,
const char *  log_tail = nullptr,
PersistentRegistry persistent_registry = nullptr,
mutils::DeserializationManager  dm = {{}} 
)
noexcept

constructor 3 is for deserialization.

It builds a Persistent<T> from the object name, a unique_ptr to the wrapped object, a unique_ptr to the log.

Parameters
object_nameThe name is used for persistent data in file.
wrapped_obj_ptrA unique pointer to the wrapped object.
log_ptrA unique pointer to the log.
dmThe deserialization manager for deserializing local log entries.

Definition at line 171 of file Persistent_impl.hpp.

◆ Persistent() [4/4]

template<typename ObjectType, StorageType storageType = ST_FILE>
persistent::Persistent< ObjectType, storageType >::Persistent ( const Persistent< ObjectType, storageType > &  )
delete

constructor 4, the default copy constructor, is disabled

◆ ~Persistent()

template<typename ObjectType , StorageType storageType>
persistent::Persistent< ObjectType, storageType >::~Persistent ( )
virtualnoexcept

destructor: release the resources

Definition at line 193 of file Persistent_impl.hpp.

Member Function Documentation

◆ applyLogTail()

template<typename ObjectType , StorageType storageType>
void persistent::Persistent< ObjectType, storageType >::applyLogTail ( mutils::DeserializationManager dsm,
char const *  v 
)

Definition at line 546 of file Persistent_impl.hpp.

◆ bytes_size()

template<typename ObjectType , StorageType storageType>
std::size_t persistent::Persistent< ObjectType, storageType >::bytes_size ( ) const
virtual

the size of the marshalled representation of this object.

useful when allocating arrays in which to store this object.

NOTE: it is recommended that users not call this directly, and prefer to use mutils::bytes_size(T,v) instead.

Implements mutils::ByteRepresentable.

Definition at line 510 of file Persistent_impl.hpp.

◆ ensure_registered()

template<typename ObjectType, StorageType storageType = ST_FILE>
virtual void persistent::Persistent< ObjectType, storageType >::ensure_registered ( mutils::DeserializationManager )
inlinevirtual

Definition at line 585 of file Persistent.hpp.

◆ from_bytes()

template<typename ObjectType , StorageType storageType>
std::unique_ptr< Persistent< ObjectType, storageType > > persistent::Persistent< ObjectType, storageType >::from_bytes ( mutils::DeserializationManager dsm,
char const *  v 
)
static

Definition at line 525 of file Persistent_impl.hpp.

◆ get() [1/6]

template<typename ObjectType , StorageType storageType>
template<typename Func >
auto persistent::Persistent< ObjectType, storageType >::get ( const Func &  fun,
mutils::DeserializationManager dm = nullptr 
)
noexcept

get the latest Value of T.

The user lambda will be fed with the latest object zerocopy:this object will not live once it returns. return value is decided by user lambda

Definition at line 232 of file Persistent_impl.hpp.

◆ get() [2/6]

template<typename ObjectType , StorageType storageType>
std::unique_ptr< ObjectType > persistent::Persistent< ObjectType, storageType >::get ( mutils::DeserializationManager dm = nullptr)
noexcept

get the latest Value of T, returns a unique pointer to the object

Definition at line 240 of file Persistent_impl.hpp.

◆ get() [3/6]

template<typename ObjectType , StorageType storageType>
template<typename Func >
auto persistent::Persistent< ObjectType, storageType >::get ( const int64_t &  ver,
const Func &  fun,
mutils::DeserializationManager dm = nullptr 
)
noexcept

get a version of Value T, specified by version.

the user lambda will be fed with an object of T. zerocopy: this object will not live once it returns. return value is decided by the user lambda.

Definition at line 286 of file Persistent_impl.hpp.

◆ get() [4/6]

template<typename ObjectType , StorageType storageType>
std::unique_ptr< ObjectType > persistent::Persistent< ObjectType, storageType >::get ( const int64_t &  ver,
mutils::DeserializationManager dm = nullptr 
)
noexcept

get a version of value T.

specified version. return a deserialized copy for the variable.

Definition at line 306 of file Persistent_impl.hpp.

◆ get() [5/6]

template<typename ObjectType , StorageType storageType>
template<typename Func >
auto persistent::Persistent< ObjectType, storageType >::get ( const HLC hlc,
const Func &  fun,
mutils::DeserializationManager dm = nullptr 
)
noexcept

get a version of Value T, specified by HLC clock.

the user lambda will be fed with an object of T. zerocopy: this object will not live once it returns. return value is decided by the user lambda.

Definition at line 343 of file Persistent_impl.hpp.

◆ get() [6/6]

template<typename ObjectType , StorageType storageType>
std::unique_ptr< ObjectType > persistent::Persistent< ObjectType, storageType >::get ( const HLC hlc,
mutils::DeserializationManager dm = nullptr 
)
noexcept

get a version of value T.

specified by HLC clock.

Definition at line 371 of file Persistent_impl.hpp.

◆ getByIndex() [1/2]

template<typename ObjectType , StorageType storageType>
template<typename Func >
auto persistent::Persistent< ObjectType, storageType >::getByIndex ( int64_t  idx,
const Func &  fun,
mutils::DeserializationManager dm = nullptr 
)
noexcept

get a version of Value T.

the user lambda will be fed with the given object zerocopy:this object will not live once it returns. return value is decided by user lambda

Definition at line 248 of file Persistent_impl.hpp.

◆ getByIndex() [2/2]

template<typename ObjectType , StorageType storageType>
std::unique_ptr< ObjectType > persistent::Persistent< ObjectType, storageType >::getByIndex ( int64_t  idx,
mutils::DeserializationManager dm = nullptr 
)
noexcept

get a version of value T.

returns a unique pointer to the object

Definition at line 263 of file Persistent_impl.hpp.

◆ getConstRef()

template<typename ObjectType , StorageType storageType>
const ObjectType & persistent::Persistent< ObjectType, storageType >::getConstRef ( ) const

get a const reference to the wrapped object

Returns
const ObjectType&

Definition at line 219 of file Persistent_impl.hpp.

◆ getEarliestIndex()

template<typename ObjectType , StorageType storageType>
int64_t persistent::Persistent< ObjectType, storageType >::getEarliestIndex ( )
virtualnoexcept

get the earliest index excluding trimmed ones.

Definition at line 403 of file Persistent_impl.hpp.

◆ getEarliestVersion()

template<typename ObjectType , StorageType storageType>
int64_t persistent::Persistent< ObjectType, storageType >::getEarliestVersion ( )
virtualnoexcept

get the earliest version excluding trimmed ones.

Definition at line 409 of file Persistent_impl.hpp.

◆ getLastPersisted()

template<typename ObjectType , StorageType storageType>
const int64_t persistent::Persistent< ObjectType, storageType >::getLastPersisted ( )
virtualnoexcept

get the last persisted index.

Definition at line 427 of file Persistent_impl.hpp.

◆ getLatestIndex()

template<typename ObjectType , StorageType storageType>
int64_t persistent::Persistent< ObjectType, storageType >::getLatestIndex ( )
virtualnoexcept

get the latest index excluding truncated ones.

Definition at line 415 of file Persistent_impl.hpp.

◆ getLatestVersion()

template<typename ObjectType , StorageType storageType>
int64_t persistent::Persistent< ObjectType, storageType >::getLatestVersion ( )
virtualnoexcept

get the lastest version excluding truncated ones.

Definition at line 421 of file Persistent_impl.hpp.

◆ getNameMaker()

template<typename ObjectType , StorageType storageType>
_NameMaker< ObjectType, storageType > & persistent::Persistent< ObjectType, storageType >::getNameMaker ( const std::string &  prefix = std::string(""))
staticprotectednoexcept

Definition at line 567 of file Persistent_impl.hpp.

◆ getNumOfVersions()

template<typename ObjectType , StorageType storageType>
int64_t persistent::Persistent< ObjectType, storageType >::getNumOfVersions ( )
virtualnoexcept

get the number of versions excluding trimmed ones.

Definition at line 397 of file Persistent_impl.hpp.

◆ getObjectName()

template<typename ObjectType , StorageType storageType>
const std::string & persistent::Persistent< ObjectType, storageType >::getObjectName ( )

get object name

Definition at line 225 of file Persistent_impl.hpp.

◆ initialize_log()

template<typename ObjectType , StorageType storageType>
void persistent::Persistent< ObjectType, storageType >::initialize_log ( const char *  object_name)
inlineprotectednoexcept

initialize from local state.

Parameters
object_nameObject name

Definition at line 83 of file Persistent_impl.hpp.

◆ initialize_object_from_log()

template<typename ObjectType, StorageType storageType>
void persistent::Persistent< ObjectType, storageType >::initialize_object_from_log ( const std::function< std::unique_ptr< ObjectType >(void)> &  object_factory,
mutils::DeserializationManager dm 
)
inlineprotected

initialize the object from log

Definition at line 111 of file Persistent_impl.hpp.

◆ operator*()

template<typename ObjectType , StorageType storageType>
ObjectType & persistent::Persistent< ObjectType, storageType >::operator* ( )
  • operator to get the memory version
    Returns
    ObjectType&

Definition at line 207 of file Persistent_impl.hpp.

◆ operator->()

template<typename ObjectType , StorageType storageType>
ObjectType * persistent::Persistent< ObjectType, storageType >::operator-> ( )

overload the '->' operator to access the wrapped object

Definition at line 213 of file Persistent_impl.hpp.

◆ operator[]() [1/2]

template<typename ObjectType, StorageType storageType = ST_FILE>
std::unique_ptr<ObjectType> persistent::Persistent< ObjectType, storageType >::operator[] ( const int64_t  ver)
inlinenoexcept

syntax sugar: get a specified version of T without DSM

Definition at line 493 of file Persistent.hpp.

◆ operator[]() [2/2]

template<typename ObjectType, StorageType storageType = ST_FILE>
std::unique_ptr<ObjectType> persistent::Persistent< ObjectType, storageType >::operator[] ( const HLC hlc)
inlinenoexcept

syntax sugar: get a specified version of T without DSM

Definition at line 500 of file Persistent.hpp.

◆ persist()

template<typename ObjectType , StorageType storageType>
const int64_t persistent::Persistent< ObjectType, storageType >::persist ( )
virtualnoexcept

persist till version

Parameters
verversion number
Returns
the given version to be persisted.

Definition at line 478 of file Persistent_impl.hpp.

◆ post_object()

template<typename ObjectType , StorageType storageType>
void persistent::Persistent< ObjectType, storageType >::post_object ( const std::function< void(char const *const, std::size_t)> &  ) const
virtual

Pass a pointer to a buffer containing this class's marshalled representation into the function f.

This pointer is not guaranteed to live beyond the duration of the call to f, so make a copy if you need to keep it around.

NOTE: it is recommended that users not call this directly, and prefer to use mutils::post_object(f,T) instead.

Implements mutils::ByteRepresentable.

Definition at line 516 of file Persistent_impl.hpp.

◆ print_performance_stat()

template<typename ObjectType, StorageType storageType = ST_FILE>
virtual void persistent::Persistent< ObjectType, storageType >::print_performance_stat ( )
virtual

◆ register_callbacks()

template<typename ObjectType , StorageType storageType>
void persistent::Persistent< ObjectType, storageType >::register_callbacks ( )
inlineprotectednoexcept

register the callbacks.

Definition at line 123 of file Persistent_impl.hpp.

◆ set() [1/2]

template<typename ObjectType, StorageType storageType>
void persistent::Persistent< ObjectType, storageType >::set ( ObjectType &  v,
const version_t ver,
const HLC mhlc 
)
virtualnoexcept

make a version with a version number and mhlc clock

Definition at line 433 of file Persistent_impl.hpp.

◆ set() [2/2]

template<typename ObjectType, StorageType storageType>
void persistent::Persistent< ObjectType, storageType >::set ( ObjectType &  v,
const version_t ver 
)
virtualnoexcept

make a version with only a version number

Definition at line 454 of file Persistent_impl.hpp.

◆ to_bytes()

template<typename ObjectType , StorageType storageType>
std::size_t persistent::Persistent< ObjectType, storageType >::to_bytes ( char *  v) const
virtual

Write this class's marshalled representation into the array found at v.

assume v has at least bytes_size() of free memory available; behavior is undefined otherwise.

Returns number of bytes written, which should be the same as bytes_size().

NOTE: it is recommended that users not call this directly, and prefer to use mutils::to_bytes(T,v) instead.

Implements mutils::ByteRepresentable.

Definition at line 494 of file Persistent_impl.hpp.

◆ trim()

template<typename ObjectType , StorageType storageType>
template<typename TKey >
void persistent::Persistent< ObjectType, storageType >::trim ( const TKey &  k)
noexcept

trim by version or index

Definition at line 326 of file Persistent_impl.hpp.

◆ truncate()

template<typename ObjectType , StorageType storageType>
void persistent::Persistent< ObjectType, storageType >::truncate ( const int64_t &  ver)

truncate the log

Parameters
verall versions strictly newer than 'ver' will be truncated.

Definition at line 334 of file Persistent_impl.hpp.

◆ unregister_callbacks()

template<typename ObjectType , StorageType storageType>
void persistent::Persistent< ObjectType, storageType >::unregister_callbacks ( )
inlineprotectednoexcept

unregister the callbacks.

Definition at line 138 of file Persistent_impl.hpp.

◆ version()

template<typename ObjectType , StorageType storageType>
void persistent::Persistent< ObjectType, storageType >::version ( const version_t ver)
virtualnoexcept

make a version with only a version number, using the current state.

Definition at line 471 of file Persistent_impl.hpp.

Member Data Documentation

◆ cnt_in_persist

template<typename ObjectType, StorageType storageType = ST_FILE>
uint64_t persistent::Persistent< ObjectType, storageType >::cnt_in_persist = 0ul

Definition at line 594 of file Persistent.hpp.

◆ cnt_in_set

template<typename ObjectType, StorageType storageType = ST_FILE>
uint64_t persistent::Persistent< ObjectType, storageType >::cnt_in_set = 0ul

Definition at line 595 of file Persistent.hpp.

◆ m_pLog

template<typename ObjectType, StorageType storageType = ST_FILE>
std::unique_ptr<PersistLog> persistent::Persistent< ObjectType, storageType >::m_pLog
protected

Definition at line 561 of file Persistent.hpp.

◆ m_pRegistry

template<typename ObjectType, StorageType storageType = ST_FILE>
PersistentRegistry* persistent::Persistent< ObjectType, storageType >::m_pRegistry
protected

Definition at line 563 of file Persistent.hpp.

◆ m_pWrappedObject

template<typename ObjectType, StorageType storageType = ST_FILE>
std::unique_ptr<ObjectType> persistent::Persistent< ObjectType, storageType >::m_pWrappedObject

Definition at line 557 of file Persistent.hpp.

◆ ns_in_persist

template<typename ObjectType, StorageType storageType = ST_FILE>
uint64_t persistent::Persistent< ObjectType, storageType >::ns_in_persist = 0ul

Definition at line 592 of file Persistent.hpp.

◆ ns_in_set

template<typename ObjectType, StorageType storageType = ST_FILE>
uint64_t persistent::Persistent< ObjectType, storageType >::ns_in_set = 0ul

Definition at line 593 of file Persistent.hpp.


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