From 0693cff9251f91a05dd96b2f8910faea29cb29ce Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Mon, 26 Dec 2016 14:29:46 -0800 Subject: Use batch transactions when syncing Faster throughput while avoiding corruption. I.e., makes running with --db-sync-mode safe more tolerable. --- src/cryptonote_core/blockchain.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/cryptonote_core') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 42279184a..b4ed06bc0 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3377,9 +3377,10 @@ bool Blockchain::add_new_block(const block& bl_, block_verification_context& bvc void Blockchain::check_against_checkpoints(const checkpoints& points, bool enforce) { const auto& pts = points.get_points(); + bool stop_batch; CRITICAL_REGION_LOCAL(m_blockchain_lock); - m_db->batch_start(); + stop_batch = m_db->batch_start(); for (const auto& pt : pts) { // if the checkpoint is for a block we don't have yet, move on @@ -3403,7 +3404,8 @@ void Blockchain::check_against_checkpoints(const checkpoints& points, bool enfor } } } - m_db->batch_stop(); + if (stop_batch) + m_db->batch_stop(); } //------------------------------------------------------------------ // returns false if any of the checkpoints loading returns false. @@ -3477,6 +3479,7 @@ bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync) CRITICAL_REGION_LOCAL(m_blockchain_lock); TIME_MEASURE_START(t1); + m_db->batch_stop(); if (m_sync_counter > 0) { if (force_sync) @@ -3546,6 +3549,8 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::listbatch_start(blocks_entry.size()); + if ((m_db->height() + blocks_entry.size()) < m_blocks_hash_check.size()) return true; -- cgit v1.2.3 From eb1fb6011a233d515a2ad97c6983d960f0a72caf Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 31 Dec 2016 19:38:55 -0800 Subject: Tweak default db-sync-mode to fast:async:1 fsync the DB asynchronously, to allow block download/verification to proceed while syncing. Sync after every batch. Note that "fastest" still defaults to fastest:async:1000. --- src/cryptonote_core/cryptonote_core.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/cryptonote_core') diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 4010d3d44..cd3ed9ab0 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -323,9 +323,9 @@ namespace cryptonote LOG_PRINT_L0("Loading blockchain from folder " << folder.string() << " ..."); const std::string filename = folder.string(); - // temporarily default to fastest:async:1000 + // default to fast:async:1 blockchain_db_sync_mode sync_mode = db_async; - uint64_t blocks_per_sync = 1000; + uint64_t blocks_per_sync = 1; try { @@ -338,12 +338,12 @@ namespace cryptonote for(const auto &option : options) LOG_PRINT_L0("option: " << option); - // default to fast:async:1000 + // default to fast:async:1 uint64_t DEFAULT_FLAGS = DBS_FAST_MODE; if(options.size() == 0) { - // temporarily default to fastest:async:1000 + // default to fast:async:1 db_flags = DEFAULT_FLAGS; } @@ -359,7 +359,10 @@ namespace cryptonote else if(options[0] == "fast") db_flags = DBS_FAST_MODE; else if(options[0] == "fastest") + { db_flags = DBS_FASTEST_MODE; + blocks_per_sync = 1000; // default to fastest:async:1000 + } else db_flags = DEFAULT_FLAGS; } -- cgit v1.2.3 From eaf8470b293c65140b135829d65422208aa29c44 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 14 Jan 2017 11:28:17 -0800 Subject: Must wait for previous batch to finish before starting new one --- src/cryptonote_core/blockchain.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/cryptonote_core') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index b4ed06bc0..c368d7b24 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3544,12 +3544,17 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::listbatch_start(blocks_entry.size()); + while (!(stop_batch = m_db->batch_start(blocks_entry.size()))) { + m_blockchain_lock.unlock(); + epee::misc_utils::sleep_no_w(1000); + m_blockchain_lock.lock(); + } if ((m_db->height() + blocks_entry.size()) < m_blocks_hash_check.size()) return true; -- cgit v1.2.3