Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
wait checkpoint finished if exit before success (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
glorv committed Sep 3, 2020
1 parent 75fcfbe commit 7b59075
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lightning/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,13 @@ func (rc *RestoreController) Run(ctx context.Context) error {
task := log.L().Begin(zap.InfoLevel, "the whole procedure")

var err error
finished := false
outside:
for i, process := range opts {
err = process(ctx)
if i == len(opts)-1 {
finished = true
}
logger := task.With(zap.Int("step", i), log.ShortError(err))

switch {
Expand All @@ -295,6 +299,11 @@ outside:
}
}

// if process is cancelled, should make sure checkpoints are written to db.
if !finished {
rc.waitCheckpointFinish()
}

task.End(zap.ErrorLevel, err)
rc.errorSummaries.emitLog()

Expand Down Expand Up @@ -1271,10 +1280,14 @@ func (rc *RestoreController) checkRequirements(_ context.Context) error {
return rc.backend.CheckRequirements()
}

func (rc *RestoreController) cleanCheckpoints(ctx context.Context) error {
func (rc *RestoreController) waitCheckpointFinish() {
// wait checkpoint process finish so that we can do cleanup safely
close(rc.saveCpCh)
rc.checkpointsWg.Wait()
}

func (rc *RestoreController) cleanCheckpoints(ctx context.Context) error {
rc.waitCheckpointFinish()

if !rc.cfg.Checkpoint.Enable {
return nil
Expand Down

0 comments on commit 7b59075

Please sign in to comment.