diff --git a/crates/storage/db/src/implementation/mdbx/mod.rs b/crates/storage/db/src/implementation/mdbx/mod.rs index 0dcaec130a..9e45049b77 100644 --- a/crates/storage/db/src/implementation/mdbx/mod.rs +++ b/crates/storage/db/src/implementation/mdbx/mod.rs @@ -63,6 +63,27 @@ pub struct DatabaseArguments { log_level: Option, /// Maximum duration of a read transaction. If [None], the default value is used. max_read_transaction_duration: Option, + /// 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, } 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) -> 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