mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: make reth-db compile without default features (#8509)
This commit is contained in:
@ -74,11 +74,7 @@ mod utils;
|
||||
pub mod version;
|
||||
|
||||
#[cfg(feature = "mdbx")]
|
||||
/// Bindings for [MDBX](https://libmdbx.dqdkfa.ru/).
|
||||
pub mod mdbx {
|
||||
pub use crate::implementation::mdbx::*;
|
||||
pub use reth_libmdbx::*;
|
||||
}
|
||||
pub mod mdbx;
|
||||
|
||||
pub use abstraction::*;
|
||||
pub use reth_storage_errors::db::{DatabaseError, DatabaseWriteOperation};
|
||||
@ -86,85 +82,7 @@ pub use tables::*;
|
||||
pub use utils::is_database_empty;
|
||||
|
||||
#[cfg(feature = "mdbx")]
|
||||
pub use mdbx::{DatabaseEnv, DatabaseEnvKind};
|
||||
|
||||
use crate::mdbx::DatabaseArguments;
|
||||
use eyre::WrapErr;
|
||||
use std::path::Path;
|
||||
|
||||
/// Creates a new database at the specified path if it doesn't exist. Does NOT create tables. Check
|
||||
/// [`init_db`].
|
||||
pub fn create_db<P: AsRef<Path>>(path: P, args: DatabaseArguments) -> eyre::Result<DatabaseEnv> {
|
||||
use crate::version::{check_db_version_file, create_db_version_file, DatabaseVersionError};
|
||||
|
||||
let rpath = path.as_ref();
|
||||
if is_database_empty(rpath) {
|
||||
reth_fs_util::create_dir_all(rpath)
|
||||
.wrap_err_with(|| format!("Could not create database directory {}", rpath.display()))?;
|
||||
create_db_version_file(rpath)?;
|
||||
} else {
|
||||
match check_db_version_file(rpath) {
|
||||
Ok(_) => (),
|
||||
Err(DatabaseVersionError::MissingFile) => create_db_version_file(rpath)?,
|
||||
Err(err) => return Err(err.into()),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mdbx")]
|
||||
{
|
||||
Ok(DatabaseEnv::open(rpath, DatabaseEnvKind::RW, args)?)
|
||||
}
|
||||
#[cfg(not(feature = "mdbx"))]
|
||||
{
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens up an existing database or creates a new one at the specified path. Creates tables if
|
||||
/// necessary. Read/Write mode.
|
||||
pub fn init_db<P: AsRef<Path>>(path: P, args: DatabaseArguments) -> eyre::Result<DatabaseEnv> {
|
||||
#[cfg(feature = "mdbx")]
|
||||
{
|
||||
let client_version = args.client_version().clone();
|
||||
let db = create_db(path, args)?;
|
||||
db.create_tables()?;
|
||||
db.record_client_version(client_version)?;
|
||||
Ok(db)
|
||||
}
|
||||
#[cfg(not(feature = "mdbx"))]
|
||||
{
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
#[cfg(feature = "mdbx")]
|
||||
{
|
||||
DatabaseEnv::open(path, DatabaseEnvKind::RO, args)
|
||||
.with_context(|| format!("Could not open database at path: {}", path.display()))
|
||||
}
|
||||
#[cfg(not(feature = "mdbx"))]
|
||||
{
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
#[cfg(feature = "mdbx")]
|
||||
{
|
||||
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)
|
||||
}
|
||||
#[cfg(not(feature = "mdbx"))]
|
||||
{
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
pub use mdbx::{create_db, init_db, open_db, open_db_read_only, DatabaseEnv, DatabaseEnvKind};
|
||||
|
||||
/// Collection of database test utilities
|
||||
#[cfg(any(test, feature = "test-utils"))]
|
||||
@ -173,11 +91,15 @@ pub mod test_utils {
|
||||
use crate::{
|
||||
database::Database,
|
||||
database_metrics::{DatabaseMetadata, DatabaseMetadataValue, DatabaseMetrics},
|
||||
mdbx::DatabaseArguments,
|
||||
models::client_version::ClientVersion,
|
||||
};
|
||||
use reth_fs_util;
|
||||
use reth_libmdbx::MaxReadTransactionDuration;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
use tempfile::TempDir;
|
||||
|
||||
/// Error during database open
|
||||
|
||||
Reference in New Issue
Block a user