joyhaldar opened a new pull request, #15038: URL: https://github.com/apache/iceberg/pull/15038
### Description Currently when expiring snapshots, the code walks the ancestor chain twice: 1. [computeBranchSnapshotsToRetain](https://github.com/apache/iceberg/blob/7f81e1e93084e50fa3676c2e131722f66a26b385/core/src/main/java/org/apache/iceberg/RemoveSnapshots.java#L316) - finds snapshots to retain 2. [unreferencedSnapshotsToRetain](https://github.com/apache/iceberg/blob/7f81e1e93084e50fa3676c2e131722f66a26b385/core/src/main/java/org/apache/iceberg/RemoveSnapshots.java#L331) - finds all referenced snapshots for orphan detection This PR combines both into a single walk, tracking retained and referenced snapshots together. also skips the orphan check entirely when all snapshots are referenced, common case for tables without orphans. ### Complexity | Scenario | Before | After | |----------|--------|-------| | Tables without orphans | O(2N + k) | O(N) | | Tables with orphans | O(2N + k) | O(2N) | Where N = total snapshots, k = retained snapshots. ### Testing - All existing `TestRemoveSnapshots` tests pass. - Added `testExpireSnapshotsWithoutOrphans` and `testExpireSnapshotsWithOrphans` to validate both paths. -- 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]
