fix(clickhouse): drop orphaned shard table after mirror resync exchange#4490
Merged
ilidemi merged 1 commit intoJun 24, 2026
Merged
Conversation
After EXCHANGE TABLES during resync, the original Distributed table is dropped but the local shard it referenced (e.g. itunes_apps_shard) was never cleaned up. Resolve the shard name from the Distributed table definition before the exchange, then drop it after the exchange succeeds.
andreyzhelnin-st
had a problem deploying
to
external-contributor
June 24, 2026 16:00 — with
GitHub Actions
Failure
andreyzhelnin-st
temporarily deployed
to
external-contributor
June 24, 2026 16:00 — with
GitHub Actions
Inactive
andreyzhelnin-st
had a problem deploying
to
external-contributor
June 24, 2026 16:00 — with
GitHub Actions
Failure
andreyzhelnin-st
temporarily deployed
to
external-contributor
June 24, 2026 16:00 — with
GitHub Actions
Inactive
andreyzhelnin-st
temporarily deployed
to
external-contributor
June 24, 2026 16:00 — with
GitHub Actions
Inactive
andreyzhelnin-st
temporarily deployed
to
external-contributor
June 24, 2026 21:03 — with
GitHub Actions
Inactive
serprex
approved these changes
Jun 24, 2026
Contributor
|
Thanks for the fix! |
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.
Problem
After a mirror resync on a clustered ClickHouse destination, the old local shard table (e.g.
itunes_apps_shard) is left behind as an orphan.During resync,
RenameTablesdoes:EXCHANGE TABLES itunes_apps AND itunes_apps_resync— swaps the two Distributed tablesDROP TABLE itunes_apps_resync— drops the now-old Distributed shellBut this only handles the Distributed layer. The local shard that the original
itunes_appspointed to (itunes_apps_shard) has no Distributed table referencing it anymore and is never dropped, leaving it as dead storage.Fix
Before the
EXCHANGE, resolve the shard table name from the original Distributed table'sengine_fulldefinition using the existinggetDistributedShardTablehelper. After the exchange and Distributed drop succeed, explicitly drop that shard table.If the shard lookup fails (e.g. non-Distributed engine, single-node deployment), we log a warning and continue — the swap itself is not blocked.
Test plan
itunes_apps_shard(or equivalent old shard) is gone after resync completesitunes_appsDistributed table still points to the new timestamped shard and data is intact