forked from blue/lmdbal
RAII transactions
This commit is contained in:
parent
a9aa6b549f
commit
de741eda21
22 changed files with 689 additions and 222 deletions
src
|
@ -75,8 +75,6 @@ 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) {
|
||||
iStorage::ensureOpened(iStorage::addRecordMethodName);
|
||||
|
||||
if (cache->count(key) > 0)
|
||||
iStorage::throwDuplicate(iStorage::toString(key));
|
||||
|
||||
|
@ -109,8 +107,6 @@ bool LMDBAL::Cache<K, V>::forceRecord(const K& key, const V& value) {
|
|||
|
||||
template<class K, class V>
|
||||
bool LMDBAL::Cache<K, V>::forceRecord(const K& key, const V& value, TransactionID txn) {
|
||||
iStorage::ensureOpened(iStorage::forceRecordMethodName);
|
||||
|
||||
bool added = Storage<K, V>::forceRecord(key, value, txn);
|
||||
|
||||
typename TransactionCache::iterator tc = transactionCache->find(txn);
|
||||
|
@ -171,8 +167,6 @@ void LMDBAL::Cache<K, V>::changeRecord(const K& key, const V& value) {
|
|||
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::changeRecord(const K& key, const V& value, TransactionID txn) {
|
||||
iStorage::ensureOpened(iStorage::changeRecordMethodName);
|
||||
|
||||
if (mode == Mode::full) {
|
||||
typename std::map<K, V>::iterator itr = cache->find(key);
|
||||
if (itr == cache->end())
|
||||
|
@ -248,8 +242,6 @@ void LMDBAL::Cache<K, V>::getRecord(const K& key, V& out) const {
|
|||
|
||||
template<class K, class V>
|
||||
V LMDBAL::Cache<K, V>::getRecord(const K& key, TransactionID txn) const {
|
||||
iStorage::ensureOpened(iStorage::getRecordMethodName);
|
||||
|
||||
V value;
|
||||
Cache<K, V>::getRecord(key, value, txn);
|
||||
return value;
|
||||
|
@ -257,8 +249,6 @@ V LMDBAL::Cache<K, V>::getRecord(const K& key, TransactionID txn) const {
|
|||
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::getRecord(const K& key, V& out, TransactionID txn) const {
|
||||
iStorage::ensureOpened(iStorage::getRecordMethodName);
|
||||
|
||||
//if there are any changes made within this transaction
|
||||
//I will be able to see them among pending changes
|
||||
//so, I'm going to go through them in reverse order
|
||||
|
@ -387,8 +377,6 @@ bool LMDBAL::Cache<K, V>::checkRecord(const K& key) const {
|
|||
|
||||
template<class K, class V>
|
||||
bool LMDBAL::Cache<K, V>::checkRecord(const K& key, TransactionID txn) const {
|
||||
iStorage::ensureOpened(iStorage::checkRecordMethodName);
|
||||
|
||||
//if there are any changes made within this transaction
|
||||
//I will be able to see them among pending changes
|
||||
//so, I'm going to go through them in reverse order
|
||||
|
@ -497,8 +485,6 @@ void LMDBAL::Cache<K, V>::readAll(std::map<K, V>& out) const {
|
|||
|
||||
template<class K, class V>
|
||||
std::map<K, V> LMDBAL::Cache<K, V>::readAll(TransactionID txn) const {
|
||||
iStorage::ensureOpened(iStorage::readAllMethodName);
|
||||
|
||||
std::map<K, V> out;
|
||||
readAll(out, txn);
|
||||
|
||||
|
@ -507,8 +493,6 @@ std::map<K, V> LMDBAL::Cache<K, V>::readAll(TransactionID txn) const {
|
|||
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::readAll(std::map<K, V>& out, TransactionID txn) const {
|
||||
iStorage::ensureOpened(iStorage::readAllMethodName);
|
||||
|
||||
typename TransactionCache::iterator tc = transactionCache->find(txn);
|
||||
if (tc != transactionCache->end()) {
|
||||
Queue& queue = tc->second;
|
||||
|
@ -676,8 +660,6 @@ void LMDBAL::Cache<K, V>::removeRecord(const K& key) {
|
|||
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::removeRecord(const K& key, TransactionID txn) {
|
||||
iStorage::ensureOpened(iStorage::removeRecordMethodName);
|
||||
|
||||
bool noKey = false;
|
||||
if (mode != Mode::full)
|
||||
noKey = cache->count(key) == 0;
|
||||
|
@ -729,7 +711,6 @@ uint32_t LMDBAL::Cache<K, V>::count() const {
|
|||
|
||||
template<class K, class V>
|
||||
uint32_t LMDBAL::Cache<K, V>::count(TransactionID txn) const {
|
||||
|
||||
int32_t diff = 0;
|
||||
bool currentTransaction = false;
|
||||
typename TransactionCache::const_iterator tc = transactionCache->find(txn);
|
||||
|
@ -800,10 +781,15 @@ void LMDBAL::Cache<K, V>::handleMode() const {
|
|||
}
|
||||
|
||||
template<class K, class V>
|
||||
int LMDBAL::Cache<K, V>::drop(TransactionID transaction) {
|
||||
int res = Storage<K, V>::drop(transaction);
|
||||
int LMDBAL::Cache<K, V>::drop(const WriteTransaction& transaction) {
|
||||
iStorage::ensureOpened(iStorage::dropMethodName);
|
||||
TransactionID txn = iStorage::extractTransactionId(transaction, iStorage::dropMethodName);
|
||||
int res = Storage<K, V>::drop(txn);
|
||||
|
||||
typename TransactionCache::iterator tc = transactionCache->find(transaction);
|
||||
if (res != MDB_SUCCESS)
|
||||
return res;
|
||||
|
||||
typename TransactionCache::iterator tc = transactionCache->find(txn);
|
||||
if (tc != transactionCache->end())
|
||||
tc->second.emplace_back(Operation::drop, nullptr);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue