Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.2] Cherry pick mdbx related fixes #189

Merged
merged 1 commit into from
Aug 9, 2024
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
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
Loading