LMDBAL 0.5.4
LMDB (Lightning Memory-Mapped Database Manager) Abstraction Layer
Loading...
Searching...
No Matches
LMDBAL::Cache< K, V > Class Template Reference

Storage with additional caching in std::map. More...

#include <cache.hpp>

Inheritance diagram for LMDBAL::Cache< K, V >:
LMDBAL::Storage< K, V > LMDBAL::iStorage

Public Member Functions

virtual int drop (const WriteTransaction &transaction) override
 Drops content of a storage interface (public transaction variant)
 
virtual void addRecord (const K &key, const V &value) override
 Adds a key-value record to the storage.
 
virtual bool forceRecord (const K &key, const V &value) override
 Adds a key-value record to the storage, overwrites if it already exists.
 
virtual void changeRecord (const K &key, const V &value) override
 Changes key-value record to the storage.
 
virtual void removeRecord (const K &key) override
 Removes one of the records.
 
virtual bool checkRecord (const K &key) const override
 Chechs if storage has value.
 
virtual void getRecord (const K &key, V &out) const override
 Gets the record from the database (reference variant)
 
virtual V getRecord (const K &key) const override
 Gets the record from the database.
 
virtual SizeType count () const override
 Storage size.
 
virtual std::map< K, V > readAll () const override
 Reads whole storage into a map.
 
virtual void readAll (std::map< K, V > &out) const override
 Reads whole storage into a map (reference variant)
 
virtual void replaceAll (const std::map< K, V > &data) override
 Replaces the content of the whole storage with the given.
 
virtual SizeType addRecords (const std::map< K, V > &data, bool overwrite=false) override
 Adds records in bulk.
 
- Public Member Functions inherited from LMDBAL::Storage< K, V >
virtual void addRecord (const K &key, const V &value, const WriteTransaction &txn)
 Adds a key-value record to the storage (public transaction variant)
 
virtual bool forceRecord (const K &key, const V &value, const WriteTransaction &txn)
 Adds a key-value record to the storage, overwrites if it already exists (public transaction variant)
 
virtual void changeRecord (const K &key, const V &value, const WriteTransaction &txn)
 Changes key-value record to the storage (public transaction variant)
 
virtual void removeRecord (const K &key, const WriteTransaction &txn)
 Removes one of the records (transaction variant)
 
virtual bool checkRecord (const K &key, const Transaction &txn) const
 Chechs if storage has value (public transaction variant)
 
virtual void getRecord (const K &key, V &value, const Transaction &txn) const
 Gets the record from the database (public transaction, reference variant)
 
virtual V getRecord (const K &key, const Transaction &txn) const
 Gets the record from the database (public transaction variant)
 
virtual std::map< K, V > readAll (const Transaction &txn) const
 Reads whole storage into a map (public transaction variant)
 
virtual void readAll (std::map< K, V > &result, const Transaction &txn) const
 Reads whole storage into a map (public transaction, reference variant)
 
virtual void replaceAll (const std::map< K, V > &data, const WriteTransaction &txn)
 Replaces the content of the whole storage with the given (public transaction variant)
 
virtual uint32_t addRecords (const std::map< K, V > &data, const WriteTransaction &txn, bool overwrite=false)
 Adds records in bulk (public transaction variant)
 
Cursor< K, V > createCursor ()
 Creates cursor.
 
void destroyCursor (Cursor< K, V > &cursor)
 Frees cursor.
 
virtual int drop (TransactionID transaction)
 Drops content of a storage interface (transaction variant)
 
virtual void drop ()
 Drops content of a storage interface.
 
virtual int drop (const WriteTransaction &txn)
 Drops content of a storage interface (public transaction variant)
 
- Public Member Functions inherited from LMDBAL::iStorage
virtual SizeType count (const Transaction &txn) const
 Storage size (public transaction variant)
 
template<>
std::string toString (const QString &value)
 A method to cast a value (which can be a value or a key) to string.
 
template<>
std::string toString (const std::string &value)
 A method to cast a value (which can be a value or a key) to string.
 

Protected Member Functions

 Cache (Base *parent, const std::string &name, bool duplicates=false)
 Creates a cache.
 
 ~Cache () override
 Destroys a cache.
 
virtual void handleDrop () override
 A method where database additionally handles drop.
 
