in priam/src/main/java/com/netflix/priam/identity/token/TokenRetriever.java [205:238]
private String getReplacedIpForAssignedToken(
ImmutableSet<PriamInstance> aliveInstances, PriamInstance instance)
throws TokenRetrieverUtils.GossipParseException {
// Infer current ownership information from other instances using gossip.
TokenRetrieverUtils.InferredTokenOwnership inferredTokenOwnership =
TokenRetrieverUtils.inferTokenOwnerFromGossip(
aliveInstances, instance.getToken(), instance.getDC());
// if unreachable rely on token database.
// if mismatch rely on token database.
String ipToReplace = null;
if (inferredTokenOwnership.getTokenInformationStatus()
== TokenRetrieverUtils.InferredTokenOwnership.TokenInformationStatus.GOOD) {
Preconditions.checkNotNull(inferredTokenOwnership.getTokenInformation());
String inferredIp = inferredTokenOwnership.getTokenInformation().getIpAddress();
if (!inferredIp.equals(myInstanceInfo.getHostIP())
&& !inferredIp.equals(myInstanceInfo.getPrivateIP())) {
if (inferredTokenOwnership.getTokenInformation().isLive()) {
throw new TokenRetrieverUtils.GossipParseException(
"We have been assigned a token that C* thinks is alive. Throwing to buy time in the hopes that Gossip just needs to settle.");
}
ipToReplace = inferredIp;
logger.info(
"Priam found that the token is not alive according to Cassandra and we should start Cassandra in replace mode with replace ip: "
+ inferredIp);
}
} else if (inferredTokenOwnership.getTokenInformationStatus()
== TokenRetrieverUtils.InferredTokenOwnership.TokenInformationStatus
.MISMATCH
&& !config.permitDirectTokenAssignmentWithGossipMismatch()) {
throw new TokenRetrieverUtils.GossipParseException(
"We saw inconsistent results from gossip. Throwing to buy time for it to settle.");
}
return ipToReplace;
}