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


##########
table/metadata.go:
##########
@@ -390,6 +390,45 @@ func (b *MetadataBuilder) currentSnapshot() *Snapshot {
        return s
 }
 
+// currentSnapshotForRef resolves the parent for createSnapshotProducer and 
mergeOverwrite.
+// An unknown branch falls back to currentSnapshot() so a new
+// branch forks from main — the opposite of currentSnapshotIDForRef,
+// which must return nil there so AssertRefSnapshotID can prove the branch is 
absent;
+// never derive one from the other. A present-but-dangling ref also yields nil.
+func (b *MetadataBuilder) currentSnapshotForRef(ref string) *Snapshot {
+       if ref == "" || ref == MainBranch {
+               return b.currentSnapshot()
+       }
+
+       r, ok := b.refs[ref]
+       if !ok {
+               return b.currentSnapshot()
+       }
+
+       s, _ := b.SnapshotByID(r.SnapshotID)
+
+       return s
+}
+
+// currentSnapshotIDForRef returns the commit's AssertRefSnapshotID id (its 
only caller).
+// An unknown branch returns nil so the requirement proves the branch is 
absent —
+// unlike currentSnapshotForRef, whose parent lookup falls back to main's head
+// so a new branch can fork from it;
+// the two must not be conflated or new-branch creates get a false OCC 
rejection.
+func (b *MetadataBuilder) currentSnapshotIDForRef(ref string) *int64 {
+       if ref == "" || ref == MainBranch {
+               return b.currentSnapshotID

Review Comment:
   Done. 
   
   The guard is now exactly where you asked (construction), and it covers all 
three helpers at once. `TestBranchCommitRejectsNameThatBecomesATagOnRetry` 
asserts the replay is rejected before a second `CommitTable` (cat.attempts == 
1) and that the tag is neither advanced nor converted.
   
   



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