Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tikv/pd into introduce-ca…
Browse files Browse the repository at this point in the history
…llerid-for-grpc

Signed-off-by: okJiang <[email protected]>
  • Loading branch information
okJiang committed Nov 15, 2024
2 parents 971f5c7 + c8c7551 commit 2a1fc44
Show file tree
Hide file tree
Showing 23 changed files with 345 additions and 327 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![Check Status](https://github.com/tikv/pd/actions/workflows/check.yaml/badge.svg)](https://github.com/tikv/pd/actions/workflows/check.yaml)
[![Build & Test Status](https://github.com/tikv/pd/actions/workflows/pd-tests.yaml/badge.svg?branch=master)](https://github.com/tikv/pd/actions/workflows/pd-tests.yaml)
[![TSO Consistency Test Status](https://github.com/tikv/pd/actions/workflows/tso-consistency-test.yaml/badge.svg)](https://github.com/tikv/pd/actions/workflows/tso-consistency-test.yaml)
[![GitHub release](https://img.shields.io/github/release/tikv/pd.svg)](https://github.com/tikv/pd/releases)
[![Go Report Card](https://goreportcard.com/badge/github.com/tikv/pd)](https://goreportcard.com/report/github.com/tikv/pd)
[![codecov](https://codecov.io/gh/tikv/pd/branch/master/graph/badge.svg)](https://codecov.io/gh/tikv/pd)
Expand Down
177 changes: 89 additions & 88 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 @@ -23,6 +23,7 @@ import (
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/stretchr/testify/require"
"github.com/tikv/pd/client/caller"
"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 @@ -56,7 +57,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 @@ -89,7 +90,7 @@ func TestClientWithRetry(t *testing.T) {
re := require.New(t)
start := time.Now()
_, err := NewClientWithContext(context.TODO(), caller.TestComponent,
[]string{testClientURL}, SecurityOption{}, WithMaxErrorRetry(5))
[]string{testClientURL}, SecurityOption{}, opt.WithMaxErrorRetry(5))
re.Error(err)
re.Less(time.Since(start), time.Second*10)
}
Expand All @@ -104,10 +105,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.inner.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.inner.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.inner.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.inner.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 @@ func (c *client) WatchGCSafePointV2(ctx context.Context, revision int64) (chan [
Revision: revision,
}

ctx, cancel := context.WithTimeout(ctx, c.inner.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.inner.option.Timeout)
defer cancel()
protoClient, ctx := c.getClientAndContext(ctx)
if protoClient == nil {
Expand Down
9 changes: 5 additions & 4 deletions client/inner_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/log"
"github.com/tikv/pd/client/errs"
"github.com/tikv/pd/client/opt"
"go.uber.org/zap"
"google.golang.org/grpc"
)
Expand All @@ -35,7 +36,7 @@ type innerClient struct {
cancel context.CancelFunc
wg sync.WaitGroup
tlsCfg *tls.Config
option *option
option *opt.Option
}

func (c *innerClient) init(updateKeyspaceIDCb updateKeyspaceIDFunc) error {
Expand All @@ -57,7 +58,7 @@ func (c *innerClient) setServiceMode(newMode pdpb.ServiceMode) {
c.Lock()
defer c.Unlock()

if c.option.useTSOServerProxy {
if c.option.UseTSOServerProxy {
// If we are using TSO server proxy, we always use PD_SVC_MODE.
newMode = pdpb.ServiceMode_PD_SVC_MODE
}

Check warning on line 64 in client/inner_client.go

View check run for this annotation

Codecov / codecov/patch

client/inner_client.go#L62-L64

Added lines #L62 - L64 were not covered by tests
Expand Down Expand Up @@ -158,8 +159,8 @@ func (c *innerClient) close() {

func (c *innerClient) setup() error {
// Init the metrics.
if c.option.initMetrics {
initAndRegisterMetrics(c.option.metricsLabels)
if c.option.InitMetrics {
initAndRegisterMetrics(c.option.MetricsLabels)
}

// Init the client base.
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.inner.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.inner.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.inner.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.inner.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.inner.option.timeout)
ctx, cancel := context.WithTimeout(ctx, c.inner.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 *innerClient) Put(ctx context.Context, key, value []byte, opts ...OpOpti
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 *innerClient) Get(ctx context.Context, key []byte, opts ...OpOption) (*m
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 2a1fc44

Please sign in to comment.