Skip to content

Commit

Permalink
feat(rooch-da): add cache size options for rocksdb (#3115)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
popcnt1 authored Dec 28, 2024
1 parent 17c0558 commit c2772f7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
22 changes: 20 additions & 2 deletions crates/rooch/src/commands/da/commands/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ pub struct ExecCommand {
#[clap(long = "btc-local-block-store-dir")]
pub btc_local_block_store_dir: Option<PathBuf>,

#[clap(name = "rocksdb-row-cache-size", long, help = "rocksdb row cache size")]
pub row_cache_size: Option<u64>,

#[clap(
name = "rocksdb-block-cache-size",
long,
help = "rocksdb block cache size"
)]
pub block_cache_size: Option<u64>,
#[clap(long = "enable-rocks-stats", help = "rocksdb-enable-statistics")]
pub enable_rocks_stats: bool,

Expand Down Expand Up @@ -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?;

Expand Down Expand Up @@ -508,11 +519,18 @@ async fn build_executor_and_store(
chain_id: Option<RoochChainID>,
actor_system: &ActorSystem,
enable_rocks_stats: bool,
row_cache_size: Option<u64>,
block_cache_size: Option<u64>,
) -> 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();
Expand Down
4 changes: 4 additions & 0 deletions crates/rooch/src/commands/da/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ pub(crate) fn build_rooch_db(
base_data_dir: Option<PathBuf>,
chain_id: Option<RoochChainID>,
enable_rocks_stats: bool,
row_cache_size: Option<u64>,
block_cache_size: Option<u64>,
) -> (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(), &registry_service.default_registry()).unwrap();
let root = rooch_db.latest_root().unwrap().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch/src/commands/da/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ impl CommandAction<String> for DA {
pub enum DACommand {
Unpack(UnpackCommand),
Namespace(NamespaceCommand),
Exec(ExecCommand),
Exec(Box<ExecCommand>),
IndexTx(IndexTxCommand),
}

0 comments on commit c2772f7

Please sign in to comment.