virtual void transactionStarted (TransactionID txn, bool readOnly) const override
 called on beginning of public transaction
 
virtual void transactionCommited (TransactionID txn) override
 called on commitment of public transaction
 
virtual void transactionAborted (TransactionID txn) const override
 called on abortion of public transaction
 
virtual void discoveredRecord (const K &key, const V &value) const override
 A private virtual method that cursor calls when he reads a record, does nothing here but populates the LMDBAL::Cache.
 
virtual void discoveredRecord (const K &key, const V &value, TransactionID txn) const override
 A private virtual method that cursor calls when he reads a record, does nothing here but populates the LMDBAL::Cache.
 
virtual SizeType count (TransactionID txn) const override
 Storage size (private transaction variant)
 
virtual void addRecord (const K &key, const V &value, TransactionID txn) override
 Adds a key-value record to the storage (private transaction variant)
 
virtual bool forceRecord (const K &key, const V &value, TransactionID txn) override
 Adds a key-value record to the storage, overwrites if it already exists (private transaction variant)
 
virtual void changeRecord (const K &key, const V &value, TransactionID txn) override
 Changes key-value record to the storage (private transaction variant)
 
virtual void removeRecord (const K &key, TransactionID txn) override
 Removes one of the records (private transaction variant)
 
virtual bool checkRecord (const K &key, TransactionID txn) const override
 Chechs if storage has value (private transaction variant)
 
virtual void getRecord (const K &key, V &out, TransactionID txn) const override
 Gets the record from the database (private transaction, reference variant)
 
virtual V getRecord (const K &key, TransactionID txn) const override
 Gets the record from the database (private transaction variant)
 
virtual std::map< K, V > readAll (TransactionID txn) const override
 Reads whole storage into a map (private transaction variant)
 
virtual void readAll (std::map< K, V > &out, TransactionID txn) const override
 Reads whole storage into a map (private transaction, reference variant)
 
virtual void replaceAll (const std::map< K, V > &data, TransactionID txn) override
 Replaces the content of the whole storage with the given (private transaction variant)
 
virtual SizeType addRecords (const std::map< K, V > &data, TransactionID txn, bool overwrite=false) override
 Adds records in bulk (private transaction variant)
 
- Protected Member Functions inherited from LMDBAL::Storage< K, V >
 Storage (Base *parent, const std::string &name, bool duplicates=false)
 Creates a storage.
 
 ~Storage () override
 Destroys a storage.
 
uint32_t flags () const
 Reads current storage flags it was opened with.
 
int open (MDB_txn *transaction) override
 A private virtual method I need to open each storage in the database.
 
void close () override
 A private virtual method I need to close each storage in the database.
 
- Protected Member Functions inherited from LMDBAL::iStorage
 iStorage (Base *parent, const std::string &name, bool duplicates=false)
 Constructs a storage interface.
 
virtual ~iStorage ()
 Destroys a storage interface.
 
bool isDBOpened () const
 Is database opened.
 
const std::string & dbName () const
 Database name.
 
void ensureOpened (const std::string &methodName) const
 Helper function, thows exception if the database is not opened.
 
void throwDuplicateOrUnknown (int rc, const std::string &key) const
 Throws LMDBAL::Exist or LMDBAL::Unknown.
 
void throwDuplicateOrUnknown (int rc, TransactionID txn, const std::string &key) const
 Throws LMDBAL::Exist or LMDBAL::Unknown (transaction vairiant)
 
void throwNotFoundOrUnknown (int rc, const std::string &key) const
 Throws LMDBAL::NotFound or LMDBAL::Unknown (transaction variant)
 
void throwNotFoundOrUnknown (int rc, TransactionID txn, const std::string &key) const
 Throws LMDBAL::NotFound or LMDBAL::Unknown (transaction vairiant)
 
void throwUnknown (int rc, TransactionID txn) const
 Throws LMDBAL::Unknown (transaction vairiant)
 
void throwUnknown (int rc) const
 Throws LMDBAL::Unknown.
 
void throwUnknown (const std::string &message) const
 Throws LMDBAL::Unknown.
 
void throwDuplicate (const std::string &key) const
 Throws LMDBAL::Exist.
 
void throwNotFound (const std::string &key) const
 Throws LMDBAL::NotFound.
 
