Source:
private String selectStandbyHost(String activeContainerID, String activeContainerResourceID) { log.info("Standby containers for active container {}", this.standbyContainerConstraints.get(activeContainerID), activeContainerID); Optional<StandbyContainerManager.FailoverMetadata> failoverMetadata = activeContainerResourceID == null ? Optional.empty() : this.getFailoverMetadata(activeContainerResourceID); for (String standbyContainerID : this.standbyContainerConstraints.get(activeContainerID)) { if (samzaApplicationState.runningContainers.containsKey(standbyContainerID)) { SamzaResource standbyContainerResource = samzaApplicationState.runningContainers.get(standbyContainerID); if (!(failoverMetadata.isPresent() && failoverMetadata.get().isStandbyResourceUsed(standbyContainerResource.getResourceID()))) { log.info("Returning standby container in running state on host for active container {}", standbyContainerID, standbyContainerResource.getHost(), activeContainerID); return standbyContainerResource.getHost(); } } } log.info("Did not find any running standby container for active container {}", activeContainerID); Map<String, String> containerToHostMapping = this.samzaApplicationState.jobModelManager.jobModel().getAllContainerLocality(); for (String standbyContainerID : this.standbyContainerConstraints.get(activeContainerID)) { String standbyHost = containerToHostMapping.get(standbyContainerID); if (standbyHost == null) { continue; } else if (!(failoverMetadata.isPresent() && failoverMetadata.get().isStandbyHostUsed(standbyHost))) { log.info("Returning standby host for active container {}", standbyHost, activeContainerID); return standbyHost; } else { log.info("Not using standby host for active container because it had already been selected", standbyHost, activeContainerID); } } log.info("Did not find any standby host for active container {}, returning any-host", activeContainerID); return ResourceRequestState.ANY_HOST; }

Target:
private String selectStandbyHost(String activeContainerID, String activeContainerResourceID) { log.info("Standby containers for active container (resourceID {})", this.standbyContainerConstraints.get(activeContainerID), activeContainerID, activeContainerResourceID); Optional<FailoverMetadata> failoverMetadata = getFailoverMetadata(activeContainerResourceID); for (String standbyContainerID : this.standbyContainerConstraints.get(activeContainerID)) { if (samzaApplicationState.runningContainers.containsKey(standbyContainerID)) { SamzaResource standbyContainerResource = samzaApplicationState.runningContainers.get(standbyContainerID); if (!(failoverMetadata.isPresent() && failoverMetadata.get() .isStandbyResourceUsed(standbyContainerResource.getResourceID()))) { log.info("Returning standby container in running state on host for active container {}", standbyContainerID, standbyContainerResource.getHost(), activeContainerID); return standbyContainerResource.getHost(); } } } log.info("Did not find any running standby container for active container {}", activeContainerID); for (String standbyContainerID : this.standbyContainerConstraints.get(activeContainerID)) { String standbyHost = this.samzaApplicationState.jobModelManager.jobModel(). getContainerToHostValue(standbyContainerID, SetContainerHostMapping.HOST_KEY); if (standbyHost == null || standbyHost.isEmpty()) { log.info("No last known standbyHost for container {}", standbyContainerID); } else if (failoverMetadata.isPresent() && failoverMetadata.get().isStandbyHostUsed(standbyHost)) { log.info("Not using standby host for active container because it had already been selected", standbyHost, activeContainerID); } else { log.info("Returning standby host for active container {}", standbyHost, activeContainerID); return standbyHost; } } log.info("Did not find any standby host for active container {}, returning any-host", activeContainerID); return ResourceRequestState.ANY_HOST; }