Repository navigation
Cherry pick #114953 to 26.3: Fix an unkillable hang when dropping a low-sorting-name TimeSeries table - #115856
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]>
…d-self-deadlock Fix an unkillable hang when dropping a low-sorting-name TimeSeries table
|
The only conflict is in This branch predates master's bool may_lock_ddl_guard = getStorageID().getQualifiedName() < target.table_id.getQualifiedName();Resolution: keep this branch's loop as it is, and take master's replacement comment at /// Best-effort to make them work: the inner table name is almost always less than the TimeSeries name (so it's safe to lock DDLGuard).
/// (See the comment in StorageMaterializedView::dropInnerTableIfAny.)with /// DDLGuards must be locked in order of increasing table name, so the inner guard
/// may be requested only when this table's name sorts first.Preprocessing both revisions ( The fix still bites here: the resolved This branch is affected, measured rather than inferred from the label expansion. Official Treatment (a TimeSeries whose name sorts below its inner tables) hangs and is killed at 90s: SET allow_experimental_time_series_table = 1;
CREATE TABLE `-ts` ENGINE = TimeSeries;
DROP TABLE `-ts`;Control (a name sorting above them) returns normally: SET allow_experimental_time_series_table = 1;
CREATE TABLE prom ENGINE = TimeSeries;
DROP TABLE prom;The control returns on this binary, so the hang is the defect and not a broken fixture. On a I cannot push the resolution myself: I do not have push access to this repository, and this |
Resolve the conflict in src/Storages/StorageTimeSeries.cpp: master reworked the loop to use tryGetTargetTableID, which does not exist on 26.3, so the branch's own target.table_id form is kept and only the reworded comment is taken.
Original pull-request #114953
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job