Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3.2
7.4.1
4 changes: 2 additions & 2 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,8 @@ def go_deps():
name = "com_github_dgryski_go_farm",
build_file_proto_mode = "disable_global",
importpath = "github.com/dgryski/go-farm",
sum = "h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=",
version = "v0.0.0-20200201041132-a6ae2369ad13",
sum = "h1:aIftn67I1fkbMa512G+w+Pxci9hJPB8oMnkcP3iZF38=",
version = "v0.0.0-20240924180020-3414d57e47da",
)
go_repository(
name = "com_github_dgryski_go_sip13",
Expand Down
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_rules_go",
patch_args = ["-p1"],
patches = ["//build/patches:rules_go_bazel7.patch"],
sha256 = "ae013bf35bd23234d1dea46b079f1e05ba74ac0321423830119d3e787ec73483",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.36.0/rules_go-v0.36.0.zip",
Expand All @@ -11,6 +13,8 @@ http_archive(

http_archive(
name = "bazel_gazelle",
patch_args = ["-p1"],
patches = ["//build/patches:gazelle_native_patch.patch"],
sha256 = "501deb3d5695ab658e82f6f6f549ba681ea3ca2a5fb7911154b5aa45596183fa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.26.0/bazel-gazelle-v0.26.0.tar.gz",
Expand Down
13 changes: 13 additions & 0 deletions build/patches/gazelle_native_patch.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/internal/go_repository.bzl b/internal/go_repository.bzl
--- a/internal/go_repository.bzl
+++ b/internal/go_repository.bzl
@@ -550,6 +550,9 @@
"""Implementation of patching an already extracted repository"""
bash_exe = ctx.os.environ["BAZEL_SH"] if "BAZEL_SH" in ctx.os.environ else "bash"
for patchfile in ctx.attr.patches:
+ if ctx.attr.patch_tool == "patch" and len(ctx.attr.patch_args) == 1 and ctx.attr.patch_args[0].startswith("-p"):
+ ctx.patch(ctx.path(patchfile), strip = int(ctx.attr.patch_args[0][2:]))
+ continue
command = "{patchtool} {patch_args} < {patchfile}".format(
patchtool = ctx.attr.patch_tool,
patchfile = ctx.path(patchfile),
10 changes: 5 additions & 5 deletions build/patches/io_etcd_go_etcd_raft_v3.patch
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
diff -urN a/raftpb/BUILD.bazel b/raftpb/BUILD.bazel
--- a/raftpb/BUILD.bazel 1969-12-31 19:00:00.000000000 -0500
+++ b/raftpb/BUILD.bazel 2000-01-01 00:00:00.000000000 -0000
diff --git a/raftpb/BUILD.bazel b/raftpb/BUILD.bazel
--- a/raftpb/BUILD.bazel
+++ b/raftpb/BUILD.bazel
@@ -1,4 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
+load("@rules_proto//proto:defs.bzl", "proto_library")

go_library(
name = "raftpb",
@@ -28,3 +29,12 @@
srcs = ["confstate_test.go"],
@@ -31,3 +32,12 @@
],
embed = [":raftpb"],
)
+
Expand Down
43 changes: 43 additions & 0 deletions build/patches/rules_go_bazel7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
diff --git a/go/private/context.bzl b/go/private/context.bzl
--- a/go/private/context.bzl
+++ b/go/private/context.bzl
@@ -577,8 +577,8 @@
mandatory = True,
providers = [GoStdLib],
),
- "_whitelist_function_transition": attr.label(
- default = "@bazel_tools//tools/whitelists/function_transition_whitelist",
+ "_allowlist_function_transition": attr.label(
+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
doc = """go_context_data gathers information about the build configuration.
diff --git a/go/private/rules/nogo.bzl b/go/private/rules/nogo.bzl
--- a/go/private/rules/nogo.bzl
+++ b/go/private/rules/nogo.bzl
@@ -102,8 +102,8 @@
"_cgo_context_data": attr.label(default = "//:cgo_context_data_proxy"),
"_go_config": attr.label(default = "//:go_config"),
"_stdlib": attr.label(default = "//:stdlib"),
- "_whitelist_function_transition": attr.label(
- default = "@bazel_tools//tools/whitelists/function_transition_whitelist",
+ "_allowlist_function_transition": attr.label(
+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
toolchains = [GO_TOOLCHAIN],
diff --git a/go/tools/builders/generate_test_main.go b/go/tools/builders/generate_test_main.go
--- a/go/tools/builders/generate_test_main.go
+++ b/go/tools/builders/generate_test_main.go
@@ -146,3 +146,8 @@
- if err != nil || totalShards <= 1 {
- return allTests
- }
+ if err != nil || totalShards <= 1 {
+ return allTests
+ }
+ file, err := os.Create(os.Getenv("TEST_SHARD_STATUS_FILE"))
+ if err != nil {
+ log.Fatalf("Failed to touch TEST_SHARD_STATUS_FILE: %v", err)
+ }
+ _ = file.Close()
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/daixiang0/gci v0.8.5
github.com/danjacques/gofslock v0.0.0-20191023191349-0a45f885bc37
github.com/dgraph-io/ristretto v0.1.1
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da
github.com/docker/go-units v0.4.0
github.com/emirpasic/gods v1.18.1
github.com/fatanugraha/noloopclosure v0.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWa
github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA=
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da h1:aIftn67I1fkbMa512G+w+Pxci9hJPB8oMnkcP3iZF38=
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
Expand Down
33 changes: 26 additions & 7 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2480,8 +2480,10 @@ func (cc *clientConn) upgradeToTLS(tlsConfig *tls.Config) error {
}

func (cc *clientConn) handleChangeUser(ctx context.Context, data []byte) error {
oldUser, oldDBName, oldAuthPlugin := cc.user, cc.dbname, cc.authPlugin
oldCtx := cc.getCtx()
user, data := parseNullTermString(data)
cc.user = string(hack.String(user))
newUser := string(hack.String(user))
if len(data) < 1 {
return mysql.ErrMalformPacket
}
Expand All @@ -2493,7 +2495,7 @@ func (cc *clientConn) handleChangeUser(ctx context.Context, data []byte) error {
pass := data[:passLen]
data = data[passLen:]
dbName, data := parseNullTermString(data)
cc.dbname = string(hack.String(dbName))
newDBName := string(hack.String(dbName))
pluginName := ""
if len(data) > 0 {
// skip character set
Expand All @@ -2506,13 +2508,22 @@ func (cc *clientConn) handleChangeUser(ctx context.Context, data []byte) error {
}
}

if err := cc.ctx.Close(); err != nil {
logutil.Logger(ctx).Debug("close old context failed", zap.Error(err))
}
// session was closed by `ctx.Close` and should `openSession` explicitly to renew session.
// `openSession` won't run again in `openSessionAndDoAuth` because ctx is not nil.
cc.user = newUser
cc.dbname = newDBName
err := cc.openSession()
restoreOldSession := func() {
if newCtx := cc.getCtx(); newCtx != nil && newCtx != oldCtx {
if err := newCtx.Close(); err != nil {
logutil.Logger(ctx).Debug("close new context failed", zap.Error(err))
}
}
cc.setCtx(oldCtx)
cc.user = oldUser
cc.dbname = oldDBName
cc.authPlugin = oldAuthPlugin
}
if err != nil {
restoreOldSession()
return err
}
fakeResp := &handshakeResponse41{
Expand All @@ -2522,19 +2533,27 @@ func (cc *clientConn) handleChangeUser(ctx context.Context, data []byte) error {
}
if fakeResp.AuthPlugin != "" {
failpoint.Inject("ChangeUserAuthSwitch", func(val failpoint.Value) {
restoreOldSession()
failpoint.Return(errors.Errorf("%v", val))
})
newpass, err := cc.checkAuthPlugin(ctx, fakeResp)
if err != nil {
restoreOldSession()
return err
}
if len(newpass) > 0 {
fakeResp.Auth = newpass
}
}
if err := cc.openSessionAndDoAuth(fakeResp.Auth, fakeResp.AuthPlugin); err != nil {
restoreOldSession()
return err
}
if oldCtx != nil {
if err := oldCtx.Close(); err != nil {
logutil.Logger(ctx).Debug("close old context failed", zap.Error(err))
}
}
return cc.handleCommonConnectionReset(ctx)
}

Expand Down
50 changes: 50 additions & 0 deletions server/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,56 @@ func TestChangeUserAuth(t *testing.T) {
err = cc.handleChangeUser(ctx, data)
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/server/ChangeUserAuthSwitch"))
require.EqualError(t, err, t.Name())
require.Same(t, tc, cc.getCtx())
require.Equal(t, "root", cc.user)
}

func TestChangeUserAuthFailureRestoresOldSession(t *testing.T) {
store := testkit.CreateMockStore(t)

cfg := newTestConfig()
cfg.Port = 0
cfg.Status.StatusPort = 0

drv := NewTiDBDriver(store)
srv, err := NewServer(cfg, drv)
require.NoError(t, err)
defer srv.Close()

cc := &clientConn{
connectionID: 1,
alloc: arena.NewAllocator(1024),
chunkAlloc: chunk.NewAllocator(),
peerHost: "localhost",
collation: mysql.DefaultCollationID,
capability: mysql.ClientProtocol41,
pkt: &packetIO{bufWriter: bufio.NewWriter(bytes.NewBuffer(nil))},
server: srv,
user: "root",
dbname: "old_db",
}
se, err := session.CreateSession4Test(store)
require.NoError(t, err)
require.NoError(t, se.Auth(&auth.UserIdentity{Username: "root", Hostname: "localhost"}, nil, nil))
tc := &TiDBContext{
Session: se,
stmts: make(map[int]*TiDBStatement),
}
cc.setCtx(tc)

data := []byte{}
data = append(data, "missing_user"...)
data = append(data, 0)
data = append(data, 0)
data = append(data, "new_db"...)
data = append(data, 0)
data = append(data, 0, 0)
err = cc.handleChangeUser(context.Background(), data)
require.Error(t, err)
require.Same(t, tc, cc.getCtx())
require.Equal(t, "root", cc.user)
require.Equal(t, "old_db", cc.dbname)
require.Equal(t, "root", cc.ctx.GetSessionVars().User.Username)
}

func TestAuthPlugin2(t *testing.T) {
Expand Down
12 changes: 7 additions & 5 deletions util/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (
"bytes"
"encoding/json"
"fmt"
_ "runtime" // import link package
_ "unsafe" // required by go:linkname
"runtime"

"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/parser/mysql"
Expand All @@ -29,6 +28,12 @@ import (
"go.uber.org/zap"
)

var buildVersion string

func init() {
buildVersion = runtime.Version()
}

// PrintTiDBInfo prints the TiDB version information.
func PrintTiDBInfo() {
logutil.BgLogger().Info("Welcome to TiDB.",
Expand Down Expand Up @@ -167,6 +172,3 @@ func GetPrintResult(cols []string, datas [][]string) (string, bool) {
value = append(value, getPrintDivLine(maxColLen)...)
return string(value), true
}

//go:linkname buildVersion runtime.buildVersion
var buildVersion string
Loading