Electroneum
db_lmdb.cpp File Reference
#include "db_lmdb.h"
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
#include <boost/circular_buffer.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <memory>
#include <cstring>
#include "string_tools.h"
#include "file_io_utils.h"
#include "common/util.h"
#include "common/pruning.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "crypto/crypto.h"
#include "profile_tools.h"
#include "ringct/rctOps.h"
Include dependency graph for db_lmdb.cpp:

Go to the source code of this file.

Classes

struct  cryptonote::mdb_block_info_1
 
struct  cryptonote::mdb_block_info_2
 
struct  cryptonote::mdb_block_info_3
 
struct  cryptonote::mdb_block_info_4
 
struct  cryptonote::blk_height
 
struct  cryptonote::pre_rct_outkey
 
struct  cryptonote::outkey
 
struct  cryptonote::outtx
 
struct  cryptonote::acc_outs_t
 
struct  cryptonote::acc_addr_tx_t
 

Namespaces

 cryptonote
 Holds cryptonote related classes and helpers.
 

Macros

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "blockchain.db.lmdb"
 
#define VERSION   5
 
#define MDB_val_set(var, val)   MDB_val var = {sizeof(val), (void *)&val}
 
#define MDB_val_sized(var, val)   MDB_val var = {val.size(), (void *)val.data()}
 
#define MDB_val_str(var, val)   MDB_val var = {strlen(val) + 1, (void *)val}
 
#define CURSOR(name)
 
#define RCURSOR(name)
 
#define TXN_PREFIX(flags)
 
#define TXN_PREFIX_RDONLY()
 
#define TXN_POSTFIX_RDONLY()
 
#define TXN_POSTFIX_SUCCESS()
 
#define TXN_BLOCK_PREFIX(flags)
 
#define TXN_BLOCK_POSTFIX_SUCCESS()
 
#define RENAME_DB(name)
 
#define LOGIF(y)   if (ELPP->vRegistry()->allowed(y, "global"))
 
#define DELETE_DB(x)
 

Typedefs

typedef struct cryptonote::mdb_block_info_1 cryptonote::mdb_block_info_1
 
typedef struct cryptonote::mdb_block_info_2 cryptonote::mdb_block_info_2
 
typedef struct cryptonote::mdb_block_info_3 cryptonote::mdb_block_info_3
 
typedef struct cryptonote::mdb_block_info_4 cryptonote::mdb_block_info_4
 
typedef mdb_block_info_4 cryptonote::mdb_block_info
 
typedef struct cryptonote::blk_height cryptonote::blk_height
 
typedef struct cryptonote::pre_rct_outkey cryptonote::pre_rct_outkey
 
typedef struct cryptonote::outkey cryptonote::outkey
 
typedef struct cryptonote::outtx cryptonote::outtx
 
typedef struct cryptonote::acc_outs_t cryptonote::acc_outs_t
 
typedef struct cryptonote::acc_addr_tx_t cryptonote::acc_addr_tx_t
 

Enumerations

enum  { cryptonote::prune_mode_prune, cryptonote::prune_mode_update, cryptonote::prune_mode_check }
 

Functions

void cryptonote::lmdb_resized (MDB_env *env)
 
int cryptonote::lmdb_txn_begin (MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
 
int cryptonote::lmdb_txn_renew (MDB_txn *txn)
 

Macro Definition Documentation

◆ CURSOR

#define CURSOR (   name)
Value:
if (!m_cur_ ## name) { \
int result = mdb_cursor_open(*m_write_txn, m_ ## name, &m_cur_ ## name); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to open cursor: ", result).c_str())); \
}
const char * name
int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor)
Create a cursor handle.

Definition at line 285 of file db_lmdb.cpp.

◆ DELETE_DB

#define DELETE_DB (   x)
Value:
do { \
LOG_PRINT_L1(" " x ":"); \
result = mdb_txn_begin(m_env, NULL, 0, txn); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to create a transaction for the db: ", result).c_str())); \
result = mdb_dbi_open(txn, x, 0, &dbi); \
if (!result) { \
result = mdb_drop(txn, dbi, 1); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to delete " x ": ", result).c_str())); \
txn.commit(); \
} } while(0)
int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi)
Open a database in the environment.
int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del)
Empty or delete+close a database.
int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Create a transaction for use with the environment.

◆ ELECTRONEUM_DEFAULT_LOG_CATEGORY

#define ELECTRONEUM_DEFAULT_LOG_CATEGORY   "blockchain.db.lmdb"

Definition at line 49 of file db_lmdb.cpp.

◆ LOGIF

#define LOGIF (   y)    if (ELPP->vRegistry()->allowed(y, "global"))

Definition at line 4954 of file db_lmdb.cpp.

◆ MDB_val_set

#define MDB_val_set (   var,
  val 
)    MDB_val var = {sizeof(val), (void *)&val}

Definition at line 89 of file db_lmdb.cpp.

◆ MDB_val_sized

#define MDB_val_sized (   var,
  val 
)    MDB_val var = {val.size(), (void *)val.data()}

Definition at line 91 of file db_lmdb.cpp.

◆ MDB_val_str

#define MDB_val_str (   var,
  val 
)    MDB_val var = {strlen(val) + 1, (void *)val}

Definition at line 93 of file db_lmdb.cpp.

