forked from blue/lmdbal
Cursors refactoring part one
This commit is contained in:
parent
ef86d0adf9
commit
bfb1d007ad
19 changed files with 824 additions and 677 deletions
|
@ -63,10 +63,10 @@ LMDBAL::Cache<K, V>::~Cache() {
|
|||
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::addRecord(const K& key, const V& value) {
|
||||
iStorage::ensureOpened(iStorage::addRecordMethodName);
|
||||
StorageCommon::ensureOpened(StorageCommon::addRecordMethodName);
|
||||
|
||||
if (cache->count(key) > 0)
|
||||
iStorage::throwDuplicate(iStorage::toString(key));
|
||||
StorageCommon::throwDuplicate(StorageCommon::toString(key));
|
||||
|
||||
Storage<K, V>::addRecord(key, value);
|
||||
handleAddRecord(key, value);
|
||||
|
@ -75,7 +75,7 @@ void LMDBAL::Cache<K, V>::addRecord(const K& key, const V& value) {
|
|||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::addRecord(const K& key, const V& value, TransactionID txn) {
|
||||
if (cache->count(key) > 0)
|
||||
iStorage::throwDuplicate(iStorage::toString(key));
|
||||
StorageCommon::throwDuplicate(StorageCommon::toString(key));
|
||||
|
||||
Storage<K, V>::addRecord(key, value, txn);
|
||||
|
||||
|
@ -96,7 +96,7 @@ void LMDBAL::Cache<K, V>::handleAddRecord(const K& key, const V& value) {
|
|||
|
||||
template<class K, class V>
|
||||
bool LMDBAL::Cache<K, V>::forceRecord(const K& key, const V& value) {
|
||||
iStorage::ensureOpened(iStorage::forceRecordMethodName);
|
||||
StorageCommon::ensureOpened(StorageCommon::forceRecordMethodName);
|
||||
|
||||
bool added = Storage<K, V>::forceRecord(key, value);
|
||||
handleForceRecord(key, value, added);
|
||||
|
@ -136,18 +136,18 @@ void LMDBAL::Cache<K, V>::handleForceRecord(const K& key, const V& value, bool a
|
|||
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::changeRecord(const K& key, const V& value) {
|
||||
iStorage::ensureOpened(iStorage::changeRecordMethodName);
|
||||
StorageCommon::ensureOpened(StorageCommon::changeRecordMethodName);
|
||||
|
||||
if (mode == Mode::full) {
|
||||
typename std::map<K, V>::iterator itr = cache->find(key);
|
||||
if (itr == cache->end())
|
||||
iStorage::throwNotFound(iStorage::toString(key));
|
||||
StorageCommon::throwNotFound(StorageCommon::toString(key));
|
||||
|
||||
Storage<K, V>::changeRecord(key, value);
|
||||
itr->second = value;
|
||||
} else {
|
||||
if (abscent->count(key) > 0)
|
||||
iStorage::throwNotFound(iStorage::toString(key));
|
||||
StorageCommon::throwNotFound(StorageCommon::toString(key));
|
||||
|
||||
try {
|
||||
Storage<K, V>::changeRecord(key, value);
|
||||
|
@ -169,12 +169,12 @@ void LMDBAL::Cache<K, V>::changeRecord(const K& key, const V& value, Transaction
|
|||
if (mode == Mode::full) {
|
||||
typename std::map<K, V>::iterator itr = cache->find(key);
|
||||
if (itr == cache->end())
|
||||
iStorage::throwNotFound(iStorage::toString(key));
|
||||
StorageCommon::throwNotFound(StorageCommon::toString(key));
|
||||
|
||||
Storage<K, V>::changeRecord(key, value, txn);
|
||||
} else {
|
||||
if (abscent->count(key) > 0)
|
||||
iStorage::throwNotFound(iStorage::toString(key));
|
||||
StorageCommon::throwNotFound(StorageCommon::toString(key));
|
||||
|
||||
try {
|
||||
Storage<K, V>::changeRecord(key, value, txn);
|
||||
|
@ -207,7 +207,7 @@ void LMDBAL::Cache<K, V>::handleChangeRecord(const K& key, const V& value) {
|
|||
|
||||
template<class K, class V>
|
||||
V LMDBAL::Cache<K, V>::getRecord(const K& key) const {
|
||||
iStorage::ensureOpened(iStorage::getRecordMethodName);
|
||||
StorageCommon::ensureOpened(StorageCommon::getRecordMethodName);
|
||||
|
||||
V value;
|
||||
Cache<K, V>::getRecord(key, value);
|
||||
|
@ -216,7 +216,7 @@ V LMDBAL::Cache<K, V>::getRecord(const K& key) const {
|
|||
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::getRecord(const K& key, V& out) const {
|
||||
iStorage::ensureOpened(iStorage::getRecordMethodName);
|
||||
StorageCommon::ensureOpened(StorageCommon::getRecordMethodName);
|
||||
|
||||
typename std::map<K, V>::const_iterator itr = cache->find(key);
|
||||
if (itr != cache->end()) {
|
||||
|
@ -225,7 +225,7 @@ void LMDBAL::Cache<K, V>::getRecord(const K& key, V& out) const {
|
|||
}
|
||||
|
||||
if (mode == Mode::full || abscent->count(key) != 0)
|
||||
iStorage::throwNotFound(iStorage::toString(key));
|
||||
StorageCommon::throwNotFound(StorageCommon::toString(key));
|
||||
|
||||
try {
|
||||
Storage<K, V>::getRecord(key, out);
|
||||
|
@ -269,7 +269,7 @@ void LMDBAL::Cache<K, V>::getRecord(const K& key, V& out, TransactionID txn) con
|
|||
}
|
||||
break;
|
||||
case Operation::remove:
|
||||
iStorage::throwNotFound(iStorage::toString(key));
|
||||
StorageCommon::throwNotFound(StorageCommon::toString(key));
|
||||
break;
|
||||
case Operation::change:
|
||||
if (static_cast<std::pair<K, V>*>(entry.second)->first == key) {
|
||||
|
@ -285,7 +285,7 @@ void LMDBAL::Cache<K, V>::getRecord(const K& key, V& out, TransactionID txn) con
|
|||
}
|
||||
break;
|
||||
case Operation::drop:
|
||||
iStorage::throwNotFound(iStorage::toString(key));
|
||||
StorageCommon::throwNotFound(StorageCommon::toString(key));
|
||||
break;
|
||||
case Operation::replace: {
|
||||
std::map<K, V>* newMap = static_cast<std::map<K, V>*>(entry.second);
|
||||
|
@ -294,7 +294,7 @@ void LMDBAL::Cache<K, V>::getRecord(const K& key, V& out, TransactionID txn) con
|
|||
out = vitr->second;
|
||||
return;
|
||||
} else {
|
||||
iStorage::throwNotFound(iStorage::toString(key));
|
||||
StorageCommon::throwNotFound(StorageCommon::toString(key));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -322,7 +322,7 @@ void LMDBAL::Cache<K, V>::getRecord(const K& key, V& out, TransactionID txn) con
|
|||
}
|
||||
|
||||
if (mode == Mode::full || abscent->count(key) != 0)
|
||||
iStorage::throwNotFound(iStorage::toString(key));
|
||||
StorageCommon::throwNotFound(StorageCommon::toString(key));
|
||||
|
||||
try {
|
||||
Storage<K, V>::getRecord(key, out, txn);
|
||||
|
@ -352,7 +352,7 @@ void LMDBAL::Cache<K, V>::discoveredRecord(const K& key, const V& value, Transac
|
|||
|
||||
template<class K, class V>
|
||||
bool LMDBAL::Cache<K, V>::checkRecord(const K& key) const {
|
||||
iStorage::ensureOpened(iStorage::checkRecordMethodName);
|
||||
StorageCommon::ensureOpened(StorageCommon::checkRecordMethodName);
|
||||
|
||||
typename std::map<K, V>::const_iterator itr = cache->find(key);
|
||||
if (itr != cache->end())
|
||||
|
@ -457,7 +457,7 @@ void LMDBAL::Cache<K, V>::appendToCache(const K& key, const V& value) const {
|
|||
|
||||
template<class K, class V>
|
||||
std::map<K, V> LMDBAL::Cache<K, V>::readAll() const {
|
||||
iStorage::ensureOpened(iStorage::readAllMethodName);
|
||||
StorageCommon::ensureOpened(StorageCommon::readAllMethodName);
|
||||
|
||||
if (mode != Mode::full) { //there is a room for optimization
|
||||
mode = Mode::full; //I can read and deserialize only those values
|
||||
|
@ -471,7 +471,7 @@ std::map<K, V> LMDBAL::Cache<K, V>::readAll() const {
|
|||
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::readAll(std::map<K, V>& out) const {
|
||||
iStorage::ensureOpened(iStorage::readAllMethodName);
|
||||
StorageCommon::ensureOpened(StorageCommon::readAllMethodName);
|
||||
|
||||
if (mode != Mode::full) { //there is a room for optimization
|
||||
mode = Mode::full; //I can read and deserialize only those values
|
||||
|
@ -642,7 +642,7 @@ void LMDBAL::Cache<K, V>::handleAddRecords(const std::map<K, V>& data, bool over
|
|||
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::removeRecord(const K& key) {
|
||||
iStorage::ensureOpened(iStorage::removeRecordMethodName);
|
||||
StorageCommon::ensureOpened(StorageCommon::removeRecordMethodName);
|
||||
|
||||
bool noKey = false;
|
||||
if (mode != Mode::full)
|
||||
|
@ -651,7 +651,7 @@ void LMDBAL::Cache<K, V>::removeRecord(const K& key) {
|
|||
noKey = abscent->count(key) > 0;
|
||||
|
||||
if (noKey)
|
||||
iStorage::throwNotFound(iStorage::toString(key));
|
||||
StorageCommon::throwNotFound(StorageCommon::toString(key));
|
||||
|
||||
Storage<K, V>::removeRecord(key);
|
||||
handleRemoveRecord(key);
|
||||
|
@ -666,7 +666,7 @@ void LMDBAL::Cache<K, V>::removeRecord(const K& key, TransactionID txn) {
|
|||
noKey = abscent->count(key) > 0;
|
||||
|
||||
if (noKey)
|
||||
iStorage::throwNotFound(iStorage::toString(key));
|
||||
StorageCommon::throwNotFound(StorageCommon::toString(key));
|
||||
|
||||
Storage<K, V>::removeRecord(key, txn);
|
||||
|
||||
|
@ -781,8 +781,8 @@ void LMDBAL::Cache<K, V>::handleMode() const {
|
|||
|
||||
template<class K, class V>
|
||||
int LMDBAL::Cache<K, V>::drop(const WriteTransaction& transaction) {
|
||||
iStorage::ensureOpened(iStorage::dropMethodName);
|
||||
TransactionID txn = iStorage::extractTransactionId(transaction, iStorage::dropMethodName);
|
||||
StorageCommon::ensureOpened(StorageCommon::dropMethodName);
|
||||
TransactionID txn = StorageCommon::extractTransactionId(transaction, StorageCommon::dropMethodName);
|
||||
int res = Storage<K, V>::drop(txn);
|
||||
|
||||
if (res != MDB_SUCCESS)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue