Repository navigation
Do not truncate external data when a DROP is skipped by ignore_drop_queries_probability - #123214
Conversation
…ueries_probability Under `ignore_drop_queries_probability` a DROP of a table that does not store data on disk was rewritten to TRUNCATE. For object storage tables (`ENGINE = S3/Azure/HDFS/...`, also through the `s3://` URL delegate), `Alias` tables and `CREATE TABLE ... AS <table function>` proxies that TRUNCATE acts on data outside the server: it deletes the remote objects, empties the alias target, or truncates whatever the table function points at. A real DROP of the same table touches none of it. On an unreachable endpoint the TRUNCATE retries for ~41 minutes (500 attempts, 5 s backoff cap) while holding the table's DDL guard. In the Upgrade check (amd_release) on PR ClickHouse#123013 the faked DROP of 05059's `ENGINE = S3('http://localhost:19999/dummy.parquet', ...)` table hung this way; a later `DROP DATABASE` of the shared stress database then prepared every table for shutdown (bricking the replica of `t_lightweight_mut_3`) and blocked behind it holding `restart_replica_mutex`, so the pre-upgrade cleanup could neither kill the leftover replicated mutation (TABLE_IS_READ_ONLY) nor restart the replica (ABORTED). Such DROPs are now ignored, as for tables that store data on disk. The table survives either way, so the set of tables left behind by Stress and the Upgrade check does not change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Narrow the ignore-DROP comment to the storage kinds it covers; File and Redis tables still truncate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own cold review (3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261001-083700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261001-072400 |
|
Workflow [PR], commit [4ab8ff6] Summary: ✅
AI ReviewSummaryThis PR narrows the Findings
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit 4ab8ff6.
Changed lines: Changed C/C++ lines covered: 10/10 (100.00%) · Uncovered code |
Under `ignore_drop_queries_probability`, a skipped DROP of a table
that reports `supportsTruncate() == false` (`URL`, including the
scheme-dispatched `URL('file://...')`, `View`, `Merge`, `Null`,
`Dictionary`, ...) was still rewritten to TRUNCATE and failed with
NOT_IMPLEMENTED (`Cannot TRUNCATE dictionary` for a dictionary).
These storages hold no data of their own, so a real DROP deletes
nothing; ignore the DROP like for the other kinds.
A materialized view's TRUNCATE truncates its inner table, so apply the
same checks to the inner table: an `ENGINE = Null` view failed with
NOT_IMPLEMENTED, and an object storage inner table had its objects
deleted, which a real DROP does not do. A view whose inner table
stores data on disk keeps the TRUNCATE, as before.
`StorageAlias` reports `supportsTruncate() == false`, so the explicit
`StorageAlias` arm is now covered by the property and removed. The
table function proxy stays checked before `supportsTruncate`, because
`StorageProxy::supportsTruncate` resolves the nested storage.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline. |
| if (materialized_view && materialized_view->hasInnerTable()) | ||
| inner_table = materialized_view->tryGetTargetTable(); | ||
|
|
||
| if (table->storesDataOnDisk() || keeps_data_on_drop(*table) || (inner_table && keeps_data_on_drop(*inner_table))) |
There was a problem hiding this comment.
TimeSeries tables whose targets are all external. For that flavor, a real DROP is metadata-only (StorageTimeSeries::drop returns without touching the targets when !hasInnerTables()), but the skipped-drop path here still rewrites it to TRUNCATE, which then throws INCORRECT_QUERY in src/Storages/StorageTimeSeries.cpp:522. That means ignore_drop_queries_probability still makes a skipped DROP do more than the real statement for this engine.
Please either treat StorageTimeSeries with !hasInnerTables() like the MATERIALIZED VIEW ... TO <existing_table> case, or move this decision behind a storage-level capability that answers whether TRUNCATE is a safe substitute for DROP.
There was a problem hiding this comment.
🕵 This PR is already merged (16e96ab), so this cannot be changed here. The case is still open on master: a TimeSeries table with only external targets (!hasInnerTables()) is still rewritten to TRUNCATE and fails with INCORRECT_QUERY. It only affects the test-only setting ignore_drop_queries_probability. The cleaner fix is a storage-level capability ("is TRUNCATE a safe substitute for DROP") rather than adding more special cases to the interpreter. That needs a separate follow-up PR.
should we fix this instead? |
I think these are separate, and this PR is needed either way:
|
| && std::uniform_real_distribution<>(0.0, 1.0)(thread_local_rng) <= static_cast<double>(settings[Setting::ignore_drop_queries_probability])) | ||
| { | ||
| ast_drop_query.sync = false; | ||
| if (table->storesDataOnDisk()) |
There was a problem hiding this comment.
What was the initial point of only truncating the data if we own/store no data?
There was a problem hiding this comment.
It comes from #61476 (closes #39636, raised in #27928 (comment)). A skipped DROP keeps the table alive for the rest of the stress/upgrade run, and for in-memory engines that means keeping all their rows in RAM, so the DROP became a TRUNCATE to reduce memory usage. Tables that store data on disk are left untouched and get loaded again after the restart. The first version matched Memory/Join by name; !storesDataOnDisk() replaced it in review, which also kept Join because it persists its data.
But !storesDataOnDisk() is also true for engines whose data is outside the server: for S3/Azure the TRUNCATE deletes the objects (StorageObjectStorage::truncate calls removeObjectsIfExist), and for URL/Merge it fails with NOT_IMPLEMENTED. This PR keeps the TRUNCATE for the memory case and skips it where a real DROP does not touch the data.
There was a problem hiding this comment.
🕵 Thanks, the explanation above answers the question: the TRUNCATE substitution came from #61476 to save memory for in-memory engines whose DROP was skipped in stress runs. The merged change keeps that and skips the TRUNCATE where a real DROP would not touch the data. Nothing more to change in this (already merged) PR.
…t-storage-truncate # Conflicts: # src/Interpreters/InterpreterDropQuery.cpp
In the AsyncInsert CI lane the `INSERT INTO FUNCTION s3(..., filename = currentDatabase() || ...)` went through the async insert queue. The flush context is built from the global context and does not carry the session database, so `currentDatabase()` in the table function arguments evaluated to `default` and the object was written to `default_skipped_drop_proxy.tsv`. The following `SELECT * FROM t_proxy` then read a missing key and failed with HTTP 404 on every rerun. Same root cause as ClickHouse#122560. Pin `async_insert = 0` on that one insert. The other inserts go into tables whose path was fixed at CREATE time and are not affected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| /// The proxy is checked first: its `supportsTruncate` resolves the table function. | ||
| auto keeps_data_on_drop = [](const IStorage & storage) | ||
| { | ||
| return storage.isObjectStorage() || typeid_cast<const StorageTableFunctionProxy *>(&storage) || !storage.supportsTruncate(); |
There was a problem hiding this comment.
This predicate is still too optimistic for storages that inherit the default supportsTruncate() == true but do not implement truncate. For example, StorageQueryRunner, StorageFileLog, and StorageKafka2 all fall through here (storesDataOnDisk() == false, not object storage, not a table-function proxy), so DROP TABLE ... SETTINGS ignore_drop_queries_probability = 1 is still rewritten to TRUNCATE and then fails with NOT_IMPLEMENTED from IStorage::truncate instead of being ignored.
That means supportsTruncate() is not equivalent to “TRUNCATE is a safe substitute for DROP”. Could we move this behind an explicit storage capability, or at least make these metadata-only / external engines report supportsTruncate() == false, before relying on it here?
There was a problem hiding this comment.
🕵 This PR is already merged (16e96ab). The point still applies on master: StorageFileLog, StorageKafka2, StorageQueryRunner (and any engine that keeps the default supportsTruncate() == true without implementing truncate) are still rewritten to TRUNCATE and fail with NOT_IMPLEMENTED under ignore_drop_queries_probability. The right fix is an explicit storage capability, or having those engines report supportsTruncate() == false. That is a separate follow-up because it changes several storages and only affects this test-only setting.
alexey-milovidov
left a comment
There was a problem hiding this comment.
This is good, thanks!
|
@alexey-milovidov, could you apply The Upgrade check runs its stress phase with the previous release's server and tests ( The next 26.9 patch release with the backport would end it; otherwise it lasts until 26.10 is the previous release. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A DROP skipped by the testing setting
ignore_drop_queries_probabilityno longer truncates the data of object storage tables,Aliastargets, tables createdAS <table function>and object storage inner tables of materialized views, and no longer fails withNOT_IMPLEMENTEDfor tables that do not support TRUNCATE (URL,View,Merge,Null, ...).Description
Related: #121409. No related open issue found.
Failing job: Upgrade check (amd_release) on #123013:
Cannot restart a read-only replica ...and1 mutations could not be killed before the upgrade.Under
ignore_drop_queries_probability, a DROP of a table that does not store data on disk becomes a TRUNCATE. For object storage tables,Aliastables andAS <table function>proxies, that TRUNCATE acts on data outside the server (remote objects, the alias target, the function's data), which a real DROP never touches. On a dead endpoint it retries for ~41 minutes holding the table's DDL guard. In that job, the faked DROP of05059'sS3('http://localhost:19999/...')table hung, a laterDROP DATABASEof the shared stress database made the replica oft_lightweight_mut_3read-only and blocked behind it holdingrestart_replica_mutex, soKILL MUTATIONgotTABLE_IS_READ_ONLYandSYSTEM RESTART REPLICAgotABORTED.These DROPs are now ignored, like DROPs of tables that store data on disk. So are DROPs of tables without TRUNCATE support (it failed with
NOT_IMPLEMENTED) and of materialized views with such an inner table. The table survives either way, so Stress and the Upgrade check keep the same set of leftover tables.Filewith a user-file path (a local file, no hang),Redisand externalTimeSeriestargets (not used in CI) still get a TRUNCATE.Validation: the new test fails on master and passes with the fix; each condition has a case that fails without it. A local rig running the Upgrade check's mutation kill step verbatim reproduces both FAIL rows on master and reports OK with the fix. 50/50 randomized runs pass.
Reach: Stress runs the PR's own server, so it is fixed at once. The Upgrade check's stress phase runs the previous release (26.9.7.9 today), so that job can still fail this way until the previous release contains this change.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123214]
Version info
26.10.1.1465-master(included in26.10and later)