Skip to content

Commit

Permalink
*: upgrade go to 1.23 (#8637)
Browse files Browse the repository at this point in the history
close #8644

Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx authored Oct 8, 2024
1 parent 76bc34a commit 697d907
Show file tree
Hide file tree
Showing 41 changed files with 79 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.23'
- name: Make Check
run: |
SWAGGER=1 make build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pd-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.23'
- name: Make
run: make docker-image
2 changes: 1 addition & 1 deletion .github/workflows/pd-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.23'
- name: ${{ matrix.name }}
env:
WORKER_ID: ${{ matrix.worker_id }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tso-consistency-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.23'
- name: Make TSO Consistency Test
run: make test-tso-consistency
2 changes: 1 addition & 1 deletion .github/workflows/tso-function-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.23'
- name: Make TSO Function Test
run: make test-tso-function
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ linters:
- gofmt
- revive
- errcheck
- exportloopref
- copyloopvar
- goimports
- depguard
linters-settings:
Expand All @@ -32,6 +32,8 @@ linters-settings:
excludes:
- G402
- G404
# TODO: enable G115 after fixing the issues
- G115
testifylint:
enable:
- bool-compare
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21-alpine as builder
FROM golang:1.23-alpine as builder

RUN apk add --no-cache \
make \
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.61.0
@grep '_' tools.go | sed 's/"//g' | awk '{print $$2}' | xargs go install

.PHONY: install-tools
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ If you're interested in contributing to PD, see [CONTRIBUTING.md](./CONTRIBUTING

## Build

1. Make sure [*Go*](https://golang.org/) (version 1.21) is installed.
1. Make sure [*Go*](https://golang.org/) (version 1.23) is installed.
2. Use `make` to install PD. `pd-server` will be installed in the `bin` directory.

## Usage
Expand Down
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,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
}
Expand All @@ -1727,7 +1727,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
}
Expand Down
2 changes: 1 addition & 1 deletion client/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/tikv/pd/client

go 1.21
go 1.23

require (
github.com/BurntSushi/toml v0.3.1
Expand Down
2 changes: 1 addition & 1 deletion client/resource_manager_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {
rootCmd.SetOutput(os.Stdout)
if err := rootCmd.Execute(); err != nil {
rootCmd.Println(err)
os.Exit(1)
exit(1)
}
}

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/tikv/pd

go 1.21
go 1.23

// When you modify PD cooperatively with kvproto, this will be useful to submit the PR to PD and the PR to
// kvproto at the same time. You can run `go mod tidy` to make it replaced with go-mod style specification.
Expand Down Expand Up @@ -40,7 +40,7 @@ require (
github.com/pingcap/tidb-dashboard v0.0.0-20240924035706-618b5cded5bf
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.5
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
Expand Down Expand Up @@ -149,7 +149,7 @@ require (
github.com/oleiade/reflections v1.0.1 // indirect
github.com/onsi/gomega v1.20.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 // indirect
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ 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.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
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/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 h1:Dx7Ovyv/SFnMFw3fD4oEoeorXc6saIiQ23LrGLth0Gw=
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4=
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d h1:U+PMnTlV2tu7RuMK5etusZG3Cf+rpow5hqQByeCzJ2g=
github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d/go.mod h1:lXfE4PvvTW5xOjO6Mba8zDPyw8M93B6AQ7frTGnMlA8=
github.com/pingcap/check v0.0.0-20191216031241-8a5a85928f12 h1:rfD9v3+ppLPzoQBgZev0qYCpegrwyFx/BUpkApEiKdY=
Expand Down Expand Up @@ -432,8 +432,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.5 h1:tNCOEEDG6tBqrNDOX35j/7hL5FcFViG6awUGROb2NsU=
github.com/sasha-s/go-deadlock v0.3.5/go.mod h1:bugP6EGbdGYObIlx7pUZtWqlvo8k9H6vCBBsiChJQ5U=
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=
Expand Down
4 changes: 2 additions & 2 deletions pkg/gc/safepoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcs/tso/server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/filter/candidates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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)
Expand Down
26 changes: 13 additions & 13 deletions pkg/unsaferecovery/unsafe_recovery_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/utils/reflectutil/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ func FindFieldByJSONTag(t reflect.Type, tags []string) reflect.Type {
if t.Kind() != reflect.Struct {
return nil
}
tag := tags[0]
tagRemain := tags[1:]
for i := 0; i < t.NumField(); i++ {
jsonTag := t.Field(i).Tag.Get("json")
if i := strings.Index(jsonTag, ","); i != -1 { // trim 'foobar,string' to 'foobar'
jsonTag = jsonTag[:i]
if j := strings.Index(jsonTag, ","); j != -1 { // trim 'foobar,string' to 'foobar'
jsonTag = jsonTag[:j]
}
if jsonTag == tags[0] {
return FindFieldByJSONTag(t.Field(i).Type, tags[1:])
if jsonTag == tag {
return FindFieldByJSONTag(t.Field(i).Type, tagRemain)
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/window/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
2 changes: 1 addition & 1 deletion server/api/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server/api/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ func requestGlobalAndLocalTSO(
re.Less(localTS, globalTS2)
lastTS = globalTS2
}
re.Greater(lastTS, uint64(0))
re.Positive(lastTS)
}(dcLocation)
}
}
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 697d907

Please sign in to comment.