-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
69591: sql: deflake TestStatusAPIStatements and TestStatusAPICombinedStatements r=xinhaoz a=xinhaoz Fixes: #69557 As mentioned in #69533, we have a race condition in tests where we request statements stats with start=now. In these tests we expect to see no results, but because in-memory stats have the aggregated_ts field set on iterator return, depending on the time the test is run we might see results returned. For example, suppose we insert stats at 15:45. If we then request stats at 16:00, requesting only stats aggregated after or at the current time, i.e. start=16:00, the aggregated_ts for in-memory stats will be set to 16:00 and thus we will see results returned. To deflake these tests, we stub the aggregated_ts field to a predetermined value. Release justification: non-production code changes Release note: None 69592: sql: proper version gate sql stats r=maryliag,ajwerner a=Azhng Previously, SQL Stats's implementation for version gating is faulty. This means that SQL Stats's job monitor would attempt to start sql stats compaction job in an incompatible cluster. This commit fixed the faulty implementation. Resolves #69459 Resolves #69544 Resolves #69565 Release justification: Category 2: Bug fixes and low-risk updates to new functionality Release note: None Co-authored-by: Xin Hao Zhang <xzhang@cockroachlabs.com> Co-authored-by: Azhng <archer.xn@gmail.com>
- Loading branch information
Showing
4 changed files
with
105 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package persistedsqlstats_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/clusterversion" | ||
"github.com/cockroachdb/cockroach/pkg/server" | ||
"github.com/cockroachdb/cockroach/pkg/sql/tests" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
) | ||
|
||
func TestVersionGating(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
ctx := context.Background() | ||
params, _ := tests.CreateTestServerParams() | ||
params.Knobs.Server = &server.TestingKnobs{ | ||
DisableAutomaticVersionUpgrade: 1, | ||
BinaryVersionOverride: clusterversion.ByKey(clusterversion.SQLStatsCompactionScheduledJob - 1), | ||
} | ||
tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{ | ||
ServerArgs: params, | ||
}) | ||
|
||
defer tc.Stopper().Stop(ctx) | ||
|
||
sqlDB := sqlutils.MakeSQLRunner(tc.ServerConn(0 /* idx */)) | ||
sqlDB.CheckQueryResults(t, | ||
"SELECT count(*) FROM [SHOW SCHEDULES FOR SQL STATISTICS]", | ||
[][]string{{"0"}}) | ||
|
||
sqlDB.Exec(t, `SET CLUSTER SETTING version = $1`, | ||
clusterversion.ByKey(clusterversion.SQLStatsCompactionScheduledJob).String()) | ||
|
||
// Change the recurrence cluster setting to force job monitor to create the | ||
// sql stats compaction schedule. | ||
sqlDB.Exec(t, "SET CLUSTER SETTING sql.stats.cleanup.recurrence = '@daily'") | ||
|
||
// Wait for the change to be picked up by the job monitor. | ||
sqlDB.CheckQueryResultsRetry(t, | ||
"SELECT recurrence FROM [SHOW SCHEDULES FOR SQL STATISTICS]", | ||
[][]string{{"@daily"}}) | ||
|
||
sqlDB.CheckQueryResults(t, | ||
"SELECT count(*) FROM [SHOW SCHEDULES FOR SQL STATISTICS]", | ||
[][]string{{"1"}}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters