From aaead1e9396456348eff826c4eb7fa16ef1938b9 Mon Sep 17 00:00:00 2001 From: yisaer Date: Wed, 10 Aug 2022 16:06:32 +0800 Subject: [PATCH 1/4] make analyze request SI Signed-off-by: yisaer --- distsql/distsql.go | 9 +++++++++ distsql/request_builder.go | 2 +- executor/analyze_test.go | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/distsql/distsql.go b/distsql/distsql.go index 7db99424dc91f..0dfd637ceb3ca 100644 --- a/distsql/distsql.go +++ b/distsql/distsql.go @@ -16,6 +16,7 @@ package distsql import ( "context" + "github.com/pingcap/failpoint" "strconv" "unsafe" @@ -153,6 +154,14 @@ func SelectWithRuntimeStats(ctx context.Context, sctx sessionctx.Context, kvReq // Analyze do a analyze request. func Analyze(ctx context.Context, client kv.Client, kvReq *kv.Request, vars interface{}, isRestrict bool, stmtCtx *stmtctx.StatementContext) (SelectResult, error) { + failpoint.Inject("assertAnalyzeIsolationLevel", func(val failpoint.Value) { + if val.(bool) { + if kvReq.IsolationLevel != kv.SI { + panic("Analyze request's IsolationLevel should be SI") + } + } + }) + ctx = WithSQLKvExecCounterInterceptor(ctx, stmtCtx) kvReq.RequestSource.RequestSourceInternal = true kvReq.RequestSource.RequestSourceType = kv.InternalTxnStats diff --git a/distsql/request_builder.go b/distsql/request_builder.go index f8beeb68cae68..61c76dfd7ceb3 100644 --- a/distsql/request_builder.go +++ b/distsql/request_builder.go @@ -163,7 +163,7 @@ func (builder *RequestBuilder) SetAnalyzeRequest(ana *tipb.AnalyzeReq) *RequestB builder.Request.Tp = kv.ReqTypeAnalyze builder.Request.Data, builder.err = ana.Marshal() builder.Request.NotFillCache = true - builder.Request.IsolationLevel = kv.RC + builder.Request.IsolationLevel = kv.SI builder.Request.Priority = kv.PriorityLow } diff --git a/executor/analyze_test.go b/executor/analyze_test.go index 2139816195b5f..0cb66619e96ab 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -16,6 +16,7 @@ package executor_test import ( "fmt" + "github.com/pingcap/failpoint" "io/ioutil" "strings" "sync/atomic" @@ -338,3 +339,15 @@ func TestAnalyzePartitionTableForFloat(t *testing.T) { } tk.MustExec("analyze table t1") } + +// fix https://github.com/pingcap/tidb/issues/36983 +func TestAnalyzeIsolationLevel(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("create table t(id int);") + tk.MustExec("insert into t values (1);") + require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/distsql/assertAnalyzeIsolationLevel", `return(true)`)) + tk.MustExec("analyze table t") + failpoint.Disable("github.com/pingcap/tidb/distsql/assertAnalyzeIsolationLevel") +} From 46f3d148c843a49a94538392a5faf6487e0d77e7 Mon Sep 17 00:00:00 2001 From: yisaer Date: Wed, 10 Aug 2022 16:08:22 +0800 Subject: [PATCH 2/4] make analyze request SI Signed-off-by: yisaer --- distsql/distsql.go | 2 +- executor/analyze_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/distsql/distsql.go b/distsql/distsql.go index 0dfd637ceb3ca..9e732fd0f222b 100644 --- a/distsql/distsql.go +++ b/distsql/distsql.go @@ -16,12 +16,12 @@ package distsql import ( "context" - "github.com/pingcap/failpoint" "strconv" "unsafe" "github.com/opentracing/opentracing-go" "github.com/pingcap/errors" + "github.com/pingcap/failpoint" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" diff --git a/executor/analyze_test.go b/executor/analyze_test.go index 0cb66619e96ab..ce71f42b77f0c 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -16,12 +16,12 @@ package executor_test import ( "fmt" - "github.com/pingcap/failpoint" "io/ioutil" "strings" "sync/atomic" "testing" + "github.com/pingcap/failpoint" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/executor" "github.com/pingcap/tidb/infoschema" From dd2be968f84bd7dffc60d1596cefcd721bbf4a6f Mon Sep 17 00:00:00 2001 From: yisaer Date: Thu, 11 Aug 2022 13:44:58 +0800 Subject: [PATCH 3/4] fix test Signed-off-by: yisaer --- distsql/distsql.go | 8 -------- distsql/request_builder_test.go | 2 +- executor/analyze_test.go | 13 ------------- 3 files changed, 1 insertion(+), 22 deletions(-) diff --git a/distsql/distsql.go b/distsql/distsql.go index 9e732fd0f222b..fb736061a0ffb 100644 --- a/distsql/distsql.go +++ b/distsql/distsql.go @@ -21,7 +21,6 @@ import ( "github.com/opentracing/opentracing-go" "github.com/pingcap/errors" - "github.com/pingcap/failpoint" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/metrics" @@ -154,13 +153,6 @@ func SelectWithRuntimeStats(ctx context.Context, sctx sessionctx.Context, kvReq // Analyze do a analyze request. func Analyze(ctx context.Context, client kv.Client, kvReq *kv.Request, vars interface{}, isRestrict bool, stmtCtx *stmtctx.StatementContext) (SelectResult, error) { - failpoint.Inject("assertAnalyzeIsolationLevel", func(val failpoint.Value) { - if val.(bool) { - if kvReq.IsolationLevel != kv.SI { - panic("Analyze request's IsolationLevel should be SI") - } - } - }) ctx = WithSQLKvExecCounterInterceptor(ctx, stmtCtx) kvReq.RequestSource.RequestSourceInternal = true diff --git a/distsql/request_builder_test.go b/distsql/request_builder_test.go index b0ffca3562dc2..946899a66b62a 100644 --- a/distsql/request_builder_test.go +++ b/distsql/request_builder_test.go @@ -494,7 +494,7 @@ func TestRequestBuilder5(t *testing.T) { KeepOrder: true, Desc: false, Concurrency: 15, - IsolationLevel: kv.RC, + IsolationLevel: kv.SI, Priority: 1, NotFillCache: true, ReadReplicaScope: kv.GlobalReplicaScope, diff --git a/executor/analyze_test.go b/executor/analyze_test.go index ce71f42b77f0c..2139816195b5f 100644 --- a/executor/analyze_test.go +++ b/executor/analyze_test.go @@ -21,7 +21,6 @@ import ( "sync/atomic" "testing" - "github.com/pingcap/failpoint" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/executor" "github.com/pingcap/tidb/infoschema" @@ -339,15 +338,3 @@ func TestAnalyzePartitionTableForFloat(t *testing.T) { } tk.MustExec("analyze table t1") } - -// fix https://github.com/pingcap/tidb/issues/36983 -func TestAnalyzeIsolationLevel(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(id int);") - tk.MustExec("insert into t values (1);") - require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/distsql/assertAnalyzeIsolationLevel", `return(true)`)) - tk.MustExec("analyze table t") - failpoint.Disable("github.com/pingcap/tidb/distsql/assertAnalyzeIsolationLevel") -} From 1f618b756816e01c1a3b4b7a28150b70ac9f1909 Mon Sep 17 00:00:00 2001 From: yisaer Date: Thu, 11 Aug 2022 13:45:28 +0800 Subject: [PATCH 4/4] fix test Signed-off-by: yisaer --- distsql/distsql.go | 1 - 1 file changed, 1 deletion(-) diff --git a/distsql/distsql.go b/distsql/distsql.go index fb736061a0ffb..7db99424dc91f 100644 --- a/distsql/distsql.go +++ b/distsql/distsql.go @@ -153,7 +153,6 @@ func SelectWithRuntimeStats(ctx context.Context, sctx sessionctx.Context, kvReq // Analyze do a analyze request. func Analyze(ctx context.Context, client kv.Client, kvReq *kv.Request, vars interface{}, isRestrict bool, stmtCtx *stmtctx.StatementContext) (SelectResult, error) { - ctx = WithSQLKvExecCounterInterceptor(ctx, stmtCtx) kvReq.RequestSource.RequestSourceInternal = true kvReq.RequestSource.RequestSourceType = kv.InternalTxnStats