badalprasadsingh commented on code in PR #1637:
URL: https://github.com/apache/iceberg-go/pull/1637#discussion_r3756764679


##########
table/table.go:
##########
@@ -689,12 +703,11 @@ func rewriteRefSnapshotRequirements(reqs []Requirement, 
branch string, fresh Met
 // list is rewritten to include the fresh parent's manifests so that the
 // rebuilt snapshot contains every committed file.
 func rebuildSnapshotUpdates(ctx context.Context, updates []Update, freshMeta 
Metadata, branch string, fs icebergio.WriteFileIO, attempt int) (rebuilt 
[]Update, orphanedPaths []string, err error) {
-       // Determine the fresh branch head to use as the rebuilt snapshot's 
parent.
+       // Must mirror createSnapshotProducer's attempt-0 fallback, or a 
retried new
+       // branch rebuilds with a nil parent and silently drops main's data.
        var freshHead *Snapshot
-       if branch != "" && freshMeta != nil {
-               freshHead = freshMeta.SnapshotByName(branch)
-       } else if freshMeta != nil {
-               freshHead = freshMeta.CurrentSnapshot()
+       if freshMeta != nil {
+               freshHead = latestSnapshotForBranch(freshMeta, branch)

Review Comment:
   Fixed. 
   
   Now, `rebuildSnapshotUpdates` replays staged snapshots as a chain: each 
rebuilt snapshot becomes the parent of the next via the `chainRebuilt` flag. 
The sequence-number and row-id derivations take a max against the freshly 
rebuilt parent so a chained sibling isn't rejected for a duplicate sequence 
number / overlapping row-id range.
   
   Regression Tests Added: `TestMultipleStagedSnapshotsChainOnRetry`, 
`TestMultipleStagedSnapshotsV3RowLineageOnRetry`, 
`TestBranchMultipleStagedSnapshotsChainOnRetry`
   
   Happy to come back to it, in case I missed something.



-- 
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]

Reply via email to