diff --git a/CHANGELOG.md b/CHANGELOG.md index 92055ea..b33f1f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,18 @@ # CHANGE LOG -## v1.0.x +## v3.x.x -Simplify functions and release v1.0.0 +- Make `::new()` lazyable + - 'Copy On Write' style +- Set `paritydb` as the default backend to save compilation time + +## v1.x.x + +- Simplify functions and release v1.0.0 ## v0.70.x -Backport the changes of the `mmdb` crate. +- Backport the changes of the `mmdb` crate. ## v0.61.x diff --git a/Cargo.toml b/Cargo.toml index a4cc0ed..12a4e05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ members = [ resolver = "2" [workspace.dependencies] -ruc = "7.0.1" +ruc = "7.5.1" rand = "0.8.5" parking_lot = "0.12.1" @@ -20,7 +20,7 @@ parity-scale-codec = "3.6.12" threadpool = "1.8.1" # used in a background cleaner -parity-db = "0.4.13" +parity-db = "0.5.0" rocksdb = { version = "0.22.0", default-features = false } keccak-hasher = "0.16.0" @@ -28,8 +28,8 @@ hash-db = "0.16.0" trie-db = "0.29.1" trie-root = "0.18.0" -vsdb = { path = "wrappers", version = "2.0", default-features = false } -vsdb_core = { path = "core", version = "2.0", default-features = false } +vsdb = { path = "wrappers", version = "3.0", default-features = false } +vsdb_core = { path = "core", version = "3.0", default-features = false } -vsdb_trie_db = { path = "utils/trie_db", version = "2.0", default-features = false } -vsdb_hash_db = { path = "utils/hash_db", version = "2.0", default-features = false } +vsdb_trie_db = { path = "utils/trie_db", version = "3.0", default-features = false } +vsdb_hash_db = { path = "utils/hash_db", version = "3.0", default-features = false } diff --git a/Makefile b/Makefile index 97ef901..095aa5b 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,8 @@ lint: cargo check --workspace --benches lintall: lint - cargo clippy --workspace --no-default-features --features "parity_backend,compress,msgpack_codec" - cargo check --workspace --tests --no-default-features --features "parity_backend,json_codec" + cargo clippy --workspace --no-default-features --features "rocks_backend,compress,msgpack_codec" + cargo check --workspace --tests --no-default-features --features "rocks_backend,json_codec" lintmusl: cargo clippy --workspace --target x86_64-unknown-linux-musl \ @@ -26,7 +26,7 @@ testall: test - rm -rf ~/.vsdb /tmp/.vsdb /tmp/vsdb_testing $(VSDB_BASE_DIR) cargo test --workspace --tests \ --no-default-features \ - --features "parity_backend,msgpack_codec" \ + --features "rocks_backend,msgpack_codec" \ -- --test-threads=1 #--nocapture testmusl: @@ -38,13 +38,13 @@ testmusl: bench: - rm -rf ~/.vsdb /tmp/.vsdb /tmp/vsdb_testing $(VSDB_BASE_DIR) - cargo bench --workspace --no-default-features --features "parity_backend,msgpack_codec" + cargo bench --workspace --no-default-features --features "rocks_backend,msgpack_codec" du -sh ~/.vsdb - rm -rf ~/.vsdb /tmp/.vsdb /tmp/vsdb_testing $(VSDB_BASE_DIR) - cargo bench --workspace --no-default-features --features "parity_backend,compress,msgpack_codec" + cargo bench --workspace du -sh ~/.vsdb - rm -rf ~/.vsdb /tmp/.vsdb /tmp/vsdb_testing $(VSDB_BASE_DIR) - cargo bench --workspace + cargo bench --workspace --no-default-features --features "rocks_backend,compress,msgpack_codec" du -sh ~/.vsdb - rm -rf ~/.vsdb /tmp/.vsdb /tmp/vsdb_testing $(VSDB_BASE_DIR) cargo bench --workspace --features "compress" diff --git a/core/Cargo.toml b/core/Cargo.toml index 73288de..7714573 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "vsdb_core" -version = "2.0.0" +version = "3.0.0" authors = ["hui.fan@mail.ru"] edition = "2021" description = "A std-collection-like database" @@ -18,8 +18,8 @@ parking_lot = { workspace = true } threadpool = { workspace = true } # used in a background cleaner -rocksdb = { workspace = true, optional = true } parity-db = { workspace = true, optional = true } +rocksdb = { workspace = true, optional = true } [dev-dependencies] msgpack = { workspace = true } @@ -27,10 +27,10 @@ hex = "0.4.3" criterion = "0.5.1" [features] -default = ["compress", "rocks_backend"] +default = ["compress", "parity_backend"] -rocks_backend = ["rocksdb"] parity_backend = ["parity-db"] +rocks_backend = ["rocksdb"] compress = ["rocksdb?/zstd"] diff --git a/core/src/basic/mapx_raw/mod.rs b/core/src/basic/mapx_raw/mod.rs index a17abf0..3665a42 100644 --- a/core/src/basic/mapx_raw/mod.rs +++ b/core/src/basic/mapx_raw/mod.rs @@ -33,7 +33,7 @@ #[cfg(test)] mod test; -use crate::common::{engines, RawKey, RawValue}; +use crate::common::{engines, PreBytes, RawKey, RawValue}; use serde::{Deserialize, Serialize}; use std::{borrow::Cow, ops::RangeBounds}; @@ -78,8 +78,8 @@ impl MapxRaw { } #[inline(always)] - pub fn gen_mut(&mut self, key: RawValue, value: RawValue) -> ValueMut { - self.inner.gen_mut(key, value) + pub fn mock_value_mut(&mut self, key: RawValue, value: RawValue) -> ValueMut { + self.inner.mock_value_mut(key, value) } #[inline(always)] @@ -183,7 +183,7 @@ impl MapxRaw { } #[inline(always)] - pub fn as_prefix_slice(&self) -> &[u8] { + pub fn as_prefix_slice(&self) -> &PreBytes { self.inner.as_prefix_slice() } @@ -210,7 +210,7 @@ impl<'a> Entry<'a> { if let Some(v) = unsafe { &mut *hdr }.get_mut(self.key) { v } else { - unsafe { &mut *hdr }.gen_mut(self.key.to_vec(), default.to_vec()) + unsafe { &mut *hdr }.mock_value_mut(self.key.to_vec(), default.to_vec()) } } @@ -222,7 +222,7 @@ impl<'a> Entry<'a> { if let Some(v) = unsafe { &mut *hdr }.get_mut(self.key) { v } else { - unsafe { &mut *hdr }.gen_mut(self.key.to_vec(), f()) + unsafe { &mut *hdr }.mock_value_mut(self.key.to_vec(), f()) } } } diff --git a/core/src/common/engines/mod.rs b/core/src/common/engines/mod.rs index bf11f4a..e1d4e41 100644 --- a/core/src/common/engines/mod.rs +++ b/core/src/common/engines/mod.rs @@ -25,10 +25,7 @@ type EngineIter = parity_backend::ParityIter; ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// -use crate::common::{ - BranchIDBase as BranchID, Pre, PreBytes, RawKey, RawValue, - VersionIDBase as VersionID, PREFIX_SIZE, VSDB, -}; +use crate::common::{Pre, PreBytes, RawKey, RawValue, PREFIX_SIZE, VSDB}; use parking_lot::Mutex; use ruc::*; use serde::{de, Deserialize, Serialize}; @@ -51,8 +48,6 @@ static LEN_LK: LazyLock>> = pub trait Engine: Sized { fn new() -> Result; fn alloc_prefix(&self) -> Pre; - fn alloc_br_id(&self) -> BranchID; - fn alloc_ver_id(&self) -> VersionID; fn area_count(&self) -> usize; // NOTE: @@ -111,7 +106,55 @@ pub trait Engine: Sized { #[derive(Debug)] pub(crate) struct Mapx { // the unique ID of each instance - prefix: PreBytes, + prefix: Prefix, +} + +#[derive(Debug)] +enum Prefix { + Recoverd(PreBytes), + Created(LazyLock), +} + +impl Prefix { + #[inline(always)] + fn as_bytes(&self) -> &PreBytes { + match self { + Self::Recoverd(bytes) => bytes, + Self::Created(lc) => LazyLock::force(lc), + } + } + + #[inline(always)] + fn to_bytes(&self) -> PreBytes { + *self.as_bytes() + } + + fn hack_bytes(&mut self) -> PreBytes { + match self { + Self::Recoverd(bytes) => *bytes, + Self::Created(lc) => { + let b = *LazyLock::force(lc); + *self = Self::Recoverd(b); + b + } + } + } + + #[inline(always)] + fn from_bytes(b: PreBytes) -> Self { + Self::Recoverd(b) + } + + #[inline(always)] + fn create() -> Self { + Self::Created(LazyLock::new(|| { + let prefix = VSDB.db.alloc_prefix(); + let prefix_bytes = prefix.to_be_bytes(); + debug_assert!(VSDB.db.iter(prefix_bytes).next().is_none()); + VSDB.db.set_instance_len(prefix_bytes, 0); + prefix_bytes + })) + } } impl Mapx { @@ -121,33 +164,25 @@ impl Mapx { // but it is safe to use in a race-free environment. pub(crate) unsafe fn shadow(&self) -> Self { Self { - prefix: self.prefix, + prefix: Prefix::from_bytes(self.prefix.to_bytes()), } } #[inline(always)] pub(crate) fn new() -> Self { - let prefix = VSDB.db.alloc_prefix(); - - let prefix_bytes = prefix.to_be_bytes(); - - assert!(VSDB.db.iter(prefix_bytes).next().is_none()); - - VSDB.db.set_instance_len(prefix_bytes, 0); - - Mapx { - prefix: prefix_bytes, + Self { + prefix: Prefix::create(), } } #[inline(always)] pub(crate) fn get(&self, key: &[u8]) -> Option { - VSDB.db.get(self.prefix, key) + VSDB.db.get(self.prefix.to_bytes(), key) } #[inline(always)] pub(crate) fn get_mut(&mut self, key: &[u8]) -> Option { - let v = VSDB.db.get(self.prefix, key)?; + let v = VSDB.db.get(self.prefix.hack_bytes(), key)?; Some(ValueMut { key: key.to_vec(), @@ -157,7 +192,7 @@ impl Mapx { } #[inline(always)] - pub(crate) fn gen_mut(&mut self, key: RawValue, value: RawValue) -> ValueMut { + pub(crate) fn mock_value_mut(&mut self, key: RawValue, value: RawValue) -> ValueMut { ValueMut { key, value, @@ -167,7 +202,7 @@ impl Mapx { #[inline(always)] pub(crate) fn len(&self) -> usize { - VSDB.db.get_instance_len(self.prefix) as usize + VSDB.db.get_instance_len(self.prefix.to_bytes()) as usize } #[inline(always)] @@ -178,7 +213,7 @@ impl Mapx { #[inline(always)] pub(crate) fn iter(&self) -> MapxIter { MapxIter { - db_iter: VSDB.db.iter(self.prefix), + db_iter: VSDB.db.iter(self.prefix.to_bytes()), _hdr: self, } } @@ -186,7 +221,7 @@ impl Mapx { #[inline(always)] pub(crate) fn iter_mut(&mut self) -> MapxIterMut { MapxIterMut { - db_iter: VSDB.db.iter(self.prefix), + db_iter: VSDB.db.iter(self.prefix.hack_bytes()), hdr: self, } } @@ -197,7 +232,7 @@ impl Mapx { bounds: R, ) -> MapxIter<'a> { MapxIter { - db_iter: VSDB.db.range(self.prefix, bounds), + db_iter: VSDB.db.range(self.prefix.to_bytes(), bounds), _hdr: self, } } @@ -208,35 +243,38 @@ impl Mapx { bounds: R, ) -> MapxIterMut<'a> { MapxIterMut { - db_iter: VSDB.db.range(self.prefix, bounds), + db_iter: VSDB.db.range(self.prefix.hack_bytes(), bounds), hdr: self, } } #[inline(always)] pub(crate) fn insert(&mut self, key: &[u8], value: &[u8]) -> Option { - let ret = VSDB.db.insert(self.prefix, key, value); + let prefix = self.prefix.hack_bytes(); + let ret = VSDB.db.insert(prefix, key, value); if ret.is_none() { - VSDB.db.increase_instance_len(self.prefix); + VSDB.db.increase_instance_len(prefix); } ret } #[inline(always)] pub(crate) fn remove(&mut self, key: &[u8]) -> Option { - let ret = VSDB.db.remove(self.prefix, key); + let prefix = self.prefix.hack_bytes(); + let ret = VSDB.db.remove(prefix, key); if ret.is_some() { - VSDB.db.decrease_instance_len(self.prefix); + VSDB.db.decrease_instance_len(prefix); } ret } #[inline(always)] pub(crate) fn clear(&mut self) { - VSDB.db.iter(self.prefix).for_each(|(k, _)| { - VSDB.db.remove(self.prefix, &k); + let prefix = self.prefix.hack_bytes(); + VSDB.db.iter(prefix).for_each(|(k, _)| { + VSDB.db.remove(prefix, &k); }); - VSDB.db.set_instance_len(self.prefix, 0); + VSDB.db.set_instance_len(prefix, 0); } #[inline(always)] @@ -244,17 +282,19 @@ impl Mapx { debug_assert_eq!(s.as_ref().len(), PREFIX_SIZE); let mut prefix = PreBytes::default(); prefix.copy_from_slice(s.as_ref()); - Self { prefix } + Self { + prefix: Prefix::Recoverd(prefix), + } } #[inline(always)] - pub(crate) fn as_prefix_slice(&self) -> &[u8] { - &self.prefix + pub(crate) fn as_prefix_slice(&self) -> &PreBytes { + self.prefix.as_bytes() } #[inline(always)] pub fn is_the_same_instance(&self, other_hdr: &Self) -> bool { - self.prefix == other_hdr.prefix + self.prefix.to_bytes() == other_hdr.prefix.to_bytes() } } @@ -348,7 +388,7 @@ impl Serialize for Mapx { where S: serde::Serializer, { - serializer.serialize_bytes(self.as_prefix_slice()) + serializer.serialize_bytes(&self.prefix.to_bytes()) } } diff --git a/core/src/common/engines/parity_backend.rs b/core/src/common/engines/parity_backend.rs index add4be8..9b60793 100644 --- a/core/src/common/engines/parity_backend.rs +++ b/core/src/common/engines/parity_backend.rs @@ -1,6 +1,5 @@ use crate::common::{ - vsdb_get_base_dir, vsdb_set_base_dir, BranchIDBase as BranchID, Engine, Pre, - PreBytes, RawBytes, RawKey, RawValue, VersionIDBase as VersionID, INITIAL_BRANCH_ID, + vsdb_get_base_dir, vsdb_set_base_dir, Engine, Pre, PreBytes, RawKey, RawValue, PREFIX_SIZE, RESERVED_ID_CNT, }; use parity_db::{BTreeIterator, CompressionType, Db as DB, Options}; @@ -23,8 +22,6 @@ const DATA_SET_NUM: u8 = 2; const META_COLID: u8 = DATA_SET_NUM; const META_KEY_MAX_KEYLEN: [u8; 1] = [u8::MAX]; -const META_KEY_BRANCH_ID: [u8; 1] = [u8::MAX - 1]; -const META_KEY_VERSION_ID: [u8; 1] = [u8::MAX - 2]; const META_KEY_PREFIX_ALLOCATOR: [u8; 1] = [u8::MIN]; const META_KEY_NULL: [u8; 0] = [0; 0]; @@ -56,12 +53,12 @@ impl ParityEngine { #[inline(always)] fn get_upper_bound_value(&self, hdr_prefix: PreBytes) -> Vec { - static BUF: LazyLock = LazyLock::new(|| vec![u8::MAX; 512]); + const BUF: [u8; 256] = [u8::MAX; 256]; let mut max_guard = hdr_prefix.to_vec(); let l = self.get_max_keylen(); - if l < 513 { + if l < 257 { max_guard.extend_from_slice(&BUF[..l]); } else { max_guard.extend_from_slice(&vec![u8::MAX; l]); @@ -86,24 +83,6 @@ impl Engine for ParityEngine { .c(d!())?; } - if hdr.get(META_COLID, &META_KEY_BRANCH_ID).c(d!())?.is_none() { - hdr.commit([( - META_COLID, - META_KEY_BRANCH_ID, - Some((1 + INITIAL_BRANCH_ID as usize).to_be_bytes().to_vec()), - )]) - .c(d!())?; - } - - if hdr.get(META_COLID, &META_KEY_VERSION_ID).c(d!())?.is_none() { - hdr.commit([( - META_COLID, - META_KEY_VERSION_ID, - Some(0_usize.to_be_bytes().to_vec()), - )]) - .c(d!())?; - } - if hdr .get(META_COLID, &prefix_allocator.key) .c(d!())? @@ -156,62 +135,6 @@ impl Engine for ParityEngine { ret } - // 'step 1' and 'step 2' is not atomic in multi-threads scene, - // so we use a `Mutex` lock for thread safe. - #[allow(unused_variables)] - fn alloc_br_id(&self) -> BranchID { - static LK: LazyLock> = LazyLock::new(|| Mutex::new(())); - let x = LK.lock(); - - // step 1 - let ret = crate::parse_int!( - self.hdr - .get(META_COLID, &META_KEY_BRANCH_ID) - .unwrap() - .unwrap(), - BranchID - ); - - // step 2 - self.hdr - .commit([( - META_COLID, - META_KEY_BRANCH_ID, - Some((1 + ret).to_be_bytes().to_vec()), - )]) - .unwrap(); - - ret - } - - // 'step 1' and 'step 2' is not atomic in multi-threads scene, - // so we use a `Mutex` lock for thread safe. - #[allow(unused_variables)] - fn alloc_ver_id(&self) -> VersionID { - static LK: LazyLock> = LazyLock::new(|| Mutex::new(())); - let x = LK.lock(); - - // step 1 - let ret = crate::parse_int!( - self.hdr - .get(META_COLID, &META_KEY_VERSION_ID) - .unwrap() - .unwrap(), - VersionID - ); - - // step 2 - self.hdr - .commit([( - META_COLID, - META_KEY_VERSION_ID, - Some((1 + ret).to_be_bytes().to_vec()), - )]) - .unwrap(); - - ret - } - fn area_count(&self) -> usize { DATA_SET_NUM as usize } diff --git a/core/src/common/engines/rocks_backend.rs b/core/src/common/engines/rocks_backend.rs index d518f01..7150704 100644 --- a/core/src/common/engines/rocks_backend.rs +++ b/core/src/common/engines/rocks_backend.rs @@ -1,7 +1,6 @@ use crate::common::{ - vsdb_get_base_dir, vsdb_set_base_dir, BranchIDBase as BranchID, Engine, Pre, - PreBytes, RawBytes, RawKey, RawValue, VersionIDBase as VersionID, GB, - INITIAL_BRANCH_ID, MB, PREFIX_SIZE, RESERVED_ID_CNT, + vsdb_get_base_dir, vsdb_set_base_dir, Engine, Pre, PreBytes, RawKey, RawValue, GB, + MB, PREFIX_SIZE, RESERVED_ID_CNT, }; use parking_lot::Mutex; use rocksdb::{ @@ -26,8 +25,6 @@ use std::{ const DATA_SET_NUM: usize = 2; const META_KEY_MAX_KEYLEN: [u8; 1] = [u8::MAX]; -const META_KEY_BRANCH_ID: [u8; 1] = [u8::MAX - 1]; -const META_KEY_VERSION_ID: [u8; 1] = [u8::MAX - 2]; const META_KEY_PREFIX_ALLOCATOR: [u8; 1] = [u8::MIN]; static HDR: LazyLock<(DB, Vec)> = LazyLock::new(|| rocksdb_open().unwrap()); @@ -60,12 +57,12 @@ impl RocksEngine { #[inline(always)] fn get_upper_bound_value(&self, meta_prefix: PreBytes) -> Vec { - static BUF: LazyLock = LazyLock::new(|| vec![u8::MAX; 512]); + const BUF: [u8; 256] = [u8::MAX; 256]; let mut max_guard = meta_prefix.to_vec(); let l = self.get_max_keylen(); - if l < 513 { + if l < 257 { max_guard.extend_from_slice(&BUF[..l]); } else { max_guard.extend_from_slice(&vec![u8::MAX; l]); @@ -87,19 +84,6 @@ impl Engine for RocksEngine { .c(d!())?; } - if meta.get(META_KEY_BRANCH_ID).c(d!())?.is_none() { - meta.put( - META_KEY_BRANCH_ID, - (1 + INITIAL_BRANCH_ID as usize).to_be_bytes(), - ) - .c(d!())?; - } - - if meta.get(META_KEY_VERSION_ID).c(d!())?.is_none() { - meta.put(META_KEY_VERSION_ID, 0_usize.to_be_bytes()) - .c(d!())?; - } - if meta.get(prefix_allocator.key).c(d!())?.is_none() { meta.put(prefix_allocator.key, initial_value).c(d!())?; } @@ -140,48 +124,6 @@ impl Engine for RocksEngine { ret } - // 'step 1' and 'step 2' is not atomic in multi-threads scene, - // so we use a `Mutex` lock for thread safe. - #[allow(unused_variables)] - fn alloc_br_id(&self) -> BranchID { - static LK: LazyLock> = LazyLock::new(|| Mutex::new(())); - let x = LK.lock(); - - // step 1 - let ret = crate::parse_int!( - self.meta.get(META_KEY_BRANCH_ID).unwrap().unwrap(), - BranchID - ); - - // step 2 - self.meta - .put(META_KEY_BRANCH_ID, (1 + ret).to_be_bytes()) - .unwrap(); - - ret - } - - // 'step 1' and 'step 2' is not atomic in multi-threads scene, - // so we use a `Mutex` lock for thread safe. - #[allow(unused_variables)] - fn alloc_ver_id(&self) -> VersionID { - static LK: LazyLock> = LazyLock::new(|| Mutex::new(())); - let x = LK.lock(); - - // step 1 - let ret = crate::parse_int!( - self.meta.get(META_KEY_VERSION_ID).unwrap().unwrap(), - VersionID - ); - - // step 2 - self.meta - .put(META_KEY_VERSION_ID, (1 + ret).to_be_bytes()) - .unwrap(); - - ret - } - fn area_count(&self) -> usize { DATA_SET_NUM } diff --git a/core/src/common/mod.rs b/core/src/common/mod.rs index 627fb16..b0c72d4 100644 --- a/core/src/common/mod.rs +++ b/core/src/common/mod.rs @@ -7,7 +7,6 @@ pub(crate) mod engines; use engines::Engine; use parking_lot::Mutex; use ruc::*; -use serde::{Deserialize, Serialize}; use std::{ env, fs, mem::size_of, @@ -32,43 +31,12 @@ pub type Pre = u64; pub const PREFIX_SIZE: usize = size_of::
();
 pub type PreBytes = [u8; PREFIX_SIZE];
 
-pub type BranchID = [u8; size_of::()];
-pub type VersionID = [u8; size_of::()];
-
-pub const VER_ID_MAX: VersionID = VersionIDBase::MAX.to_be_bytes();
-
-pub type BranchIDBase = u64;
-pub type VersionIDBase = u64;
-
-/// Avoid making mistakes between branch name and version name.
-#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
-pub struct BranchName<'a>(pub &'a [u8]);
-#[derive(Clone, Debug, Eq, PartialEq, Default, Serialize, Deserialize)]
-pub struct BranchNameOwned(pub Vec);
-/// Avoid making mistakes between branch name and version name.
-#[derive(Clone, Copy, Debug, Eq, PartialEq, Default, Serialize, Deserialize)]
-pub struct ParentBranchName<'a>(pub &'a [u8]);
-#[derive(Clone, Debug, Eq, PartialEq, Default, Serialize, Deserialize)]
-pub struct ParentBranchNameOwned(pub Vec);
-/// Avoid making mistakes between branch name and version name.
-#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
-pub struct VersionName<'a>(pub &'a [u8]);
-#[derive(Clone, Debug, Eq, PartialEq, Default, Serialize, Deserialize)]
-pub struct VersionNameOwned(pub Vec);
-
 pub const KB: u64 = 1 << 10;
 pub const MB: u64 = 1 << 20;
 pub const GB: u64 = 1 << 30;
 
 const RESERVED_ID_CNT: Pre = 4096_0000;
 pub const BIGGEST_RESERVED_ID: Pre = RESERVED_ID_CNT - 1;
-pub const NULL_ID: BranchID = (BIGGEST_RESERVED_ID as BranchIDBase).to_be_bytes();
-
-pub const INITIAL_BRANCH_ID: BranchIDBase = 0;
-pub const INITIAL_BRANCH_NAME: BranchName<'static> = BranchName(b"master");
-
-/// The default value for reserved number when pruning old data.
-pub const RESERVED_VERSION_NUM_DEFAULT: usize = 10;
 
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
@@ -136,16 +104,6 @@ impl VsDB {
         })
     }
 
-    #[inline(always)]
-    pub fn alloc_br_id(&self) -> BranchIDBase {
-        self.db.alloc_br_id()
-    }
-
-    #[inline(always)]
-    pub fn alloc_ver_id(&self) -> VersionIDBase {
-        self.db.alloc_ver_id()
-    }
-
     #[inline(always)]
     fn flush(&self) {
         self.db.flush()
@@ -196,97 +154,3 @@ pub fn vsdb_set_base_dir(dir: impl AsRef) -> Result<()> {
 pub fn vsdb_flush() {
     VSDB.flush();
 }
-
-macro_rules! impl_from_for_name {
-    ($target: tt) => {
-        impl<'a> From<&'a [u8]> for $target<'a> {
-            fn from(t: &'a [u8]) -> Self {
-                $target(t)
-            }
-        }
-        impl<'a> From<&'a Vec> for $target<'a> {
-            fn from(t: &'a Vec) -> Self {
-                $target(t.as_slice())
-            }
-        }
-        impl<'a> From<&'a str> for $target<'a> {
-            fn from(t: &'a str) -> Self {
-                $target(t.as_bytes())
-            }
-        }
-        impl<'a> From<&'a String> for $target<'a> {
-            fn from(t: &'a String) -> Self {
-                $target(t.as_bytes())
-            }
-        }
-    };
-    ($target: tt, $($t: tt),+) => {
-        impl_from_for_name!($target);
-        impl_from_for_name!($($t), +);
-    };
-}
-
-impl_from_for_name!(BranchName, ParentBranchName, VersionName);
-
-impl Default for BranchName<'static> {
-    fn default() -> Self {
-        INITIAL_BRANCH_NAME
-    }
-}
-
-impl BranchNameOwned {
-    #[inline(always)]
-    pub fn as_deref(&self) -> BranchName {
-        BranchName(&self.0)
-    }
-}
-
-impl<'a> From<&'a BranchNameOwned> for BranchName<'a> {
-    fn from(b: &'a BranchNameOwned) -> Self {
-        b.as_deref()
-    }
-}
-
-impl From> for BranchNameOwned {
-    fn from(b: BranchName) -> Self {
-        BranchNameOwned(b.0.to_vec())
-    }
-}
-
-impl ParentBranchNameOwned {
-    #[inline(always)]
-    pub fn as_deref(&self) -> ParentBranchName {
-        ParentBranchName(&self.0)
-    }
-}
-
-impl<'a> From<&'a ParentBranchNameOwned> for ParentBranchName<'a> {
-    fn from(b: &'a ParentBranchNameOwned) -> Self {
-        b.as_deref()
-    }
-}
-
-impl From> for ParentBranchNameOwned {
-    fn from(b: ParentBranchName) -> Self {
-        ParentBranchNameOwned(b.0.to_vec())
-    }
-}
-
-impl VersionNameOwned {
-    #[inline(always)]
-    pub fn as_deref(&self) -> VersionName {
-        VersionName(&self.0)
-    }
-}
-
-impl<'a> From<&'a VersionNameOwned> for VersionName<'a> {
-    fn from(b: &'a VersionNameOwned) -> Self {
-        b.as_deref()
-    }
-}
-
-impl From> for VersionNameOwned {
-    fn from(b: VersionName) -> Self {
-        VersionNameOwned(b.0.to_vec())
-    }
-}
diff --git a/utils/hash_db/Cargo.toml b/utils/hash_db/Cargo.toml
index e58483e..c2abe9b 100644
--- a/utils/hash_db/Cargo.toml
+++ b/utils/hash_db/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "vsdb_hash_db"
-version = "2.0.0"
+version = "3.0.0"
 edition = "2021"
 keywords = ["mpt", "trie", "database", "blockchain"]
 license = "MIT"
@@ -20,10 +20,10 @@ ruc = { workspace = true }
 vsdb = { workspace = true }
 
 [features]
-default = ["rocks_backend","msgpack_codec"]
+default = ["parity_backend","msgpack_codec"]
 
-rocks_backend = ["vsdb/rocks_backend"]
 parity_backend = ["vsdb/parity_backend"]
+rocks_backend = ["vsdb/rocks_backend"]
 
 json_codec = ["vsdb/json_codec"]
 msgpack_codec = ["vsdb/msgpack_codec"]
diff --git a/utils/slot_db/Cargo.toml b/utils/slot_db/Cargo.toml
index e6b15fa..f47096c 100644
--- a/utils/slot_db/Cargo.toml
+++ b/utils/slot_db/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "vsdb_slot_db"
-version = "2.0.0"
+version = "3.0.0"
 edition = "2021"
 keywords = ["index", "cache", "timestamp", "slot", "database"]
 license = "MIT"
@@ -19,10 +19,10 @@ criterion = "0.5.1"
 rand = { workspace = true }
 
 [features]
-default = ["rocks_backend", "compress", "msgpack_codec"]
+default = ["parity_backend", "compress", "msgpack_codec"]
 
-rocks_backend = ["vsdb/rocks_backend"]
 parity_backend = ["vsdb/parity_backend"]
+rocks_backend = ["vsdb/rocks_backend"]
 
 compress = ["vsdb/compress"]
 
diff --git a/utils/trie_db/Cargo.toml b/utils/trie_db/Cargo.toml
index ad76ea6..5b5e94e 100644
--- a/utils/trie_db/Cargo.toml
+++ b/utils/trie_db/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "vsdb_trie_db"
-version = "2.0.0"
+version = "3.0.0"
 edition = "2021"
 keywords = ["mpt", "trie", "database", "blockchain"]
 license = "MIT"
@@ -22,10 +22,10 @@ vsdb = { workspace = true }
 vsdb_hash_db = { workspace = true }
 
 [features]
-default = ["rocks_backend","msgpack_codec"]
+default = ["parity_backend","msgpack_codec"]
 
-rocks_backend = ["vsdb/rocks_backend"]
 parity_backend = ["vsdb/parity_backend"]
+rocks_backend = ["vsdb/rocks_backend"]
 
 json_codec = ["vsdb/json_codec"]
 msgpack_codec = ["vsdb/msgpack_codec"]
diff --git a/wrappers/Cargo.toml b/wrappers/Cargo.toml
index ac84a72..afea1fe 100644
--- a/wrappers/Cargo.toml
+++ b/wrappers/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "vsdb"
-version = "2.0.0"
+version = "3.0.0"
 authors = ["hui.fan@mail.ru"]
 edition = "2021"
 description = "A std-collection-like database"
