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
Show file tree
Hide file tree
Changes from 4 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
15 changes: 15 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,10 @@ 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>,
/// Mdbx exclusive flag. If [None], the default value is used.
///
/// See docs at: <https://libmdbx.dqdkfa.ru/group__c__opening.html#gga9138119a904355d245777c4119534061aa516c74e6fed22c9812bb909c8c459ed>
loocapro marked this conversation as resolved.
Show resolved Hide resolved
exclusive: Option<bool>,
}

impl DatabaseArguments {
Expand All @@ -80,6 +84,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 +257,7 @@ impl DatabaseEnv {
// worsens it for random access (which is our access pattern outside of sync)
no_rdahead: true,
coalesce: true,
exclusive: inner_env.is_exclusive(),
loocapro marked this conversation as resolved.
Show resolved Hide resolved
..Default::default()
});
// Configure more readers
Expand Down Expand Up @@ -308,6 +319,10 @@ impl DatabaseEnv {
inner_env.set_max_read_transaction_duration(max_read_transaction_duration);
}

if let Some(exclusive) = args.exclusive {
inner_env.set_exclusive(exclusive);
}

let env = DatabaseEnv {
inner: inner_env.open(path).map_err(|e| DatabaseError::Open(e.into()))?,
metrics: None,
Expand Down
12 changes: 12 additions & 0 deletions crates/storage/libmdbx-rs/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl Environment {
handle_slow_readers: None,
#[cfg(feature = "read-tx-timeouts")]
max_read_transaction_duration: None,
exclusive: false,
}
}

Expand Down Expand Up @@ -579,6 +580,8 @@ pub struct EnvironmentBuilder {
/// The maximum duration of a read transaction. If [None], but the `read-tx-timeout` feature is
/// enabled, the default value of [DEFAULT_MAX_READ_TRANSACTION_DURATION] is used.
max_read_transaction_duration: Option<read_transactions::MaxReadTransactionDuration>,
/// MDBX exclusive flag.
exclusive: bool,
loocapro marked this conversation as resolved.
Show resolved Hide resolved
}

impl EnvironmentBuilder {
Expand Down Expand Up @@ -722,6 +725,10 @@ impl EnvironmentBuilder {
Ok(Environment { inner: Arc::new(env) })
}

/// Returns true if mdbx exclusive flag is set.
pub fn is_exclusive(&self) -> bool {
self.exclusive
}
/// Configures how this environment will be opened.
pub fn set_kind(&mut self, kind: EnvironmentKind) -> &mut Self {
self.kind = kind;
Expand Down Expand Up @@ -860,6 +867,11 @@ pub(crate) mod read_transactions {
self.max_read_transaction_duration = Some(max_read_transaction_duration);
self
}
/// Set the mdbx exclusive flag.
pub fn set_exclusive(&mut self, exclusive: bool) -> &mut Self {
self.exclusive = exclusive;
self
}
}
}

Expand Down
Loading