Repository navigation
Fix 02378_part_log_profile_events flakiness in the MergeParts section - #110640
alexey-milovidov merged 8 commits into
Conversation
The MergeParts check runs a single SYSTEM FLUSH LOGS immediately after OPTIMIZE TABLE ... FINAL, but a merge's part_log entry can be written asynchronously after OPTIMIZE returns, so count() occasionally reads 2 instead of the expected 3 (Error: 2). Apply the same retry-flush loop the MutatePart section already uses. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-4:20260716-061500 |
|
cc @CurtizJ — could you review this? Test-only fix: the MergeParts section asserted |
|
Workflow [PR], commit [cdede53] Summary: ✅ AI ReviewSummaryThis PR makes Final Verdict✅ No new findings. |
CI finish ledger — c8e05d5Every 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
Not PR-caused: this PR only touches the Session id: cron:our-pr-ci-monitor:20260716-110000 |
…inistic The MergeParts section waited for and asserted `count() > 2`, but that is not a property of the OPTIMIZE the section tests. The table has two partitions (PARTITION BY key >= 128) and `StorageMergeTree::optimize` with FINAL and no partition runs one foreground merge per partition (`selectAllPartsToMergeWithinPartition` returns a single choice covering all parts of the partition), so a fully logged OPTIMIZE FINAL produces exactly two MergeParts entries. The third entry the assertion required could only come from an incidental background merge, so the test passed only when extra merges happened to show up and reported `Error: 2` when they did not. Disable background merges for the table with max_bytes_to_merge_at_max_space_in_pool = 1 (merges started by OPTIMIZE FINAL ignore this setting) and assert the resulting deterministic values: exactly two MergeParts entries and exactly 512 merged rows. Measured on a debug build: with the setting pinned the previous `> 2` form fails 8/8 with `Error: 2`, the reported CI signature; without the pin the new `== 2` form fails because incidental background merges add entries; the committed combination passes 50/50.
Both merges that OPTIMIZE TABLE ... FINAL starts run synchronously inside the query: StorageMergeTree::merge builds a MergePlainMergeTreeTask and runs it via executeHere, which loops executeStep to completion, and MergePlainMergeTreeTask::finish calls write_part_log before returning. The part_log entries for both partitions are therefore already queued when OPTIMIZE returns, so the retry loop could never observe a late entry. Verified on a debug build: 50/50 passes with the loop removed.
…l string The previous commit wrapped literal names in backticks in every new comment, but the comment above CREATE TABLE is inside a double-quoted shell string, so the backticks were command substitutions: the test failed with "max_bytes_to_merge_at_max_space_in_pool: command not found" and every query after it ran against a broken statement. Keep the backticks only in the shell # comment, where they are inert, and note why the SQL comment cannot have them.
The comment explaining the new `max_bytes_to_merge_at_max_space_in_pool`
setting sat inside the double-quoted shell string holding the SQL, where a
backtick starts a command substitution, so the literal names could not be
wrapped in inline code blocks as the repository instructions require. Move it
above the `${CLICKHOUSE_CLIENT}` invocation, where backticks are inert, and
drop the parenthetical that explained the shell mechanics.
CI provenance of the flaky failure this pull request fixes:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108572&sha=6838c33f876538a34fdd6beb9de4320905ec3236&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29
The previous commit cites a CI report URL containing `PR=108572`; the repository instructions ask for the corresponding pull request link to accompany it. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108572&sha=6838c33f876538a34fdd6beb9de4320905ec3236&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29 Corresponding pull request: ClickHouse#108572
CI finish ledger - cdede53Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 174 check-runs on this head are This supersedes the earlier ledger keyed to Session id: cron:our-pr-ci-monitor:20260730-180000 |
Related: #108572
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
02378_part_log_profile_eventsis flaky in theMergePartssection: it assertedcount() > 2on theMergePartsrows written byOPTIMIZE TABLE test FINAL.That count is not a property of
OPTIMIZE.StorageMergeTree::optimizeloops over the partition ids and runs one foreground merge per partition, and the table has two partitions (PARTITION BY key >= 128), soOPTIMIZEitself contributes exactly two rows.count() > 2therefore passed only when unrelated background merges happened to have run first, and failed withError: 2when they had not.The fix makes both sides deterministic.
max_bytes_to_merge_at_max_space_in_pool = 1suppresses background merges, so the only merges in the table are the two driven byOPTIMIZE; the assertion becomes the exact expected values,count() == 2andMergedRows == 512. The setting is only consulted when selecting a background merge (OPTIMIZEgoes throughselectAllPartsToMergeWithinPartition, which does not read it), soOPTIMIZEstill merges every part of each partition. 36 stateless tests already pin this setting, and an explicit per-CREATESETTINGSclause wins over the runner's randomization, so no new tag is needed.This also removes the retry-flush loop added earlier in this pull request. It was unreachable:
StorageMergeTree::mergefinishes the merge withexecuteHere, whose loop runsMergePlainMergeTreeTask::finish->write_part_logbeforeOPTIMIZEreturns, so theMergePartsrows are always queued by the time the test flushes. A singleSYSTEM FLUSH LOGS part_logis sufficient. TheMutatePartsection keeps its own retry loop, which guards a genuinely asynchronous path.Validation (25-30 runs per arm, debug build): the pre-change
count() > 2assertion fails 12/12 once background merges are suppressed; the newcount() == 2assertion fails 30/30 if the pin is removed, so both edits are load-bearing; the committed form passes 30/30. Reference output unchanged.Failure sample (
Stateless tests (amd_tsan, parallel), PR #108572): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108572&sha=6838c33f876538a34fdd6beb9de4320905ec3236&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29Version info
26.8.1.602(included in26.8and later)