Skip to content

Commit

Permalink
Update to Go 1.24.0 (#17790)
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Vicent Marti <vmg@strn.cat>
Co-authored-by: Florent Poinsard <florent.poinsard@outlook.fr>
Co-authored-by: Vicent Marti <vmg@strn.cat>
  • Loading branch information
3 people authored Feb 18, 2025
1 parent c88ac78 commit 0c6ad63
Show file tree
Hide file tree
Showing 55 changed files with 301 additions and 342 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static_checks_etc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ jobs:
- name: Install golangci-lint
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.2
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.5

- name: Clean Env
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upgrade_downgrade_test_backups_e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.23.5
go-version: 1.24.0

- name: Set up python
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.23.5
go-version: 1.24.0

- name: Set up python
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.23.5
go-version: 1.24.0

- name: Set up python
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.23.5
go-version: 1.24.0

- name: Set up python
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.23.5
go-version: 1.24.0

- name: Set up python
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.23.5
go-version: 1.24.0

- name: Set up python
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.23.5
go-version: 1.24.0

- name: Set up python
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.23.5
go-version: 1.24.0

- name: Set up python
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upgrade_downgrade_test_semi_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: 1.23.5
go-version: 1.24.0

- name: Set up python
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
Expand Down
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
go: 1.23
go: 1.24
timeout: 10m

linters-settings:
Expand Down Expand Up @@ -191,4 +191,4 @@ issues:

# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.52.2 # use the fixed version to not introduce new linters unexpectedly
golangci-lint-version: 1.64.5 # use the fixed version to not introduce new linters unexpectedly
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ $(PROTO_GO_OUTS): minimaltools install_protoc-gen-go proto/*.proto
# This rule builds the bootstrap images for all flavors.
DOCKER_IMAGES_FOR_TEST = mysql80 mysql84 percona80
DOCKER_IMAGES = common $(DOCKER_IMAGES_FOR_TEST)
BOOTSTRAP_VERSION=41
BOOTSTRAP_VERSION=42
ensure_bootstrap_version:
find docker/ -type f -exec sed -i "s/^\(ARG bootstrap_version\)=.*/\1=${BOOTSTRAP_VERSION}/" {} \;
sed -i 's/\(^.*flag.String(\"bootstrap-version\",\) *\"[^\"]\+\"/\1 \"${BOOTSTRAP_VERSION}\"/' test.go
Expand Down
2 changes: 1 addition & 1 deletion build.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
source ./tools/shell_functions.inc

go version >/dev/null 2>&1 || fail "Go is not installed or is not in \$PATH. See https://vitess.io/contributing/build-from-source for install instructions."
goversion_min 1.23.5 || echo "Go version reported: `go version`. Version 1.23.5+ recommended. See https://vitess.io/contributing/build-from-source for install instructions."
goversion_min 1.24.0 || echo "Go version reported: `go version`. Version 1.24.0+ recommended. See https://vitess.io/contributing/build-from-source for install instructions."

mkdir -p dist
mkdir -p bin
Expand Down
5 changes: 4 additions & 1 deletion docker/bootstrap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,7 @@ List of changes between bootstrap image versions.
## [41] - 2025-01-15
### Changes
- Update base image to bookworm
- Add MySQL84 image
- Add MySQL84 image

## [42] - 2025-02-14
- Update build to golang 1.24.0
2 changes: 1 addition & 1 deletion docker/bootstrap/Dockerfile.common
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 golang:1.23.5-bookworm
FROM --platform=linux/amd64 golang:1.24.0-bookworm

# Install Vitess build dependencies
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
Expand Down
2 changes: 1 addition & 1 deletion docker/lite/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=linux/amd64 golang:1.23.5-bookworm AS builder
FROM --platform=linux/amd64 golang:1.24.0-bookworm AS builder

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER
Expand Down
2 changes: 1 addition & 1 deletion docker/lite/Dockerfile.mysql84
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=linux/amd64 golang:1.23.5-bookworm AS builder
FROM --platform=linux/amd64 golang:1.24.0-bookworm AS builder

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER
Expand Down
2 changes: 1 addition & 1 deletion docker/lite/Dockerfile.percona80
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=linux/amd64 golang:1.23.5-bookworm AS builder
FROM --platform=linux/amd64 golang:1.24.0-bookworm AS builder

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER
Expand Down
2 changes: 1 addition & 1 deletion docker/vttestserver/Dockerfile.mysql80
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=linux/amd64 golang:1.23.5-bookworm AS builder
FROM --platform=linux/amd64 golang:1.24.0-bookworm AS builder

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER
Expand Down
2 changes: 1 addition & 1 deletion docker/vttestserver/Dockerfile.mysql84
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=linux/amd64 golang:1.23.5-bookworm AS builder
FROM --platform=linux/amd64 golang:1.24.0-bookworm AS builder

# Allows docker builds to set the BUILD_NUMBER
ARG BUILD_NUMBER
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module vitess.io/vitess

go 1.23.5
go 1.24.0

require (
cloud.google.com/go/storage v1.50.0
Expand Down
39 changes: 39 additions & 0 deletions go/hack/ensure_swiss_map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//go:build !goexperiment.swissmap

/*
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

// This is invalid Go code, and it will fail to compile if you disable
// Swiss maps when building Vitess. Our runtime memory accounting system
// expects the map implementation in Go 1.24 to be Swiss.

package hack

var EnsureSwissMapIsAlwaysEnabled = [-1]struct{}{}
46 changes: 46 additions & 0 deletions go/hack/hack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
package hack

import (
"runtime"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -47,3 +48,48 @@ func TestStringToByte(t *testing.T) {
b = StringBytes(s)
assert.Nil(t, b)
}

func testMapSize[K comparable, V any](t *testing.T, gen func(i int) (K, V)) {
for _, size := range []int{16 * 1024, 128 * 1024, 256 * 1024, 512 * 1024, 1024 * 1024} {
var before, after runtime.MemStats
runtime.GC()
runtime.ReadMemStats(&before)

m := make(map[K]V, size)
for i := 0; i < size; i++ {
k, v := gen(i)
m[k] = v
}

runtime.GC()
runtime.ReadMemStats(&after)

heapDiff := after.HeapAlloc - before.HeapAlloc
calcSize := RuntimeMapSize(m)

assert.InEpsilonf(t, heapDiff, calcSize, 0.1, "%Tx%v heapDiff = %v, calcSize = %v", m, size, heapDiff, calcSize)
runtime.KeepAlive(m)
}
}

func TestMapSize(t *testing.T) {
testMapSize(t, func(i int) (int, int) {
return i, i
})

testMapSize(t, func(i int) (uint32, uint32) {
return uint32(i), uint32(i)
})

testMapSize(t, func(i int) ([32]uint32, uint32) {
return [32]uint32{0: uint32(i)}, uint32(i)
})

testMapSize(t, func(i int) (uint32, [32]uint32) {
return uint32(i), [32]uint32{0: uint32(i)}
})

testMapSize(t, func(i int) ([32]uint32, [32]uint32) {
return [32]uint32{0: uint32(i)}, [32]uint32{0: uint32(i)}
})
}
102 changes: 102 additions & 0 deletions go/hack/msize.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package hack

import (
"unsafe"
)

const (
_MaxSmallSize = 32768
smallSizeDiv = 8
Expand Down Expand Up @@ -74,3 +78,101 @@ func roundupsize(size uintptr) uintptr {
func RuntimeAllocSize(size int64) int64 {
return int64(roundupsize(uintptr(size)))
}

// RuntimeMapSize returns the size of the internal data structures of a Map.
// This is an internal implementation detail based on the Swiss Map implementation
// as of Go 1.24 and needs to be kept up-to-date after every Go release.
func RuntimeMapSize[K comparable, V any](themap map[K]V) (internalSize int64) {
// The following are copies of internal data structures as of Go 1.24
// THEY MUST BE KEPT UP TO DATE

// internal/abi/type.go
const SizeofType = 48

// internal/abi/map_swiss.go
type SwissMapType struct {
pad [SizeofType]uint8
Key unsafe.Pointer
Elem unsafe.Pointer
Group unsafe.Pointer
Hasher func(unsafe.Pointer, uintptr) uintptr
GroupSize uintptr // == Group.Size_
SlotSize uintptr // size of key/elem slot
ElemOff uintptr // offset of elem in key/elem slot
Flags uint32
}

// internal/runtime/maps/map.go
type Map struct {
used uint64
seed uintptr
dirPtr unsafe.Pointer
dirLen int
globalDepth uint8
globalShift uint8
writing uint8
clearSeq uint64
}

// internal/runtime/maps/groups.go
type groupsReference struct {
data unsafe.Pointer // data *[length]typ.Group
lengthMask uint64
}

// internal/runtime/maps/table.go
type table struct {
used uint16
capacity uint16
growthLeft uint16
localDepth uint8
index int
groups groupsReference
}

directoryAt := func(m *Map, i uintptr) *table {
const PtrSize = 4 << (^uintptr(0) >> 63)
return *(**table)(unsafe.Pointer(uintptr(m.dirPtr) + PtrSize*i))
}

// Converting the map to an interface will result in two ptr-sized words;
// like all interfaces, the first word points to an *abi.Type instance,
// which is specialized as SwissMapType for maps, and to the actual
// memory allocation, which is `*Map`
type MapInterface struct {
Type *SwissMapType
Data *Map
}

mapiface := any(themap)
iface := (*MapInterface)(unsafe.Pointer(&mapiface))
m := iface.Data

var groupSize = int64(iface.Type.GroupSize)
internalSize = int64(unsafe.Sizeof(Map{}))

if m.dirLen <= 0 {
// Small map optimization: we don't allocate tables at all if all the
// entries in a map fit in a single group
if m.dirPtr != nil {
internalSize += RuntimeAllocSize(groupSize)
}
} else {
// For normal maps, we iterate each table and add the size of all the
// groups it contains.
// See: internal/runtime/maps/export_test.go
var lastTab *table
for i := range m.dirLen {
t := directoryAt(m, uintptr(i))
if t == lastTab {
continue
}
lastTab = t

gc := int64(t.groups.lengthMask + 1)
internalSize += RuntimeAllocSize(groupSize * gc)
}
}

return internalSize
}
Loading

0 comments on commit 0c6ad63

Please sign in to comment.