Skip to content

Do not truncate external data when a DROP is skipped by ignore_drop_queries_probability - #123214

Merged
alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
groeneai:fix-fake-drop-object-storage-truncate
Oct 4, 2026
Merged

alexey-milovidov merged 5 commits into
ClickHouse:masterfrom
groeneai:fix-fake-drop-object-storage-truncate

Conversation

@groeneai

@groeneai groeneai commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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_probability no longer truncates the data of object storage tables, Alias targets, tables created AS <table function> and object storage inner tables of materialized views, and no longer fails with NOT_IMPLEMENTED for 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 ... and 1 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, Alias tables and AS <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 of 05059's S3('http://localhost:19999/...') table hung, a later DROP DATABASE of the shared stress database made the replica of t_lightweight_mut_3 read-only and blocked behind it holding restart_replica_mutex, so KILL MUTATION got TABLE_IS_READ_ONLY and SYSTEM RESTART REPLICA got ABORTED.

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. File with a user-file path (a local file, no hang), Redis and external TimeSeries targets (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

  • Merged into: 26.10.1.1465-master (included in 26.10 and later)

groeneai and others added 2 commits October 1, 2026 08:29
…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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 1, 2026
@groeneai

groeneai commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author
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).

# Sev Finding Verdict Evidence / action
1 💡 The new comment in InterpreterDropQuery::executeToTableImpl claims more than the condition: File at a user-file path and Redis still get the TRUNCATE AGREE Comment narrowed to the three covered kinds before publication; the File/Redis TRUNCATE stays by design, as the description says
2 💡 02888_system_tables_with_inaccessible_table_function.sql pins the setting to 0 for a reason this change removes (a skipped proxy DROP is now ignored) AGREE Noted, not blocking: the pin still keeps that test's count() check true under Stress
3 💡 First draft of the description said no CI job uses File at a user-file path; 17 .sh tests do under Stress AGREE Description corrected before publication

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261001-083700

@groeneai

groeneai commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. CREATE TABLE t ... ENGINE = S3('http://localhost:19999/dummy.parquet', NOSIGN, Parquet); DROP TABLE t SETTINGS ignore_drop_queries_probability = 1 hangs in S3ClientRetryStrategy: Attempt N/501 on master (killed at 60 s), returns in 0.5 s with the fix.
b Root cause explained? The skipped DROP became a TRUNCATE for every table that does not store data on disk; for object storage it deletes remote objects and retries ~41 min on a dead endpoint holding the DDL guard, and a later DROP DATABASE waits behind it holding restart_replica_mutex.
c Fix matches root cause? Yes. The substitution itself no longer issues the TRUNCATE for these tables; no harness change, no per-test setting pins, no retry tuning.
d Test intent preserved / new tests added? New 05315_ignore_drop_queries_probability_external_data, one case per condition; 03013_ignore_drop_queries_probability unchanged and passing.
e Both directions demonstrated? Yes. The new test fails on master and passes with the fix; deleting each condition fails exactly its own case. The Upgrade check's kill step, run verbatim against a local rig, shows both FAIL rows on master and OK with the fix.
f Fix is general across code paths? Yes. Covers every isObjectStorage() storage (S3/Azure/HDFS/data lakes, *Cluster, the s3:// URL and DatabaseURL delegates), Alias and table function proxies. Memory/KeeperMap/RocksDB keep TRUNCATE (data the table owns); File at a user-file path (local, no hang) and Redis (not in CI) still TRUNCATE, disclosed in the description.
g Fix generalizes across inputs (params/datatypes/wrappers)? The input space is table kinds; each covered kind has a test case.
h Backward compatible? (maintainer-approved exception only) Yes. Only sessions with the testing setting ignore_drop_queries_probability are affected; no default, format or stored state changes.
i Invariants and contracts preserved? For these table kinds a skipped DROP now never does more than a real DROP; the table survives as before, and the existing ignore path (same sync = false, same log line) is reused.

Session id: cron:clickhouse-impl-slot-4:20261001-072400

@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4ab8ff6]

Summary: ✅


AI Review

Summary

This PR narrows the ignore_drop_queries_probability rewrite so skipped DROP no longer truncates several object-storage / proxy cases, and the new 05315 regression test exercises the reported S3-style failures well. But the new predicate still assumes supportsTruncate() means “TRUNCATE is a safe substitute for DROP”, which is not true for every metadata-only engine. As written, the setting can still turn a skipped DROP into a NOT_IMPLEMENTED exception instead of a no-op, so I would still request changes.

