some more tests, one subtle but important bugfix with cache
This commit is contained in:
parent
8ff5672655
commit
d57d27f952
4 changed files with 132 additions and 13 deletions
|
@ -57,6 +57,9 @@ protected:
|
|||
virtual void transactionStarted(TransactionID txn, bool readOnly) const override;
|
||||
virtual void transactionCommited(TransactionID txn) override;
|
||||
virtual void transactionAborted(TransactionID txn) const override;
|
||||
|
||||
virtual void discoveredRecord(const K& key, const V& value) const override;
|
||||
virtual void discoveredRecord(const K& key, const V& value, TransactionID txn) const override;
|
||||
private:
|
||||
void handleMode() const;
|
||||
|
||||
|
@ -70,6 +73,7 @@ private:
|
|||
void handleReplaceAll(std::map<K, V>* data);
|
||||
void handleAddRecords(const std::map<K, V>& data, bool overwrite, SizeType newSize);
|
||||
void handleDrop();
|
||||
void appendToCache(const K& key, const V& value) const;
|
||||
|
||||
public:
|
||||
using Storage<K, V>::drop;
|
||||
|
|
|
@ -235,8 +235,7 @@ void LMDBAL::Cache<K, V>::getRecord(const K& key, V& out) const {
|
|||
|
||||
try {
|
||||
Storage<K, V>::getRecord(key, out);
|
||||
cache->insert(std::make_pair(key, out));
|
||||
handleMode();
|
||||
appendToCache(key, out);
|
||||
return;
|
||||
} catch (const NotFound& error) {
|
||||
if (mode != Mode::full)
|
||||
|
@ -337,10 +336,9 @@ void LMDBAL::Cache<K, V>::getRecord(const K& key, V& out, TransactionID txn) con
|
|||
|
||||
try {
|
||||
Storage<K, V>::getRecord(key, out, txn);
|
||||
if (!currentTransaction) {
|
||||
cache->insert(std::make_pair(key, out));
|
||||
handleMode();
|
||||
}
|
||||
if (!currentTransaction)
|
||||
appendToCache(key, out);
|
||||
|
||||
return;
|
||||
} catch (const NotFound& error) {
|
||||
if (!currentTransaction && mode != Mode::full)
|
||||
|
@ -350,6 +348,18 @@ void LMDBAL::Cache<K, V>::getRecord(const K& key, V& out, TransactionID txn) con
|
|||
}
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::discoveredRecord(const K& key, const V& value) const {
|
||||
appendToCache(key, value);
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::discoveredRecord(const K& key, const V& value, TransactionID txn) const {
|
||||
typename TransactionCache::const_iterator tc = transactionCache->find(txn);
|
||||
if (tc == transactionCache->end()) //there is a way to look though all the records in transaction log and cache the new pair
|
||||
discoveredRecord(key, value); //if there is nothing in transaction log about it, but it seems like too much for a small gain
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
bool LMDBAL::Cache<K, V>::checkRecord(const K& key) const {
|
||||
iStorage::ensureOpened(iStorage::checkRecordMethodName);
|
||||
|
@ -363,8 +373,8 @@ bool LMDBAL::Cache<K, V>::checkRecord(const K& key) const {
|
|||
|
||||
try {
|
||||
V value = Storage<K, V>::getRecord(key);
|
||||
cache->insert(std::make_pair(key, value));
|
||||
handleMode();
|
||||
appendToCache(key, value);
|
||||
|
||||
return true;
|
||||
} catch (const NotFound& error) {
|
||||
if (mode != Mode::full)
|
||||
|
@ -438,10 +448,9 @@ bool LMDBAL::Cache<K, V>::checkRecord(const K& key, TransactionID txn) const {
|
|||
|
||||
try {
|
||||
V value = Storage<K, V>::getRecord(key, txn);
|
||||
if (!currentTransaction) {
|
||||
cache->insert(std::make_pair(key, value));
|
||||
handleMode();
|
||||
}
|
||||
if (!currentTransaction)
|
||||
appendToCache(key, value);
|
||||
|
||||
return true;
|
||||
} catch (const NotFound& error) {
|
||||
if (!currentTransaction && mode != Mode::full)
|
||||
|
@ -451,6 +460,13 @@ bool LMDBAL::Cache<K, V>::checkRecord(const K& key, TransactionID txn) const {
|
|||
}
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cache<K, V>::appendToCache(const K& key, const V& value) const {
|
||||
typename std::pair<typename std::map<K, V>::const_iterator, bool> pair = cache->insert(std::make_pair(key, value));
|
||||
if (pair.second)
|
||||
handleMode();
|
||||
}
|
||||
|
||||
template<class K, class V>
|
||||
std::map<K, V> LMDBAL::Cache<K, V>::readAll() const {
|
||||
iStorage::ensureOpened(iStorage::readAllMethodName);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue