Skip to content

Commit b85493a

Browse files
client: Remove public v2 client and redirect call to v2 internally if keyspace is configured (#9468)
close #8978 client: Remove public v2 client and redirect call to v2 internally if keyspace is configured Removes the GC V2 related public APIs from PD client to avoid being used by new code. This is a temporary approach, and #9292 will give a complete deprecation. Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
1 parent 9ca7953 commit b85493a

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

client/client.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ type RPCClient interface {
7474
// determine the safepoint for multiple services, it does not trigger a GC
7575
// job. Use UpdateGCSafePoint to trigger the GC job if needed.
7676
UpdateServiceGCSafePoint(ctx context.Context, serviceID string, ttl int64, safePoint uint64) (uint64, error)
77-
UpdateGCSafePointV2(ctx context.Context, keyspaceID uint32, safePoint uint64) (uint64, error)
78-
UpdateServiceSafePointV2(ctx context.Context, keyspaceID uint32, serviceID string, ttl int64, safePoint uint64) (uint64, error)
77+
// Deprecated: Avoid using this API.
7978
WatchGCSafePointV2(ctx context.Context, revision int64) (chan []*pdpb.SafePointEvent, error)
8079
// ScatterRegion scatters the specified region. Should use it for a batch of regions,
8180
// and the distribution of these regions will be dispersed.
@@ -1035,6 +1034,10 @@ func (c *client) GetAllStores(ctx context.Context, opts ...opt.GetStoreOption) (
10351034

10361035
// UpdateGCSafePoint implements the RPCClient interface.
10371036
func (c *client) UpdateGCSafePoint(ctx context.Context, safePoint uint64) (uint64, error) {
1037+
if c.inner.keyspaceID != constants.NullKeyspaceID {
1038+
return c.updateGCSafePointV2(ctx, c.inner.keyspaceID, safePoint)
1039+
}
1040+
10381041
if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
10391042
span = span.Tracer().StartSpan("pdclient.UpdateGCSafePoint", opentracing.ChildOf(span.Context()))
10401043
defer span.Finish()
@@ -1065,6 +1068,10 @@ func (c *client) UpdateGCSafePoint(ctx context.Context, safePoint uint64) (uint6
10651068
// determine the safepoint for multiple services, it does not trigger a GC
10661069
// job. Use UpdateGCSafePoint to trigger the GC job if needed.
10671070
func (c *client) UpdateServiceGCSafePoint(ctx context.Context, serviceID string, ttl int64, safePoint uint64) (uint64, error) {
1071+
if c.inner.keyspaceID != constants.NullKeyspaceID {
1072+
return c.updateServiceSafePointV2(ctx, c.inner.keyspaceID, serviceID, ttl, safePoint)
1073+
}
1074+
10681075
if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
10691076
span = span.Tracer().StartSpan("pdclient.UpdateServiceGCSafePoint", opentracing.ChildOf(span.Context()))
10701077
defer span.Finish()

client/gc_client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import (
3232
"github.com/tikv/pd/client/metrics"
3333
)
3434

35-
// UpdateGCSafePointV2 update gc safe point for the given keyspace.
36-
func (c *client) UpdateGCSafePointV2(ctx context.Context, keyspaceID uint32, safePoint uint64) (uint64, error) {
35+
// updateGCSafePointV2 update gc safe point for the given keyspace.
36+
func (c *client) updateGCSafePointV2(ctx context.Context, keyspaceID uint32, safePoint uint64) (uint64, error) {
3737
if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
3838
span = span.Tracer().StartSpan("pdclient.UpdateGCSafePointV2", opentracing.ChildOf(span.Context()))
3939
defer span.Finish()
@@ -61,8 +61,8 @@ func (c *client) UpdateGCSafePointV2(ctx context.Context, keyspaceID uint32, saf
6161
return resp.GetNewSafePoint(), nil
6262
}
6363

64-
// UpdateServiceSafePointV2 update service safe point for the given keyspace.
65-
func (c *client) UpdateServiceSafePointV2(ctx context.Context, keyspaceID uint32, serviceID string, ttl int64, safePoint uint64) (uint64, error) {
64+
// updateServiceSafePointV2 update service safe point for the given keyspace.
65+
func (c *client) updateServiceSafePointV2(ctx context.Context, keyspaceID uint32, serviceID string, ttl int64, safePoint uint64) (uint64, error) {
6666
if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
6767
span = span.Tracer().StartSpan("pdclient.UpdateServiceSafePointV2", opentracing.ChildOf(span.Context()))
6868
defer span.Finish()

tests/integrations/client/gc_api_v2_client_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (suite *gcClientTestSuite) testClientWatchWithRevision(fromNewRevision bool
163163
if fromNewRevision {
164164
startRevision = updatedRevision
165165
}
166-
watchChan, err := suite.client.WatchGCSafePointV2(suite.server.Context(), startRevision)
166+
watchChan, err := suite.client.WatchGCSafePointV2(suite.server.Context(), startRevision) //nolint:staticcheck
167167
re.NoError(err)
168168

169169
timer := time.NewTimer(time.Second)
@@ -196,7 +196,14 @@ func (suite *gcClientTestSuite) testClientWatchWithRevision(fromNewRevision bool
196196

197197
// mustUpdateSafePoint updates the gc safe point of the given keyspace id.
198198
func (suite *gcClientTestSuite) mustUpdateSafePoint(re *require.Assertions, keyspaceID uint32, safePoint uint64) {
199-
_, err := suite.client.UpdateGCSafePointV2(suite.server.Context(), keyspaceID, safePoint)
199+
client, err := pd.NewClientWithKeyspace(suite.server.Context(),
200+
caller.TestComponent,
201+
keyspaceID,
202+
[]string{suite.server.GetAddr()},
203+
pd.SecurityOption{},
204+
)
205+
re.NoError(err)
206+
_, err = client.UpdateGCSafePoint(suite.server.Context(), safePoint)
200207
re.NoError(err)
201208
}
202209

0 commit comments

Comments
 (0)