You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "swamirishi (via GitHub)" <gi...@apache.org> on 2023/05/17 00:54:44 UTC

[GitHub] [ozone] swamirishi commented on a diff in pull request #4657: HDDS-8389. [Snapshot] Added integration test for SnapDiff when OM leader failover happens

swamirishi commented on code in PR #4657:
URL: https://github.com/apache/ozone/pull/4657#discussion_r1195813779


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java:
##########
@@ -927,4 +890,103 @@ public void testSnapshotOpensWithDisabledAutoCompaction() throws Exception {
     }
   }
 
+  // Test snapshot diff when OM restarts in non-HA OM env and diff job is
+  // in_progress when it restarts.
+  @Test
+  public void testSnapshotDiffWhenOmRestart()
+      throws IOException, InterruptedException {
+    String snapshot1 = "snap-" + RandomStringUtils.randomNumeric(5);
+    String snapshot2 = "snap-" + RandomStringUtils.randomNumeric(5);
+    createSnapshots(snapshot1, snapshot2);
+
+    SnapshotDiffResponse response = store.snapshotDiff(volumeName, bucketName,
+        snapshot1, snapshot2, null, 0, false);
+
+    assertEquals(IN_PROGRESS, response.getJobStatus());
+
+    // Restart the OM and wait for sometime to make sure that previous snapDiff
+    // job finishes.
+    cluster.restartOzoneManager();
+    await().atMost(Duration.ofSeconds(120)).
+        until(() -> cluster.getOzoneManager().isRunning());
+
+    response = store.snapshotDiff(volumeName, bucketName,
+        snapshot1, snapshot2, null, 0, false);
+
+    // If job was IN_PROGRESS or DONE state when OM restarted, it should be
+    // DONE by this time.
+    // If job FAILED during crash (which mostly happens in the test because

Review Comment:
   nit: Do we have a unit test case for the FAILED state?



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java:
##########
@@ -844,12 +846,12 @@ private String createSnapshot(String volName, String buckName,
     store.createSnapshot(volName, buckName, snapshotName);
     String snapshotKeyPrefix =
         OmSnapshotManager.getSnapshotPrefix(snapshotName);
-    SnapshotInfo snapshotInfo =
-        leaderOzoneManager.getMetadataManager().getSnapshotInfoTable()
-            .get(SnapshotInfo.getTableKey(volName, buckName, snapshotName));
-    String snapshotDirName =
-        OmSnapshotManager.getSnapshotPath(leaderConfig, snapshotInfo) +
-        OM_KEY_PREFIX + "CURRENT";
+    SnapshotInfo snapshotInfo = ozoneManager.getMetadataManager()
+        .getSnapshotInfoTable()
+        .get(SnapshotInfo.getTableKey(volName, buckName, snapshotName));
+    String snapshotDirName = metaDir + OM_KEY_PREFIX +

Review Comment:
   Why this particular change?



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerHASnapshot.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.om;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.hadoop.ozone.client.OzoneBucket;
+import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
+import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import static org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.JobStatus.DONE;
+import static org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.JobStatus.IN_PROGRESS;
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Tests snapshot in OM HA setup.
+ */
+public class TestOzoneManagerHASnapshot extends TestOzoneManagerHA {
+
+  // Test snapshot diff when OM restarts in HA OM env.
+  @Test
+  public void testSnapshotDiffWhenOmLeaderRestart()
+      throws Exception {
+    OzoneBucket ozoneBucket = setupBucket();
+    String volumeName = ozoneBucket.getVolumeName();
+    String bucketName = ozoneBucket.getName();
+    String snapshot1 = "snap-" + RandomStringUtils.randomNumeric(5);
+    String snapshot2 = "snap-" + RandomStringUtils.randomNumeric(5);
+
+    createKey(ozoneBucket);
+    getObjectStore().createSnapshot(volumeName, bucketName, snapshot1);
+
+    for (int i = 0; i < 100; i++) {
+      createKey(ozoneBucket);
+    }
+
+    getObjectStore().createSnapshot(volumeName, bucketName, snapshot2);
+
+    SnapshotDiffResponse response =
+        getObjectStore().snapshotDiff(volumeName, bucketName,
+            snapshot1, snapshot2, null, 0, false);
+
+    assertEquals(IN_PROGRESS, response.getJobStatus());
+
+    String oldLeader = getCluster().getOMLeader().getOMNodeId();
+
+    OzoneManager omLeader = getCluster().getOMLeader();
+    getCluster().shutdownOzoneManager(omLeader);
+    getCluster().restartOzoneManager(omLeader, true);
+
+    await().atMost(Duration.ofSeconds(120))
+        .until(() -> getCluster().getOMLeader() != null);
+
+    String newLeader = getCluster().getOMLeader().getOMNodeId();
+
+    if (Objects.equals(oldLeader, newLeader)) {
+      // If old leader becomes leader again. Job should be done by this time.
+      response = getObjectStore().snapshotDiff(volumeName, bucketName,
+          snapshot1, snapshot2, null, 0, false);
+      assertEquals(DONE, response.getJobStatus());
+      assertEquals(100, response.getSnapshotDiffReport().getDiffList().size());
+    } else {
+      // If new leader is different from old leader. SnapDiff request will be
+      // new to OM, and job status should be IN_PROGRESS.
+      response = getObjectStore().snapshotDiff(volumeName, bucketName,
+          snapshot1, snapshot2, null, 0, false);
+      assertEquals(IN_PROGRESS, response.getJobStatus());
+      while (true) {
+        response =
+            getObjectStore().snapshotDiff(volumeName, bucketName, snapshot1,
+                snapshot2, null, 0, false);
+        if (DONE == response.getJobStatus()) {
+          assertEquals(100,
+              response.getSnapshotDiffReport().getDiffList().size());
+          break;
+        }
+        Thread.sleep(response.getWaitTimeInMs());
+      }
+    }
+  }
+
+  @Test
+  public void testSnapshotIdConsistency() throws Exception {
+    OzoneBucket ozoneBucket = setupBucket();
+    String volumeName = ozoneBucket.getVolumeName();
+    String bucketName = ozoneBucket.getName();
+
+    createKey(ozoneBucket);
+
+    String snapshotName = "snap-" + RandomStringUtils.randomNumeric(5);
+
+    getObjectStore().createSnapshot(volumeName, bucketName, snapshotName);
+    List<OzoneManager> ozoneManagers = getCluster().getOzoneManagersList();
+    List<String> snapshotIds = new ArrayList<>();
+
+    for (OzoneManager ozoneManager : ozoneManagers) {
+      await().atMost(Duration.ofSeconds(120))
+          .until(() -> {
+            SnapshotInfo snapshotInfo;
+            try {
+              snapshotInfo = ozoneManager.getMetadataManager()
+                  .getSnapshotInfoTable()
+                  .get(SnapshotInfo.getTableKey(volumeName,
+                      bucketName,
+                      snapshotName));
+            } catch (IOException e) {
+              throw new RuntimeException(e);
+            }
+
+            if (snapshotInfo != null) {
+              snapshotIds.add(snapshotInfo.getSnapshotID());
+            }
+            return snapshotInfo != null;
+          });
+    }
+
+    assertEquals(1, snapshotIds.stream().distinct().count());

Review Comment:
   Is snapshotId assertion enough? I guess we should also check rocks db contents. 



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java:
##########
@@ -927,4 +890,103 @@ public void testSnapshotOpensWithDisabledAutoCompaction() throws Exception {
     }
   }
 
+  // Test snapshot diff when OM restarts in non-HA OM env and diff job is
+  // in_progress when it restarts.
+  @Test
+  public void testSnapshotDiffWhenOmRestart()
+      throws IOException, InterruptedException {
+    String snapshot1 = "snap-" + RandomStringUtils.randomNumeric(5);
+    String snapshot2 = "snap-" + RandomStringUtils.randomNumeric(5);
+    createSnapshots(snapshot1, snapshot2);
+
+    SnapshotDiffResponse response = store.snapshotDiff(volumeName, bucketName,
+        snapshot1, snapshot2, null, 0, false);
+
+    assertEquals(IN_PROGRESS, response.getJobStatus());
+
+    // Restart the OM and wait for sometime to make sure that previous snapDiff
+    // job finishes.
+    cluster.restartOzoneManager();
+    await().atMost(Duration.ofSeconds(120)).
+        until(() -> cluster.getOzoneManager().isRunning());
+
+    response = store.snapshotDiff(volumeName, bucketName,
+        snapshot1, snapshot2, null, 0, false);
+
+    // If job was IN_PROGRESS or DONE state when OM restarted, it should be
+    // DONE by this time.
+    // If job FAILED during crash (which mostly happens in the test because
+    // of active snapshot checks), it would be removed by clean up service on
+    // startup, and request after clean up will be considered a new request
+    // and would return IN_PROGRESS. No other state is expected other than
+    // IN_PROGRESS and DONE.
+    if (response.getJobStatus() == DONE) {
+      assertEquals(100, response.getSnapshotDiffReport().getDiffList().size());
+    } else if (response.getJobStatus() == IN_PROGRESS) {
+      Thread.sleep(response.getWaitTimeInMs());
+      response = store.snapshotDiff(volumeName, bucketName,
+          snapshot1, snapshot2, null, 0, false);
+      assertEquals(DONE, response.getJobStatus());
+      assertEquals(100, response.getSnapshotDiffReport().getDiffList().size());
+    } else {
+      fail("Unexpected job status for the test.");
+    }
+  }
+
+  // Test snapshot diff when OM restarts in non-HA OM env and report is
+  // partially received.
+  @Test
+  public void testSnapshotDiffWhenOmRestartAndReportIsPartiallyFetched()
+      throws IOException, InterruptedException {
+    int pageSize = 10;
+    String snapshot1 = "snap-" + RandomStringUtils.randomNumeric(5);
+    String snapshot2 = "snap-" + RandomStringUtils.randomNumeric(5);
+    createSnapshots(snapshot1, snapshot2);
+
+    SnapshotDiffResponse response = store.snapshotDiff(volumeName, bucketName,
+        snapshot1, snapshot2, null, pageSize, false);
+
+    assertEquals(IN_PROGRESS, response.getJobStatus());
+    Thread.sleep(response.getWaitTimeInMs());

Review Comment:
   If it can get flaky putting a wait using GenericTestUtile.waitUnti would be a better thing



##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshot.java:
##########
@@ -927,4 +890,103 @@ public void testSnapshotOpensWithDisabledAutoCompaction() throws Exception {
     }
   }
 
+  // Test snapshot diff when OM restarts in non-HA OM env and diff job is
+  // in_progress when it restarts.
+  @Test
+  public void testSnapshotDiffWhenOmRestart()
+      throws IOException, InterruptedException {
+    String snapshot1 = "snap-" + RandomStringUtils.randomNumeric(5);
+    String snapshot2 = "snap-" + RandomStringUtils.randomNumeric(5);
+    createSnapshots(snapshot1, snapshot2);
+
+    SnapshotDiffResponse response = store.snapshotDiff(volumeName, bucketName,
+        snapshot1, snapshot2, null, 0, false);
+
+    assertEquals(IN_PROGRESS, response.getJobStatus());
+
+    // Restart the OM and wait for sometime to make sure that previous snapDiff
+    // job finishes.
+    cluster.restartOzoneManager();
+    await().atMost(Duration.ofSeconds(120)).
+        until(() -> cluster.getOzoneManager().isRunning());
+
+    response = store.snapshotDiff(volumeName, bucketName,
+        snapshot1, snapshot2, null, 0, false);
+
+    // If job was IN_PROGRESS or DONE state when OM restarted, it should be
+    // DONE by this time.
+    // If job FAILED during crash (which mostly happens in the test because
+    // of active snapshot checks), it would be removed by clean up service on
+    // startup, and request after clean up will be considered a new request
+    // and would return IN_PROGRESS. No other state is expected other than
+    // IN_PROGRESS and DONE.
+    if (response.getJobStatus() == DONE) {
+      assertEquals(100, response.getSnapshotDiffReport().getDiffList().size());
+    } else if (response.getJobStatus() == IN_PROGRESS) {
+      Thread.sleep(response.getWaitTimeInMs());
+      response = store.snapshotDiff(volumeName, bucketName,
+          snapshot1, snapshot2, null, 0, false);
+      assertEquals(DONE, response.getJobStatus());
+      assertEquals(100, response.getSnapshotDiffReport().getDiffList().size());
+    } else {
+      fail("Unexpected job status for the test.");
+    }
+  }
+
+  // Test snapshot diff when OM restarts in non-HA OM env and report is
+  // partially received.
+  @Test
+  public void testSnapshotDiffWhenOmRestartAndReportIsPartiallyFetched()
+      throws IOException, InterruptedException {
+    int pageSize = 10;
+    String snapshot1 = "snap-" + RandomStringUtils.randomNumeric(5);
+    String snapshot2 = "snap-" + RandomStringUtils.randomNumeric(5);
+    createSnapshots(snapshot1, snapshot2);
+
+    SnapshotDiffResponse response = store.snapshotDiff(volumeName, bucketName,
+        snapshot1, snapshot2, null, pageSize, false);
+
+    assertEquals(IN_PROGRESS, response.getJobStatus());
+    Thread.sleep(response.getWaitTimeInMs());

Review Comment:
   Will this sleep make the test flaky for any reason?



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org