viirya opened a new issue, #3579:
URL: https://github.com/apache/iceberg-rust/issues/3579
### Apache Iceberg Rust version
main (4dd8c9464)
### Describe the bug
`TableMetadataBuilder::remove_snapshots` drops refs that point at a removed
snapshot with `self.metadata.refs.retain(...)`. This has two problems:
1. No `TableUpdate::RemoveSnapshotRef` is recorded for those refs, so
`changes` (what a REST catalog receives) does not include the ref removals.
2. If `main` is one of the dropped refs, `current_snapshot_id` is left
pointing at the removed snapshot. `build()` then fails with `Cannot set invalid
snapshot log: latest entry is not the current snapshot`.
Java's `TableMetadata.Builder.rewriteSnapshotsInternal` collects the
dangling refs and calls `removeRef(name)` for each. `removeRef` resets
`currentSnapshotId` for `main` and adds a `RemoveSnapshotRef` change when a ref
was removed.
### To Reproduce
Metadata with snapshots 1 and 2, `main` -> 2 and a tag `t` -> 1:
```rust
let result =
metadata.clone().into_builder(None).remove_snapshots(&[1]).build().unwrap();
// changes: [RemoveSnapshots { snapshot_ids: [1] }]
// expected: [RemoveSnapshots { snapshot_ids: [1] }, RemoveSnapshotRef {
ref_name: "t" }]
let result = metadata.into_builder(None).remove_snapshots(&[2]).build();
// Err(DataInvalid => Cannot set invalid snapshot log: latest entry is not
the current snapshot)
// expected: Ok, with current_snapshot_id == None and a RemoveSnapshotRef {
ref_name: "main" } change
```
### Expected behavior
Match Java: remove each dangling ref through `remove_ref`, so the removal is
recorded in `changes` and removing `main` clears `current_snapshot_id`.
### Willingness to contribute
I can contribute a fix for this bug independently
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]