From c2772f7a17d031df7081e3108f4734b5708b67e5 Mon Sep 17 00:00:00 2001 From: popcnt <142196625+popcnt1@users.noreply.github.com> Date: Sat, 28 Dec 2024 17:40:59 +0800 Subject: [PATCH] feat(rooch-da): add cache size options for rocksdb (#3115) Added options to configure `row_cache_size` and `block_cache_size` for RocksDB in the DA exec command. This enhances flexibility in tuning database performance. --- crates/rooch/src/commands/da/commands/exec.rs | 22 +++++++++++++++++-- crates/rooch/src/commands/da/commands/mod.rs | 4 ++++ crates/rooch/src/commands/da/mod.rs | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/crates/rooch/src/commands/da/commands/exec.rs b/crates/rooch/src/commands/da/commands/exec.rs index 8b3659b248..25e0902561 100644 --- a/crates/rooch/src/commands/da/commands/exec.rs +++ b/crates/rooch/src/commands/da/commands/exec.rs @@ -71,6 +71,15 @@ pub struct ExecCommand { #[clap(long = "btc-local-block-store-dir")] pub btc_local_block_store_dir: Option, + #[clap(name = "rocksdb-row-cache-size", long, help = "rocksdb row cache size")] + pub row_cache_size: Option, + + #[clap( + name = "rocksdb-block-cache-size", + long, + help = "rocksdb block cache size" + )] + pub block_cache_size: Option, #[clap(long = "enable-rocks-stats", help = "rocksdb-enable-statistics")] pub enable_rocks_stats: bool, @@ -108,6 +117,8 @@ impl ExecCommand { self.chain_id.clone(), &actor_system, self.enable_rocks_stats, + self.row_cache_size, + self.block_cache_size, ) .await?; @@ -508,11 +519,18 @@ async fn build_executor_and_store( chain_id: Option, actor_system: &ActorSystem, enable_rocks_stats: bool, + row_cache_size: Option, + block_cache_size: Option, ) -> anyhow::Result<(ExecutorProxy, MoveOSStore, RoochDB)> { let registry_service = RegistryService::default(); - let (root, rooch_db) = - build_rooch_db(base_data_dir.clone(), chain_id.clone(), enable_rocks_stats); + let (root, rooch_db) = build_rooch_db( + base_data_dir.clone(), + chain_id.clone(), + enable_rocks_stats, + row_cache_size, + block_cache_size, + ); let (rooch_store, moveos_store) = (rooch_db.rooch_store.clone(), rooch_db.moveos_store.clone()); let event_bus = EventBus::new(); diff --git a/crates/rooch/src/commands/da/commands/mod.rs b/crates/rooch/src/commands/da/commands/mod.rs index 45e6af6d8e..93bf675f40 100644 --- a/crates/rooch/src/commands/da/commands/mod.rs +++ b/crates/rooch/src/commands/da/commands/mod.rs @@ -86,9 +86,13 @@ pub(crate) fn build_rooch_db( base_data_dir: Option, chain_id: Option, enable_rocks_stats: bool, + row_cache_size: Option, + block_cache_size: Option, ) -> (ObjectMeta, RoochDB) { let mut opt = RoochOpt::new_with_default(base_data_dir, chain_id, None).unwrap(); opt.store.enable_statistics = enable_rocks_stats; + opt.store.row_cache_size = row_cache_size; + opt.store.block_cache_size = block_cache_size; let registry_service = RegistryService::default(); let rooch_db = RoochDB::init(opt.store_config(), ®istry_service.default_registry()).unwrap(); let root = rooch_db.latest_root().unwrap().unwrap(); diff --git a/crates/rooch/src/commands/da/mod.rs b/crates/rooch/src/commands/da/mod.rs index 8d1a3677c9..f07786edd3 100644 --- a/crates/rooch/src/commands/da/mod.rs +++ b/crates/rooch/src/commands/da/mod.rs @@ -36,6 +36,6 @@ impl CommandAction for DA { pub enum DACommand { Unpack(UnpackCommand), Namespace(NamespaceCommand), - Exec(ExecCommand), + Exec(Box), IndexTx(IndexTxCommand), }