mvanhorn commented on code in PR #10625:
URL: https://github.com/apache/paimon/pull/10625#discussion_r4385516760


##########
paimon-core/src/main/java/org/apache/paimon/utils/TagManager.java:
##########
@@ -132,11 +172,204 @@ public void createTag(
             List<TagCallback> callbacks,
             boolean ignoreIfExists) {
         checkArgument(!StringUtils.isNullOrWhitespaceOnly(tagName), "Tag name 
shouldn't be blank.");
-        if (tagExists(tagName)) {
-            checkArgument(ignoreIfExists, "Tag '%s' already exists.", tagName);
+        // The existence check and metadata write must not race with snapshot 
expiration, which
+        // deletes files based on a tag set collected under the same lock.
+        ReentrantLock coordinationLock = coordinationLock();
+        coordinationLock.lock();
+        try {
+            if (tagExists(tagName)) {
+                checkArgument(ignoreIfExists, "Tag '%s' already exists.", 
tagName);
+                if (awaitSettledTag(tagName)) {
+                    return;
+                }
+            }
+            Runnable beforeCommit = beforeTagCommit;
+            if (beforeCommit != null) {
+                beforeCommit.run();
+            }
+            ensureSnapshotRetained(snapshot, tagName, false);
+            String owner = UUID.randomUUID().toString();
+            createPendingTagMarker(tagName, owner);
+            try {
+                createOrReplaceTag(snapshot, tagName, timeRetained, callbacks, 
true);
+            } finally {
+                fileIO.deleteQuietly(pendingTagMarkerPath(tagName, owner));

Review Comment:
   Fixed in 2fb7c3a. The pending marker is now released in only two cases: 
post-write validation passed, or the rollback deletion is confirmed by checking 
that the tag file is gone afterwards. If the write throws after persisting, 
validation never runs and the marker stays. If validation fails and the tag 
can't be deleted, the marker also stays, and the original exception propagates 
with the delete failure attached as suppressed. Both cases now behave like the 
crashed-creator case: a later `ignoreIfExists` retry waits, then fails with the 
error naming the pending directory. It never acknowledges the tag.
   
   Tests: `testIgnoreIfExistsRejectsWriteFailureAfterPublication` and 
`testIgnoreIfExistsRejectsFailedRollbackDeletion`. Both fail on 7ba4304.
   
   <!-- r:cec9f7dcedc8.7bb2ad7a9250 -->



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