diff --git a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java index 4c7841b757c9..eb71845d268d 100644 --- a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java +++ b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/OMDBInsightEndpoint.java @@ -627,6 +627,28 @@ private void getPendingForDeletionDirInfo( } } + private void calculateTotalPendingDeletedDirSizes(Map dirSummary) { + long totalUnreplicatedSize = 0L; + long totalReplicatedSize = 0L; + + Table deletedDirTable = omMetadataManager.getDeletedDirTable(); + try (TableIterator> iterator = deletedDirTable.iterator()) { + while (iterator.hasNext()) { + Table.KeyValue kv = iterator.next(); + OmKeyInfo omKeyInfo = kv.getValue(); + if (omKeyInfo != null) { + totalUnreplicatedSize += fetchSizeForDeletedDirectory(omKeyInfo.getObjectID()); + totalReplicatedSize += omKeyInfo.getReplicatedSize(); + } + } + } catch (IOException ex) { + throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR); + } + + dirSummary.put("totalUnreplicatedDataSize", totalUnreplicatedSize); + dirSummary.put("totalReplicatedDataSize", totalReplicatedSize); + } + /** * Given an object ID, return total data size (no replication) * under this object. Note:- This method is RECURSIVE. @@ -733,6 +755,28 @@ public Response getDeletedDirectorySummary() { return Response.ok(dirSummary).build(); } + /** + * Retrieves the summary of the total delete pending directory size (unreplicated and replicated). + * + * @return The HTTP response body includes a map with the following entries: + * - "totalUnreplicatedDataSize": the total replicated size of delete pending directories. + * - "totalReplicatedDataSize": the total unreplicated size of delete pending directories. + * + * Example response: + * { + * "totalUnreplicatedDataSize": 30000, + * "totalReplicatedDataSize": 90000 + * } + */ + @GET + @Path("/deletePending/dirs/size") + public Response getTotalDeletedDirectorySizeSummary() { + Map dirSummary = new HashMap<>(); + // Create a keys summary for deleted directories + calculateTotalPendingDeletedDirSizes(dirSummary); + return Response.ok(dirSummary).build(); + } + /** * This API will list out limited 'count' number of keys after applying below filters in API parameters: * Default Values of API param filters: