Transactions now get closed with the database
All checks were successful
Main LMDBAL workfow / Test LMDBAL with qt5 (push) Successful in 1m3s
Main LMDBAL workfow / Test LMDBAL with qt6 (push) Successful in 1m20s
Main LMDBAL workfow / Release documentation (push) Successful in 25s

This commit is contained in:
Blue 2024-12-22 19:39:35 +02:00
parent 56d35d4832
commit 68ea7df6a9
Signed by: blue
GPG key ID: 9B203B252A63EE38
9 changed files with 118 additions and 34 deletions

View file

@ -66,8 +66,10 @@ LMDBAL::Base::~Base() {
*/
void LMDBAL::Base::close() {
if (opened) {
for (const LMDBAL::TransactionID id : transactions)
abortTransaction(id, emptyName);
for (const std::pair<LMDBAL::TransactionID, LMDBAL::Transaction*> pair : transactions) {
abortTransaction(pair.first, emptyName);
pair.second->reset();
}
for (const std::pair<const std::string, iStorage*>& pair : storages)
pair.second->close();
@ -259,12 +261,13 @@ LMDBAL::WriteTransaction LMDBAL::Base::beginTransaction() {
* \brief Aborts transaction
*
* Terminates transaction cancelling changes.
* This is an optimal way to terminate read-only transactions
* Every storage receives notification about this transaction being aborted.
* This is an optimal way to abort public transactions
*
* \param[in] id - transaction ID you want to abort
*
* \exception LMDBAL::Closed - thrown if the database is closed
* \exception LMDBAL::Unknown - thrown if transaction with given ID was not found or if something unexpected happened
* \exception LMDBAL::Unknown - thrown if something unexpected happened
*/
void LMDBAL::Base::abortTransaction(LMDBAL::TransactionID id) const {
return abortTransaction(id, emptyName);}
@ -273,11 +276,13 @@ void LMDBAL::Base::abortTransaction(LMDBAL::TransactionID id) const {
* \brief Commits transaction
*
* Terminates transaction applying changes.
* Every storage receives notification about this transaction being committed.
* This is an optimal way to commit public transactions
*
* \param[in] id - transaction ID you want to commit
*
* \exception LMDBAL::Closed - thrown if the database is closed
* \exception LMDBAL::Unknown - thrown if transaction with given ID was not found or if something unexpected happened
* \exception LMDBAL::Unknown - thrown if something unexpected happened
*/
void LMDBAL::Base::commitTransaction(LMDBAL::TransactionID id) {
return commitTransaction(id, emptyName);}
@ -285,7 +290,9 @@ void LMDBAL::Base::commitTransaction(LMDBAL::TransactionID id) {
/**
* \brief Begins read-only transaction
*
* This function is intended to be called from subordinate storage or cache
* This function is intended to be called from subordinate storage, cache, transaction or cursor.
* Every storage receives notification about this transaction being started.
* This is an optimal way to begin read-only public transactions.
*
* \param[in] storageName - name of the storage/cache that you begin transaction from, needed just to inform if something went wrong
*
@ -299,7 +306,6 @@ LMDBAL::TransactionID LMDBAL::Base::beginReadOnlyTransaction(const std::string&
throw Closed("beginReadOnlyTransaction", name, storageName);
TransactionID txn = beginPrivateReadOnlyTransaction(storageName);
transactions.emplace(txn);
for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages)
pair.second->transactionStarted(txn, true);
@ -309,7 +315,9 @@ LMDBAL::TransactionID LMDBAL::Base::beginReadOnlyTransaction(const std::string&
/**
* \brief Begins writable transaction
*
* This function is intended to be called from subordinate storage or cache
* This function is intended to be called from subordinate storage, cache, transaction or cursor.
* Every storage receives notification about this transaction being started.
* This is an optimal way to begin public transactions.
*
* \param[in] storageName - name of the storage/cache that you begin transaction from, needed just to inform if something went wrong
*
@ -323,7 +331,6 @@ LMDBAL::TransactionID LMDBAL::Base::beginTransaction(const std::string& storageN
throw Closed("beginTransaction", name, storageName);
TransactionID txn = beginPrivateTransaction(storageName);
transactions.emplace(txn);
for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages)
pair.second->transactionStarted(txn, false);
@ -334,55 +341,46 @@ LMDBAL::TransactionID LMDBAL::Base::beginTransaction(const std::string& storageN
* \brief Aborts transaction
*
* Terminates transaction cancelling changes.
* This is an optimal way to terminate read-only transactions.
* This function is intended to be called from subordinate storage or cache
* Every storage receives notification about this transaction being aborted.
* This is an optimal way to abort public transactions.
* This function is intended to be called from subordinate storage, cache, transaction or cursor
*
* \param[in] id - transaction ID you want to abort
* \param[in] storageName - name of the storage/cache that you begin transaction from, needed just to inform if something went wrong
*
* \exception LMDBAL::Closed - thrown if the database is closed
* \exception LMDBAL::Unknown - thrown if transaction with given ID was not found or if something unexpected happened
* \exception LMDBAL::Unknown - thrown if something unexpected happened
*/
void LMDBAL::Base::abortTransaction(LMDBAL::TransactionID id, const std::string& storageName) const {
if (!opened)
throw Closed("abortTransaction", name, storageName);
Transactions::iterator itr = transactions.find(id);
if (itr == transactions.end()) //TODO may be it's a good idea to make an exception class for this
throw Unknown(name, "unable to abort transaction: transaction was not found", storageName);
abortPrivateTransaction(id, storageName);
for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages)
pair.second->transactionAborted(id);
transactions.erase(itr);
}
/**
* \brief Commits transaction
*
* Terminates transaction applying changes.
* This function is intended to be called from subordinate storage or cache
* Every storage receives notification about this transaction being committed.
* This is an optimal way to commit public transactions
* This function is intended to be called from subordinate storage, cache, transaction or cursor
*
* \param[in] id - transaction ID you want to commit
* \param[in] storageName - name of the storage/cache that you begin transaction from, needed just to inform if something went wrong
*
* \exception LMDBAL::Closed - thrown if the database is closed
* \exception LMDBAL::Unknown - thrown if transaction with given ID was not found or if something unexpected happened
* \exception LMDBAL::Unknown - thrown if something unexpected happened
*/
void LMDBAL::Base::commitTransaction(LMDBAL::TransactionID id, const std::string& storageName) {
if (!opened)
throw Closed("abortTransaction", name, storageName);
Transactions::iterator itr = transactions.find(id);
if (itr == transactions.end()) //TODO may be it's a good idea to make an exception class for this
throw Unknown(name, "unable to commit transaction: transaction was not found", storageName);
commitPrivateTransaction(id, storageName);
for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages)
pair.second->transactionCommited(id);
transactions.erase(itr);
}
/**