void throwCursorNotReady (const std::string &method) const
 Throws LMDBAL::CursorNotReady.
 
TransactionID extractTransactionId (const Transaction &txn, const std::string &action="") const
 Checks if the transaction is still active, returns inner TransactionID.
 
TransactionID beginReadOnlyTransaction () const
 Begins read-only transaction.
 
TransactionID beginTransaction () const
 Begins writable transaction.
 
void commitTransaction (TransactionID id)
 Commits transaction.
 
void abortTransaction (TransactionID id) const
 Aborts transaction.
 
int _mdbOpen (MDB_txn *txn, unsigned int flags=0)
 
int _mdbPut (MDB_txn *txn, MDB_val &key, MDB_val &data, unsigned int flags=0)
 
int _mdbGet (MDB_txn *txn, MDB_val &key, MDB_val &data) const
 
int _mdbDel (MDB_txn *txn, MDB_val &key)
 
int _mdbDel (MDB_txn *txn, MDB_val &key, MDB_val &data)
 
int _mdbStat (MDB_txn *txn, MDB_stat &stat) const
 
int _mdbFlags (MDB_txn *txn, uint32_t &flags) const
 
int _mdbCursorOpen (MDB_txn *txn, MDB_cursor **cursor) const
 
void _mdbCursorClose (MDB_cursor *cursor) const
 
int _mdbCursorGet (MDB_cursor *cursor, MDB_val &key, MDB_val &data, MDB_cursor_op operation) const
 
int _mdbCursorSet (MDB_cursor *cursor, MDB_val &key) const
 
int _mdbCursorDel (MDB_cursor *cursor, unsigned int flags=0)
 
int _mdbCursorPut (MDB_cursor *cursor, MDB_val &key, MDB_val &data, unsigned int flags=0)
 
int _mdbCursorRenew (MDB_txn *txn, MDB_cursor *cursor) const
 
MDB_txn * _mdbCursorTxn (MDB_cursor *cursor) const
 
template<class K , class V >
int makeStorage (MDB_txn *transaction, bool duplicates=false)
 A functiion to actually open MDB_dbi storage.
 

Protected Attributes

Mode mode
 Cache mode.
 
std::map< K, V > * cache
 Cached data.
 
std::set< K > * abscent
 Set of keys that are definitely not in the cache.
 
SizeType sizeDifference
 Difference of size between cached data and amount of records in the lmdb storage.
 
TransactionCache * transactionCache
 All changes made under under uncommited transactions.
 
- Protected Attributes inherited from LMDBAL::Storage< K, V >
Serializer< K > keySerializer
 internal object that would serialize and deserialize keys
 
Serializer< V > valueSerializer
 internal object that would serialize and deserialize values
 
std::map< uint32_t, Cursor< K, V > * > cursors
 a set of cursors that has been created under this storage
 
- Protected Attributes inherited from LMDBAL::iStorage
MDB_dbi dbi
 lmdb storage handle
 
Basedb
 parent database pointer (borrowed)
 
const std::string name
 this storage name
 
const bool duplicates
 true if storage supports duplicates
 

Friends

class Base
 

Additional Inherited Members

- Static Protected Member Functions inherited from LMDBAL::iStorage
template<class T >
static std::string toString (const T &value)
 A method to cast a value (which can be a value or a key) to string.
 
- Static Protected Attributes inherited from LMDBAL::iStorage
static const std::string dropMethodName = "drop"
 member function name, just for exceptions
 
static const std::string countMethodName = "count"
 member function name, just for exceptions
 
static const std::string flagsMethodName = "flags"
 member function name, just for exceptions
 
static const std::string addRecordMethodName = "addRecord"
 member function name, just for exceptions
 
static const std::string forceRecordMethodName = "forceRecord"
 member function name, just for exceptions
 
static const std::string changeRecordMethodName = "changeRecord"
 member function name, just for exceptions
 
static const std::string removeRecordMethodName = "removeRecord"
 member function name, just for exceptions
 
static const std::string checkRecordMethodName = "checkRecord"
 member function name, just for exceptions
 
static const std::string getRecordMethodName = "getRecord"
 member function name, just for exceptions
 
static const std::string readAllMethodName = "readAllRecord"
 member function name, just for exceptions
 
static const std::string replaceAllMethodName = "replaceAll"
 member function name, just for exceptions
 
