adoroszlai commented on code in PR #6751:
URL: https://github.com/apache/ozone/pull/6751#discussion_r1628874780


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java:
##########
@@ -445,47 +447,49 @@ public MultiDeleteResponse 
multiDelete(@PathParam("bucket") String bucketName,
 
     OzoneBucket bucket = getBucket(bucketName);
     MultiDeleteResponse result = new MultiDeleteResponse();
+    Map<String, ErrorInfo> undeletedKeyResultMap;

Review Comment:
   nit: can join declaration with assignment, as it is not used outside the 
`if` block.



##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java:
##########
@@ -445,47 +447,49 @@ public MultiDeleteResponse 
multiDelete(@PathParam("bucket") String bucketName,
 
     OzoneBucket bucket = getBucket(bucketName);
     MultiDeleteResponse result = new MultiDeleteResponse();
+    Map<String, ErrorInfo> undeletedKeyResultMap;
+    List<String> deleteKeys = new ArrayList<>();
+
     if (request.getObjects() != null) {
       for (DeleteObject keyToDelete : request.getObjects()) {
-        long startNanos = Time.monotonicNowNanos();
-        try {
-          bucket.deleteKey(keyToDelete.getKey());
-          getMetrics().updateDeleteKeySuccessStats(startNanos);
-
-          if (!request.isQuiet()) {
-            result.addDeleted(new DeletedObject(keyToDelete.getKey()));
-          }
-        } catch (OMException ex) {
-          if (isAccessDenied(ex)) {
-            getMetrics().updateDeleteKeyFailureStats(startNanos);
-            result.addError(
-                new Error(keyToDelete.getKey(), "PermissionDenied",
-                    ex.getMessage()));
-          } else if (ex.getResult() != ResultCodes.KEY_NOT_FOUND) {
-            getMetrics().updateDeleteKeyFailureStats(startNanos);
-            result.addError(
-                new Error(keyToDelete.getKey(), "InternalError",
-                    ex.getMessage()));
-          } else {
+        deleteKeys.add(keyToDelete.getKey());
+      }

Review Comment:
   Do we need to add all items first, then remove ones that were successfully 
deleted?  Wouldn't it be better (simpler and more efficient) to just add failed 
deletes inside the loop?
   
   If it's needed for the exception case (where we fail to delete `"ALL"` 
keys), let's create the full list in the `catch` block.
   
   Also, the name `failedDeletes` would better describe this variable.



##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java:
##########
@@ -445,47 +447,49 @@ public MultiDeleteResponse 
multiDelete(@PathParam("bucket") String bucketName,
 
     OzoneBucket bucket = getBucket(bucketName);
     MultiDeleteResponse result = new MultiDeleteResponse();
+    Map<String, ErrorInfo> undeletedKeyResultMap;
+    List<String> deleteKeys = new ArrayList<>();
+
     if (request.getObjects() != null) {
       for (DeleteObject keyToDelete : request.getObjects()) {
-        long startNanos = Time.monotonicNowNanos();
-        try {
-          bucket.deleteKey(keyToDelete.getKey());
-          getMetrics().updateDeleteKeySuccessStats(startNanos);
-
-          if (!request.isQuiet()) {
-            result.addDeleted(new DeletedObject(keyToDelete.getKey()));
-          }
-        } catch (OMException ex) {
-          if (isAccessDenied(ex)) {
-            getMetrics().updateDeleteKeyFailureStats(startNanos);
-            result.addError(
-                new Error(keyToDelete.getKey(), "PermissionDenied",
-                    ex.getMessage()));
-          } else if (ex.getResult() != ResultCodes.KEY_NOT_FOUND) {
-            getMetrics().updateDeleteKeyFailureStats(startNanos);
-            result.addError(
-                new Error(keyToDelete.getKey(), "InternalError",
-                    ex.getMessage()));
-          } else {
+        deleteKeys.add(keyToDelete.getKey());
+      }
+      long startNanos = Time.monotonicNowNanos();
+      try {
+        undeletedKeyResultMap = bucket.deleteKeys(deleteKeys, true);
+        for (DeleteObject d : request.getObjects()) {
+          if (!(undeletedKeyResultMap.containsKey(d.getKey())) ||
+              
undeletedKeyResultMap.get(d.getKey()).getCode().equals(ResultCodes.KEY_NOT_FOUND.name()))
 {
+            // if the key is not found, it is assumed to be successfully 
deleted
+            deleteKeys.remove(d.getKey());
             if (!request.isQuiet()) {
-              result.addDeleted(new DeletedObject(keyToDelete.getKey()));
+              result.addDeleted(new DeletedObject(d.getKey()));
             }
-            getMetrics().updateDeleteKeySuccessStats(startNanos);
+          } else if (undeletedKeyResultMap.containsKey(d.getKey()) &&
+              
!undeletedKeyResultMap.get(d.getKey()).getCode().equals(ResultCodes.KEY_NOT_FOUND.name()))
 {
+            // All errors other than KEY_NOT_FOUND are returned
+            ErrorInfo error = undeletedKeyResultMap.get(d.getKey());
+            result.addError(new Error(d.getKey(), error.getCode(), 
error.getMessage()));
           }

Review Comment:
   We can simplify this by storing the result of map lookup.
   
   Also, when calling `equals()`, put the one known to be not-`null` first (or 
use `Objects.equals()` if either of them can be `null`).
   
   ```java
             ErrorInfo error = undeletedKeyResultMap.get(d.getKey());
             boolean deleted = error == null
                 // if the key is not found, it is assumed to be successfully 
deleted
                 || ResultCodes.KEY_NOT_FOUND.name().equals(error.getCode());
             if (deleted) {
               deleteKeys.remove(d.getKey());
               if (!request.isQuiet()) {
                 result.addDeleted(new DeletedObject(d.getKey()));
               }
             } else {
               result.addError(new Error(d.getKey(), error.getCode(), 
error.getMessage()));
             }
   ```
   
   If you accept the suggestion to avoid filling `deleteKeys` initially, then  
call `deleteKeys.add()` in the `else` block instead of `deleteKeys.remove()` in 
the `if` block.



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