Db exclusive mode (#6755)

Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
This commit is contained in:
Luca Provini
2024-02-28 12:23:14 +01:00
committed by GitHub
parent 3179391cfd
commit 5475a12086

View File

@ -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 {
@ -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]
@ -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