◆ RCURSOR

#define RCURSOR (   name)
Value:
if (!m_cur_ ## name) { \
int result = mdb_cursor_open(m_txn, m_ ## name, (MDB_cursor **)&m_cur_ ## name); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to open cursor: ", result).c_str())); \
if (m_cursors != &m_wcursors) \
m_tinfo->m_ti_rflags.m_rf_ ## name = true; \
} else if (m_cursors != &m_wcursors && !m_tinfo->m_ti_rflags.m_rf_ ## name) { \
int result = mdb_cursor_renew(m_txn, m_cur_ ## name); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to renew cursor: ", result).c_str())); \
m_tinfo->m_ti_rflags.m_rf_ ## name = true; \
}
const char * name
int mdb_cursor_renew(MDB_txn *txn, MDB_cursor *cursor)
Renew a cursor handle.
struct MDB_cursor MDB_cursor
Opaque structure for navigating through a database.
Definition: lmdb.h:273
int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor)
Create a cursor handle.

Definition at line 292 of file db_lmdb.cpp.

◆ RENAME_DB

#define RENAME_DB (   name)
Value:
do { \
char n2[] = name; \
MDB_dbi tdbi; \
n2[sizeof(n2)-2]--; \
/* play some games to put (name) on a writable page */ \
result = mdb_dbi_open(txn, n2, MDB_CREATE, &tdbi); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to create " + std::string(n2) + ": ", result).c_str())); \
result = mdb_drop(txn, tdbi, 1); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to delete " + std::string(n2) + ": ", result).c_str())); \
k.mv_data = (void *)name; \
k.mv_size = sizeof(name)-1; \
result = mdb_cursor_open(txn, 1, &c_cur); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for " name ": ", result).c_str())); \
result = mdb_cursor_get(c_cur, &k, NULL, MDB_SET_KEY); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to get DB record for " name ": ", result).c_str())); \
ptr = (char *)k.mv_data; \
ptr[sizeof(name)-2]++; } while(0)
int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi)
Open a database in the environment.
::std::string string
Definition: gtest-port.h:1097
const char * name
#define MDB_CREATE
Definition: lmdb.h:357
int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del)
Empty or delete+close a database.
int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op)
Retrieve by cursor.
int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor)
Create a cursor handle.

Definition at line 4932 of file db_lmdb.cpp.

◆ TXN_BLOCK_POSTFIX_SUCCESS

#define TXN_BLOCK_POSTFIX_SUCCESS ( )
Value:
do { \
if (! m_batch_active && ! m_write_txn) \
auto_txn.commit(); \
} while(0)

Definition at line 1823 of file db_lmdb.cpp.

◆ TXN_BLOCK_PREFIX

#define TXN_BLOCK_PREFIX (   flags)
Value:
; \
mdb_txn_safe auto_txn; \
mdb_txn_safe* txn_ptr = &auto_txn; \
if (m_batch_active || m_write_txn) \
txn_ptr = m_write_txn; \
else \
{ \
if (auto mdb_res = lmdb_txn_begin(m_env, NULL, flags, auto_txn)) \
throw0(DB_ERROR(lmdb_error(std::string("Failed to create a transaction for the db in ")+__FUNCTION__+": ", mdb_res).c_str())); \
} \
int lmdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Definition: db_lmdb.cpp:527
::std::string string
Definition: gtest-port.h:1097

Definition at line 1812 of file db_lmdb.cpp.

◆ TXN_POSTFIX_RDONLY

#define TXN_POSTFIX_RDONLY ( )

Definition at line 1795 of file db_lmdb.cpp.

◆ TXN_POSTFIX_SUCCESS

#define TXN_POSTFIX_SUCCESS ( )
Value:
do { \
if (! m_batch_active) \
auto_txn.commit(); \
} while(0)

Definition at line 1797 of file db_lmdb.cpp.

◆ TXN_PREFIX

#define TXN_PREFIX (   flags)
Value:
; \
mdb_txn_safe auto_txn; \
mdb_txn_safe* txn_ptr = &auto_txn; \
if (m_batch_active) \
txn_ptr = m_write_txn; \
else \
{ \
if (auto mdb_res = lmdb_txn_begin(m_env, NULL, flags, auto_txn)) \
throw0(DB_ERROR(lmdb_error(std::string("Failed to create a transaction for the db in ")+__FUNCTION__+": ", mdb_res).c_str())); \
} \
int lmdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Definition: db_lmdb.cpp:527
::std::string string
Definition: gtest-port.h:1097

Definition at line 1777 of file db_lmdb.cpp.

◆ TXN_PREFIX_RDONLY

#define TXN_PREFIX_RDONLY ( )
Value:
MDB_txn *m_txn; \
mdb_txn_cursors *m_cursors; \
mdb_txn_safe auto_txn; \
bool my_rtxn = block_rtxn_start(&m_txn, &m_cursors); \
if (my_rtxn) auto_txn.m_tinfo = m_tinfo.get(); \
else auto_txn.uncheck()
struct MDB_txn MDB_txn
Opaque structure for a transaction handle.
Definition: lmdb.h:267

Definition at line 1788 of file db_lmdb.cpp.

◆ VERSION

#define VERSION   5

Definition at line 60 of file db_lmdb.cpp.