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 {}.", SafeArg.of("specifiedHost", specifiedHost.getHostString())); } CassandraClientPoolingContainer hostPool = currentPools.get(specifiedHost); if (blacklistedHosts.containsKey(specifiedHost) || hostPool == null || shouldRetryOnDifferentHost) { log.warn("Randomly redirected a query intended for host {}.", SafeArg.of("specifiedHost", 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 {}. Exception message was: : {}", fn.toString(), SafeArg.of("hostName", hostPool.getHost()), SafeArg.of("exceptionClass", e.getClass().getTypeName()), e.getMessage()); 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; } } } } }

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 {}.", SafeArg.of("specifiedHost", specifiedHost.getHostString())); } CassandraClientPoolingContainer hostPool = currentPools.get(specifiedHost); if (blacklistedHosts.containsKey(specifiedHost) || hostPool == null || shouldRetryOnDifferentHost) { log.warn("Randomly redirected a query intended for host {}.", SafeArg.of("specifiedHost", 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)) { int sleepDuration = numTries * 1000 + (ThreadLocalRandom.current().nextInt(1000) - 500); log.warn("Retrying with backoff ({}ms} a query, {}, intended for host {}.", SafeArg.of("sleepDuration", sleepDuration), UnsafeArg.of("queryString", fn.toString()), SafeArg.of("hostName", hostPool.getHost())); try { Thread.sleep(sleepDuration); } catch (InterruptedException i) { throw new RuntimeException(i); } if (numTries >= MAX_TRIES_SAME_HOST) { shouldRetryOnDifferentHost = true; } } } } }