Findings
  • ⚠️ Majors
    • [src/Interpreters/InterpreterDropQuery.cpp:230] supportsTruncate() is still not a sound proxy for “this storage can safely replace DROP with TRUNCATE”. StorageQueryRunner, StorageFileLog, and StorageKafka2 all inherit supportsTruncate() == true from IStorage but do not implement truncate, so a skipped DROP on those engines still gets rewritten here and then fails with NOT_IMPLEMENTED from IStorage::truncate instead of being ignored. Suggested fix: introduce an explicit capability for “DROP may be rewritten to TRUNCATE under ignore_drop_queries_probability”, or at minimum make the affected engines override supportsTruncate() to false before relying on this predicate.
    • [src/Interpreters/InterpreterDropQuery.cpp:237] The same rewrite still hits TimeSeries tables whose targets are all external. StorageTimeSeries::drop is metadata-only when !hasInnerTables(), but StorageTimeSeries::truncate throws INCORRECT_QUERY in that case, so DROP TABLE ... SETTINGS ignore_drop_queries_probability = 1 still fails instead of being ignored. Suggested fix: treat StorageTimeSeries with !hasInnerTables() like a metadata-only proxy, or fold it into the explicit capability above. Related thread: Do not truncate external data when a DROP is skipped by ignore_drop_queries_probability #123214 (comment)
Tests
  • ⚠️ Add one focused regression test for a storage that inherits the default supportsTruncate() path (for example QueryRunner). The new 05315 covers storages that already advertise the mismatch via isObjectStorage() / StorageTableFunctionProxy / supportsTruncate() == false, but it would not catch the remaining false positives.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Stop using raw supportsTruncate() as the sole proxy for whether a skipped DROP may be rewritten to TRUNCATE.
    • Handle TimeSeries tables without inner tables in the ignore-drop path.
    • Add a focused regression test for at least one default-supportsTruncate() engine.

LLVM Coverage Report

Measured on commit 4ab8ff6.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.70% 79.70% +0.00%

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 1, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). label Oct 1, 2026
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]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

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

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline.

Job report

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

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.

⚠️ This predicate is still incomplete for 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 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.

@tavplubix

Copy link
Copy Markdown
Member

On a dead endpoint it retries for ~41 minutes holding the table's DDL guard.

should we fix this instead?

@groeneai

groeneai commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

should we fix this instead?

I think these are separate, and this PR is needed either way:

  1. The wait is the S3 client's default retry budget for every request, not something TRUNCATE adds: s3_retry_attempts = 500 with backoff capped at 5 s (src/IO/S3Defines.h:37-39, raised from 100 in Increase the default value of the retries for S3 #89051), and Connection refused is retried like any network error. On this branch, against a closed port, TRUNCATE TABLE t and SELECT * FROM t both sit at Attempt 14/501 ... Connection refused after 30 s, and KILL QUERY ends either in under 2 s (Client::RetryStrategy::ShouldRetry checks isQueryCanceled, src/IO/S3/Client.cpp:113). In the CI job nothing killed the faked DROP. A smaller budget for connection errors would also apply to S3 disks, so I would not change it in this PR.

  2. Even with no retries, the substitution does what a real DROP never does: on a live endpoint it deletes the table's object (on master, the new test's first case then reads HTTP 404), on a glob path it fails with DATABASE_ACCESS_DENIED, and for URL, View, Merge and Null it fails with NOT_IMPLEMENTED. The setting's description only promises the TRUNCATE for Memory and Join (src/Core/Settings.cpp:8843).

&& 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())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the initial point of only truncating the data if we own/store no data?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 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.

groeneai and others added 2 commits October 1, 2026 19:28
…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();

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.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 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 alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, thanks!

@alexey-milovidov alexey-milovidov self-assigned this Oct 3, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 3, 2026
Merged via the queue into ClickHouse:master with commit 16e96ab Oct 4, 2026
149 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 4, 2026
@groeneai

groeneai commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov, could you apply v26.9-must-backport to this PR?

The Upgrade check runs its stress phase with the previous release's server and tests (v26.9.11.2-stable today), and 26.9 does not have this change, so the failure it fixes still shows up on PRs that contain it (report, 2 runs in 30 days). In that run, 26.9's 05059_storage_read_output_resize_clamped_to_max_threads had its DROP TABLE t_resize_object_storage skipped and replaced by a TRUNCATE, which retried localhost:19999 until the server stopped, holding the table lock. DROP DATABASE IF EXISTS test_3 (03053_analyzer_join_alias) then never finished and left test_3.t_update_materialized read-only, so the pre-upgrade KILL MUTATION step failed.

The next 26.9 patch release with the backport would end it; otherwise it lasts until 26.10 is the previous release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-ci 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