From 20812184a54950068a6df3370ae68f4fbaf0d11e Mon Sep 17 00:00:00 2001 From: Oliver Tan Date: Wed, 15 Sep 2021 18:47:43 +1000 Subject: [PATCH 1/2] democluster: shorten the scheduled jobs initial delay Release note (cli change): cockroach demo will now begin processing scheduled jobs after 15s, instead of the 2-5min in a production environment. --- pkg/cli/democluster/BUILD.bazel | 1 + pkg/cli/democluster/demo_cluster.go | 7 +++++++ pkg/cli/democluster/demo_cluster_test.go | 1 + 3 files changed, 9 insertions(+) diff --git a/pkg/cli/democluster/BUILD.bazel b/pkg/cli/democluster/BUILD.bazel index fc74064eb19b..a5a21438ceb3 100644 --- a/pkg/cli/democluster/BUILD.bazel +++ b/pkg/cli/democluster/BUILD.bazel @@ -20,6 +20,7 @@ go_library( "//pkg/cli/clierror", "//pkg/cli/cliflags", "//pkg/cli/democluster/api", + "//pkg/jobs", "//pkg/kv/kvserver/liveness/livenesspb", "//pkg/roachpb:with-mocks", "//pkg/rpc", diff --git a/pkg/cli/democluster/demo_cluster.go b/pkg/cli/democluster/demo_cluster.go index c1052468567d..352316d272d2 100644 --- a/pkg/cli/democluster/demo_cluster.go +++ b/pkg/cli/democluster/demo_cluster.go @@ -27,6 +27,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/cli/clierror" "github.com/cockroachdb/cockroach/pkg/cli/cliflags" + "github.com/cockroachdb/cockroach/pkg/jobs" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/rpc" @@ -645,6 +646,12 @@ func (demoCtx *Context) testServerArgsForTransientCluster( Server: &server.TestingKnobs{ StickyEngineRegistry: stickyEngineRegistry, }, + JobsTestingKnobs: &jobs.TestingKnobs{ + // Allow the scheduler daemon to start earlier in demo. + SchedulerDaemonInitialScanDelay: func() time.Duration { + return time.Second * 15 + }, + }, }, } diff --git a/pkg/cli/democluster/demo_cluster_test.go b/pkg/cli/democluster/demo_cluster_test.go index 443dfeedceb9..7eb84ced9b2f 100644 --- a/pkg/cli/democluster/demo_cluster_test.go +++ b/pkg/cli/democluster/demo_cluster_test.go @@ -126,6 +126,7 @@ func TestTestServerArgsForTransientCluster(t *testing.T) { // We cannot compare these. actual.Stopper = nil actual.StoreSpecs = nil + actual.Knobs.JobsTestingKnobs = nil assert.Equal(t, tc.expected, actual) }) From ee9b47b016288f80282a9e067011924b7163387f Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Wed, 15 Sep 2021 15:46:47 -0400 Subject: [PATCH 2/2] logictest: attempt to deflake "disallow full scans" test We've seen a couple of flakes on the testing of "disallow full scans" feature although I couldn't reproduce it manually. In an attempt to deflake the test, this commit increases the corresponding session variable as well as injects the stats manually instead of analyzing the table (to have more tight control over events). Release note: None --- pkg/sql/logictest/testdata/logic_test/select | 37 +++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/select b/pkg/sql/logictest/testdata/logic_test/select index 211d619279a7..a4cd0a652831 100644 --- a/pkg/sql/logictest/testdata/logic_test/select +++ b/pkg/sql/logictest/testdata/logic_test/select @@ -724,9 +724,11 @@ SELECT * FROM t44132 WHERE c0 true NULL # Tests for `disallow_full_table_scans` +statement ok +SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false + statement ok CREATE TABLE t_disallow_scans(a INT, b INT, INDEX b_idx(b)); -INSERT INTO t_disallow_scans VALUES (1, 1), (2, 1), (3, 1) statement ok SELECT * FROM t_disallow_scans @@ -741,11 +743,35 @@ SELECT * FROM t_disallow_scans statement error pq: query `SELECT \* FROM t_disallow_scans@b_idx` contains a full table/index scan which is explicitly disallowed SELECT * FROM t_disallow_scans@b_idx -# Disable 'large_full_scan_rows' heuristic and analyze the table in order to +# Disable 'large_full_scan_rows' heuristic and inject the stats in order to # test 'disallow_full_table_scans' in isolation. statement ok SET large_full_scan_rows = 0; -ANALYZE t_disallow_scans + +statement ok +ALTER TABLE t_disallow_scans INJECT STATISTICS '[ + { + "columns": ["rowid"], + "created_at": "2021-09-15 19:38:46.017315", + "distinct_count": 3, + "null_count": 0, + "row_count": 3 + }, + { + "columns": ["b"], + "created_at": "2021-09-15 19:38:46.017315", + "distinct_count": 1, + "null_count": 0, + "row_count": 3 + }, + { + "columns": ["a"], + "created_at": "2021-09-15 19:38:46.017315", + "distinct_count": 3, + "null_count": 0, + "row_count": 3 + } +]' statement error pq: query `SELECT \* FROM t_disallow_scans` contains a full table/index scan which is explicitly disallowed SELECT * FROM t_disallow_scans @@ -762,7 +788,7 @@ SELECT * FROM crdb_internal.jobs # Tests for 'large_full_scan_rows'. statement ok -SET large_full_scan_rows = 4 +SET large_full_scan_rows = 1000 # These queries succeed because the full table/index scans aren't considered # "large". @@ -784,7 +810,8 @@ SELECT * FROM t_disallow_scans@b_idx # Cleanup statement ok SET disallow_full_table_scans = false; -RESET large_full_scan_rows +RESET large_full_scan_rows; +RESET CLUSTER SETTING sql.stats.automatic_collection.enabled; # Regression test for #58104. statement ok