Source:
public <V, K extends Exception> V runWithRetryOnHost( InetSocketAddress specifiedHost, FunctionCheckedException<Cassandra.Client, V, K> fn) throws K { int numTries = 0; boolean shouldRetryOnDifferentHost = false; Set<InetSocketAddress> triedHosts = Sets.newHashSet(); while (true) { if (log.isTraceEnabled()) { log.trace("Running function on host {}.", specifiedHost.getHostString()); } CassandraClientPoolingContainer hostPool = currentPools.get(specifiedHost); if (blacklistedHosts.containsKey(specifiedHost) || hostPool == null || shouldRetryOnDifferentHost) { log.warn("Randomly redirected a query intended for host {}.", specifiedHost); Optional<CassandraClientPoolingContainer> hostPoolCandidate = getRandomGoodHostForPredicate(address -> !triedHosts.contains(address)); hostPool = hostPoolCandidate.orElseGet(this::getRandomGoodHost); } try { return runWithPooledResourceRecordingMetrics(hostPool, fn); } catch (Exception e) { numTries++; triedHosts.add(hostPool.getHost()); this.<K>handleException(numTries, hostPool.getHost(), e); if (isRetriableWithBackoffException(e)) { log.warn("Retrying with backoff a query intended for host {}.", hostPool.getHost(), e); try { Thread.sleep(numTries * 1000 + (ThreadLocalRandom.current().nextInt(1000) - 500)); } catch (InterruptedException i) { throw new RuntimeException(i); } if (numTries >= MAX_TRIES_SAME_HOST) { shouldRetryOnDifferentHost = true; } } else if (isFastFailoverException(e)) { log.info("Retrying with fast failover a query intended for host {}.", hostPool.getHost(), e); shouldRetryOnDifferentHost = true; } } } }

Target:
public <V, K extends Exception> V runWithRetryOnHost( InetSocketAddress specifiedHost, FunctionCheckedException<Cassandra.Client, V, K> fn) throws K { int numTries = 0; boolean shouldRetryOnDifferentHost = false; Set<InetSocketAddress> triedHosts = Sets.newHashSet(); while (true) { if (log.isTraceEnabled()) { log.trace("Running function on host {}.", specifiedHost.getHostString()); } CassandraClientPoolingContainer hostPool = currentPools.get(specifiedHost); if (blacklistedHosts.containsKey(specifiedHost) || hostPool == null || shouldRetryOnDifferentHost) { InetSocketAddress previousHostPool = hostPool == null ? specifiedHost : hostPool.getHost(); Optional<CassandraClientPoolingContainer> hostPoolCandidate = getRandomGoodHostForPredicate(address -> !triedHosts.contains(address)); hostPool = hostPoolCandidate.orElseGet(this::getRandomGoodHost); log.warn("Randomly redirected a query intended for host to {}.", previousHostPool, hostPool.getHost()); } try { return runWithPooledResourceRecordingMetrics(hostPool, fn); } catch (Exception e) { numTries++; triedHosts.add(hostPool.getHost()); this.<K>handleException(numTries, hostPool.getHost(), e); if (isRetriableWithBackoffException(e)) { log.warn("Retrying with backoff a query intended for host {}.", hostPool.getHost(), e); try { Thread.sleep(numTries * 1000 + (ThreadLocalRandom.current().nextInt(1000) - 500)); } catch (InterruptedException i) { throw new RuntimeException(i); } if (numTries >= MAX_TRIES_SAME_HOST) { shouldRetryOnDifferentHost = true; } } else if (isFastFailoverException(e)) { log.info("Retrying with fast failover a query intended for host {}.", hostPool.getHost(), e); shouldRetryOnDifferentHost = true; } } } }