feat: replace TransactionDB with DB (#468)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2024-05-15 11:14:43 +08:00 committed by GitHub
parent 1223e4d096
commit af1fe2e91e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 29 deletions

16
Cargo.lock generated
View File

@ -959,7 +959,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client" name = "dragonfly-client"
version = "0.1.55" version = "0.1.56"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -1022,7 +1022,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-backend" name = "dragonfly-client-backend"
version = "0.1.55" version = "0.1.56"
dependencies = [ dependencies = [
"dragonfly-client-core", "dragonfly-client-core",
"futures", "futures",
@ -1040,7 +1040,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-config" name = "dragonfly-client-config"
version = "0.1.55" version = "0.1.56"
dependencies = [ dependencies = [
"dragonfly-client-core", "dragonfly-client-core",
"home", "home",
@ -1059,7 +1059,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-core" name = "dragonfly-client-core"
version = "0.1.55" version = "0.1.56"
dependencies = [ dependencies = [
"libloading", "libloading",
"reqwest", "reqwest",
@ -1070,7 +1070,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-init" name = "dragonfly-client-init"
version = "0.1.55" version = "0.1.56"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
@ -1086,7 +1086,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-storage" name = "dragonfly-client-storage"
version = "0.1.55" version = "0.1.56"
dependencies = [ dependencies = [
"base16ct", "base16ct",
"blake3", "blake3",
@ -1110,7 +1110,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-util" name = "dragonfly-client-util"
version = "0.1.55" version = "0.1.56"
dependencies = [ dependencies = [
"dragonfly-api", "dragonfly-api",
"dragonfly-client-core", "dragonfly-client-core",
@ -1568,7 +1568,7 @@ dependencies = [
[[package]] [[package]]
name = "hdfs" name = "hdfs"
version = "0.1.55" version = "0.1.56"
dependencies = [ dependencies = [
"dragonfly-client-backend", "dragonfly-client-backend",
"dragonfly-client-core", "dragonfly-client-core",

View File

@ -12,7 +12,7 @@ members = [
] ]
[workspace.package] [workspace.package]
version = "0.1.55" version = "0.1.56"
authors = ["The Dragonfly Developers"] authors = ["The Dragonfly Developers"]
homepage = "https://d7y.io/" homepage = "https://d7y.io/"
repository = "https://github.com/dragonflyoss/client.git" repository = "https://github.com/dragonflyoss/client.git"
@ -22,13 +22,13 @@ readme = "README.md"
edition = "2021" edition = "2021"
[workspace.dependencies] [workspace.dependencies]
dragonfly-client = { path = "dragonfly-client", version = "0.1.55" } dragonfly-client = { path = "dragonfly-client", version = "0.1.56" }
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.1.55" } dragonfly-client-core = { path = "dragonfly-client-core", version = "0.1.56" }
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.1.55" } dragonfly-client-config = { path = "dragonfly-client-config", version = "0.1.56" }
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.1.55" } dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.1.56" }
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.1.55" } dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.1.56" }
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.1.55" } dragonfly-client-util = { path = "dragonfly-client-util", version = "0.1.56" }
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.1.55" } dragonfly-client-init = { path = "dragonfly-client-init", version = "0.1.56" }
thiserror = "1.0" thiserror = "1.0"
dragonfly-api = "2.0.112" dragonfly-api = "2.0.112"
reqwest = { version = "0.11.27", features = ["stream", "native-tls", "default-tls", "rustls-tls"] } reqwest = { version = "0.11.27", features = ["stream", "native-tls", "default-tls", "rustls-tls"] }

View File

@ -24,16 +24,16 @@ use tracing::info;
/// RocksdbStorageEngine is a storage engine based on rocksdb. /// RocksdbStorageEngine is a storage engine based on rocksdb.
pub struct RocksdbStorageEngine { pub struct RocksdbStorageEngine {
// inner is the inner rocksdb transaction db. // inner is the inner rocksdb DB.
inner: rocksdb::TransactionDB, inner: rocksdb::DB,
} }
// RocksdbStorageEngine implements deref of the storage engine. // RocksdbStorageEngine implements deref of the storage engine.
impl Deref for RocksdbStorageEngine { impl Deref for RocksdbStorageEngine {
// Target is the inner rocksdb transaction db. // Target is the inner rocksdb DB.
type Target = rocksdb::TransactionDB; type Target = rocksdb::DB;
// deref returns the inner rocksdb transaction db. // deref returns the inner rocksdb DB.
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
&self.inner &self.inner
} }
@ -80,13 +80,7 @@ impl RocksdbStorageEngine {
// Open rocksdb. // Open rocksdb.
let dir = dir.join(Self::DEFAULT_DIR_NAME); let dir = dir.join(Self::DEFAULT_DIR_NAME);
let db = rocksdb::TransactionDB::open_cf( let db = rocksdb::DB::open_cf(&options, &dir, cf_names).or_err(ErrorType::StorageError)?;
&options,
&rocksdb::TransactionDBOptions::default(),
&dir,
cf_names,
)
.or_err(ErrorType::StorageError)?;
info!("metadata initialized directory: {:?}", dir); info!("metadata initialized directory: {:?}", dir);
Ok(Self { inner: db }) Ok(Self { inner: db })
@ -149,7 +143,7 @@ impl Operations for RocksdbStorageEngine {
impl<'db> StorageEngine<'db> for RocksdbStorageEngine {} impl<'db> StorageEngine<'db> for RocksdbStorageEngine {}
/// cf_handle returns the column family handle for the given object. /// cf_handle returns the column family handle for the given object.
fn cf_handle<T>(db: &rocksdb::TransactionDB) -> Result<&rocksdb::ColumnFamily> fn cf_handle<T>(db: &rocksdb::DB) -> Result<&rocksdb::ColumnFamily>
where where
T: DatabaseObject, T: DatabaseObject,
{ {