From 532acd599c0602881a5dcb71b8120ac51fb59253 Mon Sep 17 00:00:00 2001 From: mio Date: Mon, 30 Sep 2024 15:49:16 +0800 Subject: [PATCH] MDBX_opt_sync_bytes and MDBX_opt_sync_period can only be set after mdbx_env_open Or else, this will return EPERM, which also added in this commit --- crates/storage/libmdbx-rs/src/environment.rs | 11 +++++++++-- crates/storage/libmdbx-rs/src/error.rs | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/storage/libmdbx-rs/src/environment.rs b/crates/storage/libmdbx-rs/src/environment.rs index f243c7da18ec..edf9321ace40 100644 --- a/crates/storage/libmdbx-rs/src/environment.rs +++ b/crates/storage/libmdbx-rs/src/environment.rs @@ -643,8 +643,6 @@ impl EnvironmentBuilder { } for (opt, v) in [ (ffi::MDBX_opt_max_db, self.max_dbs), - (ffi::MDBX_opt_sync_bytes, self.sync_bytes), - (ffi::MDBX_opt_sync_period, self.sync_period), (ffi::MDBX_opt_rp_augment_limit, self.rp_augment_limit), (ffi::MDBX_opt_loose_limit, self.loose_limit), (ffi::MDBX_opt_dp_reserve_limit, self.dp_reserve_limit), @@ -698,6 +696,15 @@ impl EnvironmentBuilder { mode, ))?; + for (opt, v) in [ + (ffi::MDBX_opt_sync_bytes, self.sync_bytes), + (ffi::MDBX_opt_sync_period, self.sync_period), + ] { + if let Some(v) = v { + mdbx_result(ffi::mdbx_env_set_option(env, opt, v))?; + } + } + Ok(()) })() { ffi::mdbx_env_close_ex(env, false); diff --git a/crates/storage/libmdbx-rs/src/error.rs b/crates/storage/libmdbx-rs/src/error.rs index 1df5a397b2de..a70488b08262 100644 --- a/crates/storage/libmdbx-rs/src/error.rs +++ b/crates/storage/libmdbx-rs/src/error.rs @@ -119,8 +119,11 @@ pub enum Error { /// Read transaction has been timed out. #[error("read transaction has been timed out")] ReadTransactionTimeout, + /// Permission defined + #[error("permission denied to setup database")] + Permission, /// Unknown error code. - #[error("unknown error code")] + #[error("unknown error code: {0}")] Other(i32), } @@ -157,6 +160,7 @@ impl Error { ffi::MDBX_EACCESS => Self::Access, ffi::MDBX_TOO_LARGE => Self::TooLarge, ffi::MDBX_EBADSIGN => Self::BadSignature, + ffi::MDBX_EPERM => Self::Permission, other => Self::Other(other), } } @@ -196,6 +200,7 @@ impl Error { Self::WriteTransactionUnsupportedInReadOnlyMode | Self::NestedTransactionsUnsupportedWithWriteMap => ffi::MDBX_EACCESS, Self::ReadTransactionTimeout => -96000, // Custom non-MDBX error code + Self::Permission => ffi::MDBX_EPERM, Self::Other(err_code) => *err_code, } }