Some refactor
All checks were successful
Main LMDBAL workfow / Test LMDBAL with qt5 (push) Successful in 1m7s
Main LMDBAL workfow / Test LMDBAL with qt6 (push) Successful in 2m42s
Main LMDBAL workfow / Release documentation (push) Successful in 32s

This commit is contained in:
Blue 2025-01-05 18:39:36 +02:00
parent bfb1d007ad
commit 3ae1fd15c0
Signed by: blue
GPG Key ID: 9B203B252A63EE38
5 changed files with 50 additions and 40 deletions

View File

@ -71,7 +71,7 @@ LMDBAL::CursorCommon::CursorCommon (CursorCommon&& other):
other.dropped(); other.dropped();
if (state == openedPublic) if (state == openedPublic)
storage->attachCursorToTransaction(id, handle, this); attachToTransaction();
} }
/** /**
@ -99,7 +99,7 @@ LMDBAL::CursorCommon& LMDBAL::CursorCommon::operator = (CursorCommon&& other) {
other.reset(); other.reset();
if (state == openedPublic) if (state == openedPublic)
storage->attachCursorToTransaction(id, handle, this); attachToTransaction();
return *this; return *this;
} }
@ -161,7 +161,7 @@ void LMDBAL::CursorCommon::terminated () {
void LMDBAL::CursorCommon::close () { void LMDBAL::CursorCommon::close () {
switch (state) { switch (state) {
case openedPublic: case openedPublic:
storage->disconnectCursorFromTransaction(id, handle); disconnectFromTransaction();
storage->_mdbCursorClose(handle); storage->_mdbCursorClose(handle);
state = closed; state = closed;
@ -231,7 +231,7 @@ void LMDBAL::CursorCommon::open (const Transaction& transaction) {
if (result != MDB_SUCCESS) if (result != MDB_SUCCESS)
storage->throwUnknown(result); storage->throwUnknown(result);
storage->attachCursorToTransaction(id, handle, this); transaction.cursors[id] = this;
state = openedPublic; state = openedPublic;
} break; } break;
default: default:
@ -267,7 +267,7 @@ void LMDBAL::CursorCommon::renew () {
storage->openCursorTransaction(&handle, true); storage->openCursorTransaction(&handle, true);
break; break;
case openedPublic: case openedPublic:
storage->disconnectCursorFromTransaction(id, handle); disconnectFromTransaction();
storage->openCursorTransaction(&handle, true); storage->openCursorTransaction(&handle, true);
state = openedPrivate; state = openedPrivate;
break; break;
@ -309,16 +309,16 @@ void LMDBAL::CursorCommon::renew (const Transaction& transaction) {
if (result != MDB_SUCCESS) if (result != MDB_SUCCESS)
storage->throwUnknown(result); storage->throwUnknown(result);
storage->attachCursorToTransaction(id, handle, this); transaction.cursors[id] = this;
state = openedPublic; state = openedPublic;
} break; } break;
case openedPublic: { case openedPublic: {
storage->disconnectCursorFromTransaction(id, handle); disconnectFromTransaction();
int result = storage->_mdbCursorRenew(txn, handle); int result = storage->_mdbCursorRenew(txn, handle);
if (result != MDB_SUCCESS) if (result != MDB_SUCCESS)
storage->throwUnknown(result); storage->throwUnknown(result);
storage->attachCursorToTransaction(id, handle, this); transaction.cursors[id] = this;
} break; } break;
default: default:
break; break;
@ -340,3 +340,27 @@ bool LMDBAL::CursorCommon::empty () const {
bool LMDBAL::CursorCommon::opened () const { bool LMDBAL::CursorCommon::opened () const {
return state != closed; return state != closed;
} }
/**
* \brief Links cursor to the transaction it has been opened with
*
* Cursor must be opened by a public transaction
*
* \exception std::out_of_range thrown if LMDBAL::Transaction pointer wasn't found in the LMDBAL::Base
*/
void LMDBAL::CursorCommon::attachToTransaction () {
Transaction* txn = storage->getTransactionForCursor(handle);
txn->cursors[id] = this;
}
/**
* \brief Disconnects cursor from the transaction it has been opened with
*
* Cursor must be still opened by a public transaction
*
* \exception std::out_of_range thrown if LMDBAL::Transaction pointer wasn't found in the LMDBAL::Base
*/
void LMDBAL::CursorCommon::disconnectFromTransaction () {
Transaction* txn = storage->getTransactionForCursor(handle);
txn->cursors.erase(id);
}

View File

@ -61,6 +61,10 @@ protected:
void dropped(); void dropped();
void reset(); void reset();
private:
void attachToTransaction();
void disconnectFromTransaction();
protected: protected:
uint32_t id; uint32_t id;
State state; State state;

View File

@ -162,21 +162,19 @@ LMDBAL::SizeType LMDBAL::StorageCommon::count() const {
} }
/** /**
* \brief Links cursor to the transaction it has been opened with * \brief Retrieves public transaction object for a cursor handle
* *
* This a service function is designed to be called by from LMDBAL::Cursor * Cursor must be still opened by a public transaction
* Cursor must be opened by a public transaction *
* \param[out] cursor - cursor handle
* *
* \exception std::out_of_range thrown if LMDBAL::Transaction pointer wasn't found in the LMDBAL::Base * \exception std::out_of_range thrown if LMDBAL::Transaction pointer wasn't found in the LMDBAL::Base
*/ */
LMDBAL::Transaction* LMDBAL::StorageCommon::getTransactionForCursor (MDB_cursor* cursor) const {
void LMDBAL::StorageCommon::attachCursorToTransaction (uint32_t cursorId, MDB_cursor* cursorHandle, CursorCommon* pointer) const { TransactionID txnID = _mdbCursorTxn(cursor);
TransactionID txnID = _mdbCursorTxn(cursorHandle); return db->transactions.at(txnID);
Transaction* txn = db->transactions.at(txnID);
txn->cursors[cursorId] = pointer;
} }
/** /**
* \brief Opens a transaction that is ment to be private to LMDBAL::Cursor, but public to the LMDBAL::Storage * \brief Opens a transaction that is ment to be private to LMDBAL::Cursor, but public to the LMDBAL::Storage
* *
@ -221,22 +219,6 @@ void LMDBAL::StorageCommon::closeCursorTransaction (MDB_cursor* cursor, bool clo
transactionAborted(txn); transactionAborted(txn);
} }
/**
* \brief Disconnects cursor from the transaction it has been opened with
*
* This a service function is designed to be called by from LMDBAL::Cursor
* Cursor must be still opened by a public transaction
*
* \exception std::out_of_range thrown if LMDBAL::Transaction pointer wasn't found in the LMDBAL::Base
*/
void LMDBAL::StorageCommon::disconnectCursorFromTransaction (uint32_t cursorId, MDB_cursor* cursorHandle) const {
TransactionID txnID = _mdbCursorTxn(cursorHandle);
Transaction* txn = db->transactions.at(txnID);
txn->cursors.erase(cursorId);
}
/** /**
* \brief Storage size (private transaction variant) * \brief Storage size (private transaction variant)
* *
@ -553,7 +535,6 @@ int LMDBAL::StorageCommon::_mdbFlags(MDB_txn* txn, uint32_t& flags) const {
return mdb_dbi_flags(txn, dbi, &flags); return mdb_dbi_flags(txn, dbi, &flags);
} }
int LMDBAL::StorageCommon::_mdbCursorOpen(MDB_txn* txn, MDB_cursor** cursor) const { int LMDBAL::StorageCommon::_mdbCursorOpen(MDB_txn* txn, MDB_cursor** cursor) const {
return mdb_cursor_open(txn, dbi, cursor); return mdb_cursor_open(txn, dbi, cursor);
} }

View File

@ -74,10 +74,10 @@ protected:
virtual int drop(TransactionID transaction); virtual int drop(TransactionID transaction);
virtual SizeType count(TransactionID txn) const; virtual SizeType count(TransactionID txn) const;
Transaction* getTransactionForCursor(MDB_cursor* cursor) const;
void openCursorTransaction(MDB_cursor** cursor, bool renew = false) const; void openCursorTransaction(MDB_cursor** cursor, bool renew = false) const;
void closeCursorTransaction(MDB_cursor* cursor, bool closeCursor = false) const; void closeCursorTransaction(MDB_cursor* cursor, bool closeCursor = false) const;
void attachCursorToTransaction(uint32_t cursorId, MDB_cursor* cursorHandle, CursorCommon* pointer) const;
void disconnectCursorFromTransaction(uint32_t cursorId, MDB_cursor* cursorHandle) const;
int _mdbOpen(MDB_txn* txn, unsigned int flags = 0); int _mdbOpen(MDB_txn* txn, unsigned int flags = 0);

View File

@ -27,6 +27,7 @@ class CursorCommon;
class Transaction { class Transaction {
friend class Base; friend class Base;
friend class StorageCommon; friend class StorageCommon;
friend class CursorCommon;
public: public:
explicit Transaction(); explicit Transaction();
explicit Transaction(Transaction&& other); explicit Transaction(Transaction&& other);
@ -44,10 +45,10 @@ protected:
void closeCursors(); void closeCursors();
protected: protected:
TransactionID txn; /**<\brief Transaction inner handler*/ TransactionID txn; /**<\brief Transaction inner handler*/
bool active; /**<\brief Transaction state*/ bool active; /**<\brief Transaction state*/
const Base* parent; /**<\brief Pointer to the database this transaction belongs to*/ const Base* parent; /**<\brief Pointer to the database this transaction belongs to*/
std::map<uint32_t, CursorCommon*> cursors; /**<\brief a collection of cursors curently opened under this transaction*/ mutable std::map<uint32_t, CursorCommon*> cursors; /**<\brief a collection of cursors curently opened under this transaction*/
}; };
class WriteTransaction : public Transaction { class WriteTransaction : public Transaction {