@@ -11,7 +11,7 @@ categories = ["database-implementations", "data-structures", "algorithms", "cach
 license = "GPL-3.0"
 
 [package.metadata.docs.rs]
-features = []
+# features = []
 
 [dependencies]
 serde = { workspace = true }
@@ -29,10 +29,10 @@ criterion = "0.5.1"
 rand = "0.8.5"
 
 [features]
-default = ["rocks_backend", "compress", "msgpack_codec"]
+default = ["parity_backend", "compress", "msgpack_codec"]
 
-rocks_backend = ["vsdb_core/rocks_backend"]
 parity_backend = ["vsdb_core/parity_backend"]
+rocks_backend = ["vsdb_core/rocks_backend"]
 
 compress = ["vsdb_core/compress"]
 
diff --git a/wrappers/README.md b/wrappers/README.md
index 29d51c6..ee89dff 100644
--- a/wrappers/README.md
+++ b/wrappers/README.md
@@ -22,11 +22,11 @@ This is a simplified version of the original [**vsdb**](https://crates.io/crates
 
 ### Compilation features
 
-- [ **DEFAULT** ] `rocks_backend`, use `rocksdb` as the backend database
-  - Stable
+- `rocks_backend`, use `rocksdb` as the backend database
+  - Stable ?
   - C++ implementation, difficult to be compiled into a static binary
-- `parity_backend`, use `parity-db` as the backend database
-  - Experimental
+- [ **DEFAULT** ] `parity_backend`, use `parity-db` as the backend database
+  - Experimental ?
   - Pure rust implementation, can be easily compiled into a static binary
 - `msgpack_codec`, use `rmp-serde` as the codec
     - Faster running speed than json
diff --git a/wrappers/src/basic/mapx_ord/mod.rs b/wrappers/src/basic/mapx_ord/mod.rs
index 0408cf3..1da97fb 100644
--- a/wrappers/src/basic/mapx_ord/mod.rs
+++ b/wrappers/src/basic/mapx_ord/mod.rs
@@ -465,7 +465,7 @@ where
         if let Some(v) = unsafe { &mut *hdr }.get_mut(&self.key) {
             v
         } else {
-            unsafe { &mut *hdr }.gen_mut(self.key, default)
+            unsafe { &mut *hdr }.mock_value_mut(self.key, default)
         }
     }
 }
