Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
fix region epoch error
Browse files Browse the repository at this point in the history
Signed-off-by: 5kbpers <tangminghua@pingcap.com>
  • Loading branch information
5kbpers committed Feb 11, 2020
1 parent 8622d68 commit 985676b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/restore/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

var (
errNotLeader = errors.NewNoStackError("not leader")
errEpochNotMatch = errors.NewNoStackError("epoch not match")
errKeyNotInRegion = errors.NewNoStackError("key not in region")
errResp = errors.NewNoStackError("response error")
errRewriteRuleNotFound = errors.NewNoStackError("rewrite rule not found")
Expand Down
18 changes: 16 additions & 2 deletions pkg/restore/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,16 @@ func (importer *FileImporter) Import(file *backup.File, rewriteRules *RewriteRul
err1 = importer.ingestSST(downloadMeta, info)
// If error is `NotLeader`, update the region info and retry
for err1 == errNotLeader {
info, err1 = importer.metaClient.GetRegion(ctx, info.Region.GetStartKey())
var newInfo *RegionInfo
newInfo, err1 = importer.metaClient.GetRegion(ctx, info.Region.GetStartKey())
if err1 != nil {
break
}
err1 = importer.ingestSST(downloadMeta, info)
if !checkRegionEpoch(newInfo, info) {
err1 = errEpochNotMatch
break
}
err1 = importer.ingestSST(downloadMeta, newInfo)
}
if err1 != nil {
log.Error("ingest file failed",
Expand Down Expand Up @@ -308,6 +313,15 @@ func (importer *FileImporter) ingestSST(
return nil
}

func checkRegionEpoch(new, old *RegionInfo) bool {
if new.Region.GetId() == old.Region.GetId() &&
new.Region.GetRegionEpoch().GetVersion() == old.Region.GetRegionEpoch().GetVersion() &&
new.Region.GetRegionEpoch().GetConfVer() == old.Region.GetRegionEpoch().GetConfVer() {
return true
}
return false
}

func extractDownloadSSTError(e error) error {
err := errGrpc
switch {
Expand Down

0 comments on commit 985676b

Please sign in to comment.