private <K extends Exception> void handleBackoff(RetryableCassandraRequest<?, K> req, InetSocketAddress hostTried, Exception ex, RequestExceptionHandlerStrategy strategy) { if (!shouldBackoff(ex, strategy)) { return; } long backOffPeriod = strategy.getBackoffPeriod(req.getNumberOfAttemptsOnHost(hostTried)); log.info("Retrying a query, {}, with backoff of {}ms, intended for host {}.", UnsafeArg.of("queryString", req.getFunction().toString()), SafeArg.of("sleepDuration", backOffPeriod), SafeArg.of("hostName", CassandraLogHelper.host(hostTried))); try { Thread.sleep(backOffPeriod); } catch (InterruptedException i) { Thread.currentThread().interrupt(); throw new RuntimeException(i); } }
@VisibleForTesting boolean shouldBackoff(Exception ex, RequestExceptionHandlerStrategy strategy) { return strategy.shouldBackoff(ex); }
@VisibleForTesting boolean shouldRetryOnDifferentHost(Exception ex, int numberOfAttempts, RequestExceptionHandlerStrategy strategy) { return strategy.shouldRetryOnDifferentHost(ex, maxTriesSameHost.get(), numberOfAttempts); }
private <K extends Exception> void handleBackoff(RetryableCassandraRequest<?, K> req, InetSocketAddress hostTried, Exception ex, RequestExceptionHandlerStrategy strategy) { if (!shouldBackoff(ex, strategy)) { return; } long backOffPeriod = strategy.getBackoffPeriod(req.getNumberOfAttemptsOnHost(hostTried)); log.info("Retrying a query, {}, with backoff of {}ms, intended for host {}.", UnsafeArg.of("queryString", req.getFunction().toString()), SafeArg.of("sleepDuration", backOffPeriod), SafeArg.of("hostName", CassandraLogHelper.host(hostTried))); try { Thread.sleep(backOffPeriod); } catch (InterruptedException i) { Thread.currentThread().interrupt(); throw new RuntimeException(i); } }
@VisibleForTesting boolean shouldRetryOnDifferentHost(Exception ex, int numberOfAttempts, RequestExceptionHandlerStrategy strategy) { return strategy.shouldRetryOnDifferentHost(ex, maxTriesSameHost.get(), numberOfAttempts); }
@VisibleForTesting boolean shouldBackoff(Exception ex, RequestExceptionHandlerStrategy strategy) { return strategy.shouldBackoff(ex); }