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

Commit

Permalink
[cherry-pick] restore: fix failed to retry grpc errors(tidb#27423) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
YuJuncen authored Dec 20, 2021
1 parent 809bb35 commit a135dc5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/restore/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ func (importer *FileImporter) Import(
log.Debug("failpoint download-sst-error injected.", zap.String("msg", msg))
e = errors.Annotate(e, msg)
})
failpoint.Inject("restore-gRPC-error", func(_ failpoint.Value) {
log.Warn("the connection to TiKV has been cut by a neko, meow :3")
e = status.Error(codes.Unavailable, "the connection to TiKV has been cut by a neko, meow :3")
})
if e != nil {
remainFiles = remainFiles[i:]
return errors.Trace(e)
Expand Down
5 changes: 3 additions & 2 deletions pkg/utils/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func (bo *importerBackoffer) NextBackoff(err error) time.Duration {
bo.delayTime = 2 * bo.delayTime
bo.attempt--
} else {
switch errors.Cause(err) { // nolint:errorlint
e := errors.Cause(err)
switch e { // nolint:errorlint
case berrors.ErrKVEpochNotMatch, berrors.ErrKVDownloadFailed, berrors.ErrKVIngestFailed:
bo.delayTime = 2 * bo.delayTime
bo.attempt--
Expand All @@ -68,7 +69,7 @@ func (bo *importerBackoffer) NextBackoff(err error) time.Duration {
bo.delayTime = 0
bo.attempt = 0
default:
switch status.Code(err) {
switch status.Code(e) {
case codes.Unavailable, codes.Aborted:
bo.delayTime = 2 * bo.delayTime
bo.attempt--
Expand Down
2 changes: 1 addition & 1 deletion tests/br_full/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ for ct in limit lz4 zstd; do

# restore full
echo "restore with $ct backup start..."
export GO_FAILPOINTS="github.com/pingcap/br/pkg/restore/restore-storage-error=1*return(\"connection refused\")"
export GO_FAILPOINTS="github.com/pingcap/br/pkg/restore/restore-storage-error=1*return(\"connection refused\");github.com/pingcap/br/pkg/restore/restore-gRPC-error=1*return(true)"
run_br restore full -s "local://$TEST_DIR/$DB-$ct" --pd $PD_ADDR --ratelimit 1024
export GO_FAILPOINTS=""

Expand Down

0 comments on commit a135dc5

Please sign in to comment.