This is an automated email from the ASF dual-hosted git repository.

ritesh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new ebff2f1705 HDDS-8496. S3 to return not found for object head/set when 
keyinfo indicates a directory. (#4647)
ebff2f1705 is described below

commit ebff2f17054ae53c43ad50ca3a2761bfb2e6e307
Author: Duong Nguyen <[email protected]>
AuthorDate: Wed May 3 22:58:17 2023 -0700

    HDDS-8496. S3 to return not found for object head/set when keyinfo 
indicates a directory. (#4647)
---
 .../dist/src/main/smoketest/s3/commonawslib.robot  |  6 +++++
 .../dist/src/main/smoketest/s3/objecthead.robot    |  8 +++++++
 .../org/apache/hadoop/ozone/om/KeyManagerImpl.java | 26 +++++-----------------
 3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/hadoop-ozone/dist/src/main/smoketest/s3/commonawslib.robot 
b/hadoop-ozone/dist/src/main/smoketest/s3/commonawslib.robot
index 86ac9d5ebe..3c69ee8145 100644
--- a/hadoop-ozone/dist/src/main/smoketest/s3/commonawslib.robot
+++ b/hadoop-ozone/dist/src/main/smoketest/s3/commonawslib.robot
@@ -118,6 +118,12 @@ Create legacy bucket
     ${result} =          Execute and checkrc        ozone sh bucket create -l 
LEGACY s3v/${legacy_bucket}   0
     [Return]             ${legacy_bucket}
 
+Create obs bucket
+    ${postfix} =         Generate Ozone String
+    ${bucket} =   Set Variable               obs-bucket-${postfix}
+    ${result} =          Execute and checkrc        ozone sh bucket create -l 
OBJECT_STORE s3v/${bucket}   0
+    [Return]             ${bucket}
+
 Setup s3 tests
     Return From Keyword if    ${OZONE_S3_TESTS_SET_UP}
     Run Keyword        Generate random prefix
diff --git a/hadoop-ozone/dist/src/main/smoketest/s3/objecthead.robot 
b/hadoop-ozone/dist/src/main/smoketest/s3/objecthead.robot
index 1d63bed73d..be0582edd1 100644
--- a/hadoop-ozone/dist/src/main/smoketest/s3/objecthead.robot
+++ b/hadoop-ozone/dist/src/main/smoketest/s3/objecthead.robot
@@ -47,6 +47,14 @@ Head object where path is a directory
                         Should contain          ${result}    404
                         Should contain          ${result}    Not Found
 
+Head directory objects
+    ${obs-bucket} =     Create obs bucket
+    ${result} =         Execute AWSS3APICli and checkrc    put-object --bucket 
${obs-bucket} --key ${PREFIX}/mydir/ --body /tmp/testfile   0
+    ${result} =         Execute AWSS3APICli and checkrc    head-object 
--bucket ${obs-bucket} --key ${PREFIX}/mydir   255
+                        Should contain          ${result}    404
+                        Should contain          ${result}    Not Found
+    ${result} =         Execute AWSS3APICli and checkrc    head-object 
--bucket ${obs-bucket} --key ${PREFIX}/mydir/   0
+
 Head non existing key
     ${result} =         Execute AWSS3APICli and checkrc    head-object 
--bucket ${BUCKET} --key ${PREFIX}/non-existent   255
                         Should contain          ${result}    404
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java
index 327a918898..0ee4b59396 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java
@@ -405,9 +405,11 @@ public class KeyManagerImpl implements KeyManager {
       if (bucketLayout.isFileSystemOptimized()) {
         value = getOmKeyInfoFSO(volumeName, bucketName, keyName);
       } else {
-        value = getOmKeyInfoDirectoryAware(volumeName, bucketName, keyName);
-        if (bucketLayout.isLegacy() && value != null && !value.isFile()) {
-          value = null; // Legacy buckets do not report key info for 
directories
+        value = getOmKeyInfo(volumeName, bucketName, keyName);
+        if (value != null) {
+          // For Legacy & OBS buckets, any key is a file by default. This is to
+          // keep getKeyInfo compatible with OFS clients.
+          value.setFile(true);
         }
       }
     } catch (IOException ex) {
@@ -436,24 +438,6 @@ public class KeyManagerImpl implements KeyManager {
     return value;
   }
 
-  private OmKeyInfo getOmKeyInfoDirectoryAware(String volumeName,
-            String bucketName, String keyName) throws IOException {
-    OmKeyInfo keyInfo = getOmKeyInfo(volumeName, bucketName, keyName);
-
-    // Check if the key is a directory.
-    if (keyInfo != null) {
-      keyInfo.setFile(true);
-      return keyInfo;
-    }
-
-    String dirKey = OzoneFSUtils.addTrailingSlashIfNeeded(keyName);
-    OmKeyInfo dirKeyInfo = getOmKeyInfo(volumeName, bucketName, dirKey);
-    if (dirKeyInfo != null) {
-      dirKeyInfo.setFile(false);
-    }
-    return dirKeyInfo;
-  }
-
   private OmKeyInfo getOmKeyInfo(String volumeName, String bucketName,
                                  String keyName) throws IOException {
     String keyBytes =


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to