hemantk-12 commented on code in PR #7112:
URL: https://github.com/apache/ozone/pull/7112#discussion_r1735262179


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOzoneManagerHASnapshot.java:
##########
@@ -265,4 +277,104 @@ private void createFileKey(OzoneBucket bucket, String 
keyName)
       fileKey.write(value);
     }
   }
+
+
+
+  /**
+   * This is to simulate HDDS-11152 scenario. In which a follower's 
doubleBuffer is lagging and accumulates purgeKey
+   * and purgeSnapshot in same batch.
+   */
+  @Test
+  public void testKeyAndSnapshotDeletionService() throws IOException, 
InterruptedException, TimeoutException {
+    OzoneManager omLeader = cluster.getOMLeader();
+    OzoneManager omFollower;
+
+    if (omLeader != cluster.getOzoneManager(0)) {
+      omFollower = cluster.getOzoneManager(0);
+    } else {
+      omFollower = cluster.getOzoneManager(1);
+    }
+
+    int numKeys = 5;
+    List<String> keys = new ArrayList<>();
+    for (int i = 0; i < numKeys; i++) {
+      String keyName = "key-" + RandomStringUtils.randomNumeric(10);
+      createFileKey(ozoneBucket, keyName);
+      keys.add(keyName);
+    }
+
+    // Stop the key deletion service so that deleted keys get trapped in the 
snapshots.
+    omLeader.getKeyManager().getDeletingService().suspend();
+    // Stop the snapshot deletion service so that deleted keys get trapped in 
the snapshots.
+    omLeader.getKeyManager().getSnapshotDeletingService().suspend();
+
+    // Delete half of the keys
+    for (int i = 0; i < numKeys / 2; i++) {
+      ozoneBucket.deleteKey(keys.get(i));
+    }
+
+    String snapshotName = "snap-" + RandomStringUtils.randomNumeric(10);
+    createSnapshot(volumeName, bucketName, snapshotName);
+
+    store.deleteSnapshot(volumeName, bucketName, snapshotName);
+
+    // Pause double buffer on follower node to accumulate all the key purge, 
snapshot delete and purge transactions.
+    
omFollower.getOmRatisServer().getOmStateMachine().getOzoneManagerDoubleBuffer().stopDaemon();
+
+    long keyDeleteServiceCount = 
omLeader.getKeyManager().getDeletingService().getRunCount().get();
+    omLeader.getKeyManager().getDeletingService().resume();
+
+    GenericTestUtils.waitFor(
+        () -> 
omLeader.getKeyManager().getDeletingService().getRunCount().get() > 
keyDeleteServiceCount,
+        1000, 60000);
+
+    long snapshotDeleteServiceCount = 
omLeader.getKeyManager().getSnapshotDeletingService().getRunCount().get();
+    omLeader.getKeyManager().getSnapshotDeletingService().resume();
+
+    GenericTestUtils.waitFor(
+        () -> 
omLeader.getKeyManager().getSnapshotDeletingService().getRunCount().get() > 
snapshotDeleteServiceCount,
+        1000, 60000);
+
+    String tableKey = SnapshotInfo.getTableKey(volumeName, bucketName, 
snapshotName);
+    checkSnapshotIsPurgedFromDB(omLeader, tableKey);
+
+    // Resume the DoubleBuffer and flush the pending transactions.
+    OzoneManagerDoubleBuffer omDoubleBuffer =
+        
omFollower.getOmRatisServer().getOmStateMachine().getOzoneManagerDoubleBuffer();
+    omDoubleBuffer.resume();
+    CompletableFuture.supplyAsync(() -> {
+      omDoubleBuffer.flushTransactions();
+      return null;
+    });
+    omDoubleBuffer.awaitFlush();
+    checkSnapshotIsPurgedFromDB(omFollower, tableKey);
+  }
+
+  private void createSnapshot(String volName, String buckName, String 
snapName) throws IOException {
+    store.createSnapshot(volName, buckName, snapName);
+
+    String tableKey = SnapshotInfo.getTableKey(volName, buckName, snapName);
+    SnapshotInfo snapshotInfo = cluster.getOMLeader().getMetadataManager()

Review Comment:
   Yes, changed it to use `SnapshotUtils.getSnapshotInfo`.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to