Skip to content

Fix flaky 03100_lwu_15_future_reads - #112158

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-lwu-15-future-reads-patch-parts-cleanup
Jul 28, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-lwu-15-future-reads-patch-parts-cleanup

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

03100_lwu_15_future_reads is flaky. It ends with

SELECT sum(rows) FROM system.parts
WHERE database = currentDatabase() AND table = 't_lwu_future_reads' AND startsWith(name, 'patch');

and expects 200, but that query was racing against the background cleanup thread.

Once OPTIMIZE TABLE ... FINAL has applied the patches, the data version of the merged part reaches the patches' max data version, so clearUnusedPatchParts considers both patch parts unused and drops them. For ReplicatedMergeTree the drop goes through a DROP_PART log entry, which removes the parts outright rather than leaving them Outdated, so they disappear from system.parts and the last query returns 0 - or 100, when only one of them had been dropped yet.

On a fast runner the test finishes long before the first iteration of the cleanup thread, so the race is invisible. On a loaded runner it gets a turn before the last query; accordingly, all observed failures are on amd_tsan, amd_msan and flaky checks. The two sums the test checks were always correct, so this is a test-only race and not a product bug.

The fix pins remove_unused_patch_parts = 0 on the table, the same way 03100_lwu_01_basics and other lightweight-update tests already do, so the patch parts stay in place for the final check. The future-reads check itself is unaffected.

Verified locally on a ReplicatedMergeTree setup by making the cleanup thread run every second (cleanup_delay_period = 1) and widening the window before the last query, which turns the race into a deterministic failure:

  • without this change the test fails with exactly the diff seen in CI (-200 / +0);
  • with this change the test passes (repeated runs, including with randomized settings).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=107275200b9ab432ec9375a091aad62690484bfd&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Version info

  • Merged into: 26.8.1.302 (included in 26.8 and later)

The test ends with

    SELECT sum(rows) FROM system.parts
    WHERE ... AND startsWith(name, 'patch')

and expects `200`, but that query was racing against the background cleanup
thread.

Once `OPTIMIZE TABLE ... FINAL` has applied the patches, the data version of the
merged part reaches the patches' max data version, so `clearUnusedPatchParts`
considers both patch parts unused and drops them. For `ReplicatedMergeTree` the
drop goes through a `DROP_PART` log entry, which removes the parts outright
rather than leaving them `Outdated`, so they disappear from `system.parts` and
the last query returns `0` - or `100`, when only one of them had been dropped
yet.

On a fast runner the test finishes long before the first iteration of the
cleanup thread, so the race is invisible. On a loaded runner it gets a turn
before the last query; accordingly, all observed failures are on `amd_tsan`,
`amd_msan` and flaky checks.

Pin `remove_unused_patch_parts = 0` on the table, the same way
`03100_lwu_01_basics` and other lightweight-update tests already do, so the
patch parts stay in place for the final check. The future-reads check itself is
unaffected.

Reproduced locally by making the cleanup thread run every second: without this
change the test fails with exactly the diff seen in CI (`-200` / `+0`), with it
the test passes.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=107275200b9ab432ec9375a091aad62690484bfd&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9101372]

Summary: ✅


AI Review

Summary

This PR makes 03100_lwu_15_future_reads deterministic by pinning remove_unused_patch_parts = 0 on the test table, so the final system.parts assertion no longer races the background cleanup thread after OPTIMIZE TABLE ... FINAL. I did not find a remaining correctness, coverage, or metadata issue in the current change: it preserves the future-read scenario and only stabilizes the observability of the final patch-part count.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 27, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.

@alexey-milovidov alexey-milovidov self-assigned this Jul 28, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 28, 2026
Merged via the queue into master with commit 8d6e684 Jul 28, 2026
178 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-lwu-15-future-reads-patch-parts-cleanup branch July 28, 2026 19:14
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants