aswinshakil commented on code in PR #5339:
URL: https://github.com/apache/ozone/pull/5339#discussion_r1339312236


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/DirectoryDeletingService.java:
##########
@@ -222,12 +225,122 @@ public BackgroundTaskResult call() {
           getOzoneManager().getMetadataManager().getTableLock(
               OmMetadataManagerImpl.DELETED_DIR_TABLE).writeLock().unlock();
         }
+
+        try {
+          if (remainNum > 0) {
+            expandSnapshotDirectories(remainNum);
+          }
+        } catch (Exception e) {
+          LOG.error("Error while running deep clean on snapshots. Will " +
+              "retry at next run.", e);
+        }
       }
 
       // place holder by returning empty results of this call back.
       return BackgroundTaskResult.EmptyTaskResult.newResult();
     }
 
+    private void expandSnapshotDirectories(long remainNum) throws IOException {
+      OmSnapshotManager omSnapshotManager =
+          getOzoneManager().getOmSnapshotManager();
+      Table<String, SnapshotInfo> snapshotInfoTable =
+          getOzoneManager().getMetadataManager().getSnapshotInfoTable();
+
+      long dirNum = 0L;
+      long subDirNum = 0L;
+      long subFileNum = 0L;
+      int consumedSize = 0;
+      List<PurgePathRequest> purgePathRequestList = new ArrayList<>();
+      try (TableIterator<String, ? extends Table.KeyValue
+          <String, SnapshotInfo>> iterator = snapshotInfoTable.iterator()) {
+
+        while (remainNum > 0 && iterator.hasNext()) {
+          SnapshotInfo currSnapInfo = iterator.next().getValue();
+
+          // Expand deleted dirs only on active snapshot. Deleted Snapshots
+          // will be cleaned up by SnapshotDeletingService.
+          if (!currSnapInfo.getSnapshotStatus().equals(SNAPSHOT_ACTIVE) ||
+              currSnapInfo.getExpandedDeletedDir()) {
+            continue;
+          }
+
+          try (ReferenceCounted<IOmMetadataReader, SnapshotCache>
+                   rcCurrOmSnapshot = omSnapshotManager.checkForSnapshot(
+              currSnapInfo.getVolumeName(),
+              currSnapInfo.getBucketName(),
+              getSnapshotPrefix(currSnapInfo.getName()),
+              true)) {
+
+            OmSnapshot currOmSnapshot = (OmSnapshot) rcCurrOmSnapshot.get();
+            Table<String, OmKeyInfo> snapDeletedDirTable =
+                currOmSnapshot.getMetadataManager().getDeletedDirTable();
+
+            if (snapDeletedDirTable.isEmpty()) {
+              // TODO: [SNAPSHOT] Update Snapshot state using
+              //  SetSnapshotProperty from HDDS-7743 (YET TO BE MERGED)
+              continue;
+            }
+
+            Table.KeyValue<String, OmKeyInfo> deletedDirInfo;
+            List<Pair<String, OmKeyInfo>> allSubDirList
+                = new ArrayList<>((int) remainNum);
+
+            try (TableIterator<String, ? extends Table.KeyValue<String,

Review Comment:
   We can't fully extract it because we use some snapshot-specific code 
in-between. So I kept it separately. 



-- 
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]

Reply via email to