devmadhuu commented on code in PR #4876:
URL: https://github.com/apache/ozone/pull/4876#discussion_r1226418716


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/ContainerEndpoint.java:
##########
@@ -498,46 +499,105 @@ private List<ContainerBlockMetadata> getBlocks(
     return blockIds;
   }
 
+  /**
+   * Retrieves the container mismatch insights.
+   *
+   * This method returns a list of ContainerDiscrepancyInfo objects
+   * representing the containers that are present in the Object Manager (OM)
+   * but not in the Storage Container Manager (SCM), and the containers that
+   * are present in the SCM but not in the OM. The returned list is paginated
+   * based on the provided limit and prevKey parameters.
+   *
+   * @param limit The maximum number of container discrepancies to return.
+   * @param prevKey The container ID after which the results are returned.
+   * @return The HTTP response containing the list of ContainerDiscrepancyInfo
+   * objects representing the container discrepancies.
+   */
   @GET
   @Path("/mismatch")
-  public Response getContainerMisMatchInsights() {
+  public Response getContainerMisMatchInsights(
+      @DefaultValue(DEFAULT_FETCH_COUNT) @QueryParam(RECON_QUERY_LIMIT)
+          int limit,
+      @DefaultValue(PREV_CONTAINER_ID_DEFAULT_VALUE)
+      @QueryParam(RECON_QUERY_PREVKEY) long prevKey) {
+    if (prevKey < 0 || limit < 0) {
+      // Send back an empty response
+      return Response.status(Response.Status.NOT_ACCEPTABLE).build();
+    }
+
     List<ContainerDiscrepancyInfo> containerDiscrepancyInfoList =
         new ArrayList<>();
     try {
       Map<Long, ContainerMetadata> omContainers =
           reconContainerMetadataManager.getContainers(-1, -1);
       List<Long> scmNonDeletedContainers =
           containerManager.getContainers().stream()
-              .filter(containerInfo -> !(containerInfo.getState() ==
-                  HddsProtos.LifeCycleState.DELETED))
-              .map(containerInfo -> containerInfo.getContainerID()).collect(
-                  Collectors.toList());
+              .filter(containerInfo -> containerInfo.getState() !=
+                  HddsProtos.LifeCycleState.DELETED)
+              .map(containerInfo -> containerInfo.getContainerID())
+              .collect(Collectors.toList());
 
-      // Filter list of container Ids which are present in OM but not in SCM.
+      // Filter list of container IDs which are present in OM but not in SCM.
       List<Map.Entry<Long, ContainerMetadata>> notSCMContainers =
-          omContainers.entrySet().stream().filter(containerMetadataEntry ->
-                  !(scmNonDeletedContainers.contains(
-                      containerMetadataEntry.getKey())))
-              .collect(
-                  Collectors.toList());
+          omContainers.entrySet().stream()
+              .filter(
+                  containerMetadataEntry -> !scmNonDeletedContainers.contains(
+                      containerMetadataEntry.getKey()))
+              .collect(Collectors.toList());
+
+      // Filter containers based on pagination parameters
+      if (prevKey > 0) {
+        int index = 0;
+        while (index < notSCMContainers.size() &&
+            notSCMContainers.get(index).getKey() <= prevKey) {
+          index++;
+        }
+        if (index < notSCMContainers.size()) {
+          notSCMContainers = notSCMContainers.subList(index,
+              Math.min(index + limit, notSCMContainers.size()));
+        } else {
+          notSCMContainers = Collections.emptyList();
+        }
+      } else {
+        notSCMContainers = notSCMContainers.subList(0,
+            Math.min(limit, notSCMContainers.size()));
+      }
 
       notSCMContainers.forEach(nonSCMContainer -> {
         ContainerDiscrepancyInfo containerDiscrepancyInfo =
             new ContainerDiscrepancyInfo();
         containerDiscrepancyInfo.setContainerID(nonSCMContainer.getKey());
         containerDiscrepancyInfo.setNumberOfKeys(
             nonSCMContainer.getValue().getNumberOfKeys());
-        containerDiscrepancyInfo.setPipelines(nonSCMContainer.getValue()
-            .getPipelines());
+        containerDiscrepancyInfo.setPipelines(
+            nonSCMContainer.getValue().getPipelines());
         containerDiscrepancyInfo.setExistsAt("OM");
         containerDiscrepancyInfoList.add(containerDiscrepancyInfo);

Review Comment:
   @ArafatKhan2198 Thanks for working on this patch, however I think we need to 
return prevKey in output.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/ContainerEndpoint.java:
##########
@@ -563,7 +621,6 @@ public Response getContainerMisMatchInsights() {
         containerDiscrepancyInfo.setExistsAt("SCM");
         containerDiscrepancyInfoList.add(containerDiscrepancyInfo);

Review Comment:
   @ArafatKhan2198 Thanks for working on this patch, however I think we need to 
return prevKey in output.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/ContainerEndpoint.java:
##########
@@ -498,46 +499,105 @@ private List<ContainerBlockMetadata> getBlocks(
     return blockIds;
   }
 
+  /**
+   * Retrieves the container mismatch insights.
+   *
+   * This method returns a list of ContainerDiscrepancyInfo objects
+   * representing the containers that are present in the Object Manager (OM)
+   * but not in the Storage Container Manager (SCM), and the containers that
+   * are present in the SCM but not in the OM. The returned list is paginated
+   * based on the provided limit and prevKey parameters.
+   *
+   * @param limit The maximum number of container discrepancies to return.
+   * @param prevKey The container ID after which the results are returned.
+   * @return The HTTP response containing the list of ContainerDiscrepancyInfo
+   * objects representing the container discrepancies.
+   */
   @GET
   @Path("/mismatch")
-  public Response getContainerMisMatchInsights() {
+  public Response getContainerMisMatchInsights(
+      @DefaultValue(DEFAULT_FETCH_COUNT) @QueryParam(RECON_QUERY_LIMIT)
+          int limit,
+      @DefaultValue(PREV_CONTAINER_ID_DEFAULT_VALUE)
+      @QueryParam(RECON_QUERY_PREVKEY) long prevKey) {
+    if (prevKey < 0 || limit < 0) {
+      // Send back an empty response
+      return Response.status(Response.Status.NOT_ACCEPTABLE).build();
+    }
+
     List<ContainerDiscrepancyInfo> containerDiscrepancyInfoList =
         new ArrayList<>();
     try {
       Map<Long, ContainerMetadata> omContainers =
           reconContainerMetadataManager.getContainers(-1, -1);
       List<Long> scmNonDeletedContainers =
           containerManager.getContainers().stream()
-              .filter(containerInfo -> !(containerInfo.getState() ==
-                  HddsProtos.LifeCycleState.DELETED))
-              .map(containerInfo -> containerInfo.getContainerID()).collect(
-                  Collectors.toList());
+              .filter(containerInfo -> containerInfo.getState() !=
+                  HddsProtos.LifeCycleState.DELETED)
+              .map(containerInfo -> containerInfo.getContainerID())
+              .collect(Collectors.toList());
 
-      // Filter list of container Ids which are present in OM but not in SCM.
+      // Filter list of container IDs which are present in OM but not in SCM.
       List<Map.Entry<Long, ContainerMetadata>> notSCMContainers =
-          omContainers.entrySet().stream().filter(containerMetadataEntry ->
-                  !(scmNonDeletedContainers.contains(
-                      containerMetadataEntry.getKey())))
-              .collect(
-                  Collectors.toList());
+          omContainers.entrySet().stream()
+              .filter(
+                  containerMetadataEntry -> !scmNonDeletedContainers.contains(
+                      containerMetadataEntry.getKey()))
+              .collect(Collectors.toList());
+
+      // Filter containers based on pagination parameters
+      if (prevKey > 0) {
+        int index = 0;
+        while (index < notSCMContainers.size() &&
+            notSCMContainers.get(index).getKey() <= prevKey) {
+          index++;
+        }
+        if (index < notSCMContainers.size()) {
+          notSCMContainers = notSCMContainers.subList(index,
+              Math.min(index + limit, notSCMContainers.size()));
+        } else {
+          notSCMContainers = Collections.emptyList();
+        }
+      } else {
+        notSCMContainers = notSCMContainers.subList(0,
+            Math.min(limit, notSCMContainers.size()));
+      }
 
       notSCMContainers.forEach(nonSCMContainer -> {
         ContainerDiscrepancyInfo containerDiscrepancyInfo =
             new ContainerDiscrepancyInfo();
         containerDiscrepancyInfo.setContainerID(nonSCMContainer.getKey());
         containerDiscrepancyInfo.setNumberOfKeys(
             nonSCMContainer.getValue().getNumberOfKeys());
-        containerDiscrepancyInfo.setPipelines(nonSCMContainer.getValue()
-            .getPipelines());
+        containerDiscrepancyInfo.setPipelines(
+            nonSCMContainer.getValue().getPipelines());
         containerDiscrepancyInfo.setExistsAt("OM");
         containerDiscrepancyInfoList.add(containerDiscrepancyInfo);
       });
 
-      // Filter list of container Ids which are present in SCM but not in OM.
+      // Filter list of container IDs which are present in SCM but not in OM.
       List<Long> nonOMContainers = scmNonDeletedContainers.stream()
           .filter(containerId -> !omContainers.containsKey(containerId))
           .collect(Collectors.toList());
 
+      // Filter containers based on pagination parameters
+      if (prevKey > 0) {

Review Comment:
   Same prevKey cannot be applied on response for both



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/ContainerEndpoint.java:
##########
@@ -498,46 +499,105 @@ private List<ContainerBlockMetadata> getBlocks(
     return blockIds;
   }
 
+  /**
+   * Retrieves the container mismatch insights.
+   *
+   * This method returns a list of ContainerDiscrepancyInfo objects
+   * representing the containers that are present in the Object Manager (OM)
+   * but not in the Storage Container Manager (SCM), and the containers that
+   * are present in the SCM but not in the OM. The returned list is paginated
+   * based on the provided limit and prevKey parameters.
+   *
+   * @param limit The maximum number of container discrepancies to return.
+   * @param prevKey The container ID after which the results are returned.
+   * @return The HTTP response containing the list of ContainerDiscrepancyInfo
+   * objects representing the container discrepancies.
+   */
   @GET
   @Path("/mismatch")
-  public Response getContainerMisMatchInsights() {
+  public Response getContainerMisMatchInsights(
+      @DefaultValue(DEFAULT_FETCH_COUNT) @QueryParam(RECON_QUERY_LIMIT)
+          int limit,
+      @DefaultValue(PREV_CONTAINER_ID_DEFAULT_VALUE)
+      @QueryParam(RECON_QUERY_PREVKEY) long prevKey) {

Review Comment:
   I think its better to add filter argument for querying which type of 
containers API will return (exists at Om or exists at SCM) as mentioned in JIRA.



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