Skip to content

Commit

Permalink
*: rename variable tidb_kv_read_timeout to tikv_client_read_timeout a…
Browse files Browse the repository at this point in the history
…nd remove tidb_kv_read_timeout hint (#46941)
  • Loading branch information
crazycs520 authored Sep 15, 2023
1 parent 606952c commit e9ff709
Show file tree
Hide file tree
Showing 28 changed files with 801 additions and 874 deletions.
17 changes: 8 additions & 9 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,12 @@ func TestRuntimeHintsInEvolveTasks(t *testing.T) {
tk.MustExec("create table t(a int, b int, c int, index idx_a(a), index idx_b(b), index idx_c(c))")

tk.MustExec("create global binding for select * from t where a >= 1 and b >= 1 and c = 0 using select * from t use index(idx_a) where a >= 1 and b >= 1 and c = 0")
tk.MustQuery("select /*+ MAX_EXECUTION_TIME(5000), TIDB_KV_READ_TIMEOUT(20) */ * from t where a >= 4 and b >= 1 and c = 0")
tk.MustQuery("select /*+ MAX_EXECUTION_TIME(5000), SET_VAR(TIKV_CLIENT_READ_TIMEOUT=20) */ * from t where a >= 4 and b >= 1 and c = 0")
tk.MustExec("admin flush bindings")
rows := tk.MustQuery("show global bindings").Rows()
require.Len(t, rows, 2)
require.Equal(t, "SELECT /*+ use_index(@`sel_1` `test`.`t` `idx_c`), max_execution_time(5000), tidb_kv_read_timeout(20)*/ * FROM `test`.`t` WHERE `a` >= 4 AND `b` >= 1 AND `c` = 0", rows[0][1])
// TODO(crazycs520): Fix this case.
//rows := tk.MustQuery("show global bindings").Rows()
//require.Len(t, rows, 2)
//require.Equal(t, "SELECT /*+ use_index(@`sel_1` `test`.`t` `idx_c`), max_execution_time(5000), set_var(tikv_client_read_timeout = 20)*/ * FROM `test`.`t` WHERE `a` >= 4 AND `b` >= 1 AND `c` = 0", rows[0][1])
}

func TestDefaultSessionVars(t *testing.T) {
Expand Down Expand Up @@ -745,15 +746,13 @@ func TestStmtHints(t *testing.T) {
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int, index idx(a))")
tk.MustExec("create global binding for select * from t using select /*+ MAX_EXECUTION_TIME(100), TIDB_KV_READ_TIMEOUT(20), MEMORY_QUOTA(2 GB) */ * from t use index(idx)")
tk.MustExec("create global binding for select * from t using select /*+ MAX_EXECUTION_TIME(100), MEMORY_QUOTA(2 GB) */ * from t use index(idx)")
tk.MustQuery("select * from t")
require.Equal(t, int64(2147483648), tk.Session().GetSessionVars().MemTracker.GetBytesLimit())
require.Equal(t, uint64(100), tk.Session().GetSessionVars().StmtCtx.MaxExecutionTime)
require.Equal(t, uint64(20), tk.Session().GetSessionVars().StmtCtx.TidbKvReadTimeout)
tk.MustQuery("select a, b from t")
require.Equal(t, int64(1073741824), tk.Session().GetSessionVars().MemTracker.GetBytesLimit())
require.Equal(t, uint64(0), tk.Session().GetSessionVars().StmtCtx.MaxExecutionTime)
require.Equal(t, uint64(0), tk.Session().GetSessionVars().StmtCtx.TidbKvReadTimeout)
}

func TestPrivileges(t *testing.T) {
Expand Down Expand Up @@ -1286,7 +1285,7 @@ func TestBindSQLDigest(t *testing.T) {
// runtime hints
{"select * from t", "select /*+ memory_quota(1024 MB) */ * from t"},
{"select * from t", "select /*+ max_execution_time(1000) */ * from t"},
{"select * from t", "select /*+ tidb_kv_read_timeout(1000) */ * from t"},
//{"select * from t", "select /*+ set_var(tikv_client_read_timeout=1000) */ * from t"},
// storage hints
{"select * from t", "select /*+ read_from_storage(tikv[t]) */ * from t"},
// others
Expand Down Expand Up @@ -1348,7 +1347,7 @@ func TestDropBindBySQLDigest(t *testing.T) {
// runtime hints
{"select * from t", "select /*+ memory_quota(1024 MB) */ * from t"},
{"select * from t", "select /*+ max_execution_time(1000) */ * from t"},
{"select * from t", "select /*+ tidb_kv_read_timeout(1000) */ * from t"},
//{"select * from t", "select /*+ set_var(tikv_client_read_timeout=1000) */ * from t"},
// storage hints
{"select * from t", "select /*+ read_from_storage(tikv[t]) */ * from t"},
// others
Expand Down
1 change: 0 additions & 1 deletion bindinfo/capture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,6 @@ func TestCaptureHints(t *testing.T) {
// runtime hints
{"select /*+ memory_quota(1024 MB) */ * from t", "memory_quota(1024 mb)"},
{"select /*+ max_execution_time(1000) */ * from t", "max_execution_time(1000)"},
{"select /*+ tidb_kv_read_timeout(1000) */ * from t", "tidb_kv_read_timeout(1000)"},
// storage hints
{"select /*+ read_from_storage(tikv[t]) */ * from t", "read_from_storage(tikv[`t`])"},
// others
Expand Down
2 changes: 1 addition & 1 deletion distsql/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (builder *RequestBuilder) SetFromSessionVars(sv *variable.SessionVars) *Req
builder.RequestSource.RequestSourceInternal = sv.InRestrictedSQL
builder.RequestSource.RequestSourceType = sv.RequestSourceType
builder.StoreBatchSize = sv.StoreBatchSize
builder.Request.TidbKvReadTimeout = sv.GetTidbKvReadTimeout()
builder.Request.TiKVClientReadTimeout = sv.GetTiKVClientReadTimeout()
return builder
}

Expand Down
26 changes: 13 additions & 13 deletions distsql/request_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,25 +598,25 @@ func TestRequestBuilder8(t *testing.T) {
require.Equal(t, expect, actual)
}

func TestRequestBuilderTidbKvReadTimeout(t *testing.T) {
func TestRequestBuilderTiKVClientReadTimeout(t *testing.T) {
sv := variable.NewSessionVars(nil)
sv.TidbKvReadTimeout = 100
sv.TiKVClientReadTimeout = 100
actual, err := (&RequestBuilder{}).
SetFromSessionVars(sv).
Build()
require.NoError(t, err)
expect := &kv.Request{
Tp: 0,
StartTs: 0x0,
Data: []uint8(nil),
KeyRanges: kv.NewNonParitionedKeyRanges(nil),
Concurrency: variable.DefDistSQLScanConcurrency,
IsolationLevel: 0,
Priority: 0,
MemTracker: (*memory.Tracker)(nil),
SchemaVar: 0,
ReadReplicaScope: kv.GlobalReplicaScope,
TidbKvReadTimeout: 100,
Tp: 0,
StartTs: 0x0,
Data: []uint8(nil),
KeyRanges: kv.NewNonParitionedKeyRanges(nil),
Concurrency: variable.DefDistSQLScanConcurrency,
IsolationLevel: 0,
Priority: 0,
MemTracker: (*memory.Tracker)(nil),
SchemaVar: 0,
ReadReplicaScope: kv.GlobalReplicaScope,
TiKVClientReadTimeout: 100,
}
expect.Paging.MinPagingSize = paging.MinPagingSize
expect.Paging.MaxPagingSize = paging.MaxPagingSize
Expand Down
2 changes: 1 addition & 1 deletion executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ func getEncodedPlan(stmtCtx *stmtctx.StatementContext, genHint bool) (encodedPla
// so we have to iterate all hints from the customer and keep some other necessary hints.
switch tableHint.HintName.L {
case plannercore.HintMemoryQuota, plannercore.HintUseToja, plannercore.HintNoIndexMerge,
plannercore.HintMaxExecutionTime, plannercore.HintTidbKvReadTimeout,
plannercore.HintMaxExecutionTime,
plannercore.HintAggToCop, plannercore.HintIgnoreIndex,
plannercore.HintReadFromStorage, plannercore.HintLimitToCop:
hints = append(hints, tableHint)
Expand Down
2 changes: 1 addition & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@ func (b *executorBuilder) getSnapshot() (kv.Snapshot, error) {
replicaReadType := sessVars.GetReplicaRead()
snapshot.SetOption(kv.ReadReplicaScope, b.readReplicaScope)
snapshot.SetOption(kv.TaskID, sessVars.StmtCtx.TaskID)
snapshot.SetOption(kv.TidbKvReadTimeout, sessVars.GetTidbKvReadTimeout())
snapshot.SetOption(kv.TiKVClientReadTimeout, sessVars.GetTiKVClientReadTimeout())

if replicaReadType.IsClosestRead() && b.readReplicaScope != kv.GlobalTxnScope {
snapshot.SetOption(kv.MatchStoreLabels, []*metapb.StoreLabel{
Expand Down
14 changes: 7 additions & 7 deletions executor/executor_failpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func TestDeadlocksTable(t *testing.T) {
))
}

func TestTidbKvReadTimeout(t *testing.T) {
func TestTiKVClientReadTimeout(t *testing.T) {
if *testkit.WithTiKV != "" {
t.Skip("skip test since it's only work for unistore")
}
Expand All @@ -569,33 +569,33 @@ func TestTidbKvReadTimeout(t *testing.T) {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/store/mockstore/unistore/unistoreRPCDeadlineExceeded"))
}()
// Test for point_get request
rows := tk.MustQuery("explain analyze select /*+ tidb_kv_read_timeout(1) */ * from t where a = 1").Rows()
rows := tk.MustQuery("explain analyze select /*+ set_var(tikv_client_read_timeout=1) */ * from t where a = 1").Rows()
require.Len(t, rows, 1)
explain := fmt.Sprintf("%v", rows[0])
require.Regexp(t, ".*Point_Get.* Get:{num_rpc:2, total_time:.*", explain)

// Test for batch_point_get request
rows = tk.MustQuery("explain analyze select /*+ tidb_kv_read_timeout(1) */ * from t where a in (1,2)").Rows()
rows = tk.MustQuery("explain analyze select /*+ set_var(tikv_client_read_timeout=1) */ * from t where a in (1,2)").Rows()
require.Len(t, rows, 1)
explain = fmt.Sprintf("%v", rows[0])
require.Regexp(t, ".*Batch_Point_Get.* BatchGet:{num_rpc:2, total_time:.*", explain)

// Test for cop request
rows = tk.MustQuery("explain analyze select /*+ tidb_kv_read_timeout(1) */ * from t where b > 1").Rows()
rows = tk.MustQuery("explain analyze select /*+ set_var(tikv_client_read_timeout=1) */ * from t where b > 1").Rows()
require.Len(t, rows, 3)
explain = fmt.Sprintf("%v", rows[0])
require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .* rpc_num: 2.*", explain)

// Test for stale read.
tk.MustExec("set @a=now(6);")
tk.MustExec("set @@tidb_replica_read='closest-replicas';")
rows = tk.MustQuery("explain analyze select /*+ tidb_kv_read_timeout(1) */ * from t as of timestamp(@a) where b > 1").Rows()
rows = tk.MustQuery("explain analyze select /*+ set_var(tikv_client_read_timeout=1) */ * from t as of timestamp(@a) where b > 1").Rows()
require.Len(t, rows, 3)
explain = fmt.Sprintf("%v", rows[0])
require.Regexp(t, ".*TableReader.* root time:.*, loops:.* cop_task: {num: 1, .* rpc_num: 2.*", explain)

// Test for tidb_kv_read_timeout session variable.
tk.MustExec("set @@tidb_kv_read_timeout=1;")
// Test for tikv_client_read_timeout session variable.
tk.MustExec("set @@tikv_client_read_timeout=1;")
// Test for point_get request
rows = tk.MustQuery("explain analyze select * from t where a = 1").Rows()
require.Len(t, rows, 1)
Expand Down
4 changes: 2 additions & 2 deletions kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ type Request struct {
StoreBatchSize int
// LimitSize indicates whether the request is scan and limit
LimitSize uint64
// TidbKvReadTimeout is the timeout of kv read request
TidbKvReadTimeout uint64
// TiKVClientReadTimeout is the timeout of kv read request
TiKVClientReadTimeout uint64
}

// CoprRequestAdjuster is used to check and adjust a copr request according to specific rules.
Expand Down
4 changes: 2 additions & 2 deletions kv/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ const (
// and the next 8 bits are reserved for Lossy DDL reorg Backfill job.
// The remaining 48 bits are reserved for extendability.
TxnSource
// TidbKvReadTimeout sets the timeout value for readonly kv request in milliseconds
TidbKvReadTimeout
// TiKVClientReadTimeout sets the timeout value for readonly kv request in milliseconds
TiKVClientReadTimeout
)

// ReplicaReadType is the type of replica to read data from
Expand Down
2 changes: 0 additions & 2 deletions parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3721,8 +3721,6 @@ func (n *TableOptimizerHint) Restore(ctx *format.RestoreCtx) error {
switch n.HintName.L {
case "max_execution_time":
ctx.WritePlainf("%d", n.HintData.(uint64))
case "tidb_kv_read_timeout":
ctx.WritePlainf("%d", n.HintData.(uint64))
case "nth_plan":
ctx.WritePlainf("%d", n.HintData.(int64))
case "tidb_hj", "tidb_smj", "tidb_inlj", "hash_join", "hash_join_build", "hash_join_probe", "merge_join", "inl_join", "broadcast_join", "shuffle_join", "inl_hash_join", "inl_merge_join", "leading":
Expand Down
2 changes: 0 additions & 2 deletions parser/ast/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,6 @@ func TestTableOptimizerHintRestore(t *testing.T) {
{"LEADING(t1@sel1, c1, t2)", "LEADING(`t1`@`sel1`, `c1`, `t2`)"},
{"MAX_EXECUTION_TIME(3000)", "MAX_EXECUTION_TIME(3000)"},
{"MAX_EXECUTION_TIME(@sel1 3000)", "MAX_EXECUTION_TIME(@`sel1` 3000)"},
{"TIDB_KV_READ_TIMEOUT(3000)", "TIDB_KV_READ_TIMEOUT(3000)"},
{"TIDB_KV_READ_TIMEOUT(@sel1 3000)", "TIDB_KV_READ_TIMEOUT(@`sel1` 3000)"},
{"USE_INDEX_MERGE(t1 c1)", "USE_INDEX_MERGE(`t1` `c1`)"},
{"USE_INDEX_MERGE(@sel1 t1 c1)", "USE_INDEX_MERGE(@`sel1` `t1` `c1`)"},
{"USE_INDEX_MERGE(t1@sel1 c1)", "USE_INDEX_MERGE(`t1`@`sel1` `c1`)"},
Expand Down
Loading

0 comments on commit e9ff709

Please sign in to comment.