Skip to content

Commit 54ed115

Browse files
authored
HDDS-9210. Update snapshot chain restore test to incorporate snapshot delete. (#8484)
1 parent 87dfa5a commit 54ed115

1 file changed

Lines changed: 49 additions & 12 deletions

File tree

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestOzoneManagerHASnapshot.java

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,34 +234,71 @@ public void testSnapshotChainManagerRestore() throws Exception {
234234
List<OzoneBucket> ozoneBuckets = new ArrayList<>();
235235
List<String> volumeNames = new ArrayList<>();
236236
List<String> bucketNames = new ArrayList<>();
237+
List<List<String>> snapshotNamesList = new ArrayList<>();
237238

239+
// Create 10 buckets and initialize snapshot name lists.
238240
for (int i = 0; i < 10; i++) {
239241
OzoneBucket bucket = TestDataUtil.createVolumeAndBucket(client);
240242
ozoneBuckets.add(bucket);
241243
volumeNames.add(bucket.getVolumeName());
242244
bucketNames.add(bucket.getName());
245+
snapshotNamesList.add(new ArrayList<>());
243246
}
244247

245-
for (int i = 0; i < 100; i++) {
246-
int index = i % 10;
247-
createFileKey(ozoneBuckets.get(index),
248-
"key-" + RandomStringUtils.secure().nextNumeric(10));
249-
String snapshot1 = "snapshot-" + RandomStringUtils.secure().nextNumeric(10);
250-
store.createSnapshot(volumeNames.get(index),
251-
bucketNames.get(index), snapshot1);
248+
// Create multiple snapshots for each bucket.
249+
// Here we create 5 snapshots per bucket.
250+
for (int i = 0; i < 5; i++) {
251+
for (int j = 0; j < 10; j++) {
252+
OzoneBucket bucket = ozoneBuckets.get(j);
253+
// Create a new key to generate state change.
254+
createFileKey(bucket, "key-" + RandomStringUtils.secure().nextNumeric(10));
255+
String snapshotName = "snapshot-" + RandomStringUtils.secure().nextNumeric(10);
256+
store.createSnapshot(volumeNames.get(j), bucketNames.get(j), snapshotName);
257+
snapshotNamesList.get(j).add(snapshotName);
258+
}
252259
}
253260

254-
// Restart leader OM
261+
// Restart leader OM.
255262
OzoneManager omLeader = cluster.getOMLeader();
256263
cluster.shutdownOzoneManager(omLeader);
257264
cluster.restartOzoneManager(omLeader, true);
258265

259266
cluster.waitForLeaderOM();
260267
assertNotNull(cluster.getOMLeader());
261-
OmMetadataManagerImpl metadataManager = (OmMetadataManagerImpl) cluster
262-
.getOMLeader().getMetadataManager();
263-
assertFalse(metadataManager.getSnapshotChainManager()
264-
.isSnapshotChainCorrupted());
268+
269+
// Now delete one snapshot from each bucket to simulate snapshot deletion.
270+
for (int j = 0; j < 10; j++) {
271+
// Choose the third snapshot (index 2) if it exists.
272+
if (snapshotNamesList.get(j).size() > 2) {
273+
String snapshotToDelete = snapshotNamesList.get(j).get(2);
274+
store.deleteSnapshot(volumeNames.get(j), bucketNames.get(j), snapshotToDelete);
275+
}
276+
}
277+
278+
// Restart leader OM.
279+
omLeader = cluster.getOMLeader();
280+
cluster.shutdownOzoneManager(omLeader);
281+
cluster.restartOzoneManager(omLeader, true);
282+
283+
cluster.waitForLeaderOM();
284+
assertNotNull(cluster.getOMLeader());
285+
286+
// wait until the snapshots complete deletion
287+
for (int j = 0; j < 10; j++) {
288+
String snapshotToDelete = snapshotNamesList.get(j).get(2);
289+
String tableKey = SnapshotInfo.getTableKey(volumeNames.get(j), bucketNames.get(j), snapshotToDelete);
290+
GenericTestUtils.waitFor(() -> {
291+
try {
292+
return cluster.getOMLeader().getMetadataManager().getSnapshotInfoTable().get(tableKey) == null;
293+
} catch (IOException e) {
294+
throw new RuntimeException(e);
295+
}
296+
}, 1000, 60000);
297+
}
298+
299+
OmMetadataManagerImpl metadataManager = (OmMetadataManagerImpl) cluster.getOMLeader().getMetadataManager();
300+
// Verify that the snapshot chain is not corrupted even after deletions.
301+
assertFalse(metadataManager.getSnapshotChainManager().isSnapshotChainCorrupted());
265302
}
266303

267304
private void createFileKey(OzoneBucket bucket, String keyName)

0 commit comments

Comments
 (0)