mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: use asref path for open db (#13998)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -6778,7 +6778,6 @@ dependencies = [
|
||||
"metrics",
|
||||
"page_size",
|
||||
"parking_lot",
|
||||
"paste",
|
||||
"pprof",
|
||||
"proptest",
|
||||
"reth-db-api",
|
||||
|
||||
@ -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
|
||||
@ -73,8 +73,6 @@ criterion.workspace = true
|
||||
arbitrary = { workspace = true, features = ["derive"] }
|
||||
proptest.workspace = true
|
||||
|
||||
paste.workspace = true
|
||||
|
||||
assert_matches.workspace = true
|
||||
|
||||
[features]
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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;
|
||||
@ -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())
|
||||
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(args.client_version().clone())?;
|
||||
db.record_client_version(client_version)?;
|
||||
Ok(db)
|
||||
}
|
||||
open(path.as_ref(), args)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user