Skip to content

Fix flaky 03100_lwu_06_apply_patches - #114135

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-03100-lwu-06-apply-patches
Aug 10, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-03100-lwu-06-apply-patches

Conversation

@groeneai

@groeneai groeneai commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

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

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

Related: #110202

The test asserted a patch part the engine is entitled to drop, so it lost the
patch-...-all_0_0_0_2 15 row from a system.parts listing:
failing report.

clearUnusedPatchParts drops a patch once its max source data version is <= the
minimum data version among the partition's active regular parts. The
ALTER ... APPLY PATCHES, UPDATE brings that minimum to 3, so from that point on the
patch with version 2 is droppable while the one with version 4 is not. That asymmetry
is exactly the observed diff, and it licenses the drop before all three of the test's
part listings, not only the last one. The OPTIMIZE ... FINAL does not lower the minimum.

The cleanup_delay_period = 1000 the test relied on is not a barrier: the first cleanup
iteration is scheduled with no delay, and wakeup is a bare task->schedule() that
bypasses the delay from any of its call sites. So I pin remove_unused_patch_parts = 0
instead and drop the two delay settings it replaces. Same one-line idiom as #100273
(03100_lwu_01_basics) and #112158 (03100_lwu_15_future_reads), which pin it against
the same background drop. The .reference is unchanged.

Validated in both directions on one provoked state whose arms differ only in the pin:
forcing a cleanup wakeup reproduces exactly the CI diff with
Will drop unused patch part patch-...-all_0_0_0_2 in the log, and with the pin the same
provoked run passes with that log line absent. 50/50 randomized runs pass.

I measured the data version of every part in the 9 tests that assert literal patch-part
names. Of those, only this one and the already-pinned 03100_lwu_01_basics reach the drop
condition, so I left the other 7 alone. Tests that assert patch state in aggregate rather
than by name are outside that set; 03100_lwu_15_future_reads and
03100_lwu_51_condition_evaluated_once are already pinned.

Version info

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

The test lists patch parts after `OPTIMIZE ... FINAL` and asserted a patch part
the engine is entitled to drop at that point, so it intermittently lost the
`patch-...-all_0_0_0_2` row from a `system.parts` listing.

`MergeTreeData::clearUnusedPatchParts` drops a patch once its max source data
version is <= the minimum data version among the partition's active regular
parts. The `ALTER ... APPLY PATCHES, UPDATE` brings that minimum to 3, so from
that point on the patch with version 2 is droppable while the one with version
4 is not. That asymmetry is exactly the observed diff, and it licenses the drop
before all three of the test's part listings, not only the last one. The
`OPTIMIZE ... FINAL` does not lower the minimum, it only merges the two regular
parts into one; with `apply_patches_on_merge = 0` it does not consume the
patches either.

The `cleanup_delay_period = 1000` the test relied on was never a barrier:
`IMergeTreeCleanupThread::start` schedules the first iteration with no delay
(the delay only applies from the second iteration on), and `wakeup` is a bare
`task->schedule` that bypasses the delay from any of its call sites. On
`ReplicatedMergeTree` there is also no further interval gate before the patch
cleanup.

Pin `remove_unused_patch_parts = 0` instead and drop the two superseded delay
settings, matching the existing idiom in `03100_lwu_01_basics` and
`03100_lwu_15_future_reads`. The `.reference` file is unchanged.

Validated in both directions on a single provoked state whose arms differ only
in the pin value: forcing a cleanup `wakeup` between the `OPTIMIZE` and the
final listing reproduces exactly the CI diff together with the
`Will drop unused patch part` log line, and with the pin the same provoked run
passes with that log line absent. 50/50 randomized runs pass.

I measured the data version of every part in the 9 stateless tests whose
`.reference` asserts literal patch-part names. Of those, only this one and the
already-pinned `03100_lwu_01_basics` reach the drop condition, so no other test
is touched. Tests that assert patch state in aggregate rather than by name are
outside that set; `03100_lwu_15_future_reads` and
`03100_lwu_51_condition_evaluated_once` are already pinned.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110202&sha=702986aef420b1b00b18acf938bf37f9d3844e9d&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20parallel%29
Related: ClickHouse#110202
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (3 rounds, 0 blockers) - click to expand

Three independent review rounds over this one-line test pin. All findings were in
maintainer-facing prose; the change itself (remove_unused_patch_parts = 0, two
superseded delay settings removed, .reference untouched) was never altered after
round 0.

# Round Finding Verdict
❌ r0 Comment and commit message placed the drop window after OPTIMIZE ... FINAL; the arithmetic puts it at the ALTER ... APPLY PATCHES, UPDATE, so all three part listings are inside it AGREE, fixed
⚠️ r1 Commit message claimed no other patch-asserting test reaches the drop condition; 03100_lwu_15_future_reads does and is already pinned, which contradicted #112158 AGREE, fixed
💡 r1 Repo rule on inline code for SQL literals in comments and commit messages AGREE, applied
⚠️ r2 Description called #100273 a fix for "this failure"; its CI row is an added covering patch part, not a missing one, so it is the same setting and drop path but a different observable AGREE, wording narrowed
💡 r0 Gate suggested the test also assert the drop happens with the setting on DISAGREE: a two-arm provoked pair already exists, and adding a drop trigger to a test whose reference asserts the patch is present is self-defeating

