Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
av-store: Move prune on a separte 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: #7237, for more details.

Signed-off-by: Alexandru Gheorghe <[email protected]>
  • Loading branch information
alexggh committed May 19, 2023
1 parent 99a5513 commit 4fb1923
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: The loop was existing on fatal errors from prune_all.
// probably 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 4fb1923

Please sign in to comment.