Repository navigation
feat(clickhouse): Skip past-retention partitions in attach-partitions - #8567
Merged
Merged
Conversation
attach-partitions had an upper date bound (--max-future-days) but no lower one, so it attached source partitions that were already past retention, including garbage weeks such as 90-19700101. TTL deletes those rows on the destination anyway, and attaching them recreates the destination's block_numbers znode, which prune-partitions then forgets again. On ClickHouse 25.8 an attach into a partition whose znode was forgotten can also fail with ZNONODE when the replica still has the path cached. Skip partitions that prune-partitions would classify as dead_past: past retention plus --retention-margin-days (default 14). Both commands share classify_partition, so they agree on what is dead. The filter only applies when the source table is partitioned by (retention_days, toMonday(...)), since other keys' IDs can't be read as a retention and a week, and the partition key is only read when some candidate looks expired. --include-expired restores the old behaviour. A single --partition-id that is past retention is refused unless --include-expired is passed. Co-Authored-By: Claude <[email protected]>
onewland
marked this pull request as ready for review
October 19, 2026 22:13
ElioDiNino
approved these changes
Oct 19, 2026
MeredithAnya
approved these changes
Oct 19, 2026
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.
attach-partitionsnow skips source partitions that are already past retention, using the same ruleprune-partitionsuses to decide a partition is dead.Until now, discovery mode only had an upper date bound (
--max-future-days). Every past partition with active source parts was attached, including long-expired weeks and garbage partitions such as90-19700101. That causes two problems:What changes:
classify_partitionfromprune_partitions.pyreturnsdead_past, meaningweek_start + 7d + retention_days + --retention-margin-days(default 14) is before today. Both commands use that one function, so they can't disagree about what's expired.(retention_days, toMonday(timestamp)). A key like(retention_days, toStartOfMonth(...))renders the same90-20260601ID shape but isn't weekly, so for any other key every partition is kept. The partition key is only read fromsystem.tableswhen some candidate ID looks expired, so tables with other ID formats don't pay for an extra query.--include-expiredrestores the old behaviour.--partition-idthat is past retention is refused unless--include-expiredis passed, matching how--max-future-daystreats a future partition.prune_partitions.py: the partition-key regex is exposed asis_weekly_retention_partition_key.prune-partitionsbehaves the same.For reviewers:
Skipping partition … past retention. Pass--include-expiredif a backfill really needs expired data.now, so they now passretention_margin=Noneto keep testing boundary and health-check scoping without depending on today's date.🤖 Generated with Claude Code