Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to kvproto mster and handle feedback.
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Shi <binshi.bing@gmail.com>
binshi-bing committed May 11, 2023
1 parent 7655c80 commit bc659cd
Showing 17 changed files with 68 additions and 3,487 deletions.
4 changes: 1 addition & 3 deletions client/go.mod
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ require (
github.com/opentracing/opentracing-go v1.2.0
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00
github.com/pingcap/kvproto v0.0.0-20230426023724-d90a321b46be
github.com/pingcap/kvproto v0.0.0-20230511011722-6e0e8a7deaa1
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/prometheus/client_golang v1.11.1
github.com/stretchr/testify v1.8.2
@@ -39,5 +39,3 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/pingcap/kvproto => github.com/binshi-bing/kvproto v0.0.0-20230510010110-735e184fe7b2
4 changes: 2 additions & 2 deletions client/go.sum
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/binshi-bing/kvproto v0.0.0-20230510010110-735e184fe7b2 h1:83Lk7NcyZ8b+kwnA4JQNO5pU/KugoH4CddHGVmPTBHI=
github.com/binshi-bing/kvproto v0.0.0-20230510010110-735e184fe7b2/go.mod h1:guCyM5N+o+ru0TsoZ1hi9lDjUMs2sIBjW3ARTEpVbnk=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
@@ -84,6 +82,8 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c h1:xpW9bvK+HuuTm
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00 h1:C3N3itkduZXDZFh4N3vQ5HEtld3S+Y+StULhWVvumU0=
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00/go.mod h1:4qGtCB0QK0wBzKtFEGDhxXnSnbQApw1gc9siScUl8ew=
github.com/pingcap/kvproto v0.0.0-20230511011722-6e0e8a7deaa1 h1:VXQ6Du/nKZ9IQnI9NWMzKbftWu8NV5pQkSLKIRzzGN4=
github.com/pingcap/kvproto v0.0.0-20230511011722-6e0e8a7deaa1/go.mod h1:guCyM5N+o+ru0TsoZ1hi9lDjUMs2sIBjW3ARTEpVbnk=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
5 changes: 2 additions & 3 deletions client/tso_client.go
Original file line number Diff line number Diff line change
@@ -314,14 +314,13 @@ func (c *tsoClient) getMinTS(ctx context.Context) (physical, logical int64, err
// Check the results. The returned minimal timestamp is valid if all the conditions are met:
// 1. The number of responses is equal to the number of TSO servers/pods.
// 2. The number of keyspace groups asked is equal to the number of TSO servers/pods.
// 3. Every TSO server/pod returns the same total count of keyspace groups
// 3. The minimal timestamp is not zero.
var (
minTS *pdpb.Timestamp
keyspaceGroupsAsked uint32
)
if len(resps) != len(addrs) {
return 0, 0, errs.ErrClientGetMinTSO.FastGenByArgs("failed to get min ts from all tso servers/pods")
if len(resps) == 0 {
return 0, 0, errs.ErrClientGetMinTSO.FastGenByArgs("none of tso server/pod responded")
}
emptyTS := &pdpb.Timestamp{}
keyspaceGroupsTotal := resps[0].KeyspaceGroupsTotal
1 change: 1 addition & 0 deletions client/tsoutil/tsoutil.go
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ func AddLogical(logical, count int64, suffixBits uint32) int64 {
return logical + count<<suffixBits
}

// TSLessEqual returns true if (physical, logical) <= (thatPhysical, thatLogical).
func TSLessEqual(physical, logical, thatPhysical, thatLogical int64) bool {
if physical == thatPhysical {
return logical <= thatLogical
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ require (
github.com/pingcap/errcode v0.3.0
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00
github.com/pingcap/kvproto v0.0.0-20230426023724-d90a321b46be
github.com/pingcap/kvproto v0.0.0-20230511011722-6e0e8a7deaa1
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21
github.com/pingcap/tidb-dashboard v0.0.0-20230508075335-d6e0218addd5
@@ -204,5 +204,3 @@ replace google.golang.org/grpc v1.54.0 => google.golang.org/grpc v1.26.0
// kvproto at the same time. You can run `go mod tidy` to make it replaced with go-mod style specification.
// After the PR to kvproto is merged, remember to comment this out and run `go mod tidy`.
// replace github.com/pingcap/kvproto => github.com/$YourPrivateRepo $YourPrivateBranch

replace github.com/pingcap/kvproto => github.com/binshi-bing/kvproto v0.0.0-20230510010110-735e184fe7b2
869 changes: 10 additions & 859 deletions go.sum

Large diffs are not rendered by default.

33 changes: 15 additions & 18 deletions pkg/mcs/tso/server/grpc_service.go
Original file line number Diff line number Diff line change
@@ -158,15 +158,10 @@ func (s *Service) Tso(stream tsopb.TSO_TsoServer) error {
func (s *Service) FindGroupByKeyspaceID(
ctx context.Context, request *tsopb.FindGroupByKeyspaceIDRequest,
) (*tsopb.FindGroupByKeyspaceIDResponse, error) {
if s.IsClosed() || s.keyspaceGroupManager == nil {
return &tsopb.FindGroupByKeyspaceIDResponse{
Header: s.wrapErrorToHeader(tsopb.ErrorType_NOT_BOOTSTRAPPED, ErrNotStarted.Error(), 0),
}, nil
}

if request.GetHeader().GetClusterId() != s.clusterID {
respKeyspaceGroup := request.GetHeader().GetKeyspaceGroupId()
if errorType, err := s.validRequest(request.GetHeader()); err != nil {
return &tsopb.FindGroupByKeyspaceIDResponse{
Header: s.wrapErrorToHeader(tsopb.ErrorType_CLUSTER_MISMATCHED, ErrClusterMismatched.Error(), 0),
Header: s.wrapErrorToHeader(errorType, err.Error(), respKeyspaceGroup),
}, nil
}

@@ -218,17 +213,9 @@ func (s *Service) GetMinTS(
ctx context.Context, request *tsopb.GetMinTSRequest,
) (*tsopb.GetMinTSResponse, error) {
respKeyspaceGroup := request.GetHeader().GetKeyspaceGroupId()
if s.IsClosed() || s.keyspaceGroupManager == nil {
return &tsopb.GetMinTSResponse{
Header: s.wrapErrorToHeader(
tsopb.ErrorType_NOT_BOOTSTRAPPED, ErrNotStarted.Error(), respKeyspaceGroup),
}, nil
}

if request.GetHeader().GetClusterId() != s.clusterID {
if errorType, err := s.validRequest(request.GetHeader()); err != nil {
return &tsopb.GetMinTSResponse{
Header: s.wrapErrorToHeader(
tsopb.ErrorType_CLUSTER_MISMATCHED, ErrClusterMismatched.Error(), respKeyspaceGroup),
Header: s.wrapErrorToHeader(errorType, err.Error(), respKeyspaceGroup),
}, nil
}

@@ -251,6 +238,16 @@ func (s *Service) GetMinTS(
}, nil
}

func (s *Service) validRequest(header *tsopb.RequestHeader) (tsopb.ErrorType, error) {
if s.IsClosed() || s.keyspaceGroupManager == nil {
return tsopb.ErrorType_NOT_BOOTSTRAPPED, ErrNotStarted
}
if header == nil || header.GetClusterId() != s.clusterID {
return tsopb.ErrorType_CLUSTER_MISMATCHED, ErrClusterMismatched
}
return tsopb.ErrorType_OK, nil
}

func (s *Service) header(keyspaceGroupBelongTo uint32) *tsopb.ResponseHeader {
if s.clusterID == 0 {
return s.wrapErrorToHeader(
4 changes: 1 addition & 3 deletions tests/integrations/client/go.mod
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ replace google.golang.org/grpc v1.54.0 => google.golang.org/grpc v1.26.0
require (
github.com/docker/go-units v0.4.0
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00
github.com/pingcap/kvproto v0.0.0-20230426023724-d90a321b46be
github.com/pingcap/kvproto v0.0.0-20230511011722-6e0e8a7deaa1
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/stretchr/testify v1.8.2
github.com/tikv/pd v0.0.0-00010101000000-000000000000
@@ -181,5 +181,3 @@ require (
moul.io/zapgorm2 v1.1.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace github.com/pingcap/kvproto => github.com/binshi-bing/kvproto v0.0.0-20230510010110-735e184fe7b2
872 changes: 10 additions & 862 deletions tests/integrations/client/go.sum

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions tests/integrations/mcs/go.mod
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ replace google.golang.org/grpc v1.54.0 => google.golang.org/grpc v1.26.0

require (
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00
github.com/pingcap/kvproto v0.0.0-20230426023724-d90a321b46be
github.com/pingcap/kvproto v0.0.0-20230511011722-6e0e8a7deaa1
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.2
@@ -181,5 +181,3 @@ require (
moul.io/zapgorm2 v1.1.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace github.com/pingcap/kvproto => github.com/binshi-bing/kvproto v0.0.0-20230510010110-735e184fe7b2
872 changes: 10 additions & 862 deletions tests/integrations/mcs/go.sum

Large diffs are not rendered by default.

Binary file added tests/integrations/tso/__debug_bin
Binary file not shown.
1 change: 1 addition & 0 deletions tests/integrations/tso/client_test.go
Original file line number Diff line number Diff line change
@@ -197,6 +197,7 @@ func (suite *tsoClientTestSuite) TestGetTSAsync() {
wg.Wait()
}

// TestGetMinTS tests the correctness of GetMinTS.
func (suite *tsoClientTestSuite) TestGetMinTS() {
var wg sync.WaitGroup
wg.Add(tsoRequestConcurrencyNumber * len(suite.clients))
4 changes: 1 addition & 3 deletions tests/integrations/tso/go.mod
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ replace google.golang.org/grpc v1.54.0 => google.golang.org/grpc v1.26.0

require (
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00
github.com/pingcap/kvproto v0.0.0-20230426023724-d90a321b46be
github.com/pingcap/kvproto v0.0.0-20230511011722-6e0e8a7deaa1
github.com/stretchr/testify v1.8.2
github.com/tikv/pd v0.0.0-00010101000000-000000000000
github.com/tikv/pd/client v0.0.0-00010101000000-000000000000
@@ -182,5 +182,3 @@ require (
moul.io/zapgorm2 v1.1.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace github.com/pingcap/kvproto => github.com/binshi-bing/kvproto v0.0.0-20230510010110-735e184fe7b2
872 changes: 10 additions & 862 deletions tests/integrations/tso/go.sum

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions tools/pd-tso-bench/go.mod
Original file line number Diff line number Diff line change
@@ -12,5 +12,3 @@ require (
)

replace github.com/tikv/pd/client => ../../client

replace github.com/pingcap/kvproto => github.com/binshi-bing/kvproto v0.0.0-20230510010110-735e184fe7b2
4 changes: 2 additions & 2 deletions tools/pd-tso-bench/go.sum
Original file line number Diff line number Diff line change
@@ -619,8 +619,6 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/binshi-bing/kvproto v0.0.0-20230510010110-735e184fe7b2 h1:83Lk7NcyZ8b+kwnA4JQNO5pU/KugoH4CddHGVmPTBHI=
github.com/binshi-bing/kvproto v0.0.0-20230510010110-735e184fe7b2/go.mod h1:guCyM5N+o+ru0TsoZ1hi9lDjUMs2sIBjW3ARTEpVbnk=
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -853,6 +851,8 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c h1:xpW9bvK+HuuTm
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00 h1:C3N3itkduZXDZFh4N3vQ5HEtld3S+Y+StULhWVvumU0=
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00/go.mod h1:4qGtCB0QK0wBzKtFEGDhxXnSnbQApw1gc9siScUl8ew=
github.com/pingcap/kvproto v0.0.0-20230511011722-6e0e8a7deaa1 h1:VXQ6Du/nKZ9IQnI9NWMzKbftWu8NV5pQkSLKIRzzGN4=
github.com/pingcap/kvproto v0.0.0-20230511011722-6e0e8a7deaa1/go.mod h1:guCyM5N+o+ru0TsoZ1hi9lDjUMs2sIBjW3ARTEpVbnk=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw=
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=

0 comments on commit bc659cd

Please sign in to comment.