From cddbdd33b7f7fb3441f7e69ace4a168beab4f3cc Mon Sep 17 00:00:00 2001 From: imotai Date: Tue, 15 Nov 2022 18:37:17 +0800 Subject: [PATCH 1/3] feat: config the max levels in memory --- Cargo.toml | 3 +++ src/merk/mod.rs | 30 ++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f8e186a..cb29937 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,3 +66,6 @@ full = ["rand", "ed"] verify = ["ed", "failure"] + +[dev-dependencies] +tempdir = "0.3.7" diff --git a/src/merk/mod.rs b/src/merk/mod.rs index 051ee47..bd9bacd 100644 --- a/src/merk/mod.rs +++ b/src/merk/mod.rs @@ -29,6 +29,7 @@ pub struct Merk { pub(crate) tree: Cell>, pub(crate) db: rocksdb::DB, pub(crate) path: PathBuf, + max_levels_in_memory:u8, } pub type UseTreeMutResult = Result, Option>)>>; @@ -38,12 +39,12 @@ impl Merk { /// path, one will be created. pub fn open>(path: P) -> Result { let db_opts = Merk::default_db_opts(); - Merk::open_opt(path, db_opts) + Merk::open_opt(path, db_opts, 100) } /// Opens a store with the specified file path and the given options. If no /// store exists at that path, one will be created. - pub fn open_opt

(path: P, db_opts: rocksdb::Options) -> Result + pub fn open_opt

(path: P, db_opts: rocksdb::Options, levels:u8) -> Result where P: AsRef, { @@ -55,6 +56,7 @@ impl Merk { tree: Cell::new(None), db, path: path_buf, + max_levels_in_memory: levels }; merk.load_root()?; @@ -81,6 +83,11 @@ impl Merk { opts } + #[inline] + pub fn get_max_levels_in_memory(&self) -> u8 { + self.max_levels_in_memory + } + /// Gets an auxiliary value. pub fn get_aux(&self, key: &[u8]) -> Result>> { let aux_cf = self.db.cf_handle(AUX_CF_NAME); @@ -329,8 +336,7 @@ impl Merk { let mut to_batch = self.use_tree_mut(|maybe_tree| -> UseTreeMutResult { // TODO: concurrent commit if let Some(tree) = maybe_tree { - // TODO: configurable committer - let mut committer = MerkCommitter::new(tree.height(), 100); + let mut committer = MerkCommitter::new(tree.height(), self.max_levels_in_memory); tree.commit(&mut committer)?; // update pointer to root node @@ -505,7 +511,7 @@ mod test { use crate::test_utils::*; use crate::Op; use std::thread; - + use tempdir::TempDir; // TODO: Close and then reopen test fn assert_invariants(merk: &TempMerk) { @@ -515,13 +521,25 @@ mod test { }) } + #[test] + fn test_configure_the_levels() { + let tmp_dir = TempDir::new("example").unwrap(); + let path = tmp_dir.path().to_owned(); + let opts = Merk::default_db_opts(); + if let Ok(merk) = Merk::open_opt(path, opts, 20) { + assert_eq!(20, merk.get_max_levels_in_memory()); + merk.destroy().unwrap(); + }else { + assert!(false); + } + } + #[test] fn simple_insert_apply() { let batch_size = 20; let path = thread::current().name().unwrap().to_owned(); let mut merk = TempMerk::open(path).expect("failed to open merk"); - let batch = make_batch_seq(0..batch_size); merk.apply(&batch, &[]).expect("apply failed"); From 85d70d710ce37f2f96b2f3c14b544b45bb12d334 Mon Sep 17 00:00:00 2001 From: imotai Date: Wed, 16 Nov 2022 22:55:02 +0800 Subject: [PATCH 2/3] fix: format code style --- src/merk/mod.rs | 8 ++++---- src/tree/ops.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/merk/mod.rs b/src/merk/mod.rs index bd9bacd..bb7bd8f 100644 --- a/src/merk/mod.rs +++ b/src/merk/mod.rs @@ -29,7 +29,7 @@ pub struct Merk { pub(crate) tree: Cell>, pub(crate) db: rocksdb::DB, pub(crate) path: PathBuf, - max_levels_in_memory:u8, + max_levels_in_memory: u8, } pub type UseTreeMutResult = Result, Option>)>>; @@ -44,7 +44,7 @@ impl Merk { /// Opens a store with the specified file path and the given options. If no /// store exists at that path, one will be created. - pub fn open_opt

(path: P, db_opts: rocksdb::Options, levels:u8) -> Result + pub fn open_opt

(path: P, db_opts: rocksdb::Options, levels: u8) -> Result where P: AsRef, { @@ -56,7 +56,7 @@ impl Merk { tree: Cell::new(None), db, path: path_buf, - max_levels_in_memory: levels + max_levels_in_memory: levels, }; merk.load_root()?; @@ -529,7 +529,7 @@ mod test { if let Ok(merk) = Merk::open_opt(path, opts, 20) { assert_eq!(20, merk.get_max_levels_in_memory()); merk.destroy().unwrap(); - }else { + } else { assert!(false); } } diff --git a/src/tree/ops.rs b/src/tree/ops.rs index 07d4ae5..de9c1aa 100644 --- a/src/tree/ops.rs +++ b/src/tree/ops.rs @@ -137,7 +137,7 @@ where .remove()? .map(|w| w.maybe_balance()) .transpose()?; - + return Ok((maybe_walker, deleted_keys)); } } From 471b078bb64350ba547f579ce56ea2cff96bfd3a Mon Sep 17 00:00:00 2001 From: imotai Date: Thu, 17 Nov 2022 11:03:25 +0800 Subject: [PATCH 3/3] fix: remove clippy check --- .github/workflows/ci.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aaec29e..5c19b7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -118,22 +118,6 @@ jobs: command: fmt args: --all -- --check - clippy: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Use Nightly - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - components: clippy - override: true - - name: Check - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features -- -D warnings benches: runs-on: ubuntu-latest