Skip to content

Fix ignore_drop_queries_probability breaking dependencies during DROP DATABASE - #102506

Merged
shankar-iyer merged 1 commit into
masterfrom
fix-stress-test-ttl-dependency-attach
Apr 13, 2026
Merged

shankar-iyer merged 1 commit into
masterfrom
fix-stress-test-ttl-dependency-attach

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Apr 12, 2026 •

Copy link
Copy Markdown
Member

The stress test setting ignore_drop_queries_probability could selectively ignore individual table drops within a DROP DATABASE operation. Since DROP DATABASE skips same-database dependency checks (by design), this could leave a dependent table alive while dropping the table it depends on.

For example, table A with a TTL WHERE a IN (SELECT a FROM B) referencing table B: if A's drop is ignored but B's drop proceeds, the server cannot restart because A's TTL expression references a nonexistent table B.

The fix disables ignore_drop_queries_probability for table drops that are part of a DROP DATABASE operation, similar to how it's already disabled for secondary queries and refreshable materialized views.

Root cause analysis of the Stress test (arm_debug) failure in #100300:

  1. Test 02908_table_ttl_dependency creates 02908_main and 02908_dependent (TTL WHERE references 02908_main) in test_3
  2. Cleanup DROPs are ignored by ignore_drop_queries_probability=0.2 — both tables survive
  3. A different test (03655_keeper_map_alter_comment) runs DROP DATABASE IF EXISTS test_3
  4. Tables are sorted by dependency order for dropping: 02908_dependent first
  5. DROP TABLE 02908_dependent is randomly ignored (20% probability)
  6. DROP TABLE 02908_main passes the dependency check (same-database dependents are skipped for DROP DATABASE) and succeeds
  7. 02908_dependent is orphaned with a TTL referencing nonexistent 02908_main
  8. Server restart fails: Unknown table expression identifier 'test_3.02908_main'

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100300&sha=4bcde9f5e2ff130c9fdb0192330170491c0b9015&name_0=PR&name_1=Stress%20test%20%28arm_debug%29

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

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code

Version info

  • Merged into: 26.4.1.865

…g DROP DATABASE

The stress test setting `ignore_drop_queries_probability` could selectively
ignore individual table drops within a `DROP DATABASE` operation. Since
`DROP DATABASE` skips same-database dependency checks (by design), this could
leave a dependent table alive while dropping the table it depends on.

For example, table A with a TTL referencing table B: if A's drop is ignored
but B's drop proceeds, the server cannot restart because A's TTL expression
references a nonexistent table B.

The fix disables `ignore_drop_queries_probability` for table drops that are
part of a `DROP DATABASE` operation, similar to how it's already disabled
for secondary queries and refreshable materialized views.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100300&sha=4bcde9f5e2ff130c9fdb0192330170491c0b9015&name_0=PR&name_1=Stress%20test%20%28arm_debug%29
Related PR: #100300

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Apr 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f1c0f88]

Summary: ✅


AI Review

Summary

This PR fixes a real stress-test failure mode where ignore_drop_queries_probability could skip an individual table drop inside DROP DATABASE, leaving dependency-orphaned tables and causing restart-time exceptions. The change is small, targeted, and correctly scopes the probabilistic ignore behavior away from DROP DATABASE-driven table drops. I did not find correctness, safety, performance, or compatibility regressions in the patch.

ClickHouse Rules
Item Status Notes
Deletion logging ✅
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Apr 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.00% -0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.50% -0.10%

Changed lines: 100.00% (10/10) | lost baseline coverage: 2 line(s) · Uncovered code

Full report · Diff report

@shankar-iyer
shankar-iyer added this pull request to the merge queue Apr 13, 2026
Merged via the queue into master with commit c278a51 Apr 13, 2026
164 checks passed
@shankar-iyer
shankar-iyer deleted the fix-stress-test-ttl-dependency-attach branch April 13, 2026 06:41
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 13, 2026
bacek pushed a commit to bacek/ClickHouse that referenced this pull request Aug 15, 2026
…rder

`DatabaseCatalog::checkTableCanBeRemovedOrRenamedUnlocked` skips dependent
tables from the same database when the removal comes from `DROP DATABASE`,
and carried a TODO asking for tables to be unloaded in reverse topological
order instead.

That ordering exists since ClickHouse#97057:
`InterpreterDropQuery::executeToDatabaseImpl` sorts the tables of a
`DROP DATABASE` in reverse loading dependency order, so a dependent is always
dropped before the table it depends on. The skip here is still required - the
dependency graph is consulted per table while the database is being emptied -
so only the obsolete TODO is replaced by a pointer to the code that maintains
the invariant.

Related: ClickHouse#87369
Related: ClickHouse#102506

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants