Skip to content

Fail CHECK TABLE that a shutdown aborted, instead of reporting broken data - #119381

Merged
alexey-milovidov merged 10 commits into
masterfrom
fix-check-table-shutdown-abort-115748
Oct 7, 2026
Merged

alexey-milovidov merged 10 commits into
masterfrom
fix-check-table-shutdown-abort-115748

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

CHECK TABLE on a ReplicatedMergeTree replica whose Keeper session was lost now fails with ABORTED instead of returning 0, which means that the check found broken data. Nothing was read in that case, so the healthy table was certified as broken.

Documentation entry for user-facing changes

...

A ReplicatedMergeTree replica that has lost its Keeper session enters partial shutdown, and checkDataNext then throws ABORTED before reading anything. TableCheckTask::checkNext turned that into a check result with an empty part path and is_passed = 0, and marked the task finished, so the remaining parts were never looked at and CHECK TABLE t SETTINGS check_query_single_value_result = 1 answered 0 — the value documented to mean that the check found an error in the data — on a table whose data is intact. Monitoring that alerts, quarantines or re-replicates on 0 fires on every Keeper flap; a few seconds earlier in the same outage the query correctly fails with KEEPER_EXCEPTION.

Rethrow it, like every other retryable error at that catch site (isRetryableException already treats ABORTED as retryable; it was excluded explicitly). CHECK TABLE then fails with ABORTED and Table shutdown was called, which is what a check that could not run should say, and 0 keeps meaning that a part failed its data check.

The same partial shutdown also calls part_check_thread.stop(), which cancels a part check that is already running. ReplicatedMergeTreePartCheckThread::checkPartImpl returned that as {success = false, "Checking part was cancelled"} for a healthy part, so the query still answered 0 in that window. checkPartAndFix now takes throw_if_cancelled; the foreground CHECK TABLE path passes it and gets ABORTED as well, while the background part check thread keeps dropping cancelled results silently.

checkDataNext looks at the shutdown flags only when there is a part left to check, so a shutdown that starts after the last part was checked does not turn the final end-of-list call into a failure.

The new check_table_inject_shutdown_abort and check_table_inject_part_check_cancelled failpoints abort or cancel the check the way a partial shutdown does, so the test does not have to take a Keeper session down.

New test: 05227_check_table_shutdown_abort, next to 04506_check_table_retryable_zk_error, which covers the neighbouring window. test_check_replicated_does_not_block_shutdown accepted the 0 result while Keeper was killed mid-check - the false broken-data report this change removes - and now requires the query to fail with a Keeper error or ABORTED.

Closes: #115748


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

Version info

  • Merged into: 26.10.1.1723-master (included in 26.10 and later)

…en data

A `ReplicatedMergeTree` replica that has lost its Keeper session enters partial shutdown, and
`checkDataNext` then throws `ABORTED` before reading anything. `TableCheckTask::checkNext` turned that
into a check result with an empty part path and `is_passed = 0`, and marked the task finished, so the
remaining parts were never looked at and `CHECK TABLE t SETTINGS check_query_single_value_result = 1`
answered `0` - the value documented to mean that the check found an error in the data - on a table
whose data is intact. Monitoring that alerts, quarantines or re-replicates on `0` fires on every
Keeper flap; a few seconds earlier in the same outage the query correctly fails with
`KEEPER_EXCEPTION`.

Rethrow it, like every other retryable error at that catch site (`isRetryableException` already treats
`ABORTED` as retryable; it was excluded explicitly). `CHECK TABLE` then fails with `ABORTED` and
`Table shutdown was called`, which is what a check that could not run should say, and `0` keeps
meaning that a part failed its data check.

The new `check_table_inject_shutdown_abort` failpoint aborts the check the way a partial shutdown
does, so the test does not have to take a Keeper session down.

Closes: #115748
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0141460]

Summary: ✅


AI Review

Summary

This PR fixes the two shutdown-triggered false-negative CHECK TABLE cases on ReplicatedMergeTree: it now rethrows ABORTED when the replica enters partial shutdown before a part check starts or while an in-flight part check is being cancelled, and it avoids spuriously failing the final EOF probe after the last part. The targeted regression tests look good, but the touched CHECK TABLE contract is still incomplete: retryable read failures that checkDataPart converts into an empty checksum result can still make both replicated and plain MergeTree checks report success without a full scan.

Findings
  • ⚠️ Majors
    • [src/Storages/MergeTree/checkDataPart.cpp:603] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/119381#discussion_r4045929514] checkDataPart still swallows retryable read failures by returning {}. The replicated caller ignores that return value entirely and logs Part {} looks good. (src/Storages/MergeTree/ReplicatedMergeTreePartCheckThread.cpp:403, src/Storages/MergeTree/ReplicatedMergeTreePartCheckThread.cpp:419), and the plain MergeTree path likewise returns success after checkDataPart (src/Storages/StorageMergeTree.cpp:4220). So CHECK TABLE can still return 1 even though no full data scan completed, which violates the new “retryable => fail the query, not emit a verdict row” contract for a broad class of transient S3 / socket / ENOMEM / cache errors. Suggested fix: make checkDataPart report an explicit “not checked / retryable” state and propagate that as a retryable exception from both callers instead of overloading empty checksums as success.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: either propagate the checkDataPart retryable-empty state so CHECK TABLE never reports success without a completed scan, or narrow the change / contract so this PR no longer claims transient check failures are handled generically beyond the shutdown-specific ABORTED cases it actually fixes.