diff --git a/wrappers/src/basic/mapx_ord_rawkey/mod.rs b/wrappers/src/basic/mapx_ord_rawkey/mod.rs
index aa646e0..9d618ab 100644
--- a/wrappers/src/basic/mapx_ord_rawkey/mod.rs
+++ b/wrappers/src/basic/mapx_ord_rawkey/mod.rs
@@ -107,11 +107,11 @@ where
     }
 
     #[inline(always)]
-    pub(crate) fn gen_mut(&mut self, key: RawKey, value: V) -> ValueMut<'_, V> {
+    pub(crate) fn mock_value_mut(&mut self, key: RawKey, value: V) -> ValueMut<'_, V> {
         let v = value.encode();
         ValueMut {
             value,
-            inner: self.inner.gen_mut(key, v),
+            inner: self.inner.mock_value_mut(key, v),
         }
     }
 
@@ -325,7 +325,7 @@ where
         if let Some(v) = unsafe { &mut *hdr }.get_mut(self.key) {
             v
         } else {
-            unsafe { &mut *hdr }.gen_mut(self.key.to_vec(), default)
+            unsafe { &mut *hdr }.mock_value_mut(self.key.to_vec(), default)
         }
     }
 }
diff --git a/wrappers/src/basic/mapx_ord_rawvalue/mod.rs b/wrappers/src/basic/mapx_ord_rawvalue/mod.rs
index a1a316a..ba390f9 100644
--- a/wrappers/src/basic/mapx_ord_rawvalue/mod.rs
+++ b/wrappers/src/basic/mapx_ord_rawvalue/mod.rs
@@ -106,7 +106,7 @@ where
     }
 
     #[inline(always)]
