From 646d5e9c6694cda9ebc13a83b85576cb5b391a3b Mon Sep 17 00:00:00 2001 From: yarkinwho <99302011+yarkinwho@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:09:54 +0800 Subject: [PATCH] Merge pull request #137 from eosnetworkfoundation/yarkin/mdbx_flags Fix mdbx related issues --- silkworm/node/db/mdbx.cpp | 18 +++++++++--------- silkworm/silkrpc/daemon.cpp | 3 ++- silkworm/silkrpc/settings.hpp | 1 + 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/silkworm/node/db/mdbx.cpp b/silkworm/node/db/mdbx.cpp index 81582cca2..514ea0e51 100644 --- a/silkworm/node/db/mdbx.cpp +++ b/silkworm/node/db/mdbx.cpp @@ -131,14 +131,13 @@ ::mdbx::env_managed open_env(const EnvConfig& config) { } ::mdbx::env_managed::create_parameters cp{}; // Default create parameters - if (!config.shared) { - auto max_map_size = static_cast(config.in_memory ? 128_Mebi : config.max_size); - auto growth_size = static_cast(config.in_memory ? 8_Mebi : config.growth_size); - cp.geometry.make_dynamic(::mdbx::env::geometry::default_value, max_map_size); - cp.geometry.growth_step = growth_size; - if (!db_ondisk_file_size) - cp.geometry.pagesize = static_cast(config.page_size); - } + // We will set create_parameters even when opening existing db so that we can update max_map_size if config changed. + auto max_map_size = static_cast(config.in_memory ? 128_Mebi : config.max_size); + auto growth_size = static_cast(config.in_memory ? 8_Mebi : config.growth_size); + cp.geometry.make_dynamic(::mdbx::env::geometry::default_value, max_map_size); + cp.geometry.growth_step = growth_size; + if (!db_ondisk_file_size) + cp.geometry.pagesize = static_cast(config.page_size); using OP = ::mdbx::env::operate_parameters; OP op{}; // Operational parameters @@ -157,7 +156,8 @@ ::mdbx::env_managed open_env(const EnvConfig& config) { " db has " + human_size(db_page_size)); } - if (!config.shared) { + // Those settings should only need to be set once during creation. + if (config.create) { // C++ bindings don't have setoptions ::mdbx::error::success_or_throw(::mdbx_env_set_option(ret, MDBX_opt_rp_augment_limit, 32_Mebi)); if (!config.readonly) { diff --git a/silkworm/silkrpc/daemon.cpp b/silkworm/silkrpc/daemon.cpp index e4721fc00..5f6d85b12 100644 --- a/silkworm/silkrpc/daemon.cpp +++ b/silkworm/silkrpc/daemon.cpp @@ -194,9 +194,10 @@ Daemon::Daemon(DaemonSettings settings, std::shared_ptr chain chaindata_env_ = std::make_shared(); silkworm::db::EnvConfig db_config{ .path = settings_.datadir->string() + kChaindataRelativePath, + .readonly = true, .in_memory = true, .shared = true, - .max_readers = kDatabaseMaxReaders}; + .max_readers = settings.max_readers ? *settings.max_readers : kDatabaseMaxReaders}; *chaindata_env_ = silkworm::db::open_env(db_config); } else if (chaindata_env) { // Use the existing chaindata environment diff --git a/silkworm/silkrpc/settings.hpp b/silkworm/silkrpc/settings.hpp index 9cbbbf227..bcde9071b 100644 --- a/silkworm/silkrpc/settings.hpp +++ b/silkworm/silkrpc/settings.hpp @@ -37,6 +37,7 @@ struct DaemonSettings { std::optional jwt_secret_file; bool skip_protocol_check{false}; uint64_t rpc_quirk_flag{0}; + std::optional max_readers; }; } // namespace silkworm::rpc