Skip to content

Commit

Permalink
chore: use asref path for open db (#13998)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jan 27, 2025
1 parent 6342162 commit 79a5217
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions crates/storage/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ workspace = true
# reth
reth-db-api.workspace = true
reth-primitives = { workspace = true, features = ["reth-codec"] }
reth-primitives-traits = { workspace = true, features = ["serde", "reth-codec"] }
reth-primitives-traits = { workspace = true, features = ["reth-codec"] }
reth-fs-util.workspace = true
reth-storage-errors.workspace = true
reth-nippy-jar.workspace = true
Expand Down Expand Up @@ -73,8 +73,6 @@ criterion.workspace = true
arbitrary = { workspace = true, features = ["derive"] }
proptest.workspace = true

paste.workspace = true

assert_matches.workspace = true

[features]
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/db/src/implementation/mdbx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const DEFAULT_MAX_READERS: u64 = 32_000;
const MAX_SAFE_READER_SPACE: usize = 10 * GIGABYTE;

/// Environment used when opening a MDBX environment. RO/RW.
#[derive(Debug)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum DatabaseEnvKind {
/// Read-only MDBX environment.
RO,
Expand Down
22 changes: 15 additions & 7 deletions crates/storage/db/src/mdbx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Bindings for [MDBX](https://libmdbx.dqdkfa.ru/).
//! Helper functions for initializing and opening a database.
use crate::{is_database_empty, TableSet, Tables};
use eyre::Context;
Expand Down Expand Up @@ -48,16 +48,24 @@ pub fn init_db_for<P: AsRef<Path>, TS: TableSet>(
}

/// Opens up an existing database. Read only mode. It doesn't create it or create tables if missing.
pub fn open_db_read_only(path: &Path, args: DatabaseArguments) -> eyre::Result<DatabaseEnv> {
pub fn open_db_read_only(
path: impl AsRef<Path>,
args: DatabaseArguments,
) -> eyre::Result<DatabaseEnv> {
let path = path.as_ref();
DatabaseEnv::open(path, DatabaseEnvKind::RO, args)
.with_context(|| format!("Could not open database at path: {}", path.display()))
}

/// Opens up an existing database. Read/Write mode with `WriteMap` enabled. It doesn't create it or
/// create tables if missing.
pub fn open_db(path: &Path, args: DatabaseArguments) -> eyre::Result<DatabaseEnv> {
let db = DatabaseEnv::open(path, DatabaseEnvKind::RW, args.clone())
.with_context(|| format!("Could not open database at path: {}", path.display()))?;
db.record_client_version(args.client_version().clone())?;
Ok(db)
pub fn open_db(path: impl AsRef<Path>, args: DatabaseArguments) -> eyre::Result<DatabaseEnv> {
fn open(path: &Path, args: DatabaseArguments) -> eyre::Result<DatabaseEnv> {
let client_version = args.client_version().clone();
let db = DatabaseEnv::open(path, DatabaseEnvKind::RW, args)
.with_context(|| format!("Could not open database at path: {}", path.display()))?;
db.record_client_version(client_version)?;
Ok(db)
}
open(path.as_ref(), args)
}

0 comments on commit 79a5217

Please sign in to comment.