Skip to content

Commit 53be550

Browse files
RidRisRti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#54084
Signed-off-by: ti-chi-bot <[email protected]>
1 parent b75a314 commit 53be550

File tree

3 files changed

+150
-3
lines changed

3 files changed

+150
-3
lines changed

br/pkg/restore/import_retry_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ func TestPaginateScanLeader(t *testing.T) {
427427
assertRegions(t, collectedRegions, "", "aay", "bba")
428428
}
429429

430+
<<<<<<< HEAD:br/pkg/restore/import_retry_test.go
430431
func TestImportKVFiles(t *testing.T) {
431432
var (
432433
importer = restore.FileImporter{}
@@ -596,4 +597,26 @@ func TestFilterFilesByRegion(t *testing.T) {
596597
require.Equal(t, err, c.err)
597598
require.Equal(t, subfile, c.subfiles)
598599
}
600+
=======
601+
func TestRetryRecognizeErrCode(t *testing.T) {
602+
waitTime := 1 * time.Millisecond
603+
maxWaitTime := 16 * time.Millisecond
604+
ctx := context.Background()
605+
inner := 0
606+
outer := 0
607+
utils.WithRetry(ctx, func() error {
608+
e := utils.WithRetry(ctx, func() error {
609+
inner++
610+
e := status.Error(codes.Unavailable, "the connection to TiKV has been cut by a neko, meow :3")
611+
if e != nil {
612+
return errors.Trace(e)
613+
}
614+
return nil
615+
}, utils.NewBackoffer(10, waitTime, maxWaitTime, utils.NewErrorContext("download sst", 3)))
616+
outer++
617+
return errors.Trace(e)
618+
}, utils.NewBackoffer(10, waitTime, maxWaitTime, utils.NewErrorContext("import sst", 3)))
619+
require.Equal(t, 10, outer)
620+
require.Equal(t, 100, inner)
621+
>>>>>>> c12bf3fa024 (br: fix backoffer can't handle multierrs (#54084)):br/pkg/restore/log_client/import_retry_test.go
599622
}

br/pkg/restore/log_client/BUILD.bazel

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
2+
3+
go_library(
4+
name = "log_client",
5+
srcs = [
6+
"client.go",
7+
"import.go",
8+
"import_retry.go",
9+
"log_file_manager.go",
10+
"log_file_map.go",
11+
],
12+
importpath = "github.com/pingcap/tidb/br/pkg/restore/log_client",
13+
visibility = ["//visibility:public"],
14+
deps = [
15+
"//br/pkg/checkpoint",
16+
"//br/pkg/checksum",
17+
"//br/pkg/conn",
18+
"//br/pkg/conn/util",
19+
"//br/pkg/errors",
20+
"//br/pkg/glue",
21+
"//br/pkg/logutil",
22+
"//br/pkg/metautil",
23+
"//br/pkg/restore",
24+
"//br/pkg/restore/ingestrec",
25+
"//br/pkg/restore/internal/import_client",
26+
"//br/pkg/restore/internal/log_split",
27+
"//br/pkg/restore/internal/rawkv",
28+
"//br/pkg/restore/split",
29+
"//br/pkg/restore/tiflashrec",
30+
"//br/pkg/restore/utils",
31+
"//br/pkg/storage",
32+
"//br/pkg/stream",
33+
"//br/pkg/summary",
34+
"//br/pkg/utils",
35+
"//br/pkg/utils/iter",
36+
"//br/pkg/version",
37+
"//pkg/ddl/util",
38+
"//pkg/domain",
39+
"//pkg/kv",
40+
"//pkg/meta",
41+
"//pkg/parser/model",
42+
"//pkg/util",
43+
"//pkg/util/codec",
44+
"//pkg/util/redact",
45+
"//pkg/util/table-filter",
46+
"@com_github_fatih_color//:color",
47+
"@com_github_opentracing_opentracing_go//:opentracing-go",
48+
"@com_github_pingcap_errors//:errors",
49+
"@com_github_pingcap_failpoint//:failpoint",
50+
"@com_github_pingcap_kvproto//pkg/brpb",
51+
"@com_github_pingcap_kvproto//pkg/errorpb",
52+
"@com_github_pingcap_kvproto//pkg/import_sstpb",
53+
"@com_github_pingcap_kvproto//pkg/kvrpcpb",
54+
"@com_github_pingcap_kvproto//pkg/metapb",
55+
"@com_github_pingcap_log//:log",
56+
"@com_github_tikv_client_go_v2//config",
57+
"@com_github_tikv_client_go_v2//kv",
58+
"@com_github_tikv_client_go_v2//util",
59+
"@com_github_tikv_pd_client//:client",
60+
"@com_github_tikv_pd_client//http",
61+
"@org_golang_google_grpc//codes",
62+
"@org_golang_google_grpc//keepalive",
63+
"@org_golang_google_grpc//status",
64+
"@org_golang_x_sync//errgroup",
65+
"@org_uber_go_multierr//:multierr",
66+
"@org_uber_go_zap//:zap",
67+
"@org_uber_go_zap//zapcore",
68+
],
69+
)
70+
71+
go_test(
72+
name = "log_client_test",
73+
timeout = "short",
74+
srcs = [
75+
"client_test.go",
76+
"export_test.go",
77+
"import_retry_test.go",
78+
"import_test.go",
79+
"log_file_manager_test.go",
80+
"log_file_map_test.go",
81+
"main_test.go",
82+
],
83+
embed = [":log_client"],
84+
flaky = True,
85+
shard_count = 39,
86+
deps = [
87+
"//br/pkg/errors",
88+
"//br/pkg/gluetidb",
89+
"//br/pkg/mock",
90+
"//br/pkg/restore/internal/import_client",
91+
"//br/pkg/restore/split",
92+
"//br/pkg/restore/utils",
93+
"//br/pkg/storage",
94+
"//br/pkg/stream",
95+
"//br/pkg/utils",
96+
"//br/pkg/utils/iter",
97+
"//br/pkg/utiltest",
98+
"//pkg/kv",
99+
"//pkg/store/pdtypes",
100+
"//pkg/tablecodec",
101+
"//pkg/testkit/testsetup",
102+
"//pkg/util/codec",
103+
"//pkg/util/table-filter",
104+
"@com_github_pingcap_errors//:errors",
105+
"@com_github_pingcap_failpoint//:failpoint",
106+
"@com_github_pingcap_kvproto//pkg/brpb",
107+
"@com_github_pingcap_kvproto//pkg/errorpb",
108+
"@com_github_pingcap_kvproto//pkg/import_sstpb",
109+
"@com_github_pingcap_kvproto//pkg/metapb",
110+
"@com_github_pingcap_kvproto//pkg/pdpb",
111+
"@com_github_pingcap_log//:log",
112+
"@com_github_stretchr_testify//require",
113+
"@com_github_tikv_pd_client//:client",
114+
"@org_golang_google_grpc//codes",
115+
"@org_golang_google_grpc//keepalive",
116+
"@org_golang_google_grpc//status",
117+
"@org_uber_go_goleak//:goleak",
118+
"@org_uber_go_zap//:zap",
119+
"@org_uber_go_zap//zapcore",
120+
],
121+
)

br/pkg/utils/backoff.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/pingcap/failpoint"
1414
"github.com/pingcap/log"
1515
berrors "github.com/pingcap/tidb/br/pkg/errors"
16+
"go.uber.org/multierr"
1617
"go.uber.org/zap"
1718
"google.golang.org/grpc/codes"
1819
"google.golang.org/grpc/status"
@@ -169,12 +170,14 @@ func NewBackupSSTBackoffer() Backoffer {
169170

170171
func (bo *importerBackoffer) NextBackoff(err error) time.Duration {
171172
// we don't care storeID here.
172-
res := bo.errContext.HandleErrorMsg(err.Error(), 0)
173+
errs := multierr.Errors(err)
174+
lastErr := errs[len(errs)-1]
175+
res := bo.errContext.HandleErrorMsg(lastErr.Error(), 0)
173176
if res.Strategy == RetryStrategy {
174177
bo.delayTime = 2 * bo.delayTime
175178
bo.attempt--
176179
} else {
177-
e := errors.Cause(err)
180+
e := errors.Cause(lastErr)
178181
switch e { // nolint:errorlint
179182
case berrors.ErrKVEpochNotMatch, berrors.ErrKVDownloadFailed, berrors.ErrKVIngestFailed, berrors.ErrPDLeaderNotFound:
180183
bo.delayTime = 2 * bo.delayTime
@@ -189,7 +192,7 @@ func (bo *importerBackoffer) NextBackoff(err error) time.Duration {
189192
bo.delayTime = 2 * bo.delayTime
190193
bo.attempt--
191194
case codes.Canceled:
192-
if isGRPCCancel(err) {
195+
if isGRPCCancel(lastErr) {
193196
bo.delayTime = 2 * bo.delayTime
194197
bo.attempt--
195198
} else {

0 commit comments

Comments
 (0)