vjagadish1989 commented on a change in pull request #952: Improved standby-aware container allocation for active-containers on job redeploys URL: https://github.com/apache/samza/pull/952#discussion_r267635366
########## File path: samza-core/src/main/java/org/apache/samza/clustermanager/StandbyContainerManager.java ########## @@ -161,54 +161,72 @@ private void handleStandbyContainerStop(String standbyContainerID, String resour } } - /** Method to handle failover for an active container. - * We try to find a standby for the active container, and issue a stop on it. - * If we do not find a standby container, we simply issue an anyhost request to place it. + /** Method to handle standby-aware allocation for an active container. + * We try to find a standby host for the active container, and issue a stop on any standby-containers running on it, + * request resource to place the active on the standby's host, and one to place the standby elsewhere. * - * @param containerID the samzaContainerID of the active-container + * @param activeContainerID the samzaContainerID of the active-container * @param resourceID the samza-resource-ID of the container when it failed (used to index failover-state) */ - private void initiateActiveContainerFailover(String containerID, String resourceID, + private void initiateStandbyAwareAllocation(String activeContainerID, String resourceID, AbstractContainerAllocator containerAllocator) { - Optional<Entry<String, SamzaResource>> standbyContainer = this.selectStandby(containerID, resourceID); + String standbyHost = this.selectStandbyHost(activeContainerID, resourceID); - // If we find a standbyContainer, we initiate a failover - if (standbyContainer.isPresent()) { + // Check if there is a running standby-container on that host that needs to be stopped + List<String> standbyContainers = this.standbyContainerConstraints.get(activeContainerID); + Map<String, SamzaResource> runningStandbyContainersOnHost = this.samzaApplicationState.runningContainers.entrySet().stream().filter(x -> standbyContainers.contains(x.getKey())) + .filter(x -> x.getValue().getHost().equals(standbyHost)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - String standbyContainerId = standbyContainer.get().getKey(); - SamzaResource standbyResource = standbyContainer.get().getValue(); - String standbyResourceID = standbyResource.getResourceID(); - String standbyHost = standbyResource.getHost(); + // if the standbyHost returned is anyhost, we proceed with the request directly Review comment: As a readability guideline, `If...Else-if..Else` blocks should check predicates which are related. For eg: it may not be obvious that standbyHost == ANY_HOST and runningStandbyContainersOnHost.isEmpty are related.. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services