Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

disable undo_stack by default, set tested typical rocksdb configurati… #10547

Merged
merged 3 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion libraries/chain_kv/include/b1/chain_kv/chain_kv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,24 @@ struct database {
std::vector<rocksdb::ColumnFamilyHandle*> 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: ");
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/rodeos/include/b1/rodeos/rodeos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct rodeos_db_partition {
struct rodeos_db_snapshot {
std::shared_ptr<rodeos_db_partition> partition = {};
std::shared_ptr<chain_kv::database> db = {};
bool undo_stack_disabled = false;
bool undo_stack_enabled = false;
std::optional<chain_kv::undo_stack> undo_stack = {}; // only if persistent
std::optional<rocksdb::ManagedSnapshot> snap = {}; // only if !persistent
std::optional<chain_kv::write_session> write_session = {};
Expand Down
8 changes: 4 additions & 4 deletions libraries/rodeos/rodeos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<rodeos_db_partition> 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<rodeos_db_partition> 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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions programs/rodeos/cloner_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:");
Expand Down Expand Up @@ -302,7 +302,7 @@ void cloner_plugin::set_program_options(options_description& cli, options_descri
op("filter-name", bpo::value<std::string>(), "Filter name");
op("filter-wasm", bpo::value<std::string>(), "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<bool>()->default_value(false), "Enable undo stack");
op("force-write-stride", bpo::value<uint32_t>()->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 "
Expand Down Expand Up @@ -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<bool>();
my->config->undo_stack_enabled = options["enable-undo-stack"].as<bool>();

#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
if (options.count("eos-vm-oc-cache-size-mb"))
Expand Down
7 changes: 7 additions & 0 deletions programs/rodeos/rocksdb_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bfs::path>(),
"File (including path) store RocksDB options. Must follow INI file format. Consult RocksDB documentation for details.");
op("rdb-threads", bpo::value<uint32_t>(),
"Deprecated. Please use max_background_jobs in options file to configure it. Default is 20. An example options file is <build-dir>/programs/rodeos/rocksdb_options.ini");
op("rdb-max-files", bpo::value<uint32_t>(),
"Deprecated. Please use max_open_files in options file to configure it. Default is 765. An example options file is <build-dir>/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 <build-dir>/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 <build-dir>/programs/rodeos/rocksdb_options.ini");

auto db_path = options.at("rdb-database").as<bfs::path>();
if (db_path.is_relative())
my->db_path = app().data_dir() / db_path;
Expand Down