xyuanlu commented on code in PR #2736:
URL: https://github.com/apache/helix/pull/2736#discussion_r1470342814


##########
helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/InstancesAccessor.java:
##########
@@ -302,16 +305,50 @@ private Response batchGetStoppableInstances(String 
clusterId, JsonNode node, boo
       ClusterService clusterService =
           new ClusterServiceImpl(getDataAccssor(clusterId), 
getConfigAccessor());
       ClusterTopology clusterTopology = 
clusterService.getClusterTopology(clusterId);
-      StoppableInstancesSelector stoppableInstancesSelector =
+      StoppableInstancesSelector.StoppableInstancesSelectorBuilder builder =
           new StoppableInstancesSelector.StoppableInstancesSelectorBuilder()
               .setClusterId(clusterId)
               .setOrderOfZone(orderOfZone)
               .setCustomizedInput(customizedInput)
               .setMaintenanceService(maintenanceService)
               .setClusterTopology(clusterTopology)
               .setDataAccessor((ZKHelixDataAccessor) getDataAccssor(clusterId))
-              .build();
+              .setContinueOnFailure(continueOnFailures);
+
+      Set<String> currentOfflineInstances = Collections.emptySet();
+      if (notExceedingMaxOfflineInstances) {
+        // If the clusterConfig or maxOfflineInstancesAllowed is not set, this 
is an invalid request.
+        ClusterConfig clusterConfig = 
getConfigAccessor().getClusterConfig(clusterId);
+        if (clusterConfig == null) {
+          String message =
+              "Invalid cluster name: " + clusterId + ". Cluster config does 
not exist.";
+          _logger.error(message);
+          return badRequest(message);
+        }
+        int maxOfflineAllowed = clusterConfig.getMaxOfflineInstancesAllowed();
+        if (maxOfflineAllowed == -1) {
+          String message =
+              "Invalid cluster config: " + clusterId + ". 
maxOfflineInstancesAllowed is not set.";
+          _logger.error(message);
+          return badRequest(message);
+        }
+
+        HelixDataAccessor dataAccessor = getDataAccssor(clusterId);
+        List<String> liveInstances =
+            
dataAccessor.getChildNames(dataAccessor.keyBuilder().liveInstances());
+        currentOfflineInstances = clusterTopology.getAllInstances().stream()
+            .filter(instance -> 
!liveInstances.contains(instance)).collect(Collectors.toSet());
+        maxOfflineAllowed = Math.max(0, maxOfflineAllowed - 
currentOfflineInstances.size());
+        builder.setMaxAdditionalOfflineInstances(maxOfflineAllowed);
+      }
+
+      StoppableInstancesSelector stoppableInstancesSelector = builder.build();
       stoppableInstancesSelector.calculateOrderOfZone(instances, random);
+      Set<String> finalCurrentOfflineInstances = currentOfflineInstances;

Review Comment:
   Why we want to create a new list? 



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