Skip to content
Closed
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
3 changes: 2 additions & 1 deletion docs/generated/settings/settings-for-tenants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ sql.temp_object_cleaner.cleanup_interval duration 30m0s how often to clean up or
sql.temp_object_cleaner.wait_interval duration 30m0s how long after creation a temporary object will be cleaned up application
sql.log.all_statements.enabled (alias: sql.trace.log_statement_execute) boolean false set to true to enable logging of all executed statements application
sql.trace.stmt.enable_threshold duration 0s enables tracing on all statements; statements executing for longer than this duration will have their trace logged (set to 0 to disable); note that enabling this may have a negative performance impact; this setting applies to individual statements within a transaction and is therefore finer-grained than sql.trace.txn.enable_threshold application
sql.trace.txn.enable_threshold duration 0s enables tracing on all transactions; transactions open for longer than this duration will have their trace logged (set to 0 to disable); note that enabling this may have a negative performance impact; this setting is coarser-grained than sql.trace.stmt.enable_threshold because it applies to all statements within a transaction as well as client communication (e.g. retries) application
sql.trace.txn.enable_threshold duration 0s enables transaction traces for transactions exceeding this duration, used with 'sql.trace.txn.percent' application
sql.trace.txn.percent float 0 enables probabilistic transaction tracing. It should be used in conjunction with traceTxnThreshold. A percentage of transactions between 0 and 1.0 will have tracing enabled, and only those which exceed the configured threshold will be logged. application
sql.ttl.changefeed_replication.disabled boolean false if true, deletes issued by TTL will not be replicated via changefeeds (this setting will be ignored by changefeeds that have the ignore_disable_changefeed_replication option set; such changefeeds will continue to replicate all TTL deletes) application
sql.ttl.default_delete_batch_size integer 100 default amount of rows to delete in a single query during a TTL job application
sql.ttl.default_delete_rate_limit integer 100 default delete rate limit (rows per second) per node for each TTL job. Use 0 to signify no rate limit. application
Expand Down
3 changes: 2 additions & 1 deletion docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@
<tr><td><div id="setting-sql-temp-object-cleaner-wait-interval" class="anchored"><code>sql.temp_object_cleaner.wait_interval</code></div></td><td>duration</td><td><code>30m0s</code></td><td>how long after creation a temporary object will be cleaned up</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-trace-log-statement-execute" class="anchored"><code>sql.log.all_statements.enabled<br />(alias: sql.trace.log_statement_execute)</code></div></td><td>boolean</td><td><code>false</code></td><td>set to true to enable logging of all executed statements</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-trace-stmt-enable-threshold" class="anchored"><code>sql.trace.stmt.enable_threshold</code></div></td><td>duration</td><td><code>0s</code></td><td>enables tracing on all statements; statements executing for longer than this duration will have their trace logged (set to 0 to disable); note that enabling this may have a negative performance impact; this setting applies to individual statements within a transaction and is therefore finer-grained than sql.trace.txn.enable_threshold</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-trace-txn-enable-threshold" class="anchored"><code>sql.trace.txn.enable_threshold</code></div></td><td>duration</td><td><code>0s</code></td><td>enables tracing on all transactions; transactions open for longer than this duration will have their trace logged (set to 0 to disable); note that enabling this may have a negative performance impact; this setting is coarser-grained than sql.trace.stmt.enable_threshold because it applies to all statements within a transaction as well as client communication (e.g. retries)</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-trace-txn-enable-threshold" class="anchored"><code>sql.trace.txn.enable_threshold</code></div></td><td>duration</td><td><code>0s</code></td><td>enables transaction traces for transactions exceeding this duration, used with &#39;sql.trace.txn.percent&#39;</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-trace-txn-percent" class="anchored"><code>sql.trace.txn.percent</code></div></td><td>float</td><td><code>0</code></td><td>enables probabilistic transaction tracing. It should be used in conjunction with traceTxnThreshold. A percentage of transactions between 0 and 1.0 will have tracing enabled, and only those which exceed the configured threshold will be logged.</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-ttl-changefeed-replication-disabled" class="anchored"><code>sql.ttl.changefeed_replication.disabled</code></div></td><td>boolean</td><td><code>false</code></td><td>if true, deletes issued by TTL will not be replicated via changefeeds (this setting will be ignored by changefeeds that have the ignore_disable_changefeed_replication option set; such changefeeds will continue to replicate all TTL deletes)</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-ttl-default-delete-batch-size" class="anchored"><code>sql.ttl.default_delete_batch_size</code></div></td><td>integer</td><td><code>100</code></td><td>default amount of rows to delete in a single query during a TTL job</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
<tr><td><div id="setting-sql-ttl-default-delete-rate-limit" class="anchored"><code>sql.ttl.default_delete_rate_limit</code></div></td><td>integer</td><td><code>100</code></td><td>default delete rate limit (rows per second) per node for each TTL job. Use 0 to signify no rate limit.</td><td>Serverless/Dedicated/Self-Hosted</td></tr>
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ func (s *Server) newConnExecutor(
sessionDataStack: sdMutIterator.sds,
dataMutatorIterator: sdMutIterator,
state: txnState{
rng: rand.New(rand.NewSource(time.Now().UnixNano())),
mon: txnMon,
connCtx: ctx,
testingForceRealTracingSpans: s.cfg.TestingKnobs.ForceRealTracingSpans,
Expand Down
31 changes: 18 additions & 13 deletions pkg/sql/exec_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,23 +257,28 @@ var SecondaryTenantScatterEnabled = settings.RegisterBoolSetting(
settings.WithName("sql.virtual_cluster.feature_access.manual_range_scatter.enabled"),
)

// traceTxnThreshold can be used to log SQL transactions that take
// longer than duration to complete. For example, traceTxnThreshold=1s
// will log the trace for any transaction that takes 1s or longer. To
// log traces for all transactions use traceTxnThreshold=1ns. Note
// that any positive duration will enable tracing and will slow down
// all execution because traces are gathered for all transactions even
// if they are not output.
// traceTxnThreshold logs SQL transactions exceeding a duration, captured via
// probabilistic tracing. For example, with `sql.trace.txn.percent` set to 0.5,
// 50% of transactions are traced, and those exceeding this threshold are
// logged.
var traceTxnThreshold = settings.RegisterDurationSetting(
settings.ApplicationLevel,
"sql.trace.txn.enable_threshold",
"enables tracing on all transactions; transactions open for longer than "+
"this duration will have their trace logged (set to 0 to disable); "+
"note that enabling this may have a negative performance impact; "+
"this setting is coarser-grained than sql.trace.stmt.enable_threshold "+
"because it applies to all statements within a transaction as well as "+
"client communication (e.g. retries)",
"enables transaction traces for transactions exceeding this duration, used "+
"with 'sql.trace.txn.percent'",
0,
settings.WithPublic)

// traceTxnPct Enables probabilistic transaction tracing.
var traceTxnPct = settings.RegisterFloatSetting(
settings.ApplicationLevel,
"sql.trace.txn.percent",
"enables probabilistic transaction tracing. It should be used in conjunction "+
"with traceTxnThreshold. A percentage of transactions between 0 and 1.0 "+
"will have tracing enabled, and only those which exceed the configured "+
"threshold will be logged.",
0,
settings.NonNegativeFloatWithMaximum(1.0),
settings.WithPublic)

// TraceStmtThreshold is identical to traceTxnThreshold except it applies to
Expand Down
15 changes: 12 additions & 3 deletions pkg/sql/txn_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package sql

import (
"context"
"math/rand"
"sync/atomic"
"time"

Expand Down Expand Up @@ -92,6 +93,11 @@ type txnState struct {
// txn context.
txnCancelFn context.CancelFunc

rng *rand.Rand

// recording indicates that sp is recording
shouldRecord bool

// recordingThreshold, is not zero, indicates that sp is recording and that
// the recording should be dumped to the log if execution of the transaction
// took more than this.
Expand Down Expand Up @@ -205,7 +211,9 @@ func (ts *txnState) resetForNewSQLTxn(
ctx, cancelFn := context.WithCancel(connCtx)
var sp *tracing.Span
duration := traceTxnThreshold.Get(&tranCtx.settings.SV)
if alreadyRecording || duration > 0 {
probabilisticTracePct := traceTxnPct.Get(&tranCtx.settings.SV)
ts.shouldRecord = probabilisticTracePct > 0 && ts.rng.Float64() < probabilisticTracePct && duration > 0
if alreadyRecording || ts.shouldRecord {
ts.Ctx, sp = tracing.EnsureChildSpan(ctx, tranCtx.tracer, opName,
tracing.WithRecording(tracingpb.RecordingVerbose))
} else if ts.testingForceRealTracingSpans {
Expand All @@ -218,7 +226,7 @@ func (ts *txnState) resetForNewSQLTxn(
sp.SetTag("implicit", attribute.StringValue("true"))
}

if !alreadyRecording && (duration > 0) {
if !alreadyRecording && ts.shouldRecord {
ts.recordingThreshold = duration
ts.recordingStart = timeutil.Now()
}
Expand Down Expand Up @@ -283,7 +291,7 @@ func (ts *txnState) finishSQLTxn() (txnID uuid.UUID, commitTimestamp hlc.Timesta
ts.mon.Stop(ts.Ctx)
sp := tracing.SpanFromContext(ts.Ctx)

if ts.recordingThreshold > 0 {
if ts.shouldRecord {
if elapsed := timeutil.Since(ts.recordingStart); elapsed >= ts.recordingThreshold {
logTraceAboveThreshold(ts.Ctx,
sp.GetRecording(sp.RecordingType()), /* recording */
Expand All @@ -300,6 +308,7 @@ func (ts *txnState) finishSQLTxn() (txnID uuid.UUID, commitTimestamp hlc.Timesta
ts.txnCancelFn()
}
ts.Ctx = nil
ts.shouldRecord = false
ts.recordingThreshold = 0
return func() (txnID uuid.UUID, timestamp hlc.Timestamp) {
ts.mu.Lock()
Expand Down
Loading