ChenSammi commented on code in PR #8568:
URL: https://github.com/apache/ozone/pull/8568#discussion_r2204116008
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java:
##########
@@ -628,24 +629,28 @@ private void getPendingForDeletionDirInfo(
}
/**
- * Given an object ID, return total data size (no replication)
+ * Given an object ID, return total data size as a pair of Total Size, Total
Replicated Size
* under this object. Note:- This method is RECURSIVE.
*
* @param objectId the object's ID
- * @return total used data size in bytes
+ * @return total used data size and replicated total used data size in bytes
* @throws IOException ioEx
*/
- protected long fetchSizeForDeletedDirectory(long objectId)
+ protected Pair<Long, Long> fetchSizeForDeletedDirectory(long objectId)
throws IOException {
NSSummary nsSummary = reconNamespaceSummaryManager.getNSSummary(objectId);
if (nsSummary == null) {
- return 0L;
+ return Pair.of(0L, 0L);
}
long totalSize = nsSummary.getSizeOfFiles();
+ long totalReplicatedSize = nsSummary.getReplicatedSizeOfFiles();
+
for (long childId : nsSummary.getChildDir()) {
- totalSize += fetchSizeForDeletedDirectory(childId);
+ Pair<Long, Long> childSize = fetchSizeForDeletedDirectory(childId);
Review Comment:
The recursive implementation of `fetchSizeForDeletedDirectory` could lead to
a `StackOverflowError` if it encounters a very deep directory structure. An
iterative approach using a stack would be more robust and prevent this
potential issue.
```java
protected Pair<Long, Long> fetchSizeForDeletedDirectory(long objectId)
throws IOException {
long totalSize = 0;
long totalReplicatedSize = 0;
java.util.Deque<Long> stack = new java.util.ArrayDeque<>();
stack.push(objectId);
while (!stack.isEmpty()) {
long currentId = stack.pop();
NSSummary nsSummary =
reconNamespaceSummaryManager.getNSSummary(currentId);
if (nsSummary != null) {
totalSize += nsSummary.getSizeOfFiles();
totalReplicatedSize += nsSummary.getReplicatedSizeOfFiles();
for (long childId : nsSummary.getChildDir()) {
stack.push(childId);
}
}
}
return Pair.of(totalSize, totalReplicatedSize);
}
```
Suggested by Gemini.
--
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]