From 7666ee9bc07eb0bbd409ca60909deef4c998ddd3 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Fri, 20 Sep 2024 11:50:43 +0800 Subject: [PATCH] fix lint Signed-off-by: Ryan Leung --- .golangci.yml | 4 ++- Makefile | 2 +- client/client.go | 4 +-- client/resource_manager_client.go | 2 +- go.mod | 2 +- go.sum | 5 ++-- pkg/gc/safepoint.go | 4 +-- pkg/mcs/tso/server/grpc_service.go | 2 +- pkg/schedule/filter/candidates_test.go | 2 +- .../unsafe_recovery_controller_test.go | 26 +++++++++---------- pkg/utils/reflectutil/tag.go | 4 +-- pkg/window/policy_test.go | 4 +-- server/api/pprof.go | 2 +- server/api/store_test.go | 2 +- server/forward.go | 2 +- server/grpc_service.go | 2 +- tests/integrations/client/client_test.go | 6 ++--- tests/integrations/go.mod | 2 +- tests/integrations/go.sum | 5 ++-- tests/integrations/tso/testutil.go | 2 +- tests/server/tso/common_test.go | 2 +- tests/tso_cluster.go | 3 ++- tools/go.mod | 2 +- tools/go.sum | 5 ++-- tools/pd-api-bench/config/config.go | 3 --- tools/pd-api-bench/main.go | 3 --- 26 files changed, 51 insertions(+), 51 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index e5b5fe1ab565..ddca6d63d2a9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -15,7 +15,7 @@ linters: - gofmt - revive - errcheck - - exportloopref + - copyloopvar - goimports - depguard linters-settings: @@ -32,6 +32,8 @@ linters-settings: excludes: - G402 - G404 + # TODO: enable G115 after fixing the issues + - G115 testifylint: enable: - bool-compare diff --git a/Makefile b/Makefile index 0cba7051a299..4831997bb3c8 100644 --- a/Makefile +++ b/Makefile @@ -170,7 +170,7 @@ SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash) install-tools: @mkdir -p $(GO_TOOLS_BIN_PATH) - @which golangci-lint >/dev/null 2>&1 || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_TOOLS_BIN_PATH) v1.56.2 + @which golangci-lint >/dev/null 2>&1 || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_TOOLS_BIN_PATH) v1.60.3 @grep '_' tools.go | sed 's/"//g' | awk '{print $$2}' | xargs go install .PHONY: install-tools diff --git a/client/client.go b/client/client.go index d5cf7cf28d00..0c590c96f31c 100644 --- a/client/client.go +++ b/client/client.go @@ -1699,7 +1699,7 @@ func (c *client) GetExternalTimestamp(ctx context.Context) (uint64, error) { } resErr := resp.GetHeader().GetError() if resErr != nil { - return 0, errors.Errorf("[pd]" + resErr.Message) + return 0, errors.New("[pd]" + resErr.Message) } return resp.GetTimestamp(), nil } @@ -1721,7 +1721,7 @@ func (c *client) SetExternalTimestamp(ctx context.Context, timestamp uint64) err } resErr := resp.GetHeader().GetError() if resErr != nil { - return errors.Errorf("[pd]" + resErr.Message) + return errors.New("[pd]" + resErr.Message) } return nil } diff --git a/client/resource_manager_client.go b/client/resource_manager_client.go index 45182c07d3a4..11e798a89fbe 100644 --- a/client/resource_manager_client.go +++ b/client/resource_manager_client.go @@ -198,7 +198,7 @@ func (c *client) LoadResourceGroups(ctx context.Context) ([]*rmpb.ResourceGroup, return nil, 0, err } if resp.Header.Error != nil { - return nil, resp.Header.Revision, errors.Errorf(resp.Header.Error.Message) + return nil, resp.Header.Revision, errors.New(resp.Header.Error.Message) } groups := make([]*rmpb.ResourceGroup, 0, len(resp.Kvs)) for _, item := range resp.Kvs { diff --git a/go.mod b/go.mod index ec9441d3d506..eac4639b1496 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,7 @@ require ( github.com/pingcap/tidb-dashboard v0.0.0-20240830080600-3d0c3db0d55c github.com/prometheus/client_golang v1.19.0 github.com/prometheus/common v0.51.1 - github.com/sasha-s/go-deadlock v0.2.0 + github.com/sasha-s/go-deadlock v0.3.3 github.com/shirou/gopsutil/v3 v3.23.3 github.com/smallnest/chanx v1.2.1-0.20240521153536-01121e21ff99 github.com/soheilhy/cmux v0.1.5 diff --git a/go.sum b/go.sum index b9977d126c36..cd2136bc2579 100644 --- a/go.sum +++ b/go.sum @@ -377,6 +377,7 @@ github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5Jxq github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 h1:64bxqeTEN0/xoEqhKGowgihNuzISS9rEG6YUMU4bzJo= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d h1:U+PMnTlV2tu7RuMK5etusZG3Cf+rpow5hqQByeCzJ2g= @@ -435,8 +436,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/samber/lo v1.37.0 h1:XjVcB8g6tgUp8rsPsJ2CvhClfImrpL04YpQHXeHPhRw= github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA= -github.com/sasha-s/go-deadlock v0.2.0 h1:lMqc+fUb7RrFS3gQLtoQsJ7/6TV/pAIFvBsqX73DK8Y= -github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= +github.com/sasha-s/go-deadlock v0.3.3 h1:WHpIjWunvK1x476su56cLXOYDaMiFXaVx9JkSYC6wO0= +github.com/sasha-s/go-deadlock v0.3.3/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shirou/gopsutil/v3 v3.21.12/go.mod h1:BToYZVTlSVlfazpDDYFnsVZLaoRG+g8ufT6fPQLdJzA= diff --git a/pkg/gc/safepoint.go b/pkg/gc/safepoint.go index be12cfb78a53..c1b4687e1098 100644 --- a/pkg/gc/safepoint.go +++ b/pkg/gc/safepoint.go @@ -56,7 +56,7 @@ func (manager *SafePointManager) UpdateGCSafePoint(newSafePoint uint64) (oldSafe return } if manager.cfg.BlockSafePointV1 { - err = errors.Errorf(blockGCSafePointErrmsg) + err = errors.New(blockGCSafePointErrmsg) return } @@ -73,7 +73,7 @@ func (manager *SafePointManager) UpdateGCSafePoint(newSafePoint uint64) (oldSafe // UpdateServiceGCSafePoint update the safepoint for a specific service. func (manager *SafePointManager) UpdateServiceGCSafePoint(serviceID string, newSafePoint uint64, ttl int64, now time.Time) (minServiceSafePoint *endpoint.ServiceSafePoint, updated bool, err error) { if manager.cfg.BlockSafePointV1 { - return nil, false, errors.Errorf(blockServiceSafepointErrmsg) + return nil, false, errors.New(blockServiceSafepointErrmsg) } manager.serviceGCLock.Lock() defer manager.serviceGCLock.Unlock() diff --git a/pkg/mcs/tso/server/grpc_service.go b/pkg/mcs/tso/server/grpc_service.go index 7dd9c6b5605e..44083eb9a63d 100644 --- a/pkg/mcs/tso/server/grpc_service.go +++ b/pkg/mcs/tso/server/grpc_service.go @@ -117,7 +117,7 @@ func (s *Service) Tso(stream tsopb.TSO_TsoServer) error { keyspaceID, keyspaceGroupID, dcLocation, count) if err != nil { - return status.Errorf(codes.Unknown, err.Error()) + return status.Error(codes.Unknown, err.Error()) } keyspaceGroupIDStr := strconv.FormatUint(uint64(keyspaceGroupID), 10) tsoHandleDuration.WithLabelValues(keyspaceGroupIDStr).Observe(time.Since(start).Seconds()) diff --git a/pkg/schedule/filter/candidates_test.go b/pkg/schedule/filter/candidates_test.go index 0d805312ba78..ea7a37bbbbad 100644 --- a/pkg/schedule/filter/candidates_test.go +++ b/pkg/schedule/filter/candidates_test.go @@ -95,7 +95,7 @@ func TestCandidates(t *testing.T) { cs.Sort(idComparer) check(re, cs, 1, 2, 3, 4, 5, 6, 7) store = cs.RandomPick() - re.Greater(store.GetID(), uint64(0)) + re.Positive(store.GetID()) re.Less(store.GetID(), uint64(8)) cs = newTestCandidates(10, 15, 23, 20, 33, 32, 31) diff --git a/pkg/unsaferecovery/unsafe_recovery_controller_test.go b/pkg/unsaferecovery/unsafe_recovery_controller_test.go index 4eeed08077cf..5284b3727589 100644 --- a/pkg/unsaferecovery/unsafe_recovery_controller_test.go +++ b/pkg/unsaferecovery/unsafe_recovery_controller_test.go @@ -224,8 +224,8 @@ func TestFinished(t *testing.T) { recoveryController.HandleStoreHeartbeat(req, resp) // require peer report by empty plan re.NotNil(resp.RecoveryPlan) - re.Empty(len(resp.RecoveryPlan.Creates)) - re.Empty(len(resp.RecoveryPlan.Demotes)) + re.Empty(resp.RecoveryPlan.Creates) + re.Empty(resp.RecoveryPlan.Demotes) re.Nil(resp.RecoveryPlan.ForceLeader) re.Equal(uint64(1), resp.RecoveryPlan.Step) applyRecoveryPlan(re, storeID, reports, resp) @@ -304,8 +304,8 @@ func TestFailed(t *testing.T) { resp := &pdpb.StoreHeartbeatResponse{} recoveryController.HandleStoreHeartbeat(req, resp) re.NotNil(resp.RecoveryPlan) - re.Empty(len(resp.RecoveryPlan.Creates)) - re.Empty(len(resp.RecoveryPlan.Demotes)) + re.Empty(resp.RecoveryPlan.Creates) + re.Empty(resp.RecoveryPlan.Demotes) re.Nil(resp.RecoveryPlan.ForceLeader) applyRecoveryPlan(re, storeID, reports, resp) } @@ -604,7 +604,7 @@ func TestAutoDetectMode(t *testing.T) { if result, ok := expects[storeID]; ok { re.Equal(result.PeerReports, report.PeerReports) } else { - re.Empty(len(report.PeerReports)) + re.Empty(report.PeerReports) } } } @@ -701,7 +701,7 @@ func TestOneLearner(t *testing.T) { if result, ok := expects[storeID]; ok { re.Equal(result.PeerReports, report.PeerReports) } else { - re.Empty(len(report.PeerReports)) + re.Empty(report.PeerReports) } } } @@ -876,7 +876,7 @@ func TestTiflashLearnerPeer(t *testing.T) { if result, ok := expects[storeID]; ok { re.Equal(result.PeerReports, report.PeerReports) } else { - re.Empty(len(report.PeerReports)) + re.Empty(report.PeerReports) } } } @@ -1125,7 +1125,7 @@ func TestJointState(t *testing.T) { if result, ok := expects[storeID]; ok { re.Equal(result.PeerReports, report.PeerReports) } else { - re.Empty(len(report.PeerReports)) + re.Empty(report.PeerReports) } } } @@ -1258,7 +1258,7 @@ func TestExitForceLeader(t *testing.T) { if result, ok := expects[storeID]; ok { re.Equal(result.PeerReports, report.PeerReports) } else { - re.Empty(len(report.PeerReports)) + re.Empty(report.PeerReports) } } } @@ -1375,8 +1375,8 @@ func TestOnHealthyRegions(t *testing.T) { resp := &pdpb.StoreHeartbeatResponse{} recoveryController.HandleStoreHeartbeat(req, resp) re.NotNil(resp.RecoveryPlan) - re.Empty(len(resp.RecoveryPlan.Creates)) - re.Empty(len(resp.RecoveryPlan.Demotes)) + re.Empty(resp.RecoveryPlan.Creates) + re.Empty(resp.RecoveryPlan.Demotes) re.Nil(resp.RecoveryPlan.ForceLeader) applyRecoveryPlan(re, storeID, reports, resp) } @@ -1486,7 +1486,7 @@ func TestCreateEmptyRegion(t *testing.T) { if expect, ok := expects[storeID]; ok { re.Equal(expect.PeerReports, report.PeerReports) } else { - re.Empty(len(report.PeerReports)) + re.Empty(report.PeerReports) } } } @@ -1593,7 +1593,7 @@ func TestRangeOverlap1(t *testing.T) { if result, ok := expects[storeID]; ok { re.Equal(result.PeerReports, report.PeerReports) } else { - re.Empty(len(report.PeerReports)) + re.Empty(report.PeerReports) } } } diff --git a/pkg/utils/reflectutil/tag.go b/pkg/utils/reflectutil/tag.go index 1d04d25502ba..ccf5fbdd0858 100644 --- a/pkg/utils/reflectutil/tag.go +++ b/pkg/utils/reflectutil/tag.go @@ -71,8 +71,8 @@ func FindFieldByJSONTag(t reflect.Type, tags []string) reflect.Type { if i := strings.Index(jsonTag, ","); i != -1 { // trim 'foobar,string' to 'foobar' jsonTag = jsonTag[:i] } - if jsonTag == tags[0] { - return FindFieldByJSONTag(t.Field(i).Type, tags[1:]) + if jsonTag == tags[0] { //nolint:gosec + return FindFieldByJSONTag(t.Field(i).Type, tags[1:]) //nolint:gosec } } return nil diff --git a/pkg/window/policy_test.go b/pkg/window/policy_test.go index a08d1d4ff437..f4ae9989e193 100644 --- a/pkg/window/policy_test.go +++ b/pkg/window/policy_test.go @@ -137,8 +137,8 @@ func TestRollingPolicy_AddWithTimespan(t *testing.T) { t.Logf("%+v", bkt) } - re.Zero(len(policy.window.buckets[0].Points)) + re.Empty(policy.window.buckets[0].Points) re.Equal(4, int(policy.window.buckets[1].Points[0])) - re.Zero(len(policy.window.buckets[2].Points)) + re.Empty(policy.window.buckets[2].Points) }) } diff --git a/server/api/pprof.go b/server/api/pprof.go index bd41a34a6f00..ee4398c60b2b 100644 --- a/server/api/pprof.go +++ b/server/api/pprof.go @@ -52,7 +52,7 @@ func newPprofHandler(svr *server.Server, rd *render.Render) *pprofHandler { // @Produce application/octet-stream // @Router /debug/pprof/zip [get] func (h *pprofHandler) PProfZip(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="pd_debug"`+time.Now().Format("20060102_150405")+".zip")) + w.Header().Set("Content-Disposition", `attachment; filename="pd_debug"`+time.Now().Format("20060102_150405")+".zip") // dump goroutine/heap/mutex items := []struct { diff --git a/server/api/store_test.go b/server/api/store_test.go index 0fb970b42eda..056893333959 100644 --- a/server/api/store_test.go +++ b/server/api/store_test.go @@ -509,7 +509,7 @@ func (suite *storeTestSuite) TestGetAllLimit() { re := suite.Require() for _, testCase := range testCases { - suite.T().Logf(testCase.name) + suite.T().Log(testCase.name) info := make(map[uint64]any, 4) err := tu.ReadGetJSON(re, testDialClient, testCase.url, &info) re.NoError(err) diff --git a/server/forward.go b/server/forward.go index e13f5d45f71c..79aea2da119c 100644 --- a/server/forward.go +++ b/server/forward.go @@ -131,7 +131,7 @@ func (s *GrpcServer) forwardTSO(stream pdpb.PD_TsoServer) error { } if request.GetCount() == 0 { err = errs.ErrGenerateTimestamp.FastGenByArgs("tso count should be positive") - return status.Errorf(codes.Unknown, err.Error()) + return status.Error(codes.Unknown, err.Error()) } forwardedHost, ok := s.GetServicePrimaryAddr(stream.Context(), constant.TSOServiceName) diff --git a/server/grpc_service.go b/server/grpc_service.go index 216611038e52..556ea3917888 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -584,7 +584,7 @@ func (s *GrpcServer) Tso(stream pdpb.PD_TsoServer) error { task.End() tsoHandleDuration.Observe(time.Since(start).Seconds()) if err != nil { - return status.Errorf(codes.Unknown, err.Error()) + return status.Error(codes.Unknown, err.Error()) } response := &pdpb.TsoResponse{ Header: s.header(), diff --git a/tests/integrations/client/client_test.go b/tests/integrations/client/client_test.go index 3c8bba1fafd3..9f0b5f8d523d 100644 --- a/tests/integrations/client/client_test.go +++ b/tests/integrations/client/client_test.go @@ -594,7 +594,7 @@ func requestGlobalAndLocalTSO( re.Less(localTS, globalTS2) lastTS = globalTS2 } - re.Greater(lastTS, uint64(0)) + re.Positive(lastTS) }(dcLocation) } } @@ -1124,8 +1124,8 @@ func TestCloseClient(t *testing.T) { cli.Close() physical, logical, err := ts.Wait() if err == nil { - re.Greater(physical, int64(0)) - re.Greater(logical, int64(0)) + re.Positive(physical) + re.Positive(logical) } else { re.ErrorIs(err, context.Canceled) re.Zero(physical) diff --git a/tests/integrations/go.mod b/tests/integrations/go.mod index 9e365d8afa88..695853de577a 100644 --- a/tests/integrations/go.mod +++ b/tests/integrations/go.mod @@ -139,7 +139,7 @@ require ( github.com/prometheus/procfs v0.13.0 // indirect github.com/rs/cors v1.7.0 // indirect github.com/samber/lo v1.37.0 // indirect - github.com/sasha-s/go-deadlock v0.2.0 // indirect + github.com/sasha-s/go-deadlock v0.3.3 // indirect github.com/shirou/gopsutil/v3 v3.23.3 // indirect github.com/shoenig/go-m1cpu v0.1.5 // indirect github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0 // indirect diff --git a/tests/integrations/go.sum b/tests/integrations/go.sum index 223655edd6d2..3b892813a6bc 100644 --- a/tests/integrations/go.sum +++ b/tests/integrations/go.sum @@ -374,6 +374,7 @@ github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5Jxq github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 h1:64bxqeTEN0/xoEqhKGowgihNuzISS9rEG6YUMU4bzJo= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d h1:U+PMnTlV2tu7RuMK5etusZG3Cf+rpow5hqQByeCzJ2g= @@ -431,8 +432,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/samber/lo v1.37.0 h1:XjVcB8g6tgUp8rsPsJ2CvhClfImrpL04YpQHXeHPhRw= github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA= -github.com/sasha-s/go-deadlock v0.2.0 h1:lMqc+fUb7RrFS3gQLtoQsJ7/6TV/pAIFvBsqX73DK8Y= -github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= +github.com/sasha-s/go-deadlock v0.3.3 h1:WHpIjWunvK1x476su56cLXOYDaMiFXaVx9JkSYC6wO0= +github.com/sasha-s/go-deadlock v0.3.3/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shirou/gopsutil/v3 v3.21.12/go.mod h1:BToYZVTlSVlfazpDDYFnsVZLaoRG+g8ufT6fPQLdJzA= github.com/shirou/gopsutil/v3 v3.23.3 h1:Syt5vVZXUDXPEXpIBt5ziWsJ4LdSAAxF4l/xZeQgSEE= diff --git a/tests/integrations/tso/testutil.go b/tests/integrations/tso/testutil.go index 2a4e5eabd90d..ae81f0fbe2b7 100644 --- a/tests/integrations/tso/testutil.go +++ b/tests/integrations/tso/testutil.go @@ -34,7 +34,7 @@ type tsoResponse interface { func checkAndReturnTimestampResponse[T tsoResponse](re *require.Assertions, resp T) *pdpb.Timestamp { re.Equal(uint32(tsoCount), resp.GetCount()) timestamp := resp.GetTimestamp() - re.Greater(timestamp.GetPhysical(), int64(0)) + re.Positive(timestamp.GetPhysical()) re.GreaterOrEqual(uint32(timestamp.GetLogical())>>timestamp.GetSuffixBits(), uint32(tsoCount)) return timestamp } diff --git a/tests/server/tso/common_test.go b/tests/server/tso/common_test.go index 877fcb109826..6e6d394f11a3 100644 --- a/tests/server/tso/common_test.go +++ b/tests/server/tso/common_test.go @@ -36,7 +36,7 @@ const ( func checkAndReturnTimestampResponse(re *require.Assertions, req *pdpb.TsoRequest, resp *pdpb.TsoResponse) *pdpb.Timestamp { re.Equal(req.GetCount(), resp.GetCount()) timestamp := resp.GetTimestamp() - re.Greater(timestamp.GetPhysical(), int64(0)) + re.Positive(timestamp.GetPhysical()) re.GreaterOrEqual(uint32(timestamp.GetLogical())>>timestamp.GetSuffixBits(), req.GetCount()) return timestamp } diff --git a/tests/tso_cluster.go b/tests/tso_cluster.go index 50495bc4abc0..2087e9d4422b 100644 --- a/tests/tso_cluster.go +++ b/tests/tso_cluster.go @@ -20,6 +20,7 @@ import ( "sync" "time" + "github.com/pingcap/errors" "github.com/stretchr/testify/require" tso "github.com/tikv/pd/pkg/mcs/tso/server" "github.com/tikv/pd/pkg/mcs/utils/constant" @@ -98,7 +99,7 @@ func RestartTestTSOCluster( }) if err != nil { - return nil, fmt.Errorf("failed to restart the cluster." + err.Error()) + return nil, errors.New("failed to restart the cluster." + err.Error()) } return newCluster, nil diff --git a/tools/go.mod b/tools/go.mod index cfe6700a556c..7fc973d2f446 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -143,7 +143,7 @@ require ( github.com/prometheus/procfs v0.13.0 // indirect github.com/rs/cors v1.7.0 // indirect github.com/samber/lo v1.37.0 // indirect - github.com/sasha-s/go-deadlock v0.2.0 // indirect + github.com/sasha-s/go-deadlock v0.3.3 // indirect github.com/shirou/gopsutil/v3 v3.23.3 // indirect github.com/shoenig/go-m1cpu v0.1.5 // indirect github.com/shurcooL/httpgzip v0.0.0-20190720172056-320755c1c1b0 // indirect diff --git a/tools/go.sum b/tools/go.sum index cde0d8eeae64..28a10236fbe4 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -371,6 +371,7 @@ github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5Jxq github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 h1:64bxqeTEN0/xoEqhKGowgihNuzISS9rEG6YUMU4bzJo= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d h1:U+PMnTlV2tu7RuMK5etusZG3Cf+rpow5hqQByeCzJ2g= @@ -430,8 +431,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/samber/lo v1.37.0 h1:XjVcB8g6tgUp8rsPsJ2CvhClfImrpL04YpQHXeHPhRw= github.com/samber/lo v1.37.0/go.mod h1:9vaz2O4o8oOnK23pd2TrXufcbdbJIa3b6cstBWKpopA= -github.com/sasha-s/go-deadlock v0.2.0 h1:lMqc+fUb7RrFS3gQLtoQsJ7/6TV/pAIFvBsqX73DK8Y= -github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= +github.com/sasha-s/go-deadlock v0.3.3 h1:WHpIjWunvK1x476su56cLXOYDaMiFXaVx9JkSYC6wO0= +github.com/sasha-s/go-deadlock v0.3.3/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shirou/gopsutil/v3 v3.21.12/go.mod h1:BToYZVTlSVlfazpDDYFnsVZLaoRG+g8ufT6fPQLdJzA= github.com/shirou/gopsutil/v3 v3.23.3 h1:Syt5vVZXUDXPEXpIBt5ziWsJ4LdSAAxF4l/xZeQgSEE= diff --git a/tools/pd-api-bench/config/config.go b/tools/pd-api-bench/config/config.go index d493479348de..47a02461cfd7 100644 --- a/tools/pd-api-bench/config/config.go +++ b/tools/pd-api-bench/config/config.go @@ -96,21 +96,18 @@ func (c *Config) Parse(arguments []string) error { // InitCoordinator set case config from config itself. func (c *Config) InitCoordinator(co *cases.Coordinator) { for name, cfg := range c.HTTP { - cfg := cfg err := co.SetHTTPCase(name, &cfg) if err != nil { log.Error("create HTTP case failed", zap.Error(err)) } } for name, cfg := range c.GRPC { - cfg := cfg err := co.SetGRPCCase(name, &cfg) if err != nil { log.Error("create gRPC case failed", zap.Error(err)) } } for name, cfg := range c.Etcd { - cfg := cfg err := co.SetEtcdCase(name, &cfg) if err != nil { log.Error("create etcd case failed", zap.Error(err)) diff --git a/tools/pd-api-bench/main.go b/tools/pd-api-bench/main.go index f642ede0069b..b30b21aab1d8 100644 --- a/tools/pd-api-bench/main.go +++ b/tools/pd-api-bench/main.go @@ -255,7 +255,6 @@ func runHTTPServer(cfg *config.Config, co *cases.Coordinator) { return } for name, cfg := range input { - cfg := cfg co.SetHTTPCase(name, &cfg) } c.String(http.StatusOK, "") @@ -273,7 +272,6 @@ func runHTTPServer(cfg *config.Config, co *cases.Coordinator) { return } for name, cfg := range input { - cfg := cfg co.SetGRPCCase(name, &cfg) } c.String(http.StatusOK, "") @@ -291,7 +289,6 @@ func runHTTPServer(cfg *config.Config, co *cases.Coordinator) { return } for name, cfg := range input { - cfg := cfg co.SetEtcdCase(name, &cfg) } c.String(http.StatusOK, "")