Skip to content

Part check ignore query cancellation - #128083

Merged
evillique merged 6 commits into
ClickHouse:masterfrom
andybradshaw:part-check-ignore-query-cancellation
Nov 5, 2026
Merged

evillique merged 6 commits into
ClickHouse:masterfrom
andybradshaw:part-check-ignore-query-cancellation

Conversation

@andybradshaw

@andybradshaw andybradshaw commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #128199

Previously, query cancellation (either due to an explicit kill or a timeout) could trigger a part to be reported as broken, as those exceptions are not considered "retryable". It seems like the isRetryableException(...) method is a little bit overloaded, so instead this PR chooses to introduce a new isQueryCancellation(...) call, and skip the broken reporting based on those within the merge tree reader.

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):

Query cancellation and timeouts within the merge tree reader no longer mark parts as potentially broken and trigger part checks


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

Version info

  • Merged into: 26.11.1.1433-master (included in 26.11 and later)

andybradshaw and others added 3 commits October 28, 2026 12:01
A query that is killed, or that hits `max_execution_time`, while it waits
in `FileSegment::wait` for another query's cache download throws
`TIMEOUT_EXCEEDED` or `QUERY_WAS_CANCELLED` from inside
`MergeTreeReaderWide::readRows`. The reader treats every exception that
is not retryable as a sign of a broken part, so a healthy part is
enqueued for a full data check. On object storage such a check reads the
whole part, and a replica restart blocks in
`ReplicatedMergeTreePartCheckThread::stop` until it ends.

The test pauses a downloader on the `file_segment_pause_before_write`
failpoint, lets a second query time out inside the wait, and asserts
that no part check is requested.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
`MergeTreeReaderWide`, `MergeTreeReaderCompactSingleBuffer` and
`MergeTreeSequentialSource` report the part as broken for every
exception that is not retryable. Since a killed query, or one that hit
`max_execution_time`, can throw `QUERY_WAS_CANCELLED` or
`TIMEOUT_EXCEEDED` from inside a read (`FileSegment::wait`, the S3
client, the marks loader), a healthy part was enqueued for a full data
check each time that happened. On object storage such a check reads the
whole part, which took 30 to 47 minutes per part in production, and a
Keeper session loss during the check left the table read-only for as
long, because `partialShutdown` waits in
`ReplicatedMergeTreePartCheckThread::stop` for the running check.

Add `isQueryCancellation` next to `isRetryableException` and skip
`reportBroken` for a cancellation. The codes are kept out of
`isRetryableException` on purpose: inside `checkDataPart` a retryable
exception yields empty checksums, and a cancelled `CHECK TABLE` would
then pass an unchecked part.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
A downloader that never writes to the cache left the test blocked in
`SYSTEM WAIT FAILPOINT` until the test timeout; the wait is now bounded
and reported. The check thread logs under the table name, so a repeated
run in the same database counted the checks of the earlier runs; the
`text_log` query is now bounded to the current run.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. external Author is not a member of the ClickHouse organization labels Oct 28, 2026
@andybradshaw

Copy link
Copy Markdown
Contributor Author

Related to #128199

@evillique evillique self-assigned this Nov 2, 2026
@evillique evillique added the can be tested Allows running workflows for external contributors label Nov 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f9ddb75]

Summary: ✅


AI Review

Summary

The PR prevents ordinary query cancellation and timeout exceptions from requesting integrity checks of healthy MergeTree parts, while leaving CHECK TABLE retry semantics unchanged. Reviewed head f9ddb75579f2074984fdd38241441c5dd78ce590. One existing Major remains unresolved; no new inline findings were identified.

Findings

⚠️ Majors

  • src/Storages/MergeTree/checkDataPart.cpp:195–197: Cancellation can still request a check of a healthy part. QueryStatus::cancelQuery accepts an original exception, which throwQueryWasCancelled rethrows. For example, the background writer of PrettyBlockOutputFormat cancels with BAD_ARGUMENTS when output_format_float_precision is out of range. A concurrent reader waiting in FileSegment::wait receives that exception through throwIfKilled. Both isRetryableException and isQueryCancellation return false, so MergeTreeReaderWide::readRows still calls reportBroken, scheduling the expensive full-part check this PR aims to avoid. Recognize the query's stored cancellation exception while distinguishing independent read failures. This remains present in the current code and is already tracked in the existing inline thread; no duplicate comment was posted.
Tests
  • ⚠️ Add a focused regression for cancellation carrying an original exception outside the three recognized codes, asserting that the error propagates without enqueueing a part check. The added timeout test does not cover this path.