-    pub(crate) fn gen_mut(&mut self, key: K, value: RawValue) -> ValueMut<'_, K> {
+    pub(crate) fn mock_value_mut(&mut self, key: K, value: RawValue) -> ValueMut<'_, K> {
         ValueMut {
             hdr: self,
             key,
@@ -355,7 +355,7 @@ where
         if let Some(v) = unsafe { &mut *hdr }.get_mut(&self.key) {
             v
         } else {
-            unsafe { &mut *hdr }.gen_mut(self.key, default.as_ref().to_vec())
+            unsafe { &mut *hdr }.mock_value_mut(self.key, default.as_ref().to_vec())
         }
     }
 }
diff --git a/wrappers/src/basic_multi_key/mapx_double_key/mod.rs b/wrappers/src/basic_multi_key/mapx_double_key/mod.rs
index 2e7e3ab..c585c4c 100644
--- a/wrappers/src/basic_multi_key/mapx_double_key/mod.rs
+++ b/wrappers/src/basic_multi_key/mapx_double_key/mod.rs
@@ -73,7 +73,7 @@ where
     }
 
     #[inline(always)]
-    pub fn gen_mut<'a>(
+    pub fn mock_value_mut<'a>(
         &'a mut self,
         key: &'a (&'a K1, &'a K2),
         v: V,
@@ -234,7 +234,7 @@ where
         if let Some(v) = unsafe { &mut *hdr }.get_mut(self.key) {
             v
         } else {
-            unsafe { &mut *hdr }.gen_mut(self.key, default)
+            unsafe { &mut *hdr }.mock_value_mut(self.key, default)
         }
     }
 }
diff --git a/wrappers/src/basic_multi_key/mapx_raw/mod.rs b/wrappers/src/basic_multi_key/mapx_raw/mod.rs
index cbd0a8d..d4c24ad 100644
--- a/wrappers/src/basic_multi_key/mapx_raw/mod.rs
+++ b/wrappers/src/basic_multi_key/mapx_raw/mod.rs
@@ -78,7 +78,7 @@ impl MapxRawMk {
     }
 
     #[inline(always)]
-    pub(crate) fn gen_mut<'a>(
+    pub(crate) fn mock_value_mut<'a>(
         &'a mut self,
         key: &'a [&'a [u8]],
         v: RawValue,
@@ -398,7 +398,7 @@ impl<'a> Entry<'a> {
         if let Some(v) = unsafe { &mut *hdr }.get_mut(self.key) {
             v
         } else {
-            unsafe { &mut *hdr }.gen_mut(self.key, default.to_vec())
+            unsafe { &mut *hdr }.mock_value_mut(self.key, default.to_vec())
         }
     }
 }
diff --git a/wrappers/src/basic_multi_key/mapx_rawkey/mod.rs b/wrappers/src/basic_multi_key/mapx_rawkey/mod.rs
index c5a3fab..7b8fe9f 100644
--- a/wrappers/src/basic_multi_key/mapx_rawkey/mod.rs
+++ b/wrappers/src/basic_multi_key/mapx_rawkey/mod.rs
@@ -57,7 +57,7 @@ impl MapxRawKeyMk {
     }
 
     #[inline(always)]
-    pub(crate) fn gen_mut<'a>(
+    pub(crate) fn mock_value_mut<'a>(
         &'a mut self,
         key: &'a [&'a [u8]],
         v: V,
@@ -196,7 +196,7 @@ impl<'a, V: ValueEnDe> Entry<'a, V> {
         if let Some(v) = unsafe { &mut *hdr }.get_mut(self.key) {
             v
         } else {
-            unsafe { &mut *hdr }.gen_mut(self.key, default)
+            unsafe { &mut *hdr }.mock_value_mut(self.key, default)
         }
     }
 }
diff --git a/wrappers/src/basic_multi_key/mapx_triple_key/mod.rs b/wrappers/src/basic_multi_key/mapx_triple_key/mod.rs
index cd13eeb..8288174 100644
--- a/wrappers/src/basic_multi_key/mapx_triple_key/mod.rs
+++ b/wrappers/src/basic_multi_key/mapx_triple_key/mod.rs
@@ -75,7 +75,7 @@ where
     }
 
     #[inline(always)]
-    pub fn gen_mut<'a>(
+    pub fn mock_value_mut<'a>(
         &'a mut self,
         key: &'a (&'a K1, &'a K2, &'a K3),
         v: V,
@@ -258,7 +258,7 @@ where
         if let Some(v) = unsafe { &mut *hdr }.get_mut(self.key) {
             v
         } else {
-            unsafe { &mut *hdr }.gen_mut(self.key, default)
+            unsafe { &mut *hdr }.mock_value_mut(self.key, default)
         }
     }
 }