db_lmdb: include the error codes from lmdb api in error logs
This commit is contained in:
parent
d7fb03fc97
commit
79117d4275
|
@ -545,11 +545,12 @@ void BlockchainLMDB::add_block(const block& blk, const size_t& block_size, const
|
||||||
{
|
{
|
||||||
MDB_val_copy<crypto::hash> parent_key(blk.prev_id);
|
MDB_val_copy<crypto::hash> parent_key(blk.prev_id);
|
||||||
MDB_val parent_h;
|
MDB_val parent_h;
|
||||||
if (mdb_cursor_get(m_cur_block_heights, &parent_key, &parent_h, MDB_SET))
|
int result = mdb_cursor_get(m_cur_block_heights, &parent_key, &parent_h, MDB_SET);
|
||||||
|
if (result)
|
||||||
{
|
{
|
||||||
LOG_PRINT_L3("m_height: " << m_height);
|
LOG_PRINT_L3("m_height: " << m_height);
|
||||||
LOG_PRINT_L3("parent_key: " << blk.prev_id);
|
LOG_PRINT_L3("parent_key: " << blk.prev_id);
|
||||||
throw0(DB_ERROR("Failed to get top block hash to check for new block's parent"));
|
throw0(DB_ERROR(lmdb_error("Failed to get top block hash to check for new block's parent: ", result).c_str()));
|
||||||
}
|
}
|
||||||
uint64_t parent_height = *(const uint64_t *)parent_h.mv_data;
|
uint64_t parent_height = *(const uint64_t *)parent_h.mv_data;
|
||||||
if (parent_height != m_height - 1)
|
if (parent_height != m_height - 1)
|
||||||
|
@ -606,6 +607,8 @@ void BlockchainLMDB::add_block(const block& blk, const size_t& block_size, const
|
||||||
|
|
||||||
void BlockchainLMDB::remove_block()
|
void BlockchainLMDB::remove_block()
|
||||||
{
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||||
check_open();
|
check_open();
|
||||||
|
|
||||||
|
@ -614,29 +617,29 @@ void BlockchainLMDB::remove_block()
|
||||||
|
|
||||||
MDB_val_copy<uint64_t> k(m_height - 1);
|
MDB_val_copy<uint64_t> k(m_height - 1);
|
||||||
MDB_val h;
|
MDB_val h;
|
||||||
if (mdb_get(*m_write_txn, m_block_hashes, &k, &h))
|
if ((result = mdb_get(*m_write_txn, m_block_hashes, &k, &h)))
|
||||||
throw1(BLOCK_DNE("Attempting to remove block that's not in the db"));
|
throw1(BLOCK_DNE(lmdb_error("Attempting to remove block that's not in the db: ", result).c_str()));
|
||||||
|
|
||||||
if (mdb_del(*m_write_txn, m_blocks, &k, NULL))
|
if ((result = mdb_del(*m_write_txn, m_blocks, &k, NULL)))
|
||||||
throw1(DB_ERROR("Failed to add removal of block to db transaction"));
|
throw1(DB_ERROR(lmdb_error("Failed to add removal of block to db transaction: ", result).c_str()));
|
||||||
|
|
||||||
if (mdb_del(*m_write_txn, m_block_sizes, &k, NULL))
|
if ((result = mdb_del(*m_write_txn, m_block_sizes, &k, NULL)))
|
||||||
throw1(DB_ERROR("Failed to add removal of block size to db transaction"));
|
throw1(DB_ERROR(lmdb_error("Failed to add removal of block size to db transaction: ", result).c_str()));
|
||||||
|
|
||||||
if (mdb_del(*m_write_txn, m_block_diffs, &k, NULL))
|
if ((result = mdb_del(*m_write_txn, m_block_diffs, &k, NULL)))
|
||||||
throw1(DB_ERROR("Failed to add removal of block cumulative difficulty to db transaction"));
|
throw1(DB_ERROR(lmdb_error("Failed to add removal of block cumulative difficulty to db transaction: ", result).c_str()));
|
||||||
|
|
||||||
if (mdb_del(*m_write_txn, m_block_coins, &k, NULL))
|
if ((result = mdb_del(*m_write_txn, m_block_coins, &k, NULL)))
|
||||||
throw1(DB_ERROR("Failed to add removal of block total generated coins to db transaction"));
|
throw1(DB_ERROR(lmdb_error("Failed to add removal of block total generated coins to db transaction: ", result).c_str()));
|
||||||
|
|
||||||
if (mdb_del(*m_write_txn, m_block_timestamps, &k, NULL))
|
if ((result = mdb_del(*m_write_txn, m_block_timestamps, &k, NULL)))
|
||||||
throw1(DB_ERROR("Failed to add removal of block timestamp to db transaction"));
|
throw1(DB_ERROR(lmdb_error("Failed to add removal of block timestamp to db transaction: ", result).c_str()));
|
||||||
|
|
||||||
if (mdb_del(*m_write_txn, m_block_heights, &h, NULL))
|
if ((result = mdb_del(*m_write_txn, m_block_heights, &h, NULL)))
|
||||||
throw1(DB_ERROR("Failed to add removal of block height by hash to db transaction"));
|
throw1(DB_ERROR(lmdb_error("Failed to add removal of block height by hash to db transaction: ", result).c_str()));
|
||||||
|
|
||||||
if (mdb_del(*m_write_txn, m_block_hashes, &k, NULL))
|
if ((result = mdb_del(*m_write_txn, m_block_hashes, &k, NULL)))
|
||||||
throw1(DB_ERROR("Failed to add removal of block hash to db transaction"));
|
throw1(DB_ERROR(lmdb_error("Failed to add removal of block hash to db transaction: ", result).c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash)
|
void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash)
|
||||||
|
@ -674,6 +677,8 @@ void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const tr
|
||||||
|
|
||||||
void BlockchainLMDB::remove_transaction_data(const crypto::hash& tx_hash, const transaction& tx)
|
void BlockchainLMDB::remove_transaction_data(const crypto::hash& tx_hash, const transaction& tx)
|
||||||
{
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||||
check_open();
|
check_open();
|
||||||
|
|
||||||
|
@ -682,16 +687,16 @@ void BlockchainLMDB::remove_transaction_data(const crypto::hash& tx_hash, const
|
||||||
if (mdb_get(*m_write_txn, m_txs, &val_h, &unused))
|
if (mdb_get(*m_write_txn, m_txs, &val_h, &unused))
|
||||||
throw1(TX_DNE("Attempting to remove transaction that isn't in the db"));
|
throw1(TX_DNE("Attempting to remove transaction that isn't in the db"));
|
||||||
|
|
||||||
if (mdb_del(*m_write_txn, m_txs, &val_h, NULL))
|
if ((result = mdb_del(*m_write_txn, m_txs, &val_h, NULL)))
|
||||||
throw1(DB_ERROR("Failed to add removal of tx to db transaction"));
|
throw1(DB_ERROR(lmdb_error("Failed to add removal of tx to db transaction: ", result).c_str()));
|
||||||
if (mdb_del(*m_write_txn, m_tx_unlocks, &val_h, NULL))
|
if ((result = mdb_del(*m_write_txn, m_tx_unlocks, &val_h, NULL)))
|
||||||
throw1(DB_ERROR("Failed to add removal of tx unlock time to db transaction"));
|
throw1(DB_ERROR(lmdb_error("Failed to add removal of tx unlock time to db transaction: ", result).c_str()));
|
||||||
if (mdb_del(*m_write_txn, m_tx_heights, &val_h, NULL))
|
if ((result = mdb_del(*m_write_txn, m_tx_heights, &val_h, NULL)))
|
||||||
throw1(DB_ERROR("Failed to add removal of tx block height to db transaction"));
|
throw1(DB_ERROR(lmdb_error("Failed to add removal of tx block height to db transaction: ", result).c_str()));
|
||||||
|
|
||||||
remove_tx_outputs(&val_h, tx);
|
remove_tx_outputs(&val_h, tx);
|
||||||
|
|
||||||
auto result = mdb_del(*m_write_txn, m_tx_outputs, &val_h, NULL);
|
result = mdb_del(*m_write_txn, m_tx_outputs, &val_h, NULL);
|
||||||
if (result == MDB_NOTFOUND)
|
if (result == MDB_NOTFOUND)
|
||||||
LOG_PRINT_L1("tx has no outputs to remove: " << tx_hash);
|
LOG_PRINT_L1("tx has no outputs to remove: " << tx_hash);
|
||||||
else if (result)
|
else if (result)
|
||||||
|
@ -741,8 +746,8 @@ void BlockchainLMDB::add_output(const crypto::hash& tx_hash, const tx_out& tx_ou
|
||||||
|
|
||||||
MDB_val_copy<output_data_t> data(od);
|
MDB_val_copy<output_data_t> data(od);
|
||||||
//MDB_val_copy<crypto::public_key> val_pubkey(boost::get<txout_to_key>(tx_output.target).key);
|
//MDB_val_copy<crypto::public_key> val_pubkey(boost::get<txout_to_key>(tx_output.target).key);
|
||||||
if (mdb_cursor_put(m_cur_output_keys, &k, &data, MDB_APPEND))
|
if ((result = mdb_cursor_put(m_cur_output_keys, &k, &data, MDB_APPEND)))
|
||||||
throw0(DB_ERROR("Failed to add output pubkey to db transaction"));
|
throw0(DB_ERROR(lmdb_error("Failed to add output pubkey to db transaction: ", result).c_str()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -767,7 +772,7 @@ void BlockchainLMDB::remove_tx_outputs(const MDB_val *tx_hash, const transaction
|
||||||
}
|
}
|
||||||
else if (result)
|
else if (result)
|
||||||
{
|
{
|
||||||
throw0(DB_ERROR("DB error attempting to get an output"));
|
throw0(DB_ERROR(lmdb_error("DB error attempting to get an output", result).c_str()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -879,9 +884,9 @@ void BlockchainLMDB::remove_amount_output_index(const uint64_t amount, const MDB
|
||||||
{
|
{
|
||||||
// found the amount output index
|
// found the amount output index
|
||||||
// now delete it
|
// now delete it
|
||||||
result = mdb_cursor_del(m_cur_output_amounts, 0);
|
int result = mdb_cursor_del(m_cur_output_amounts, 0);
|
||||||
if (result)
|
if (result)
|
||||||
throw0(DB_ERROR(std::string("Error deleting amount output index ").append(boost::lexical_cast<std::string>(amount_output_index)).c_str()));
|
throw0(DB_ERROR(lmdb_error(std::string("Error deleting amount output index ").append(boost::lexical_cast<std::string>(amount_output_index).append(": ")).c_str(), result).c_str()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -996,6 +1001,8 @@ BlockchainLMDB::BlockchainLMDB(bool batch_transactions)
|
||||||
|
|
||||||
void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
|
void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
|
||||||
{
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||||
|
|
||||||
if (m_open)
|
if (m_open)
|
||||||
|
@ -1025,10 +1032,10 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
|
||||||
m_folder = filename;
|
m_folder = filename;
|
||||||
|
|
||||||
// set up lmdb environment
|
// set up lmdb environment
|
||||||
if (mdb_env_create(&m_env))
|
if ((result = mdb_env_create(&m_env)))
|
||||||
throw0(DB_ERROR("Failed to create lmdb environment"));
|
throw0(DB_ERROR(lmdb_error("Failed to create lmdb environment: ", result).c_str()));
|
||||||
if (mdb_env_set_maxdbs(m_env, 20))
|
if ((result = mdb_env_set_maxdbs(m_env, 20)))
|
||||||
throw0(DB_ERROR("Failed to set max number of dbs"));
|
throw0(DB_ERROR(lmdb_error("Failed to set max number of dbs: ", result).c_str()));
|
||||||
|
|
||||||
size_t mapsize = DEFAULT_MAPSIZE;
|
size_t mapsize = DEFAULT_MAPSIZE;
|
||||||
|
|
||||||
|
@ -1104,14 +1111,14 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
|
||||||
|
|
||||||
// get and keep current height
|
// get and keep current height
|
||||||
MDB_stat db_stats;
|
MDB_stat db_stats;
|
||||||
if (mdb_stat(txn, m_blocks, &db_stats))
|
if ((result = mdb_stat(txn, m_blocks, &db_stats)))
|
||||||
throw0(DB_ERROR("Failed to query m_blocks"));
|
throw0(DB_ERROR(lmdb_error("Failed to query m_blocks: ", result).c_str()));
|
||||||
LOG_PRINT_L2("Setting m_height to: " << db_stats.ms_entries);
|
LOG_PRINT_L2("Setting m_height to: " << db_stats.ms_entries);
|
||||||
m_height = db_stats.ms_entries;
|
m_height = db_stats.ms_entries;
|
||||||
|
|
||||||
// get and keep current number of outputs
|
// get and keep current number of outputs
|
||||||
if (mdb_stat(txn, m_output_indices, &db_stats))
|
if ((result = mdb_stat(txn, m_output_indices, &db_stats)))
|
||||||
throw0(DB_ERROR("Failed to query m_output_indices"));
|
throw0(DB_ERROR(lmdb_error("Failed to query m_output_indices: ", result).c_str()));
|
||||||
m_num_outputs = db_stats.ms_entries;
|
m_num_outputs = db_stats.ms_entries;
|
||||||
|
|
||||||
bool compatible = true;
|
bool compatible = true;
|
||||||
|
@ -1232,8 +1239,8 @@ void BlockchainLMDB::reset()
|
||||||
check_open();
|
check_open();
|
||||||
|
|
||||||
mdb_txn_safe txn;
|
mdb_txn_safe txn;
|
||||||
if (mdb_txn_begin(m_env, NULL, 0, txn))
|
if (auto result = mdb_txn_begin(m_env, NULL, 0, txn))
|
||||||
throw0(DB_ERROR("Failed to create a transaction for the db"));
|
throw0(DB_ERROR(lmdb_error("Failed to create a transaction for the db: ", result).c_str()));
|
||||||
mdb_drop(txn, m_blocks, 0);
|
mdb_drop(txn, m_blocks, 0);
|
||||||
mdb_drop(txn, m_block_timestamps, 0);
|
mdb_drop(txn, m_block_timestamps, 0);
|
||||||
mdb_drop(txn, m_block_heights, 0);
|
mdb_drop(txn, m_block_heights, 0);
|
||||||
|
|
Loading…
Reference in New Issue