Skip to content

Commit

Permalink
fix(state-sync): gracefully shutdown the dumper
Browse files Browse the repository at this point in the history
  • Loading branch information
VanBarbascu committed Feb 7, 2025
1 parent 20ea311 commit 8fcf099
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions nearcore/src/state_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ impl DumpState {
}
}
}

pub fn cancel(&self) {
self.canceled.store(true, Ordering::Relaxed);
for (_shard_id, d) in self.dump_state.iter() {
// Set it to -1 to tell the existing tasks not to set the metrics anymore
d.parts_dumped.store(-1, Ordering::SeqCst);
}
}
}

// Represents the state of the current epoch's state part dump
Expand Down Expand Up @@ -951,11 +959,7 @@ impl StateDumper {
target: "state_sync_dump", "Canceling existing dump of state for epoch {} upon new epoch {}",
&dump.epoch_id.0, &sync_header.epoch_id().0,
);
dump.canceled.store(true, Ordering::Relaxed);
for (_shard_id, d) in dump.dump_state.iter() {
// Set it to -1 to tell the existing tasks not to set the metrics anymore
d.parts_dumped.store(-1, Ordering::SeqCst);
}
dump.cancel();
}
CurrentDump::Done(epoch_id) => {
if epoch_id == sync_header.epoch_id() {
Expand Down Expand Up @@ -1034,6 +1038,10 @@ async fn state_sync_dump(
}
}

tracing::debug!(target: "state_sync_dump", "Stopping state dump thread");
if let CurrentDump::InProgress(dump) = dumper.current_dump {
dump.cancel();
}
tracing::debug!(target: "state_sync_dump", "Stopped state dump thread");
Ok(())
}
Expand Down

0 comments on commit 8fcf099

Please sign in to comment.