Electroneum
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 137 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 400 of file db_lmdb.cpp.

400  : m_txn(NULL), m_tinfo(NULL), m_check(check)
401 {
402  if (check)
403  {
404  while (creation_gate.test_and_set());
405  num_active_txns++;
406  creation_gate.clear();
407  }
408 }
mdb_threadinfo * m_tinfo
Definition: db_lmdb.h:167
static std::atomic< uint64_t > num_active_txns
Definition: db_lmdb.h:171
static std::atomic_flag creation_gate
Definition: db_lmdb.h:174

◆ ~mdb_txn_safe()

cryptonote::mdb_txn_safe::~mdb_txn_safe ( )

Definition at line 410 of file db_lmdb.cpp.

411 {
412  if (!m_check)
413  return;
414  LOG_PRINT_L3("mdb_txn_safe: destructor");
415  if (m_tinfo != nullptr)
416  {
418  memset(&m_tinfo->m_ti_rflags, 0, sizeof(m_tinfo->m_ti_rflags));
419  } else if (m_txn != nullptr)
420  {
421  if (m_batch_txn) // this is a batch txn and should have been handled before this point for safety
422  {
423  LOG_PRINT_L0("WARNING: mdb_txn_safe: m_txn is a batch txn and it's not NULL in destructor - calling mdb_txn_abort()");
424  }
425  else
426  {
427  // Example of when this occurs: a lookup fails, so a read-only txn is
428  // aborted through this destructor. However, successful read-only txns
429  // ideally should have been committed when done and not end up here.
430  //
431  // NOTE: not sure if this is ever reached for a non-batch write
432  // transaction, but it's probably not ideal if it did.
433  LOG_PRINT_L3("mdb_txn_safe: m_txn not NULL in destructor - calling mdb_txn_abort()");
434  }
436  }
437  num_active_txns--;
438 }
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)
Definition: misc_log_ex.h:102
#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 461 of file db_lmdb.cpp.

462 {
463  LOG_PRINT_L3("mdb_txn_safe: abort()");
464  if(m_txn != nullptr)
465  {
467  m_txn = nullptr;
468  }
469  else
470  {
471  LOG_PRINT_L0("WARNING: mdb_txn_safe: abort() called, but m_txn is NULL");
472  }
473 }
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 490 of file db_lmdb.cpp.

491 {
492  creation_gate.clear();
493 }

◆ commit()

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

Definition at line 446 of file db_lmdb.cpp.

447 {
448  if (message.size() == 0)
449  {
450  message = "Failed to commit a transaction to the db";
451  }
452 
453  if (auto result = mdb_txn_commit(m_txn))
454  {
455  m_txn = nullptr;
456  throw0(DB_ERROR(lmdb_error(message + ": ", result).c_str()));
457  }
458  m_txn = nullptr;
459 }
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 475 of file db_lmdb.cpp.

476 {
477  return num_active_txns;
478 }

◆ operator MDB_txn *()

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

Definition at line 151 of file db_lmdb.h.

152  {
153  return m_txn;
154  }

◆ operator MDB_txn **()

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

Definition at line 156 of file db_lmdb.h.

157  {
158  return &m_txn;
159  }

◆ prevent_new_txns()

void cryptonote::mdb_txn_safe::prevent_new_txns ( )
static

Definition at line 480 of file db_lmdb.cpp.

481 {
482  while (creation_gate.test_and_set());
483 }

◆ uncheck()

void cryptonote::mdb_txn_safe::uncheck ( )

Definition at line 440 of file db_lmdb.cpp.

441 {
442  num_active_txns--;
443  m_check = false;
444 }

◆ wait_no_active_txns()

void cryptonote::mdb_txn_safe::wait_no_active_txns ( )
static

Definition at line 485 of file db_lmdb.cpp.

486 {
487  while (num_active_txns > 0);
488 }

Member Data Documentation

◆ creation_gate

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

Definition at line 174 of file db_lmdb.h.

◆ m_batch_txn

bool cryptonote::mdb_txn_safe::m_batch_txn = false

Definition at line 169 of file db_lmdb.h.

◆ m_check

bool cryptonote::mdb_txn_safe::m_check

Definition at line 170 of file db_lmdb.h.

◆ m_tinfo

mdb_threadinfo* cryptonote::mdb_txn_safe::m_tinfo

Definition at line 167 of file db_lmdb.h.

◆ m_txn

MDB_txn* cryptonote::mdb_txn_safe::m_txn

Definition at line 168 of file db_lmdb.h.

◆ num_active_txns

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

Definition at line 171 of file db_lmdb.h.


The documentation for this struct was generated from the following files: