Skip to content

Make CHECK TABLE retry retryable errors instead of reporting a broken part - #109465

Merged
tiandiwonder merged 5 commits into
masterfrom
check-table-retry-retryable-errors
Jul 7, 2026
Merged

tiandiwonder merged 5 commits into
masterfrom
check-table-retry-retryable-errors

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 6, 2026 •

Copy link
Copy Markdown
Member

CHECK TABLE on a ReplicatedMergeTree table could report a healthy part as broken (return 0) when it hit a transient, retryable error — most notably a ZooKeeper hardware error such as connection loss or session expiration — during the check.

On a healthy part the only way CHECK TABLE returns 0 is a thrown exception, and two catch sites silently converted retryable exceptions into a "broken" result:

  • StorageReplicatedMergeTree::checkDataNext had a blanket catch (const Exception &) that returned CheckResult(name, false, ...), unlike the non-replicated StorageMergeTree::checkDataNext which already re-throws retryable exceptions.
  • InterpreterCheckQuery::TableCheckTask::checkNext also blanket-caught and returned a false result for every storage.

Both catch sites now 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).

This is the underlying false-negative behind the chronic flaky test_broken_projections/test.py::test_mutation_with_broken_projection: aggressive background merges add ZooKeeper/IO churn that raises the transient-error rate on the first CHECK TABLE.

A new check_table_inject_retryable_zk_error failpoint and the stateless test 04506_check_table_retryable_zk_error inject a transient ZooKeeper error during CHECK TABLE and assert it throws rather than returning a broken row for a healthy part.

Related: #63002
Related: #107290

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 into CHANGELOG.md):

Fixed CHECK TABLE on a ReplicatedMergeTree table reporting a healthy part as broken when a transient, retryable ZooKeeper error (e.g. connection loss) occurred during the check; such errors are now surfaced as a retryable query error instead.

Version info

  • Merged into: 26.7.1.569 (included in 26.7 and later)

… 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` (#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: #63002
Related: #107290

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [43d98f1]

Summary: ✅


AI Review

Summary

This PR changes CHECK TABLE so transient retryable errors during replicated-part validation are surfaced as query errors instead of being converted into a false "broken part" result, and it adds focused regression coverage for that path. After reviewing the current diff, the affected CHECK TABLE call chain, and the existing PR discussion, I did not find a new correctness or safety issue that warrants an inline review comment.

Missing context / blind spots
  • ⚠️ I did not run the tests locally because this checkout does not contain a build directory or test binaries; the review is based on code inspection, the current PR diff, the existing GitHub discussion, and the published coverage summary.
Final Verdict

✅ No new inline findings.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 6, 2026
@tiandiwonder tiandiwonder self-assigned this Jul 6, 2026
Address review from @tiandiwonder: the `check_table_inject_retryable_zk_error`
failpoint is placed only inside `StorageReplicatedMergeTree::checkDataNext`.
Under `--replace-replicated-with-shared` the table becomes `SharedMergeTree`,
which has its own check path and never triggers the failpoint, so the expected
`KEEPER_EXCEPTION` would not fire and the test would fail. Tag the test
`no-shared-merge-tree` so it is skipped in that mode.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
/// retried, instead of silently reporting a healthy part as broken (returning a "0" row).
/// The shutdown ABORTED exception is still swallowed here (that is what this catch was originally added
/// for); `isRetryableException` treats ABORTED as retryable, so exclude it explicitly.
if (e.code() != ErrorCodes::ABORTED && isRetryableException(std::current_exception()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

optional: add a test pinning the ABORTED-swallow behavior — it's the one changed branch the new test doesn't reach, and this exclusion looks like a removable special case to a future cleanup.

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.

Good point about the coverage gap. Leaving this as a follow-up rather than folding it into this PR: the ABORTED swallow is pre-existing shutdown behavior (this PR does not introduce it — it only narrows the catch so that retryable non-ABORTED errors are rethrown), and pinning what CHECK TABLE returns while the server is shutting down is a separate semantic question from the retryable-error fix here. The now-explicit comment documents why the != ABORTED guard exists, which should deter an accidental removal in the meantime. Leaving the thread open so the follow-up test is not lost.

alexey-milovidov and others added 3 commits July 6, 2026 11:15
…ng lines

Apply @tiandiwonder's optional simplification suggestions on #109465: the
`CHECK TABLE` retry comments in `InterpreterCheckQuery::TableCheckTask::checkNext`
and `StorageReplicatedMergeTree::checkDataNext` restated what the code does. Keep
only the load-bearing rationale (why transient errors are rethrown, and why the
shutdown `ABORTED` exception stays swallowed).

Comment-only change; no behavior change.
… TABLE errors

This PR makes `CHECK TABLE` rethrow retryable exceptions (including the
ZooKeeper connection-loss `KEEPER_EXCEPTION`) instead of reporting a spurious
broken part, so the integration test `test_check_replicated_does_not_block_shutdown`
no longer always observes a `0` result when ZooKeeper is killed mid-check.

Once the ZooKeeper session is lost the abort now surfaces in one of two ways,
depending on which condition wins the race:
  * the transient error is rethrown from `checkDataNext` (retryable), so
    `CHECK TABLE` fails with `KEEPER_EXCEPTION`; or
  * the replica's partial shutdown makes the check swallow the `ABORTED` and
    return `0`.

Both are acceptable: the invariant this test protects is that `CHECK TABLE`
aborts quickly instead of scanning every part. Accept both outcomes while
keeping the timing assertion.

Surfaced by the `CH Inc sync` job (private sync PR
ClickHouse/clickhouse-private#63397): "Integration
tests (amd_asan_ubsan, db disk, old analyzer, 4/7)".

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Updating the branch to fix the 04001_join_reorder_through_expression test, which was broken today in master.

@clickhouse-gh

clickhouse-gh Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.60% 85.60% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 77.80% 77.80% +0.00%

Changed lines: Changed C/C++ lines covered: 21/23 (91.30%) · Uncovered code

Full report · Diff report

@tiandiwonder
tiandiwonder added this pull request to the merge queue Jul 7, 2026
Merged via the queue into master with commit 20e1dca Jul 7, 2026
175 checks passed
@tiandiwonder
tiandiwonder deleted the check-table-retry-retryable-errors branch July 7, 2026 02:35
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 7, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ng lines

Apply @tiandiwonder's optional simplification suggestions on ClickHouse#109465: the
`CHECK TABLE` retry comments in `InterpreterCheckQuery::TableCheckTask::checkNext`
and `StorageReplicatedMergeTree::checkDataNext` restated what the code does. Keep
only the load-bearing rationale (why transient errors are rethrown, and why the
shutdown `ABORTED` exception stays swallowed).

Comment-only change; no behavior change.
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…y-retryable-errors

Make CHECK TABLE retry retryable errors instead of reporting a broken part
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Development

Successfully merging this pull request may close these issues.

3 participants