Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lightning: recover status from checkpoint after index engine closed #39365

Merged
merged 6 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
17 changes: 17 additions & 0 deletions br/pkg/lightning/restore/table_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,12 @@ func (tr *TableRestore) restoreEngines(pCtx context.Context, rc *Controller, cp
// data-engines that need to be restore or import. Otherwise, all data-engines should
// be finished already.

handleDataEngineThisRun := false
idxEngineCfg := &backend.EngineConfig{
TableInfo: tr.tableInfo,
}
if indexEngineCp.Status < checkpoints.CheckpointStatusClosed {
handleDataEngineThisRun = true
indexWorker := rc.indexWorkers.Apply()
defer rc.indexWorkers.Recycle(indexWorker)

Expand Down Expand Up @@ -370,11 +372,26 @@ func (tr *TableRestore) restoreEngines(pCtx context.Context, rc *Controller, cp
return errors.Trace(restoreErr)
}

// if data engine is handled in previous run and we continue importing from checkpoint
if !handleDataEngineThisRun {
for _, engine := range cp.Engines {
for _, chunk := range engine.Chunks {
rc.status.FinishedFileSize.Add(chunk.Chunk.EndOffset - chunk.Key.Offset)
}
}
}

if cp.Status < checkpoints.CheckpointStatusIndexImported {
var err error
if indexEngineCp.Status < checkpoints.CheckpointStatusImported {
err = tr.importKV(ctx, closedIndexEngine, rc, indexEngineID)
failpoint.Inject("FailBeforeIndexEngineImported", func() {
finished := rc.status.FinishedFileSize.Load()
total := rc.status.TotalFileSize.Load()
tr.logger.Warn("print lightning status",
zap.Int64("finished", finished),
zap.Int64("total", total),
zap.Bool("equal", finished == total))
panic("forcing failure due to FailBeforeIndexEngineImported")
})
}
Expand Down
3 changes: 3 additions & 0 deletions br/tests/lightning_checkpoint/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ for i in $(seq "$TABLE_COUNT"); do
done
set -e

# at the failure of last table, all data engines are imported so finished == total
grep "print lightning status" "$TEST_DIR/lightning.log" | grep -q "equal=true"

export GO_FAILPOINTS="$SLOWDOWN_FAILPOINTS"
# After everything is done, there should be no longer new calls to ImportEngine
# (and thus `kill_lightning_after_one_import` will spare this final check)
Expand Down