Skip to content

Commit

Permalink
Allow forcing cache purge (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop authored Nov 3, 2023
1 parent 46e10a0 commit 687e9c4
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ pub struct Options {
/// Path and file name to use for mmap file when building dense tree.
#[clap(long, env, default_value = "./dense_tree_mmap")]
pub dense_tree_mmap_file: String,

/// If set will not use cached tree state.
#[clap(long, env)]
pub force_cache_purge: bool,
}

pub struct App {
Expand Down Expand Up @@ -211,6 +215,7 @@ impl App {
identity_manager.initial_leaf_value(),
initial_root_hash,
options.dense_tree_mmap_file,
options.force_cache_purge,
)
.await?;
info!("Tree state initialization took: {:?}", timer.elapsed());
Expand Down Expand Up @@ -253,27 +258,33 @@ impl App {
initial_leaf_value: Hash,
initial_root_hash: Hash,
mmap_file_path: String,
force_cache_purge: bool,
) -> AnyhowResult<TreeState> {

Check warning on line 262 in src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> src/app.rs:253:5 | 253 | / async fn restore_or_initialize_tree( 254 | | database: &Database, 255 | | tree_depth: usize, 256 | | dense_prefix_depth: usize, ... | 261 | | force_cache_purge: bool, 262 | | ) -> AnyhowResult<TreeState> { | |________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments note: the lint level is defined here --> src/lib.rs:2:9 | 2 | #![warn(clippy::all, clippy::pedantic, clippy::cargo)] | ^^^^^^^^^^^ = note: `#[warn(clippy::too_many_arguments)]` implied by `#[warn(clippy::all)]`

Check warning on line 262 in src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> src/app.rs:253:5 | 253 | / async fn restore_or_initialize_tree( 254 | | database: &Database, 255 | | tree_depth: usize, 256 | | dense_prefix_depth: usize, ... | 261 | | force_cache_purge: bool, 262 | | ) -> AnyhowResult<TreeState> { | |________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments note: the lint level is defined here --> src/lib.rs:2:9 | 2 | #![warn(clippy::all, clippy::pedantic, clippy::cargo)] | ^^^^^^^^^^^ = note: `#[warn(clippy::too_many_arguments)]` implied by `#[warn(clippy::all)]`

Check warning on line 262 in src/app.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> src/app.rs:253:5 | 253 | / async fn restore_or_initialize_tree( 254 | | database: &Database, 255 | | tree_depth: usize, 256 | | dense_prefix_depth: usize, ... | 261 | | force_cache_purge: bool, 262 | | ) -> AnyhowResult<TreeState> { | |________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments note: the lint level is defined here --> src/lib.rs:2:9 | 2 | #![warn(clippy::all, clippy::pedantic, clippy::cargo)] | ^^^^^^^^^^^ = note: `#[warn(clippy::too_many_arguments)]` implied by `#[warn(clippy::all)]`
let mut mined_items = database
.get_commitments_by_status(ProcessedStatus::Mined)
.await?;
mined_items.sort_by_key(|item| item.leaf_index);

if let Some(tree_state) = Self::get_cached_tree_state(
database,
tree_depth,
dense_prefix_depth,
gc_threshold,
&initial_leaf_value,
initial_root_hash,
mined_items.clone(),
&mmap_file_path,
)
.await?
{
info!("tree restored from cache");
return Ok(tree_state);
if !force_cache_purge {
info!("Attempting to restore tree from cache");
if let Some(tree_state) = Self::get_cached_tree_state(
database,
tree_depth,
dense_prefix_depth,
gc_threshold,
&initial_leaf_value,
initial_root_hash,
mined_items.clone(),
&mmap_file_path,
)
.await?
{
info!("tree restored from cache");
return Ok(tree_state);
}
}

info!("Initializing tree from the database");
let tree_state = Self::initialize_tree(
database,
tree_depth,
Expand All @@ -284,7 +295,9 @@ impl App {
mmap_file_path,
)
.await?;

info!("tree initialization successful");

Ok(tree_state)
}

Expand Down

0 comments on commit 687e9c4

Please sign in to comment.