Skip to content

Commit 813a079

Browse files
changefeedccl: fix row count in nemeses test
There was a bug in this test where, when using the declarative schema changer, we would increment the running row count by a factor of 3 when doing addColumn/dropColumn operations. This behavior aligns with the legacy schema changer where we expect to see two backfills. For the declarative schema changer, we should only double the row count because we see one backfill. In cockroachdb#108155, this bug was caused the rowcount would be incorrectly nonzero which would cause test would get stuck waiting for rows to be emitted. Fixes: cockroachdb#108155 Release note: None Epic: None
1 parent c5c821a commit 813a079

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

pkg/ccl/changefeedccl/cdctest/nemeses.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
// real output of a changefeed. The output rows and resolved timestamps of the
3131
// tested feed are fed into them to check for anomalies.
3232
func RunNemesis(
33-
f TestFeedFactory, db *gosql.DB, isSinkless bool, rng *rand.Rand,
33+
f TestFeedFactory, db *gosql.DB, isSinkless bool, withLegacySchemaChanger bool, rng *rand.Rand,
3434
) (Validator, error) {
3535
// possible additional nemeses:
3636
// - schema changes
@@ -54,9 +54,10 @@ func RunNemesis(
5454
eventPauseCount = 0
5555
}
5656
ns := &nemeses{
57-
maxTestColumnCount: 10,
58-
rowCount: 4,
59-
db: db,
57+
withLegacySchemaChanger: withLegacySchemaChanger,
58+
maxTestColumnCount: 10,
59+
rowCount: 4,
60+
db: db,
6061
// eventMix does not have to add to 100
6162
eventMix: map[fsm.Event]int{
6263
// We don't want `eventFinished` to ever be returned by `nextEvent` so we set
@@ -262,6 +263,8 @@ type addColumnPayload struct {
262263
}
263264

264265
type nemeses struct {
266+
withLegacySchemaChanger bool
267+
265268
rowCount int
266269
maxTestColumnCount int
267270
eventMix map[fsm.Event]int
@@ -692,9 +695,14 @@ func addColumn(a fsm.Args) error {
692695
if err := ns.db.QueryRow(`SELECT count(*) FROM foo`).Scan(&rows); err != nil {
693696
return err
694697
}
695-
// We expect one table scan that corresponds to the schema change backfill, and one
696-
// scan that corresponds to the changefeed level backfill.
697-
ns.availableRows += 2 * rows
698+
if ns.withLegacySchemaChanger {
699+
// We expect one table scan that corresponds to the schema change backfill, and one
700+
// scan that corresponds to the changefeed level backfill.
701+
ns.availableRows += 2 * rows
702+
} else {
703+
// We expect to see a backfill
704+
ns.availableRows += rows
705+
}
698706
return nil
699707
}
700708

@@ -715,9 +723,14 @@ func removeColumn(a fsm.Args) error {
715723
if err := ns.db.QueryRow(`SELECT count(*) FROM foo`).Scan(&rows); err != nil {
716724
return err
717725
}
718-
// We expect one table scan that corresponds to the schema change backfill, and one
719-
// scan that corresponds to the changefeed level backfill.
720-
ns.availableRows += 2 * rows
726+
if ns.withLegacySchemaChanger {
727+
// We expect one table scan that corresponds to the schema change backfill, and one
728+
// scan that corresponds to the changefeed level backfill.
729+
ns.availableRows += 2 * rows
730+
} else {
731+
// We expect to see a backfill
732+
ns.availableRows += rows
733+
}
721734
return nil
722735
}
723736

pkg/ccl/changefeedccl/nemeses_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ func TestChangefeedNemeses(t *testing.T) {
3232
t.Logf("random seed: %d", seed)
3333

3434
sqlDB := sqlutils.MakeSQLRunner(s.DB)
35-
_ = maybeDisableDeclarativeSchemaChangesForTest(t, sqlDB, rng)
35+
withLegacySchemaChanger := maybeDisableDeclarativeSchemaChangesForTest(t, sqlDB, rng)
3636
// TODO(dan): Ugly hack to disable `eventPause` in sinkless feeds. See comment in
3737
// `RunNemesis` for details.
3838
isSinkless := strings.Contains(t.Name(), "sinkless")
39-
v, err := cdctest.RunNemesis(f, s.DB, isSinkless, rng)
39+
v, err := cdctest.RunNemesis(f, s.DB, isSinkless, withLegacySchemaChanger, rng)
4040
if err != nil {
4141
t.Fatalf("%+v", err)
4242
}

0 commit comments

Comments
 (0)