static const std::string addRecordsMethodName = "addRecords"
 member function name, just for exceptions
 

Detailed Description

template<class K, class V>
class LMDBAL::Cache< K, V >

Storage with additional caching in std::map.

Template Parameters
Ktype of the keys of the cache
Vtype of the values of the cache

You can receive an instance of this class calling LMDBAL::Base::addCache(const std::string&) if the database is yet closed and you're defining the storages you're going to need. Or you can call LMDBAL::Base::getCache(const std::string&) if you didn't save a pointer to the cache at first

You are not supposed to instantiate or destory instances of this class yourself!

Constructor & Destructor Documentation

◆ Cache()

template<class K , class V >
LMDBAL::Cache< K, V >::Cache ( Base parent,
const std::string &  name,
bool  duplicates = false 
)
protected

Creates a cache.

Parameters
[in]parent- LMDBAL::Base pointer for the owning database (borrowed)
[in]name- the name of the storage
[in]duplicates- true if key duplicates are allowed (false by default)

Member Function Documentation

◆ addRecord() [1/2]

template<class K , class V >
void LMDBAL::Cache< K, V >::addRecord ( const K &  key,
const V &  value 
)
overridevirtual

Adds a key-value record to the storage.

Take a note that if the storage already had a record you want to add LMDBAL::Exist is thrown. If your storage doesn't support duplicates LMDBAL::Exist is thrown if the record with the same key already exists in the database. If your storage supports duplicates LMDBAL::Exist is thrown only if the record with the same key AND already exists in the database.

Parameters
[in]keykey of the record
[in]valuevalue of the record
Exceptions
LMDBAL::Existthrown if the storage already has a record with the given key
LMDBAL::Closedthrown if the database was not opened
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ addRecord() [2/2]

template<class K , class V >
void LMDBAL::Cache< K, V >::addRecord ( const K &  key,
const V &  value,
TransactionID  txn 
)
overrideprotectedvirtual

Adds a key-value record to the storage (private transaction variant)

Take a note that if the storage already had a record you want to add LMDBAL::Exist is thrown. If your storage doesn't support duplicates LMDBAL::Exist is thrown if the record with the same key already exists in the database. If your storage supports duplicates LMDBAL::Exist is thrown only if the record with the same key AND already exists in the database.

Parameters
[in]keykey of the record
[in]valuevalue of the record
[in]txntransaction ID, needs to be a writable transaction!
Exceptions
LMDBAL::Existthrown if the storage already has a record with the given key
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ addRecords() [1/2]

template<class K , class V >
LMDBAL::SizeType LMDBAL::Cache< K, V >::addRecords ( const std::map< K, V > &  data,
bool  overwrite = false 
)
overridevirtual

Adds records in bulk.

Parameters
[in]datathe data to be added
[in]overwriteif false method throws LMDBAL::Exist on repeated key, if true - overwrites it
Returns
new actual amount of records in the storage
Exceptions
LMDBAL::Closedthrown if the database was not opened
LMDBAL::Existthrown if overwrite==false and at least one of the keys of data already exists in the storage
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ addRecords() [2/2]

template<class K , class V >
LMDBAL::SizeType LMDBAL::Cache< K, V >::addRecords ( const std::map< K, V > &  data,
TransactionID  txn,
bool  overwrite = false 
)
overrideprotectedvirtual

Adds records in bulk (private transaction variant)

This method schedules a data addition, but doesn't immidiately execute it.

Parameters
[in]datathe data to be added
[in]txntransaction ID, needs to be a writable transaction!
[in]overwriteif false method throws LMDBAL::Exist on repeated key, if true - overwrites it
Returns
new actual amount of records in the storage
Exceptions
LMDBAL::Existthrown if overwrite==false and at least one of the keys of data already exists in the storage
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ changeRecord() [1/2]

template<class K , class V >
void LMDBAL::Cache< K, V >::changeRecord ( const K &  key,
const V &  value 
)
overridevirtual

Changes key-value record to the storage.

Take a note that if the storage didn't have a record you want to change LMDBAL::NotFound is thrown

If duplicates mode is enabled this function will find the first entry of the key (which is pretty couterintuitive, see LMDBAL::Storage::getRecord() description) and change it's value to the given one. If the given value matches some of the other values for given key the method will throw LMDBAL::Exist, if no key was found it will still throw LMDBAL::NotFound.

Parameters
[in]keykey of the record
[in]valuenew value of the record
Exceptions
LMDBAL::NotFoundthrown if the storage doesn't have a record with the given key
LMDBAL::Existthrown in duplicates mode when the given value matches some of existing values for the given key
LMDBAL::Closedthrown if the database was not opened
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ changeRecord() [2/2]

template<class K , class V >
void LMDBAL::Cache< K, V >::changeRecord ( const K &  key,
const V &  value,
TransactionID  txn 
)
overrideprotectedvirtual

Changes key-value record to the storage (private transaction variant)

This method schedules a modification of a key-value record, but doesn't immidiately changes it. Take a note that if the storage didn't have a record you want to change LMDBAL::NotFound is thrown

If duplicates mode is enabled this function will find the first entry of the key (which is pretty couterintuitive, see LMDBAL::Storage::getRecord() description) and change it's value to the given one. If the given value matches some of the other values for given key the method will throw LMDBAL::Exist, if no key was found it will still throw LMDBAL::NotFound.

Parameters
[in]keykey of the record
[in]valuenew value of the record
[in]txntransaction ID, needs to be a writable transaction!
Exceptions
LMDBAL::NotFoundthrown if the storage doesn't have a record with the given key
LMDBAL::Existthrown in duplicates mode when the given value matches some of existing values for the given key
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ checkRecord() [1/2]

template<class K , class V >
bool LMDBAL::Cache< K, V >::checkRecord ( const K &  key) const
overridevirtual

Chechs if storage has value.

Parameters
[in]keykey of the record you look for
Returns
true if there was a record with given key, false otherwise
Exceptions
LMDBAL::Closedthrown if the database was not opened
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ checkRecord() [2/2]

template<class K , class V >
bool LMDBAL::Cache< K, V >::checkRecord ( const K &  key,
TransactionID  txn 
) const
overrideprotectedvirtual

Chechs if storage has value (private transaction variant)

Parameters
[in]keykey of the record you look for
[in]txntransaction ID, can be read only transaction
Returns
true if there was a record with given key, false otherwise
Exceptions
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ count() [1/2]

template<class K , class V >
uint32_t LMDBAL::Cache< K, V >::count ( ) const
overridevirtual

Storage size.

Returns
amount of records in the storage
Exceptions
LMDBAL::Closedthrown if the database was closed
LMDBAL::Unknownthrown if something unexpected happened

Reimplemented from LMDBAL::iStorage.

◆ count() [2/2]

template<class K , class V >
uint32_t LMDBAL::Cache< K, V >::count ( TransactionID  txn) const
overrideprotectedvirtual

Storage size (private transaction variant)

Parameters
[in]txn- transaction ID, can be read-only transaction
Returns
amount of records in the storage
Exceptions
LMDBAL::Unknownthrown if something unexpected happened

Reimplemented from LMDBAL::iStorage.

◆ discoveredRecord() [1/2]

template<class K , class V >
void LMDBAL::Cache< K, V >::discoveredRecord ( const K &  key,
const V &  value 
) const
overrideprotectedvirtual

A private virtual method that cursor calls when he reads a record, does nothing here but populates the LMDBAL::Cache.

Parameters
[in]keya key of discovered record
[in]valuea value of discovered record

Reimplemented from LMDBAL::Storage< K, V >.

◆ discoveredRecord() [2/2]

template<class K , class V >
void LMDBAL::Cache< K, V >::discoveredRecord ( const K &  key,
const V &  value,
TransactionID  txn 
) const
overrideprotectedvirtual

A private virtual method that cursor calls when he reads a record, does nothing here but populates the LMDBAL::Cache.

Parameters
[in]keya key of discovered record
[in]valuea value of discovered record
[in]txnTransactionID under which the dicovery happened, to avoid not commited changes collisions

Reimplemented from LMDBAL::Storage< K, V >.

◆ drop()

template<class K , class V >
int LMDBAL::Cache< K, V >::drop ( const WriteTransaction txn)
overridevirtual

Drops content of a storage interface (public transaction variant)

Just performs content drop

Parameters
[in]txn- transaction ID, must be writable transaction!
Returns
MDB_SUCCESS if everything went fine, MDB_<error> code otherwise
Exceptions
LMDBAL::TransactionTerminatedthrown if the transaction was not active

Reimplemented from LMDBAL::iStorage.

◆ forceRecord() [1/2]

template<class K , class V >
bool LMDBAL::Cache< K, V >::forceRecord ( const K &  key,
const V &  value 
)
overridevirtual

Adds a key-value record to the storage, overwrites if it already exists.

This method is mostly useless in duplicates mode. In this mode it basically does the same thing LMDBAL::Storage::addRecord() does, but suppresses LMDBAL::Exist exception if the record with the same key-value pair existed in the storage. In this case just false is returned from the method.

Parameters
[in]keykey of the record
[in]valuevalue of the record
Returns
true if the record was added, false otherwise
Exceptions
LMDBAL::Closedthrown if the database was not opened
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ forceRecord() [2/2]

template<class K , class V >
bool LMDBAL::Cache< K, V >::forceRecord ( const K &  key,
const V &  value,
TransactionID  txn 
)
overrideprotectedvirtual

Adds a key-value record to the storage, overwrites if it already exists (private transaction variant)

This method schedules an addition of a key-value record, but doesn't immidiately add it.

This method is mostly useless in duplicates mode. In this mode it basically does the same thing LMDBAL::Storage::addRecord() does, but suppresses LMDBAL::Exist exception if the record with the same key-value pair existed in the storage. In this case just false is returned from the method.

Parameters
[in]keykey of the record
[in]valuevalue of the record
[in]txntransaction ID, needs to be a writable transaction!
Returns
true if the record was added, false otherwise
Exceptions
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ getRecord() [1/4]

template<class K , class V >
V LMDBAL::Cache< K, V >::getRecord ( const K &  key) const
overridevirtual

Gets the record from the database.

Take a note that if the storage didn't have a record you want to get LMDBAL::NotFound is thrown

If the storage supports duplicates the exact value returned from it depends on comparison function of lmdb. It's not very straight forward, so, you shouldn't really use this method if you use duplicates and you rely on exact result. Anyway:

  • if your values are signed or unsigned integer of any size the LOWEST value is returned compared as UNSIGNED. For example for storage with int32_t as value, from the same key, from the set of values {-33, -1, 5573, 77753} 5573 is returned as it is the lowest by UNSIGNED comparison.
  • if your values are anything else - they are compared byte by byte as if they are strings, it makes it especially complicated to predict the exact value for float or double templated storages. For strings if makes a bit more sence: if the choise is from "50" and "100" - "100" is returned, because the first byte of the "100" is lower than the first byte of the "50"
Parameters
[in]keykey of the record you look for
Returns
the value from the storage
Exceptions
LMDBAL::NotFoundthrown if the storage doesn't have a record with the given key
LMDBAL::Closedthrown if the database was not opened
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ getRecord() [2/4]

template<class K , class V >
V LMDBAL::Cache< K, V >::getRecord ( const K &  key,
TransactionID  txn 
) const
overrideprotectedvirtual

Gets the record from the database (private transaction variant)

Take a note that if the storage didn't have a record you want to get LMDBAL::NotFound is thrown

If the storage supports duplicates the exact value returned from it depends on comparison function of lmdb. It's not very straight forward, so, you shouldn't really use this method if you use duplicates and you rely on exact result. Anyway:

  • if your values are signed or unsigned integer of any size the LOWEST value is returned compared as UNSIGNED. For example for storage with int32_t as value, from the same key, from the set of values {-33, -1, 5573, 77753} 5573 is returned as it is the lowest by UNSIGNED comparison.
  • if your values are anything else - they are compared byte by byte as if they are strings, it makes it especially complicated to predict the exact value for float or double templated storages. For strings if makes a bit more sence: if the choise is from "50" and "100" - "100" is returned, because the first byte of the "100" is lower than the first byte of the "50"
Parameters
[in]keykey of the record you look for
[in]txntransaction ID, can be read only transaction
Returns
the value from the storage
Exceptions
LMDBAL::NotFoundthrown if the storage doesn't have a record with the given key
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ getRecord() [3/4]

template<class K , class V >
void LMDBAL::Cache< K, V >::getRecord ( const K &  key,
V &  value 
) const
overridevirtual

Gets the record from the database (reference variant)

