You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "alessandro-nori (via GitHub)" <gi...@apache.org> on 2026/08/25 08:45:16 UTC
[PR] feat(transaction): clean expired metadata in ExpireSnapshotsAction [iceberg-rust]
alessandro-nori opened a new pull request, #3064:
URL: https://github.com/apache/iceberg-rust/pull/3064
## Which issue does this PR close?
Follows up on #2591, which landed `ExpireSnapshotsAction` and called this out as remaining work: "Left for follow-ups: ... `cleanExpiredMetadata` (removing unreferenced partition specs and schemas)."
## What changes are included in this PR?
Adds `clean_expired_metadata(bool)` to `ExpireSnapshotsAction` (off by default). When enabled, the action also emits `RemoveSchemas` / `RemovePartitionSpecs` for partition specs and schemas that no surviving snapshot references anymore.
- **Schemas** need no I/O: each snapshot records its `schema_id`, so the reachable set is a union over surviving snapshots, seeded with the current schema.
- **Partition specs** require reading each surviving snapshot's manifest list to collect `partition_spec_id`s. The walk is skipped entirely when the table has at most one spec (the common case, so no I/O is added there), reads run concurrently via `buffer_unordered`, and the loop breaks early once every spec is proven reachable.
- The current schema and default spec are always seeded as reachable, so they are never removed.
- `commit()` no longer returns early when nothing expires, since metadata cleanup can still have work to do; it falls back to an empty commit only when no updates are produced at all.
Two intentional differences from the Java implementation, both toward safety/precision:
1. Reachability is computed over the snapshots that **survive** the expiry, rather than over the retained set. Java walks `idsToRetain`, which can still contain a snapshot named explicitly for expiry, causing it to over-retain specs in that case.
2. A surviving snapshot with no `schema_id` suppresses schema removal entirely. Java treats an unknown schema as referencing nothing, which can drop a schema that is still in use; since the id is an explicit `Option` here, this takes the conservative path.
## Are these changes tested?
Yes — 9 new unit tests: unreferenced schema/spec removed, current schema and default spec never removed, schema/spec still used by a retained snapshot survives, the unknown-`schema_id` case, the flag being off by default, cleanup running when nothing expires, and the single-spec table skipping manifest reads. The spec tests write real manifest lists into the table's in-memory `FileIO`.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(transaction): clean expired metadata in ExpireSnapshotsAction [iceberg-rust]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #3064: feat(transaction): clean expired metadata in ExpireSnapshotsAction
URL: https://github.com/apache/iceberg-rust/pull/3064
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(transaction): clean expired metadata in ExpireSnapshotsAction [iceberg-rust]
Posted by "alessandro-nori (via GitHub)" <gi...@apache.org>.
alessandro-nori commented on code in PR #3064:
URL: https://github.com/apache/iceberg-rust/pull/3064#discussion_r3851178040
##########
crates/iceberg/src/transaction/expire_snapshots.rs:
##########
@@ -209,15 +227,112 @@ impl ExpireSnapshotsAction {
}
}
+ // The snapshots that survive this expiry. Note this is not `retained_ids`: a snapshot named
+ // explicitly is expired even when the age/branch policy would have retained it.
+ let surviving_ids: Vec<i64> = metadata
+ .snapshots()
+ .map(|snapshot| snapshot.snapshot_id())
+ .filter(|id| !expiring_ids.contains(id))
+ .collect();
+
let mut ids_to_remove: Vec<i64> = expiring_ids.into_iter().collect();
ids_to_remove.sort_unstable();
removed_ref_names.sort();
Ok(ExpirePlan {
ids_to_remove,
refs_to_remove: removed_ref_names,
+ surviving_ids,
})
}
+ /// Computes the `RemoveSchemas`/`RemovePartitionSpecs` updates for specs and schemas that no
+ /// surviving snapshot references anymore.
+ ///
+ /// The current schema and the default spec are always treated as reachable, so they are never
+ /// removed even when no snapshot uses them yet.
+ async fn clean_expired_metadata_updates(
+ &self,
+ table: &Table,
+ surviving_ids: &[i64],
+ ) -> Result<Vec<TableUpdate>> {
+ let metadata = table.metadata();
+ let mut updates = vec![];
+
+ // Reading a manifest list per surviving snapshot is the expensive part, so skip it when
+ // there is at most one spec: the default spec is reachable by definition, leaving nothing
+ // to remove.
+ if metadata.partition_specs_iter().len() > 1 {
+ let mut reachable_specs: HashSet<i32> =
+ HashSet::from([metadata.default_partition_spec_id()]);
+ let total_specs = metadata.partition_specs_iter().len();
+
+ let readers: Vec<_> = surviving_ids
+ .iter()
+ .filter_map(|id| metadata.snapshot_by_id(*id))
+ .map(|snapshot| table.manifest_list_reader(snapshot))
+ .collect();
+ let mut manifest_lists = stream::iter(readers)
+ .map(|reader| async move {
+ let manifest_list = reader.load().await?;
+ Ok::<HashSet<i32>, Error>(
+ manifest_list
+ .entries()
+ .iter()
+ .map(|entry| entry.partition_spec_id)
+ .collect(),
+ )
+ })
+ .buffer_unordered(available_parallelism().get());
+ while let Some(spec_ids) = manifest_lists.try_next().await? {
+ reachable_specs.extend(spec_ids);
+ // Every spec is in use, so no further reads can change the outcome.
+ if reachable_specs.len() >= total_specs {
+ break;
+ }
+ }
+
+ let mut spec_ids: Vec<i32> = metadata
+ .partition_specs_iter()
+ .map(|spec| spec.spec_id())
+ .filter(|spec_id| !reachable_specs.contains(spec_id))
+ .collect();
+ if !spec_ids.is_empty() {
+ spec_ids.sort_unstable();
+ updates.push(TableUpdate::RemovePartitionSpecs { spec_ids });
+ }
+ }
+
+ // Unlike specs, a snapshot's schema is recorded in metadata, so this needs no I/O. A
+ // snapshot that predates `schema-id` leaves its schema unknown; treating it as referencing
Review Comment:
schema-id is an optional field on a snapshot and snapshots written by older writers don't have it
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(transaction): clean expired metadata in ExpireSnapshotsAction [iceberg-rust]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3064:
URL: https://github.com/apache/iceberg-rust/pull/3064#issuecomment-5824548760
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 dev@iceberg.apache.org list. Thank you for your contributions.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(transaction): clean expired metadata in ExpireSnapshotsAction [iceberg-rust]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3064:
URL: https://github.com/apache/iceberg-rust/pull/3064#issuecomment-5943263740
This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org