diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/service/TestDirectoryDeletingServiceWithFSO.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/service/TestDirectoryDeletingServiceWithFSO.java index e64a3f09e216..d4bba6364dc0 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/service/TestDirectoryDeletingServiceWithFSO.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/service/TestDirectoryDeletingServiceWithFSO.java @@ -571,7 +571,7 @@ public void testAOSKeyDeletingWithSnapshotCreateParallelExecution() Table snapshotInfoTable = omMetadataManager.getSnapshotInfoTable(); Table deletedDirTable = omMetadataManager.getDeletedDirTable(); Table renameTable = omMetadataManager.getSnapshotRenamedTable(); - cluster.getOzoneManager().getKeyManager().getSnapshotDeletingService().shutdown(); + cluster.getOzoneManager().getKeyManager().getSnapshotDeletingService().suspend(); DirectoryDeletingService dirDeletingService = cluster.getOzoneManager().getKeyManager().getDirDeletingService(); // Suspend KeyDeletingService dirDeletingService.suspend(); @@ -659,23 +659,7 @@ public void testAOSKeyDeletingWithSnapshotCreateParallelExecution() service.runPeriodicalTaskNow(); store.deleteSnapshot(testVolumeName, testBucketName, snap1); cluster.getOzoneManager().awaitDoubleBufferFlush(); - cluster.restartOzoneManager(); - cluster.waitForClusterToBeReady(); - cluster.getOzoneManager().awaitDoubleBufferFlush(); - SnapshotDeletingService snapshotDeletingService = - cluster.getOzoneManager().getKeyManager().getSnapshotDeletingService(); - GenericTestUtils.waitFor(() -> { - try { - snapshotDeletingService.runPeriodicalTaskNow(); - cluster.getOzoneManager().awaitDoubleBufferFlush(); - long currentSnapshotCount = cluster.getOzoneManager().getMetadataManager() - .countRowsInTable(cluster.getOzoneManager().getMetadataManager().getSnapshotInfoTable()); - return currentSnapshotCount <= initialSnapshotCount; - } catch (Exception e) { - throw new RuntimeException(e); - } - }, 100, 10000); - assertTableRowCount(cluster.getOzoneManager().getMetadataManager().getSnapshotInfoTable(), initialSnapshotCount); + waitForSnapshotsPurged(snapshotInfoTable, initialSnapshotCount); dirDeletingService.resume(); } @@ -789,6 +773,8 @@ public void testDirDeletedTableCleanUpForSnapshot() throws Exception { // Manual cleanup deletedDirTable for next tests client.getObjectStore().deleteSnapshot(volumeName, bucketName, "snap1"); + cluster.getOzoneManager().awaitDoubleBufferFlush(); + waitForSnapshotsPurged(snapshotInfoTable, 0); cleanupTables(); } @@ -823,6 +809,28 @@ static void assertSubPathsCount(LongSupplier pathCount, long expectedCount) 1000, 120000); } + /** + * Wait until SnapshotDeletingService has purged snapshots and snapshotInfoTable + * reaches the expected row count. + */ + private void waitForSnapshotsPurged(Table snapshotInfoTable, + int expectedCount) throws Exception { + SnapshotDeletingService snapshotDeletingService = + cluster.getOzoneManager().getKeyManager().getSnapshotDeletingService(); + snapshotDeletingService.resume(); + GenericTestUtils.waitFor(() -> { + try { + snapshotDeletingService.runPeriodicalTaskNow(); + cluster.getOzoneManager().awaitDoubleBufferFlush(); + return cluster.getOzoneManager().getMetadataManager() + .countRowsInTable(snapshotInfoTable) == expectedCount; +} catch (Exception e) { + throw new RuntimeException("Failed to run SnapshotDeletingService purge task", e); +} + }, 1000, 120000); + assertTableRowCount(snapshotInfoTable, expectedCount); + } + private void assertTableRowCount(Table table, int count) throws TimeoutException, InterruptedException { GenericTestUtils.waitFor(() -> assertTableRowCount(count, table), 1000,