diff --git a/libraries/chain_kv/include/b1/chain_kv/chain_kv.hpp b/libraries/chain_kv/include/b1/chain_kv/chain_kv.hpp index 6f8273c2356..76aab985dc2 100644 --- a/libraries/chain_kv/include/b1/chain_kv/chain_kv.hpp +++ b/libraries/chain_kv/include/b1/chain_kv/chain_kv.hpp @@ -318,10 +318,24 @@ struct database { std::vector handles; check(rocksdb::DB::Open(loaded_db_opt, db_path, loaded_cf_descs, &handles, &p), "database::database:rocksdb::DB::Open (options files): "); } else { - // This is only for embedded RocksDB instance creation. rocksdb::Options options; options.create_if_missing = create_if_missing; + // Configuration tested. + options.IncreaseParallelism(20); // number of background threads + options.max_open_files = 765; // max number of files in open + + // Those are from RocksDB Performance Tuning Guide for a typical + // setting. Applications are encuroage to experiment different settings + // and use options file instead. + options.compaction_style = rocksdb::kCompactionStyleLevel; // level style compaction + options.level0_file_num_compaction_trigger = 10; // number of L0 files to trigger L0 to L1 compaction. + options.level0_slowdown_writes_trigger = 20; // number of L0 files that will slow down writes + options.level0_stop_writes_trigger = 40; // number of L0 files that will stop writes + options.write_buffer_size = 256 * 1024 * 1024; // memtable size + options.target_file_size_base = 256 * 1024 * 1024; // size of files in L1 + options.max_bytes_for_level_base = 10 * options.target_file_size_base; // total size of L1, recommended to be 10 * target_file_size_base + check(rocksdb::DB::Open(options, db_path, &p), "database::database: rocksdb::DB::Open: "); } diff --git a/libraries/rodeos/include/b1/rodeos/rodeos.hpp b/libraries/rodeos/include/b1/rodeos/rodeos.hpp index c803f106446..cbbf6baf59c 100644 --- a/libraries/rodeos/include/b1/rodeos/rodeos.hpp +++ b/libraries/rodeos/include/b1/rodeos/rodeos.hpp @@ -40,7 +40,7 @@ struct rodeos_db_partition { struct rodeos_db_snapshot { std::shared_ptr partition = {}; std::shared_ptr db = {}; - bool undo_stack_disabled = false; + bool undo_stack_enabled = false; std::optional undo_stack = {}; // only if persistent std::optional snap = {}; // only if !persistent std::optional write_session = {}; diff --git a/libraries/rodeos/rodeos.cpp b/libraries/rodeos/rodeos.cpp index 50bf7382f98..1d91f56c0fa 100644 --- a/libraries/rodeos/rodeos.cpp +++ b/libraries/rodeos/rodeos.cpp @@ -16,8 +16,8 @@ using ship_protocol::get_blocks_result_v1; using ship_protocol::signed_block_header; using ship_protocol::signed_block_variant; -rodeos_db_snapshot::rodeos_db_snapshot(std::shared_ptr partition, bool persistent, bool undo_stack_disabled) - : partition{ std::move(partition) }, db{ this->partition->db }, undo_stack_disabled{ undo_stack_disabled } { +rodeos_db_snapshot::rodeos_db_snapshot(std::shared_ptr partition, bool persistent, bool undo_stack_enabled) + : partition{ std::move(partition) }, db{ this->partition->db }, undo_stack_enabled{ undo_stack_enabled } { if (persistent) { undo_stack.emplace(*db, this->partition->undo_prefix); write_session.emplace(*db); @@ -88,7 +88,7 @@ void rodeos_db_snapshot::start_block(const get_blocks_result_base& result) { throw std::runtime_error("get_blocks_result this_block is empty"); if (result.this_block->block_num <= head) { - if (undo_stack_disabled) { + if (!undo_stack_enabled) { wlog("can't switch forks at ${b} since undo stack is disabled. head: ${h}", ("b", result.this_block->block_num) ("h", head)); EOS_ASSERT(false, eosio::chain::unsupported_feature, "can't switch forks at ${b} since undo stack is disabled. head: ${h}", ("b", result.this_block->block_num) ("h", head)); } else { @@ -106,7 +106,7 @@ void rodeos_db_snapshot::start_block(const get_blocks_result_base& result) { if (head_id != eosio::checksum256{} && (!result.prev_block || result.prev_block->block_id != head_id)) throw std::runtime_error("prev_block does not match"); - if (undo_stack_disabled) { + if (!undo_stack_enabled) { end_write(false); } else { if (result.this_block->block_num <= result.last_irreversible.block_num) { diff --git a/programs/rodeos/cloner_plugin.cpp b/programs/rodeos/cloner_plugin.cpp index 846af953be9..959b0efd069 100644 --- a/programs/rodeos/cloner_plugin.cpp +++ b/programs/rodeos/cloner_plugin.cpp @@ -42,7 +42,7 @@ struct cloner_config : ship_client::connection_config { eosio::name filter_name = {}; // todo: remove std::string filter_wasm = {}; // todo: remove bool profile = false; - bool undo_stack_disabled = false; + bool undo_stack_enabled = false; uint32_t force_write_stride = 0; #ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED @@ -103,7 +103,7 @@ struct cloner_session : ship_client::connection_callbacks, std::enable_shared_fr } void connect(asio::io_context& ioc) { - rodeos_snapshot.emplace(partition, true, config->undo_stack_disabled); + rodeos_snapshot.emplace(partition, true, config->undo_stack_enabled); rodeos_snapshot->force_write_stride = config->force_write_stride; ilog("cloner database status:"); @@ -302,7 +302,7 @@ void cloner_plugin::set_program_options(options_description& cli, options_descri op("filter-name", bpo::value(), "Filter name"); op("filter-wasm", bpo::value(), "Filter wasm"); op("profile-filter", bpo::bool_switch(), "Enable filter profiling"); - op("disable-undo-stack", bpo::bool_switch(), "disable undo stack"); + op("enable-undo-stack", bpo::value()->default_value(false), "Enable undo stack"); op("force-write-stride", bpo::value()->default_value(200), "Maximum number of blocks to process before forcing rocksdb to flush. This option is primarily useful to control re-sync durations " "under disaster recovery scenarios (when rodeos has unexpectedly exited, the option ensures blocks stored in rocksdb are at most " @@ -353,7 +353,7 @@ void cloner_plugin::plugin_initialize(const variables_map& options) { } else if (options.count("filter-name") || options.count("filter-wasm")) { throw std::runtime_error("filter-name and filter-wasm must be used together"); } - my->config->undo_stack_disabled = options["disable-undo-stack"].as(); + my->config->undo_stack_enabled = options["enable-undo-stack"].as(); #ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED if (options.count("eos-vm-oc-cache-size-mb")) diff --git a/programs/rodeos/rocksdb_plugin.cpp b/programs/rodeos/rocksdb_plugin.cpp index 3fc05ad3c94..5683996fb30 100644 --- a/programs/rodeos/rocksdb_plugin.cpp +++ b/programs/rodeos/rocksdb_plugin.cpp @@ -26,10 +26,17 @@ void rocksdb_plugin::set_program_options(options_description& cli, options_descr "Database path (absolute path or relative to application data dir)"); op("rdb-options-file", bpo::value(), "File (including path) store RocksDB options. Must follow INI file format. Consult RocksDB documentation for details."); + op("rdb-threads", bpo::value(), + "Deprecated. Please use max_background_jobs in options file to configure it. Default is 20. An example options file is /programs/rodeos/rocksdb_options.ini"); + op("rdb-max-files", bpo::value(), + "Deprecated. Please use max_open_files in options file to configure it. Default is 765. An example options file is /programs/rodeos/rocksdb_options.ini"); } void rocksdb_plugin::plugin_initialize(const variables_map& options) { try { + EOS_ASSERT(options["rdb-threads"].empty(), eosio::chain::plugin_config_exception, "rdb-threads is deprecated. Please use max_background_jobs in options file to configure it. Default is 20. An example options file is /programs/rodeos/rocksdb_options.ini"); + EOS_ASSERT(options["rdb-max-files"].empty(), eosio::chain::plugin_config_exception, "rdb-max-files is deprecated. Please use max_open_files in options file to configure it. Default is 765. An example options file is /programs/rodeos/rocksdb_options.ini"); + auto db_path = options.at("rdb-database").as(); if (db_path.is_relative()) my->db_path = app().data_dir() / db_path;