Skip to content

Commit a1b06fb

Browse files
authored
*: update tipb and support ResourceGroupTag with keyspace info (#61096)
close #61095
1 parent 8a1ee5d commit a1b06fb

File tree

17 files changed

+86
-26
lines changed

17 files changed

+86
-26
lines changed

DEPS.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6075,13 +6075,13 @@ def go_deps():
60756075
name = "com_github_pingcap_tipb",
60766076
build_file_proto_mode = "disable_global",
60776077
importpath = "github.com/pingcap/tipb",
6078-
sha256 = "5bffa36fa7e42bca9b6de7ba2536f64f5482be1104c838dda78b9beff550942d",
6079-
strip_prefix = "github.com/pingcap/[email protected]20250401143359-775c2379cbc7",
6078+
sha256 = "4f13b6fc9e5adf6b065369bc9b1a535b4f3e98764002cd2884fe6656c1bfc4e8",
6079+
strip_prefix = "github.com/pingcap/[email protected]20250513092957-b555ca3fc078",
60806080
urls = [
6081-
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20250401143359-775c2379cbc7.zip",
6082-
"http://ats.apps.svc/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20250401143359-775c2379cbc7.zip",
6083-
"https://cache.hawkingrei.com/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20250401143359-775c2379cbc7.zip",
6084-
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20250401143359-775c2379cbc7.zip",
6081+
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20250513092957-b555ca3fc078.zip",
6082+
"http://ats.apps.svc/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20250513092957-b555ca3fc078.zip",
6083+
"https://cache.hawkingrei.com/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20250513092957-b555ca3fc078.zip",
6084+
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/tipb/com_github_pingcap_tipb-v0.0.0-20250513092957-b555ca3fc078.zip",
60856085
],
60866086
)
60876087
go_repository(

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ require (
9393
github.com/pingcap/log v1.1.1-0.20250514022801-14f3b4ca066e
9494
github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5
9595
github.com/pingcap/tidb/pkg/parser v0.0.0-20211011031125-9b13dc409c5e
96-
github.com/pingcap/tipb v0.0.0-20250401143359-775c2379cbc7
96+
github.com/pingcap/tipb v0.0.0-20250513092957-b555ca3fc078
9797
github.com/prometheus/client_golang v1.22.0
9898
github.com/prometheus/client_model v0.6.2
9999
github.com/prometheus/common v0.63.0

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
355355
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
356356
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
357357
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
358-
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
359358
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
360359
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
361360
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
@@ -691,8 +690,8 @@ github.com/pingcap/log v1.1.1-0.20250514022801-14f3b4ca066e h1:8AZZRv1Ox9FVGATVZ
691690
github.com/pingcap/log v1.1.1-0.20250514022801-14f3b4ca066e/go.mod h1:ORfBOFp1eteu2odzsyaxI+b8TzJwgjwyQcGhI+9SfEA=
692691
github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5 h1:T4pXRhBflzDeAhmOQHNPRRogMYxP13V7BkYw3ZsoSfE=
693692
github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5/go.mod h1:rlimy0GcTvjiJqvD5mXTRr8O2eNZPBrcUgiWVYp9530=
694-
github.com/pingcap/tipb v0.0.0-20250401143359-775c2379cbc7 h1:iRRoPMrpj4jkIzhMT+yabc98bhGeUzAFSjh5HUOn5Yg=
695-
github.com/pingcap/tipb v0.0.0-20250401143359-775c2379cbc7/go.mod h1:zrnYy8vReNODg8G0OiYaX9OK+kpq+rK1jHmvd1DnIWw=
693+
github.com/pingcap/tipb v0.0.0-20250513092957-b555ca3fc078 h1:vkg2gG9XYbgqaxpiI9Qf0w6V4A9sUS+djrpwvLTx+WU=
694+
github.com/pingcap/tipb v0.0.0-20250513092957-b555ca3fc078/go.mod h1:RM8iRcMalzOthG2XJxnNBniM4xFGb/lDwHUwqkaVzt4=
696695
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
697696
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
698697
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
@@ -1378,7 +1377,6 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi
13781377
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
13791378
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
13801379
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
1381-
google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA=
13821380
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
13831381
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
13841382
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=

pkg/ddl/job_worker.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/pingcap/tidb/pkg/ddl/systable"
3636
"github.com/pingcap/tidb/pkg/ddl/util"
3737
"github.com/pingcap/tidb/pkg/infoschema"
38+
"github.com/pingcap/tidb/pkg/keyspace"
3839
"github.com/pingcap/tidb/pkg/kv"
3940
"github.com/pingcap/tidb/pkg/meta"
4041
"github.com/pingcap/tidb/pkg/meta/autoid"
@@ -702,7 +703,7 @@ func (w *ReorgContext) getResourceGroupTaggerForTopSQL() *kv.ResourceGroupTagBui
702703
}
703704

704705
digest := w.cacheDigest
705-
return kv.NewResourceGroupTagBuilder().SetSQLDigest(digest)
706+
return kv.NewResourceGroupTagBuilder(keyspace.GetKeyspaceIDBySettings()).SetSQLDigest(digest)
706707
}
707708

