Skip to content
Merged
Show file tree
Hide file tree
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 @@ -101,9 +101,11 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, Execut
continue;
}
SnapshotInfo nextSnapshot = SnapshotUtils.getNextSnapshot(ozoneManager, snapshotChainManager, fromSnapshot);

// Step 1: Update the deep clean flag for the next active snapshot
SnapshotInfo nextToNextSnapshot = nextSnapshot == null ? null : SnapshotUtils.getNextSnapshot(ozoneManager,
snapshotChainManager, nextSnapshot);
// Step 1: Update the deep clean flag for the next snapshot
updateSnapshotInfoAndCache(nextSnapshot, omMetadataManager, trxnLogIndex);
updateSnapshotInfoAndCache(nextToNextSnapshot, omMetadataManager, trxnLogIndex);
// Step 2: Update the snapshot chain.
updateSnapshotChainAndCache(omMetadataManager, fromSnapshot, trxnLogIndex);
// Step 3: Purge the snapshot from SnapshotInfoTable cache and also remove from the map.
Expand Down Expand Up @@ -140,6 +142,7 @@ private void updateSnapshotInfoAndCache(SnapshotInfo snapInfo, OmMetadataManager
// current snapshot is deleted. We can potentially
// reclaim more keys in the next snapshot.
snapInfo.setDeepClean(false);
snapInfo.setDeepCleanedDeletedDir(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

setting it to false makes the next and the next of next snapshots to perform deep cleaning.
I dunno but why is it use 'false' rather than 'true' to indicate performing deep cleaning? or maybe i didn't understand it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The flag indicates that the snapshot if the snapshot has already been deepCleaned or not. So when it is set to false deep cleaning would be performed on the snapshot


// Update table cache first
omMetadataManager.getSnapshotInfoTable().addCacheEntry(new CacheKey<>(snapInfo.getTableKey()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,11 @@ public void testSnapshotChainInSnapshotInfoTableAfterSnapshotPurge(
SnapshotInfo.getTableKey(getVolumeName(), bucket, snapshotName);
SnapshotInfo snapshotInfo =
getOmMetadataManager().getSnapshotInfoTable().get(snapshotTableKey);
snapshotInfoList.add(snapshotInfo);
snapshotInfo.setDeepClean(true);
snapshotInfo.setDeepCleanedDeletedDir(true);
getOmMetadataManager().getSnapshotInfoTable().addCacheEntry(snapshotTableKey, snapshotInfo,
System.currentTimeMillis());
snapshotInfoList.add(getOmMetadataManager().getSnapshotInfoTable().get(snapshotTableKey));
}
}

Expand All @@ -403,13 +407,16 @@ public void testSnapshotChainInSnapshotInfoTableAfterSnapshotPurge(
assertEquals(totalKeys, numberOfSnapshotBeforePurge);
assertEquals(totalKeys, chainManager.getGlobalSnapshotChain().size());
Map<UUID, ByteString> expectedTransactionInfos = new HashMap<>();
Map<UUID, Boolean> expectedDeepCleanFlags = new HashMap<>();
// Ratis transaction uses term index 1 while creating snapshot.
ByteString expectedLastTransactionVal = TransactionInfo.valueOf(TransactionInfo.getTermIndex(1L))
.toByteString();
for (SnapshotInfo snapshotInfo : snapshotInfoList) {
expectedTransactionInfos.put(snapshotInfo.getSnapshotId(), expectedLastTransactionVal);
expectedDeepCleanFlags.put(snapshotInfo.getSnapshotId(), true);
}
validateSnapshotOrderInSnapshotInfoTableAndSnapshotChain(snapshotInfoList, expectedTransactionInfos);
validateSnapshotOrderInSnapshotInfoTableAndSnapshotChain(snapshotInfoList, expectedTransactionInfos,
expectedDeepCleanFlags);
// Ratis transaction uses term index 200 while purging snapshot.
expectedLastTransactionVal = TransactionInfo.valueOf(TransactionInfo.getTermIndex(200L))
.toByteString();
Expand All @@ -422,8 +429,15 @@ public void testSnapshotChainInSnapshotInfoTableAfterSnapshotPurge(
expectedTransactionInfos.put(chainManager.nextGlobalSnapshot(snapId), expectedLastTransactionVal);
}
if (chainManager.hasNextPathSnapshot(purgeSnapshotInfo.getSnapshotPath(), snapId)) {
expectedTransactionInfos.put(chainManager.nextPathSnapshot(purgeSnapshotInfo.getSnapshotPath(), snapId),
expectedLastTransactionVal);
UUID nextPathSnapshot = chainManager.nextPathSnapshot(purgeSnapshotInfo.getSnapshotPath(), snapId);
expectedTransactionInfos.put(nextPathSnapshot, expectedLastTransactionVal);
expectedDeepCleanFlags.put(nextPathSnapshot, false);
if (chainManager.hasNextPathSnapshot(purgeSnapshotInfo.getSnapshotPath(), nextPathSnapshot)) {
UUID nextToNextPathSnapshot = chainManager.nextPathSnapshot(purgeSnapshotInfo.getSnapshotPath(),
nextPathSnapshot);
expectedTransactionInfos.put(nextToNextPathSnapshot, expectedLastTransactionVal);
expectedDeepCleanFlags.put(nextToNextPathSnapshot, false);
}
}
String purgeSnapshotKey = SnapshotInfo.getTableKey(getVolumeName(),
purgeSnapshotInfo.getBucketName(),
Expand Down Expand Up @@ -453,16 +467,20 @@ public void testSnapshotChainInSnapshotInfoTableAfterSnapshotPurge(
actualNumberOfSnapshotAfterPurge);
assertEquals(expectNumberOfSnapshotAfterPurge, chainManager
.getGlobalSnapshotChain().size());
validateSnapshotOrderInSnapshotInfoTableAndSnapshotChain(snapshotInfoListAfterPurge, expectedTransactionInfos);
validateSnapshotOrderInSnapshotInfoTableAndSnapshotChain(snapshotInfoListAfterPurge, expectedTransactionInfos,
expectedDeepCleanFlags);
}

private void validateSnapshotOrderInSnapshotInfoTableAndSnapshotChain(
List<SnapshotInfo> snapshotInfoList, Map<UUID, ByteString> expectedTransactionInfos) throws IOException {
List<SnapshotInfo> snapshotInfoList, Map<UUID, ByteString> expectedTransactionInfos,
Map<UUID, Boolean> expectedDeepCleanFlags) throws IOException {
if (snapshotInfoList.isEmpty()) {
return;
}
for (SnapshotInfo snapshotInfo : snapshotInfoList) {
assertEquals(snapshotInfo.getLastTransactionInfo(), expectedTransactionInfos.get(snapshotInfo.getSnapshotId()));
assertEquals(snapshotInfo.getDeepClean(), expectedDeepCleanFlags.get(snapshotInfo.getSnapshotId()));
assertEquals(snapshotInfo.getDeepCleanedDeletedDir(), expectedDeepCleanFlags.get(snapshotInfo.getSnapshotId()));
}
OmMetadataManagerImpl metadataManager =
(OmMetadataManagerImpl) getOmMetadataManager();
Expand Down