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

ritesh pushed a commit to branch revert-4647-HDDS-8496
in repository https://gitbox.apache.org/repos/asf/ozone.git

commit 604cd995aa9e1930bf6fa33e1b9506b56ef51e6d
Author: Ritesh H Shukla <[email protected]>
AuthorDate: Wed May 3 22:59:05 2023 -0700

    Revert "HDDS-8496. S3 to return not found for object head/set when keyinfo 
indicates a directory. (#4647)"
    
    This reverts commit ebff2f17054ae53c43ad50ca3a2761bfb2e6e307.
---
 .../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, 21 insertions(+), 19 deletions(-)

diff --git a/hadoop-ozone/dist/src/main/smoketest/s3/commonawslib.robot 
b/hadoop-ozone/dist/src/main/smoketest/s3/commonawslib.robot
index 3c69ee8145..86ac9d5ebe 100644
--- a/hadoop-ozone/dist/src/main/smoketest/s3/commonawslib.robot
+++ b/hadoop-ozone/dist/src/main/smoketest/s3/commonawslib.robot
@@ -118,12 +118,6 @@ 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 be0582edd1..1d63bed73d 100644
--- a/hadoop-ozone/dist/src/main/smoketest/s3/objecthead.robot
+++ b/hadoop-ozone/dist/src/main/smoketest/s3/objecthead.robot
@@ -47,14 +47,6 @@ 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 0ee4b59396..327a918898 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,11 +405,9 @@ public class KeyManagerImpl implements KeyManager {
       if (bucketLayout.isFileSystemOptimized()) {
         value = getOmKeyInfoFSO(volumeName, bucketName, keyName);
       } else {
-        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);
+        value = getOmKeyInfoDirectoryAware(volumeName, bucketName, keyName);
+        if (bucketLayout.isLegacy() && value != null && !value.isFile()) {
+          value = null; // Legacy buckets do not report key info for 
directories
         }
       }
     } catch (IOException ex) {
@@ -438,6 +436,24 @@ 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