Repository navigation
Fix an unkillable hang when dropping a low-sorting-name TimeSeries table - #114953
PedroTadim merged 2 commits into
Conversation
DROP TABLE of a TimeSeries table hung forever, and could not be cancelled
with KILL QUERY, whenever the table's own qualified name sorted below its
inner tables' names:
SET allow_experimental_time_series_table = 1;
CREATE TABLE `-ts` ENGINE = TimeSeries;
DROP TABLE `-ts`;
No unusual name is needed to reach it. A materialized view's inner name is
.inner_id.<uuid>, which always sorts below .inner_id.metrics.<uuid>, so
dropping a view declared with ENGINE = TimeSeries hung as well.
InterpreterDropQuery::executeDropQuery did not honour its own
need_ddl_guard contract. It takes the DDL guard for the inner table, then
synthesizes an ASTDropQuery for that same table without setting
no_ddl_lock, so the nested InterpreterDropQuery takes the guard for the
identical name a second time. DDLGuard::table_lock is a unique_lock over a
non-recursive std::mutex, so the thread deadlocks against itself. A mutex
wait is not a cancellation point, which is why KILL QUERY could not land
and the guard for that name stayed held for the server's lifetime.
need_ddl_guard = true reaches that code from a single call site,
StorageTimeSeries::dropInnerTableIfAny, which requests the inner guard only
when the parent name sorts first. That predicate is correct and is kept,
since DDL guards must be taken in increasing name order and the outer DROP
already holds the parent's guard. Only its comment was wrong: it claimed
the inner name is almost always less than the parent's, which holds for
MaterializedView but not for TimeSeries, where it is almost always false.
Set no_ddl_lock on the synthesized AST so the inner name is guarded exactly
once, by the caller, held across the nested execute. InterpreterCreateQuery
already sets the same field for the same reason. The other ten call sites
take the need_ddl_guard = false default, so the change is inert for them.
The null check on ddl_guard in executeToTableImpl is defensive hardening
rather than part of the fix. That shouldReplicateQuery branch is not
reachable from the TimeSeries paths, because executeDropQuery sets
is_replicated_database_internal only when a metadata transaction is
present, and it is already reachable today from InterpreterCreateQuery. It
is guarded because this change routes a second caller through the line.
Validated against a pristine master build: both shapes above time out
before the change and succeed after it, while a high-sorting-name control
passes on both builds. Across a seven-name matrix, every name sorting below
its inner tables hangs before and passes after, and every name sorting
above passes on both. Eight concurrent drops of one table serialize and
complete, and the name is re-creatable afterwards, so no lock is stranded.
…asttest The stress runner passes ignore_drop_queries_probability=0.2. A TimeSeries table does not override storesDataOnDisk, so InterpreterDropQuery rewrites such a DROP into a TRUNCATE, and TRUNCATE never calls dropInnerTableIfAny. The test then observes nothing. Forcing the setting to 1 leaves 13 inner tables behind without the pin and 0 with it. The no-fasttest tag claimed the TimeSeries engine is absent from the fast-test image. registerStorageTimeSeries is called unconditionally in registerStorages.cpp, and the untagged 03222_create_timeseries_table has run in Fast test 3898 times over the last 7 days, so the claim was wrong and the tag needlessly removed the test from the fastest job. No no-replicated-database tag: the test was measured 10 times in that mode and passes, while the same runs against the pre-fix binary hang in DatabaseReplicated::dropTable, so that config covers a real carrier. The comment above may_lock_ddl_guard now states the lock-ordering rule without asserting that a parent guard is always held, which is false on the background dropTableFinally path. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model review (2 rounds, 6 findings adjudicated)Before opening this PR I reviewed the change myself and had a second model review it ❌ Blockers
|
| Finding | Verdict | Action |
|---|---|---|
The test does not disable ignore_drop_queries_probability, so a stress run can rewrite the target DROP into a TRUNCATE and skip the regression path |
Agreed | Fixed. The test now pins the setting to 0. I verified the line is load-bearing rather than decorative with a negative control at the setting's worst case (=1, harder than the stress runner's 0.2): as committed the leak oracle prints 0, and with that single SET deleted it prints 13 surviving inner tables. I did not accept the finding's claim that this reddens CI, because the Stress job validates no per-test stateless results; the real cost is silent loss of coverage. |
The no-fasttest exclusion is unjustified because the TimeSeries engine is available in fast-test builds |
Agreed | Fixed, and the stated justification was simply false: registerStorageTimeSeries is called unconditionally at registerStorages.cpp:144, with no build guard, unlike the optional engines beside it. The untagged 03222_create_timeseries_table, which creates a TimeSeries table, ran in Fast test several thousand times in the last week. The tag and its false comment are gone. |
| The test does not prove the inner-table DDL guard stays continuously held | Disagreed | That is not this PR's contract, and it is not observable: no system table or failpoint exposes DDL guard acquisition, so such an assertion would be a wall-clock race and flaky by construction. The property is evidenced instead by measurement: eight concurrent drops of the same table all complete and the name is reusable afterwards, so the guard is taken and released. Not re-raised on the second round. |
💡 Nits
| Finding | Verdict | Action |
|---|---|---|
The comment claimed the parent DDL guard is always held (StorageTimeSeries.cpp) |
Agreed | Fixed. StorageTimeSeries::drop() reaches this from the background dropTableFinally task, which holds no DDL guard, so the claim was wrong. The comment now states only the ordering rule. |
The comment in executeDropQuery reads as if the guard were unconditionally held |
Agreed, noted, not fixed here | Accurate: the guard is created conditionally at InterpreterDropQuery.cpp:876 and the sentence above no_ddl_lock = need_ddl_guard does not say so, which is untrue for the ten call sites that take the false default. The assignment itself is correct in both branches, so there is no behavioural defect and nothing a test could observe. Better wording for whoever next touches the line: "when the caller took this non-recursive guard, the nested interpreter must not take it again". |
Coverage under --replicated-database was unverified |
Agreed | Measured rather than guessed. The test passes 10/10 in that mode against a two-replica setup using the CI profile. I deliberately did not copy the no-replicated-database tag its siblings carry: against the pre-fix binary the same run hangs, with the deadlock reached through DatabaseReplicated::dropTable, so that config is the only one covering a second real carrier of this bug and tagging it out would delete that coverage. |
I also found one carrier the first round missed and closed it by reading rather than by assumption:
with no_ddl_lock = true the guard is null at InterpreterDropQuery.cpp:274, where it is moved
into tryEnqueueReplicatedDDL. It is only stored to extend a lifetime, never dereferenced, in all
four files along that chain, and that branch is unreachable from the TimeSeries call sites
anyway.
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260815-071000 |
|
Workflow [PR], commit [fcf6b92] Summary: ❌
AI ReviewSummaryThis PR fixes the Tests
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 15/15 (100.00%) · Uncovered code |
|
cc @nikitamikhaylov @evillique, could you review this? |
|
|
||
| -- A TimeSeries whose own name sorts below its inner tables' names used to self-deadlock on the | ||
| -- DDL guard, so this hung instead of returning. | ||
| DROP TABLE IF EXISTS `-ts`; |
There was a problem hiding this comment.
Bugfix validation gate never exercised it: all per-arch validation reports for this PR were empty, and Finish Workflow failed with No per-arch Bugfix Validation job validated the bug.
The green stateless matrix only proves the test passes after the change. For a Bug Fix PR we still need one automated before/after path that reproduces on master and passes on the PR. Please fix the bugfix-validation plumbing for this test (or otherwise add equivalent automated proof) before merging.
There was a problem hiding this comment.
The empty reports are the can be tested label gate, not this test's plumbing.
Config Workflow failed can_be_tested on workflow attempts 1 and 2, so all five Bugfix validation jobs were skipped before they could run, and new_tests_check.py then correctly reported that no arch had validated. The can be tested label was applied at 22:30:23Z and attempt 3 started 3 seconds later; its Config Workflow passed at 22:31:54Z. This comment at 23:20Z reads the attempt-2 report.
In the current run Bugfix validation (functional tests, amd64) and (aarch64) are PENDING, not skipped; only the integration arms are skipped, with the correct reason Skipped, no integration tests updates. I will let them finish and report the outcome rather than predicting it.
No change to the test: 04920 reproduces by hanging on the pre-fix binary, so weakening it to satisfy a gate that was never reached would remove the evidence you are asking for.
Build profile diff (arm_release)Comparing ✅ No significant changes. 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 units7 translation units recompiled, 18 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger — fcf6b92Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
On the Stress row: the stack is Follow-up promised in the bot thread: the Session id: cron:our-pr-ci-monitor:20260816-050000 |
|
cc @vitlibar |
941dd98
ReproducerSET allow_experimental_time_series_table = 1;
CREATE TABLE `-ts` ENGINE = TimeSeries;
DROP TABLE `-ts`; -- hangs forever; KILL QUERY cannot land
-- control: a name sorting above `.inner_id.*` returns normally
CREATE TABLE prom ENGINE = TimeSeries;
DROP TABLE prom;Results:
Backport the fix to CC component owner: @vitlibar @alexey-milovidov Analysis metadata
Introducing change: not identified
|
|
I verified the backport ask independently before relaying it. All five branches are affected and the fix is live on all five, so the request is correct. Measured with the official per-branch binaries (
The control returns on every binary, so the hangs are the defect and not a broken probe. The master binary's One label is enough: Merge forecast, simulated in the shape @alexey-milovidov could you apply |
…sorting-name TimeSeries table
Backport #114953 to 26.6: Fix an unkillable hang when dropping a low-sorting-name TimeSeries table
…sorting-name TimeSeries table
Backport #114953 to 26.7: Fix an unkillable hang when dropping a low-sorting-name TimeSeries table
Cherry pick #114953 to 26.5: Fix an unkillable hang when dropping a low-sorting-name TimeSeries table
Cherry pick #114953 to 26.3: Fix an unkillable hang when dropping a low-sorting-name TimeSeries table
Cherry pick #114953 to 25.8: Fix an unkillable hang when dropping a low-sorting-name TimeSeries table
…sorting-name TimeSeries table
…sorting-name TimeSeries table
…sorting-name TimeSeries table
Backport #114953 to 26.3: Fix an unkillable hang when dropping a low-sorting-name TimeSeries table
Backport #114953 to 26.5: Fix an unkillable hang when dropping a low-sorting-name TimeSeries table
OTHER: DROP of a TimeSeries table whose name sorts below its inner tables -> hang (deadlock). Effect in the production build a394e92: wrong/failing (the upstream test fails on it and passes on official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro/residual/114953.PROD263.txt). Upstream patch unchanged, with its test(s): 04920_timeseries_drop_low_sorting_name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #114259
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a hang when dropping a
TimeSeriestable whose name sorts lexicographically below its inner tables' names, for exampleDROP TABLE `-ts`or dropping a materialized view declared withENGINE = TimeSeries. The drop self-deadlocked on the DDL guard and could not be cancelled withKILL QUERY.Description
DROP TABLEof aTimeSeriestable never returned and could not be killed when the table's ownqualified name sorted below its inner tables' names:
A materialized view's inner name is
.inner_id.<uuid>, which always sorts below.inner_id.metrics.<uuid>, so dropping anMV ... ENGINE = TimeSerieshung too.Root cause.
executeDropQuerytakes the DDL guard for the inner table, then synthesizes anASTDropQueryfor that same table without settingno_ddl_lock, so the nested interpreter takesthe guard for the identical name again.
DDLGuard::table_lockwraps a non-recursivestd::mutex,so the thread deadlocks against itself. A mutex wait is not a cancellation point, so
KILL QUERYcould not land and the guard stayed held for the server's lifetime.
need_ddl_guard = truecomes from one call site,StorageTimeSeries::dropInnerTableIfAny, whichrequests the inner guard only when the parent name sorts first. That predicate is correct and is
kept: guards must be taken in increasing name order. Only its comment was wrong, claiming the
inner name is "almost always less", which holds for
MaterializedViewbut notTimeSeries.The change.
executeDropQuerynow setsno_ddl_lock = need_ddl_guard, so the inner name isguarded exactly once, by the caller, across the nested execute.
InterpreterCreateQuerysets thesame field for the same reason. The fix is inert for the other ten call sites, which all take the
need_ddl_guard = falsedefault. Theddl_guardnull check is pre-existing hardening.Validation. Both shapes time out before the fix and succeed after, while a high-sorting-name
control passes on both builds. Eight concurrent drops serialize and complete and the name is
reusable afterwards, so the guard is still taken and released. New test
04920covers both shapesand asserts no inner table is left behind.
Version info
26.8.1.1839(included in26.8and later)26.7.6.7,26.6.4.12,26.5.8.20,26.3.22.8