Repository navigation
MergeTreeSink: honor query cancellation while writing many parts - #107929
Conversation
The per-part loops in `consume` and `finishDelayedChunk` had no cancellation point, so a killed or timed-out `INSERT` that splits into many parts (e.g. a high-cardinality partition key with `max_partitions_per_insert_block`) kept running for a long time. Call `process_list_element->checkTimeLimit()` between parts, as `ReplicatedMergeTreeSink` already does. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [03d9834] Summary: ✅
AI ReviewSummaryThis PR adds per-part time-limit checks to non-replicated Findings
Tests
Final VerdictStatus: Minimum required actions: handle |
| /// A single INSERT can split into very many parts (e.g. high-cardinality partition key with | ||
| /// max_partitions_per_insert_block); honor cancellation/timeout between them. | ||
| if (process_list_element) | ||
| process_list_element->checkTimeLimit(); |
There was a problem hiding this comment.
checkTimeLimit returns false instead of throwing when max_execution_time is exceeded with timeout_overflow_mode = 'break'. Since this call ignores the return value, that mode still keeps writing every remaining part in this long consume loop; the executor cannot observe and cancel until consume returns. Existing insert timeout behavior treats break-mode insert timeouts as cancellation, so this should handle the false return here and in finishDelayedChunk, and add a focused regression test for a many-part MergeTree insert.
| /// A single INSERT can split into very many parts (e.g. high-cardinality partition key with | ||
| /// max_partitions_per_insert_block); honor cancellation/timeout between them. | ||
| if (process_list_element) | ||
| process_list_element->checkTimeLimit(); |
There was a problem hiding this comment.
optional: worth a regression test for the kill/timeout-during-many-parts path.
an INSERT with a high-cardinality partition key and a small throw-mode max_execution_time should come back with TIMEOUT_EXCEEDED promptly instead of running to completion, which would guard against a future refactor dropping this check.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 16/16 (100.00%) | Lost baseline coverage: none · Uncovered code |
…ellation-check MergeTreeSink: honor query cancellation while writing many parts
A single
INSERTcan split into a very large number of parts (e.g. a high-cardinality partition key together withmax_partitions_per_insert_block), and writing/finalizing each part can be slow on object storage with the filesystem cache. The per-part loops inMergeTreeSink::consumeandMergeTreeSink::finishDelayedChunkhad no cancellation point, so a killed or timed-outINSERTkept grinding through all remaining parts — which could keep the query (and server shutdown) stuck for a long time, surfacing as "Hung check failed" in stress tests.Call
process_list_element->checkTimeLimit()between parts in both loops, the same idiomReplicatedMergeTreeSinkalready uses. It throwsQUERY_WAS_CANCELLEDon a kill orTIMEOUT_EXCEEDEDon a 'throw'-modemax_execution_timetimeout.onFinishalready skipsfinishDelayedChunkwhen cancelled, so a normal finish never throws.Related: #107477
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
INSERTinto aMergeTreetable now honors query cancellation andmax_execution_timewhile writing many parts, instead of potentially running long after being killed.Version info
26.7.1.187(included in26.7and later)