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

br: fix backoffer can't handle multierrs #54084

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion br/pkg/restore/log_client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ go_test(
],
embed = [":log_client"],
flaky = True,
shard_count = 38,
shard_count = 39,
deps = [
"//br/pkg/errors",
"//br/pkg/gluetidb",
Expand Down
22 changes: 22 additions & 0 deletions br/pkg/restore/log_client/import_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,25 @@ func TestPaginateScanLeader(t *testing.T) {
})
assertRegions(t, collectedRegions, "", "aay", "bba")
}

func TestRetryRecognizeErrCode(t *testing.T) {
waitTime := 1 * time.Millisecond
maxWaitTime := 16 * time.Millisecond
ctx := context.Background()
inner := 0
outer := 0
utils.WithRetry(ctx, func() error {
e := utils.WithRetry(ctx, func() error {
inner++
e := status.Error(codes.Unavailable, "the connection to TiKV has been cut by a neko, meow :3")
if e != nil {
return errors.Trace(e)
}
return nil
}, utils.NewBackoffer(10, waitTime, maxWaitTime, utils.NewErrorContext("download sst", 3)))
RidRisR marked this conversation as resolved.
Show resolved Hide resolved
outer++
return errors.Trace(e)
}, utils.NewBackoffer(10, waitTime, maxWaitTime, utils.NewErrorContext("import sst", 3)))
require.Equal(t, 10, outer)
require.Equal(t, 100, inner)
}
9 changes: 6 additions & 3 deletions br/pkg/utils/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/log"
berrors "github.com/pingcap/tidb/br/pkg/errors"
"go.uber.org/multierr"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -169,12 +170,14 @@ func NewBackupSSTBackoffer() Backoffer {

func (bo *importerBackoffer) NextBackoff(err error) time.Duration {
// we don't care storeID here.
res := bo.errContext.HandleErrorMsg(err.Error(), 0)
errs := multierr.Errors(err)
lastErr := errs[len(errs)-1]
res := bo.errContext.HandleErrorMsg(lastErr.Error(), 0)
if res.Strategy == RetryStrategy {
bo.delayTime = 2 * bo.delayTime
bo.attempt--
} else {
e := errors.Cause(err)
e := errors.Cause(lastErr)
switch e { // nolint:errorlint
case berrors.ErrKVEpochNotMatch, berrors.ErrKVDownloadFailed, berrors.ErrKVIngestFailed, berrors.ErrPDLeaderNotFound:
bo.delayTime = 2 * bo.delayTime
Expand All @@ -189,7 +192,7 @@ func (bo *importerBackoffer) NextBackoff(err error) time.Duration {
bo.delayTime = 2 * bo.delayTime
bo.attempt--
case codes.Canceled:
if isGRPCCancel(err) {
if isGRPCCancel(lastErr) {
bo.delayTime = 2 * bo.delayTime
bo.attempt--
} else {
Expand Down
Loading