zhang-arvin commented on code in PR #9363:
URL: https://github.com/apache/paimon/pull/9363#discussion_r3934758105


##########
paimon-core/src/main/java/org/apache/paimon/operation/commit/DataEvolutionConflictDetection.java:
##########
@@ -356,8 +368,34 @@ private Optional<RuntimeException> 
checkForRowIdFromSnapshot(
             return Optional.empty();
         }
 
+        // Fail closed when the latest snapshot ID is less than the base 
snapshot ID.
+        // This indicates a rollback has deleted newer snapshots, and the 
staged update
+        // is based on a snapshot lineage that no longer exists.
+        if (latestSnapshot.id() < rowIdCheckFromSnapshot) {
+            return Optional.of(
+                    new RuntimeException(
+                            
ErrorMessages.DATA_EVOLUTION_SNAPSHOT_LINEAGE_CONFLICT_MESSAGE));
+        }
+
+        // Detect equal snapshot IDs with different snapshot UUIDs (ABA 
problem).
+        // A rollback can delete a snapshot and a new commit can reuse the 
same numeric ID.
+        // If the base snapshot UUID differs from the current snapshot UUID at 
that ID,
+        // the staged update is based on a different snapshot lineage.
+        Snapshot baseSnapshot = 
snapshotManager.snapshot(rowIdCheckFromSnapshot);
+        if (baseSnapshot == null) {
+            return Optional.of(
+                    new RuntimeException(
+                            
ErrorMessages.DATA_EVOLUTION_SNAPSHOT_LINEAGE_CONFLICT_MESSAGE));
+        }
+        if (baseSnapshotUuid != null

Review Comment:
   Good catch! I have fixed the single-arg `setRowIdCheckFromSnapshot(Long)` in 
`DataEvolutionConflictDetection` to capture the snapshot UUID from the snapshot 
manager. Now the ABA check will be invoked even when callers use the 
single-argument API. The Spark and Flink callers (MergeInto, DeleteSink) 
already use the two-arg version with explicit UUID, and the single-arg 
convenience methods now also capture UUID for ABA protection.



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

Reply via email to