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

Commit

Permalink
fix retry error
Browse files Browse the repository at this point in the history
Signed-off-by: 5kbpers <[email protected]>
  • Loading branch information
5kbpers committed Feb 11, 2020
1 parent 35e811b commit b4aef67
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/restore/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func newDownloadSSTBackoffer() utils.Backoffer {

func (bo *importerBackoffer) NextBackoff(err error) time.Duration {
switch errors.Cause(err) {
case errResp, errGrpc:
case errResp, errGrpc, errEpochNotMatch, errNotLeader:
bo.delayTime = 2 * bo.delayTime
bo.attempt--
case errRangeIsEmpty, errRewriteRuleNotFound:
Expand Down
16 changes: 8 additions & 8 deletions pkg/restore/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (importer *FileImporter) Import(file *backup.File, rewriteRules *RewriteRul
zap.Binary("startKey", startKey),
zap.Binary("endKey", endKey))
err = utils.WithRetry(importer.ctx, func() error {
ctx, cancel := context.WithTimeout(importer.ctx, importScanResgionTime)
ctx, cancel := context.WithTimeout(importer.ctx, importScanRegionTime)
defer cancel()
// Scan regions covered by the file range
regionInfos, err1 := importer.metaClient.ScanRegions(ctx, startKey, endKey, 0)
Expand Down Expand Up @@ -197,7 +197,7 @@ func (importer *FileImporter) Import(file *backup.File, rewriteRules *RewriteRul
log.Debug("ingest sst returns not leader error, retry it",
zap.Stringer("region", info.Region))
var newInfo *RegionInfo
newInfo, err1 = importer.metaClient.GetRegion(ctx, info.Region.GetStartKey())
newInfo, err1 = importer.metaClient.GetRegion(importer.ctx, info.Region.GetStartKey())
if err1 != nil {
break
}
Expand Down Expand Up @@ -271,7 +271,7 @@ func (importer *FileImporter) downloadSST(
return nil, extractDownloadSSTError(err)
}
if resp.GetIsEmpty() {
return nil, errRangeIsEmpty
return nil, errors.Trace(errRangeIsEmpty)
}
}
sstMeta.Range.Start = truncateTS(resp.Range.GetStart())
Expand Down Expand Up @@ -299,18 +299,18 @@ func (importer *FileImporter) ingestSST(
log.Debug("download SST", zap.Stringer("sstMeta", sstMeta))
resp, err := importer.importClient.IngestSST(importer.ctx, leader.GetStoreId(), req)
if err != nil {
return err
return errors.Trace(err)
}
respErr := resp.GetError()
if respErr != nil {
log.Debug("ingest sst resp error", zap.Stringer("error", respErr))
if respErr.GetKeyNotInRegion() != nil {
return errKeyNotInRegion
return errors.Trace(errKeyNotInRegion)
}
if respErr.GetNotLeader() != nil {
return errNotLeader
return errors.Trace(errNotLeader)
}
return errResp
return errors.Trace(errResp)
}
return nil
}
Expand All @@ -336,5 +336,5 @@ func extractDownloadSSTError(e error) error {
case strings.Contains(e.Error(), "Cannot read"):
err = errCannotRead
}
return err
return errors.Trace(err)
}

0 comments on commit b4aef67

Please sign in to comment.