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

*: independent the client option #8813

Merged
merged 1 commit into from
Nov 14, 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
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 @@
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 @@
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)

Check warning on line 73 in client/gc_client.go

View check run for this annotation

Codecov / codecov/patch

client/gc_client.go#L73

Added line #L73 was not covered by tests
req := &pdpb.UpdateServiceSafePointV2Request{
Header: c.requestHeader(),
KeyspaceId: keyspaceID,
Expand Down Expand Up @@ -99,7 +99,7 @@
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