LLVM Coverage Report

Measured on commit 0141460.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 37/40 (92.50%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 11, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. label Sep 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 0141460ac5b825c31cdc2c87b696ebac00329730 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

alexey-milovidov and others added 2 commits September 18, 2026 09:19
The previous commit made `checkDataNext` rethrow the `ABORTED` it throws when
a shutdown is already in progress before the part check starts. A partial
shutdown also calls `part_check_thread.stop()`, which flips `need_stop` under
a part check that is already running. `checkPartImpl` then returned
`{success = false, "Checking part was cancelled"}` for a healthy part, and
`CHECK TABLE ... SETTINGS check_query_single_value_result = 1` still answered
`0` on intact data.

`checkPartAndFix` now takes `throw_if_cancelled`; the foreground `CHECK TABLE`
path passes it and gets `ABORTED`, which `isRetryableException` treats as
retryable, so the query fails instead of reporting broken data. The background
part check thread keeps dropping cancelled results silently.

The new `check_table_inject_part_check_cancelled` failpoint drives that branch
in the test, which is renumbered to the next free number, 05227.

`test_check_replicated_does_not_block_shutdown` accepted a `0` result while
Keeper was killed mid-check; that was exactly the false broken-data report this
PR removes, so the test now requires the query to fail with a Keeper error or
`ABORTED`.

Addresses the review thread on `StorageReplicatedMergeTree.cpp`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Unrelated failures in the last CI run:

@groeneai, investigate the upgrade-check failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119381&sha=d897f0cba3442e9ef871f9f6b8797a75e62c5faa&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

The test_check_replicated_does_not_block_shutdown failures were caused by this PR and are fixed in 1f12091.

@groeneai

Copy link
Copy Markdown
Collaborator

🕵 The upgrade-check failure in that run is the t_mt_index_rp carrier of #110518: the server aborts in ParallelReplicasReadingCoordinator::handleRequest on Got read request from replica 1 for unknown stream test_y0o1t6z3u2n9.t_mt_index_rp.

That exposure came from the upgrade check's own option generator. It drew serialize_query_plan=1 into the parallel-replicas arm, and the pre-upgrade load runs against the previous release, which fails on that path, so no change to master could fix it there. I removed the draw in #119406, merged 2026-09-11 10:25:59Z, about four hours after your run started at 06:39Z. Public CIDB agrees: 34 rows on this carrier, all between 2026-09-11 00:22Z and 14:13Z (the tail being branches still carrying the old generator), then 0 across the 1,774 distinct commits Upgrade check (amd_release) has run since.

What was still open is whether the same failure is reachable with master on both sides. I left that unproven in the route census on #110518. It is now proven, in the Stress test lanes, where every replica runs the build under test and the serialize_query_plan draw is still live: 2026-09-14 23:32Z Stress test (amd_asan_ubsan), stream test_7.t0 (#114823, bystander), and 2026-09-17 23:28Z Stress test (amd_debug), stream test_3.t_mt_index_rp (#117212, bystander). The t_mt_index_rp carrier is the mergeTreeAnalyzeIndexes(...) query in 04891_mergetree_index_respects_row_policy, so that shape is join-free.

Merged already, for the join-bearing routes of the same message: #118084 (a replica re-orders a shipped join) and #119861 (join_algorithm = 'direct' into a MergeTree right table under plan-based parallel replicas, #119372).

Nothing is in progress for the join-free route. I am taking it, and I will link the PR here.

@groeneai

Copy link
Copy Markdown
Collaborator

I traced the upgrade-check failure to its source. It is the parallel-replicas symptom of #112891, and my fix for that is already open: #114955. My earlier note here was wrong to say nothing is in progress, and wrong about the statement: it is not mergeTreeAnalyzeIndexes.

The failing statement, both on your run and on the one recurrence since #119406 (Stress test (amd_debug), master on both sides, 2026-09-17 23:28), is 04891_mergetree_index_respects_row_policy.sql line 17, SELECT id, department FROM t_mt_index_rp ORDER BY id. The table is ORDER BY (department, id) and the policy is USING department = 'engineering'. There is no join in the plan.

From your job's own server log:

  • Initiator: Key condition: (column 0 in ['engineering', 'engineering']), 2/4 marks, Spreading ranges among streams with order, Created coordinator for stream test_y0o1t6z3u2n9.t_mt_index_rp#split_0 with mode WithOrder, total streams: 1. The policy filter fixes department, so ORDER BY id matches the second key position, the read is planned in order, and in-order parallel-replicas reads suffix the stream id with #split_i.
  • Followers, (stage: QueryPlan): Received query plan, then Key condition: unknown, 4/4 marks, Spreading mark ranges among streams (default reading). The shipped plan carries no row-level filter, so nothing is fixed, no in-order read is derived, and the default pool announces the bare test_y0o1t6z3u2n9.t_mt_index_rp.
  • Coordinator: Ignoring announcement from non-snapshot replica 0/1 for unknown stream test_y0o1t6z3u2n9.t_mt_index_rp. The default pool then discards the announcement response by design, so it never learns the stream is unknown and sends a read request for it anyway, which is the LOGICAL_ERROR.

The same log shows the other half of #112891 directly: the followers selected 4/4 marks where the policy allows 2/4.

#114955 replans the read on the executing server with that server's own policies, which restores the fixed column, so both sides derive the same coordination mode and the same stream id. The regression test currently on that branch cannot reach this shape, because its policy is a range on a non-key column and no in-order read is ever planned, so I am pinning this shape there as well.

Two notes on scope. Your run aborted on the pre-upgrade 26.8.2.7 server, so no change to master can clear that lane, which is why #119406 removed the serialize_query_plan draw from the upgrade check; the defect itself is on master and the Stress test (amd_debug) recurrence proves it. And the sibling abort on the same table, Coordination mode mismatch for stream ...: got Default, expected WithOrder, is the same divergence with a policy value that matches no row.

alexey-milovidov and others added 7 commits September 19, 2026 20:48
`StorageReplicatedMergeTree::checkDataNext` checked the shutdown flags before
pulling the next part, so the final call that only reports the end of the part
list threw `ABORTED` if a partial shutdown began after every part was checked,
turning a completed check into a failure. Check the flags only when there is a
part to check.

Also disable the fail points in `05227_check_table_shutdown_abort` explicitly
(the style check requires it) and cover the empty table, whose check consists
of that final call alone.

Addresses the review comment about the end-of-list call in `checkDataNext`.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119381&sha=a556bf3c7f156d611fdb0e282f674d7667fcb38b&name_0=PR

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

alexey-milovidov commented Oct 5, 2026 •

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119381&sha=d46a59af6c91e199a9fd5e5bacff15cdc94a2da6&name_0=PR&name_1=Upgrade%20check%20(amd_release) and provide a fix in a separate PR. If the fix is already in progress, link it here.

Upgrade check (amd_release): Logical error: 'Part all_2_2_1 intersects next part all_2_7_1' while loading a table at startup (DatabaseOrdinary::loadTableFromMetadata). This PR only changes CHECK TABLE / the part-check thread, not part loading. CIDB shows the same error in the last 30 days on master (Stress tests, 2026-10-03) and on unrelated PRs (#111956, #122986, #122853, #122136, #121997, #111663, #107960, #115393, #119819, #90740, #119949). Possibly related: #122212, #120980.

I merged the latest master into the branch to re-run CI.

@groeneai

groeneai commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Same failure as on #119181, not caused by this PR. The STID differs (2002-2037 instead of 3562-39cd) only because the six frames between the exception and createTableFromAST are unsymbolized in this run; the message without "in the ZooKeeper data" is the one from PartLoadingTree::add.

From the logs of this run (table test_y3a6b7v6m3n0.test, test 02561_null_as_default_more_formats.sh):

  • In the stress phase on the previous release 26.9.10.4, truncate table test failed in MetadataOperationsHolder::commit() with an injected memory fault after tmp_empty_all_2_2_1 .. tmp_empty_all_6_6_1 had been renamed to their final names, and the rollback (Undoing transaction ... Removing parts: all_2_2_1 ...) left them on disk.
  • 0.2 s later a merge wrote all_2_7_1 from all_2_2_0 .. all_7_7_0.
  • The upgraded server started 3 minutes later, inside old_parts_lifetime, and could not load the table: all_2_2_1 and all_2_7_1 have the same level, so neither contains the other.

The fix is in progress: #122375 (yours, removes the rolled back empty parts in renameAndCommitEmptyParts right away) and #121708 (mine). As on #119181, the leftover is written by the previous release binary, so this red continues until the fix is in a 26.9 release.

About the master hits of 2026-10-03:

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks, @groeneai. Agreed: the Part all_2_2_1 intersects next part all_2_7_1 failure in Upgrade check (amd_release) comes from rolled-back empty parts that the previous release left behind, so it is unrelated to this PR, which only changes CHECK TABLE and the part-check thread. The fixes are tracked in #122375 and #121708. The latest CI run on this PR (after merging master on 2026-10-05) is green, so nothing else is needed here.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Though the comment is not easy to read.

@alexey-milovidov alexey-milovidov self-assigned this Oct 7, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 7, 2026
Merged via the queue into master with commit d40d48c Oct 7, 2026
150 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-check-table-shutdown-abort-115748 branch October 7, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

3 participants