Skip to content

Decouple 04321_table_readonly_background_merges from the global TTL merge slot count - #119884

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/04321-pin-ttl-merge-slots
Sep 19, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/04321-pin-ttl-merge-slots

Conversation

@groeneai

@groeneai groeneai commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #110326
Related: #111925

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

Requested by @ alexey-milovidov in #110326 (comment), where this test failed on the private mirror with writable control table TTL did not run in the background.

max_number_of_merges_with_ttl_in_pool is per-table, but StorageMergeTree::selectPartsToMerge compares it against MergeTreeData::getTotalMergesWithTTLInMergeList(), the single per-server MergeList::merges_with_ttl_counter, and MergeSelectorApplier gates every TTL selector behind that comparison. The default is 2 and this test left both TTL tables there, so two concurrent TTL merges on any other table in the same parallel-run server keep the writable control table's expired part undropped for the whole 60 s window, with no leak involved. The same predicate makes the negative assertion pass for the wrong reason: readonly ttl rows: 2 holds just as well when no table in the server could schedule a TTL merge at all.

So I pin the setting on both TTL tables, as 02293_part_log_has_merge_reason.sh and 01921_concurrent_ttl_and_normal_merges_zookeeper_long.sh already do, and dump system.parts and system.merges on a wait timeout, on the failure path only. .reference is unchanged.

Measured on a debug build: with two TTL merges from another database holding the counter, the pinned table's expired part is dropped while they run and the unpinned one waits for them. Mutation arms, 3 runs each: writable pin to 0 goes red with the dump rendered; deleting the read-only marking goes red (readonly ttl rows: 1); the same deletion with the read-only pin at 0 goes green, the vacuity that second pin removes. Final state passes 50/50 with randomization on.

This does not replace #111925, which fixes the engine-side booking leak on the DROP/DETACH path: that leak is one way to reach this state, and the coupling needs none. The failing job is private and unreadable with my credentials, so the analysis is from public sources. I did not measure 04267_ttl_drop_merge_no_data_read, named alongside this test in the 2026-08-07 comment on #96130.


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

Version info

  • Merged into: 26.10.1.216 (included in 26.10 and later)

…erge slot count

max_number_of_merges_with_ttl_in_pool is a per-table setting, but
StorageMergeTree::selectPartsToMerge compares it against
MergeTreeData::getTotalMergesWithTTLInMergeList(), which returns the single
per-server MergeList::merges_with_ttl_counter, and MergeSelectorApplier gates
every TTL selector, TTLPartDropMergeSelector included, behind that comparison.
The setting defaults to 2, so two concurrent TTL merges on any other table in
the same parallel-run server keep this test's writable control table from
dropping its expired part for the whole 60 s window, which is the
"writable control table TTL did not run in the background" failure. The same
predicate also makes the following negative assertion pass for the wrong
reason: "readonly ttl rows: 2" holds just as well when no table in the server
could have scheduled a TTL merge at all.

Pin the setting on both TTL tables so the assertions depend only on this
test's own tables, as 02293_part_log_has_merge_reason.sh and
01921_concurrent_ttl_and_normal_merges_zookeeper_long.sh already do for the
same reason. Measured on a debug build: with the pin the expired part is
dropped while two TTL merges from another database hold the counter, without it
the drop is not selected until the counter frees.

Dump system.parts and system.merges on a wait timeout, on the failure path
only, so the next red says which of the three causes it was: other tables
holding the global TTL slots, a pool busy with something else, or nothing ever
selected for these tables.

Requested by @ alexey-milovidov in
ClickHouse#110326 (comment)

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-review-human PR origin: human review feedback on a groeneai PR labels Sep 14, 2026
@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) plus my own cold pass
(4 nits). No finding was accepted, so nothing changed after the gate; here is the reasoning, and
one line from a maintainer overrules any of it.

# Sev Finding Verdict Evidence
1 ⚠️ The test creates no competing TTL merges, so it passes with or without the two pins; add an in-test fixture that holds two TTL merges and check the pinned table proceeds. DISAGREE Conceded that the script creates no contention. What I dispute is that this leaves the pins unverified, and the prescription. The contention was measured out of band, twice: two row-TTL tables in another database holding 2 slots, plus two controls differing only in the pin, oracle system.part_log ordering. Pinned: MergePartsStart TTLDropMerge while the counter is at 2. Default: nothing until 113 ms after the last hog finished. The arms are exact, not approximate: at StorageMergeTree.cpp:1733 the predicate is getTotalMergesWithTTLInMergeList() < max_number_of_merges_with_ttl_in_pool, so = 0 is unconditionally false and reproduces an exhausted counter deterministically (writable pin 0: red 3/3; table_readonly removed with pin 100: red 3/3, readonly ttl rows: 1; same with the read-only pin at 0: green 3/3, the vacuity that pin removes). Shipping the fixture instead would make this test hold 2 of the server-global slots itself, which is the interference being removed and would stall every parallel test left at the default of 2; the hogs needed 10M rows per table and an 80M variant died on the memory cap. Neither in-tree pin of this setting carries such a fixture (02293_part_log_has_merge_reason.sh:20, 01921_concurrent_ttl_and_normal_merges_zookeeper_long.sh:28).
2 💡 ReplicatedMergeTree reads the same predicate and was not enumerated. DISAGREE Verified benign: StorageReplicatedMergeTree.cpp:4489-4490 ANDs a per-table-queue term (default 1, and one TTL merge is needed) with the same server-global term, which is the one pinned.
3 💡 04267_ttl_drop_merge_no_data_read has the same exposure with tighter windows. DISAGREE True, and disclosed in the description. Inside 30 days CIDB shows one failure on an unrelated PR, below the bar I use to open work, so I am not raising it.
4 💡 The pin lets this test push the global counter past a default-limit table's threshold. DISAGREE Bounded to 2 drop merges of one tiny expired part each, measured at 2 ms; both precedents above do more.
5 💡 On a timeout the server-merges section prints a bare header when nothing is merging. DISAGREE Unambiguous: a failed read prints merges dump failed instead, so a bare header can only mean nothing is in flight.

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