Missing context / blind spots
  • ⚠️ CI reports 05457_part_check_ignores_query_cancellation passing at 5402f870fe81fee8ccd1d6fc44519015e7142a2e. An individual result for the revised test at the current head was unavailable; a passing run would validate its new query-id-based assertion. No tests were executed locally.
Final Verdict

⚠️ Request changes. Handle cancellation with a stored original exception and add regression coverage for that path.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 2, 2026
Comment on lines +195 to +197
return e.code() == ErrorCodes::QUERY_WAS_CANCELLED
|| e.code() == ErrorCodes::QUERY_WAS_CANCELLED_BY_CLIENT
|| e.code() == ErrorCodes::TIMEOUT_EXCEEDED;

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.

[P2] Recognize cancellations that rethrow the original error

QueryStatus::throwQueryWasCancelled rethrows the exception supplied to cancelQuery, so a cancellation need not carry any of these three codes. For example, the background writer of PrettyBlockOutputFormat calls cancelQuery(CANCELLED_BY_ERROR, exception) when formatting fails; an out-of-range output_format_float_precision produces BAD_ARGUMENTS. If a read thread is in FileSegment::wait at that point, throwIfKilled rethrows that formatting error inside the reader. Both isRetryableException and this helper return false, so the reader still calls reportBroken and requests a full check of a healthy part. Please recognize the current query's stored cancellation error as well, preserving the distinction from an independent read error, and cover this cancellation path in a focused regression test.

@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f9ddb7557 with master 6ba6845be (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 989ecd896; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

18 translation units recompiled, 189 s compile time in total, 18 of them have a recent master baseline.

Job report

@andybradshaw

Copy link
Copy Markdown
Contributor Author

@evillique looks like CI is green here, is this good to merge?

@andybradshaw

Copy link
Copy Markdown
Contributor Author

Also, what are the odds of getting this back ported to the LTS and getting a release for that?

@evillique evillique left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! One suggestion: the test is no-parallel and takes up to 95 s in CI, mostly in the polling loop. Polling isn't needed, because the reading thread logs Enqueueing ... for check under its own query id, so a single lookup by query_id is enough (see the suggestions below).

@evillique evillique added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 4, 2026
Co-authored-by: Nikolay Degterinsky <[email protected]>
@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default and removed pr-improvement Pull request with some product improvements labels Nov 4, 2026
@evillique evillique added v26.8-must-backport and removed pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Nov 5, 2026
@evillique
evillique added this pull request to the merge queue Nov 5, 2026
Merged via the queue into ClickHouse:master with commit de6daf9 Nov 5, 2026
185 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 5, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 5, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 8, 2026
…not-found-on-active-part-load

Resolve the checkDataPart.cpp conflict: keep master's isQueryCancellation
(ClickHouse#128083) and add isObjectStorageNotFoundException after it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 8, 2026
…lation-compact-reader-mark-loop

Conflicts resolved:

- MergeTreeReaderCompactSingleBuffer.cpp: master (ClickHouse#127287) moved the mark
  loop out of readRows into MergeTreeReaderCompact::readGranules, and ClickHouse#128083
  already guards the reportBroken catch with isQueryCancellation. Took master's
  file as is; the per-granule checkTimeLimit moves to both loops of
  MergeTreeReaderCompact (readGranules and readGranulesWithColumnsCache).
- checkDataPart.{cpp,h}: ClickHouse#128083 added isQueryCancellation under the same name.
  Kept master's function and declaration; dropped ours. Master accepts only the
  three cancellation codes on a DB::Exception, so isCodeOfCancelledQuery stays as
  an extra clause in both catch branches: a killed query can rethrow the error it
  was cancelled with, of any code and any exception type.
- MergeTreeSequentialSource.cpp: master's catch line is identical to ours.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-ch-test-poll4 added a commit that referenced this pull request Nov 10, 2026
Cherry pick #128083 to 26.8: Part check ignore query cancellation
robot-ch-test-poll added a commit that referenced this pull request Nov 10, 2026
Cherry pick #128083 to 26.9: Part check ignore query cancellation
robot-ch-test-poll added a commit that referenced this pull request Nov 10, 2026
Cherry pick #128083 to 26.10: Part check ignore query cancellation
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 10, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 10, 2026
Backport #128083 to 26.8: Part check ignore query cancellation
clickhouse-gh Bot added a commit that referenced this pull request Nov 10, 2026
Backport #128083 to 26.10: Part check ignore query cancellation
clickhouse-gh Bot added a commit that referenced this pull request Nov 10, 2026
Backport #128083 to 26.9: Part check ignore query cancellation
@clickhouse-gh clickhouse-gh Bot added comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. 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-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... external Author is not a member of the ClickHouse organization pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.8-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Queries on S3 cache unecessarily enqueues part check on TIMEOUT_EXCEEDED exception

5 participants