Electroneum
Loading...
Searching...
No Matches
cryptonote::mdb_txn_safe Struct Reference

#include <db_lmdb.h>

Collaboration diagram for cryptonote::mdb_txn_safe:

Public Member Functions

 mdb_txn_safe (const bool check=true)
 ~mdb_txn_safe ()
void commit (std::string message="")
void abort ()
void uncheck ()
 operator MDB_txn * ()
 operator MDB_txn ** ()
uint64_t num_active_tx () const

Static Public Member Functions

static void prevent_new_txns ()
static void wait_no_active_txns ()
static void allow_new_txns ()

Public Attributes

mdb_threadinfom_tinfo
MDB_txnm_txn
bool m_batch_txn = false
bool m_check

Static Public Attributes

static std::atomic< uint64_tnum_active_txns {0}
static std::atomic_flag creation_gate = ATOMIC_FLAG_INIT

Detailed Description

Definition at line 140 of file db_lmdb.h.

Constructor & Destructor Documentation

◆ mdb_txn_safe()

cryptonote::mdb_txn_safe::mdb_txn_safe ( const bool check = true)

Definition at line 407 of file db_lmdb.cpp.

407 : m_txn(NULL), m_tinfo(NULL), m_check(check)
408{
409 if (check)
410 {
411 while (creation_gate.test_and_set());
413 creation_gate.clear();
414 }
415}
mdb_threadinfo * m_tinfo
Definition db_lmdb.h:170
static std::atomic< uint64_t > num_active_txns
Definition db_lmdb.h:174
static std::atomic_flag creation_gate
Definition db_lmdb.h:177

◆ ~mdb_txn_safe()

cryptonote::mdb_txn_safe::~mdb_txn_safe ( )

Definition at line 417 of file db_lmdb.cpp.

418{
419 if (!m_check)
420 return;
421 LOG_PRINT_L3("mdb_txn_safe: destructor");
422 if (m_tinfo != nullptr)
423 {
424 mdb_txn_reset(m_tinfo->m_ti_rtxn);
425 memset(&m_tinfo->m_ti_rflags, 0, sizeof(m_tinfo->m_ti_rflags));
426 } else if (m_txn != nullptr)
427 {
428 if (m_batch_txn) // this is a batch txn and should have been handled before this point for safety
429 {
430 LOG_PRINT_L0("WARNING: mdb_txn_safe: m_txn is a batch txn and it's not NULL in destructor - calling mdb_txn_abort()");
431 }
432 else
433 {
434 // Example of when this occurs: a lookup fails, so a read-only txn is
435 // aborted through this destructor. However, successful read-only txns
436 // ideally should have been committed when done and not end up here.
437 //
438 // NOTE: not sure if this is ever reached for a non-batch write
439 // transaction, but it's probably not ideal if it did.
440 LOG_PRINT_L3("mdb_txn_safe: m_txn not NULL in destructor - calling mdb_txn_abort()");
441 }
443 }
445}
void mdb_txn_reset(MDB_txn *txn)
Reset a read-only transaction.
void mdb_txn_abort(MDB_txn *txn)
Abandon all the operations of the transaction instead of saving them.
#define LOG_PRINT_L3(x)
#define LOG_PRINT_L0(x)
Definition misc_log_ex.h:99
Here is the call graph for this function:

Member Function Documentation

◆ abort()

void cryptonote::mdb_txn_safe::abort ( )

Definition at line 468 of file db_lmdb.cpp.

469{
470 LOG_PRINT_L3("mdb_txn_safe: abort()");
471 if(m_txn != nullptr)
472 {
474 m_txn = nullptr;
475 }
476 else
477 {
478 LOG_PRINT_L0("WARNING: mdb_txn_safe: abort() called, but m_txn is NULL");
479 }
480}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ allow_new_txns()

void cryptonote::mdb_txn_safe::allow_new_txns ( )
static

Definition at line 497 of file db_lmdb.cpp.

498{
499 creation_gate.clear();
500}
Here is the caller graph for this function:

◆ commit()

void cryptonote::mdb_txn_safe::commit ( std::string message = "")

Definition at line 453 of file db_lmdb.cpp.

454{
455 if (message.size() == 0)
456 {
457 message = "Failed to commit a transaction to the db";
458 }
459
460 if (auto result = mdb_txn_commit(m_txn))
461 {
462 m_txn = nullptr;
463 throw0(DB_ERROR(lmdb_error(message + ": ", result).c_str()));
464 }
465 m_txn = nullptr;
466}
std::string message("Message requiring signing")
int mdb_txn_commit(MDB_txn *txn)
Commit all the operations of a transaction into the database.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ num_active_tx()

uint64_t cryptonote::mdb_txn_safe::num_active_tx ( ) const

Definition at line 482 of file db_lmdb.cpp.

483{
484 return num_active_txns;
485}

◆ operator MDB_txn *()

cryptonote::mdb_txn_safe::operator MDB_txn * ( )
inline

Definition at line 154 of file db_lmdb.h.

155 {
156 return m_txn;
157 }

◆ operator MDB_txn **()

cryptonote::mdb_txn_safe::operator MDB_txn ** ( )
inline

Definition at line 159 of file db_lmdb.h.

160 {
161 return &m_txn;
162 }

◆ prevent_new_txns()

void cryptonote::mdb_txn_safe::prevent_new_txns ( )
static

Definition at line 487 of file db_lmdb.cpp.

488{
489 while (creation_gate.test_and_set());
490}
Here is the caller graph for this function:

◆ uncheck()

void cryptonote::mdb_txn_safe::uncheck ( )

Definition at line 447 of file db_lmdb.cpp.

448{
450 m_check = false;
451}

◆ wait_no_active_txns()

void cryptonote::mdb_txn_safe::wait_no_active_txns ( )
static

Definition at line 492 of file db_lmdb.cpp.

493{
494 while (num_active_txns > 0);
495}
Here is the caller graph for this function:

Member Data Documentation

◆ creation_gate

std::atomic_flag cryptonote::mdb_txn_safe::creation_gate = ATOMIC_FLAG_INIT
static

Definition at line 177 of file db_lmdb.h.

◆ m_batch_txn

bool cryptonote::mdb_txn_safe::m_batch_txn = false

Definition at line 172 of file db_lmdb.h.

◆ m_check

bool cryptonote::mdb_txn_safe::m_check

Definition at line 173 of file db_lmdb.h.

◆ m_tinfo

mdb_threadinfo* cryptonote::mdb_txn_safe::m_tinfo

Definition at line 170 of file db_lmdb.h.

◆ m_txn

MDB_txn* cryptonote::mdb_txn_safe::m_txn

Definition at line 171 of file db_lmdb.h.

◆ num_active_txns

std::atomic< uint64_t > cryptonote::mdb_txn_safe::num_active_txns {0}
static

Definition at line 174 of file db_lmdb.h.


The documentation for this struct was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/blockchain_db/lmdb/db_lmdb.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/blockchain_db/lmdb/db_lmdb.cpp