708709
func (w *ReorgContext) ddlJobSourceType() string {

pkg/distsql/request_builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ func TestRequestBuilderHandle(t *testing.T) {
884884
handles := []kv.Handle{kv.IntHandle(0), kv.IntHandle(2), kv.IntHandle(3), kv.IntHandle(4),
885885
kv.IntHandle(5), kv.IntHandle(10), kv.IntHandle(11), kv.IntHandle(100)}
886886

887-
resourceTagBuilder := kv.NewResourceGroupTagBuilder()
887+
resourceTagBuilder := kv.NewResourceGroupTagBuilder(nil)
888888
tableID := int64(15)
889889
actual, err := (&RequestBuilder{}).SetTableHandles(tableID, handles).
890890
SetDAGRequest(&tipb.DAGRequest{}).

pkg/executor/select.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/pingcap/tidb/pkg/executor/sortexec"
3737
"github.com/pingcap/tidb/pkg/expression"
3838
"github.com/pingcap/tidb/pkg/infoschema"
39+
"github.com/pingcap/tidb/pkg/keyspace"
3940
"github.com/pingcap/tidb/pkg/kv"
4041
"github.com/pingcap/tidb/pkg/meta/model"
4142
"github.com/pingcap/tidb/pkg/parser/ast"
@@ -322,7 +323,7 @@ func newLockCtx(sctx sessionctx.Context, lockWaitTime int64, numKeys int) (*tikv
322323
}
323324
_, planDigest := seVars.StmtCtx.GetPlanDigest()
324325

325-
return kv.NewResourceGroupTagBuilder().
326+
return kv.NewResourceGroupTagBuilder(keyspace.GetKeyspaceIDBySettings()).
326327
SetPlanDigest(planDigest).
327328
SetSQLDigest(digest).
328329
EncodeTagWithKey(mutation.Key)

pkg/infoschema/test/clustertablestest/cluster_tables_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ func TestTestDataLockWaits(t *testing.T) {
167167
_, digest1 := parser.NormalizeDigest("select * from test_data_lock_waits for update")
168168
_, digest2 := parser.NormalizeDigest("update test_data_lock_waits set f1=1 where id=2")
169169
s.store.(mockstorage.MockLockWaitSetter).SetMockLockWaits([]*deadlock.WaitForEntry{
170-
{Txn: 1, WaitForTxn: 2, Key: []byte("key1"), ResourceGroupTag: kv.NewResourceGroupTagBuilder().SetSQLDigest(digest1).EncodeTagWithKey([]byte(""))},
171-
{Txn: 3, WaitForTxn: 4, Key: []byte("key2"), ResourceGroupTag: kv.NewResourceGroupTagBuilder().SetSQLDigest(digest2).EncodeTagWithKey([]byte(""))},
170+
{Txn: 1, WaitForTxn: 2, Key: []byte("key1"), ResourceGroupTag: kv.NewResourceGroupTagBuilder(nil).SetSQLDigest(digest1).EncodeTagWithKey([]byte(""))},
171+
{Txn: 3, WaitForTxn: 4, Key: []byte("key2"), ResourceGroupTag: kv.NewResourceGroupTagBuilder(nil).SetSQLDigest(digest2).EncodeTagWithKey([]byte(""))},
172172
// Invalid digests
173-
{Txn: 5, WaitForTxn: 6, Key: []byte("key3"), ResourceGroupTag: kv.NewResourceGroupTagBuilder().EncodeTagWithKey([]byte(""))},
173+
{Txn: 5, WaitForTxn: 6, Key: []byte("key3"), ResourceGroupTag: kv.NewResourceGroupTagBuilder(nil).EncodeTagWithKey([]byte(""))},
174174
{Txn: 7, WaitForTxn: 8, Key: []byte("key4"), ResourceGroupTag: []byte("asdfghjkl")},
175175
})
176176
tk := s.newTestKitWithRoot(t)

pkg/keyspace/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ go_library(
77
visibility = ["//visibility:public"],
88
deps = [
99
"//pkg/config",
10+
"//pkg/config/kerneltype",
1011
"@com_github_pingcap_kvproto//pkg/kvrpcpb",
1112
"@com_github_tikv_client_go_v2//tikv",
1213
"@org_uber_go_zap//:zap",
@@ -20,8 +21,10 @@ go_test(
2021
srcs = ["keyspace_test.go"],
2122
embed = [":keyspace"],
2223
flaky = True,
24+
shard_count = 3,
2325
deps = [
2426
"//pkg/config",
27+
"//pkg/config/kerneltype",
2528
"@com_github_stretchr_testify//require",
2629
],
2730
)

pkg/keyspace/keyspace.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ package keyspace
1616

1717
import (
1818
"fmt"
19+
"strconv"
1920

2021
"github.com/pingcap/kvproto/pkg/kvrpcpb"
2122
"github.com/pingcap/tidb/pkg/config"
23+
"github.com/pingcap/tidb/pkg/config/kerneltype"
2224
"github.com/tikv/client-go/v2/tikv"
2325
"go.uber.org/zap"
2426
"go.uber.org/zap/zapcore"
@@ -54,6 +56,20 @@ func GetKeyspaceNameBySettings() (keyspaceName string) {
5456
return keyspaceName
5557
}
5658

59+
// GetKeyspaceIDBySettings is used to get Keyspace ID setting.
60+
func GetKeyspaceIDBySettings() (keyspaceID *uint32) {
61+
keyspaceName := config.GetGlobalKeyspaceName()
62+
if !IsKeyspaceNameEmpty(keyspaceName) && kerneltype.IsNextGen() {
63+
keyspaceIDU64, err := strconv.ParseUint(keyspaceName, 10, 32)
64+
if err != nil {
65+
return nil
66+
}
67+
keyspaceIDU32 := uint32(keyspaceIDU64)
68+
return &keyspaceIDU32
69+
}
70+
return nil
71+
}
72+
5773
// IsKeyspaceNameEmpty is used to determine whether keyspaceName is set.
5874
func IsKeyspaceNameEmpty(keyspaceName string) bool {
5975
return keyspaceName == ""

pkg/keyspace/keyspace_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"testing"
1919

2020
"github.com/pingcap/tidb/pkg/config"
21+
"github.com/pingcap/tidb/pkg/config/kerneltype"
2122
"github.com/stretchr/testify/require"
2223
)
2324

@@ -50,3 +51,21 @@ func TestNoKeyspaceNameSet(t *testing.T) {
5051
require.Equal(t, "", getKeyspaceName)
5152
require.Equal(t, true, IsKeyspaceNameEmpty(getKeyspaceName))
5253
}
54+
55+
func TestNoKeyspaceIDBySettings(t *testing.T) {
56+
config.UpdateGlobal(func(conf *config.Config) {
57+
conf.KeyspaceName = ""
58+
})
59+
getKeyspaceID := GetKeyspaceIDBySettings()
60+
require.Nil(t, getKeyspaceID)
61+
62+
config.UpdateGlobal(func(conf *config.Config) {
63+
conf.KeyspaceName = "123"
64+
})
65+
getKeyspaceID = GetKeyspaceIDBySettings()
66+
if kerneltype.IsNextGen() {
67+
require.Equal(t, uint32(123), *getKeyspaceID)
68+
} else {
69+
require.Nil(t, getKeyspaceID)
70+
}
71+
}

0 commit comments

Comments
 (0)