Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6530,13 +6530,13 @@ def go_deps():
name = "com_github_pingcap_kvproto",
build_file_proto_mode = "disable_global",
importpath = "github.com/pingcap/kvproto",
sha256 = "0b2ac95b21dc86677699d8b6a11531a3b8ae0ddf29331c4d77f851137fae0dd9",
strip_prefix = "github.com/pingcap/kvproto@v0.0.0-20260320060847-534bbfabf736",
sha256 = "c92084d6f9f39398a997ae0530e9e4a8acfc82b98ab17a1178c414293909f4fc",
strip_prefix = "github.com/pingcap/kvproto@v0.0.0-20260414083400-4388bfaaedab",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20260320060847-534bbfabf736.zip",
"http://ats.apps.svc/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20260320060847-534bbfabf736.zip",
"https://cache.hawkingrei.com/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20260320060847-534bbfabf736.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20260320060847-534bbfabf736.zip",
"http://bazel-cache.pingcap.net:8080/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20260414083400-4388bfaaedab.zip",
"http://ats.apps.svc/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20260414083400-4388bfaaedab.zip",
"https://cache.hawkingrei.com/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20260414083400-4388bfaaedab.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/pingcap/kvproto/com_github_pingcap_kvproto-v0.0.0-20260414083400-4388bfaaedab.zip",
],
)
go_repository(
Expand Down Expand Up @@ -7805,13 +7805,13 @@ def go_deps():
build_tags = ["nextgen", "intest"],
build_file_proto_mode = "disable_global",
importpath = "github.com/tikv/client-go/v2",
sha256 = "46ee8c64e0f95ad1514e824506e49ea1d9f75329ee6419aae4b0817336550557",
strip_prefix = "github.com/tikv/client-go/v2@v2.0.8-0.20260401083018-b7f9a9e9d2ab",
sha256 = "a5e70899561f437abf34016a1fd907ab6394ab4771f75ba509b61dd5bb806351",
strip_prefix = "github.com/tikv/client-go/v2@v2.0.8-0.20260414033830-1adc54c38a51",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20260401083018-b7f9a9e9d2ab.zip",
"http://ats.apps.svc/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20260401083018-b7f9a9e9d2ab.zip",
"https://cache.hawkingrei.com/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20260401083018-b7f9a9e9d2ab.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20260401083018-b7f9a9e9d2ab.zip",
"http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20260414033830-1adc54c38a51.zip",
"http://ats.apps.svc/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20260414033830-1adc54c38a51.zip",
"https://cache.hawkingrei.com/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20260414033830-1adc54c38a51.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20260414033830-1adc54c38a51.zip",
],
)
go_repository(
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ require (
github.com/pingcap/errors v0.11.5-0.20260310054046-9c8b3586e4b2
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86
github.com/pingcap/fn v1.0.0
github.com/pingcap/kvproto v0.0.0-20260320060847-534bbfabf736
github.com/pingcap/kvproto v0.0.0-20260414083400-4388bfaaedab
github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9
github.com/pingcap/metering_sdk v0.0.0-20260324055927-14fead745f1d
github.com/pingcap/sysutil v1.0.1-0.20240311050922-ae81ee01f3a5
Expand All @@ -124,7 +124,7 @@ require (
github.com/stathat/consistent v1.0.0
github.com/stretchr/testify v1.11.1
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
github.com/tikv/client-go/v2 v2.0.8-0.20260401083018-b7f9a9e9d2ab
github.com/tikv/client-go/v2 v2.0.8-0.20260414033830-1adc54c38a51
github.com/tikv/pd/client v0.0.0-20260401072359-048f0d8f6f71
github.com/timakin/bodyclose v0.0.0-20241222091800-1db5c5ca4d67
github.com/twmb/murmur3 v1.1.6
Expand All @@ -145,7 +145,7 @@ require (
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.1
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b
golang.org/x/net v0.50.0
golang.org/x/net v0.51.0
golang.org/x/oauth2 v0.33.0
golang.org/x/sync v0.20.0
golang.org/x/sys v0.41.0
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,8 @@ github.com/pingcap/fn v1.0.0/go.mod h1:u9WZ1ZiOD1RpNhcI42RucFh/lBuzTu6rw88a+oF2Z
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 h1:surzm05a8C9dN8dIUmo4Be2+pMRb6f55i+UIYrluu2E=
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989/go.mod h1:O17XtbryoCJhkKGbT62+L2OlrniwqiGLSqrmdHCMzZw=
github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w=
github.com/pingcap/kvproto v0.0.0-20260320060847-534bbfabf736 h1:GKdGsEfcE4ImbSN24AIt51t+3sUyqNTLoeUaJiZld8s=
github.com/pingcap/kvproto v0.0.0-20260320060847-534bbfabf736/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
github.com/pingcap/kvproto v0.0.0-20260414083400-4388bfaaedab h1:nZwtL+Fn+/EPaPby8D3b/elN2YNUZy1Mriuih/dwxqQ=
github.com/pingcap/kvproto v0.0.0-20260414083400-4388bfaaedab/go.mod h1:z6+aAHB7dBkA+LyinEX+48/ImRJ3jag0Hg0c7wkhEvE=
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM=
github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
github.com/pingcap/log v1.1.1-0.20250917021125-19901e015dc9 h1:qG9BSvlWFEE5otQGamuWedx9LRm0nrHvsQRQiW8SxEs=
Expand Down Expand Up @@ -895,8 +895,8 @@ github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/tikv/client-go/v2 v2.0.8-0.20260401083018-b7f9a9e9d2ab h1:t9Kh7tVsSSUMuSPpHChPF6W3VtN4Kq7Gi8EgWPbYRyY=
github.com/tikv/client-go/v2 v2.0.8-0.20260401083018-b7f9a9e9d2ab/go.mod h1:lfRxHwyBp1rjTmNC04SUZ+dqk7i1R1AeJ2zraMQaNvY=
github.com/tikv/client-go/v2 v2.0.8-0.20260414033830-1adc54c38a51 h1:HiKahyqWSI5aijRsSk1JciFg61D5a0x3TFyleYERBl4=
github.com/tikv/client-go/v2 v2.0.8-0.20260414033830-1adc54c38a51/go.mod h1:PILS4Yr8mWPD7J6W0+hVq4Z+lwhTIYxPYUA/OTxPSvg=
github.com/tikv/pd/client v0.0.0-20260401072359-048f0d8f6f71 h1:5hCQ6J2fwUpYqIgQGR625bW98wvYS9FUpTiVszIbVSg=
github.com/tikv/pd/client v0.0.0-20260401072359-048f0d8f6f71/go.mod h1:4kxXuAQAREpH+lVbydVwGNNDmcwdj0RG4Ofwky08W/k=
github.com/timakin/bodyclose v0.0.0-20241222091800-1db5c5ca4d67 h1:9LPGD+jzxMlnk5r6+hJnar67cgpDIz/iyD+rfl5r2Vk=
Expand Down Expand Up @@ -1150,8 +1150,8 @@ golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
3 changes: 2 additions & 1 deletion pkg/ddl/backfilling_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
"github.com/pingcap/tidb/pkg/util/chunk"
contextutil "github.com/pingcap/tidb/pkg/util/context"
"github.com/pingcap/tidb/pkg/util/dbterror"
"github.com/pingcap/tidb/pkg/util/execdetails"
"github.com/pingcap/tidb/pkg/util/intest"
"github.com/pingcap/tidb/pkg/util/logutil"
"github.com/pingcap/tidb/pkg/util/size"
Expand Down Expand Up @@ -585,7 +586,7 @@ func (w *tableScanWorker) scanRecords(task TableScanTask, sender func(IndexRecor
terror.Call(rs.Close)
return err
}
w.collector.Accepted(execDetails.UnpackedBytesReceivedKVTotal)
w.collector.Accepted(execdetails.LoadTiKVExecDetails(&execDetails).UnpackedBytesReceivedKVTotal)
execDetails = kvutil.ExecDetails{}

_, tableScanRowCount := distsqlCtx.RuntimeStatsColl.GetCopCountAndRows(tableScanCopID)
Expand Down
2 changes: 0 additions & 2 deletions pkg/distsql/context/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ go_library(
"//pkg/util/tiflash",
"//pkg/util/topsql/stmtstats",
"@com_github_tikv_client_go_v2//kv",
"@com_github_tikv_client_go_v2//tikvrpc/interceptor",
"@org_uber_go_atomic//:atomic",
],
)
Expand All @@ -43,7 +42,6 @@ go_test(
"//pkg/util/tiflash",
"//pkg/util/topsql/stmtstats",
"@com_github_tikv_client_go_v2//kv",
"@com_github_tikv_client_go_v2//tikvrpc/interceptor",
"@org_uber_go_atomic//:atomic",
],
)
2 changes: 0 additions & 2 deletions pkg/distsql/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/pingcap/tidb/pkg/util/tiflash"
"github.com/pingcap/tidb/pkg/util/topsql/stmtstats"
tikvstore "github.com/tikv/client-go/v2/kv"
"github.com/tikv/client-go/v2/tikvrpc/interceptor"
"go.uber.org/atomic"
)

Expand All @@ -46,7 +45,6 @@ type DistSQLContext struct {
KVVars *tikvstore.Variables
KvExecCounter *stmtstats.KvExecCounter
RUV2Metrics *execdetails.RUV2Metrics
RUV2RPCInterceptor interceptor.RPCInterceptor
SessionMemTracker *memory.Tracker

Location *time.Location
Expand Down
8 changes: 1 addition & 7 deletions pkg/distsql/context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/pingcap/tidb/pkg/util/tiflash"
"github.com/pingcap/tidb/pkg/util/topsql/stmtstats"
tikvstore "github.com/tikv/client-go/v2/kv"
"github.com/tikv/client-go/v2/tikvrpc/interceptor"
"go.uber.org/atomic"
)

Expand All @@ -55,10 +54,7 @@ func TestContextDetach(t *testing.T) {
KVVars: kvVars,
KvExecCounter: &stmtstats.KvExecCounter{},
RUV2Metrics: execdetails.NewRUV2Metrics(),
RUV2RPCInterceptor: interceptor.NewRPCInterceptor("test", func(next interceptor.RPCInterceptorFunc) interceptor.RPCInterceptorFunc {
return next
}),
SessionMemTracker: &memory.Tracker{},
SessionMemTracker: &memory.Tracker{},

Location: time.Local,
RuntimeStatsColl: &execdetails.RuntimeStatsColl{},
Expand Down Expand Up @@ -113,7 +109,6 @@ func TestContextDetach(t *testing.T) {
"$.RunawayChecker",
"$.RUConsumptionReporter",
"$.ExecDetails",
"$.RUV2RPCInterceptor",
}))

staticObj := obj.Detach()
Expand All @@ -130,7 +125,6 @@ func TestContextDetach(t *testing.T) {
"$.RUConsumptionReporter",
"$.ExecDetails",
"$.RUV2Metrics",
"$.RUV2RPCInterceptor",
"$.KVVars.Killed",
"$.KvExecCounter",
"$.SessionMemTracker",
Expand Down
11 changes: 0 additions & 11 deletions pkg/distsql/distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func Select(ctx context.Context, dctx *distsqlctx.DistSQLContext, kvReq *kv.Requ
}

ctx = WithSQLKvExecCounterInterceptor(ctx, dctx.KvExecCounter)
ctx = WithRUV2MetricsInterceptor(ctx, dctx.RUV2RPCInterceptor)
option := &kv.ClientSendOption{
SessionMemTracker: dctx.SessionMemTracker,
EnabledRateLimitAction: enabledRateLimitAction,
Expand Down Expand Up @@ -178,7 +177,6 @@ func SelectWithRuntimeStats(ctx context.Context, dctx *distsqlctx.DistSQLContext
func Analyze(ctx context.Context, client kv.Client, kvReq *kv.Request, vars any,
isRestrict bool, dctx *distsqlctx.DistSQLContext) (SelectResult, error) {
ctx = WithSQLKvExecCounterInterceptor(ctx, dctx.KvExecCounter)
ctx = WithRUV2MetricsInterceptor(ctx, dctx.RUV2RPCInterceptor)
failpoint.Inject("mockAnalyzeRequestWaitForCancel", func(val failpoint.Value) {
if val.(bool) {
<-ctx.Done()
Expand Down Expand Up @@ -290,12 +288,3 @@ func WithSQLKvExecCounterInterceptor(ctx context.Context, counter *stmtstats.KvE
}
return ctx
}

// WithRUV2MetricsInterceptor binds an interceptor for client-go to collect
// statement-level RUv2 request counters and TiKV ExecDetailsV2-based metrics.
func WithRUV2MetricsInterceptor(ctx context.Context, ruv2Interceptor interceptor.RPCInterceptor) context.Context {
if ruv2Interceptor != nil {
return interceptor.WithRPCInterceptor(ctx, ruv2Interceptor)
}
return ctx
}
1 change: 1 addition & 0 deletions pkg/executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ go_test(
"//pkg/executor/internal/testutil",
"//pkg/executor/join",
"//pkg/executor/sortexec",
"//pkg/executor/staticrecordset",
"//pkg/executor/unionexec",
"//pkg/expression",
"//pkg/expression/aggregation",
Expand Down
27 changes: 25 additions & 2 deletions pkg/executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ func (a *recordSet) Next(ctx context.Context, req *chunk.Chunk) (err error) {
if len(a.traceID) > 0 {
ctx = tikvtrace.ContextWithTraceID(ctx, a.traceID)
}
ctx = inheritStmtRUV2Context(ctx, a.stmt)

err = a.stmt.next(ctx, a.executor, req)
syncRUV2MetricsAfterExec(a.stmt)
if err != nil {
a.lastErrs = append(a.lastErrs, err)
return err
Expand All @@ -204,6 +206,25 @@ func (a *recordSet) Next(ctx context.Context, req *chunk.Chunk) (err error) {
return nil
}

func inheritStmtRUV2Context(ctx context.Context, stmt *ExecStmt) context.Context {
if stmt == nil || stmt.GoCtx == nil {
return ctx
}
return execdetails.ContextWithInheritedRUV2Details(ctx, stmt.GoCtx)
}

func syncRUV2MetricsAfterExec(stmt *ExecStmt) {
if stmt == nil || stmt.GoCtx == nil {
return
}
sessVars := stmt.Ctx.GetSessionVars()
if sessVars.RUV2Metrics == nil {
return
}
ruDetail, _ := stmt.GoCtx.Value(util.RUDetailsCtxKey).(*util.RUDetails)
execdetails.SyncRUV2MetricsFromRUDetails(sessVars.RUV2Metrics, ruDetail)
}

// NewChunk create a chunk base on top-level executor's exec.NewFirstChunk().
func (a *recordSet) NewChunk(alloc chunk.Allocator) *chunk.Chunk {
if alloc == nil {
Expand Down Expand Up @@ -259,7 +280,7 @@ func (a *recordSet) TryDetach() (sqlexec.RecordSet, bool, error) {
if !ok {
return nil, false, nil
}
return staticrecordset.New(a.Fields(), e, a.stmt.GetTextToLog(false)), true, nil
return staticrecordset.New(a.Fields(), e, a.stmt.GetTextToLog(false), a.stmt.GoCtx), true, nil
}

// GetExecutor4Test exports the internal executor for test purpose.
Expand Down Expand Up @@ -1110,6 +1131,7 @@ func (a *ExecStmt) handleNoDelayExecutor(ctx context.Context, e exec.Executor) (
}

err = a.next(ctx, e, exec.TryNewCacheChunk(e))
syncRUV2MetricsAfterExec(a)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1717,6 +1739,7 @@ func (a *ExecStmt) finalizeStatementRUV2Metrics() {
if ruDetail == nil {
return
}
execdetails.SyncRUV2MetricsFromRUDetails(sessVars.RUV2Metrics, ruDetail)

weights := sessVars.RUV2Weights()
tidbRU := sessVars.RUV2Metrics.CalculateRUValues(weights)
Expand Down Expand Up @@ -1951,7 +1974,7 @@ func (a *ExecStmt) updateNetworkTrafficStatsAndMetrics() {
hasMPPTraffic := a.updateMPPNetworkTraffic()
tikvExecDetailRaw := a.GoCtx.Value(util.ExecDetailsKey)
if tikvExecDetailRaw != nil {
tikvExecDetail := tikvExecDetailRaw.(*util.ExecDetails)
tikvExecDetail := execdetails.LoadTiKVExecDetails(tikvExecDetailRaw.(*util.ExecDetails))
executor_metrics.ExecutorNetworkTransmissionSentTiKVTotal.Add(float64(tikvExecDetail.UnpackedBytesSentKVTotal))
executor_metrics.ExecutorNetworkTransmissionSentTiKVCrossZone.Add(float64(tikvExecDetail.UnpackedBytesSentKVCrossZone))
executor_metrics.ExecutorNetworkTransmissionReceivedTiKVTotal.Add(float64(tikvExecDetail.UnpackedBytesReceivedKVTotal))
Expand Down
Loading