Commit 7f72af5
authored
fix(clickhouse): drop orphaned shard table after mirror resync exchange (#4490)
## 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, `RenameTables` does:
1. `EXCHANGE TABLES itunes_apps AND itunes_apps_resync` — swaps the two
Distributed tables
2. `DROP TABLE itunes_apps_resync` — drops the now-old Distributed shell
But this only handles the Distributed layer. The local shard that the
original `itunes_apps` pointed 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's `engine_full` definition using the existing
`getDistributedShardTable` helper. 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
- [ ] Run a mirror resync on a clustered ClickHouse destination
- [ ] Confirm `itunes_apps_shard` (or equivalent old shard) is gone
after resync completes
- [ ] Confirm `itunes_apps` Distributed table still points to the new
timestamped shard and data is intact1 parent c21a707 commit 7f72af5
1 file changed
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
334 | 346 | | |
335 | 347 | | |
336 | 348 | | |
| |||
344 | 356 | | |
345 | 357 | | |
346 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
347 | 368 | | |
348 | 369 | | |
349 | 370 | | |
| |||
0 commit comments