Skip to content

Commit 08ffd5d

Browse files
committed
changefeedccl: deflake TestChangefeedSchemaTTL
Previously, TestChangefeedSchemaTTL started flaking when create_table_with_schema_locked was enabled by default in the test suite. This happened because schema_locked tables can cause historical versions of descriptors to be cached in the lease manager, as the changefeed logic intentionally queries prior versions. As a result, even after the test garbage-collected the descriptors table, these old versions could remain in the in-memory cache, leading to flakes. To address this, this patch adds a canary schema change, which bumps the descriptor's version. When a descriptor's version is bumped, all older cached versions are purged. Fixes: cockroachdb#149167 Release note: None
1 parent 9e8fbe3 commit 08ffd5d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/ccl/changefeedccl/changefeed_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6545,6 +6545,7 @@ func TestChangefeedSchemaTTL(t *testing.T) {
65456545
// Create the data table; it will only contain a single row with multiple
65466546
// versions.
65476547
sqlDB.Exec(t, `CREATE TABLE foo (a INT PRIMARY KEY, b STRING)`)
6548+
sqlDB.Exec(t, `CREATE USER joe`)
65486549

65496550
counter := 0
65506551
upsertRow := func() {
@@ -6575,6 +6576,15 @@ func TestChangefeedSchemaTTL(t *testing.T) {
65756576
// table to be deleted, with the middle version being lost to the changefeed.
65766577
forceTableGC(t, s.SystemServer, sqlDB, "system", "descriptor")
65776578

6579+
// Do an unnecessary version bump on the descriptor, which will purge old
6580+
// versions of the descriptor that the lease manager may have cached for
6581+
// historical queries. When schema_locked support is active, the act of
6582+
// detecting polling inside pauseOrResumePolling can cause old versions
6583+
// to be cached. The historical descriptors are cleared everytime a
6584+
// version bump occurs, otherwise this test can flake if the prior versions
6585+
// need to decode a row is already cached.
6586+
waitForSchemaChange(t, sqlDB, "ALTER TABLE foo OWNER TO joe")
6587+
65786588
// Resume our changefeed normally.
65796589
atomic.StoreInt32(&shouldWait, 0)
65806590
resume <- struct{}{}

0 commit comments

Comments
 (0)