Repository navigation
Make the busy-wait in UNDROP TABLE interruptible by KILL QUERY - #113263
Conversation
`DatabaseCatalog::undropTable` busy-waits until the dropped table's storage pointer becomes unique before re-attaching the table. When another query still holds the storage, this wait ignored `KILL QUERY` and could stall for an unbounded time. It was caught by the hung check in a stress test run: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110997&sha=5ce1c10802e941bcf7a07b908bc4dd4ef5f54f61&name_0=PR&name_1=Stress%20test%20%28amd_debug%29 (PR: #110997, where the failure was unrelated to the PR's changes.) Pass a `throw_if_cancelled` callback into `undropTable`, following the existing pattern of `waitTableFinallyDropped`, and check it in the busy-wait loop. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [a0db43b] Summary: ✅
AI ReviewSummaryThis PR makes the local Findings
Final VerdictChanges requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 14/14 (100.00%) · Uncovered code |
The stateless test config sets `database_atomic_wait_for_drop_and_detach_synchronously = 1`, so the plain `DROP TABLE` in the test waited for the holder `SELECT` to release the storage and for the table to be finally dropped. The subsequent `UNDROP TABLE` then failed with `UNKNOWN_TABLE` and the test timed out polling for it, exceeding the 60 second Fast test limit: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113263&sha=99535efe15ec0a42d88a63bfbbf3dd546b06468f&name_0=PR&name_1=Fast%20test Disable the setting for that DROP so it returns while the storage is still referenced. Verified against a local server with the test config's value of the setting: the previous version reproduces the CI failure, the fixed test passes in ~3 seconds. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 The only red on Merged |
|
🕵 All three reds on
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113263&sha=b035f1d93d57d9465ec2e650e661dcb1dc1e01d0&name_0=PR&name_1=Stress%20test%20%28arm_msan%29 (issue #113712) and provide a fix in a separate PR. If the fix is already in progress (it may share a root cause with #107603 or #112219), link it here. None of these fixes are on |
|
Reproduced it, root-caused it, and found the missing condition. Neither 107603 nor 112219 owns this route, and no other open PR does, so I will send a separate PR. The extra condition is a Minimal reproducer, no CREATE TABLE t1 (x UInt8) ENGINE = MergeTree ORDER BY tuple();
CREATE TABLE t2 (y UInt8, x UInt8 ALIAS y IN (1, 2, 3)) ENGINE = MergeTree ORDER BY tuple();
SELECT * FROM merge(currentDatabase(), '.+');Aborts with the same assertion and the same stack as the stress run, down to
The last row is the control: same query, same ALIAS-with- Root cause. That is why it is a different bug from 107603 and 112219. Those fix key drift: a query-tree node shared between the join tree and an 113140 is the only other open PR touching Fix direction. There is already a precedent for exactly this in the analyzer: Worth flagging: the same unguarded pattern appears a second time in Will link the PR here. |
|
I opened #113757 for issue #113712. The extra condition your standalone reproducer was missing is a disagreement between the child tables Two tables suffice, and neither the filter nor CREATE TABLE t1 (x UInt8) ENGINE = MergeTree ORDER BY tuple();
CREATE TABLE t2 (y UInt8, x UInt8 ALIAS y IN (1, 2, 3)) ENGINE = MergeTree ORDER BY tuple();
SELECT * FROM merge(currentDatabase(), '.+');The I checked the two candidates before writing anything: neither the 108045 guard work nor the 113140 |
|
🕵 Merged |
Build profile diff (arm_release)Comparing Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units
|
|
🕵 The only red on |
If the regression this test guards against reappears, `UNDROP TABLE` completes after the holder query drains, `ATTACH TABLE` fails with `TABLE_ALREADY_EXISTS`, and the trailing `DROP TABLE ... SYNC` in the same multi-statement invocation never runs, leaving `t_undrop_kill` behind in the shared stateless database. Move the cleanup into a `trap cleanup EXIT` that kills both background queries and drops the table regardless of where the test fails. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 The only test failure on |
…itly in the `UNDROP TABLE` kill test The `wait $undrop_pid` result was not checked, so if the `UNDROP TABLE ... | grep 'QUERY_WAS_CANCELLED'` pipeline failed, a later successful `ATTACH TABLE` could let the test pass without proving the cancellation contract. Make the wait an explicit assertion, and also fail early with a clear message if the `SELECT` that must hold the storage reference is not running, since without it the `UNDROP` returns instantly and the test proves nothing. Verified locally against a server with the CI value of `database_atomic_wait_for_drop_and_detach_synchronously` and a `parallel_replicas` cluster configured: 10/10 runs pass in ~2.3 s under randomized settings; with a deliberately broken holder `SELECT`, the new assertions fail the test instead of letting it pass silently. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 The only red on @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113263&sha=31b96f7e658af6bb429d602fe612be389c423dd6&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 and provide a fix in a separate PR (likely a backport of the patch-part commit fix to |
| { | ||
| ${CLICKHOUSE_CLIENT} --query "KILL QUERY WHERE query_id IN ('$select_query_id', '$undrop_query_id') SYNC FORMAT Null" | ||
| wait | ||
| ${CLICKHOUSE_CLIENT} --query "DROP TABLE IF EXISTS t_undrop_kill SYNC" |
There was a problem hiding this comment.
After DatabaseCatalog::undropTable moves the metadata back into the regular database path (the moveFile before the wait in src/Interpreters/DatabaseCatalog.cpp), a killed UNDROP TABLE leaves t_undrop_kill in a metadata-only state until the script does the final manual ATTACH TABLE. If the test exits anywhere in that window, DROP TABLE IF EXISTS t_undrop_kill SYNC is a no-op because DROP only sees attached tables, so the .sql stays behind and the next CREATE TABLE t_undrop_kill fails with TABLE_ALREADY_EXISTS. Please normalize that state in cleanup first, e.g. try ATTACH TABLE IF NOT EXISTS t_undrop_kill (ignoring the “no metadata” case) and then DROP TABLE IF EXISTS ... SYNC.
|
Confirmed on the log read, and the old-server attribution holds. The fatal is Three corrections, and they change the deliverable from a backport to a master fix. 1. This is not specific to the old release. The identical patch-part fatal, same part name, same 2. 3. Also worth recording: the same fatal sits in a second The asymmetry that looks like the fix: One caveat before I write that patch. I could not reproduce it on master (5 campaigns, including |
|
Hi @alexey-milovidov @alesapin — while reviewing this PR I found the following:
Could you review the test PR and add the |
|
Closing the loop here, since both halves of your question are now answerable by measurement. The root cause was a concurrent The On the second half: So this check will not go green yet, and further sightings are expected rather than a sign the fix is wrong: One measured aside on the rest of the backport surface, since it concerns my own test: 26.8 already carried the fix and 26.6 landed via #116864, but #116863 ( |
Related: #110997
Related: #113224
Related: #112203
DatabaseCatalog::undropTablebusy-waits until the dropped table's storage pointer becomes unique before re-attaching the table. When another query still holds the storage, this wait ignoredKILL QUERYand could stall for an unbounded time. A stress-test hung check caught anUNDROP TABLEstuck in this loop (unrelated to that PR's changes): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110997&sha=5ce1c10802e941bcf7a07b908bc4dd4ef5f54f61&name_0=PR&name_1=Stress%20test%20%28amd_debug%29This passes a
throw_if_cancelledcallback intoundropTable, following the existing pattern ofwaitTableFinallyDropped, and checks it in the busy-wait loop. Cancellation leaves the same intermediate state as any failure of the subsequentATTACH(the metadata file has already been returned to the database), so the table can be attached afterwards — the added test checks that too.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
UNDROP TABLEcan now be interrupted byKILL QUERYwhile it waits for running queries to release the dropped table.