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 840c14b12ace..16c47bd92c70 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 @@ -676,6 +676,29 @@ private void getPendingForDeletionDirInfo( } } + private void calculateTotalPendingDeletedDirSizes(Map dirSummary) { + long totalDataSize = 0L; + long totalReplicatedDataSize = 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) { + Pair sizeInfo = fetchSizeForDeletedDirectory(omKeyInfo.getObjectID()); + totalDataSize += sizeInfo.getLeft(); + totalReplicatedDataSize += sizeInfo.getRight(); + } + } + } catch (IOException ex) { + throw new WebApplicationException(ex, Response.Status.INTERNAL_SERVER_ERROR); + } + + dirSummary.put("totalDataSize", totalDataSize); + dirSummary.put("totalReplicatedDataSize", totalReplicatedDataSize); + } + /** * 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. @@ -790,6 +813,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: + * - "totalDataSize": the total replicated size of delete pending directories. + * - "totalReplicatedDataSize": the total unreplicated size of delete pending directories. + * + * Example response: + * { + * "totalDataSize": 30000, + * "totalReplicatedDataSize": 90000 + * } + */ + @GET + @Path("/deletePending/dirs/size-summary") + 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: