forked from blue/lmdbal
Cursors get closed after transaction that open them
This commit is contained in:
parent
68ea7df6a9
commit
e88efb458f
12 changed files with 225 additions and 56 deletions
|
@ -40,7 +40,8 @@
|
|||
LMDBAL::Transaction::Transaction():
|
||||
txn(nullptr),
|
||||
active(false),
|
||||
parent(nullptr)
|
||||
parent(nullptr),
|
||||
cursors()
|
||||
{}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +50,8 @@ LMDBAL::Transaction::Transaction():
|
|||
LMDBAL::Transaction::Transaction(TransactionID txn, const Base* parent) :
|
||||
txn(txn),
|
||||
active(true),
|
||||
parent(parent)
|
||||
parent(parent),
|
||||
cursors()
|
||||
{
|
||||
parent->transactions[txn] = this;
|
||||
}
|
||||
|
@ -60,7 +62,8 @@ LMDBAL::Transaction::Transaction(TransactionID txn, const Base* parent) :
|
|||
LMDBAL::Transaction::Transaction(Transaction&& other):
|
||||
txn(other.txn),
|
||||
active(other.active),
|
||||
parent(other.parent)
|
||||
parent(other.parent),
|
||||
cursors(other.cursors)
|
||||
{
|
||||
if (active) {
|
||||
parent->transactions[txn] = this;
|
||||
|
@ -88,6 +91,7 @@ LMDBAL::Transaction& LMDBAL::Transaction::operator=(Transaction&& other) {
|
|||
txn = other.txn;
|
||||
active = other.active;
|
||||
parent = other.parent;
|
||||
cursors = other.cursors;
|
||||
|
||||
if (active) {
|
||||
parent->transactions[txn] = this;
|
||||
|
@ -105,13 +109,14 @@ LMDBAL::Transaction& LMDBAL::Transaction::operator=(Transaction&& other) {
|
|||
*/
|
||||
void LMDBAL::Transaction::terminate() {
|
||||
if (active) {
|
||||
closeCursors();
|
||||
parent->abortTransaction(txn);
|
||||
|
||||
parent->transactions.erase(txn);
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Resets inner transaction properties to inactive state
|
||||
*/
|
||||
|
@ -119,8 +124,16 @@ void LMDBAL::Transaction::reset() {
|
|||
active = false;
|
||||
txn = nullptr;
|
||||
parent = nullptr;
|
||||
cursors.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Closes attached curors;
|
||||
*/
|
||||
void LMDBAL::Transaction::closeCursors () {
|
||||
for (const std::pair<const uint32_t, iCursor*>& pair : cursors)
|
||||
pair.second->terminated();
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Returns transaction states
|
||||
|
@ -197,8 +210,8 @@ void LMDBAL::WriteTransaction::abort() {
|
|||
*/
|
||||
void LMDBAL::WriteTransaction::commit() {
|
||||
if (active) {
|
||||
closeCursors();
|
||||
const_cast<Base*>(parent)->commitTransaction(txn);
|
||||
|
||||
parent->transactions.erase(txn);
|
||||
reset();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue