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

checkpoint: wait checkpoint finished if exit before success #386

Merged
merged 2 commits into from
Sep 3, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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