Skip to content

Commit

Permalink
Db exclusive mode (paradigmxyz#6755)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexey Shekhirin <[email protected]>
  • Loading branch information
2 people authored and fgimenez committed Feb 29, 2024
1 parent 5c0d63e commit d69d907
Showing 1 changed file with 28 additions and 0 deletions.
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

0 comments on commit d69d907

Please sign in to comment.