From 2deabb333e668beaee324f8be9cff07f94c9365c Mon Sep 17 00:00:00 2001 From: nolouch Date: Wed, 5 Jul 2023 17:05:58 +0800 Subject: [PATCH] address Signed-off-by: nolouch --- DEPS.bzl | 5 +++-- distsql/request_builder.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- kv/option.go | 4 ++-- session/session.go | 2 +- session/sessiontest/BUILD.bazel | 4 ++++ sessionctx/sessionstates/session_states_test.go | 6 +++--- sessionctx/variable/session.go | 4 ++-- sessionctx/variable/sysvar.go | 7 ++++--- store/copr/BUILD.bazel | 1 + store/driver/txn/txn_driver.go | 2 +- 12 files changed, 25 insertions(+), 18 deletions(-) diff --git a/DEPS.bzl b/DEPS.bzl index 8b5bde200bc95..77d7c98589487 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -3871,8 +3871,9 @@ def go_deps(): name = "com_github_tikv_client_go_v2", build_file_proto_mode = "disable_global", importpath = "github.com/tikv/client-go/v2", - sum = "h1:KIqPtZ+U4RLuqL6wjobTnNn+111esFtu7+bY/50KKP4=", - version = "v2.0.8-0.20230621031026-864a5fc0c482", + replace = "github.com/nolouch/client-go/v2", + sum = "h1:T7YjnmguXAvSLXmV7+sIeMllYdDBLGOyGK13AyFVjRs=", + version = "v2.0.0-alpha.0.20230705081011-2596ac95a7c0", ) go_repository( diff --git a/distsql/request_builder.go b/distsql/request_builder.go index b4d0723d9801a..4911347475446 100644 --- a/distsql/request_builder.go +++ b/distsql/request_builder.go @@ -306,7 +306,7 @@ func (builder *RequestBuilder) SetFromSessionVars(sv *variable.SessionVars) *Req } builder.RequestSource.RequestSourceInternal = sv.InRestrictedSQL builder.RequestSource.RequestSourceType = sv.RequestSourceType - builder.RequestSource.ExplicitRequestSoureType = sv.ExplicitRequestSoureType + builder.RequestSource.ExplicitRequestSourceType = sv.ExplicitRequestSourceType builder.StoreBatchSize = sv.StoreBatchSize builder.Request.ResourceGroupName = sv.ResourceGroupName builder.Request.StoreBusyThreshold = sv.LoadBasedReplicaReadThreshold diff --git a/go.mod b/go.mod index f6db7c5484b25..6208bab586702 100644 --- a/go.mod +++ b/go.mod @@ -307,4 +307,4 @@ replace ( go.opencensus.io => go.opencensus.io v0.23.1-0.20220331163232-052120675fac ) -replace github.com/tikv/client-go/v2 => github.com/nolouch/client-go/v2 v2.0.0-alpha.0.20230705075110-157d072330bf +replace github.com/tikv/client-go/v2 => github.com/nolouch/client-go/v2 v2.0.0-alpha.0.20230705081011-2596ac95a7c0 diff --git a/go.sum b/go.sum index 3afd535466d05..4cd32dc13c30b 100644 --- a/go.sum +++ b/go.sum @@ -742,8 +742,8 @@ github.com/ngaut/sync2 v0.0.0-20141008032647-7a24ed77b2ef/go.mod h1:7WjlapSfwQyo github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nishanths/predeclared v0.2.2 h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm/w98Vk= github.com/nishanths/predeclared v0.2.2/go.mod h1:RROzoN6TnGQupbC+lqggsOlcgysk3LMK/HI84Mp280c= -github.com/nolouch/client-go/v2 v2.0.0-alpha.0.20230705075110-157d072330bf h1:N1wvE/FIEU1Ak3kBPIoOBFsMeUf0raxAekqOnYHqrCQ= -github.com/nolouch/client-go/v2 v2.0.0-alpha.0.20230705075110-157d072330bf/go.mod h1:4KkKqjJgKlvvWMyNqdnAlYFfV4QjEj1fEb5Hb/FoT88= +github.com/nolouch/client-go/v2 v2.0.0-alpha.0.20230705081011-2596ac95a7c0 h1:T7YjnmguXAvSLXmV7+sIeMllYdDBLGOyGK13AyFVjRs= +github.com/nolouch/client-go/v2 v2.0.0-alpha.0.20230705081011-2596ac95a7c0/go.mod h1:4KkKqjJgKlvvWMyNqdnAlYFfV4QjEj1fEb5Hb/FoT88= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= diff --git a/kv/option.go b/kv/option.go index 45d6db4840b0b..977e07b3899be 100644 --- a/kv/option.go +++ b/kv/option.go @@ -92,8 +92,8 @@ const ( RequestSourceInternal // RequestSourceType set request source type of the current statement. RequestSourceType - // ExplicitRequestSoureType is a complement of RequestSourceType, it may specified by the client or users. - ExplicitRequestSoureType + // ExplicitRequestSourceType is a complement of RequestSourceType, it may specified by the client or users. + ExplicitRequestSourceType // ReplicaReadAdjuster set the adjust function of cop requsts. ReplicaReadAdjuster // ScanBatchSize set the iter scan batch size. diff --git a/session/session.go b/session/session.go index 69f0f3915e8dc..e51883ed559de 100644 --- a/session/session.go +++ b/session/session.go @@ -644,7 +644,7 @@ func (s *session) doCommit(ctx context.Context) error { s.txn.SetOption(kv.EnableAsyncCommit, sessVars.EnableAsyncCommit) s.txn.SetOption(kv.Enable1PC, sessVars.Enable1PC) s.txn.SetOption(kv.ResourceGroupTagger, sessVars.StmtCtx.GetResourceGroupTagger()) - s.txn.SetOption(kv.ExplicitRequestSoureType, sessVars.ExplicitRequestSoureType) + s.txn.SetOption(kv.ExplicitRequestSourceType, sessVars.ExplicitRequestSourceType) if sessVars.StmtCtx.KvExecCounter != nil { // Bind an interceptor for client-go to count the number of SQL executions of each TiKV. s.txn.SetOption(kv.RPCInterceptor, sessVars.StmtCtx.KvExecCounter.RPCInterceptor()) diff --git a/session/sessiontest/BUILD.bazel b/session/sessiontest/BUILD.bazel index c8348dd42c6e2..56c2f55f38ed7 100644 --- a/session/sessiontest/BUILD.bazel +++ b/session/sessiontest/BUILD.bazel @@ -39,8 +39,12 @@ go_test( "//util/memory", "//util/sqlexec", "@com_github_pingcap_failpoint//:failpoint", + "@com_github_pingcap_kvproto//pkg/coprocessor", + "@com_github_pingcap_kvproto//pkg/kvrpcpb", "@com_github_stretchr_testify//require", "@com_github_tikv_client_go_v2//tikv", + "@com_github_tikv_client_go_v2//tikvrpc", + "@com_github_tikv_client_go_v2//tikvrpc/interceptor", "@com_github_tikv_client_go_v2//txnkv/transaction", "@org_uber_go_goleak//:goleak", ], diff --git a/sessionctx/sessionstates/session_states_test.go b/sessionctx/sessionstates/session_states_test.go index f65688de41372..98eb3a3e0132c 100644 --- a/sessionctx/sessionstates/session_states_test.go +++ b/sessionctx/sessionstates/session_states_test.go @@ -498,13 +498,13 @@ func TestSessionCtx(t *testing.T) { { // check reqest source setFunc: func(tk *testkit.TestKit) any { - tk.MustExec(`set @@tidb_reqest_source="BR"`) - require.Equal(t, "BR", tk.Session().GetSessionVars().RequestSourceType) + tk.MustExec(`set @@tidb_request_source_type="lightning"`) + require.Equal(t, "lightning", tk.Session().GetSessionVars().ExplicitRequestSourceType) return nil }, checkFunc: func(tk *testkit.TestKit, param any) { tk.MustExec(`select count(*) from test.t1`) - tk.MustQuery(`select @@tidb_reqest_source`).Check(testkit.Rows("BR")) + tk.MustQuery(`select @@tidb_request_source_type`).Check(testkit.Rows("lightning")) }, }, } diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 5a3874d12a3df..5a9a04d403502 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -1323,8 +1323,8 @@ type SessionVars struct { // RequestSourceType is the type of inner request. RequestSourceType string - // ExplicitRequestSoureType is the type of origin external request. - ExplicitRequestSoureType string + // ExplicitRequestSourceType is the type of origin external request. + ExplicitRequestSourceType string // MemoryDebugModeMinHeapInUse indicated the minimum heapInUse threshold that triggers the memoryDebugMode. MemoryDebugModeMinHeapInUse int64 diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 37f93f8cae353..f07bd268eadbc 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -51,6 +51,7 @@ import ( "github.com/pingcap/tidb/util/versioninfo" tikvcfg "github.com/tikv/client-go/v2/config" tikvstore "github.com/tikv/client-go/v2/kv" + tikvcliutil "github.com/tikv/client-go/v2/util" atomic2 "go.uber.org/atomic" "go.uber.org/zap" ) @@ -384,10 +385,10 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeSession, Name: TiDBUseAlloc, Value: BoolToOnOff(DefTiDBUseAlloc), Type: TypeBool, ReadOnly: true, GetSession: func(s *SessionVars) (string, error) { return BoolToOnOff(s.preUseChunkAlloc), nil }}, - {Scope: ScopeSession, Name: TiDBExplicitRequestSourceType, Value: "", Type: TypeEnum, PossibleValues: []string{"", "lightning", "br", "dumping", "tispark", "background"}, GetSession: func(s *SessionVars) (string, error) { - return s.ExplicitRequestSoureType, nil + {Scope: ScopeSession, Name: TiDBExplicitRequestSourceType, Value: "", Type: TypeEnum, PossibleValues: tikvcliutil.ExplictTypeList, GetSession: func(s *SessionVars) (string, error) { + return s.ExplicitRequestSourceType, nil }, SetSession: func(s *SessionVars, val string) error { - s.ExplicitRequestSoureType = val + s.ExplicitRequestSourceType = val return nil }}, /* The system variables below have INSTANCE scope */ diff --git a/store/copr/BUILD.bazel b/store/copr/BUILD.bazel index 56c271066a478..1f36698ef252a 100644 --- a/store/copr/BUILD.bazel +++ b/store/copr/BUILD.bazel @@ -53,6 +53,7 @@ go_library( "@com_github_tikv_client_go_v2//metrics", "@com_github_tikv_client_go_v2//tikv", "@com_github_tikv_client_go_v2//tikvrpc", + "@com_github_tikv_client_go_v2//tikvrpc/interceptor", "@com_github_tikv_client_go_v2//txnkv/txnlock", "@com_github_tikv_client_go_v2//txnkv/txnsnapshot", "@com_github_tikv_client_go_v2//util", diff --git a/store/driver/txn/txn_driver.go b/store/driver/txn/txn_driver.go index c8424e1ba7fed..d96da324135bb 100644 --- a/store/driver/txn/txn_driver.go +++ b/store/driver/txn/txn_driver.go @@ -270,7 +270,7 @@ func (txn *tikvTxn) SetOption(opt int, val interface{}) { txn.KVTxn.SetRequestSourceInternal(val.(bool)) case kv.RequestSourceType: txn.KVTxn.SetRequestSourceType(val.(string)) - case kv.ExplicitRequestSoureType: + case kv.ExplicitRequestSourceType: txn.KVTxn.SetExplicitRequestSourceType(val.(string)) case kv.ReplicaReadAdjuster: txn.KVTxn.GetSnapshot().SetReplicaReadAdjuster(val.(txnkv.ReplicaReadAdjuster))