Skip to content

Commit

Permalink
br: retry more time to get pd leader (#54059) (#54873)
Browse files Browse the repository at this point in the history
close #54017
  • Loading branch information
ti-chi-bot authored Jul 24, 2024
1 parent 406ffe9 commit 710538b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions br/pkg/backup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ go_library(
"//pkg/statistics/handle/util",
"//pkg/util",
"//pkg/util/codec",
"//pkg/util/mathutil",
"//pkg/util/ranger",
"//pkg/util/table-filter",
"@com_github_google_btree//:btree",
Expand Down
8 changes: 4 additions & 4 deletions br/pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/util"
"github.com/pingcap/tidb/pkg/util/codec"
"github.com/pingcap/tidb/pkg/util/mathutil"
"github.com/pingcap/tidb/pkg/util/ranger"
filter "github.com/pingcap/tidb/pkg/util/table-filter"
"github.com/tikv/client-go/v2/oracle"
Expand Down Expand Up @@ -1053,12 +1054,12 @@ func (bc *Client) findTargetPeer(ctx context.Context, key []byte, isRawKv bool,
// Keys are saved in encoded format in TiKV, so the key must be encoded
// in order to find the correct region.
key = codec.EncodeBytesExt([]byte{}, key, isRawKv)
for i := 0; i < 5; i++ {
for i := 1; i < 100; i++ {
// better backoff.
region, err := bc.mgr.GetPDClient().GetRegion(ctx, key)
if err != nil || region == nil {
logutil.CL(ctx).Error("find region failed", zap.Error(err), zap.Reflect("region", region))
time.Sleep(time.Millisecond * time.Duration(100*i))
time.Sleep(time.Millisecond * time.Duration(mathutil.Min(i*100, 3000)))
continue
}
if len(targetStoreIds) == 0 {
Expand All @@ -1081,9 +1082,8 @@ func (bc *Client) findTargetPeer(ctx context.Context, key []byte, isRawKv bool,
return peer, nil
}
}

logutil.CL(ctx).Warn("fail to find a target peer", logutil.Key("key", key))
time.Sleep(time.Millisecond * time.Duration(1000*i))
time.Sleep(time.Millisecond * time.Duration(mathutil.Min(i*100, 3000)))
continue
}
logutil.CL(ctx).Error("can not find a valid target peer", logutil.Key("key", key))
Expand Down

0 comments on commit 710538b

Please sign in to comment.