Skip to content

Commit 9c9b6dc

Browse files
changefeedccl: remove two usages of disableDeclarativeSchemaChangesForTest
This change removes two usages of `disableDeclarativeSchemaChangesForTest` from tests and replaces them with `maybeDisableDeclarativeSchemaChangesForTest` which will use the legacy schema changer 10% of the time. Release note: None Informs: cockroachdb#106906 Epic: None
1 parent e9add29 commit 9c9b6dc

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

pkg/ccl/changefeedccl/alter_changefeed_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,11 +1103,19 @@ func TestAlterChangefeedAddTargetsDuringSchemaChangeError(t *testing.T) {
11031103
defer leaktest.AfterTest(t)()
11041104
defer log.Scope(t).Close(t)
11051105

1106-
rnd, _ := randutil.NewPseudoRand()
1106+
rnd, seed := randutil.NewPseudoRand()
1107+
t.Logf("random seed: %d", seed)
11071108

11081109
testFn := func(t *testing.T, s TestServerWithSystem, f cdctest.TestFeedFactory) {
11091110
sqlDB := sqlutils.MakeSQLRunner(s.DB)
1110-
disableDeclarativeSchemaChangesForTest(t, sqlDB)
1111+
usingLegacySchemaChanger := maybeDisableDeclarativeSchemaChangesForTest(t, sqlDB, rnd)
1112+
// NB: For the `ALTER TABLE foo ADD COLUMN ... DEFAULT` schema change,
1113+
// the expected boundary is different depending on if we are using the
1114+
// legacy schema changer or not.
1115+
expectedBoundaryType := jobspb.ResolvedSpan_RESTART
1116+
if usingLegacySchemaChanger {
1117+
expectedBoundaryType = jobspb.ResolvedSpan_BACKFILL
1118+
}
11111119

11121120
knobs := s.TestingKnobs.
11131121
DistSQL.(*execinfra.TestingKnobs).
@@ -1182,10 +1190,9 @@ func TestAlterChangefeedAddTargetsDuringSchemaChangeError(t *testing.T) {
11821190
return true, nil
11831191
}
11841192

1185-
// A backfill begins when the backfill resolved event arrives, which has a
1186-
// timestamp such that all backfill spans have a timestamp of
1187-
// timestamp.Next()
1188-
if r.BoundaryType == jobspb.ResolvedSpan_BACKFILL {
1193+
// A backfill begins when the associated resolved event arrives, which has a
1194+
// timestamp such that all backfill spans have a timestamp of timestamp.Next().
1195+
if r.BoundaryType == expectedBoundaryType {
11891196
backfillTimestamp = r.Timestamp
11901197
return false, nil
11911198
}

pkg/ccl/changefeedccl/changefeed_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,8 @@ func TestChangefeedSchemaChangeBackfillCheckpoint(t *testing.T) {
18661866
defer leaktest.AfterTest(t)()
18671867
defer log.Scope(t).Close(t)
18681868

1869-
rnd, _ := randutil.NewPseudoRand()
1869+
rnd, seed := randutil.NewPseudoRand()
1870+
t.Logf("random seed: %d", seed)
18701871

18711872
// This test asserts that a second checkpoint made after resumption does its
18721873
// best to not lose information from the first checkpoint, therefore the
@@ -1876,7 +1877,14 @@ func TestChangefeedSchemaChangeBackfillCheckpoint(t *testing.T) {
18761877

18771878
testFn := func(t *testing.T, s TestServerWithSystem, f cdctest.TestFeedFactory) {
18781879
sqlDB := sqlutils.MakeSQLRunner(s.DB)
1879-
disableDeclarativeSchemaChangesForTest(t, sqlDB)
1880+
usingLegacySchemaChanger := maybeDisableDeclarativeSchemaChangesForTest(t, sqlDB, rnd)
1881+
// NB: For the `ALTER TABLE foo ADD COLUMN ... DEFAULT` schema change,
1882+
// the expected boundary is different depending on if we are using the
1883+
// legacy schema changer or not.
1884+
expectedBoundaryType := jobspb.ResolvedSpan_RESTART
1885+
if usingLegacySchemaChanger {
1886+
expectedBoundaryType = jobspb.ResolvedSpan_BACKFILL
1887+
}
18801888

18811889
knobs := s.TestingKnobs.
18821890
DistSQL.(*execinfra.TestingKnobs).
@@ -1957,10 +1965,10 @@ func TestChangefeedSchemaChangeBackfillCheckpoint(t *testing.T) {
19571965
return true, nil
19581966
}
19591967

1960-
// A backfill begins when the backfill resolved event arrives, which has a
1968+
// A backfill begins when the associated resolved event arrives, which has a
19611969
// timestamp such that all backfill spans have a timestamp of
1962-
// timestamp.Next()
1963-
if r.BoundaryType == jobspb.ResolvedSpan_BACKFILL {
1970+
// timestamp.Next().
1971+
if r.BoundaryType == expectedBoundaryType {
19641972
backfillTimestamp = r.Timestamp
19651973
return false, nil
19661974
}

pkg/ccl/changefeedccl/helpers_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ import (
5858

5959
var testSinkFlushFrequency = 100 * time.Millisecond
6060

61+
// disableDeclarativeSchemaChangesForTest will disable the declarative schema
62+
// changer with a probability of 10% using the provided SQL DB connection. This
63+
// returns true if the declarative schema changer is disabled.
64+
func maybeDisableDeclarativeSchemaChangesForTest(
65+
t testing.TB, sqlDB *sqlutils.SQLRunner, rnd *rand.Rand,
66+
) bool {
67+
disable := rnd.Float32() < 0.1
68+
if disable {
69+
t.Log("using legacy schema changer")
70+
sqlDB.Exec(t, "SET use_declarative_schema_changer='off'")
71+
sqlDB.Exec(t, "SET CLUSTER SETTING sql.defaults.use_declarative_schema_changer='off'")
72+
}
73+
return disable
74+
}
75+
6176
// disableDeclarativeSchemaChangesForTest tests that are disabled due to differences
6277
// in changefeed behaviour and are tracked by issue #80545.
6378
func disableDeclarativeSchemaChangesForTest(t testing.TB, sqlDB *sqlutils.SQLRunner) {

0 commit comments

Comments
 (0)