Session id: cron:clickhouse-review-slot-8:20260914-043600

@clickhouse-gh clickhouse-gh Bot closed this Sep 14, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 14, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, on demand, not a percentage. Two tables of the control table's exact shape differing only in max_number_of_merges_with_ttl_in_pool: at 100 the expired part is dropped in under a second, at 0 it is still there after 69 s (120 polls). 0 makes count < limit false unconditionally, an exact stand-in for an exhausted counter.
b Root cause explained? Yes. StorageMergeTree.cpp:1733 compares the per-table max_number_of_merges_with_ttl_in_pool (default 2, MergeTreeSettings.cpp:571) against getTotalMergesWithTTLInMergeList(), which is the single per-server MergeList::merges_with_ttl_counter (MergeTreeData.cpp:13139, MergeList.h:161); MergeSelectorApplier.cpp:220 gates every TTL selector, TTLPartDropMergeSelector included, behind it. Two concurrent TTL merges anywhere in the server therefore stall this test's control table for its whole window, and make its negative assertion vacuous.
c Fix matches root cause? Yes: it pins the exact setting the predicate reads, on exactly the two tables whose TTL behaviour is asserted. Not a widened window (with the counter occupied no timeout is long enough), not a no-parallel tag, not a reduced dataset, no defensive guard.
d Test intent preserved / new tests added? Preserved and strengthened; .reference is byte-identical and both oracles are unchanged. This is itself the test fix, so no new test file. Arm A2 (delete the read-only marking) proves the negative assertion is live; arm A3 proves the second pin removes a real vacuity.
e Both directions demonstrated? Yes. Final state: 50/50 pass with randomization on. Deliberately broken: writable pin to 0 fails 3/3 with the dump rendered; SYSTEM START MERGES withheld from the first control table fails 3/3 at the first wait; read-only marking deleted fails 3/3 with readonly ttl rows: 1.
f Fix is general across code paths? Both TTL tables are pinned, and both FAIL paths get the dump (one arm each). The non-TTL first table pair needs nothing: hasAnyTTL() is false there, so the flag is never consulted. Sibling tests that depend on this counter already pin it (02293_part_log_has_merge_reason.sh:20, 01921_concurrent_ttl_and_normal_merges_zookeeper_long.sh:28); the ttl_* tests that set it to 0 do so deliberately to suppress TTL merges and are unaffected.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for a test-setting fix: no new code path and no type or parameter surface. The pin is value-independent above the largest reachable global count; 100 matches the in-tree precedent.
h Backward compatible? (maintainer-approved exception only) N/A. Test-only: no setting default changed, no SettingsChangesHistory.cpp entry, no format or gate change.
i Invariants and contracts preserved? Yes. An explicit SETTINGS clause beats the runner's randomizer, so the pin cannot be overridden, and the MergeTree randomizer touches no TTL or merge-slot setting. The dump runs only after a FAIL: line has already broken the diff, so happy-path stdout is unchanged, which the untouched .reference and the 50/50 pass both confirm. Each dump is timeout 30-guarded with a fallback line, so a hung system-table read cannot swallow the output of an already-failing test.

Session id: cron:clickhouse-impl-slot-5:20260914-004600

@clickhouse-gh

clickhouse-gh Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3110c6c]

Summary: ✅


AI Review

Summary

This PR hard-pins max_number_of_merges_with_ttl_in_pool on the two TTL tables in 04321_table_readonly_background_merges.sh and adds failure-path state dumps so the test no longer depends on unrelated server-global TTL merge-slot usage. I traced the touched MergeTree selection path against the current code and the fix matches the actual guard that made the original assertion flaky; I did not find any new correctness, coverage, or PR-metadata issues in the current diff.

Final Verdict

✅ Approved

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Sep 14, 2026
@PedroTadim PedroTadim assigned PedroTadim and unassigned PedroTadim Sep 14, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 19, 2026
Merged via the queue into ClickHouse:master with commit 4580174 Sep 19, 2026
176 of 348 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 Sep 19, 2026
@clickhouse-gh clickhouse-gh Bot added comp-background-ops Background pools/scheduling for merges, cleanup, maintenance. 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-background-ops Background pools/scheduling for merges, cleanup, maintenance. groeneai-origin-review-human PR origin: human review feedback on a groeneai PR 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