Skip to content

Commit 7a56451

Browse files
craig[bot]yuzefovich
andcommitted
Merge #149078
149078: sql: de-flake TestDistSQLReceiverReportsContention/contention=false r=yuzefovich a=yuzefovich Previously, `TestDistSQLReceiverReportsContention` with `contention=false` test case asserted that no contention has been observed since we reset the state. However, we have sources of contention among internal queries (in some test runs I observed contention on `system.jobs`, `system.job_info`, and `system.scheduled_jobs` tables), so we previously tried to eliminate reporting of that via disabling the txn stats sampling, yet we still see this test fail occasionally. In order for a contention event to be reported, we only need to have Structured recording level enabled in the trace. On a quick glance I didn't find where that happens (e.g. we recently added `sql.trace.txn.sample_rate` cluster setting which is another way to enable things, but disabling it didn't fix the flake), and I don't think it's actually worth figuring this out for this test. The main goal of the test is ensuring that we do and don't have contention on _our_ table, so this commit relaxes the test a bit. In `contention=false` test case we now only check that our table isn't present in the contention registry. Fixes: #146569. Release note: None Co-authored-by: Yahor Yuzefovich <[email protected]>
2 parents 62c6f5e + 990f0f0 commit 7a56451

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

pkg/sql/distsql_running_test.go

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -484,25 +484,17 @@ func TestDistSQLReceiverErrorRanking(t *testing.T) {
484484

485485
// TestDistSQLReceiverReportsContention verifies that the distsql receiver
486486
// reports contention events via an observable metric if they occur. This test
487-
// additionally verifies that the metric stays at zero if there is no
488-
// contention.
487+
// additionally verifies that if there is no contention on user tables, the
488+
// contention registry doesn't report any events.
489489
func TestDistSQLReceiverReportsContention(t *testing.T) {
490490
defer leaktest.AfterTest(t)()
491491
defer log.Scope(t).Close(t)
492492

493493
ctx := context.Background()
494494
testutils.RunTrueAndFalse(t, "contention", func(t *testing.T, contention bool) {
495-
// TODO(yuzefovich): add an onContentionEventCb() to
496-
// DistSQLRunTestingKnobs and use it here to accumulate contention
497-
// events.
498495
s, db, _ := serverutils.StartServer(t, base.TestServerArgs{})
499496
defer s.Stopper().Stop(ctx)
500497

501-
// Disable sampling so that only our query (below) gets a trace.
502-
// Otherwise, we're subject to flakes when internal queries experience contention.
503-
_, err := db.Exec("SET CLUSTER SETTING sql.txn_stats.sample_rate = 0")
504-
require.NoError(t, err)
505-
506498
sqlutils.CreateTable(
507499
t, db, "test", "x INT PRIMARY KEY", 1, sqlutils.ToRowFn(sqlutils.RowIdxFn),
508500
)
@@ -514,9 +506,6 @@ func TestDistSQLReceiverReportsContention(t *testing.T) {
514506
// Begin a contending transaction.
515507
conn, err := db.Conn(ctx)
516508
require.NoError(t, err)
517-
defer func() {
518-
require.NoError(t, conn.Close())
519-
}()
520509
_, err = conn.ExecContext(ctx, "BEGIN; UPDATE test.test SET x = 10 WHERE x = 1;")
521510
require.NoError(t, err)
522511
}
@@ -527,11 +516,6 @@ func TestDistSQLReceiverReportsContention(t *testing.T) {
527516
contentionRegistry := s.ExecutorConfig().(ExecutorConfig).ContentionRegistry
528517
otherConn, err := db.Conn(ctx)
529518
require.NoError(t, err)
530-
defer func() {
531-
require.NoError(t, otherConn.Close())
532-
}()
533-
// TODO(yuzefovich): turning the tracing ON won't be necessary once
534-
// always-on tracing is enabled.
535519
_, err = otherConn.ExecContext(ctx, `SET TRACING=on;`)
536520
require.NoError(t, err)
537521
txn, err := otherConn.BeginTx(ctx, nil)
@@ -540,23 +524,21 @@ func TestDistSQLReceiverReportsContention(t *testing.T) {
540524
SET TRANSACTION PRIORITY HIGH;
541525
UPDATE test.test SET x = 100 WHERE x = 1;
542526
`)
543-
544527
require.NoError(t, err)
528+
545529
if contention {
546530
// Soft check to protect against flakiness where an internal query
547531
// causes the contention metric to increment.
548532
require.GreaterOrEqual(t, metrics.ContendedQueriesCount.Count(), int64(1))
549533
require.Positive(t, metrics.CumulativeContentionNanos.Count())
550-
} else {
551-
require.Zero(
552-
t,
553-
metrics.ContendedQueriesCount.Count(),
554-
"contention metric unexpectedly non-zero when no contention events are produced",
555-
)
556-
require.Zero(t, metrics.CumulativeContentionNanos.Count())
557534
}
558-
535+
// Note that in the contention=false case, we've seen flakes where
536+
// contention on system tables occasionally shows up. In that scenario,
537+
// this check is the meat of the test - we're ensuring that if we didn't
538+
// explicitly create contention, then we don't see our table in the
539+
// contention registry.
559540
require.Equal(t, contention, strings.Contains(contentionRegistry.String(), contentionEventSubstring))
541+
560542
err = txn.Commit()
561543
require.NoError(t, err)
562544
_, err = otherConn.ExecContext(ctx, `SET TRACING=off;`)

0 commit comments

Comments
 (0)