Skip to content

Commit

Permalink
Merge pull request #241 from uprendis/feature/save-snapsync-journal-o…
Browse files Browse the repository at this point in the history
…n-quit

Save snapsync journal during stopping
  • Loading branch information
uprendis authored Mar 3, 2022
2 parents 906bdb9 + 69a2266 commit 34c6942
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions gossip/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@ func (h *handler) snapsyncStageLoop() {
}
}

// mayCancel cancels existing snapsync process if any
func (ss *snapsyncState) mayCancel() error {
if ss.cancel != nil {
err := ss.cancel()
ss.cancel = nil
return err
}
return nil
}

func (h *handler) snapsyncStateLoop() {
defer h.loopsWg.Done()
for {
Expand All @@ -263,26 +273,19 @@ func (h *handler) snapsyncStateLoop() {
continue
}
h.snapState.epoch = upd.epoch
// cancel existing snapsync state
if h.snapState.cancel != nil {
_ = h.snapState.cancel()
h.snapState.cancel = nil
}
_ = h.snapState.mayCancel()
// start new snapsync state
h.Log.Info("Update snapsync epoch", "epoch", upd.epoch, "root", upd.root)
h.process.PauseEvmSnapshot()
ss := h.snapLeecher.SyncState(upd.root)
h.snapState.cancel = ss.Cancel
}
if cmd.snapsyncCancelCmd != nil {
// cancel existing snapsync state
if h.snapState.cancel != nil {
_ = h.snapState.cancel()
h.snapState.cancel = nil
}
_ = h.snapState.mayCancel()
cmd.snapsyncCancelCmd.done <- struct{}{}
}
case <-h.snapState.quit:
_ = h.snapState.mayCancel()
return
}
}
Expand Down

0 comments on commit 34c6942

Please sign in to comment.