Skip to content

Commit

Permalink
sql: plumb tracer explicitly through EvalCtx
Browse files Browse the repository at this point in the history
Some builtins needed the Tracer and was accessing it through the Settings.
I'm trying to untangle the Tracer from the Settings. This patch passes
the Tracer through the EvalCtx.

Release note: None
  • Loading branch information
andreimatei committed Oct 7, 2021
1 parent 16def61 commit 014874e
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2447,6 +2447,7 @@ func (ex *connExecutor) initEvalCtx(ctx context.Context, evalCtx *extendedEvalCo
NodeID: ex.server.cfg.NodeID,
Codec: ex.server.cfg.Codec,
Locality: ex.server.cfg.Locality,
Tracer: ex.server.cfg.AmbientCtx.Tracer,
ReCache: ex.server.reCache,
InternalExecutor: &ie,
DB: ex.server.cfg.DB,
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/distsql/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ func (ds *ServerImpl) setupFlow(
ReCache: ds.regexpCache,
Mon: monitor,
Locality: ds.ServerConfig.Locality,
Tracer: ds.ServerConfig.Tracer,
// Most processors will override this Context with their own context in
// ProcessorBase. StartInternal().
Context: ctx,
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ func internalExtendedEvalCtx(
TxnImplicit: true,
Settings: execCfg.Settings,
Codec: execCfg.Codec,
Tracer: execCfg.AmbientCtx.Tracer,
Context: ctx,
Mon: plannerMon,
TestingKnobs: evalContextTestingKnobs,
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/schema_changer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,7 @@ func createSchemaChangeEvalCtx(
NodeID: execCfg.NodeID,
Codec: execCfg.Codec,
Locality: execCfg.Locality,
Tracer: execCfg.AmbientCtx.Tracer,
},
}
// The backfill is going to use the current timestamp for the various
Expand Down
5 changes: 4 additions & 1 deletion pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -4330,7 +4330,10 @@ value if you rely on the HLC for accuracy.`,
verbosity := bool(*(args[1].(*tree.DBool)))

var rootSpan *tracing.Span
if err := ctx.Settings.Tracer.VisitSpans(func(span *tracing.Span) error {
if ctx.Tracer == nil {
return nil, errors.AssertionFailedf("Tracer not configured")
}
if err := ctx.Tracer.VisitSpans(func(span *tracing.Span) error {
if span.TraceID() == traceID && rootSpan == nil {
rootSpan = span
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sem/builtins/generator_builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,7 @@ func makePayloadsForSpanGenerator(
)
}
spanID := uint64(*(args[0].(*tree.DInt)))
span, found := ctx.Settings.Tracer.GetActiveSpanFromID(spanID)
span, found := ctx.Tracer.GetActiveSpanFromID(spanID)
if !found {
return nil, nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/sem/tree/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ go_library(
"//pkg/util/timetz",
"//pkg/util/timeutil",
"//pkg/util/timeutil/pgdate",
"//pkg/util/tracing",
"//pkg/util/uint128",
"//pkg/util/uuid",
"@com_github_cockroachdb_apd_v2//:apd",
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/sem/tree/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/timeofday"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/cockroach/pkg/util/timeutil/pgdate"
"github.com/cockroachdb/cockroach/pkg/util/tracing"
"github.com/cockroachdb/cockroach/pkg/util/uuid"
"github.com/cockroachdb/errors"
"github.com/lib/pq/oid"
Expand Down Expand Up @@ -3482,6 +3483,8 @@ type EvalContext struct {
//
Locality roachpb.Locality

Tracer *tracing.Tracer

// The statement timestamp. May be different for every statement.
// Used for statement_timestamp().
StmtTimestamp time.Time
Expand Down

0 comments on commit 014874e

Please sign in to comment.