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

hemant 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 adac71e358 HDDS-10057. [Snapshot] 'ozone fs -ls' on '.snapshot' dir of 
a bucket should list only active snapshots (#5924)
adac71e358 is described below

commit adac71e358382f1d9bf76f9e98006b69d04f2207
Author: Hemant Kumar <[email protected]>
AuthorDate: Fri Jan 5 19:26:33 2024 -0800

    HDDS-10057. [Snapshot] 'ozone fs -ls' on '.snapshot' dir of a bucket should 
list only active snapshots (#5924)
    
    * 'ozone fs -ls /vol/bucket/.snapshot'  should list only active snapshots
    
    * Addressed review comment
---
 .../hadoop/fs/ozone/TestOzoneFsSnapshot.java       | 106 ++++++++++++++-------
 .../ozone/BasicRootedOzoneClientAdapterImpl.java   |   7 +-
 2 files changed, 76 insertions(+), 37 deletions(-)

diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFsSnapshot.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFsSnapshot.java
index 90b5daabad..d74c77d343 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFsSnapshot.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFsSnapshot.java
@@ -55,6 +55,7 @@ import static 
org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
 import static org.apache.hadoop.ozone.OzoneConsts.OZONE_OFS_URI_SCHEME;
 import static org.apache.hadoop.ozone.OzoneConsts.OM_SNAPSHOT_INDICATOR;
 import static org.apache.hadoop.ozone.om.OmSnapshotManager.getSnapshotPath;
+import static org.assertj.core.api.Assertions.assertThat;
 
 /**
  * Test client-side CRUD snapshot operations with Ozone Manager.
@@ -257,41 +258,73 @@ class TestOzoneFsSnapshot {
 
   /**
    * Test list snapshot and snapshot keys with "ozone fs -ls".
+   * It also verifies that list .snapshot only lists active snapshots.
    */
   @Test
   void testFsLsSnapshot(@TempDir Path tempDir) throws Exception {
-    String newKey = "key-" + RandomStringUtils.randomNumeric(5);
-    String newKeyPath = BUCKET_PATH + OM_KEY_PREFIX + newKey;
-
+    String key1 = "key-" + RandomStringUtils.randomNumeric(5);
+    String newKeyPath = BUCKET_PATH + OM_KEY_PREFIX + key1;
+    // Pause SnapshotDeletingService so that Snapshot marked deleted is not 
reclaimed.
+    ozoneManager.getKeyManager().getSnapshotDeletingService().suspend();
     // Write a non-zero byte key.
     Path tempFile = tempDir.resolve("testFsLsSnapshot-any-suffix");
     FileUtils.write(tempFile.toFile(), "random data", UTF_8);
-    execShellCommandAndGetOutput(0,
-        new String[]{"-put", tempFile.toString(), newKeyPath});
-    Files.deleteIfExists(tempFile);
-
-    // Create snapshot
-    String snapshotName = createSnapshot();
-    // Setup snapshot paths
-    String snapshotPath = BUCKET_WITH_SNAPSHOT_INDICATOR_PATH +
-        OM_KEY_PREFIX + snapshotName;
-    String snapshotKeyPath = snapshotPath + OM_KEY_PREFIX + newKey;
-
-    // Check for snapshot with "ozone fs -ls"
-    String listSnapOut = execShellCommandAndGetOutput(0,
-        new String[]{"-ls", BUCKET_WITH_SNAPSHOT_INDICATOR_PATH});
-
-    // Assert that output contains above snapshotName
-    Assertions.assertTrue(listSnapOut
-        .contains(snapshotPath));
-
-    // Check for snapshot keys with "ozone fs -ls"
-    String listSnapKeyOut = execShellCommandAndGetOutput(0,
-        new String[]{"-ls", snapshotPath});
+    try {
+      execShellCommandAndGetOutput(0,
+          new String[]{"-put", tempFile.toString(), newKeyPath});
+
+      // Create snapshot
+      String snapshotName1 = createSnapshot();
+      // Setup snapshot paths
+      String snapshotPath1 = BUCKET_WITH_SNAPSHOT_INDICATOR_PATH +
+          OM_KEY_PREFIX + snapshotName1;
+
+      String key2 = "key-" + RandomStringUtils.randomNumeric(5);
+      String newKeyPath2 = BUCKET_PATH + OM_KEY_PREFIX + key2;
+      execShellCommandAndGetOutput(0,
+          new String[]{"-put", tempFile.toString(), newKeyPath2});
+      String snapshotName2 = createSnapshot();
+      String snapshotPath2 = BUCKET_WITH_SNAPSHOT_INDICATOR_PATH +
+          OM_KEY_PREFIX + snapshotName2;
+      String snapshotKeyPath2 = snapshotPath2 + OM_KEY_PREFIX + key2;
+
+      int res = ToolRunner.run(shell,
+          new String[]{"-deleteSnapshot", BUCKET_PATH, snapshotName1});
+      // Asserts that delete request succeeded
+      Assertions.assertEquals(0, res);
 
-    // Assert that output contains the snapshot key
-    Assertions.assertTrue(listSnapKeyOut
-        .contains(snapshotKeyPath));
+      // Wait for the snapshot to be marked deleted.
+      GenericTestUtils.waitFor(() -> {
+        try {
+          SnapshotInfo snapshotInfo = ozoneManager.getMetadataManager()
+              .getSnapshotInfoTable()
+              .get(SnapshotInfo.getTableKey(VOLUME, BUCKET, snapshotName1));
+          return snapshotInfo.getSnapshotStatus() == 
SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED;
+        } catch (IOException e) {
+          throw new RuntimeException(e);
+        }
+      }, 200, 10000);
+
+      // Check for snapshot with "ozone fs -ls"
+      String listSnapOut = execShellCommandAndGetOutput(0,
+          new String[]{"-ls", BUCKET_WITH_SNAPSHOT_INDICATOR_PATH});
+
+      assertThat(listSnapOut).doesNotContain(snapshotName1);
+      assertThat(listSnapOut).contains(snapshotName2);
+
+      // Check for snapshot keys with "ozone fs -ls"
+      String listSnapKeyOut = execShellCommandAndGetOutput(1,
+          new String[]{"-ls", snapshotPath1});
+
+      listSnapKeyOut = execShellCommandAndGetOutput(0,
+          new String[]{"-ls", snapshotPath2});
+      // Assert that output contains the snapshot key
+      assertThat(listSnapKeyOut).contains(snapshotKeyPath2);
+    } finally {
+      // Resume SnapshotDeletingService.
+      ozoneManager.getKeyManager().getSnapshotDeletingService().resume();
+      Files.deleteIfExists(tempFile);
+    }
   }
 
   @Test
@@ -336,13 +369,16 @@ class TestOzoneFsSnapshot {
     Assertions.assertEquals(0, res);
 
     // Wait for the snapshot to be marked deleted.
-    SnapshotInfo snapshotInfo = ozoneManager.getMetadataManager()
-        .getSnapshotInfoTable()
-        .get(SnapshotInfo.getTableKey(VOLUME, BUCKET, snapshotName));
-
-    GenericTestUtils.waitFor(() -> snapshotInfo.getSnapshotStatus().equals(
-            SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED),
-        200, 10000);
+    GenericTestUtils.waitFor(() -> {
+      try {
+        SnapshotInfo snapshotInfo = ozoneManager.getMetadataManager()
+            .getSnapshotInfoTable()
+            .get(SnapshotInfo.getTableKey(VOLUME, BUCKET, snapshotName));
+        return snapshotInfo.getSnapshotStatus() == 
SnapshotInfo.SnapshotStatus.SNAPSHOT_DELETED;
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+    }, 200, 10000);
   }
 
   private static Stream<Arguments> deleteSnapshotFailureScenarios() {
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 8e9a6f4b9f..8804278612 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
@@ -74,6 +74,7 @@ import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
 import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
 import org.apache.hadoop.ozone.om.helpers.OzoneFileStatus;
 import org.apache.hadoop.ozone.om.helpers.OzoneFSUtils;
+import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
 import org.apache.hadoop.ozone.security.OzoneTokenIdentifier;
 import org.apache.hadoop.ozone.snapshot.SnapshotDiffReportOzone;
 import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse;
@@ -823,8 +824,10 @@ public class BasicRootedOzoneClientAdapterImpl
 
     while (snapshotIter.hasNext()) {
       OzoneSnapshot ozoneSnapshot = snapshotIter.next();
-      res.add(getFileStatusAdapterForBucketSnapshot(
-          ozoneBucket, ozoneSnapshot, uri, owner, group));
+      if 
(SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE.name().equals(ozoneSnapshot.getSnapshotStatus()))
 {
+        res.add(getFileStatusAdapterForBucketSnapshot(
+            ozoneBucket, ozoneSnapshot, uri, owner, group));
+      }
     }
 
     return res;


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

Reply via email to