-
Notifications
You must be signed in to change notification settings - Fork 6.2k
*: refactor traceevent to make some concept clear #65562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 18 commits
90d112b
57952b2
16f1cad
8fe28b1
ae45bed
2af9e30
87b8e5e
b5dec50
fd19e63
a999b83
575eb19
1271435
e3f5024
da43548
eb57a8a
441167f
bf563f1
fc8a822
d601503
922c245
98635b6
d4c6c36
3a26d8a
773b92f
0c9b064
d7833b0
98d7c39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -310,8 +310,8 @@ func (s *jobScheduler) schedule() error { | |
| defer ticker.Stop() | ||
| s.mustReloadSchemas() | ||
|
|
||
| trace := traceevent.NewTrace() | ||
| ctx := tracing.WithFlightRecorder(s.schCtx, trace) | ||
| trace := traceevent.NewTraceBuf() | ||
| ctx := traceevent.WithTraceBuf(s.schCtx, trace) | ||
|
|
||
| for { | ||
| if err := s.schCtx.Err(); err != nil { | ||
|
|
@@ -525,7 +525,7 @@ func (s *jobScheduler) deliveryJob(ctx context.Context, wk *worker, pool *worker | |
| pool.put(wk) | ||
| }() | ||
|
|
||
| trace := traceevent.NewTrace() | ||
| trace := traceevent.NewTraceBuf() | ||
| jobCtx := s.getJobRunCtx(trace, jobW.ID, jobW.TraceInfo) | ||
| defer trace.DiscardOrFlush(jobCtx.ctx) | ||
|
|
||
|
|
@@ -565,11 +565,11 @@ func (s *jobScheduler) deliveryJob(ctx context.Context, wk *worker, pool *worker | |
| }) | ||
| } | ||
|
|
||
| func (s *jobScheduler) getJobRunCtx(trace *traceevent.Trace, jobID int64, traceInfo *tracing.TraceInfo) *jobContext { | ||
| func (s *jobScheduler) getJobRunCtx(trace *traceevent.TraceBuf, jobID int64, traceInfo *tracing.TraceInfo) *jobContext { | ||
| ch, _ := s.ddlJobDoneChMap.Load(jobID) | ||
| newCtx := tracing.WithFlightRecorder(s.schCtx, trace) | ||
| newCtx := traceevent.WithTraceBuf(s.schCtx, trace) | ||
| if len(traceInfo.TraceID) > 0 { | ||
| newCtx = traceevent.ContextWithTraceID(newCtx, traceInfo.TraceID) | ||
| trace.SetTraceID(traceInfo.TraceID) | ||
| } | ||
|
||
| return &jobContext{ | ||
| ctx: newCtx, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1849,9 +1849,9 @@ func (s *session) getOomAlarmVariablesInfo() sessmgr.OOMAlarmVariablesInfo { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func (s *session) ExecuteInternal(ctx context.Context, sql string, args ...any) (rs sqlexec.RecordSet, err error) { | ||||||||||||||||||
| if sink := tracing.GetSink(ctx); sink == nil { | ||||||||||||||||||
| trace := traceevent.NewTrace() | ||||||||||||||||||
| ctx = tracing.WithFlightRecorder(ctx, trace) | ||||||||||||||||||
| if sink := tracing.GetTraceBuf(ctx); sink == nil { | ||||||||||||||||||
| trace := traceevent.NewTraceBuf() | ||||||||||||||||||
| ctx = traceevent.WithTraceBuf(ctx, trace) | ||||||||||||||||||
| defer trace.DiscardOrFlush(ctx) | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use typed TraceBuf lookup for the fallback guard. Line 1835 checks raw context presence, not typed 🔧 Proposed fix func (s *session) ExecuteInternal(ctx context.Context, sql string, args ...any) (rs sqlexec.RecordSet, err error) {
- if sink := tracing.GetTraceBuf(ctx); sink == nil {
+ if traceevent.GetTraceBuf(ctx) == nil {
trace := traceevent.NewTraceBuf()
ctx = traceevent.WithTraceBuf(ctx, trace)
defer trace.DiscardOrFlush(ctx)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| // A developer debugging event so we can see what trace is missing! | ||||||||||||||||||
|
|
@@ -2822,7 +2822,10 @@ func resetStmtTraceID(ctx context.Context, se *session) (context.Context, []byte | |||||||||||||||||
| // The trace ID is generated from transaction start_ts and statement count | ||||||||||||||||||
| startTS := se.sessionVars.TxnCtx.StartTS | ||||||||||||||||||
| stmtCount := uint64(se.sessionVars.TxnCtx.StatementCount) | ||||||||||||||||||
| traceID := traceevent.GenerateTraceID(ctx, startTS, stmtCount) | ||||||||||||||||||
| traceID := traceevent.GenerateTraceID(startTS, stmtCount) | ||||||||||||||||||
| if traceBuf := traceevent.GetTraceBuf(ctx); traceBuf != nil { | ||||||||||||||||||
| traceBuf.SetTraceID(traceID) | ||||||||||||||||||
| } | ||||||||||||||||||
| ctx = trace.ContextWithTraceID(ctx, traceID) | ||||||||||||||||||
| se.currentCtx = ctx | ||||||||||||||||||
| // Store trace ID for next statement | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.