Take a note that if the storage didn't have a record you want to get LMDBAL::NotFound is thrown

If the storage supports duplicates the exact value returned from it depends on comparison function of lmdb. It's not very straight forward, so, you shouldn't really use this method if you use duplicates and you rely on exact result. Anyway:

  • if your values are signed or unsigned integer of any size the LOWEST value is returned compared as UNSIGNED. For example for storage with int32_t as value, from the same key, from the set of values {-33, -1, 5573, 77753} 5573 is returned as it is the lowest by UNSIGNED comparison.
  • if your values are anything else - they are compared byte by byte as if they are strings, it makes it especially complicated to predict the exact value for float or double templated storages. For strings if makes a bit more sence: if the choise is from "50" and "100" - "100" is returned, because the first byte of the "100" is lower than the first byte of the "50"
Parameters
[in]keykey of the record you look for
[out]valuethe value from the storage
Exceptions
LMDBAL::NotFoundthrown if the storage doesn't have a record with the given key
LMDBAL::Closedthrown if the database was not opened
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ getRecord() [4/4]

template<class K , class V >
void LMDBAL::Cache< K, V >::getRecord ( const K &  key,
V &  value,
TransactionID  txn 
) const
overrideprotectedvirtual

Gets the record from the database (private transaction, reference variant)

Take a note that if the storage didn't have a record you want to get LMDBAL::NotFound is thrown

If the storage supports duplicates the exact value returned from it depends on comparison function of lmdb. It's not very straight forward, so, you shouldn't really use this method if you use duplicates and you rely on exact result. Anyway:

  • if your values are signed or unsigned integer of any size the LOWEST value is returned compared as UNSIGNED. For example for storage with int32_t as value, from the same key, from the set of values {-33, -1, 5573, 77753} 5573 is returned as it is the lowest by UNSIGNED comparison.
  • if your values are anything else - they are compared byte by byte as if they are strings, it makes it especially complicated to predict the exact value for float or double templated storages. For strings if makes a bit more sence: if the choise is from "50" and "100" - "100" is returned, because the first byte of the "100" is lower than the first byte of the "50"
Parameters
[in]keykey of the record you look for
[out]valuethe value from the storage
[in]txntransaction ID, can be read only transaction
Exceptions
LMDBAL::NotFoundthrown if the storage doesn't have a record with the given key
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ handleDrop()

template<class K , class V >
void LMDBAL::Cache< K, V >::handleDrop ( )
overrideprotectedvirtual

A method where database additionally handles drop.

It's a protected method that is called to optimise drop process after the transaction is commited. Used just for optimisations.

Reimplemented from LMDBAL::iStorage.

◆ readAll() [1/4]

template<class K , class V >
std::map< K, V > LMDBAL::Cache< K, V >::readAll ( ) const
overridevirtual

Reads whole storage into a map.

Basically just reads all database in an std::map, usefull when you store small storages

In case storage supports duplicates only what lmdb considered to be lowest value (see LMDBAL::Storage::getRecord() description) is returned in the resulting map

Exceptions
LMDBAL::Closedthrown if the database was not opened
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ readAll() [2/4]

template<class K , class V >
void LMDBAL::Cache< K, V >::readAll ( std::map< K, V > &  result) const
overridevirtual

Reads whole storage into a map (reference variant)

Basically just reads all database in an std::map, usefull when you store small storages

In case storage supports duplicates only what lmdb considered to be lowest value (see LMDBAL::Storage::getRecord() description) is returned in the resulting map

Parameters
[out]resulta map that is going to contain all data
Exceptions
LMDBAL::Closedthrown if the database was not opened
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ readAll() [3/4]

template<class K , class V >
void LMDBAL::Cache< K, V >::readAll ( std::map< K, V > &  result,
TransactionID  txn 
) const
overrideprotectedvirtual

Reads whole storage into a map (private transaction, reference variant)

Basically just reads all database in an std::map, usefull when you store small storages In case storage supports duplicates only what lmdb considered to be lowest value (see LMDBAL::Storage::getRecord() description) is returned in the resulting map

Parameters
[out]resulta map that is going to contain all data
[in]txntransaction ID, can be read only transaction
Exceptions
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ readAll() [4/4]

template<class K , class V >
std::map< K, V > LMDBAL::Cache< K, V >::readAll ( TransactionID  txn) const
overrideprotectedvirtual

Reads whole storage into a map (private transaction variant)

Basically just reads all database in an std::map, usefull when you store small storages In case storage supports duplicates only what lmdb considered to be lowest value (see LMDBAL::Storage::getRecord() description) is returned in the resulting map

Parameters
[in]txntransaction ID, can be read only transaction
Exceptions
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ removeRecord() [1/2]

template<class K , class V >
void LMDBAL::Cache< K, V >::removeRecord ( const K &  key)
overridevirtual

Removes one of the records.

Take a note that if the storage didn't have a record you want to remove LMDBAL::NotFound is thrown

Parameters
[in]keykey of the record you wish to be removed
Exceptions
LMDBAL::Closedthrown if the database was not opened
LMDBAL::NotFoundthrown if the record with given key wasn't found
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ removeRecord() [2/2]

template<class K , class V >
void LMDBAL::Cache< K, V >::removeRecord ( const K &  key,
TransactionID  txn 
)
overrideprotectedvirtual

Removes one of the records (private transaction variant)

Take a note that if the storage didn't have a record you want to remove LMDBAL::NotFound is thrown This method schedules a record removal, but doesn't immidiately execute it.

Parameters
[in]keykey of the record you wish to be removed
[in]txntransaction ID, needs to be a writable transaction!
Exceptions
LMDBAL::NotFoundthrown if the record with given key wasn't found
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ replaceAll() [1/2]

template<class K , class V >
void LMDBAL::Cache< K, V >::replaceAll ( const std::map< K, V > &  data)
overridevirtual

Replaces the content of the whole storage with the given.

Basically this method drops the database and adds all the records from the given map

Parameters
[in]datanew data of the storage
Exceptions
LMDBAL::Closedthrown if the database was not opened
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ replaceAll() [2/2]

template<class K , class V >
void LMDBAL::Cache< K, V >::replaceAll ( const std::map< K, V > &  data,
TransactionID  txn 
)
overrideprotectedvirtual

Replaces the content of the whole storage with the given (private transaction variant)

Basically this method drops the database and adds all the records from the given map

Parameters
[in]datanew data of the storage
[in]txntransaction ID, needs to be a writable transaction!
Exceptions
LMDBAL::Unknownthrown if something unexpected happend within lmdb

Reimplemented from LMDBAL::Storage< K, V >.

◆ transactionAborted()

template<class K , class V >
void LMDBAL::Cache< K, V >::transactionAborted ( TransactionID  txn) const
overrideprotectedvirtual

called on abortion of public transaction

This function is called on every storage of the database when user calls LMDBAL::Base::abortTransaction(LMDBAL::TransactionID)

This function is met to be reimplemented in heirs if the heir code requires some transaction custom handling

Parameters
[in]txn- ID of started transaction

Reimplemented from LMDBAL::iStorage.

◆ transactionCommited()

template<class K , class V >
void LMDBAL::Cache< K, V >::transactionCommited ( TransactionID  txn)
overrideprotectedvirtual

called on commitment of public transaction

This function is called on every storage of the database when user calls LMDBAL::Base::commitTransaction(LMDBAL::TransactionID)

This function is met to be reimplemented in heirs if the heir code requires some transaction custom handling

Parameters
[in]txn- ID of started transaction

Reimplemented from LMDBAL::iStorage.

◆ transactionStarted()

template<class K , class V >
void LMDBAL::Cache< K, V >::transactionStarted ( TransactionID  txn,
bool  readOnly 
) const
overrideprotectedvirtual

called on beginning of public transaction

This function is called on every storage of the database when user calls LMDBAL::Base::beginTransaction() or LMDBAL::Base::beginReadOnlyTransaction()

This function is met to be reimplemented in heirs if the heir code requires some transaction custom handling

Parameters
[in]txn- ID of started transaction
[in]readOnly- true if transaction is read-only, false otherwise

Reimplemented from LMDBAL::iStorage.

Member Data Documentation

◆ mode

template<class K , class V >
Mode LMDBAL::Cache< K, V >::mode
mutableprotected

Cache mode.

Sometimes we have a complete information about the content of the database, and we don't even need to call lmdb to fetch or check for data. This member actually shows what is the current state, more about them you can read in Enum descriptions


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