Skip to content

Commit

Permalink
executor: add explicit request source for point get request (#45526)
Browse files Browse the repository at this point in the history
ref #44769
  • Loading branch information
glorv authored Jul 27, 2023
1 parent c9d8a74 commit 0ed68bf
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 6 deletions.
4 changes: 3 additions & 1 deletion ddl/tests/resourcegroup/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ func TestResourceGroupBasic(t *testing.T) {

// test default resource group.
tk.MustQuery("select * from information_schema.resource_groups where name = 'default'").Check(testkit.Rows("default UNLIMITED MEDIUM YES <nil> <nil>"))
tk.MustExec("alter resource group `default` RU_PER_SEC=1000 PRIORITY=LOW")
tk.MustExec("alter resource group `default` PRIORITY=LOW")
tk.MustQuery("select * from information_schema.resource_groups where name = 'default'").Check(testkit.Rows("default UNLIMITED LOW YES <nil> <nil>"))
tk.MustExec("alter resource group `default` ru_per_sec=1000")
tk.MustQuery("select * from information_schema.resource_groups where name = 'default'").Check(testkit.Rows("default 1000 LOW YES <nil> <nil>"))
tk.MustContainErrMsg("drop resource group `default`", "can't drop reserved resource group")

Expand Down
3 changes: 2 additions & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,8 @@ 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.ResourceGroupName, sessVars.ResourceGroupName)
snapshot.SetOption(kv.ExplicitRequestSourceType, sessVars.ExplicitRequestSourceType)

if replicaReadType.IsClosestRead() && b.readReplicaScope != kv.GlobalTxnScope {
snapshot.SetOption(kv.MatchStoreLabels, []*metapb.StoreLabel{
Expand Down Expand Up @@ -5210,7 +5212,6 @@ func (b *executorBuilder) buildBatchPointGet(plan *plannercore.BatchPointGetPlan
if e.Ctx().GetSessionVars().IsReplicaReadClosestAdaptive() {
e.snapshot.SetOption(kv.ReplicaReadAdjuster, newReplicaReadAdjuster(e.Ctx(), plan.GetAvgRowSize()))
}
e.snapshot.SetOption(kv.ResourceGroupName, b.ctx.GetSessionVars().ResourceGroupName)
if e.RuntimeStats() != nil {
snapshotStats := &txnsnapshot.SnapshotRuntimeStats{}
e.stats = &runtimeStatsWithSnapshot{
Expand Down
1 change: 0 additions & 1 deletion executor/point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func (b *executorBuilder) buildPointGet(p *plannercore.PointGetPlan) exec.Execut
if b.ctx.GetSessionVars().IsReplicaReadClosestAdaptive() {
e.snapshot.SetOption(kv.ReplicaReadAdjuster, newReplicaReadAdjuster(e.Ctx(), p.GetAvgRowSize()))
}
e.snapshot.SetOption(kv.ResourceGroupName, b.ctx.GetSessionVars().ResourceGroupName)
if e.RuntimeStats() != nil {
snapshotStats := &txnsnapshot.SnapshotRuntimeStats{}
e.stats = &runtimeStatsWithSnapshot{
Expand Down
3 changes: 2 additions & 1 deletion meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
"math"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -84,7 +85,7 @@ var (
// the default meta of the `default` group
defaultRGroupMeta = &model.ResourceGroupInfo{
ResourceGroupSettings: &model.ResourceGroupSettings{
RURate: 1000000,
RURate: math.MaxInt32,
BurstLimit: -1,
Priority: model.MediumPriorityValue,
},
Expand Down
4 changes: 2 additions & 2 deletions metrics/grafana/tidb.json
Original file line number Diff line number Diff line change
Expand Up @@ -19827,7 +19827,7 @@
"dashLength": 10,
"dashes": false,
"datasource": "${DS_TEST-CLUSTER}",
"description": "The hit/miss count of kv request that read from closest tikv. null means the request don't not support follower read",
"description": "The hit/miss count of kv requests that read from closest tikv. null means the request don't not support follower read",
"fieldConfig": {
"defaults": {},
"overrides": []
Expand Down Expand Up @@ -19982,7 +19982,7 @@
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Coprocssor Response Size Per Instance and TiKV",
"title": "Coprocessor Response Size Per Instance and TiKV",
"tooltip": {
"shared": true,
"sort": 0,
Expand Down
6 changes: 6 additions & 0 deletions session/sessiontest/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,10 @@ func TestRequestSource(t *testing.T) {
requestSource = r.GetContext().GetRequestSource()
case *coprocessor.Request:
requestSource = r.GetContext().GetRequestSource()
case *kvrpcpb.GetRequest:
requestSource = r.GetContext().GetRequestSource()
case *kvrpcpb.BatchGetRequest:
requestSource = r.GetContext().GetRequestSource()
}
require.Equal(t, source, requestSource)
return next(target, req)
Expand All @@ -2468,4 +2472,6 @@ func TestRequestSource(t *testing.T) {
tk.MustExecWithContext(insertCtx, "insert into t values(1, 1)")
selectCtx := interceptor.WithRPCInterceptor(context.Background(), withCheckInterceptor("external_Select_lightning"))
tk.MustExecWithContext(selectCtx, "select count(*) from t;")
tk.MustQueryWithContext(selectCtx, "select b from t where a = 1;")
tk.MustQueryWithContext(selectCtx, "select b from t where a in (1, 2, 3);")
}
3 changes: 3 additions & 0 deletions sessiontxn/internal/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func GetSnapshotWithTS(s sessionctx.Context, ts uint64, interceptor kv.SnapshotI
if tp := s.GetSessionVars().RequestSourceType; tp != "" {
snap.SetOption(kv.RequestSourceType, tp)
}
if tp := s.GetSessionVars().ExplicitRequestSourceType; tp != "" {
snap.SetOption(kv.ExplicitRequestSourceType, tp)
}
if s.GetSessionVars().LoadBasedReplicaReadThreshold > 0 {
snap.SetOption(kv.LoadBasedReplicaReadThreshold, s.GetSessionVars().LoadBasedReplicaReadThreshold)
}
Expand Down
2 changes: 2 additions & 0 deletions store/driver/txn/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func (s *tikvSnapshot) SetOption(opt int, val interface{}) {
s.KVSnapshot.SetRequestSourceInternal(val.(bool))
case kv.RequestSourceType:
s.KVSnapshot.SetRequestSourceType(val.(string))
case kv.ExplicitRequestSourceType:
s.KVSnapshot.SetExplicitRequestSourceType(val.(string))
case kv.ReplicaReadAdjuster:
s.KVSnapshot.SetReplicaReadAdjuster(val.(txnkv.ReplicaReadAdjuster))
case kv.ScanBatchSize:
Expand Down

0 comments on commit 0ed68bf

Please sign in to comment.