Expire stale refs in ExpireSnapshots#3246
Open
alessandro-nori wants to merge 1 commit intoapache:mainfrom
Open
Expire stale refs in ExpireSnapshots#3246alessandro-nori wants to merge 1 commit intoapache:mainfrom
alessandro-nori wants to merge 1 commit intoapache:mainfrom
Conversation
73e24a0 to
8373d34
Compare
alessandro-nori
commented
Apr 16, 2026
| MIN_SNAPSHOTS_TO_KEEP = "history.expire.min-snapshots-to-keep" | ||
| MIN_SNAPSHOTS_TO_KEEP_DEFAULT = 1 | ||
|
|
||
| MAX_REF_AGE_MS = "history.expire.max-ref-age-ms" |
Contributor
Author
There was a problem hiding this comment.
this is not used in this PR but I thought it could be useful for callers of ExpireSnapshot to get the default value for max-ref-age-ms from table properties (like in the Java implementation)
alessandro-nori
commented
Apr 16, 2026
| for snapshot in self._transaction.table_metadata.snapshots: | ||
| if snapshot.timestamp_ms < expire_from and snapshot.snapshot_id not in protected_ids: | ||
| self._snapshot_ids_to_expire.add(snapshot.snapshot_id) | ||
| self._expire_older_than_ms = datetime_to_millis(dt) |
Contributor
Author
There was a problem hiding this comment.
moved most of the logic to _commit() to avoid order-dependence between older_than() and
remove_expired_refs() calls
alessandro-nori
commented
Apr 16, 2026
| table_v2.catalog.commit_table.return_value = mock_response | ||
|
|
||
| # Remove any refs that protect the snapshots to be expired | ||
| table_v2.metadata = table_v2.metadata.model_copy( |
Contributor
Author
There was a problem hiding this comment.
removed because it duplicates old line 205?
b45c6fe to
dcfdd04
Compare
dcfdd04 to
ad0a92d
Compare
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.
Changes
remove_expired_refs(default_max_ref_age_ms)method onExpireSnapshots: removes branches/tags whose snapshot age exceeds theirmax_ref_age_ms(per-ref setting, with fallback to the method parameter);mainis never removedolder_than()is now lazy — threshold is evaluated in_commit()so that call order withremove_expired_refs()does not affect the result_get_protected_snapshot_ids()to exclude refs marked for removal, so their orphaned snapshots become eligible for age-based expiryMotivation
Mirrors Java's
RemoveSnapshots.computeRetainedRefs()behavior. Previously,ExpireSnapshotsnever removed stale refs even whenmax-ref-age-mswas configured on a branch or tag.This PR was AI-assisted.