Skip to content

Fix flaky test 05227_mutate_part_ahead_of_table_metadata_version_mergetree - #127925

Merged
Avogar merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-05227-mutate-part-ahead-empty-part
Oct 28, 2026
Merged

Avogar merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-05227-mutate-part-ahead-empty-part

Conversation

@groeneai

@groeneai groeneai commented Oct 27, 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: #120817 (adds the test), #121121 (reported there).

The test printed the rewrite dropped the column: 1 instead of 0, twice on the same master base: Stateless tests (arm_binary, parallel) and Fast test.

Root cause: DETACH PARTITION 1 covers 1_1_1_0 with an empty part 1_1_1_1 that still has column c (it is built before DROP COLUMN c). It is outdated only in memory and stays on disk for old_parts_lifetime (480 s), so every later clickhouse-local process loads it as active. Startup clearEmptyParts hides it, except while outdated parts are still loading, which is the case from the DELETE on (1_3_3_0 stays on disk). So after the DELETE, 1_1_1_1 is active until the pending mutations rewrite it in the background; if that rewrite has not committed before the system.parts_columns query, the test sees c.

Change: old_parts_lifetime = 0 for the test table, so 1_1_1_1 is removed from disk inside the DETACH PARTITION statement. Test only.

Validation, local debug build of the failing base:

  • after the first statement block 1_1_1_1 with c is on disk in 20/20 runs before, 0/20 after;
  • forcing the losing side of the race (pending mutation files moved aside before the query): 1 in 20/20 runs before, 0 in 20/20 after;
  • 1500 runs of the fixed test, 48 at a time on 16 cores, pass with the debug build and with the CI amd_binary. The race itself did not reproduce locally (0 of 4884 runs of the unmodified test).

On a server the cleanup thread hides such a part right after outdated parts finish loading; only short-lived clickhouse-local processes hit the window, so the engine is unchanged.


Workflow [PR]
Sync PR [sync-upstream/pr/127925]

Version info

  • Merged into: 26.11.1.850-master (included in 26.11 and later)

…etree

`ALTER TABLE ... DETACH PARTITION 1` covers the inserted part with a new empty
part `1_1_1_1`. It is built from the covered part's columns, so it still has
column `c` (the test drops `c` only afterwards). `clearEmptyParts` outdates it
in memory only, and it stays on disk for `old_parts_lifetime` (480 s).

Every `local_query` is a separate `clickhouse-local` process over the same
path, and each one loads `1_1_1_1` as an active part again. At startup
`clearEmptyParts` hides it, but not while outdated parts are still loading
asynchronously (the guard from ClickHouse#98698). The `DELETE` leaves the outdated
`1_3_3_0` on disk, so from then on every process keeps `1_1_1_1` active until
the pending mutations rewrite it in the background. When that rewrite has not
committed before the `system.parts_columns` query, the query sees `c` and the
test prints `the rewrite dropped the column: 1` (seen in `Stateless tests
(arm_binary, parallel)` and `Fast test`).

Set `old_parts_lifetime = 0` for the test table, so the empty part is removed
from disk inside the `DETACH PARTITION` statement and no later process can
load it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test does not assert that the empty part is gone after setup, so reverting old_parts_lifetime = 0 does not fail it deterministically DISAGREE Not guaranteed even with the fix: grabOldParts yields nothing while the cleanup thread holds grab_old_parts_mutex (MergeTreeData.cpp:4851-4854), so the assertion would add a failure mode. Both directions shown outside the test: empty part with c after setup 20/20 before vs 0/20 after; forced early read 1 20/20 before vs 0 20/20 after.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261027-083000

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the defect state and the failing query: empty 1_1_1_1 with c on disk after setup 20/20; with pending mutation files moved aside after the DELETE, the query returns 1 20/20. The CI timing did not reproduce locally (0 of 4884 runs).
b Root cause explained? DETACH PARTITION leaves an empty covering part with c on disk for old_parts_lifetime; later clickhouse-local processes load it as active and startup clearEmptyParts skips it while outdated parts load, so it is visible until its background rewrite commits.
c Fix matches root cause? Yes: old_parts_lifetime = 0 removes the part from disk in the statement that creates it. No widened assertion, no tag, no src/ change.
d Test intent preserved / new tests added? Yes: every assertion and the .reference are unchanged; the part-ahead-of-metadata mutation path is exercised as before.
e Both directions demonstrated? Yes: 20/20 vs 0/20 (fixture state), 20/20 1 vs 20/20 0 (forced query), 0/3000 stress failures with the fix.
f Fix is general across code paths? N/A (test fixture). Sibling clickhouse-local tests checked: none leaves an empty covering part next to an outdated one.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (one table setting in one test).
h Backward compatible? (maintainer-approved exception only) Yes, test only.
i Invariants and contracts preserved? Yes: engine code untouched; after the DELETE the only active part is the rewritten one.

Session id: cron:clickhouse-impl-slot-4:20261027-072500

@clickhouse-gh

clickhouse-gh Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1033610]

Summary: ✅


AI Review

Summary

PR #127925 sets old_parts_lifetime = 0 in the affected test fixture, allowing immediate cleanup of the empty covering part left by DETACH PARTITION before subsequent clickhouse-local processes reopen the table. The mutation regression assertions remain intact. No actionable findings at 1033610919b0c6408ec81bee3d150d811568b958; the focused test passes in the current Fast test report.

Final Verdict

Status: ✅ Approve.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tiandiwonder, could you review this and add the can be tested label so CI runs? DETACH PARTITION leaves an empty covering part that still has the dropped column on disk for old_parts_lifetime, and every later clickhouse-local process keeps it active because startup clearEmptyParts skips it while outdated parts load (the guard from #98698), so the test sets old_parts_lifetime = 0.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 27, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 27, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 1033610

Every failure below has an owner: a fixing PR (mine 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
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / Some queries hung flaky, not from this PR: the only hung query is the parallel replicas secondary read of 04117_detach_database_kill_query (is_initial_query: 0, sleepEachRow(3), is_cancelled: 0, 197 s), while this PR changes only the 05227 test #127149 (mine, open)
Mergeable Check, PR praktika rollups of the row above #127149 (the owner of the row above)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261027-193015

@Avogar Avogar self-assigned this Oct 28, 2026
@Avogar
Avogar added this pull request to the merge queue Oct 28, 2026
@alexey-milovidov alexey-milovidov mentioned this pull request Oct 28, 2026
1 task done
Merged via the queue into ClickHouse:master with commit 86fbe53 Oct 28, 2026
700 of 703 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 28, 2026
@clickhouse-gh clickhouse-gh Bot added comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). and removed comp-testing Test content only (no production code). labels Nov 22, 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 comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). 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.

5 participants