BlockchainDB/LMDB/BDB: Extract DB txn functions for block add/remove

This commit is contained in:
warptangent 2016-02-08 08:32:19 -08:00
parent f47d5b0fe3
commit f3a6000094
No known key found for this signature in database
GPG Key ID: 0E490BEBFBE4E92D
5 changed files with 65 additions and 0 deletions

View File

@ -1831,6 +1831,21 @@ void BlockchainBDB::set_batch_transactions(bool batch_transactions)
LOG_PRINT_L3("batch transactions " << (m_batch_transactions ? "enabled" : "disabled")); 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) 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__); LOG_PRINT_L3("BlockchainBDB::" << __func__);

View File

@ -328,6 +328,10 @@ public:
virtual void batch_stop(); virtual void batch_stop();
virtual void batch_abort(); 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 void pop_block(block& blk, std::vector<transaction>& txs);
#if defined(BDB_BULK_CAN_THREAD) #if defined(BDB_BULK_CAN_THREAD)

View File

@ -368,6 +368,10 @@ public:
virtual void batch_stop() = 0; virtual void batch_stop() = 0;
virtual void set_batch_transactions(bool) = 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 // 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 // NOTE: subclass implementations of this (or the functions it calls) need
// to handle undoing any partially-added blocks in the event of a failure. // to handle undoing any partially-added blocks in the event of a failure.

View File

@ -2190,6 +2190,44 @@ void BlockchainLMDB::set_batch_transactions(bool batch_transactions)
LOG_PRINT_L3("batch transactions " << (m_batch_transactions ? "enabled" : "disabled")); 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, 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) const std::vector<transaction>& txs)
{ {

View File

@ -194,6 +194,10 @@ public:
virtual void batch_stop(); virtual void batch_stop();
virtual void batch_abort(); 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 void pop_block(block& blk, std::vector<transaction>& txs);
virtual bool can_thread_bulk_indices() const { return true; } virtual bool can_thread_bulk_indices() const { return true; }