public InetSocketAddress getRandomHostForKey(byte[] key) { List<InetSocketAddress> hostsForKey = getHostsFor(key); if (hostsForKey == null) { log.info("We attempted to route your query to a cassandra host that already contains the relevant data." + " However, the mapping of which host contains which data is not available yet." + " We will choose a random host instead."); return getRandomGoodHost().getHost(); } Set<InetSocketAddress> liveOwnerHosts = blacklist.filterBlacklistedHostsFrom(hostsForKey); if (!liveOwnerHosts.isEmpty()) { Optional<InetSocketAddress> activeHost = getRandomHostByActiveConnections(liveOwnerHosts); if (activeHost.isPresent()) { return activeHost.get(); } } log.warn("Perf / cluster stability issue. Token aware query routing has failed because there are no known " + "live hosts that claim ownership of the given range. Falling back to choosing a random live node." + " Current host blacklist is {}." + " Current state logged at TRACE", SafeArg.of("blacklistedHosts", blacklist.blacklistDetails())); log.trace("Current ring view is: {}.", SafeArg.of("tokenMap", getRingViewDescription())); return getRandomGoodHost().getHost(); }
public InetSocketAddress getRandomHostForKey(byte[] key) { List<InetSocketAddress> hostsForKey = getHostsFor(key); if (hostsForKey == null) { log.info("We attempted to route your query to a cassandra host that already contains the relevant data." + " However, the mapping of which host contains which data is not available yet." + " We will choose a random host instead."); return getRandomGoodHost().getHost(); } Set<InetSocketAddress> liveOwnerHosts = blacklist.filterBlacklistedHostsFrom(hostsForKey); if (!liveOwnerHosts.isEmpty()) { Optional<InetSocketAddress> activeHost = getRandomHostByActiveConnections(liveOwnerHosts); if (activeHost.isPresent()) { return activeHost.get(); } } log.warn("Perf / cluster stability issue. Token aware query routing has failed because there are no known " + "live hosts that claim ownership of the given range. Falling back to choosing a random live node." + " Current host blacklist is {}." + " Current state logged at TRACE", SafeArg.of("blacklistedHosts", blacklist.blacklistDetails())); log.trace("Current ring view is: {}.", SafeArg.of("tokenMap", getRingViewDescription())); return getRandomGoodHost().getHost(); }