Repository navigation
Fix Memory mutation cancellation handling - #104522
Conversation
`PullingPipelineExecutor` can return `false` when a query is cancelled or stopped by a soft timeout. `StorageMemory` treated that result as normal EOF and then assumed the mutation pipeline produced one block for every stored block, which could walk past the end of the output vector while updating columns. Check the query status around mutation pulls and fail before applying partial data. Also validate the block count before partial-column updates. CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=1b76e322cbdb89960eea5236f4eda5ad3f9e164d&name_0=MasterCI&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20arm_asan_ubsan%29&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20arm_asan_ubsan%29 Examples: https://play.clickhouse.com/play?user=play&run=1#U0VMRUNUIGNoZWNrX3N0YXJ0X3RpbWUsIGNoZWNrX25hbWUsIHRlc3RfbmFtZSwgcmVwb3J0X3VybApGUk9NIGNoZWNrcwpXSEVSRSAxCiAgICBBTkQgY2hlY2tfc3RhcnRfdGltZSA+PSBub3coKSAtIElOVEVSVkFMIDI0IEhPVVIKICAgIEFORCAoaGVhZF9yZWYgPSAnbWFzdGVyJyBBTkQgc3RhcnRzV2l0aChoZWFkX3JlcG8sICdDbGlja0hvdXNlLycpKQogICAgQU5EIHRlc3Rfc3RhdHVzICE9ICdTS0lQUEVEJwogICAgQU5EICh0ZXN0X3N0YXR1cyBMSUtFICdGJScgT1IgdGVzdF9zdGF0dXMgTElLRSAnRSUnKQogICAgQU5EIGNoZWNrX3N0YXR1cyAhPSAnc3VjY2VzcycKICAgIEFORCBjaGVja19uYW1lIE5PVCBMSUtFICdsaWJGdXp6ZXIlJwogICAgQU5EIGNoZWNrX25hbWUgIT0gJ0NsaWNrSG91c2UgS2VlcGVyIEplcHNlbicKICAgIEFORCBjaGVja19uYW1lIE5PVCBMSUtFICdJbnRlZ3JhdGlvbiB0ZXN0cyAoYW1kX2xsdm1fY292ZXJhZ2UlJwpPUkRFUiBCWSBjaGVja19zdGFydF90aW1lIERFU0M=
|
Workflow [PR], commit [3ce5d1f] Summary: ✅ AI ReviewSummaryThis PR hardens Findings
Tests
Final Verdict
|
`04216_memory_mutation_timeout_break` clashed with `04216_materialized_view_reused_target_name_dependency` that landed on master while this PR was open. Bump our test to `04217`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
In `pullMutationBlock` the return value of `checkTimeLimit` was ignored. With `timeout_overflow_mode = 'break'`, `checkTimeLimit` returns `false` on a soft timeout without throwing, so the mutation could keep pulling extra blocks past the time limit and only fail later. Check the return value before `pull` and throw `TIMEOUT_EXCEEDED` immediately. CI sync report: ClickHouse/clickhouse-private#57620 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Move the `checkTimeLimit` call to run only after `executor.pull` returns `false`. The previous pre-check could throw `TIMEOUT_EXCEEDED` on the normal end-of-stream path with `timeout_overflow_mode = 'break'` when the timeout flips between the last produced block and the loop's final `pull` call, even though the mutation actually completed successfully. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`04227_memory_mutation_timeout_break` clashed with `04227_case_with_expression_array_result_78352` and `04227_prewhere_parameterized_view_join_102074` that landed on master while this PR was open. Bump our test to `04229`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ignal The previous code threw `TIMEOUT_EXCEEDED` based on `QueryStatus::checkTimeLimit` after `executor.pull` returned `false`. That is a false positive when the soft timeout flips between the last produced block and the final `pull` that observes normal end-of-stream: the mutation actually completed, but we threw anyway. Distinguish the two cases by consulting `PipelineExecutor::getExecutionStatus`, which `cancel` switches to `CancelledByTimeout` / `CancelledByUser` on cancellation but leaves at `Executing` on a clean end-of-stream. Expose the status through `PullingPipelineExecutor::getExecutionStatus` (matching the pattern used by `PushingPipelineExecutor::throwOnExecutionStatus`). The wrapper also falls back to `QueryStatus::isKilled` / `checkTimeLimitSoft` when the executor's status is `NotStarted` — `cancel(CancelledByTimeout)` only transitions `Executing` → `CancelledByTimeout`, so if the timeout fires before the very first `executeStep`, the executor's status would otherwise lie about having been cancelled. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ngthen test For partial-column `Memory` mutations the output block count must equal the input, so a count mismatch is precise evidence that the pipeline did not produce all expected blocks. Throwing `TIMEOUT_EXCEEDED` / `QUERY_WAS_CANCELLED` only when this evidence is present avoids a false cancellation exception when the soft timeout flips between the last successful `pull` and the next `pull`'s pre-step `checkTimeLimitSoft`, after all blocks were already produced. The fail-close behaviour is preserved for the all-columns path, where output completeness cannot be precisely validated. Also strengthens `04229_memory_mutation_timeout_break.sql` to use a value-changing update (`a = a + 1 + toUInt64(sleepEachRow(0.01))`) — `sleepEachRow` returns `0`, so the previous expression `a + 0` was a no-op and could not detect a regression where a partial mutation result was swapped into the table. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ellation `PullingPipelineExecutor::pull(Block)` can return `true` with an empty block on timeout. With only a block-count check, an empty trailing block could slip past: `updateBlockData` no-ops on a block that has no columns, silently keeping the un-mutated old block while swallowing the cancellation signal. Strengthen the partial-column completeness check to also require per-block row counts to match `old_data`. Any shape mismatch rethrows through `throw_on_cancellation` so a real cancellation always surfaces. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…classification `cancelQuery` sets `is_killed` for both user-initiated kills and `CancellationChecker` timeouts, and the `NotStarted` fallback in `PullingPipelineExecutor::getExecutionStatus` mapped `isKilled() == true` unconditionally to `CancelledByUser`. As a result, a `StorageMemory` mutation cancelled by `CancellationChecker` for a timeout could be reported as `QUERY_WAS_CANCELLED` instead of `TIMEOUT_EXCEEDED`. Add a public `QueryStatus::getCancelReason` accessor, lock-protected to match the existing `cancel_mutex` discipline, and consult it in the fallback so timeout cancellations are classified as `CancelledByTimeout`.
|
@groeneai, please investigate two CI failures that look unrelated to this PR (which only touches
If a fix is already in progress, please link it here. |
…meout `ExecutorHolder::cancel` forwards to the no-arg `PipelineExecutor::cancel`, which always reports `CancelledByUser` regardless of the `CancelReason` recorded by `cancelQuery`. When `CancellationChecker` triggers `cancelQuery(CancelReason::TIMEOUT)` after the executor is already attached (the default `timeout_overflow_mode = 'throw'` path), the executor's status becomes `CancelledByUser` and `StorageMemory::mutate` would have thrown `QUERY_WAS_CANCELLED` instead of `TIMEOUT_EXCEEDED`. Extend the remap in `PullingPipelineExecutor::getExecutionStatus` to also cover the `CancelledByUser` case, reading the recorded `CancelReason` from `QueryStatus` to recover the actual reason. Reviewer feedback: #104522 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
@groeneai, follow-up on the latest CI run (commit
If a fix is already in progress for either, please link it here. Otherwise please investigate. |
|
@groeneai, follow-up on the latest CI run (commit
If a fix is already in progress for any of these, please link it here. Otherwise please investigate. |
|
@groeneai, investigate the failure: |
|
@groeneai, investigate the failure: |
|
@groeneai, follow-up on the latest CI run (commit
If a fix is already in progress for any of these, please link it here. Otherwise please investigate. |
|
@alexey-milovidov — apologies for the silence on the last 7 directives; they fell through a gap in our inbox routing that's now closed. Catching up with the mapping you asked for:
None of the 8 failure classes above are caused by this PR's Cron rules tightened so this doesn't happen again — apologies for the multi-day delay. |
| /// `PipelineExecutor::cancel(CancelledByTimeout)` only transitions `Executing` → `CancelledByTimeout`, | ||
| /// so a timeout that fires before the first `executeStep` leaves the executor at `NotStarted`. | ||
| /// Consult the `QueryStatus` to recover the actual reason in both cases. | ||
| if (pipeline.process_list_element->isKilled() |
There was a problem hiding this comment.
getExecutionStatus still misclassifies a user cancel as timeout in a real race:
cancelQuerysetsis_killed = truewith reasonCANCELLED_BY_USER.- Before
ExecutorHolder::cancelruns, the pull thread entersPipelineExecutor::checkTimeLimitSoft. QueryStatus::checkTimeLimitSoftreturnsfalseonly becauseis_killedis set, andPipelineExecutor::cancel(CancelledByTimeout)transitionsExecuting -> CancelledByTimeout.- Later
ExecutorHolder::cancelcannot switch the state toCancelledByUseranymore. - This branch keeps
CancelledByTimeout, soStorageMemory::mutatethrowsTIMEOUT_EXCEEDEDfor a user kill.
Could we also normalize status == CancelledByTimeout from QueryStatus::getCancelReason (same way as CancelledByUser), so timeout vs user cancellation is always derived from cancel_reason when isKilled is true?
|
This was fixed by #105146. Let's update the branch. |
LLVM Coverage Report
Changed lines: 75.00% (39/52) · Uncovered code |
The disk health check thread (controlled by `local_disk_check_period_ms`) periodically opens directories under storage paths. When the test mounts `proc` over a JBOD storage directory and then immediately calls `umount`, the thread can be holding an open file descriptor on the mount point, causing `umount` to fail with `target is busy`. Wrap both `umount` call sites in a small helper that retries on this specific error string and lets every other exception (and the final attempt) propagate unchanged. Observed on PR ClickHouse#104522: ClickHouse#104522
Fixes a CI
AddressSanitizerexception inStorageMemorymutations whenPullingPipelineExecutorstops because of query cancellation or soft timeout before producing all expected blocks. The mutation now checks query status before applying output and validates the output block count before partial-column updates.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=1b76e322cbdb89960eea5236f4eda5ad3f9e164d&name_0=MasterCI&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20arm_asan_ubsan%29&name_1=Stress%20test%20%28experimental%2C%20serverfuzz%2C%20arm_asan_ubsan%29
Examples query: https://play.clickhouse.com/play?user=play&run=1#U0VMRUNUIGNoZWNrX3N0YXJ0X3RpbWUsIGNoZWNrX25hbWUsIHRlc3RfbmFtZSwgcmVwb3J0X3VybApGUk9NIGNoZWNrcwpXSEVSRSAxCiAgICBBTkQgY2hlY2tfc3RhcnRfdGltZSA+PSBub3coKSAtIElOVEVSVkFMIDI0IEhPVVIKICAgIEFORCAoaGVhZF9yZWYgPSAnbWFzdGVyJyBBTkQgc3RhcnRzV2l0aChoZWFkX3JlcG8sICdDbGlja0hvdXNlLycpKQogICAgQU5EIHRlc3Rfc3RhdHVzICE9ICdTS0lQUEVEJwogICAgQU5EICh0ZXN0X3N0YXR1cyBMSUtFICdGJScgT1IgdGVzdF9zdGF0dXMgTElLRSAnRSUnKQogICAgQU5EIGNoZWNrX3N0YXR1cyAhPSAnc3VjY2VzcycKICAgIEFORCBjaGVja19uYW1lIE5PVCBMSUtFICdsaWJGdXp6ZXIlJwogICAgQU5EIGNoZWNrX25hbWUgIT0gJ0NsaWNrSG91c2UgS2VlcGVyIEplcHNlbicKICAgIEFORCBjaGVja19uYW1lIE5PVCBMSUtFICdJbnRlZ3JhdGlvbiB0ZXN0cyAoYW1kX2xsdm1fY292ZXJhZ2UlJwpPUkRFUiBCWSBjaGVja19zdGFydF90aW1lIERFU0M=
Related open issues: none found for
STID: 1374-2634,AddressSanitizerStorageMemorymutation, orMemorymutation timeout.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required.
Documentation entry for user-facing changes
Version info
26.5.1.736