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

fix(libmdbx): Some options can only be set after mdbx_env_open #11328

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions crates/storage/libmdbx-rs/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion crates/storage/libmdbx-rs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down Expand Up @@ -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),
}
}
Expand Down Expand Up @@ -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,
}
}
Expand Down
Loading