private <K extends Exception> void handleRetryOnDifferentHosts(RetryableCassandraRequest<?, K> req, InetSocketAddress hostTried, Exception ex, RequestExceptionHandlerStrategy strategy) { if (shouldRetryOnDifferentHost(ex, req.getNumberOfAttemptsOnHost(hostTried), strategy)) { log.info("Retrying a query intended for host {} on a different host.", SafeArg.of("hostName", CassandraLogHelper.host(hostTried))); req.giveUpOnPreferredHost(); } }
@Test public void connectionExceptionRetriesOnDifferentHostAfterSufficientRetriesDefault() { for (Exception ex : CONNECTION_EXCEPTIONS) { assertFalse(String.format("Exception %s should not retry on different host", ex), handlerLegacy.shouldRetryOnDifferentHost(ex, MAX_RETRIES_PER_HOST - 1, handlerLegacy.getStrategy())); } for (Exception ex : CONNECTION_EXCEPTIONS) { assertTrue(String.format("Exception %s should retry on different host", ex), handlerLegacy.shouldRetryOnDifferentHost(ex, MAX_RETRIES_PER_HOST, handlerLegacy.getStrategy())); } }
@Test public void connectionExceptionRetriesOnDifferentHostAfterSufficientRetriesConservative() { for (Exception ex : CONNECTION_EXCEPTIONS) { assertFalse(String.format("Exception %s should not retry on different host", ex), handlerConservative.shouldRetryOnDifferentHost(ex, MAX_RETRIES_PER_HOST - 1, handlerConservative.getStrategy())); } for (Exception ex : CONNECTION_EXCEPTIONS) { assertTrue(String.format("Exception %s should retry on different host", ex), handlerConservative.shouldRetryOnDifferentHost(ex, MAX_RETRIES_PER_HOST, handlerConservative.getStrategy())); } }
@Test public void cassandraLoadExceptionRetriesOnDifferentHostAfterSufficientRetriesDefault() { for (Exception ex : INDICATIVE_OF_CASSANDRA_LOAD_EXCEPTIONS) { assertTrue(String.format("Exception %s should retry on different host", ex), handlerLegacy.shouldRetryOnDifferentHost(ex, MAX_RETRIES_PER_HOST, handlerLegacy.getStrategy())); } }
@Test public void cassandraLoadExceptionRetriesOnDifferentHostAfterSufficientRetriesConservative() { for (Exception ex : INDICATIVE_OF_CASSANDRA_LOAD_EXCEPTIONS) { assertTrue(String.format("Exception %s should retry on different host", ex), handlerConservative.shouldRetryOnDifferentHost(ex, MAX_RETRIES_PER_HOST, handlerConservative.getStrategy())); } }
@Test public void exceptionAfterMaxRetriesPerHostAlwaysRetriesOnDifferentHostConservative() { for (Exception ex : ALL_EXCEPTIONS) { assertTrue(String.format("If the max retries per host has been exceeded, we should always retry on a" + " different host - but we didn't for exception %s", ex), handlerConservative.shouldRetryOnDifferentHost( ex, MAX_RETRIES_PER_HOST + 1, handlerConservative.getStrategy())); } }
@Test public void fastFailoverExceptionAlwaysRetriesOnDifferentHostDefault() { for (Exception ex : FAST_FAILOVER_EXCEPTIONS) { assertTrue(String.format("Fast failover exception %s should always retry on different host", ex), handlerLegacy.shouldRetryOnDifferentHost(ex, 0, handlerLegacy.getStrategy())); } }
@Test public void fastFailoverExceptionAlwaysRetriesOnDifferentHostConservative() { for (Exception ex : FAST_FAILOVER_EXCEPTIONS) { assertTrue(String.format("Fast failover exception %s should always retry on different host", ex), handlerConservative.shouldRetryOnDifferentHost(ex, 0, handlerConservative.getStrategy())); } }
@Test public void exceptionAfterMaxRetriesPerHostAlwaysRetriesOnDifferentHostDefault() { for (Exception ex : ALL_EXCEPTIONS) { assertTrue(String.format("If the max retries per host has been exceeded, we should always retry on a" + " different host - but we didn't for exception %s", ex), handlerConservative.shouldRetryOnDifferentHost( ex, MAX_RETRIES_PER_HOST + 1, handlerLegacy.getStrategy())); } }
@Test public void cassandraLoadExceptionRetriesOnDifferentHostWithoutRetryingConservative() { for (Exception ex : INDICATIVE_OF_CASSANDRA_LOAD_EXCEPTIONS) { assertTrue(handlerConservative.shouldRetryOnDifferentHost(ex, 0, handlerConservative.getStrategy())); } }
@Test public void cassandraLoadExceptionRetriesOnSameHostDefault() { for (Exception ex : INDICATIVE_OF_CASSANDRA_LOAD_EXCEPTIONS) { assertFalse(handlerLegacy.shouldRetryOnDifferentHost(ex, 0, handlerLegacy.getStrategy())); } }
private <K extends Exception> void handleRetryOnDifferentHosts(RetryableCassandraRequest<?, K> req, InetSocketAddress hostTried, Exception ex, RequestExceptionHandlerStrategy strategy) { if (shouldRetryOnDifferentHost(ex, req.getNumberOfAttemptsOnHost(hostTried), strategy)) { log.info("Retrying a query intended for host {} on a different host.", SafeArg.of("hostName", CassandraLogHelper.host(hostTried))); req.giveUpOnPreferredHost(); } }