Skip to content
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

sqlstats: add retries to stats test on locked table #119977

Merged

Conversation

dhartunian
Copy link
Collaborator

Previously, the TestSQLStatsReadLimitSizeOnLockedTable test would fail very occasionally due to a rare scenario. When stats are written, they contain a column that's a hashed shard index. It's expected that statements are uniformly distributed across this shard, but that's not guaranteed. Later in the test we check a random shard to make sure its stats count exceeds a minimum of 1 (because we place a total lower bound of 8 in the cluster setting, which is then divided by 8 to derive the per-shard limit). This case will occasionally fail if the random shard that's picked happens to only contain a single statement within.

This change modifies the loop at the end of the test to expect a false value and make sure to get at least a single true result after 3 iterations, instead of requiring 3 true results every single time. The requirement that the queries run despite contention will still stand since we'll return an error in that case.

Resolves: #119067
Epic: None

Release note: None

Previously, the `TestSQLStatsReadLimitSizeOnLockedTable` test would
fail very occasionally due to a rare scenario. When stats are written,
they contain a column that's a hashed shard index. It's expected that
statements are uniformly distributed across this shard, but that's
not guaranteed. Later in the test we check a random shard to make
sure its stats count exceeds a minimum of 1 (because we place a total
lower bound of 8 in the cluster setting, which is then divided by 8 to
derive the per-shard limit). This case will occasionally fail if the
random shard that's picked happens to only contain a single statement
within.

This change modifies the loop at the end of the test to expect a
`false` value and make sure to get at least a single `true` result
after 3 iterations, instead of requiring 3 `true` results every single
time. The requirement that the queries run despite contention will
still stand since we'll return an error in that case.

Resolves: cockroachdb#119067
Epic: None

Release note: None
@dhartunian dhartunian requested review from xinhaoz and a team March 5, 2024 23:53
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@xinhaoz xinhaoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -705,7 +704,7 @@ func TestSQLStatsReadLimitSizeOnLockedTable(t *testing.T) {

// Set table size check interval to .0000001 second. So the next check doesn't
// use the cached value.
sqlConn.Exec(t, "SET CLUSTER SETTING sql.stats.limit_table_size_check.interval='.0000001s'")
persistedsqlstats.SQLStatsLimitTableCheckInterval.Override(ctx, &s.ClusterSettings().SV, time.Nanosecond)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we need to override this instead of using the set statement above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new code does the same thing. Override just sets the setting value directly.
This is an unnecessary change but one that simplifies test execution by removing the need for a full SQL parse/exec loop when we have the ability to set the value directly.

@dhartunian dhartunian added the backport-23.2.x Flags PRs that need to be backported to 23.2. label Mar 6, 2024
@dhartunian
Copy link
Collaborator Author

TFTR

bors r=xinhaoz

@craig
Copy link
Contributor

craig bot commented Mar 6, 2024

Build succeeded:

@craig craig bot merged commit 82eb30e into cockroachdb:master Mar 6, 2024
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.2.x Flags PRs that need to be backported to 23.2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pkg/sql/sqlstats/persistedsqlstats/persistedsqlstats_test: TestSQLStatsReadLimitSizeOnLockedTable failed
3 participants