Repository navigation
Cancel background merges early in DROP DATABASE for ordinary shared merge tree - #98161
Merged
alexey-milovidov merged 2 commits intoFeb 27, 2026
Merged
Conversation
Contributor
CheSema
approved these changes
Feb 27, 2026
Merged
via the queue into
ClickHouse:master
with commit Feb 27, 2026
78a7f5f
287 of 288 checks passed
pda
added a commit
to buildkite-forks/ClickHouse
that referenced
this pull request
Sep 11, 2026
`TRUNCATE ALL TABLES` used the database shutdown-preparation path before truncating each storage. After PR ClickHouse#98161 moved permanent `MergeTree` merge cancellation into `flushAndPrepareForShutdown`, this left live tables unable to merge and caused later `OPTIMIZE FINAL` queries to fail with `ABORTED`. Route filtered and unfiltered `TRUNCATE TABLES` through the existing per-table truncate path. Keep shutdown preparation unchanged for `DROP`, `DETACH`, and `TRUNCATE DATABASE`. Add a regression that truncates a `MergeTree`, inserts two new parts, runs `OPTIMIZE FINAL`, and verifies that they merge into one active part. Regression associated with: ClickHouse#98161
pda
added a commit
to buildkite-forks/ClickHouse
that referenced
this pull request
Sep 11, 2026
The unfiltered `TRUNCATE ALL TABLES FROM db` form used the database shutdown-preparation path before truncating each storage. After PR ClickHouse#98161 moved permanent `MergeTree` merge cancellation into `flushAndPrepareForShutdown`, this left live tables unable to merge and caused later `OPTIMIZE FINAL` queries to fail with `ABORTED`. Route the unfiltered form through the existing per-table truncate path already used by filtered `TRUNCATE TABLES ... LIKE` queries. Keep shutdown preparation unchanged for `DROP`, `DETACH`, and `TRUNCATE DATABASE`. Add a regression that truncates a `MergeTree`, inserts two new parts, runs `OPTIMIZE FINAL`, and verifies that they merge into one active part. Regression associated with: ClickHouse#98161
pda
added a commit
to buildkite-forks/ClickHouse
that referenced
this pull request
Sep 11, 2026
PR ClickHouse#98161 moved permanent `MergeTree` merge and move cancellation into `flushAndPrepareForShutdown`. The unfiltered `TRUNCATE ALL TABLES FROM db` form used this database shutdown-preparation path before truncating each storage, leaving retained tables unable to merge and causing later `OPTIMIZE TABLE ... FINAL` queries to fail with `ABORTED`. Source-built probes at the exact PR boundary confirm the attribution. Its first parent passes unfiltered, ordinary, and filtered truncate probes. The merge commit fails only the unfiltered probes with Code 236, while the ordinary and filtered controls continue to pass. Route the unfiltered form through the existing per-table truncate path already used by filtered `TRUNCATE TABLES ... LIKE` queries. Keep shutdown preparation unchanged for `DROP`, `DETACH`, and `TRUNCATE DATABASE`. This also aligns unfiltered truncation with `LIKE '%'` for databases where `shouldBeEmptyOnDetach` is false and for read-only database metadata disks, instead of retaining the previous no-op or per-table `DETACH` behavior. Add a regression that truncates a `MergeTree`, inserts two new parts, runs `OPTIMIZE FINAL`, and verifies that they merge into one active part. Regression introduced by: ClickHouse#98161
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In InterpreterDropQuery::executeToDatabaseImpl(), currently flushAndPrepareForShutdown() is not override, so we depends StorageMergeTree::shutdown() to cancel background merges in executeToTableImpl() in sequence
So we override StorageMergeTree::flushAndPrepareForShutdown() to cancel background merges early in prepare stage in parallel.
Note: we already override StorageReplicatedMergeTree::flushAndPrepareForShutdown() for replicated merge tree.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Cancel background merges early in DROP DATABASE for ordinary shared merge tree.
Documentation entry for user-facing changes
Version info
26.3.1.120