JacksonYao287 commented on a change in pull request #2606:
URL: https://github.com/apache/ozone/pull/2606#discussion_r701825274



##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java
##########
@@ -379,21 +379,53 @@ private boolean hasRequiredReplicas(ContainerInfo 
contInfo) {
   @Override
   public List<ContainerInfo> listContainer(long startContainerID,
       int count, HddsProtos.LifeCycleState state) throws IOException {
+    return listContainer(startContainerID, count, state, null);
+  }
+
+  /**
+   * Lists a range of containers and get their info.
+   *
+   * @param startContainerID start containerID.
+   * @param count count must be {@literal >} 0.
+   * @param state Container with this state will be returned.
+   * @param factor Container factor.
+   * @return a list of pipeline.
+   * @throws IOException
+   */
+  @Override
+  public List<ContainerInfo> listContainer(long startContainerID,
+      int count, HddsProtos.LifeCycleState state,
+      HddsProtos.ReplicationFactor factor) throws IOException {
     boolean auditSuccess = true;
     Map<String, String> auditMap = Maps.newHashMap();
     auditMap.put("startContainerID", String.valueOf(startContainerID));
     auditMap.put("count", String.valueOf(count));
     if (state != null) {
       auditMap.put("state", state.name());
     }
+    if (factor != null) {
+      auditMap.put("factor", factor.name());
+    }
     try {
       final ContainerID containerId = ContainerID.valueOf(startContainerID);
-      if(null == state) {
+      if(state != null && factor != null) {
+        return scm.getContainerManager().getContainers(state).stream()
+            .filter(info -> info.containerID().getId() >= startContainerID)
+            .filter(info -> (info.getReplicationFactor() == factor))
+            .sorted().limit(count).collect(Collectors.toList());
+      } else if (state == null && factor == null) {
         return scm.getContainerManager().getContainers(containerId, count);
+      } else if (state != null) {
+        return scm.getContainerManager().getContainers(state).stream()
+            .filter(info -> info.containerID().getId() >= startContainerID)
+            .sorted().limit(count).collect(Collectors.toList());
+      } else {
+        // factor != null
+        return scm.getContainerManager().getContainers().stream()
+            .filter(info -> info.containerID().getId() >= startContainerID)
+            .filter(info -> info.getReplicationFactor() == factor)
+            .sorted().limit(count).collect(Collectors.toList());

Review comment:
       maybe we can refactor the codes as below, i think it will make the logic 
more clear and efficient!
   ```
   if (state == null){
       if(factor == null){
           .............
       } else{
            ............
       }
   }else{
       if(factor == null){
          ...........
       } else{
             .......
       }
   }
   ```




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