aswinshakil commented on code in PR #4935:
URL: https://github.com/apache/ozone/pull/4935#discussion_r1238938110
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyDeletingService.java:
##########
@@ -153,9 +194,194 @@ public BackgroundTaskResult call() {
manager.getMetadataManager().getTableLock(
OmMetadataManagerImpl.DELETED_TABLE).writeLock().unlock();
}
+
+ try {
+ if (delCount < keyLimitPerTask) {
+ processSnapshotDeepClean(delCount);
+ }
+ } catch (Exception e) {
+ LOG.error("Error while running deep clean on snapshots. Will " +
+ "retry at next run.", e);
+ }
+
}
// By design, no one cares about the results of this call back.
return EmptyTaskResult.newResult();
}
+
+ private void processSnapshotDeepClean(int delCount)
+ throws IOException {
+ OmSnapshotManager omSnapshotManager =
+ getOzoneManager().getOmSnapshotManager();
+ OmMetadataManagerImpl metadataManager = (OmMetadataManagerImpl)
+ getOzoneManager().getMetadataManager();
+ SnapshotChainManager snapChainManager = metadataManager
+ .getSnapshotChainManager();
+ Table<String, SnapshotInfo> snapshotInfoTable =
+ getOzoneManager().getMetadataManager().getSnapshotInfoTable();
+ List<String> deepCleanedSnapshots = new ArrayList<>();
+ try (TableIterator<String, ? extends Table.KeyValue
+ <String, SnapshotInfo>> iterator = snapshotInfoTable.iterator()) {
+
+ while (delCount < keyLimitPerTask && iterator.hasNext()) {
+ List<BlockGroup> keysToPurge = new ArrayList<>();
+ HashMap<String, RepeatedOmKeyInfo> keysToModify = new HashMap<>();
+ SnapshotInfo currSnapInfo = iterator.next().getValue();
+
+ // Deep clean only on active snapshot. Deleted Snapshots will be
+ // cleaned up by SnapshotDeletingService.
+ if (!currSnapInfo.getSnapshotStatus().equals(SNAPSHOT_ACTIVE) ||
+ !currSnapInfo.getDeepClean()) {
+ continue;
+ }
+
+ OmSnapshot currOmSnapshot = (OmSnapshot) omSnapshotManager
+ .checkForSnapshot(currSnapInfo.getVolumeName(),
+ currSnapInfo.getBucketName(),
+ getSnapshotPrefix(currSnapInfo.getName()),
+ true);
+
+ Table<String, RepeatedOmKeyInfo> snapDeletedTable =
+ currOmSnapshot.getMetadataManager().getDeletedTable();
+ Table<String, String> snapRenamedTable =
+ currOmSnapshot.getMetadataManager().getSnapshotRenamedTable();
+
+ long volumeId = metadataManager.getVolumeId(
+ currSnapInfo.getVolumeName());
+ // Get bucketInfo for the snapshot bucket to get bucket layout.
+ String dbBucketKey = metadataManager.getBucketKey(
+ currSnapInfo.getVolumeName(), currSnapInfo.getBucketName());
+ OmBucketInfo bucketInfo = metadataManager.getBucketTable()
+ .get(dbBucketKey);
+
+ if (bucketInfo == null) {
+ throw new IllegalStateException("Bucket " + "/" + currSnapInfo
+ .getVolumeName() + "/" + currSnapInfo.getBucketName() +
+ " is not found. BucketInfo should not be null for snapshotted"
+
+ " bucket. The OM is in unexpected state.");
+ }
+
+ String snapshotBucketKey = dbBucketKey + OzoneConsts.OM_KEY_PREFIX;
+ SnapshotInfo previousSnapshot = getPreviousActiveSnapshot(
+ currSnapInfo, snapChainManager, omSnapshotManager);
+ Table<String, OmKeyInfo> previousKeyTable = null;
+ OmSnapshot omPreviousSnapshot = null;
+
+ // Split RepeatedOmKeyInfo and update current snapshot
deletedKeyTable
+ // and next snapshot deletedKeyTable.
+ if (previousSnapshot != null) {
+ omPreviousSnapshot = (OmSnapshot) omSnapshotManager
+ .checkForSnapshot(previousSnapshot.getVolumeName(),
+ previousSnapshot.getBucketName(),
+ getSnapshotPrefix(previousSnapshot.getName()), true);
+
+ previousKeyTable = omPreviousSnapshot
+
.getMetadataManager().getKeyTable(bucketInfo.getBucketLayout());
+ }
+
+ try (TableIterator<String, ? extends Table.KeyValue<String,
+ RepeatedOmKeyInfo>> deletedIterator = snapDeletedTable
+ .iterator()) {
+
+ deletedIterator.seek(snapshotBucketKey);
+ while (deletedIterator.hasNext() && delCount < keyLimitPerTask) {
+ Table.KeyValue<String, RepeatedOmKeyInfo>
+ deletedKeyValue = deletedIterator.next();
+ String deletedKey = deletedKeyValue.getKey();
+
+ // Exit if it is out of the bucket scope.
+ if (!deletedKey.startsWith(snapshotBucketKey)) {
+ break;
+ }
+
+ RepeatedOmKeyInfo repeatedOmKeyInfo = deletedKeyValue.getValue();
+
+ List<BlockGroup> blockGroupList = new ArrayList<>();
+ RepeatedOmKeyInfo newRepeatedOmKeyInfo = new RepeatedOmKeyInfo();
+ for (OmKeyInfo keyInfo : repeatedOmKeyInfo.getOmKeyInfoList()) {
+ if (isKeyReclaimable(previousKeyTable, snapRenamedTable,
+ keyInfo, bucketInfo, volumeId, null)) {
+ List<BlockGroup> blocksForKeyDelete = currOmSnapshot
+ .getMetadataManager()
+ .getBlocksForKeyDelete(deletedKey);
+ if (blocksForKeyDelete != null) {
+ blockGroupList.addAll(blocksForKeyDelete);
+ }
+ delCount++;
+ } else {
+ newRepeatedOmKeyInfo.addOmKeyInfo(keyInfo);
+ }
+ }
+
+ if (newRepeatedOmKeyInfo.getOmKeyInfoList().size() > 0 &&
+ newRepeatedOmKeyInfo.getOmKeyInfoList().size() !=
+ repeatedOmKeyInfo.getOmKeyInfoList().size()) {
+ keysToModify.put(deletedKey, newRepeatedOmKeyInfo);
+ }
+
+ if (newRepeatedOmKeyInfo.getOmKeyInfoList().size() !=
+ repeatedOmKeyInfo.getOmKeyInfoList().size()) {
+ keysToPurge.addAll(blockGroupList);
+ }
+ }
+
+ if (delCount < keyLimitPerTask) {
+ // Deep clean is completed, we can update the SnapInfo.
+ deepCleanedSnapshots.add(currSnapInfo.getTableKey());
+ }
+
+ if (!keysToPurge.isEmpty()) {
+ processKeyDeletes(keysToPurge, currOmSnapshot.getKeyManager(),
+ keysToModify, currSnapInfo.getTableKey());
+ }
+
+ }
+ }
+ }
+ updateDeepCleanedSnapshots(deepCleanedSnapshots);
+ }
+
+ private void updateDeepCleanedSnapshots(List<String> deepCleanedSnapshots)
{
+ if (!deepCleanedSnapshots.isEmpty()) {
+ SnapshotPurgeRequest snapshotPurgeRequest = SnapshotPurgeRequest
+ .newBuilder()
+ .addAllUpdatedSnapshotDBKey(deepCleanedSnapshots)
+ .build();
+
+ OMRequest omRequest = OMRequest.newBuilder()
+ .setCmdType(Type.SnapshotPurge)
+ .setSnapshotPurgeRequest(snapshotPurgeRequest)
+ .setClientId(clientId.toString())
+ .build();
+
+ submitRequest(omRequest);
+ }
+ }
+
+ public void submitRequest(OMRequest omRequest) {
+ try {
+ if (isRatisEnabled()) {
+ OzoneManagerRatisServer server =
getOzoneManager().getOmRatisServer();
+
+ RaftClientRequest raftClientRequest = RaftClientRequest.newBuilder()
+ .setClientId(clientId)
+ .setServerId(server.getRaftPeerId())
+ .setGroupId(server.getRaftGroupId())
+ .setCallId(getRunCount().get())
+ .setMessage(Message.valueOf(
+ OMRatisHelper.convertRequestToByteString(omRequest)))
+ .setType(RaftClientRequest.writeRequestType())
+ .build();
+
+ server.submitRequest(omRequest, raftClientRequest);
+ } else {
+ getOzoneManager().getOmServerProtocol()
+ .submitRequest(null, omRequest);
+ }
+ } catch (ServiceException e) {
+ LOG.error("Snapshot Deleting request failed. " +
+ "Will retry at next run.", e);
+ }
+ }
Review Comment:
I tried this, but strangely the request is not going to OM at all.
--
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]