Repository navigation
Conversation
test_broken_projections/test.py::test_mutation_with_broken_projection is a chronic flaky integration test (tracked in ClickHouse#63002): the first CHECK TABLE on the freshly created and inserted table returns 0 (broken) before anything is deliberately broken, so the test fails with 'assert 1 == 0'. The table is created with aggressive background merges enabled (max_parts_to_merge_at_once=3), but the test asserts exact per-source-part lineage names throughout (all_N_N_0 -> _4 -> _5 -> _6) and never needs a background merge to combine parts. When a background merge fires near the first CHECK TABLE, CHECK observes a freshly merged or in-flight part whose projections are transiently inconsistent and reports it broken, returning 0. Disable background merges for this test only. SYSTEM STOP MERGES cannot be used here: on ReplicatedMergeTree it cancels merger_mutator.merges_blocker, which the replication queue checks for both MERGE_PARTS and MUTATE_PART, so it would also block the test's synchronous (mutations_sync=1) ALTER DELETEs. Instead set max_bytes_to_merge_at_max_space_in_pool=1, which stops background merge selection (getMaxSourcePartsBytesForMerge returns 0) while mutation selection uses a separate gate (getMaxSourcePartBytesForMutation) and is unaffected. The setting is scoped via a new disable_background_merge flag so sibling tests (e.g. test_broken_ignored, which needs a background merge) are unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Tracked flaky issue: #63002 (named explicitly in that issue as the most-frequent failure; confirmed still broken). Session id: cron:clickhouse-worker-slot-1:20260611-202600 |
|
cc @CurtizJ — could you review this? It fixes the chronic flaky |
|
Workflow [PR], commit [b159ed3] Summary: ✅ AI ReviewSummaryThis PR now only disables background merges in Findings
Final Verdict
|
|
I didn't expect that projections could be inconsistent inside the data parts. Maybe it is a fundamental problem. In ClickHouse, either the data part is invisible (being created with the tmp_ prefix) or fully consistent. All changes to data parts went through mutations, where the new data part is created with hardlinks to the old one, and materializes all the missing parts while it is still not committed. When it is committed, it is fully consistent. If projections break this approach, we are in trouble. CC @amosbird |
|
@alexey-milovidov you are right, and my PR description was wrong. I traced the part lifecycle and your invariant holds: there is no projection-consistency bug here. I have retracted the "transiently inconsistent committed part" wording and corrected the description. The invariant holds (a committed/Active part is fully consistent, projections included). In a merge the new part's projection parts are attached and the whole part is finalized (checksums written) before it becomes visible:
So a part becomes visible only after it is fully written, exactly as you said for mutations. There is no window where a visible part has inconsistent projections. The flaky
I cannot prove the exact server-side cause of each historical Why the fix is test-only. The early phase asserts the exact unmerged layout ( If you would prefer a different direction (making CHECK retry transient ZK errors, or having the test poll rather than disable merges), I am happy to follow your call. |
@groeneai, What is the reason CHECK query does it this way? Can it work similarly to SELECT queries in this regard - take a snapshot of data parts, hold it during the operation, and process every data part? |
|
@alexey-milovidov Good question. Short answer: the parts snapshot is already held, and the non-replicated check already works the way you describe. The replicated path re-resolves by name on purpose, for a reason specific to replication, and that re-resolution is not what produces the spurious The snapshot is already held. Why the replicated path re-resolves by name. So a held-snapshot CHECK is fine for the local data validation, and feasible since the snapshot is right there, but it cannot replace the ZK reconciliation, which is the whole point of CHECK on a replicated table and is name/ZK-keyed by nature. The spurious
Concrete fix. The minimal fundamental fix is to make replicated |
…t_mutation_with_broken_projection
…jection With background merges disabled from table creation, the dual-branch tolerance around the third ALTER DELETE is dead: nothing can repair the broken projection, so all_2_2_0_5 must stay broken and CHECK TABLE must return 0. Require that deterministically instead of tolerating either outcome, so the test keeps proving the hardlink invariant it covers. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Thanks, both points are correct. Addressed: Point 2 (tighten the hardlink invariant) - done in e7a6009. With background merges disabled from table creation, the Point 1 (the workaround only shifts probability) - agreed. I traced the two paths that turn a healthy
So this PR is a genuine but partial mitigation. It removes the merge-driven churn that dominates the failure rate in this test (the empirical result: 0 local failures across the runs above), but it does not close path 2. Correction to my earlier reply: I said the non-replicated The fundamental fix is to make It is a user-visible behavior change to |
Pre-PR validation gate (click to expand) - updated for the tightened assertion
Session id: cron:clickhouse-worker-slot-0:20260705-210500 |
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 1410 line(s), 61 function(s) across 36 file(s) · Details Top files
|
CI finish ledger — e7a6009CI fully finished on this head (Finish Workflow / Mergeable Check / PR all green). No test failure rows in CIDB; the only red check is the private upstream sync.
Session id: cron:our-pr-ci-monitor:20260706-000000 |
Yes, let's fix CHECK TABLE so it will retry retriable Keeper errors. Then the changes in the test may be unnecessary anymore. |
|
@alexey-milovidov Will do. I'll put up a separate PR that makes CHECK TABLE retry retriable Keeper errors instead of reporting the part broken, at the two catch sites that currently collapse them to One care point: the interpreter catch was added to swallow the shutdown Once it lands I'll re-check whether the test-only merge-disable change here is still needed and drop it if not. |
|
Opened #109465 for the fundamental fix: it makes |
A replicated CHECK reconciles each local part against ZooKeeper. A transient Keeper hardware error (connection loss, session expired) thrown during that reconciliation was collapsed into CheckResult(false), so CHECK TABLE returned a spurious 0 on a healthy table. checkPartImpl already re-throws retryable errors, but two outer catch sites defeated that: StorageReplicatedMergeTree::checkDataNext and InterpreterCheckQuery::TableCheckTask::checkNext. Wrap the per-part check in ZooKeeperRetriesControl (bounded by the existing keeper_max_retries / keeper_retry_*_backoff_ms settings) so a transient blip is retried. On retry exhaustion the Keeper hardware error is re-thrown instead of reported as a broken part; the interpreter catch does the same. The guard is narrowed to Coordination::Exception with isHardwareError, so the shutdown ABORTED exception the interpreter catch was originally added for (a plain DB::Exception, not Coordination::Exception) is still swallowed, and genuine corruption or missing parts still report CheckResult(false) as before. New failpoint check_data_part_zk_hardware_error injects a retriable Keeper error on the query check path; the regression test asserts CHECK returns 1 after a retriable error is retried and throws (not 0) when retries are disabled. Requested by Alexey Milovidov in ClickHouse#107290 (comment) Co-Authored-By: Claude Opus 4.8 <[email protected]>
A replicated CHECK reconciles each local part against ZooKeeper. A transient Keeper hardware error (connection loss, session expired) thrown during that reconciliation was collapsed into CheckResult(false), so CHECK TABLE returned a spurious 0 on a healthy table. checkPartImpl already re-throws retryable errors, but two outer catch sites defeated that: StorageReplicatedMergeTree::checkDataNext and InterpreterCheckQuery::TableCheckTask::checkNext. Wrap the per-part check in ZooKeeperRetriesControl (bounded by the existing keeper_max_retries / keeper_retry_*_backoff_ms settings) so a transient blip is retried. On retry exhaustion the Keeper hardware error is re-thrown instead of reported as a broken part; the interpreter catch does the same. The guard is narrowed to Coordination::Exception with isHardwareError, so the shutdown ABORTED exception the interpreter catch was originally added for (a plain DB::Exception, not Coordination::Exception) is still swallowed, and genuine corruption or missing parts still report CheckResult(false) as before. New failpoint check_data_part_zk_hardware_error injects a retriable Keeper error on the query check path; the regression test asserts CHECK returns 1 after a retriable error is retried and throws (not 0) when retries are disabled. Requested by Alexey Milovidov in ClickHouse#107290 (comment) Co-Authored-By: Claude Opus 4.8 <[email protected]>
… part On a healthy part, the only way `CHECK TABLE` returns 0 (part reported broken) is a thrown exception. Transient/retryable errors - most notably ZooKeeper hardware errors such as connection loss or session expiration on a `ReplicatedMergeTree` table - were silently converted into a "broken" result at two catch sites: - `StorageReplicatedMergeTree::checkDataNext` had a blanket `catch (const Exception &)` that returned `CheckResult(name, false, ...)`, unlike `StorageMergeTree::checkDataNext` which already re-throws retryable exceptions. - `InterpreterCheckQuery::TableCheckTask::checkNext` also blanket-caught and returned a false result for every storage. This is the false-negative behind the chronic flaky `test_broken_projections/test.py::test_mutation_with_broken_projection` (ClickHouse#63002): aggressive background merges add ZooKeeper/IO churn that raises the transient-error rate on the first `CHECK TABLE`. Now both catch sites re-throw retryable exceptions (via `isRetryableException`), so a transient error surfaces as a retryable query error instead of a spurious 0. The interpreter catch still swallows the shutdown `ABORTED` exception it was originally added for (`isRetryableException` treats `ABORTED` as retryable, so it is excluded explicitly). Adds a `check_table_inject_retryable_zk_error` failpoint and a stateless regression test that injects a transient ZooKeeper error during `CHECK TABLE` and asserts it throws rather than returning a broken row for a healthy part. Related: ClickHouse#63002 Related: ClickHouse#107290 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
@groeneai, the fundamental fix #109465 has merged into That closes the transient-error path we identified as the real root cause behind
Either direction is fine — your call. |
…tion_with_broken_projection
|
@groeneai I refreshed this branch by merging the latest |
| table_name = "test1" | ||
| create_table(node, table_name, 1) | ||
| # Asserts exact per-source-part lineage names and never needs a merge. | ||
| create_table(node, table_name, 1, disable_background_merge=True) |
There was a problem hiding this comment.
#109465 is now in master, and that change fixed the actual flaky path here: CHECK TABLE no longer collapses retryable Keeper errors into a spurious 0, and #63002 is already closed. After that merge, this line is no longer "fix the flake"; it just changes test_mutation_with_broken_projection to run with background merges disabled all the time.
If you still want this, I think it needs to be re-scoped as pure test hardening and justified on its own merits, because it narrows the test away from the normal background-merge configuration without showing a remaining failure on current master. Otherwise I would drop it now that the underlying CHECK TABLE bug is already fixed.
|
@alexey-milovidov thanks for the refresh. CIDB confirms #109465 de-flaked it on its own: since that merge (2026-07-07 02:35Z), So the test-only |
CI finish ledger — b159ed3Every failure below has an owner. Only
No PR-caused failure; CIDB shows zero FAIL/ERROR test rows on this head. This head is @alexey-milovidov's master-merge (b159ed3) which pulls in the merged #109465; the PR content itself is unchanged (test-only Session id: cron:our-pr-ci-monitor:20260714-070000 |
… part On a healthy part, the only way `CHECK TABLE` returns 0 (part reported broken) is a thrown exception. Transient/retryable errors - most notably ZooKeeper hardware errors such as connection loss or session expiration on a `ReplicatedMergeTree` table - were silently converted into a "broken" result at two catch sites: - `StorageReplicatedMergeTree::checkDataNext` had a blanket `catch (const Exception &)` that returned `CheckResult(name, false, ...)`, unlike `StorageMergeTree::checkDataNext` which already re-throws retryable exceptions. - `InterpreterCheckQuery::TableCheckTask::checkNext` also blanket-caught and returned a false result for every storage. This is the false-negative behind the chronic flaky `test_broken_projections/test.py::test_mutation_with_broken_projection` (ClickHouse#63002): aggressive background merges add ZooKeeper/IO churn that raises the transient-error rate on the first `CHECK TABLE`. Now both catch sites re-throw retryable exceptions (via `isRetryableException`), so a transient error surfaces as a retryable query error instead of a spurious 0. The interpreter catch still swallows the shutdown `ABORTED` exception it was originally added for (`isRetryableException` treats `ABORTED` as retryable, so it is excluded explicitly). Adds a `check_table_inject_retryable_zk_error` failpoint and a stateless regression test that injects a transient ZooKeeper error during `CHECK TABLE` and asserts it throws rather than returning a broken row for a healthy part. Related: ClickHouse#63002 Related: ClickHouse#107290 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Related: #63002
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
test_broken_projections/test.py::test_mutation_with_broken_projectionis a chronic flaky integration test (tracked in #63002). The firstCHECK TABLEon the freshly created and inserted table returns0(broken) before anything is deliberately broken, so the test fails withassert 1 == 0.This is not a projection-consistency bug. A committed (Active) data part is always fully consistent on disk, projections included: a merge attaches the new projection parts and finalizes the whole part (
addProjectionPart->finalizePart->precommitTransaction,MergeTask.cpp:2084/2088/2100) before the part becomes visible, and the visibility flip is atomic underdata_parts_lockin aNOEXCEPT_SCOPE(covered parts -> Outdated, merged part -> Active,MergeTreeData::Transaction::commit,MergeTreeData.cpp:8836-8903). (Thanks to @alexey-milovidov for catching the incorrect "transiently inconsistent committed part" explanation in the original description.)Root cause of the spurious
0. On a healthy part the only route toCHECK TABLE = 0is a thrown exception, and transient ZooKeeper/network errors are converted toCheckResult(false)->0at two catch sites:StorageReplicatedMergeTree::checkDataNext(StorageReplicatedMergeTree.cpp:10280-10285) andInterpreterCheckQuery::TableCheckTask::checkNext(InterpreterCheckQuery.cpp:149-154).checkPartImplre-throws retryable errors (ReplicatedMergeTreePartCheckThread.cpp:398-399), but both outer catches defeat that. The aggressive background merges in this test (max_parts_to_merge_at_once=3) add ZooKeeper and IO churn during the per-part check and raise the rate of that transient error, so the failure clusters on the firstCHECK TABLE.Scope of this PR (test-only mitigation). This PR removes the dominant trigger by disabling background merges for this test only, so the assertion window is stable. It does not fix the underlying silent-
0-on-transient-error behavior ofCHECK TABLE; that fundamental fix (re-throw retryable errors instead of reporting the part broken) is discussed in the PR thread and is best landed as a separate PR since it is a user-visible behavior change.SYSTEM STOP MERGEScannot be used here: onReplicatedMergeTreeit cancelsmerger_mutator.merges_blocker, which the replication queue checks for bothMERGE_PARTSandMUTATE_PART(ReplicatedMergeTreeQueue.cpp:1746), so it would also block the test's synchronousALTER ... DELETEs. Instead setmax_bytes_to_merge_at_max_space_in_pool=1, which stops background merge selection (getMaxSourcePartsBytesForMergereturns0,CompactionStatistics.cpp:107) while mutation selection uses a separate gate (getMaxSourcePartBytesForMutation) and is unaffected. The setting is scoped via a newdisable_background_mergeflag, so sibling tests (e.g.test_broken_ignored, which needs a background merge) are unchanged.With merges disabled, the later branch around the third
ALTER ... DELETEcan no longer "not be broken because of a merge", so the dual-branch tolerance there is tightened to requireall_2_2_0_5to stay broken andCHECK TABLEto return0, keeping the hardlink invariant the test covers.Verified locally: the test passes 20/20 runs through the integration runner with the fix.