Monero
Loading...
Searching...
No Matches
db_lmdb.cpp File Reference
#include "db_lmdb.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/format.hpp>
#include <boost/circular_buffer.hpp>
#include <memory>
#include <cstring>
#include "string_tools.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:

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

Namespaces

namespace  cryptonote
 Holds cryptonote related classes and helpers.

Macros

#define MONERO_DEFAULT_LOG_CATEGORY   "blockchain.db.lmdb"
#define VERSION   5
#define MDB_val_set(var, val)
#define MDB_val_sized(var, val)
#define MDB_val_str(var, 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)
#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

Enumerations

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

Functions

void cryptonote::lmdb_resized (MDB_env *env, int isactive)
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)
static bool cryptonote::is_v1_tx (MDB_cursor *c_txs_pruned, MDB_val *tx_id)
template<class t_pod_type>
std::string pod_to_hex (const t_pod_type &s)

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())); \
}
int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor)
Create a cursor handle.
Definition mdb.c:8570
const char * name
Definition options.c:30
tools::wallet2::message_signature_result_t result
Definition signature.cpp:62

◆ 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_drop(MDB_txn *txn, MDB_dbi dbi, int del)
Empty or delete+close a database.
Definition mdb.c:10943
int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi)
Open a database in the environment.
Definition mdb.c:10675
int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Create a transaction for use with the environment.
Definition mdb.c:3132

◆ LOGIF

#define LOGIF ( y)
Value:
if (ELPP->vRegistry()->allowed(y, "global"))
#define ELPP
Definition easylogging++.h:2794

◆ MDB_val_set

#define MDB_val_set ( var,
val )
Value:
MDB_val var = {sizeof(val), (void *)&val}
Generic structure used for passing keys and data in and out of the database.
Definition lmdb.h:286

◆ MDB_val_sized

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

◆ MDB_val_str

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

◆ MONERO_DEFAULT_LOG_CATEGORY

#define MONERO_DEFAULT_LOG_CATEGORY   "blockchain.db.lmdb"

◆ 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; \
}
int mdb_cursor_renew(MDB_txn *txn, MDB_cursor *cursor)
Renew a cursor handle.
Definition mdb.c:8604
Definition mdb.c:1372

◆ 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_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op)
Retrieve by cursor.
Definition mdb.c:7257
@ MDB_SET_KEY
Definition lmdb.h:423
#define MDB_CREATE
Definition lmdb.h:357
unsigned int MDB_dbi
A handle for an individual database in the DB environment.
Definition lmdb.h:270

◆ TXN_BLOCK_POSTFIX_SUCCESS

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

◆ 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())); \
} \
static int flags
Definition mdb_load.c:31

◆ TXN_POSTFIX_RDONLY

#define TXN_POSTFIX_RDONLY ( )

◆ TXN_POSTFIX_SUCCESS

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

◆ 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())); \
} \

◆ 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()
Definition mdb.c:1254

◆ VERSION

#define VERSION   5

Function Documentation

◆ pod_to_hex()

template<class t_pod_type>
std::string epee::string_tools::pod_to_hex ( const t_pod_type & s)