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

RocksDB - Renaming / creation of some parameters and change of default value for create_if_missing #9692

Merged
merged 3 commits into from
Nov 19, 2020
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
20 changes: 9 additions & 11 deletions libraries/chain/combined_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,30 +161,28 @@ namespace eosio { namespace chain {
: backing_store(backing_store_type::ROCKSDB), db(chain_db), kv_database{ [&]() {
rocksdb::Options options;

options.create_if_missing = !cfg.read_only; // Creates a database if it is missing
options.create_if_missing = true; // Creates a database if it is missing
options.level_compaction_dynamic_level_bytes = true;
options.bytes_per_sync = 1048576; // used to control the write rate of flushes and compactions.
options.bytes_per_sync = cfg.persistent_storage_bytes_per_sync; // used to control the write rate of flushes and compactions.

// By default, RocksDB uses only one background thread
// for flush and compaction.
// Good value for `total_threads` is the number of cores
options.IncreaseParallelism(cfg.rocksdb_threads);
// Number of threads used for flush and compaction.
options.IncreaseParallelism(cfg.persistent_storage_num_threads);

options.OptimizeLevelStyleCompaction(512ull << 20); // optimizes level style compaction

// Number of open files that can be used by the DB.
// Setting it to -1 means files opened are always kept open.
options.max_open_files = cfg.rocksdb_max_open_files;
options.max_open_files = cfg.persistent_storage_max_num_files;

// Use this option to increase the number of threads
// used to open the files.
options.max_file_opening_threads = cfg.rocksdb_threads; // Default should be the # of Cores
options.max_file_opening_threads = cfg.persistent_storage_num_threads;

// Write Buffer Size - Sets the size of a single
// memtable. Once memtable exceeds this size, it is
// marked immutable and a new one is created.
// Default should be 128MB
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@victorj8 Apologies - i missed this yesterday, but can you remove the comment '// Default should be 128MB'. thanks

options.write_buffer_size = cfg.rocksdb_write_buffer_size;
options.write_buffer_size = cfg.persistent_storage_write_buffer_size;
options.max_write_buffer_number = 10; // maximum number of memtables, both active and immutable
options.min_write_buffer_number_to_merge = 2; // minimum number of memtables to be merged before flushing to storage

Expand All @@ -193,7 +191,7 @@ namespace eosio { namespace chain {

// Size of L0 = write_buffer_size * min_write_buffer_number_to_merge * level0_file_num_compaction_trigger
// For optimal performance make this equal to L0
options.max_bytes_for_level_base = cfg.rocksdb_write_buffer_size * options.min_write_buffer_number_to_merge * options.level0_file_num_compaction_trigger;
options.max_bytes_for_level_base = cfg.persistent_storage_write_buffer_size * options.min_write_buffer_number_to_merge * options.level0_file_num_compaction_trigger;

// Files in level 1 will have target_file_size_base
// bytes. It’s recommended setting target_file_size_base
Expand All @@ -204,7 +202,7 @@ namespace eosio { namespace chain {
// that will concurrently perform a compaction job by
// breaking it into multiple,
// smaller ones that are run simultaneously.
options.max_subcompactions = cfg.rocksdb_threads; // Default should be the # of CPUs
options.max_subcompactions = cfg.persistent_storage_num_threads;

// Full and partitioned filters in the block-based table
// use an improved Bloom filter implementation, enabled
Expand Down
6 changes: 4 additions & 2 deletions libraries/chain/include/eosio/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ const static uint16_t default_controller_thread_pool_size = 2;
const static uint32_t default_max_variable_signature_length = 16384u;
const static uint32_t default_max_nonprivileged_inline_action_size = 4 * 1024; // 4 KB
const static uint32_t default_max_action_return_value_size = 256;
const static int default_rocksdb_max_open_files = -1;
const static uint64_t default_rocksdb_write_buffer_size = 128 * 1024 * 1024;
const static uint16_t default_persistent_storage_num_threads = 1;
const static int default_persistent_storage_max_num_files = -1;
const static uint64_t default_persistent_storage_write_buffer_size = 128 * 1024 * 1024;
const static uint64_t default_persistent_storage_bytes_per_sync = 1 * 1024 * 1024;

static_assert(MAX_SIZE_OF_BYTE_ARRAYS == 20*1024*1024, "Changing MAX_SIZE_OF_BYTE_ARRAYS breaks consensus. Make sure this is expected");

Expand Down
7 changes: 4 additions & 3 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ namespace eosio { namespace chain {
uint16_t max_retained_block_files = chain::config::default_max_retained_block_files;
uint64_t blocks_log_stride = chain::config::default_blocks_log_stride;
backing_store_type backing_store = backing_store_type::CHAINBASE;
uint16_t rocksdb_threads = 0; // Will be set to number of cores dynamically or by user configuration;
int rocksdb_max_open_files = chain::config::default_rocksdb_max_open_files;
uint64_t rocksdb_write_buffer_size = chain::config::default_rocksdb_write_buffer_size;
uint16_t persistent_storage_num_threads = 0; // Will be set to number of cores dynamically or by user configuration;
int persistent_storage_max_num_files = chain::config::default_persistent_storage_max_num_files;
uint64_t persistent_storage_write_buffer_size = chain::config::default_persistent_storage_write_buffer_size;
uint64_t persistent_storage_bytes_per_sync = chain::config::default_persistent_storage_bytes_per_sync;
fc::microseconds abi_serializer_max_time_us = fc::microseconds(chain::config::default_abi_serializer_max_time_us);
uint32_t max_nonprivileged_inline_action_size = chain::config::default_max_nonprivileged_inline_action_size;
bool read_only = false;
Expand Down
40 changes: 23 additions & 17 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip

std::string default_wasm_runtime_str= eosio::chain::wasm_interface::vm_type_string(eosio::chain::config::default_wasm_runtime);

uint16_t default_rocksdb_threads = 1;

cfg.add_options()
("blocks-dir", bpo::value<bfs::path>()->default_value("blocks"),
"the location of the blocks directory (absolute path or relative to application data dir)")
Expand Down Expand Up @@ -306,12 +304,14 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
("chain-state-db-guard-size-mb", bpo::value<uint64_t>()->default_value(config::default_state_guard_size / (1024 * 1024)), "Safely shut down node when free space remaining in the chain state database drops below this size (in MiB).")
("backing-store", boost::program_options::value<eosio::chain::backing_store_type>()->default_value(eosio::chain::backing_store_type::CHAINBASE),
"The storage for state, chainbase or rocksdb")
("rocksdb-threads", bpo::value<uint16_t>()->default_value(default_rocksdb_threads),
("persistent-storage-num-threads", bpo::value<uint16_t>()->default_value(default_persistent_storage_num_threads),
"Number of rocksdb threads for flush and compaction")
("rocksdb-files", bpo::value<int>()->default_value(config::default_rocksdb_max_open_files),
("persistent-storage-max-num-files", bpo::value<int>()->default_value(config::default_persistent_storage_max_num_files),
"Max number of rocksdb files to keep open. -1 = unlimited.")
("rocksdb-write-buffer-size-mb", bpo::value<uint64_t>()->default_value(config::default_rocksdb_write_buffer_size / (1024 * 1024)),
("persistent-storage-write-buffer-size-mb", bpo::value<uint64_t>()->default_value(config::default_persistent_storage_write_buffer_size / (1024 * 1024)),
"Size of a single rocksdb memtable (in MiB)")
("persistent-storage-bytes-per-sync", bpo::value<uint64_t>()->default_value(config::default_persistent_storage_bytes_per_sync),
"Rocksdb write rate of flushes and compactions.")
Comment on lines +313 to +314
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want its unit to be in MiB, but then it might be too coarse. If we do use MiB, here is a tricky one: you'll need to divide config::default_persistent_storage_bytes_per_sync by 1024 * 1024 here for the default value and then multiply back below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was told that this value may be getting values such as 512K, that's why i didn't use the MiB here.


("reversible-blocks-db-size-mb", bpo::value<uint64_t>()->default_value(config::default_reversible_cache_size / (1024 * 1024)), "Maximum size (in MiB) of the reversible blocks database")
("reversible-blocks-db-guard-size-mb", bpo::value<uint64_t>()->default_value(config::default_reversible_guard_size / (1024 * 1024)), "Safely shut down node when free space remaining in the reverseible blocks database drops below this size (in MiB).")
Expand Down Expand Up @@ -832,22 +832,28 @@ void chain_plugin::plugin_initialize(const variables_map& options) {

my->chain_config->backing_store = options.at( "backing-store" ).as<backing_store_type>();

if( options.count( "rocksdb-threads" )) {
my->chain_config->rocksdb_threads = options.at( "rocksdb-threads" ).as<uint16_t>();
EOS_ASSERT( my->chain_config->rocksdb_threads > 0, plugin_config_exception,
"rocksdb-threads ${num} must be greater than 0", ("num", my->chain_config->rocksdb_threads) );
if( options.count( "persistent-storage-num-threads" )) {
my->chain_config->persistent_storage_num_threads = options.at( "persistent-storage-num-threads" ).as<uint16_t>();
EOS_ASSERT( my->chain_config->persistent_storage_num_threads > 0, plugin_config_exception,
"persistent-storage-num-threads ${num} must be greater than 0", ("num", my->chain_config->persistent_storage_num_threads) );
}

if( options.count( "persistent-storage-max-num-files" )) {
my->chain_config->persistent_storage_max_num_files = options.at( "persistent-storage-max-num-files" ).as<int>();
EOS_ASSERT( my->chain_config->persistent_storage_max_num_files == -1 || my->chain_config->persistent_storage_max_num_files > 0, plugin_config_exception,
"persistent-storage-max-num-files ${num} must be equal to -1 or be greater than 0", ("num", my->chain_config->persistent_storage_max_num_files) );
}

if( options.count( "rocksdb-files" )) {
my->chain_config->rocksdb_max_open_files = options.at( "rocksdb-files" ).as<int>();
EOS_ASSERT( my->chain_config->rocksdb_max_open_files == -1 || my->chain_config->rocksdb_max_open_files > 0, plugin_config_exception,
"rocksdb-files ${num} must be equal to -1 or be greater than 0", ("num", my->chain_config->rocksdb_max_open_files) );
if( options.count( "persistent-storage-write-buffer-size-mb" )) {
my->chain_config->persistent_storage_write_buffer_size = options.at( "persistent-storage-write-buffer-size-mb" ).as<uint64_t>() * 1024 * 1024;
EOS_ASSERT( my->chain_config->persistent_storage_write_buffer_size > 0, plugin_config_exception,
"persistent-storage-write-buffer-size-mb ${num} must be greater than 0", ("num", my->chain_config->persistent_storage_write_buffer_size) );
}

if( options.count( "rocksdb-write-buffer-size-mb" )) {
my->chain_config->rocksdb_write_buffer_size = options.at( "rocksdb-write-buffer-size-mb" ).as<uint64_t>() * 1024 * 1024;
EOS_ASSERT( my->chain_config->rocksdb_write_buffer_size > 0, plugin_config_exception,
"rocksdb-write-buffer-size-mb ${num} must be greater than 0", ("num", my->chain_config->rocksdb_write_buffer_size) );
if( options.count( "persistent-storage-bytes-per-sync" )) {
my->chain_config->persistent_storage_bytes_per_sync = options.at( "persistent-storage-bytes-per-sync" ).as<uint64_t>();
EOS_ASSERT( my->chain_config->persistent_storage_bytes_per_sync > 0, plugin_config_exception,
"persistent-storage-bytes-per-sync ${num} must be greater than 0", ("num", my->chain_config->persistent_storage_bytes_per_sync) );
}

if( options.count( "reversible-blocks-db-size-mb" ))
Expand Down