1
0
Fork 0
forked from blue/lmdbal

some more transaction thought on cache

This commit is contained in:
Blue 2023-04-03 21:48:13 +03:00
parent f0779ae2aa
commit 8be63d7551
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
6 changed files with 241 additions and 58 deletions

View file

@ -21,6 +21,7 @@
#include <map>
#include <set>
#include <tuple>
#include "storage.h"
@ -34,33 +35,63 @@ class Cache : public Storage<K, V> {
size, // - know just an amount of records
full // - shure that our cache is equal to the database on disk
};
enum class Operation {
add,
remove,
change,
force,
drop,
replace,
addMany
};
typedef std::pair<Operation, void*> Entry;
typedef std::list<Entry> Queue;
typedef std::map<TransactionID, Queue> TransactionCache;
protected:
Cache(const std::string& name, Base* parent);
~Cache() override;
virtual void transactionStarted(TransactionID txn, bool readOnly) const override;
virtual void transactionCommited(TransactionID txn) override;
virtual void transactionAborted(TransactionID txn) const override;
private:
void handleMode() const;
void handleTransactionEntry(const Entry& entry);
void destroyTransactionEntry(const Entry& entry) const;
void handleAddRecord(const K& key, const V& value);
void handleRemoveRecord(const K& key);
void handleChangeRecord(const K& key, const V& value);
void handleForceRecord(const K& key, const V& value, bool added);
void handleReplaceAll(std::map<K, V>* data);
void handleAddRecords(const std::map<K, V>& data, bool overwrite, SizeType newSize);
void handleDrop();
public:
using Storage<K, V>::drop;
virtual int drop(TransactionID transaction) override;
virtual void addRecord(const K& key, const V& value) override;
virtual bool forceRecord(const K& key, const V& value) override;
virtual void changeRecord(const K& key, const V& value) override;
virtual void removeRecord(const K& key) override;
virtual bool checkRecord(const K& key) const override;
virtual V getRecord(const K& key) const override;
virtual uint32_t count() const override;
virtual SizeType count() const override;
using Storage<K, V>::drop;
virtual int drop(MDB_txn * transaction) override;
virtual std::map<K, V> readAll() const override;
virtual void replaceAll(const std::map<K, V>& data) override;
virtual uint32_t addRecords(const std::map<K, V>& data, bool overwrite = false) override;
virtual SizeType addRecords(const std::map<K, V>& data, bool overwrite = false) override;
protected:
Mode* mode;
std::map<K, V>* cache;
std::set<K>* abscent;
uint32_t* sizeDifference;
SizeType* sizeDifference;
TransactionCache* transactionCache;
};
}