aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authorwarptangent <warptangent@inbox.com>2015-02-10 20:01:02 -0800
committerwarptangent <warptangent@inbox.com>2015-02-23 00:33:38 -0800
commit83fb6d8d07c0b473e7b53a35d8e69f586bd1945e (patch)
tree08f98bacfa03fc394caf03135abce73d20a2dbf9 /src/cryptonote_core
parentBlockchainDB, BlockchainLMDB: Add profiling for DB commits (diff)
downloadmonero-83fb6d8d07c0b473e7b53a35d8e69f586bd1945e.tar.xz
BlockchainLMDB: Add batch transaction support to tx_exists()
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp b/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp
index 25c25f399..4e9f6cb28 100644
--- a/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp
+++ b/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp
@@ -1132,20 +1132,23 @@ bool BlockchainLMDB::tx_exists(const crypto::hash& h) const
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
+ txn_safe txn;
+ txn_safe* txn_ptr = &txn;
if (m_batch_active)
+ txn_ptr = m_write_txn;
+ else
{
- LOG_PRINT_L0("WARNING: active batch transaction while creating a read-only txn in tx_exists()");
+ if (mdb_txn_begin(m_env, NULL, MDB_RDONLY, txn))
+ throw0(DB_ERROR("Failed to create a transaction for the db"));
}
- txn_safe txn;
- if (mdb_txn_begin(m_env, NULL, MDB_RDONLY, txn))
- throw0(DB_ERROR("Failed to create a transaction for the db"));
MDB_val_copy<crypto::hash> key(h);
MDB_val result;
- auto get_result = mdb_get(txn, m_txs, &key, &result);
+ auto get_result = mdb_get(*txn_ptr, m_txs, &key, &result);
if (get_result == MDB_NOTFOUND)
{
- txn.commit();
+ if (! m_batch_active)
+ txn.commit();
LOG_PRINT_L1("transaction with hash " << epee::string_tools::pod_to_hex(h) << " not found in db");
return false;
}