Also noticed and deliberately not raised: no test covers the positive
remove_unused_patch_parts = 1 side. Pre-existing, no user-reachable consequence,
0 CI occurrences.

Session id: cron:clickhouse-review-slot-10:20260810-100800

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Forcing a cleanup wakeup (SYSTEM STOP CLEANUP + SYSTEM START CLEANUP) between the OPTIMIZE ... FINAL and the final system.parts listing fails on demand with exactly the CI diff (only patch-...-all_0_0_0_2 15 missing, _4 retained), plus Will drop unused patch part patch-...-all_0_0_0_2 in the server log. Not a probabilistic repro.
b Root cause explained? Yes. clearUnusedPatchParts drops a patch whose max source data version is <= the minimum data version of the partition's active regular parts. Measured after the OPTIMIZE: sole regular part all_0_1_1_3 has data version 3, patch _2 has 2 (droppable), patch _4 has 4 (kept). The test's cleanup_delay_period = 1000 was never a barrier: the first cleanup iteration is scheduled with no delay, and wakeup() is a bare task->schedule() that bypasses the delay from any call site.
c Fix matches root cause? Yes. remove_unused_patch_parts = 0 makes clearUnusedPatchParts return early, disabling the exact path that removed the row. Not a widened bound, not a data reduction, not a blanket no-random-* tag. The engine behaviour is correct; the test over-asserted.
d Test intent preserved / new tests added? Yes, preserved. The .reference is byte-identical and every assertion, including both patch-part names and their row counts, is unchanged. No new test is needed: this makes an existing test deterministic and changes no product code.
e Both directions demonstrated? Yes, on one provoked state whose two arms differ only in the pin value (proven by diffing the arms with the setting line filtered out). Unpinned: fails with exactly the CI diff, 1 drop log line. Pinned: passes 4/4, 0 drop log lines. Re-confirmed after a server restart.
f Fix is general across code paths? Yes. All 9 stateless tests asserting patch-part rows were measured, not inferred: only this test and the already-pinned 03100_lwu_01_basics can reach the drop condition; the other 7 keep the minimum regular-part data version below every patch version. Only two clearUnusedPatchParts call sites exist and there is no other patch-drop path, so no engine change is warranted.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only table-setting pin, no input matrix). The randomization dimension is covered: the relevant settings appear 0 times in tests/clickhouse-test, and 50/50 randomized runs pass.
h Backward compatible? (maintainer-approved exception only) Yes, trivially. Test-only change, no src/ edit, no setting default changed, so no SettingsChangesHistory.cpp entry, no serialization or format change, no user-visible behaviour.
i Invariants and contracts preserved? Yes. No code is touched, so no pre/postcondition, data-structure invariant or concurrency contract is affected. The setting is scoped to a table this test creates and drops, so the blast radius is this test only.

Session id: cron:clickhouse-impl-slot-4:20260810-063700

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Michicosun, could you review this? Same pin you added in #100273, here for 03100_lwu_06_apply_patches: after ALTER ... APPLY PATCHES the regular parts reach data version 3, so clearUnusedPatchParts may drop the version-2 patch the test asserts, and the cleanup_delay_period the test relied on never gated that window.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4ca5499]

Summary: ❌

job_name test_name status info comment
Stress test (arm_msan) FAIL
Hung check failed, possible deadlock found FAIL cidb IGNORED

AI Review

Summary

This PR makes 03100_lwu_06_apply_patches deterministic by pinning remove_unused_patch_parts = 0 instead of relying on cleanup-delay settings that do not actually guarantee the version-2 patch part survives until the test's system.parts assertions. I did not find a correctness or coverage regression in the current diff: clearUnusedPatchParts is gated only by that setting, the dedicated cleanup behavior is still exercised separately in 03100_lwu_17_cleanup, and the current PR CI is green.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 10, 2026
@PedroTadim PedroTadim self-assigned this Aug 10, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 4ca5499

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (arm_msan) / Hung check failed, possible deadlock found chronic trunk deadlock, 55 unrelated PRs + 2 master runs in 14 days, 0 relation to this test-only diff #113140 (external, open)
Build (arm_release) / Post Hooks CIDB bookkeeping row; the GitHub check itself concluded success not a failure of this build

03100_lwu_06_apply_patches, the test this PR pins, is green on this head everywhere it ran,
including 200 flaky-check runs across four sanitizers.

Session id: cron:our-pr-ci-monitor:20260810-160000

@PedroTadim
PedroTadim added this pull request to the merge queue Aug 10, 2026
Merged via the queue into ClickHouse:master with commit fffccf8 Aug 10, 2026
179 of 181 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 10, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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.

4 participants