Skip to content

Commit

Permalink
av-store: Move prune on a separate thread
Browse files Browse the repository at this point in the history
There are situations where pruning of the data could take more than a few
seconds and that might make the whole subsystem unreponsive. To avoid this just
move the prune process on a separate thread.

See: paritytech#7237, for more details.

Signed-off-by: Alexandru Gheorghe <[email protected]>
  • Loading branch information
alexggh committed May 22, 2023
1 parent cbd5330 commit 7ff883b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions node/core/av-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,17 @@ async fn run_iteration<Context>(
*next_pruning = Delay::new(subsystem.pruning_config.pruning_interval).fuse();

let _timer = subsystem.metrics.time_pruning();
prune_all(&subsystem.db, &subsystem.config, &*subsystem.clock)?;

let db = subsystem.db.clone();
let config = subsystem.config.clone();
let time_now = subsystem.clock.now()?;
ctx.spawn_blocking("av-store-prunning", Box::pin(async move {
// TODO: When prune all was throwing fatal errors the main loop is exiting
// so, so we should achieve the same here.
if let Err(err) = prune_all(&db, &config, time_now) {
err.trace();
}
}))?;
}
}

Expand Down Expand Up @@ -1250,8 +1260,7 @@ fn store_available_data(
Ok(())
}

fn prune_all(db: &Arc<dyn Database>, config: &Config, clock: &dyn Clock) -> Result<(), Error> {
let now = clock.now()?;
fn prune_all(db: &Arc<dyn Database>, config: &Config, now: Duration) -> Result<(), Error> {
let (range_start, range_end) = pruning_range(now);

let mut tx = DBTransaction::new();
Expand Down

0 comments on commit 7ff883b

Please sign in to comment.