sumitagrawl commented on code in PR #8823:
URL: https://github.com/apache/ozone/pull/8823#discussion_r2213552822


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskWithFSO.java:
##########
@@ -179,6 +134,152 @@ public Pair<Integer, Boolean> 
processWithFSO(OMUpdateEventBatch events,
     return new ImmutablePair<>(seekPos, true);
   }
 
+  private void handleUpdateOnDirTable(OMDBUpdateEvent<String, ? extends 
WithParentObjectId> omdbUpdateEvent,
+                         OMDBUpdateEvent.OMDBUpdateAction action, Map<Long, 
NSSummary> nsSummaryMap, String updatedKey)
+      throws IOException {
+    OMDBUpdateEvent<String, OmDirectoryInfo> dirTableUpdateEvent =
+            (OMDBUpdateEvent<String, OmDirectoryInfo>) omdbUpdateEvent;
+    OmDirectoryInfo updatedDirectoryInfo = dirTableUpdateEvent.getValue();
+    OmDirectoryInfo oldDirectoryInfo = dirTableUpdateEvent.getOldValue();
+
+    switch (action) {
+    case PUT:
+      handlePutDirEvent(updatedDirectoryInfo, nsSummaryMap);
+      break;
+
+    case DELETE:
+      handleDeleteDirEvent(updatedDirectoryInfo, nsSummaryMap);
+      break;
+
+    case UPDATE:
+      if (oldDirectoryInfo != null) {
+        // delete first, then put
+        handleDeleteDirEvent(oldDirectoryInfo, nsSummaryMap);
+      } else {
+        LOG.warn("Update event does not have the old dirInfo for {}.",
+            updatedKey);
+      }
+      handlePutDirEvent(updatedDirectoryInfo, nsSummaryMap);
+      break;
+
+    default:
+      LOG.debug("Skipping DB update event : {}",
+              omdbUpdateEvent.getAction());
+    }
+  }
+
+  private void handleUpdateOnDeletedDirTable(OMDBUpdateEvent<String, 
OmKeyInfo> omdbUpdateEvent,
+                                OMDBUpdateEvent.OMDBUpdateAction action, 
Map<Long, NSSummary> nsSummaryMap) {
+    OMDBUpdateEvent<String, OmKeyInfo> deletedDirTableUpdateEvent =
+        omdbUpdateEvent;
+    OmKeyInfo deletedKeyInfo = deletedDirTableUpdateEvent.getValue();
+
+    switch (action) {
+    case DELETE:
+      // When entry is removed from deletedDirTable, remove from nsSummaryMap 
to prevent memory leak
+      if (deletedKeyInfo != null) {
+        long objectId = deletedKeyInfo.getObjectID();
+        nsSummaryMap.remove(objectId);
+        LOG.info("Removed hard deleted directory with objectId {} from 
nsSummaryMap", objectId);
+        
+        // Also remove the parent directory's entry that references this 
deleted directory
+        long parentObjectId = deletedKeyInfo.getParentObjectID();
+        NSSummary parentSummary = nsSummaryMap.get(parentObjectId);
+        if (parentSummary != null) {
+          parentSummary.removeChildDir(objectId);
+          nsSummaryMap.put(parentObjectId, parentSummary);
+          LOG.info("Updated parent directory {} to remove child directory {}", 
parentObjectId, objectId);
+        }
+        
+        // Delete the NSSummary entry from the database to prevent memory leak
+        try {
+          getReconNamespaceSummaryManager().deleteNSSummary(objectId);
+          LOG.info("Deleted NSSummary entry for objectId {} from database", 
objectId);
+        } catch (Exception e) {
+          LOG.error("Failed to delete NSSummary entry for objectId {} from 
database", objectId, e);
+        }
+      }
+      break;
+
+    default:
+      LOG.info("Skipping DB update event on deletedDirTable: {}", action);
+    }
+  }
+
+  private void handleUpdateOnDeletedTable(OMDBUpdateEvent<String, ? extends 
WithParentObjectId> omdbUpdateEvent,

Review Comment:
   But order of deletion from map, this should be last operation when all event 
is handled, as order of map flush and this may cause adding back this entry.



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