swamirishi commented on code in PR #8450:
URL: https://github.com/apache/ozone/pull/8450#discussion_r2103460669


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyDeletingService.java:
##########
@@ -186,9 +173,116 @@ public void setKeyLimitPerTask(int keyLimitPerTask) {
    */
   private final class KeyDeletingTask implements BackgroundTask {
     private final KeyDeletingService deletingService;
+    private final UUID snapshotId;
 
-    private KeyDeletingTask(KeyDeletingService service) {
+    private KeyDeletingTask(KeyDeletingService service, UUID snapshotId) {
       this.deletingService = service;
+      this.snapshotId = snapshotId;
+    }
+
+    private OzoneManagerProtocolProtos.SetSnapshotPropertyRequest 
getSetSnapshotRequestUpdatingExclusiveSize(
+        Map<UUID, Long> exclusiveSizeMap, Map<UUID, Long> 
exclusiveReplicatedSizeMap, UUID snapshotID) {
+      OzoneManagerProtocolProtos.SnapshotSize snapshotSize = 
OzoneManagerProtocolProtos.SnapshotSize.newBuilder()
+          .setExclusiveSize(
+              exclusiveSizeMap.getOrDefault(snapshotID, 0L))
+          .setExclusiveReplicatedSize(
+              exclusiveReplicatedSizeMap.getOrDefault(
+                  snapshotID, 0L))
+          .build();
+      exclusiveSizeMap.remove(snapshotID);
+      exclusiveReplicatedSizeMap.remove(snapshotID);
+
+      return OzoneManagerProtocolProtos.SetSnapshotPropertyRequest.newBuilder()
+          .setSnapshotKey(snapshotChainManager.getTableKey(snapshotID))
+          .setSnapshotSize(snapshotSize)
+          .build();
+    }
+
+    /**
+     *
+     * @param currentSnapshotInfo if null, deleted directories in AOS should 
be processed.
+     * @param keyManager KeyManager of the underlying store.
+     */
+    private void processDeletedKeysForStore(SnapshotInfo currentSnapshotInfo, 
KeyManager keyManager,
+        int remainNum) throws IOException, InterruptedException {
+      String volume = null, bucket = null, snapshotTableKey = null;
+      if (currentSnapshotInfo != null) {
+        volume = currentSnapshotInfo.getVolumeName();
+        bucket = currentSnapshotInfo.getBucketName();
+        snapshotTableKey = currentSnapshotInfo.getTableKey();
+      }
+
+      String startKey = null;
+      boolean successStatus = true;
+      try {
+        // TODO: [SNAPSHOT] HDDS-7968. Reclaim eligible key blocks in
+        //  snapshot's deletedTable when active DB's deletedTable
+        //  doesn't have enough entries left.
+        //  OM would have to keep track of which snapshot the key is coming
+        //  from if the above would be done inside getPendingDeletionKeys().
+        OmSnapshotManager omSnapshotManager = 
getOzoneManager().getOmSnapshotManager();
+        // This is to avoid race condition b/w purge request and snapshot 
chain update. For AOS taking the global
+        // snapshotId since AOS could process multiple buckets in one 
iteration. While using path
+        // previous snapshotId for a snapshot since it would process only one 
bucket.
+        UUID expectedPreviousSnapshotId = currentSnapshotInfo == null ?
+            snapshotChainManager.getLatestGlobalSnapshotId() :
+            SnapshotUtils.getPreviousSnapshotId(currentSnapshotInfo, 
snapshotChainManager);
+
+        IOzoneManagerLock lock = 
getOzoneManager().getMetadataManager().getLock();
+
+        // Purge deleted Keys in the deletedTable && rename entries in the 
snapshotRenamedTable which doesn't have a
+        // reference in the previous snapshot.
+        try (ReclaimableKeyFilter reclaimableKeyFilter = new 
ReclaimableKeyFilter(getOzoneManager(),
+            omSnapshotManager, snapshotChainManager, currentSnapshotInfo, 
keyManager, lock)) {
+          // Get pending keys that can be deleted
+          PendingKeysDeletion pendingKeysDeletion = currentSnapshotInfo == null
+              ? keyManager.getPendingDeletionKeys(reclaimableKeyFilter, 
remainNum)
+              : keyManager.getPendingDeletionKeys(volume, bucket, startKey, 
reclaimableKeyFilter, remainNum);
+          List<BlockGroup> keyBlocksList = 
pendingKeysDeletion.getKeyBlocksList();
+          //submit purge requests if there are renamed entries to be purged or 
keys to be purged.
+          if (keyBlocksList != null && !keyBlocksList.isEmpty()) {
+            // Validating if the previous snapshot is still the same before 
purging the blocks.
+            SnapshotUtils.validatePreviousSnapshotId(currentSnapshotInfo, 
snapshotChainManager,
+                expectedPreviousSnapshotId);
+            Pair<Integer, Boolean> purgeResult = 
processKeyDeletes(keyBlocksList,
+                 pendingKeysDeletion.getKeysToModify(), snapshotTableKey,
+                 expectedPreviousSnapshotId);
+            remainNum -= purgeResult.getKey();
+            successStatus = purgeResult.getValue();
+            metrics.incrNumKeysProcessed(keyBlocksList.size());
+            metrics.incrNumKeysSentForPurge(purgeResult.getKey());
+            if (successStatus) {
+              deletedKeyCount.addAndGet(purgeResult.getKey());
+            }
+          }
+
+          // Checking remainNum is greater than zero and not equal to the 
initial value if there were some keys to
+          // reclaim. This is to check if

Review Comment:
   done updated it. Missed this while resolving merge conflict



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyDeletingService.java:
##########
@@ -186,9 +173,116 @@ public void setKeyLimitPerTask(int keyLimitPerTask) {
    */
   private final class KeyDeletingTask implements BackgroundTask {
     private final KeyDeletingService deletingService;
+    private final UUID snapshotId;
 
-    private KeyDeletingTask(KeyDeletingService service) {
+    private KeyDeletingTask(KeyDeletingService service, UUID snapshotId) {
       this.deletingService = service;
+      this.snapshotId = snapshotId;
+    }
+
+    private OzoneManagerProtocolProtos.SetSnapshotPropertyRequest 
getSetSnapshotRequestUpdatingExclusiveSize(
+        Map<UUID, Long> exclusiveSizeMap, Map<UUID, Long> 
exclusiveReplicatedSizeMap, UUID snapshotID) {
+      OzoneManagerProtocolProtos.SnapshotSize snapshotSize = 
OzoneManagerProtocolProtos.SnapshotSize.newBuilder()
+          .setExclusiveSize(
+              exclusiveSizeMap.getOrDefault(snapshotID, 0L))
+          .setExclusiveReplicatedSize(
+              exclusiveReplicatedSizeMap.getOrDefault(
+                  snapshotID, 0L))
+          .build();
+      exclusiveSizeMap.remove(snapshotID);
+      exclusiveReplicatedSizeMap.remove(snapshotID);
+
+      return OzoneManagerProtocolProtos.SetSnapshotPropertyRequest.newBuilder()
+          .setSnapshotKey(snapshotChainManager.getTableKey(snapshotID))
+          .setSnapshotSize(snapshotSize)
+          .build();
+    }
+
+    /**
+     *
+     * @param currentSnapshotInfo if null, deleted directories in AOS should 
be processed.
+     * @param keyManager KeyManager of the underlying store.
+     */
+    private void processDeletedKeysForStore(SnapshotInfo currentSnapshotInfo, 
KeyManager keyManager,
+        int remainNum) throws IOException, InterruptedException {
+      String volume = null, bucket = null, snapshotTableKey = null;
+      if (currentSnapshotInfo != null) {
+        volume = currentSnapshotInfo.getVolumeName();
+        bucket = currentSnapshotInfo.getBucketName();
+        snapshotTableKey = currentSnapshotInfo.getTableKey();
+      }
+
+      String startKey = null;
+      boolean successStatus = true;
+      try {
+        // TODO: [SNAPSHOT] HDDS-7968. Reclaim eligible key blocks in
+        //  snapshot's deletedTable when active DB's deletedTable
+        //  doesn't have enough entries left.
+        //  OM would have to keep track of which snapshot the key is coming
+        //  from if the above would be done inside getPendingDeletionKeys().
+        OmSnapshotManager omSnapshotManager = 
getOzoneManager().getOmSnapshotManager();
+        // This is to avoid race condition b/w purge request and snapshot 
chain update. For AOS taking the global
+        // snapshotId since AOS could process multiple buckets in one 
iteration. While using path
+        // previous snapshotId for a snapshot since it would process only one 
bucket.
+        UUID expectedPreviousSnapshotId = currentSnapshotInfo == null ?
+            snapshotChainManager.getLatestGlobalSnapshotId() :
+            SnapshotUtils.getPreviousSnapshotId(currentSnapshotInfo, 
snapshotChainManager);
+
+        IOzoneManagerLock lock = 
getOzoneManager().getMetadataManager().getLock();
+
+        // Purge deleted Keys in the deletedTable && rename entries in the 
snapshotRenamedTable which doesn't have a
+        // reference in the previous snapshot.
+        try (ReclaimableKeyFilter reclaimableKeyFilter = new 
ReclaimableKeyFilter(getOzoneManager(),
+            omSnapshotManager, snapshotChainManager, currentSnapshotInfo, 
keyManager, lock)) {
+          // Get pending keys that can be deleted
+          PendingKeysDeletion pendingKeysDeletion = currentSnapshotInfo == null
+              ? keyManager.getPendingDeletionKeys(reclaimableKeyFilter, 
remainNum)
+              : keyManager.getPendingDeletionKeys(volume, bucket, startKey, 
reclaimableKeyFilter, remainNum);
+          List<BlockGroup> keyBlocksList = 
pendingKeysDeletion.getKeyBlocksList();
+          //submit purge requests if there are renamed entries to be purged or 
keys to be purged.

Review Comment:
   Done



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyDeletingService.java:
##########
@@ -186,9 +173,116 @@ public void setKeyLimitPerTask(int keyLimitPerTask) {
    */
   private final class KeyDeletingTask implements BackgroundTask {
     private final KeyDeletingService deletingService;
+    private final UUID snapshotId;
 
-    private KeyDeletingTask(KeyDeletingService service) {
+    private KeyDeletingTask(KeyDeletingService service, UUID snapshotId) {
       this.deletingService = service;
+      this.snapshotId = snapshotId;
+    }
+
+    private OzoneManagerProtocolProtos.SetSnapshotPropertyRequest 
getSetSnapshotRequestUpdatingExclusiveSize(
+        Map<UUID, Long> exclusiveSizeMap, Map<UUID, Long> 
exclusiveReplicatedSizeMap, UUID snapshotID) {
+      OzoneManagerProtocolProtos.SnapshotSize snapshotSize = 
OzoneManagerProtocolProtos.SnapshotSize.newBuilder()
+          .setExclusiveSize(
+              exclusiveSizeMap.getOrDefault(snapshotID, 0L))
+          .setExclusiveReplicatedSize(
+              exclusiveReplicatedSizeMap.getOrDefault(
+                  snapshotID, 0L))
+          .build();
+      exclusiveSizeMap.remove(snapshotID);
+      exclusiveReplicatedSizeMap.remove(snapshotID);
+
+      return OzoneManagerProtocolProtos.SetSnapshotPropertyRequest.newBuilder()
+          .setSnapshotKey(snapshotChainManager.getTableKey(snapshotID))
+          .setSnapshotSize(snapshotSize)
+          .build();
+    }
+
+    /**
+     *
+     * @param currentSnapshotInfo if null, deleted directories in AOS should 
be processed.
+     * @param keyManager KeyManager of the underlying store.
+     */
+    private void processDeletedKeysForStore(SnapshotInfo currentSnapshotInfo, 
KeyManager keyManager,
+        int remainNum) throws IOException, InterruptedException {
+      String volume = null, bucket = null, snapshotTableKey = null;
+      if (currentSnapshotInfo != null) {
+        volume = currentSnapshotInfo.getVolumeName();
+        bucket = currentSnapshotInfo.getBucketName();
+        snapshotTableKey = currentSnapshotInfo.getTableKey();
+      }
+
+      String startKey = null;
+      boolean successStatus = true;
+      try {
+        // TODO: [SNAPSHOT] HDDS-7968. Reclaim eligible key blocks in
+        //  snapshot's deletedTable when active DB's deletedTable
+        //  doesn't have enough entries left.
+        //  OM would have to keep track of which snapshot the key is coming
+        //  from if the above would be done inside getPendingDeletionKeys().
+        OmSnapshotManager omSnapshotManager = 
getOzoneManager().getOmSnapshotManager();
+        // This is to avoid race condition b/w purge request and snapshot 
chain update. For AOS taking the global
+        // snapshotId since AOS could process multiple buckets in one 
iteration. While using path
+        // previous snapshotId for a snapshot since it would process only one 
bucket.
+        UUID expectedPreviousSnapshotId = currentSnapshotInfo == null ?
+            snapshotChainManager.getLatestGlobalSnapshotId() :
+            SnapshotUtils.getPreviousSnapshotId(currentSnapshotInfo, 
snapshotChainManager);
+
+        IOzoneManagerLock lock = 
getOzoneManager().getMetadataManager().getLock();
+
+        // Purge deleted Keys in the deletedTable && rename entries in the 
snapshotRenamedTable which doesn't have a
+        // reference in the previous snapshot.
+        try (ReclaimableKeyFilter reclaimableKeyFilter = new 
ReclaimableKeyFilter(getOzoneManager(),
+            omSnapshotManager, snapshotChainManager, currentSnapshotInfo, 
keyManager, lock)) {
+          // Get pending keys that can be deleted
+          PendingKeysDeletion pendingKeysDeletion = currentSnapshotInfo == null
+              ? keyManager.getPendingDeletionKeys(reclaimableKeyFilter, 
remainNum)
+              : keyManager.getPendingDeletionKeys(volume, bucket, startKey, 
reclaimableKeyFilter, remainNum);
+          List<BlockGroup> keyBlocksList = 
pendingKeysDeletion.getKeyBlocksList();
+          //submit purge requests if there are renamed entries to be purged or 
keys to be purged.
+          if (keyBlocksList != null && !keyBlocksList.isEmpty()) {
+            // Validating if the previous snapshot is still the same before 
purging the blocks.
+            SnapshotUtils.validatePreviousSnapshotId(currentSnapshotInfo, 
snapshotChainManager,
+                expectedPreviousSnapshotId);
+            Pair<Integer, Boolean> purgeResult = 
processKeyDeletes(keyBlocksList,
+                 pendingKeysDeletion.getKeysToModify(), snapshotTableKey,
+                 expectedPreviousSnapshotId);
+            remainNum -= purgeResult.getKey();
+            successStatus = purgeResult.getValue();
+            metrics.incrNumKeysProcessed(keyBlocksList.size());
+            metrics.incrNumKeysSentForPurge(purgeResult.getKey());
+            if (successStatus) {
+              deletedKeyCount.addAndGet(purgeResult.getKey());
+            }
+          }
+
+          // Checking remainNum is greater than zero and not equal to the 
initial value if there were some keys to
+          // reclaim. This is to check if
+          if (remainNum > 0 && successStatus) {
+            List<SetSnapshotPropertyRequest> setSnapshotPropertyRequests = new 
ArrayList<>();
+            Map<UUID, Long> exclusiveReplicatedSizeMap = 
reclaimableKeyFilter.getExclusiveReplicatedSizeMap();
+            Map<UUID, Long> exclusiveSizeMap = 
reclaimableKeyFilter.getExclusiveSizeMap();
+            List<UUID> previousPathSnapshotsInChain =
+                Stream.of(exclusiveSizeMap.keySet(), 
exclusiveReplicatedSizeMap.keySet())
+                
.flatMap(Collection::stream).distinct().collect(Collectors.toList());
+            for (UUID snapshot : previousPathSnapshotsInChain) {
+              
setSnapshotPropertyRequests.add(getSetSnapshotRequestUpdatingExclusiveSize(exclusiveSizeMap,
+                  exclusiveReplicatedSizeMap, snapshot));
+            }
+
+            //Updating directory deep clean flag of snapshot.

Review Comment:
   done



-- 
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: issues-unsubscr...@ozone.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org
For additional commands, e-mail: issues-h...@ozone.apache.org

Reply via email to