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

sammichen pushed a commit to branch HDDS-7593
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/HDDS-7593 by this push:
     new 5b6be2b5b1 HDDS-10754. [hsync] lease recovery contract test class not 
substantiated (#6638)
5b6be2b5b1 is described below

commit 5b6be2b5b12b89ec15681bd77f1ab5654f9e009b
Author: Chung En Lee <[email protected]>
AuthorDate: Tue May 7 09:38:19 2024 +0800

    HDDS-10754. [hsync] lease recovery contract test class not substantiated 
(#6638)
---
 .../ozone/AbstractOzoneFileSystemTestWithFSO.java  |  3 +-
 .../AbstractRootedOzoneFileSystemTestWithFSO.java  |  4 +-
 .../apache/hadoop/fs/ozone/TestLeaseRecovery.java  |  3 +-
 .../ozone/contract/AbstractOzoneContractTest.java  | 44 ++++++++++++++++++
 .../fs/ozone/BasicOzoneClientAdapterImpl.java      | 37 ++++++++++-----
 .../ozone/BasicRootedOzoneClientAdapterImpl.java   | 52 ++++++++++++++++------
 .../hadoop/fs/ozone/OzonePathCapabilities.java     |  1 +
 7 files changed, 116 insertions(+), 28 deletions(-)

diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTestWithFSO.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTestWithFSO.java
index f0ff1ab43b..51f7596f25 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTestWithFSO.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTestWithFSO.java
@@ -27,7 +27,6 @@ import org.apache.hadoop.fs.RemoteIterator;
 import org.apache.hadoop.fs.contract.ContractTestUtils;
 import org.apache.hadoop.ozone.OzoneConsts;
 import org.apache.hadoop.ozone.om.OMMetadataManager;
-import org.apache.hadoop.ozone.om.exceptions.OMException;
 import org.apache.hadoop.ozone.om.helpers.BucketLayout;
 import org.apache.hadoop.ozone.om.helpers.OmBucketInfo;
 import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo;
@@ -504,7 +503,7 @@ abstract class AbstractOzoneFileSystemTestWithFSO extends 
AbstractOzoneFileSyste
     FSDataOutputStream stream = getFs().create(source);
     try {
       // file not visible yet
-      assertThrows(OMException.class, () -> fs.isFileClosed(source));
+      assertThrows(FileNotFoundException.class, () -> fs.isFileClosed(source));
       stream.write(1);
       stream.hsync();
       // file is visible and open
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTestWithFSO.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTestWithFSO.java
index 4d35d863ac..9389a4fdbd 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTestWithFSO.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTestWithFSO.java
@@ -22,7 +22,6 @@ import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.LeaseRecoverable;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.contract.ContractTestUtils;
-import org.apache.hadoop.ozone.om.exceptions.OMException;
 
 import org.apache.hadoop.ozone.om.helpers.BucketLayout;
 import org.junit.jupiter.api.Test;
@@ -30,6 +29,7 @@ import org.junit.jupiter.api.TestInstance;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.FileNotFoundException;
 import java.io.IOException;
 
 import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
@@ -217,7 +217,7 @@ abstract class AbstractRootedOzoneFileSystemTestWithFSO 
extends AbstractRootedOz
     LeaseRecoverable fs = (LeaseRecoverable)getFs();
     FSDataOutputStream stream = getFs().create(source);
     try {
-      assertThrows(OMException.class, () -> fs.isFileClosed(source));
+      assertThrows(FileNotFoundException.class, () -> fs.isFileClosed(source));
       stream.write(1);
       stream.hsync();
       assertFalse(fs.isFileClosed(source));
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java
index 64029b0518..3eb80d03c1 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java
@@ -53,6 +53,7 @@ import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
 import org.slf4j.event.Level;
 
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.ConnectException;
@@ -478,7 +479,7 @@ public class TestLeaseRecovery {
       stream.hsync();
       assertFalse(fs.isFileClosed(file));
 
-      assertThrows(OMException.class, () -> fs.recoverLease(notExistFile));
+      assertThrows(FileNotFoundException.class, () -> 
fs.recoverLease(notExistFile));
     } finally {
       closeIgnoringKeyNotFound(stream);
     }
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/contract/AbstractOzoneContractTest.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/contract/AbstractOzoneContractTest.java
index ab1736c3b0..b79c9a870e 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/contract/AbstractOzoneContractTest.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/contract/AbstractOzoneContractTest.java
@@ -21,6 +21,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.contract.AbstractContractCreateTest;
 import org.apache.hadoop.fs.contract.AbstractContractDeleteTest;
 import org.apache.hadoop.fs.contract.AbstractContractGetFileStatusTest;
+import org.apache.hadoop.fs.contract.AbstractContractLeaseRecoveryTest;
 import org.apache.hadoop.fs.contract.AbstractContractMkdirTest;
 import org.apache.hadoop.fs.contract.AbstractContractOpenTest;
 import org.apache.hadoop.fs.contract.AbstractContractRenameTest;
@@ -33,6 +34,7 @@ import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.apache.hadoop.hdds.ratis.conf.RatisClientConfig;
 import org.apache.hadoop.hdds.utils.IOUtils;
 import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.om.helpers.BucketLayout;
 import org.apache.hadoop.tools.contract.AbstractContractDistCpTest;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
@@ -46,6 +48,7 @@ import java.time.Duration;
 import static org.apache.hadoop.fs.contract.ContractTestUtils.cleanup;
 import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_FS_HSYNC_ENABLED;
 import static org.apache.hadoop.ozone.OzoneConsts.OZONE_OFS_URI_SCHEME;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_DEFAULT_BUCKET_LAYOUT;
 import static org.assertj.core.api.Assumptions.assumeThat;
 
 /**
@@ -312,4 +315,45 @@ abstract class AbstractOzoneContractTest {
     }
   }
 
+  @Nested
+  class TestContractLeaseRecovery extends AbstractContractLeaseRecoveryTest {
+
+    @Override
+    protected AbstractFSContract createContract(Configuration conf) {
+      return createOzoneContract(conf);
+    }
+
+    @Override
+    protected Configuration createConfiguration() {
+      return createOzoneConfig();
+    }
+
+    @Override
+    @Test
+    public void testLeaseRecovery() throws Throwable {
+      assumeThat(getContract().getConf().get(OZONE_DEFAULT_BUCKET_LAYOUT,
+          BucketLayout.FILE_SYSTEM_OPTIMIZED.name()))
+          .isEqualTo(BucketLayout.FILE_SYSTEM_OPTIMIZED.name());
+      super.testLeaseRecovery();
+    }
+
+    @Override
+    @Test
+    public void testLeaseRecoveryFileNotExist() throws Throwable {
+      assumeThat(getContract().getConf().get(OZONE_DEFAULT_BUCKET_LAYOUT,
+          BucketLayout.FILE_SYSTEM_OPTIMIZED.name()))
+          .isEqualTo(BucketLayout.FILE_SYSTEM_OPTIMIZED.name());
+      super.testLeaseRecoveryFileNotExist();
+    }
+
+    @Override
+    @Test
+    public void testLeaseRecoveryFileOnDirectory() throws Throwable {
+      assumeThat(getContract().getConf().get(OZONE_DEFAULT_BUCKET_LAYOUT,
+          BucketLayout.FILE_SYSTEM_OPTIMIZED.name()))
+          .isEqualTo(BucketLayout.FILE_SYSTEM_OPTIMIZED.name());
+      super.testLeaseRecoveryFileOnDirectory();
+    }
+  }
+
 }
diff --git 
a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneClientAdapterImpl.java
 
b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneClientAdapterImpl.java
index d44055236d..b8dbd0de0d 100644
--- 
a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneClientAdapterImpl.java
+++ 
b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicOzoneClientAdapterImpl.java
@@ -83,6 +83,10 @@ import org.apache.hadoop.security.token.Token;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.DIRECTORY_NOT_FOUND;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.FILE_NOT_FOUND;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.NOT_A_FILE;
 import static 
org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.JobStatus.DONE;
 
 import org.slf4j.Logger;
@@ -705,8 +709,18 @@ public class BasicOzoneClientAdapterImpl implements 
OzoneClientAdapter {
   public LeaseKeyInfo recoverFilePrepare(final String pathStr, boolean force) 
throws IOException {
     incrementCounter(Statistic.INVOCATION_RECOVER_FILE_PREPARE, 1);
 
-    return ozoneClient.getProxy().getOzoneManagerClient().recoverLease(
-        volume.getName(), bucket.getName(), pathStr, force);
+    try {
+      return ozoneClient.getProxy().getOzoneManagerClient().recoverLease(
+          volume.getName(), bucket.getName(), pathStr, force);
+    } catch (OMException ome) {
+      if (ome.getResult() == NOT_A_FILE) {
+        throw new FileNotFoundException("Path is not a file. " + 
ome.getMessage());
+      } else if (ome.getResult() == KEY_NOT_FOUND ||
+          ome.getResult() == DIRECTORY_NOT_FOUND) {
+        throw new FileNotFoundException("File does not exist. " + 
ome.getMessage());
+      }
+      throw ome;
+    }
   }
 
   @Override
@@ -771,15 +785,18 @@ public class BasicOzoneClientAdapterImpl implements 
OzoneClientAdapter {
   @Override
   public boolean isFileClosed(String pathStr) throws IOException {
     incrementCounter(Statistic.INVOCATION_IS_FILE_CLOSED, 1);
-    OFSPath ofsPath = new OFSPath(pathStr, config);
-    if (!ofsPath.isKey()) {
-      throw new IOException("not a file");
-    }
-    OzoneFileStatus status = bucket.getFileStatus(pathStr);
-    if (!status.isFile()) {
-      throw new IOException("not a file");
+    try {
+      OzoneFileStatus status = bucket.getFileStatus(pathStr);
+      if (!status.isFile()) {
+        throw new FileNotFoundException("Path is not a file.");
+      }
+      return !status.getKeyInfo().isHsync();
+    } catch (OMException ome) {
+      if (ome.getResult() == FILE_NOT_FOUND) {
+        throw new FileNotFoundException("File does not exist. " + 
ome.getMessage());
+      }
+      throw ome;
     }
-    return !status.getKeyInfo().isHsync();
   }
 
   @Override
diff --git 
a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java
 
b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java
index de9603c475..7db04293e4 100644
--- 
a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java
+++ 
b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java
@@ -101,8 +101,14 @@ import static 
org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_INDICATOR;
 import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
 import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes
     .BUCKET_ALREADY_EXISTS;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.BUCKET_NOT_FOUND;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.DIRECTORY_NOT_FOUND;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.FILE_NOT_FOUND;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.NOT_A_FILE;
 import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes
     .VOLUME_ALREADY_EXISTS;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.VOLUME_NOT_FOUND;
 import static 
org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.JobStatus.DONE;
 
 /**
@@ -1359,17 +1365,26 @@ public class BasicRootedOzoneClientAdapterImpl
     OFSPath ofsPath = new OFSPath(pathStr, config);
     String key = ofsPath.getKeyName();
     if (ofsPath.isRoot() || ofsPath.isVolume()) {
-      throw new IOException("not a file");
+      throw new FileNotFoundException("Path is not a file.");
     } else {
-      OzoneBucket bucket = getBucket(ofsPath, false);
-      if (ofsPath.isSnapshotPath()) {
-        throw new IOException("file is in a snapshot.");
-      } else {
-        OzoneFileStatus status = bucket.getFileStatus(key);
-        if (!status.isFile()) {
-          throw new IOException("not a file");
+      try {
+        OzoneBucket bucket = getBucket(ofsPath, false);
+        if (ofsPath.isSnapshotPath()) {
+          throw new IOException("file is in a snapshot.");
+        } else {
+          OzoneFileStatus status = bucket.getFileStatus(key);
+          if (!status.isFile()) {
+            throw new FileNotFoundException("Path is not a file.");
+          }
+          return !status.getKeyInfo().isHsync();
+        }
+      } catch (OMException ome) {
+        if (ome.getResult() == FILE_NOT_FOUND ||
+            ome.getResult() == VOLUME_NOT_FOUND ||
+            ome.getResult() == BUCKET_NOT_FOUND) {
+          throw new FileNotFoundException("File does not exist. " + 
ome.getMessage());
         }
-        return !status.getKeyInfo().isHsync();
+        throw ome;
       }
     }
   }
@@ -1379,10 +1394,21 @@ public class BasicRootedOzoneClientAdapterImpl
     incrementCounter(Statistic.INVOCATION_RECOVER_FILE_PREPARE, 1);
     OFSPath ofsPath = new OFSPath(pathStr, config);
 
-    OzoneVolume volume = objectStore.getVolume(ofsPath.getVolumeName());
-    OzoneBucket bucket = getBucket(ofsPath, false);
-    return ozoneClient.getProxy().getOzoneManagerClient().recoverLease(
-        volume.getName(), bucket.getName(), ofsPath.getKeyName(), force);
+    try {
+      OzoneBucket bucket = getBucket(ofsPath, false);
+      return ozoneClient.getProxy().getOzoneManagerClient().recoverLease(
+          bucket.getVolumeName(), bucket.getName(), ofsPath.getKeyName(), 
force);
+    } catch (OMException ome) {
+      if (ome.getResult() == NOT_A_FILE) {
+        throw new FileNotFoundException("Path is not a file. " + 
ome.getMessage());
+      } else if (ome.getResult() == KEY_NOT_FOUND ||
+          ome.getResult() == DIRECTORY_NOT_FOUND ||
+          ome.getResult() == VOLUME_NOT_FOUND ||
+          ome.getResult() == BUCKET_NOT_FOUND) {
+        throw new FileNotFoundException("File does not exist. " + 
ome.getMessage());
+      }
+      throw ome;
+    }
   }
 
   @Override
diff --git 
a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzonePathCapabilities.java
 
b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzonePathCapabilities.java
index 5668ff281a..4f15d1b621 100644
--- 
a/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzonePathCapabilities.java
+++ 
b/hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/OzonePathCapabilities.java
@@ -44,6 +44,7 @@ public final class OzonePathCapabilities {
     case CommonPathCapabilities.FS_ACLS:
     case CommonPathCapabilities.FS_CHECKSUMS:
     case CommonPathCapabilities.FS_SNAPSHOTS:
+    case CommonPathCapabilities.LEASE_RECOVERABLE:
       return true;
     default:
       return false;


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

Reply via email to