aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db
diff options
context:
space:
mode:
Diffstat (limited to 'src/blockchain_db')
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp15
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.h4
-rw-r--r--src/blockchain_db/blockchain_db.h4
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp38
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h4
5 files changed, 65 insertions, 0 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index 2c18ae5df..f572ddf9d 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -1831,6 +1831,21 @@ void BlockchainBDB::set_batch_transactions(bool batch_transactions)
LOG_PRINT_L3("batch transactions " << (m_batch_transactions ? "enabled" : "disabled"));
}
+void BlockchainBDB::block_txn_start()
+{
+ // TODO
+}
+
+void BlockchainBDB::block_txn_stop()
+{
+ // TODO
+}
+
+void BlockchainBDB::block_txn_abort()
+{
+ // TODO
+}
+
uint64_t BlockchainBDB::add_block(const block& blk, const size_t& block_size, const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated, const std::vector<transaction>& txs)
{
LOG_PRINT_L3("BlockchainBDB::" << __func__);
diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h
index 6db91aa1e..42119da93 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.h
+++ b/src/blockchain_db/berkeleydb/db_bdb.h
@@ -328,6 +328,10 @@ public:
virtual void batch_stop();
virtual void batch_abort();
+ virtual void block_txn_start();
+ virtual void block_txn_stop();
+ virtual void block_txn_abort();
+
virtual void pop_block(block& blk, std::vector<transaction>& txs);
#if defined(BDB_BULK_CAN_THREAD)
diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h
index 4a140e5f6..31d5e2644 100644
--- a/src/blockchain_db/blockchain_db.h
+++ b/src/blockchain_db/blockchain_db.h
@@ -368,6 +368,10 @@ public:
virtual void batch_stop() = 0;
virtual void set_batch_transactions(bool) = 0;
+ virtual void block_txn_start() = 0;
+ virtual void block_txn_stop() = 0;
+ virtual void block_txn_abort() = 0;
+
// adds a block with the given metadata to the top of the blockchain, returns the new height
// NOTE: subclass implementations of this (or the functions it calls) need
// to handle undoing any partially-added blocks in the event of a failure.
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 401983f19..de82357b6 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -2190,6 +2190,44 @@ void BlockchainLMDB::set_batch_transactions(bool batch_transactions)
LOG_PRINT_L3("batch transactions " << (m_batch_transactions ? "enabled" : "disabled"));
}
+void BlockchainLMDB::block_txn_start()
+{
+ LOG_PRINT_L3("BlockchainLMDB::" << __func__);
+ if (! m_batch_active && m_write_txn)
+ throw0(DB_ERROR((std::string("Attempted to start new write txn when write txn already exists in ")+__FUNCTION__).c_str()));
+ if (! m_batch_active)
+ {
+ m_write_txn = new mdb_txn_safe();
+ if (auto mdb_res = mdb_txn_begin(m_env, NULL, 0, *m_write_txn))
+ throw0(DB_ERROR(lmdb_error("Failed to create a transaction for the db: ", mdb_res).c_str()));
+ }
+}
+
+void BlockchainLMDB::block_txn_stop()
+{
+ LOG_PRINT_L3("BlockchainLMDB::" << __func__);
+ if (! m_batch_active)
+ {
+ TIME_MEASURE_START(time1);
+ m_write_txn->commit();
+ TIME_MEASURE_FINISH(time1);
+ time_commit1 += time1;
+
+ delete m_write_txn;
+ m_write_txn = NULL;
+ }
+}
+
+void BlockchainLMDB::block_txn_abort()
+{
+ LOG_PRINT_L3("BlockchainLMDB::" << __func__);
+ if (! m_batch_active)
+ {
+ delete m_write_txn;
+ m_write_txn = NULL;
+ }
+}
+
uint64_t BlockchainLMDB::add_block(const block& blk, const size_t& block_size, const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated,
const std::vector<transaction>& txs)
{
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index eb0704ab2..e88bcd01b 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -194,6 +194,10 @@ public:
virtual void batch_stop();
virtual void batch_abort();
+ virtual void block_txn_start();
+ virtual void block_txn_stop();
+ virtual void block_txn_abort();
+
virtual void pop_block(block& blk, std::vector<transaction>& txs);
virtual bool can_thread_bulk_indices() const { return true; }