Skip to content

Make the busy-wait in UNDROP TABLE interruptible by KILL QUERY - #113263

Merged
alexey-milovidov merged 7 commits into
masterfrom
fix/undrop-busy-wait-cancellation
Aug 9, 2026
Merged

alexey-milovidov merged 7 commits into
masterfrom
fix/undrop-busy-wait-cancellation

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

Related: #110997
Related: #113224
Related: #112203

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. A stress-test hung check caught an UNDROP TABLE stuck 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%29

This passes a throw_if_cancelled callback into undropTable, following the existing pattern of waitTableFinallyDropped, and checks it in the busy-wait loop. Cancellation leaves the same intermediate state as any failure of the subsequent ATTACH (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):

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

UNDROP TABLE can now be interrupted by KILL QUERY while it waits for running queries to release the dropped table.

`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]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a0db43b]

Summary: ✅


AI Review

Summary

This PR makes the local UNDROP TABLE refcount wait observe KILL QUERY and adds a regression shell test. The main C++ change follows the existing synchronous drop/detach cancellation pattern, but the new test cleanup still misses one failure mode and can leave t_undrop_kill behind in the shared stateless database.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/04726_kill_undrop_table_busy_wait.sh:28] After DatabaseCatalog::undropTable moves the metadata back to the regular database path before entering the wait (src/Interpreters/DatabaseCatalog.cpp:1505-1508), a killed UNDROP TABLE leaves a metadata-only table until the script's manual ATTACH TABLE. If the script exits 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. Suggested fix: in cleanup, first try ATTACH TABLE IF NOT EXISTS t_undrop_kill while ignoring the “no metadata” case, then DROP TABLE IF EXISTS t_undrop_kill SYNC.
Final Verdict

Changes requested.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.60% 86.60% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.90% 78.80% -0.10%

Changed lines: Changed C/C++ lines covered: 14/14 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 4, 2026
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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only red on ac5c3dab was AST fuzzer (arm_asan_ubsan): Logical error: 'database_name != "_temporary_and_external_tables"' (STID: 2508-48e6), hit at ASTSelectQuery::replaceDatabaseAndTable from ReadFromMerge::createPlanForTable. It is unrelated to this PR (no code from this change in any frame; this PR only touches the undropTable refcount wait and InterpreterUndropQuery) — it is the Merge-over-the-internal-temporary-tables-database exception, already being fixed in #113224, which is not on master yet.

Merged master and pushed b035f1d93d5 to re-run CI. Also switched the changelog category to Bug Fix as the AI review suggested.

@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 Aug 5, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 All three reds on b035f1d are unrelated to this PR (which only touches the undropTable refcount wait and InterpreterUndropQuery):

  1. Stateless tests (amd_debug, parallel) — 04357_distributed_alias_same_expression, labeled flaky by CI itself (15/78 reruns failed with the same randomized settings, group_by_two_level_threshold_bytes=1). This is the known wrong-result bug with duplicate-ALIAS GROUP BY over a Distributed table under two-level aggregation: issue Wrong results: GROUP BY two ALIAS columns with the same expression over a Distributed table duplicates groups under two-level aggregation #112987, fix in progress in Fix wrong results for duplicate-ALIAS GROUP BY on a Distributed table under two-level aggregation #108855 (not yet merged).
  2. Stress test (amd_debug) — hung check: the hung query is SELECT * FROM merge(REGEXP('.*'), '.*') (AST fuzzer), stuck uninterruptibly in analyzer resolution (QueryAnalyzer::resolve), is_cancelled=1. No UNDROP/undropTable frame anywhere in the hung-check log — notably, the undropTable busy-wait this PR makes interruptible is not among the hung queries this time. Tracked by Uninterruptible CPU-bound function evaluation over a large value #112203.
  3. Stress test (arm_msan) — server aborted on Logical error: 'No set is registered for key __set_…' in ReadFromMerge::getModifiedQueryInfo → PlannerActionsVisitor for the fuzzer query SELECT * FROM merge(currentDatabase(), '.+') LIMIT -326, 33 FORMAT ORC. Filed Logical error "No set is registered for key" in ReadFromMerge::getModifiedQueryInfo for a merge() table with ALIAS columns #113712.

@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 master yet, so re-merging master would not clear the reds; the branch already merged master on 2026-08-05.

@groeneai

groeneai commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

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 default_desc disagreement between the child tables. StorageMerge::getColumnsDescriptionFromSourceTablesImpl merges child schemas, and when two children declare the same column differently it clears the default: what.default_desc = {} (src/Storages/StorageMerge.cpp:250). The Merge-level column then looks physical, so it enters required_column_names -- while the child still has it as an ALIAS, which getModifiedQueryInfo expands at :1197. That is why a single table with x UInt8 ALIAS y IN (1, 2, 3) does not trigger it: with one child, or several identical ones, the Merge table keeps the ALIAS default, the column is never requested as physical, and the expansion never happens.

Minimal reproducer, no INSERT and no LIMIT needed:

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 getModifiedQueryInfo -> PlannerActionsVisitor::visit. Measured on a debug build of current master:

children Merge-level x result
physical x + ALIAS x physical (defaults disagree) aborts
DEFAULT x + ALIAS x physical (defaults disagree) aborts
ALIAS y IN (1,2,3) + ALIAS y IN (4,5,6) physical (defaults disagree) aborts
ALIAS y IN (1,2,3) on both stays ALIAS passes

The last row is the control: same query, same ALIAS-with-IN, only the disagreement removed.

Root cause. getModifiedQueryInfo derives a fresh planner context per child, std::make_shared<PlannerContext>(modified_context, modified_query_info.planner_context) (:1142). That constructor copies global_planner_context and is_ast_level_optimization_allowed only (src/Planner/PlannerContext.cpp:83-86); prepared_sets is a member of the derived context and starts empty. The alias expression is then resolved and handed to a PlannerActionsVisitor over that context (:1227-1228), and makeSetForInFunction looks the set up with getPreparedSets().findTuple (src/Planner/PlannerActionsVisitor.cpp:1109), which misses and throws at :1120. Nothing in StorageMerge.cpp ever registers sets: it contains zero calls to collectSets or getPreparedSets.

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 IN argument is mutated in place after the set is registered, so the later lookup recomputes a different hash. Here the key is stable and the registry is simply empty. Consistent with that, the failing key ends in (UInt8) -- PreparedSets::toString appends element types only on the constant-tuple path, so this is findTuple, not the subquery path those PRs are about. Neither PR touches this file, and neither can help a lookup against a registry nothing populated.

113140 is the only other open PR touching StorageMerge.cpp, but it rewrites the per-identifier QueryAnalysisPass loop in replaceTableExpressionAndRemoveJoin for planning complexity; it does not touch :1227 or the planner-context construction.

Fix direction. There is already a precedent for exactly this in the analyzer: collectSetsAndSourceColumns exists because collectSourceColumns expands ALIAS columns through PlannerActionsVisitor, and its header comment states that the sets "must therefore be registered by collectSets beforehand, otherwise an IN inside an ALIAS expression throws" (src/Planner/CollectTableExpressionData.h:31), with the call at CollectTableExpressionData.cpp:117. The Merge path is the same situation and is missing that step. I plan to register the sets of the resolved alias expression in the child's planner context before visiting it, which keeps the failure impossible rather than merely non-fatal, since Exception::handleErrorCode aborts at throw time in debug and sanitizer builds and so guarding the lookup would not help.

Worth flagging: the same unguarded pattern appears a second time in convertAndFilterSourceStream (:1686-1687), building actions for aliases over the same context. I did not manage to reach that one, since every reproducer I built aborts earlier at :1228, but it has the same shape, so I will cover both sites.

Will link the PR here.

@groeneai

groeneai commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

I opened #113757 for issue #113712.

The extra condition your standalone reproducer was missing is a disagreement between the child tables
about the column's default. StorageMerge::getColumnsDescriptionFromSourceTablesImpl clears the default
when children disagree about it, so the Merge-level column looks physical and is requested from every
child, while the child that declares it still calls it ALIAS. ReadFromMerge::getModifiedQueryInfo
then expands the alias and builds actions with a PlannerActionsVisitor over a planner context it
derived a few lines earlier; the deriving constructor does not copy prepared_sets, so the IN lookup
misses an empty registry. With two children that agree there is no disagreement, the column keeps its
ALIAS, and nothing reaches that path, which is why a single table did not reproduce it.

Two tables suffice, and neither the filter nor LIMIT -326, 33 FORMAT ORC is needed:

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 merge() regexp over a database of heterogeneous leftover tables in the fuzzer run is what supplied
the disagreeing pair, so the mix across children was the requirement rather than any single schema.

I checked the two candidates before writing anything: neither the 108045 guard work nor the 113140
planning change touches this lookup, so no open PR owned the route.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master and pushed 202f6da7c15: the fix for the Stress test (arm_msan) red — #113757 for issue #113712 — has landed on master today, so re-running CI on the updated head should clear it. The merge was conflict-free (master's only touch to a PR file was the getSchedulePool pointer-return migration in DatabaseCatalog.cpp, unrelated to this change), and both affected translation units compile. The remaining two reds on the previous head stay tracked by #112987 (fix #108855, still open) and #112203.

@clickhouse-gh

clickhouse-gh Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a0db43ba4 with master 8cb46d93b (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: compile time of recompiled translation units.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 690.64 MiB 687.62 MiB -3.02 MiB (-0.44%)

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 ⚠️

7314 translation units recompiled, 8801 s compile time in total, 297 of them have a recent master baseline.

Translation units without a recent master baseline:

  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Passes/PassBuilder.cpp: 24.9 s
  • contrib/aws-cmake/__/aws/generated/src/aws-cpp-sdk-s3/source/S3Client.cpp: 16.0 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp: 14.7 s
  • contrib/aws-cmake/__/aws/generated/src/aws-cpp-sdk-glue/source/GlueClient1.cpp: 14.1 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/vm/plugin_modules.cpp: 13.9 s
  • contrib/aws-cmake/__/aws/generated/src/aws-cpp-sdk-glue/source/GlueClient.cpp: 12.0 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp: 11.9 s
  • contrib/rocksdb-cmake/__/rocksdb/db/db_impl/db_impl.cc: 10.4 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Analysis/ScalarEvolution.cpp: 9.6 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/api/wasmedge.cpp: 9.6 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Passes/PassBuilderPipelines.cpp: 9.5 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/vm/vm.cpp: 9.3 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp: 9.3 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/CodeGen/CodeGenPrepare.cpp: 9.0 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/host/wasi/wasimodule.cpp: 8.9 s
  • contrib/ai-sdk-cpp-cmake/__/ai-sdk-cpp/src/providers/openai/openai_client.cpp: 8.6 s
  • contrib/wasmedge-cmake/__/wasmedge/lib/host/wasi/wasifunc.cpp: 8.6 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp: 8.4 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/Transforms/IPO/SampleProfile.cpp: 8.4 s
  • contrib/llvm-project-cmake/__/llvm-project/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp: 8.3 s
  • ... and 107 more

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only red on 202f6da was 04561_ie_join_storage_join in Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) — unrelated to this PR: the test broke across ~121 PRs on 2026-08-07 in this same check and was fixed by #113840, which merged to master after this branch's previous merge. Merged master (conflict-free; no PR files touched) and pushed 77baac4e8c1 to pull in that fix; both affected translation units compile. AI Review verdict on the previous head was ✅ Approve with changed-lines coverage 14/14.

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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only test failure on 77baac4e8c1 — 03443_projection_sparse in Stateless tests (amd_debug, parallel) — is unrelated to this PR: it is a known flaky test tracked in #111970 with an open fix in #110637. The CI diagnosis re-ran it 212 times with the same randomized settings and it passed every time. The reviewer finding about the test's cleanup path is addressed in 31b96f7e658a (unconditional trap-based cleanup).

…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only red on 31b96f7e — Upgrade check (amd_release) — is unrelated to this PR (which only touches the undropTable refcount wait, InterpreterUndropQuery, and its test). The report title Logical error '!part.empty()' is a misattribution by the crash reporter, which picked up query-echoed comment text from 04367_lambda_arg_backquoted_dot_no_logical_error (the naming bug being fixed in #111708). The actual fatal in the server log is on the old server of the upgrade pair, the released 26.7.3.19, during 03100_lwu_drop_update_race: Logical error: 'Part patch-...-all_0_0_0_1 doesn't exist' in MergeTreeData::modifyPartState reached from MergeTreeData::Transaction::commit ← ReplicatedMergeTreeSink::commitPart ← ReplicatedMergeTreeSinkPatch::finishDelayed, i.e. a lightweight-update patch-part commit race in the old release; no frame touches this PR's code. master has since reworked that path (e.g. commit 13a7d88 in #89658, which is not in 26.7.3.19), and CIDB shows no other occurrence of this signature in 90 days, so this is a rare old-release race that a re-run should clear.

@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 26.7, or verification that 26.7.4 already has it). If the fix is already in progress, link it here.

{
${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"

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.

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.

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Confirmed on the log read, and the old-server attribution holds. The fatal is Part patch-4811bd937f1be8e9d5ec5374e149fefa-all_0_0_0_1 doesn't exist, thrown at MergeTreeData.h:1710, and 1710 is that line in v26.7.1.1315, v26.7.2.59 and v26.7.3.19 only (master 1774, 26.6 1668, 26.5 1633), so it is the old server of the pair. 04367_lambda_arg_backquoted_dot_no_logical_error is a bystander, and no frame touches this PR.

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 finishDelayed -> commitPart -> Transaction::commit -> modifyPartState chain, fired on a plain Stress test (arm_tsan) with no old server in the picture: report (2026-06-22, master-based build). Across 90 days that frame chain has 9 events, 3 of them on master or release refs.

2. master has not reworked that path. Comparing v26.7.3.19-stable with master: Transaction::commit, Transaction::rollback and all three modifyPartState overloads are byte-identical, as are removePartsFromWorkingSet (both overloads), forcefullyMovePartToDetachedAndRemoveFromMemory and dropAllData. 13a7d882e62e only adds four getDataPartStorage().commitTransaction() calls and does not touch Transaction::commit or the throw; the sole ReplicatedMergeTreeSinkPatch.cpp delta between the two is that one line, which runs before commitPart. So there is no fix on master to backport. I should be exact about the limits of that: every one of the 9 CIDB events predates 13a7d882e62e (2026-07-23), so I am arguing from code identity, not from a post-#89658 failure.

3. 26.7.4 is not tagged. Newest 26.7 tag is v26.7.3.19-stable; the 26.7 branch is 29 commits ahead of it and touches only KeyCondition.cpp under MergeTree.

Also worth recording: the same fatal sits in a second Upgrade check (amd_release) report about 6 hours earlier on an unrelated PR, likewise under a misattributed title (report). And it terminates release builds too, not only assertion builds: all three modifyPartState calls sit inside NOEXCEPT_SCOPE, whose catch-all is std::terminate().

The asymmetry that looks like the fix: Transaction::rollback already tolerates data_parts_indexes.empty() when all_data_dropped, while commit has no equivalent tolerance for the same concurrent-drop window.

One caveat before I write that patch. I could not reproduce it on master (5 campaigns, including sleep_before_commit_local_part_in_replicated_table_ms with 126 confirmed sleeps inside the commit window, 0 reproductions), and the standing guidance here is not to change code I cannot back with a repro. Do you want me to open the commit-side tolerance patch on that basis, or keep digging for a deterministic repro first? Either way I will link the result here, and if 26.7 should get it, applying v26.7-must-backport to the merged master PR is the route I would ask you for, since I do not hand-author release-branch PRs.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 9, 2026
Merged via the queue into master with commit e48a8aa Aug 9, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix/undrop-busy-wait-cancellation branch August 9, 2026 16:14
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 9, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi @alexey-milovidov @alesapin — while reviewing this PR I found the following:

Could you review the test PR and add the can be tested label if it looks good?
Happy to discuss — close anything that's wrong or already addressed.

@groeneai

Copy link
Copy Markdown
Collaborator

Closing the loop here, since both halves of your question are now answerable by measurement.

The root cause was a concurrent DROP TABLE clearing data_parts_indexes while the lightweight UPDATE pipeline was still committing its patch part, so MergeTreeData::Transaction::commit called modifyPartState for a part that was already gone. The fix holds the table's SHARE lock across the whole update pipeline, so the DROP waits instead of clearing the index: #114826, merged to master on 2026-08-21 as a5d8725ce148, with a deterministic reproducer (04905_lwu_drop_race_table_lock, driven by the rmt_pause_before_commit_local_part failpoint) rather than the timing-dependent one I could not make fire.

The 26.7 backport is #116466, merged 2026-08-29T20:51:38Z as 4a74aca69bf5; compare/4a74aca6...26.7 is behind_by = 0, so it is an ancestor of the branch tip.

On the second half: 26.7.4 does not have it, and neither does 26.7.5. v26.7.3.19-stable, v26.7.4.58-stable and v26.7.5.10-stable all measure behind that merge commit, and table_locks.emplace_back in InterpreterUpdateQuery.cpp is 0 at v26.7.5.10-stable against 1 on the 26.7 branch. It ships in the next 26.7 patch release.

So this check will not go green yet, and further sightings are expected rather than a sign the fix is wrong: Upgrade check (amd_release) starts a stock released binary, and all 15 sightings of this throw in the last 30 days record it at MergeTreeData.h:1710, which is that line on the 26.7 refs and 1797 on master. On master the race itself is clean since the merge: 03100_lwu_drop_update_race is 0 FAIL against 15102 OK.

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 (26.3) is red on exactly one test out of 732, and that test is mine. tests/queries/shell_config.sh exports CLICKHOUSE_DATABASE_1 on master, 26.6 and 26.7 at line 9, but the 26.3 copy has no such line, so the test's first statement expands to the literal DROP DATABASE IF EXISTS and it aborts with Code: 62 Syntax error ... at position 25. The code half of that backport is complete; only the test cannot run on 26.3.

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.

5 participants