Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#46589
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
Leavrth authored and ti-chi-bot committed Sep 4, 2023
1 parent e2ba276 commit 01ae5a2
Show file tree
Hide file tree
Showing 2 changed files with 281 additions and 22 deletions.
51 changes: 41 additions & 10 deletions br/pkg/restore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2323,6 +2323,34 @@ func (rc *Client) RestoreMetaKVFiles(
}
}

<<<<<<< HEAD
=======
failpoint.Inject("failed-before-id-maps-saved", func(_ failpoint.Value) {
failpoint.Return(errors.New("failpoint: failed before id maps saved"))
})

log.Info("start to restore meta files",
zap.Int("total files", len(files)),
zap.Int("default files", len(filesInDefaultCF)),
zap.Int("write files", len(filesInWriteCF)))

if schemasReplace.NeedConstructIdMap() {
// Preconstruct the map and save it into external storage.
if err := rc.PreConstructAndSaveIDMap(
ctx,
filesInWriteCF,
filesInDefaultCF,
schemasReplace,
); err != nil {
return errors.Trace(err)
}
}
failpoint.Inject("failed-after-id-maps-saved", func(_ failpoint.Value) {
failpoint.Return(errors.New("failpoint: failed after id maps saved"))
})

// run the rewrite and restore meta-kv into TiKV cluster.
>>>>>>> 5319cf7d8a8 (br: fix restore metakv without default cf files (#46589))
if err := rc.RestoreMetaKVFilesWithBatchMethod(
ctx,
SortMetaKVFiles(filesInDefaultCF),
Expand Down Expand Up @@ -2380,6 +2408,7 @@ func (rc *Client) RestoreMetaKVFilesWithBatchMethod(
if i == 0 {
rangeMax = f.MaxTs
rangeMin = f.MinTs
batchSize = f.Length
} else {
if f.MinTs <= rangeMax && batchSize+f.Length <= MetaKVBatchSize {
rangeMin = mathutil.Min(rangeMin, f.MinTs)
Expand Down Expand Up @@ -2412,16 +2441,18 @@ func (rc *Client) RestoreMetaKVFilesWithBatchMethod(
writeIdx = toWriteIdx
}
}
if i == len(defaultFiles)-1 {
_, err = restoreBatch(ctx, defaultFiles[defaultIdx:], schemasReplace, defaultKvEntries, math.MaxUint64, updateStats, progressInc, stream.DefaultCF)
if err != nil {
return errors.Trace(err)
}
_, err = restoreBatch(ctx, writeFiles[writeIdx:], schemasReplace, writeKvEntries, math.MaxUint64, updateStats, progressInc, stream.WriteCF)
if err != nil {
return errors.Trace(err)
}
}
}

// restore the left meta kv files and entries
// Notice: restoreBatch needs to realize the parameter `files` and `kvEntries` might be empty
// Assert: defaultIdx <= len(defaultFiles) && writeIdx <= len(writeFiles)
_, err = restoreBatch(ctx, defaultFiles[defaultIdx:], schemasReplace, defaultKvEntries, math.MaxUint64, updateStats, progressInc, stream.DefaultCF)
if err != nil {
return errors.Trace(err)
}
_, err = restoreBatch(ctx, writeFiles[writeIdx:], schemasReplace, writeKvEntries, math.MaxUint64, updateStats, progressInc, stream.WriteCF)
if err != nil {
return errors.Trace(err)
}

return nil
Expand Down
Loading

0 comments on commit 01ae5a2

Please sign in to comment.