private String getReplacedIpForExistingToken()

in priam/src/main/java/com/netflix/priam/identity/token/TokenRetriever.java [240:286]


    private String getReplacedIpForExistingToken(
            ImmutableSet<PriamInstance> allInstancesWithinCluster, PriamInstance priamInstance) {

        // Infer current ownership information from other instances using gossip.
        TokenRetrieverUtils.InferredTokenOwnership inferredTokenInformation =
                TokenRetrieverUtils.inferTokenOwnerFromGossip(
                        allInstancesWithinCluster, priamInstance.getToken(), priamInstance.getDC());

        switch (inferredTokenInformation.getTokenInformationStatus()) {
            case GOOD:
                if (inferredTokenInformation.getTokenInformation() == null) {
                    logger.error(
                            "If you see this message, it should not have happened. We expect token ownership information if all nodes agree. This is a code bounty issue.");
                    return null;
                }
                // Everyone agreed to a value. Check if it is live node.
                if (inferredTokenInformation.getTokenInformation().isLive()) {
                    logger.info(
                            "This token is considered alive unanimously! We will not replace this instance.");
                    return null;
                } else {
                    String ip = inferredTokenInformation.getTokenInformation().getIpAddress();
                    logger.info("Will try to replace token owned by {}", ip);
                    return ip;
                }
            case UNREACHABLE_NODES:
                // In case of unable to reach sufficient nodes, fallback to IP in token
                // database. This could be a genuine case of say missing security
                // permissions.
                logger.warn(
                        "Unable to reach sufficient nodes. Please check security group permissions or there might be a network partition.");
                logger.info(
                        "Will try to replace token: {} with replacedIp from Token database: {}",
                        priamInstance.getToken(),
                        priamInstance.getHostIP());
                return priamInstance.getHostIP();
            case MISMATCH:
                // Lets not replace the instance if gossip info is not merging!!
                logger.info(
                        "Mismatch in gossip. We will not replace this instance, until gossip settles down.");
                return null;
            default:
                throw new IllegalStateException(
                        "Unexpected value: "
                                + inferredTokenInformation.getTokenInformationStatus());
        }
    }