peterxcli commented on code in PR #9332:
URL: https://github.com/apache/ozone/pull/9332#discussion_r2988796749


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyCommitRequest.java:
##########
@@ -616,14 +616,23 @@ protected void validateAtomicRewrite(OmKeyInfo existing, 
OmKeyInfo toCommit, Map
     if (toCommit.getExpectedDataGeneration() != null) {
       // These values are not passed in the request keyArgs, so add them into 
the auditMap if they are present
       // in the open key entry.
-      auditMap.put(OzoneConsts.REWRITE_GENERATION, 
String.valueOf(toCommit.getExpectedDataGeneration()));
-      if (existing == null) {
-        throw new OMException("Atomic rewrite is not allowed for a new key", 
KEY_NOT_FOUND);
-      }
-      if 
(!toCommit.getExpectedDataGeneration().equals(existing.getUpdateID())) {
-        throw new OMException("Cannot commit as current generation (" + 
existing.getUpdateID() +
-            ") does not match the expected generation to rewrite (" + 
toCommit.getExpectedDataGeneration() + ")",
-            KEY_NOT_FOUND);
+      Long expectedGen = toCommit.getExpectedDataGeneration();
+      auditMap.put(OzoneConsts.REWRITE_GENERATION, 
String.valueOf(expectedGen));
+
+      if (expectedGen == OzoneConsts.EXPECTED_GEN_CREATE_IF_NOT_EXISTS) {
+        if (existing != null) {
+          throw new OMException("Key already exists",
+              OMException.ResultCodes.KEY_ALREADY_EXISTS);
+        }

Review Comment:
   I think we can use the header to tell the meaning behind the exception
   
   just like how `KEY_NOT_FOUND` is interpreted in 
https://github.com/apache/ozone/pull/9815 in  the context of the normal put and 
conditional put.
   
    
https://github.com/apache/ozone/pull/9815/changes#diff-bd6abd262ed8e24eaeea5cb0e7c2a1a128411b284f9f27dae1ad47be6717a940R198-R201
   ```java
   } else if (ex.getResult() == ResultCodes.KEY_NOT_FOUND
       && getHeaders().getHeaderString(S3Consts.IF_MATCH_HEADER) != null) {
     // If-Match failed because the key doesn't exist
     throw newError(PRECOND_FAILED, keyPath, ex);
   ```



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