ArafatKhan2198 commented on code in PR #8797:
URL: https://github.com/apache/ozone/pull/8797#discussion_r2255966168
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/tasks/NSSummaryTaskDbEventHandler.java:
##########
@@ -157,35 +175,59 @@ protected void handleDeleteKeyEvent(OmKeyInfo keyInfo,
int binIndex = ReconUtils.getFileSizeBinIndex(keyInfo.getDataSize());
- // decrement count, data size, and bucket count
- // even if there's no direct key, we still keep the entry because
- // we still need children dir IDs info
+ // Decrement immediate parent's totals (these fields now represent totals)
nsSummary.setNumOfFiles(nsSummary.getNumOfFiles() - 1);
nsSummary.setSizeOfFiles(nsSummary.getSizeOfFiles() -
keyInfo.getDataSize());
--fileBucket[binIndex];
nsSummary.setFileSizeBucket(fileBucket);
nsSummaryMap.put(parentObjectId, nsSummary);
+
+ // Propagate upwards to all parents in the parent chain
+ propagateSizeUpwards(parentObjectId, -keyInfo.getDataSize(), -1,
nsSummaryMap);
}
protected void handleDeleteDirEvent(OmDirectoryInfo directoryInfo,
Map<Long, NSSummary> nsSummaryMap)
throws IOException {
+ long deletedDirObjectId = directoryInfo.getObjectID();
long parentObjectId = directoryInfo.getParentObjectID();
- // Try to get the NSSummary from our local map that maps NSSummaries to IDs
- NSSummary nsSummary = nsSummaryMap.get(parentObjectId);
- if (nsSummary == null) {
- // If we don't have it in this batch we try to get it from the DB
- nsSummary = reconNamespaceSummaryManager.getNSSummary(parentObjectId);
+
+ // Get the deleted directory's NSSummary to extract its totals
+ NSSummary deletedDirSummary = nsSummaryMap.get(deletedDirObjectId);
+ if (deletedDirSummary == null) {
+ deletedDirSummary =
reconNamespaceSummaryManager.getNSSummary(deletedDirObjectId);
+ }
+
+ // Get the parent directory's NSSummary
+ NSSummary parentNsSummary = nsSummaryMap.get(parentObjectId);
+ if (parentNsSummary == null) {
+ parentNsSummary =
reconNamespaceSummaryManager.getNSSummary(parentObjectId);
}
// Just in case the OmDirectoryInfo isn't correctly written.
- if (nsSummary == null) {
+ if (parentNsSummary == null) {
LOG.error("The namespace table is not correctly populated.");
return;
}
- nsSummary.removeChildDir(directoryInfo.getObjectID());
- nsSummaryMap.put(parentObjectId, nsSummary);
+ // If deleted directory exists, decrement its totals from parent and
propagate
+ if (deletedDirSummary != null) {
+ // Decrement parent's totals by the deleted directory's totals
+ parentNsSummary.setNumOfFiles(parentNsSummary.getNumOfFiles() -
deletedDirSummary.getNumOfFiles());
+ parentNsSummary.setSizeOfFiles(parentNsSummary.getSizeOfFiles() -
deletedDirSummary.getSizeOfFiles());
+
+ // Propagate the decrements upwards to all ancestors
+ propagateSizeUpwards(parentObjectId,
-deletedDirSummary.getSizeOfFiles(),
+ -deletedDirSummary.getNumOfFiles(), nsSummaryMap);
+
+ // Set the deleted directory's parentId to 0 (unlink it)
+ deletedDirSummary.setParentId(0);
Review Comment:
Resolving as discussed!
--
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]