some ideas about transaction

This commit is contained in:
Blue 2023-04-02 16:00:21 +03:00
parent a4bb7e6269
commit f0779ae2aa
Signed by: blue
GPG key ID: 9B203B252A63EE38
7 changed files with 125 additions and 65 deletions

View file

@ -81,7 +81,7 @@ public:
LMDBAL::Cache<K, V>* getCache(const std::string& name);
private:
typedef std::map<std::string, LMDBAL::iStorage*> Tables;
typedef std::map<std::string, LMDBAL::iStorage*> Storages;
typedef std::set<TransactionID> Transactions;
TransactionID beginReadOnlyTransaction(const std::string& storageName) const;
@ -89,12 +89,17 @@ private:
void commitTransaction(TransactionID id, const std::string& storageName) const;
void abortTransaction(TransactionID id, const std::string& storageName) const;
TransactionID beginPrivateReadOnlyTransaction(const std::string& storageName) const;
TransactionID beginPrivateTransaction(const std::string& storageName) const;
void commitPrivateTransaction(TransactionID id, const std::string& storageName) const;
void abortPrivateTransaction(TransactionID id, const std::string& storageName) const;
private:
std::string name;
bool opened;
uint16_t size;
MDB_env* environment;
Tables tables;
Storages storages;
Transactions* transactions;
inline static const std::string emptyName = "";
@ -109,11 +114,11 @@ private:
template <class K, class V>
LMDBAL::Storage<K, V>* LMDBAL::Base::addStorage(const std::string& p_name) {
if (opened) {
throw Opened(name, "add table " + p_name);
throw Opened(name, "add storage " + p_name);
}
Storage<K, V>* table = new Storage<K, V>(p_name, this);
tables.insert(std::make_pair(p_name, (iStorage*)table));
return table;
Storage<K, V>* storage = new Storage<K, V>(p_name, this);
storages.insert(std::make_pair(p_name, (iStorage*)storage));
return storage;
}
/**
@ -125,7 +130,7 @@ LMDBAL::Cache<K, V> * LMDBAL::Base::addCache(const std::string& p_name) {
throw Opened(name, "add cache " + p_name);
}
Cache<K, V>* cache = new Cache<K, V>(p_name, this);
tables.insert(std::make_pair(p_name, (iStorage*)cache));
storages.insert(std::make_pair(p_name, (iStorage*)cache));
return cache;
}
@ -134,7 +139,7 @@ LMDBAL::Cache<K, V> * LMDBAL::Base::addCache(const std::string& p_name) {
*/
template <class K, class V>
LMDBAL::Storage<K, V>* LMDBAL::Base::getStorage(const std::string& p_name) {
return static_cast<Storage<K, V>*>(tables.at(p_name));
return static_cast<Storage<K, V>*>(storages.at(p_name));
}
/**
@ -142,7 +147,7 @@ LMDBAL::Storage<K, V>* LMDBAL::Base::getStorage(const std::string& p_name) {
*/
template <class K, class V>
LMDBAL::Cache<K, V>* LMDBAL::Base::getCache(const std::string& p_name) {
return static_cast<Cache<K, V>*>(tables.at(p_name));
return static_cast<Cache<K, V>*>(storages.at(p_name));
}
#endif //LMDBAL_BASE_H