Skip to content

Commit 449ec91

Browse files
committed
update client-go to 7.5-cse
Signed-off-by: disksing <i@disksing.com>
1 parent 899e5cc commit 449ec91

File tree

43 files changed

+481
-257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+481
-257
lines changed

br/pkg/backup/prepare_snap/env.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"github.com/pingcap/tidb/br/pkg/utils"
3030
"github.com/pingcap/tidb/pkg/util/engine"
3131
"github.com/tikv/client-go/v2/tikv"
32-
pd "github.com/tikv/pd/client"
32+
"github.com/tikv/pd/client/opt"
3333
"go.uber.org/zap"
3434
"google.golang.org/grpc"
3535
)
@@ -103,7 +103,7 @@ type CliEnv struct {
103103
}
104104

105105
func (c CliEnv) GetAllLiveStores(ctx context.Context) ([]*metapb.Store, error) {
106-
stores, err := c.Cache.PDClient().GetAllStores(ctx, pd.WithExcludeTombstone())
106+
stores, err := c.Cache.PDClient().GetAllStores(ctx, opt.WithExcludeTombstone())
107107
if err != nil {
108108
return nil, err
109109
}

br/pkg/backup/prepare_snap/prepare_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func (m *mockStores) AssertIsNormalMode(t *testing.T) {
264264

265265
func fakeCluster(t *testing.T, nodes int, keys ...[]byte) pd.Client {
266266
tmp := t.TempDir()
267-
_, pdc, cluster, err := unistore.New(tmp)
267+
_, pdc, cluster, err := unistore.New(tmp, nil)
268268
unistore.BootstrapWithMultiStores(cluster, nodes)
269269
require.NoError(t, err)
270270
cluster.SplitArbitrary(keys...)

br/pkg/conn/util/util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/pingcap/kvproto/pkg/metapb"
1010
berrors "github.com/pingcap/tidb/br/pkg/errors"
1111
"github.com/pingcap/tidb/pkg/util/engine"
12-
pd "github.com/tikv/pd/client"
12+
"github.com/tikv/pd/client/opt"
1313
)
1414

1515
// StoreBehavior is the action to do in GetAllTiKVStores when a non-TiKV
@@ -34,7 +34,7 @@ type StoreMeta interface {
3434
// GetAllStores gets all stores from pd.
3535
// The store may expire later. Caller is responsible for caching and taking care
3636
// of store change.
37-
GetAllStores(ctx context.Context, opts ...pd.GetStoreOption) ([]*metapb.Store, error)
37+
GetAllStores(ctx context.Context, opts ...opt.GetStoreOption) ([]*metapb.Store, error)
3838
}
3939

4040
// GetAllTiKVStores returns all TiKV stores registered to the PD client. The
@@ -45,7 +45,7 @@ func GetAllTiKVStores(
4545
storeBehavior StoreBehavior,
4646
) ([]*metapb.Store, error) {
4747
// get all live stores.
48-
stores, err := pdClient.GetAllStores(ctx, pd.WithExcludeTombstone())
48+
stores, err := pdClient.GetAllStores(ctx, opt.WithExcludeTombstone())
4949
if err != nil {
5050
return nil, errors.Trace(err)
5151
}

br/pkg/lightning/backend/local/checksum.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
tikvstore "github.com/tikv/client-go/v2/kv"
3939
"github.com/tikv/client-go/v2/oracle"
4040
pd "github.com/tikv/pd/client"
41+
pderrs "github.com/tikv/pd/client/errs"
4142
"go.uber.org/atomic"
4243
"go.uber.org/zap"
4344
)
@@ -351,7 +352,7 @@ func (e *TiKVChecksumManager) Checksum(ctx context.Context, tableInfo *checkpoin
351352
)
352353
physicalTS, logicalTS, err = e.manager.pdClient.GetTS(ctx)
353354
for err != nil {
354-
if !pd.IsLeaderChange(errors.Cause(err)) {
355+
if !pderrs.IsLeaderChange(errors.Cause(err)) {
355356
return nil, errors.Annotate(err, "fetch tso from pd failed")
356357
}
357358
retryTime++

br/pkg/lightning/backend/local/local.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import (
6666
"github.com/tikv/client-go/v2/oracle"
6767
tikvclient "github.com/tikv/client-go/v2/tikv"
6868
pd "github.com/tikv/pd/client"
69+
"github.com/tikv/pd/client/opt"
6970
"go.uber.org/atomic"
7071
"go.uber.org/zap"
7172
"golang.org/x/sync/errgroup"
@@ -305,10 +306,10 @@ func (g *targetInfoGetter) CheckRequirements(ctx context.Context, checkCtx *back
305306
if err := checkTiDBVersion(ctx, versionStr, localMinTiDBVersion, localMaxTiDBVersion); err != nil {
306307
return err
307308
}
308-
if err := tikv.CheckPDVersion(ctx, g.tls, g.pdCli.GetLeaderAddr(), localMinPDVersion, localMaxPDVersion); err != nil {
309+
if err := tikv.CheckPDVersion(ctx, g.tls, g.pdCli.GetLeaderURL(), localMinPDVersion, localMaxPDVersion); err != nil {
309310
return err
310311
}
311-
if err := tikv.CheckTiKVVersion(ctx, g.tls, g.pdCli.GetLeaderAddr(), localMinTiKVVersion, localMaxTiKVVersion); err != nil {
312+
if err := tikv.CheckTiKVVersion(ctx, g.tls, g.pdCli.GetLeaderURL(), localMinTiKVVersion, localMaxTiKVVersion); err != nil {
312313
return err
313314
}
314315

@@ -700,7 +701,7 @@ func (local *Backend) TotalMemoryConsume() int64 {
700701
}
701702

702703
func checkMultiIngestSupport(ctx context.Context, pdCtl *pdutil.PdController, importClientFactory ImportClientFactory) (bool, error) {
703-
stores, err := pdCtl.GetPDClient().GetAllStores(ctx, pd.WithExcludeTombstone())
704+
stores, err := pdCtl.GetPDClient().GetAllStores(ctx, opt.WithExcludeTombstone())
704705
if err != nil {
705706
return false, errors.Trace(err)
706707
}
@@ -2056,7 +2057,7 @@ func getSplitConfFromStore(ctx context.Context, host string, tls *common.TLS) (
20562057
// GetRegionSplitSizeKeys return region split size, region split keys, error
20572058
func GetRegionSplitSizeKeys(ctx context.Context, cli pd.Client, tls *common.TLS) (
20582059
regionSplitSize int64, regionSplitKeys int64, err error) {
2059-
stores, err := cli.GetAllStores(ctx, pd.WithExcludeTombstone())
2060+
stores, err := cli.GetAllStores(ctx, opt.WithExcludeTombstone())
20602061
if err != nil {
20612062
return 0, 0, err
20622063
}

br/pkg/lightning/backend/local/local_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ import (
6060
"github.com/pingcap/tidb/pkg/util/hack"
6161
"github.com/stretchr/testify/require"
6262
pd "github.com/tikv/pd/client"
63+
"github.com/tikv/pd/client/clients/router"
64+
"github.com/tikv/pd/client/opt"
6365
"google.golang.org/grpc"
6466
"google.golang.org/grpc/codes"
6567
"google.golang.org/grpc/encoding"
@@ -664,11 +666,11 @@ type mockPdClient struct {
664666
regions []*pd.Region
665667
}
666668

667-
func (c *mockPdClient) GetAllStores(ctx context.Context, opts ...pd.GetStoreOption) ([]*metapb.Store, error) {
669+
func (c *mockPdClient) GetAllStores(ctx context.Context, opts ...opt.GetStoreOption) ([]*metapb.Store, error) {
668670
return c.stores, nil
669671
}
670672

671-
func (c *mockPdClient) ScanRegions(ctx context.Context, key, endKey []byte, limit int) ([]*pd.Region, error) {
673+
func (c *mockPdClient) ScanRegions(ctx context.Context, key, endKey []byte, limit int, _ ...opt.GetRegionOption) ([]*router.Region, error) {
672674
return c.regions, nil
673675
}
674676

br/pkg/lightning/backend/local/localhelper_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/pingcap/tidb/pkg/types"
3939
"github.com/pingcap/tidb/pkg/util/codec"
4040
"github.com/stretchr/testify/require"
41+
"github.com/tikv/pd/client/opt"
4142
"go.uber.org/atomic"
4243
)
4344

@@ -250,7 +251,7 @@ func (c *testSplitClient) GetOperator(ctx context.Context, regionID uint64) (*pd
250251
}, nil
251252
}
252253

253-
func (c *testSplitClient) ScanRegions(ctx context.Context, key, endKey []byte, limit int) ([]*split.RegionInfo, error) {
254+
func (c *testSplitClient) ScanRegions(ctx context.Context, key, endKey []byte, limit int, _ ...opt.GetRegionOption) ([]*split.RegionInfo, error) {
254255
c.mu.Lock()
255256
defer c.mu.Unlock()
256257

br/pkg/lightning/backend/local/tikv_mode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (rc *switcher) switchTiKVMode(ctx context.Context, mode sstpb.SwitchMode, r
6969
} else {
7070
minState = tikv.StoreStateDisconnected
7171
}
72-
tls := rc.tls.WithHost(rc.pdCli.GetLeaderAddr())
72+
tls := rc.tls.WithHost(rc.pdCli.GetLeaderURL())
7373
// we ignore switch mode failure since it is not fatal.
7474
// no need log the error, it is done in kv.SwitchMode already.
7575
_ = tikv.ForAllStores(

br/pkg/pdutil/pd.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import (
3232
"github.com/pingcap/tidb/pkg/store/pdtypes"
3333
"github.com/pingcap/tidb/pkg/util/codec"
3434
pd "github.com/tikv/pd/client"
35+
"github.com/tikv/pd/client/opt"
36+
"github.com/tikv/pd/client/pkg/caller"
3537
"go.uber.org/zap"
3638
"google.golang.org/grpc"
3739
)
@@ -301,12 +303,12 @@ func NewPdController(
301303
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(maxMsgSize)),
302304
}
303305
pdClient, err := pd.NewClientWithContext(
304-
ctx, addrs, securityOption,
305-
pd.WithGRPCDialOptions(maxCallMsgSize...),
306+
ctx, caller.Component("br"), addrs, securityOption,
307+
opt.WithGRPCDialOptions(maxCallMsgSize...),
306308
// If the time too short, we may scatter a region many times, because
307309
// the interface `ScatterRegions` may time out.
308-
pd.WithCustomTimeoutOption(60*time.Second),
309-
pd.WithMaxErrorRetry(3),
310+
opt.WithCustomTimeoutOption(60*time.Second),
311+
opt.WithMaxErrorRetry(3),
310312
)
311313
if err != nil {
312314
log.Error("fail to create pd client", zap.Error(err))
@@ -348,7 +350,7 @@ func parseVersion(versionBytes []byte) *semver.Version {
348350
func (p *PdController) getAllPDAddrs() []string {
349351
ret := make([]string, 0, len(p.addrs)+1)
350352
if p.pdClient != nil {
351-
ret = append(ret, p.pdClient.GetLeaderAddr())
353+
ret = append(ret, p.pdClient.GetLeaderURL())
352354
}
353355
ret = append(ret, p.addrs...)
354356
return ret

br/pkg/restore/rawkv_client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/pingcap/tidb/pkg/util/hack"
1111
"github.com/tikv/client-go/v2/config"
1212
"github.com/tikv/client-go/v2/rawkv"
13-
pd "github.com/tikv/pd/client"
13+
"github.com/tikv/pd/client/opt"
1414
)
1515

1616
// RawkvClient is the interface for rawkv.client
@@ -28,8 +28,8 @@ func NewRawkvClient(ctx context.Context, pdAddrs []string, security config.Secur
2828
ctx,
2929
pdAddrs,
3030
security,
31-
pd.WithCustomTimeoutOption(10*time.Second),
32-
pd.WithMaxErrorRetry(5))
31+
opt.WithCustomTimeoutOption(10*time.Second),
32+
opt.WithMaxErrorRetry(5))
3333
}
3434

3535
type KVPair struct {

0 commit comments

Comments
 (0)