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

feat(storage): MDBX exclusive mode #6755

Merged
merged 8 commits into from
Feb 28, 2024
Merged
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
28 changes: 28 additions & 0 deletions crates/storage/db/src/implementation/mdbx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ pub struct DatabaseArguments {
log_level: Option<LogLevel>,
/// Maximum duration of a read transaction. If [None], the default value is used.
max_read_transaction_duration: Option<MaxReadTransactionDuration>,
/// Open environment in exclusive/monopolistic mode. If [None], the default value is used.
///
/// This can be used as a replacement for `MDB_NOLOCK`, which don't supported by MDBX. In this
/// way, you can get the minimal overhead, but with the correct multi-process and multi-thread
/// locking.
///
/// If `true` = open environment in exclusive/monopolistic mode or return `MDBX_BUSY` if
/// environment already used by other process. The main feature of the exclusive mode is the
/// ability to open the environment placed on a network share.
///
/// If `false` = open environment in cooperative mode, i.e. for multi-process
/// access/interaction/cooperation. The main requirements of the cooperative mode are:
/// - Data files MUST be placed in the LOCAL file system, but NOT on a network share.
/// - Environment MUST be opened only by LOCAL processes, but NOT over a network.
/// - OS kernel (i.e. file system and memory mapping implementation) and all processes that
/// open the given environment MUST be running in the physically single RAM with
/// cache-coherency. The only exception for cache-consistency requirement is Linux on MIPS
/// architecture, but this case has not been tested for a long time).
///
/// This flag affects only at environment opening but can't be changed after.
exclusive: Option<bool>,
}

impl DatabaseArguments {
Expand All @@ -80,6 +101,12 @@ impl DatabaseArguments {
self.max_read_transaction_duration = max_read_transaction_duration;
self
}

/// Set the mdbx exclusive flag.
pub fn exclusive(mut self, exclusive: Option<bool>) -> Self {
self.exclusive = exclusive;
self
}
}

/// Wrapper for the libmdbx environment: [Environment]
Expand Down Expand Up @@ -247,6 +274,7 @@ impl DatabaseEnv {
// worsens it for random access (which is our access pattern outside of sync)
no_rdahead: true,
coalesce: true,
exclusive: args.exclusive.unwrap_or_default(),
..Default::default()
});
// Configure more readers
Expand Down
Loading