diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-09-02 11:30:57 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-09-02 11:30:57 +0200 |
commit | 1e57e48342f66efe215b306aaf902a0e41b3629c (patch) | |
tree | 15f0cd3bed84c680f5b16041b241a6cdcc823999 /src/blockchain_db | |
parent | Merge pull request #2370 (diff) | |
parent | cryptonote_protocol: error handling on cleanup_handle_incoming_blocks (diff) | |
download | monero-1e57e48342f66efe215b306aaf902a0e41b3629c.tar.xz |
Merge pull request #2372
c867357a cryptonote_protocol: error handling on cleanup_handle_incoming_blocks (moneromooo-monero)
ce901fcb Fix blockchain_import wedge on exception in cleanup_handle_incoming_blocks (moneromooo-monero)
84fa015e core: guard against exceptions in handle_incoming_{block,tx} (moneromooo-monero)
Diffstat (limited to 'src/blockchain_db')
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.cpp | 31 | ||||
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.h | 3 |
2 files changed, 25 insertions, 9 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 4100d9cca..b6978bdc4 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -2604,6 +2604,16 @@ void BlockchainLMDB::batch_commit() memset(&m_wcursors, 0, sizeof(m_wcursors)); } +void BlockchainLMDB::cleanup_batch() +{ + // for destruction of batch transaction + m_write_txn = nullptr; + delete m_write_batch_txn; + m_write_batch_txn = nullptr; + m_batch_active = false; + memset(&m_wcursors, 0, sizeof(m_wcursors)); +} + void BlockchainLMDB::batch_stop() { LOG_PRINT_L3("BlockchainLMDB::" << __func__); @@ -2618,15 +2628,18 @@ void BlockchainLMDB::batch_stop() check_open(); LOG_PRINT_L3("batch transaction: committing..."); TIME_MEASURE_START(time1); - m_write_txn->commit(); - TIME_MEASURE_FINISH(time1); - time_commit1 += time1; - // for destruction of batch transaction - m_write_txn = nullptr; - delete m_write_batch_txn; - m_write_batch_txn = nullptr; - m_batch_active = false; - memset(&m_wcursors, 0, sizeof(m_wcursors)); + try + { + m_write_txn->commit(); + TIME_MEASURE_FINISH(time1); + time_commit1 += time1; + cleanup_batch(); + } + catch (const std::exception &e) + { + cleanup_batch(); + throw; + } LOG_PRINT_L3("batch transaction: end"); } diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h index 3a11ddf0d..90274b904 100644 --- a/src/blockchain_db/lmdb/db_lmdb.h +++ b/src/blockchain_db/lmdb/db_lmdb.h @@ -368,6 +368,9 @@ private: // migrate from DB version 0 to 1 void migrate_0_1(); + void cleanup_batch(); + +private: MDB_env* m_env; MDB_dbi m_blocks; |