Skip to content

Commit

Permalink
*: independent the client option (#8813)
Browse files Browse the repository at this point in the history
ref #8690

Independent the client option to reduce the number of files under the client root directory.

Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato authored Nov 14, 2024
1 parent 40ae26c commit 71745a1
Show file tree
Hide file tree
Showing 21 changed files with 344 additions and 326 deletions.
185 changes: 93 additions & 92 deletions client/client.go

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/stretchr/testify/require"
"github.com/tikv/pd/client/opt"
"github.com/tikv/pd/client/utils/testutil"
"github.com/tikv/pd/client/utils/tsoutil"
"go.uber.org/goleak"
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestUpdateURLs(t *testing.T) {
}
return
}
cli := &pdServiceDiscovery{option: newOption()}
cli := &pdServiceDiscovery{option: opt.NewOption()}
cli.urls.Store([]string{})
cli.updateURLs(members[1:])
re.Equal(getURLs([]*pdpb.Member{members[1], members[3], members[2]}), cli.GetServiceURLs())
Expand Down Expand Up @@ -86,7 +87,7 @@ func TestClientCtx(t *testing.T) {
func TestClientWithRetry(t *testing.T) {
re := require.New(t)
start := time.Now()
_, err := NewClientWithContext(context.TODO(), []string{testClientURL}, SecurityOption{}, WithMaxErrorRetry(5))
_, err := NewClientWithContext(context.TODO(), []string{testClientURL}, SecurityOption{}, opt.WithMaxErrorRetry(5))
re.Error(err)
re.Less(time.Since(start), time.Second*10)
}
Expand All @@ -101,10 +102,10 @@ func TestGRPCDialOption(t *testing.T) {
ctx: ctx,
cancel: cancel,
tlsCfg: nil,
option: newOption(),
option: opt.NewOption(),
}
cli.urls.Store([]string{testClientURL})
cli.option.gRPCDialOptions = []grpc.DialOption{grpc.WithBlock()}
cli.option.GRPCDialOptions = []grpc.DialOption{grpc.WithBlock()}
err := cli.updateMember()
re.Error(err)
re.Greater(time.Since(start), 500*time.Millisecond)
Expand Down
6 changes: 3 additions & 3 deletions client/gc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c *client) UpdateGCSafePointV2(ctx context.Context, keyspaceID uint32, saf
start := time.Now()
defer func() { cmdDurationUpdateGCSafePointV2.Observe(time.Since(start).Seconds()) }()

ctx, cancel := context.WithTimeout(ctx, c.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.option.Timeout)
req := &pdpb.UpdateGCSafePointV2Request{
Header: c.requestHeader(),
KeyspaceId: keyspaceID,
Expand Down Expand Up @@ -70,7 +70,7 @@ func (c *client) UpdateServiceSafePointV2(ctx context.Context, keyspaceID uint32
start := time.Now()
defer func() { cmdDurationUpdateServiceSafePointV2.Observe(time.Since(start).Seconds()) }()

ctx, cancel := context.WithTimeout(ctx, c.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.option.Timeout)
req := &pdpb.UpdateServiceSafePointV2Request{
Header: c.requestHeader(),
KeyspaceId: keyspaceID,
Expand Down Expand Up @@ -99,7 +99,7 @@ func (c *client) WatchGCSafePointV2(ctx context.Context, revision int64) (chan [
Revision: revision,
}

ctx, cancel := context.WithTimeout(ctx, c.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.option.Timeout)
defer cancel()
protoClient, ctx := c.getClientAndContext(ctx)
if protoClient == nil {
Expand Down
6 changes: 3 additions & 3 deletions client/keyspace_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *client) LoadKeyspace(ctx context.Context, name string) (*keyspacepb.Key
}
start := time.Now()
defer func() { cmdDurationLoadKeyspace.Observe(time.Since(start).Seconds()) }()
ctx, cancel := context.WithTimeout(ctx, c.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.option.Timeout)
req := &keyspacepb.LoadKeyspaceRequest{
Header: c.requestHeader(),
Name: name,
Expand Down Expand Up @@ -96,7 +96,7 @@ func (c *client) UpdateKeyspaceState(ctx context.Context, id uint32, state keysp
}
start := time.Now()
defer func() { cmdDurationUpdateKeyspaceState.Observe(time.Since(start).Seconds()) }()
ctx, cancel := context.WithTimeout(ctx, c.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.option.Timeout)
req := &keyspacepb.UpdateKeyspaceStateRequest{
Header: c.requestHeader(),
Id: id,
Expand Down Expand Up @@ -140,7 +140,7 @@ func (c *client) GetAllKeyspaces(ctx context.Context, startID uint32, limit uint
}
start := time.Now()
defer func() { cmdDurationGetAllKeyspaces.Observe(time.Since(start).Seconds()) }()
ctx, cancel := context.WithTimeout(ctx, c.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.option.Timeout)
req := &keyspacepb.GetAllKeyspacesRequest{
Header: c.requestHeader(),
StartId: startID,
Expand Down
4 changes: 2 additions & 2 deletions client/meta_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *client) Put(ctx context.Context, key, value []byte, opts ...OpOption) (
start := time.Now()
defer func() { cmdDurationPut.Observe(time.Since(start).Seconds()) }()

ctx, cancel := context.WithTimeout(ctx, c.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.option.Timeout)
req := &meta_storagepb.PutRequest{
Key: key,
Value: value,
Expand Down Expand Up @@ -157,7 +157,7 @@ func (c *client) Get(ctx context.Context, key []byte, opts ...OpOption) (*meta_s
start := time.Now()
defer func() { cmdDurationGet.Observe(time.Since(start).Seconds()) }()

ctx, cancel := context.WithTimeout(ctx, c.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.option.Timeout)
req := &meta_storagepb.GetRequest{
Key: key,
RangeEnd: options.rangeEnd,
Expand Down
Loading

0 comments on commit 71745a1

Please sign in to comment.