Skip to content

Commit

Permalink
Merge pull request #137 from eosnetworkfoundation/yarkin/mdbx_flags
Browse files Browse the repository at this point in the history
Fix mdbx related issues
  • Loading branch information
yarkinwho authored Apr 7, 2024
2 parents d3e6ead + ffe51c8 commit 67e0299
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
18 changes: 9 additions & 9 deletions silkworm/node/db/mdbx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<intptr_t>(config.in_memory ? 128_Mebi : config.max_size);
auto growth_size = static_cast<intptr_t>(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<intptr_t>(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<intptr_t>(config.in_memory ? 128_Mebi : config.max_size);
auto growth_size = static_cast<intptr_t>(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<intptr_t>(config.page_size);

using OP = ::mdbx::env::operate_parameters;
OP op{}; // Operational parameters
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion silkworm/silkrpc/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ Daemon::Daemon(DaemonSettings settings, std::shared_ptr<mdbx::env_managed> chain
chaindata_env_ = std::make_shared<mdbx::env_managed>();
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
Expand Down
1 change: 1 addition & 0 deletions silkworm/silkrpc/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct DaemonSettings {
std::optional<std::string> jwt_secret_file;
bool skip_protocol_check{false};
uint64_t rpc_quirk_flag{0};
std::optional<uint32_t> max_readers;
};

} // namespace silkworm::rpc

0 comments on commit 67e0299

Please sign in to comment.