diff options
Diffstat (limited to 'src/blockchain_utilities')
-rw-r--r-- | src/blockchain_utilities/CMakeLists.txt | 10 | ||||
-rw-r--r-- | src/blockchain_utilities/README.md | 58 | ||||
-rw-r--r-- | src/blockchain_utilities/blockchain_converter.cpp | 6 | ||||
-rw-r--r-- | src/blockchain_utilities/blockchain_dump.cpp | 2 | ||||
-rw-r--r-- | src/blockchain_utilities/blockchain_export.cpp | 73 | ||||
-rw-r--r-- | src/blockchain_utilities/blockchain_import.cpp | 6 | ||||
-rw-r--r-- | src/blockchain_utilities/bootstrap_file.h | 2 | ||||
-rw-r--r-- | src/blockchain_utilities/cn_deserialize.cpp | 2 | ||||
-rw-r--r-- | src/blockchain_utilities/fake_core.h | 2 |
9 files changed, 137 insertions, 24 deletions
diff --git a/src/blockchain_utilities/CMakeLists.txt b/src/blockchain_utilities/CMakeLists.txt index ad2a5b40a..96b30b83b 100644 --- a/src/blockchain_utilities/CMakeLists.txt +++ b/src/blockchain_utilities/CMakeLists.txt @@ -99,6 +99,11 @@ target_link_libraries(blockchain_converter blockchain_db ${CMAKE_THREAD_LIBS_INIT}) +if(ARCH_WIDTH) + target_compile_definitions(blockchain_converter + PUBLIC -DARCH_WIDTH=${ARCH_WIDTH}) +endif() + add_dependencies(blockchain_converter version) set_property(TARGET blockchain_converter @@ -117,6 +122,11 @@ target_link_libraries(blockchain_import p2p ${CMAKE_THREAD_LIBS_INIT}) +if(ARCH_WIDTH) + target_compile_definitions(blockchain_import + PUBLIC -DARCH_WIDTH=${ARCH_WIDTH}) +endif() + add_dependencies(blockchain_import version) set_property(TARGET blockchain_import diff --git a/src/blockchain_utilities/README.md b/src/blockchain_utilities/README.md index d763bc4dd..9c69647ad 100644 --- a/src/blockchain_utilities/README.md +++ b/src/blockchain_utilities/README.md @@ -52,18 +52,68 @@ the `blockchain_import` command again, and it will restart from where it left of ## use default settings to import blockchain.raw into database $ blockchain_import -## fast import with large batch size, verification off -$ blockchain_import --batch-size 100000 --verify off +## fast import with large batch size, database mode "fastest", verification off +$ blockchain_import --batch-size 20000 --database lmdb#fastest --verify off + +``` + +### Import options + +`--input-file` +specifies input file path for importing + +default: `<data-dir>/export/blockchain.raw` + +`--output-file` +specifies output file path to export to + +default: `<data-dir>/export/blockchain.raw` + +`--block-stop` +stop at block number + +`--database <database type>` + +`--database <database type>#<flag(s)>` + +database type: `lmdb, berkeley, memory` + +flags: + +The flag after the # is interpreted as a composite mode/flag if there's only +one (no comma separated arguments). + +The composite mode represents multiple DB flags and support different database types: + +`safe, fast, fastest` + +Database-specific flags can be set instead. + +LMDB flags (more than one may be specified): + +`nosync, nometasync, writemap, mapasync, nordahead` + +BerkeleyDB flags (takes one): + +`txn_write_nosync, txn_nosync, txn_sync` + +``` +## Examples: +$ blockchain_import --database lmdb#fastest +$ blockchain_import --database berkeley#fastest -## LMDB flags can be set by appending them to the database type: -## flags: nosync, nometasync, writemap, mapasync $ blockchain_import --database lmdb#nosync $ blockchain_import --database lmdb#nosync,nometasync + +$ blockchain_import --database berkeley#txn_nosync ``` + ### Blockchain converter with batching `blockchain_converter` has also been updated and includes batching for faster writes. However, on lower RAM systems, this will be slower than using the exporter and importer utilities. The converter needs to keep the blockchain in memory for the duration of the conversion, like the original bitmonerod, thus leaving less memory available to the destination database to operate. +Due to higher resource use, it is recommended to use the importer with an exported file instead of the converter. + ```bash $ blockchain_converter --batch on --batch-size 20000 ``` diff --git a/src/blockchain_utilities/blockchain_converter.cpp b/src/blockchain_utilities/blockchain_converter.cpp index fdd369e79..7c33ec399 100644 --- a/src/blockchain_utilities/blockchain_converter.cpp +++ b/src/blockchain_utilities/blockchain_converter.cpp @@ -45,8 +45,6 @@ #include <iostream> -unsigned int epee::g_test_dbg_lock_sleep = 0; - namespace { @@ -57,12 +55,12 @@ bool opt_testnet = false; // number of blocks per batch transaction // adjustable through command-line argument according to available RAM -#if !defined(WIN32) +#if ARCH_WIDTH != 32 uint64_t db_batch_size_verify = 5000; #else // set a lower default batch size for Windows, pending possible LMDB issue with // large batch size. -uint64_t db_batch_size_verify = 1000; +uint64_t db_batch_size_verify = 100; #endif // converter only uses verify mode diff --git a/src/blockchain_utilities/blockchain_dump.cpp b/src/blockchain_utilities/blockchain_dump.cpp index 53dc22f8b..6fa5ce801 100644 --- a/src/blockchain_utilities/blockchain_dump.cpp +++ b/src/blockchain_utilities/blockchain_dump.cpp @@ -38,8 +38,6 @@ #include "common/command_line.h" #include "version.h" -unsigned int epee::g_test_dbg_lock_sleep = 0; - namespace po = boost::program_options; using namespace epee; // log_space diff --git a/src/blockchain_utilities/blockchain_export.cpp b/src/blockchain_utilities/blockchain_export.cpp index f5dea731a..964c610cd 100644 --- a/src/blockchain_utilities/blockchain_export.cpp +++ b/src/blockchain_utilities/blockchain_export.cpp @@ -29,15 +29,42 @@ #include "bootstrap_file.h" #include "blocksdat_file.h" #include "common/command_line.h" +#include "blockchain_db/blockchain_db.h" +#include "blockchain_db/lmdb/db_lmdb.h" +#if defined(BERKELEY_DB) +#include "blockchain_db/berkeleydb/db_bdb.h" +#endif +#include "blockchain_db/db_types.h" #include "version.h" -unsigned int epee::g_test_dbg_lock_sleep = 0; - namespace po = boost::program_options; using namespace epee; // log_space +std::string join_set_strings(const std::unordered_set<std::string>& db_types_all, const char* delim) +{ + std::string result; + std::ostringstream s; + std::copy(db_types_all.begin(), db_types_all.end(), std::ostream_iterator<std::string>(s, delim)); + result = s.str(); + if (result.length() > 0) + result.erase(result.end()-strlen(delim), result.end()); + return result; +} + int main(int argc, char* argv[]) { +#if defined(BLOCKCHAIN_DB) && (BLOCKCHAIN_DB == DB_MEMORY) + std::string default_db_type = "memory"; +#else + std::string default_db_type = "lmdb"; +#endif + + std::unordered_set<std::string> db_types_all = cryptonote::blockchain_db_types; + db_types_all.insert("memory"); + + std::string available_dbs = join_set_strings(db_types_all, ", "); + available_dbs = "available: " + available_dbs; + uint32_t log_level = 0; uint64_t block_stop = 0; bool blocks_dat = false; @@ -58,6 +85,9 @@ int main(int argc, char* argv[]) , "Run on testnet." , false }; + const command_line::arg_descriptor<std::string> arg_database = { + "database", available_dbs.c_str(), default_db_type + }; const command_line::arg_descriptor<bool> arg_blocks_dat = {"blocksdat", "Output in blocks.dat format", blocks_dat}; @@ -66,6 +96,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_cmd_sett, arg_output_file); command_line::add_arg(desc_cmd_sett, arg_testnet_on); command_line::add_arg(desc_cmd_sett, arg_log_level); + command_line::add_arg(desc_cmd_sett, arg_database); command_line::add_arg(desc_cmd_sett, arg_block_stop); command_line::add_arg(desc_cmd_sett, arg_blocks_dat); @@ -107,6 +138,20 @@ int main(int argc, char* argv[]) auto data_dir_arg = opt_testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir; m_config_folder = command_line::get_arg(vm, data_dir_arg); + std::string db_type = command_line::get_arg(vm, arg_database); + if (db_types_all.count(db_type) == 0) + { + std::cerr << "Invalid database type: " << db_type << std::endl; + return 1; + } +#if !defined(BERKELEY_DB) + if (db_type == "berkeley") + { + LOG_ERROR("BerkeleyDB support disabled."); + return false; + } +#endif + if (command_line::has_arg(vm, arg_output_file)) output_file_path = boost::filesystem::path(command_line::get_arg(vm, arg_output_file)); else @@ -138,17 +183,33 @@ int main(int argc, char* argv[]) tx_memory_pool m_mempool(*core_storage); core_storage = new Blockchain(m_mempool); - BlockchainDB* db = new BlockchainLMDB(); + int db_flags = 0; + + BlockchainDB* db = nullptr; + if (db_type == "lmdb") + { + db_flags |= MDB_RDONLY; + db = new BlockchainLMDB(); + } +#if defined(BERKELEY_DB) + else if (db_type == "berkeley") + db = new BlockchainBDB(); +#endif + else + { + LOG_ERROR("Attempted to use non-existent database type: " << db_type); + throw std::runtime_error("Attempting to use non-existent database type"); + } + LOG_PRINT_L0("database: " << db_type); + boost::filesystem::path folder(m_config_folder); folder /= db->get_db_name(); - int lmdb_flags = 0; - lmdb_flags |= MDB_RDONLY; const std::string filename = folder.string(); LOG_PRINT_L0("Loading blockchain from folder " << filename << " ..."); try { - db->open(filename, lmdb_flags); + db->open(filename, db_flags); } catch (const std::exception& e) { diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp index daa5db2a3..1aaf2bddc 100644 --- a/src/blockchain_utilities/blockchain_import.cpp +++ b/src/blockchain_utilities/blockchain_import.cpp @@ -44,8 +44,6 @@ #include "fake_core.h" -unsigned int epee::g_test_dbg_lock_sleep = 0; - namespace { // CONFIG @@ -56,11 +54,11 @@ bool opt_testnet = true; // number of blocks per batch transaction // adjustable through command-line argument according to available RAM -#if !defined(WIN32) +#if ARCH_WIDTH != 32 uint64_t db_batch_size = 20000; #else // set a lower default batch size, pending possible LMDB issue with large transaction size -uint64_t db_batch_size = 1000; +uint64_t db_batch_size = 100; #endif // when verifying, use a smaller default batch size so progress is more diff --git a/src/blockchain_utilities/bootstrap_file.h b/src/blockchain_utilities/bootstrap_file.h index 1e1c66ba9..dd134f7ae 100644 --- a/src/blockchain_utilities/bootstrap_file.h +++ b/src/blockchain_utilities/bootstrap_file.h @@ -37,8 +37,6 @@ #include "cryptonote_core/cryptonote_basic.h" #include "cryptonote_core/blockchain_storage.h" #include "cryptonote_core/blockchain.h" -#include "blockchain_db/blockchain_db.h" -#include "blockchain_db/lmdb/db_lmdb.h" #include <algorithm> #include <cstdio> diff --git a/src/blockchain_utilities/cn_deserialize.cpp b/src/blockchain_utilities/cn_deserialize.cpp index 6c6288aec..bf02dc150 100644 --- a/src/blockchain_utilities/cn_deserialize.cpp +++ b/src/blockchain_utilities/cn_deserialize.cpp @@ -32,8 +32,6 @@ #include "common/command_line.h" #include "version.h" -unsigned int epee::g_test_dbg_lock_sleep = 0; - namespace po = boost::program_options; using namespace epee; // log_space diff --git a/src/blockchain_utilities/fake_core.h b/src/blockchain_utilities/fake_core.h index 20a3361b6..2fb5031d3 100644 --- a/src/blockchain_utilities/fake_core.h +++ b/src/blockchain_utilities/fake_core.h @@ -33,7 +33,9 @@ #include "cryptonote_core/blockchain_storage.h" // in-memory DB #include "blockchain_db/blockchain_db.h" #include "blockchain_db/lmdb/db_lmdb.h" +#if defined(BERKELEY_DB) #include "blockchain_db/berkeleydb/db_bdb.h" +#endif using namespace cryptonote; |