Repository navigation
Preserve a ref's retention policy when its snapshot moves - #4020
Conversation
Branch writes and current-snapshot moves rebuilt refs without carrying their retention fields, clearing policies that create_branch had set. Preserve the existing ref's max ref age, max snapshot age, and min snapshots to keep on those move paths. Refs without retention stay unset. Signed-off-by: 1fanwang <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved issues were identified.
Review effort: Lite
Findings: None
What changed in this PR
Preserves ref retention policies when snapshots move through writes, current-snapshot changes, and rollbacks.
Changes:
- Carries retention fields through ref updates.
- Adds unit and integration regression coverage.
| File | Description |
|---|---|
tests/table/test_manage_snapshots.py |
Adds unit coverage for retention behavior. |
tests/integration/test_writes/test_writes.py |
Adds catalog integration coverage. |
pyiceberg/table/update/snapshot.py |
Preserves retention metadata during snapshot moves. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that's incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions. |
…retention-policy Signed-off-by: 1fanwang <[email protected]>
|
@Fokko review when you can? |
…retention-policy Signed-off-by: 1fanwang <[email protected]>
create_branch now rejects an existing ref name, so the test can no longer use it to put a retention policy on main. Signed-off-by: 1fanwang <[email protected]>
Fokko
left a comment
There was a problem hiding this comment.
Thanks @1fanwang, this looks right and the reproducer is convincing. 🙌
One question: in set_current_snapshot (pyiceberg/table/update/snapshot.py:1262) the new code always reads the existing ref from MAIN_BRANCH, but the method also accepts a ref_name argument. When ref_name is passed, is the intent still to move main, or should the retention be looked up from that ref instead?
It still moves main. The named branch or tag supplies the snapshot ID. Looking up retention on that ref would copy its policy onto main; the update keeps main's own policy instead. iceberg-python/pyiceberg/table/update/snapshot.py Lines 1254 to 1270 in 799acd2 |
|
Makes sense @1fanwang Thanks for adding this |
The intent is always to move main: a few lines below, the call always passes ref_name=MAIN_BRANCH to _set_ref_snapshot, regardless of whether snapshot_id or ref_name was the argument. When ref_name is passed, it only resolves which snapshot_id becomes current, it never changes which ref gets updated. So reading the existing retention from MAIN_BRANCH matches what the method actually does: main's own settings carry forward onto its new snapshot, whichever way that snapshot was chosen. |
Rationale for this change
A ref created with a retention policy (max ref age, max snapshot age and minimum snapshots to keep) loses all three settings once a branch is written to, or once main is moved with set_current_snapshot or rollback_to_snapshot. The ref is rebuilt without them, so the policy a table owner set is silently unset.
Fast-forward already carries the settings over. This change makes branch writes, set_current_snapshot and rollback_to_snapshot do the same, and a ref created without a policy still stays unset. It continues #3770 and is separate from #3760, which expires stale refs.
Are these changes tested?
Yes, with a live reproducer; the commands and observed output are under Testing Done.
Testing Done
The reproducer below uses the public API against a SQLite-backed catalog with a local warehouse. It creates a branch with a policy, writes to it three times, then rolls main back and forward again, printing the policy after each step. A branch created without a policy is the control. The same script runs twice on one checkout: first with the one changed source file taken from origin/main, then with the branch's own file.
Before, with the file from origin/main:
After, with this branch's file:
Only the SQLite-backed SqlCatalog on a local filesystem was exercised.
Reproducer source: repro_ref_retention.py
Are there any user-facing changes?
A ref keeps the retention policy it was created with when its snapshot moves. There is no API change.
AI Disclosure
AI disclosure: GitHub Copilot CLI (GPT-6 Astra and Claude Sonnet 5.5) helped rebase the stale PR, bring it up to date with main, rewrite this description around a live reproducer, and rerun the checks.