Skip to content
Open
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
12 changes: 6 additions & 6 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7649,13 +7649,13 @@ def go_deps():
build_tags = ["nextgen", "intest"],
build_file_proto_mode = "disable_global",
importpath = "github.com/tikv/client-go/v2",
sha256 = "01b98b4ba8ba6ae2519907bd1ce80bec4eee3f20a7069ac3ec9917cabeea2bf3",
strip_prefix = "github.com/tikv/client-go/v2@v2.0.8-0.20251112113123-1264c1278595",
sha256 = "adef9104eec7fa9035971796205d6a110428f6997efed3d732f802f3526936b0",
strip_prefix = "github.com/tiancaiamao/client-go/v2@v2.0.0-alpha.0.20251119122352-647fceb7683f",
urls = [
"http://bazel-cache.pingcap.net:8080/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20251112113123-1264c1278595.zip",
"http://ats.apps.svc/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20251112113123-1264c1278595.zip",
"https://cache.hawkingrei.com/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20251112113123-1264c1278595.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/tikv/client-go/v2/com_github_tikv_client_go_v2-v2.0.8-0.20251112113123-1264c1278595.zip",
"http://bazel-cache.pingcap.net:8080/gomod/github.com/tiancaiamao/client-go/v2/com_github_tiancaiamao_client_go_v2-v2.0.0-alpha.0.20251119122352-647fceb7683f.zip",
"http://ats.apps.svc/gomod/github.com/tiancaiamao/client-go/v2/com_github_tiancaiamao_client_go_v2-v2.0.0-alpha.0.20251119122352-647fceb7683f.zip",
"https://cache.hawkingrei.com/gomod/github.com/tiancaiamao/client-go/v2/com_github_tiancaiamao_client_go_v2-v2.0.0-alpha.0.20251119122352-647fceb7683f.zip",
"https://storage.googleapis.com/pingcapmirror/gomod/github.com/tiancaiamao/client-go/v2/com_github_tiancaiamao_client_go_v2-v2.0.0-alpha.0.20251119122352-647fceb7683f.zip",
],
)
go_repository(
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,5 @@ replace (
sourcegraph.com/sourcegraph/appdash => github.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0
sourcegraph.com/sourcegraph/appdash-data => github.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67
)

replace github.com/tikv/client-go/v2 => github.com/tiancaiamao/client-go/v2 v2.0.0-alpha.0.20251119122352-647fceb7683f
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,8 @@ github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpR
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY=
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJfDRtkanvQPiooDH8HvJ2FBh+iKT/OmiQQ=
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU=
github.com/tiancaiamao/client-go/v2 v2.0.0-alpha.0.20251119122352-647fceb7683f h1:pjSXyGNgo7Lx7wV6hEnlI89Fi6tVMLlXAn3zm9TP6n8=
github.com/tiancaiamao/client-go/v2 v2.0.0-alpha.0.20251119122352-647fceb7683f/go.mod h1:ZLHQiuG/o3JHzMuE7dT2GnGCf+SPxUNbcr6farUsU18=
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW93SG+q0F8KI+yFrcIDT4c/RNoc4=
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM=
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
Expand All @@ -883,8 +885,6 @@ 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.20251112113123-1264c1278595 h1:FbQU6n+neYgeeU7jFW2i8g7M03xSfVRdOSNmb/FmKMI=
github.com/tikv/client-go/v2 v2.0.8-0.20251112113123-1264c1278595/go.mod h1:ZLHQiuG/o3JHzMuE7dT2GnGCf+SPxUNbcr6farUsU18=
github.com/tikv/pd/client v0.0.0-20250703091733-dfd345b89500 h1:ZUCeeEEU76I/jFUK3C9EV3dSSrtVZt3rwpHF6cT8V3k=
github.com/tikv/pd/client v0.0.0-20250703091733-dfd345b89500/go.mod h1:SicyvcZE0fzrGGWW3AEtZWWPRzGw/h5img4/6qiSYws=
github.com/timakin/bodyclose v0.0.0-20241222091800-1db5c5ca4d67 h1:9LPGD+jzxMlnk5r6+hJnar67cgpDIz/iyD+rfl5r2Vk=
Expand Down
16 changes: 2 additions & 14 deletions pkg/executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1682,10 +1682,6 @@ func resetCTEStorageMap(se sessionctx.Context) error {
return nil
}

func slowQueryDumpTriggerCheck(config *traceevent.DumpTriggerConfig) bool {
return config.Event.Type == "slow_query"
}

// LogSlowQuery is used to print the slow query in the log files.
func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
sessVars := a.Ctx.GetSessionVars()
Expand Down Expand Up @@ -1740,7 +1736,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
if trace.IsEnabled() {
trace.Log(a.GoCtx, "details", slowLog)
}
traceevent.CheckFlightRecorderDumpTrigger(a.GoCtx, "dump_trigger.suspicious_event", slowQueryDumpTriggerCheck)
traceevent.CheckFlightRecorderDumpTrigger(a.GoCtx, "dump_trigger.suspicious_event", "slow_query")

if !matchRules {
return
Expand Down Expand Up @@ -1918,14 +1914,6 @@ func getEncodedPlan(stmtCtx *stmtctx.StatementContext, genHint bool) (encodedPla
return
}

type planDigestAlias struct {
Digest string
}

func (digest planDigestAlias) planDigestDumpTriggerCheck(config *traceevent.DumpTriggerConfig) bool {
return config.UserCommand.PlanDigest == digest.Digest
}

// SummaryStmt collects statements for information_schema.statements_summary
func (a *ExecStmt) SummaryStmt(succ bool) {
sessVars := a.Ctx.GetSessionVars()
Expand Down Expand Up @@ -1972,7 +1960,7 @@ func (a *ExecStmt) SummaryStmt(succ bool) {
if a.Plan.TP() != plancodec.TypePointGet {
_, tmp := GetPlanDigest(stmtCtx)
planDigest = tmp.String()
traceevent.CheckFlightRecorderDumpTrigger(a.GoCtx, "dump_trigger.user_command.plan_digest", planDigestAlias{planDigest}.planDigestDumpTriggerCheck)
traceevent.CheckFlightRecorderDumpTrigger(a.GoCtx, "dump_trigger.user_command.plan_digest", planDigest)
}

execDetail := stmtCtx.GetExecDetails()
Expand Down
68 changes: 5 additions & 63 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"iter"
"math"
"math/rand"
"regexp"
"runtime/pprof"
"slices"
"strconv"
Expand Down Expand Up @@ -1921,22 +1920,12 @@ func (s *session) Execute(ctx context.Context, sql string) (recordSets []sqlexec
return []sqlexec.RecordSet{rs}, err
}

type sqlRegexp struct {
regexp string
}

func (s sqlRegexp) sqlRegexpDumpTriggerCheck(cfg *traceevent.DumpTriggerConfig) bool {
// TODO: pre-compile the regexp to improve performance
match, err := regexp.MatchString(cfg.UserCommand.SQLRegexp, s.regexp)
return err == nil && match
}

// Parse parses a query string to raw ast.StmtNode.
func (s *session) Parse(ctx context.Context, sql string) ([]ast.StmtNode, error) {
logutil.Logger(ctx).Debug("parse", zap.String("sql", sql))
parseStartTime := time.Now()

traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.user_command.sql_regexp", sqlRegexp{sql}.sqlRegexpDumpTriggerCheck)
traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.user_command.sql_regexp", sql)

// Load the session variables to the context.
// This is necessary for the parser to get the current sql_mode.
Expand Down Expand Up @@ -2375,33 +2364,10 @@ func (s *session) ExecuteInternalStmt(ctx context.Context, stmtNode ast.StmtNode
return s.ExecuteStmt(ctx, stmtNode)
}

func queryFailDumpTriggerCheck(config *traceevent.DumpTriggerConfig) bool {
return config.Event.Type == "query_fail"
}

type isInternalAlias struct {
bool
}

// isInternalAlias is not intuitive, but it is defined to avoid allocation.
// If the code is written as
//
// traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.suspicious_event.is_internal", func(conf *traceevent.DumpTriggerConfig) {
// conf.Event.IsInternal = conf.Event.IsInternal
// })
//
// It's uncertain whether the Go compiler escape analysis is powerful enough to avoid allocation for the closure object.
// isInternalAlias is defined to help the compiler, this coding style will not cause closure object allocation.
//
// traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.suspicious_event.is_internal", isInternalAlias{s.isInternal()}.isInternalDumpTriggerCheck)
func (i isInternalAlias) isInternalDumpTriggerCheck(config *traceevent.DumpTriggerConfig) bool {
return config.Event.IsInternal == i.bool
}

func (s *session) ExecuteStmt(ctx context.Context, stmtNode ast.StmtNode) (sqlexec.RecordSet, error) {
rs, err := s.executeStmtImpl(ctx, stmtNode)
if err != nil {
traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.suspicious_event", queryFailDumpTriggerCheck)
traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.suspicious_event", "query_fail")
}
return rs, err
}
Expand Down Expand Up @@ -2797,30 +2763,6 @@ func (s *session) hasFileTransInConn() bool {
return false
}

type sqlDigestAlias struct {
Digest string
}

func (digest sqlDigestAlias) sqlDigestDumpTriggerCheck(config *traceevent.DumpTriggerConfig) bool {
return config.UserCommand.SQLDigest == digest.Digest
}

type userAlias struct {
user string
}

func (u userAlias) byUserDumpTriggerCheck(config *traceevent.DumpTriggerConfig) bool {
return config.UserCommand.ByUser == u.user
}

type stmtLabelAlias struct {
label string
}

func (s stmtLabelAlias) stmtLabelDumpTriggerCheck(config *traceevent.DumpTriggerConfig) bool {
return config.UserCommand.StmtLabel == s.label
}

// runStmt executes the sqlexec.Statement and commit or rollback the current transaction.
func runStmt(ctx context.Context, se *session, s sqlexec.Statement) (rs sqlexec.RecordSet, err error) {
failpoint.Inject("assertTxnManagerInRunStmt", func() {
Expand Down Expand Up @@ -2872,11 +2814,11 @@ func runStmt(ctx context.Context, se *session, s sqlexec.Statement) (rs sqlexec.
traceevent.TraceEvent(ctx, traceevent.StmtLifecycle, "stmt.start", fields...)
}
// Not using closure to avoid unnecessary memory allocation.
traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.user_command.sql_digest", sqlDigestAlias{sqlDigest}.sqlDigestDumpTriggerCheck)
traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.user_command.sql_digest", sqlDigest)
if se.sessionVars.User != nil && se.sessionVars.User.Username != "" {
traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.user_command.by_user", userAlias{se.sessionVars.User.Username}.byUserDumpTriggerCheck)
traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.user_command.by_user", se.sessionVars.User.Username)
}
traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.user_command.stmt_label", stmtLabelAlias{stmtCtx.StmtType}.stmtLabelDumpTriggerCheck)
traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.user_command.stmt_label", stmtCtx.StmtType)

// Defer stmt.finish trace event to capture final state including errors
defer func() {
Expand Down
6 changes: 1 addition & 5 deletions pkg/store/copr/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1834,14 +1834,10 @@ func (worker *copIteratorWorker) handleBatchRemainsOnErr(bo *Backoffer, rpcCtx *
}, nil
}

func regionErrorDumpTriggerCheck(config *traceevent.DumpTriggerConfig) bool {
return config.Event.Type == "region_error"
}

func getRegionError(ctx context.Context, resp interface{ GetRegionError() *errorpb.Error }) *errorpb.Error {
err := resp.GetRegionError()
if err != nil {
traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.suspicious_event", regionErrorDumpTriggerCheck)
traceevent.CheckFlightRecorderDumpTrigger(ctx, "dump_trigger.suspicious_event", "region_error")
return err
}
return nil
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/traceevent/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func RegisterWithClientGo() {
trace.SetTraceEventFunc(handleClientGoTraceEvent)
trace.SetIsCategoryEnabledFunc(handleClientGoIsCategoryEnabled)
trace.SetTraceControlExtractor(handleTraceControlExtractor)
trace.SetCheckFlightRecorderDumpTriggerFunc(CheckFlightRecorderDumpTrigger)
}

// handleClientGoTraceEvent is the function called by client-go to emit trace events.
Expand Down Expand Up @@ -103,6 +104,8 @@ func mapCategory(category trace.Category) TraceCategory {
return tracing.TxnLockResolve
case trace.CategoryKVRequest:
return tracing.KvRequest
case trace.CategoryDevDebug:
return tracing.DevDebug
default:
return tracing.UnknownClient
}
Expand Down
Loading