Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -79,9 +81,9 @@
import org.apache.hadoop.ozone.om.service.SnapshotDeletingService;
import org.apache.ozone.test.GenericTestUtils;
import org.apache.ozone.test.tag.Flaky;
import org.apache.ozone.test.tag.Unhealthy;
import org.apache.ratis.util.function.UncheckedAutoCloseableSupplier;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
Expand All @@ -99,7 +101,6 @@

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(OrderAnnotation.class)
@Unhealthy("HDDS-13244")
public class TestSnapshotDeletingServiceIntegrationTest {

private static final Logger LOG =
Expand All @@ -111,6 +112,7 @@ public class TestSnapshotDeletingServiceIntegrationTest {
private OzoneManager om;
private OzoneBucket bucket1;
private OzoneClient client;
private final Deque<UncheckedAutoCloseableSupplier<OmSnapshot>> rcSnaps = new ArrayDeque<>();
private static final String VOLUME_NAME = "vol1";
private static final String BUCKET_NAME_ONE = "bucket1";
private static final String BUCKET_NAME_TWO = "bucket2";
Expand Down Expand Up @@ -154,6 +156,19 @@ public void teardown() {
}
}

@AfterEach
public void closeAllSnapshots() {
while (!rcSnaps.isEmpty()) {
rcSnaps.pop().close();
}
}

private UncheckedAutoCloseableSupplier<OmSnapshot> getOmSnapshot(String volume, String bucket, String snapshotName)
throws IOException {
rcSnaps.push(om.getOmSnapshotManager().getSnapshot(volume, bucket, snapshotName));
return rcSnaps.peek();
}

@Test
@Order(2)
@Flaky("HDDS-11130")
Expand All @@ -171,8 +186,7 @@ public void testSnapshotSplitAndMove() throws Exception {
GenericTestUtils.waitFor(() -> snapshotDeletingService
.getSuccessfulRunCount() >= 1, 1000, 10000);
}
OmSnapshot bucket1snap3 = om.getOmSnapshotManager()
.getSnapshot(VOLUME_NAME, BUCKET_NAME_ONE, "bucket1snap3").get();
OmSnapshot bucket1snap3 = getOmSnapshot(VOLUME_NAME, BUCKET_NAME_ONE, "bucket1snap3").get();

// Check bucket1key1 added to next non deleted snapshot db.
List<? extends Table.KeyValue<String, RepeatedOmKeyInfo>> omKeyInfos =
Expand Down Expand Up @@ -403,9 +417,9 @@ public void testSnapshotWithFSO() throws Exception {
}
om.getKeyManager().getDirDeletingService().suspend();
om.getKeyManager().getDeletingService().suspend();

OmSnapshot snap2 = om.getOmSnapshotManager()
.getSnapshot(VOLUME_NAME, BUCKET_NAME_FSO, "snap2").get();
UncheckedAutoCloseableSupplier<OmSnapshot> rcSnap2 =
getOmSnapshot(VOLUME_NAME, BUCKET_NAME_FSO, "snap2");
OmSnapshot snap2 = rcSnap2.get();
//Child directories should have moved to deleted Directory table to deleted directory table of snap2
assertTableRowCount(dirTable, 0);
assertTableRowCount(keyTable, 11);
Expand All @@ -414,7 +428,7 @@ public void testSnapshotWithFSO() throws Exception {

client.getObjectStore().deleteSnapshot(VOLUME_NAME, BUCKET_NAME_FSO,
"snap2");

rcSnap2.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to close this and rcSnap3 explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the snapshot to get purged we have to get write lock. OmSnapshotManager.get() acquires a read lock. So here we need to explicitly close references for it to get purged.


assertTableRowCount(snapshotInfoTable, 2);

Expand All @@ -428,8 +442,8 @@ public void testSnapshotWithFSO() throws Exception {
assertTableRowCount(om.getMetadataManager().getSnapshotInfoTable(), 2);

verifySnapshotChain(deletedSnap, "/vol1/bucketfso/snap3");
OmSnapshot snap3 = om.getOmSnapshotManager()
.getSnapshot(VOLUME_NAME, BUCKET_NAME_FSO, "snap3").get();
UncheckedAutoCloseableSupplier<OmSnapshot> rcSnap3 = getOmSnapshot(VOLUME_NAME, BUCKET_NAME_FSO, "snap3");
OmSnapshot snap3 = rcSnap3.get();

Table<String, OmKeyInfo> snapDeletedDirTable =
snap3.getMetadataManager().getDeletedDirTable();
Expand Down Expand Up @@ -471,6 +485,8 @@ public void testSnapshotWithFSO() throws Exception {
// Delete Snapshot3 and check entries moved to active DB
client.getObjectStore().deleteSnapshot(VOLUME_NAME, BUCKET_NAME_FSO,
"snap3");
rcSnap3.close();

om.getKeyManager().getDirDeletingService().resume();
om.getKeyManager().getDeletingService().resume();
// Check entries moved to active DB
Expand All @@ -479,9 +495,7 @@ public void testSnapshotWithFSO() throws Exception {
assertTableRowCount(deletedDirTable, 12);
assertTableRowCount(deletedTable, 15);

UncheckedAutoCloseableSupplier<OmSnapshot> rcSnap1 =
om.getOmSnapshotManager().getSnapshot(
VOLUME_NAME, BUCKET_NAME_FSO, "snap1");
UncheckedAutoCloseableSupplier<OmSnapshot> rcSnap1 = getOmSnapshot(VOLUME_NAME, BUCKET_NAME_FSO, "snap1");
OmSnapshot snap1 = rcSnap1.get();
Table<String, OmKeyInfo> snap1KeyTable =
snap1.getMetadataManager().getFileTable();
Expand Down Expand Up @@ -516,7 +530,6 @@ public void testSnapshotWithFSO() throws Exception {
assertTableRowCount(deletedTable, 15);

snap1 = null;
rcSnap1.close();
}

private DirectoryDeletingService getMockedDirectoryDeletingService(AtomicBoolean dirDeletionWaitStarted,
Expand Down
Loading