String errorMessage = String.format("Operation '%s:%s' failed after retrying %d times, retry limit %d", operationName, shortDescription, internalNumberOfRetries.get(), 3); logger.debug(errorMessage, retryException.getLastFailedAttempt().getExceptionCause()); throw new RuntimeException(errorMessage, retryException.getLastFailedAttempt().getExceptionCause());
} catch (RetryException e) { LOG.warn("Tried to update session 10 times, but still failed. This is likely because of https://jira.mongodb.org/browse/SERVER-14322", e); throw new RuntimeException(e.getCause());
private BulkResult runBulkRequest(final Bulk request, int count) { try { return BULK_REQUEST_RETRYER.call(() -> client.execute(request)); } catch (ExecutionException | RetryException e) { if (e instanceof RetryException) { LOG.error("Could not bulk index {} messages. Giving up after {} attempts.", count, ((RetryException) e).getNumberOfFailedAttempts()); } else { LOG.error("Couldn't bulk index " + count + " messages.", e); } throw new RuntimeException(e); } }
@Test public void testRetryIfResult() throws Exception { Callable<Boolean> callable = notNullAfter5Attempts(); Retryer retryer = RetryerBuilder.newBuilder() .retryIfResult(Objects::isNull) .build(); assertTrue(retryer.call(callable)); callable = notNullAfter5Attempts(); retryer = RetryerBuilder.newBuilder() .retryIfResult(Objects::isNull) .withStopStrategy(StopStrategies.stopAfterAttempt(3)) .build(); try { retryer.call(callable); fail("Exception expected"); } catch (RetryException e) { assertEquals(3, e.getNumberOfFailedAttempts()); assertTrue(e.getLastFailedAttempt().hasResult()); assertNull(e.getLastFailedAttempt().getResult()); assertNull(e.getCause()); } }
metrics.error(); LOG.warn("{} Couldn't upload or delete {}", logIdentifier, file, re); exceptionNotifier.notify(String.format("%s exception during upload", re.getCause().getClass()), re.getCause(), ImmutableMap.of("logIdentifier", logIdentifier, "file", file.toString(), "failedAttempts", Integer.toString(re.getNumberOfFailedAttempts()))); } catch (Exception e) { metrics.error();
/** * Throw the Attempt's exception, if it has one, wrapped in a RetryException. Otherwise, * return the attempt's result. * * @param attempt An attempt that was made by invoking the call * @param <T> The type of the attempt * @return The result of the attempt * @throws RetryException If the attempt has an exception */ private <T> T getOrThrow(Attempt<T> attempt) throws RetryException { if (attempt.hasException()) { throw new RetryException(attempt); } return attempt.get(); }
@Override public List<Identification> fetchIdentifications() { List<Identification> identificationList = new ArrayList<>(); String authToken = null; try { authToken = login(); } catch (ExecutionException ee) { LOG.error("Error while logging in", ee.getMessage()); } catch (RetryException re) { LOG.error("Reached max number of retries while logging in", re.getMessage()); } if(authToken != null) { try { identificationList = getIdentifications(authToken); } catch (ExecutionException ee) { LOG.error("Error while getting identifications", ee.getMessage()); } catch (RetryException re) { LOG.error("Reached maximum number of retries while getting identifications", re.getMessage()); } } else { LOG.error("AuthToken still null after login"); //Should never happen } return identificationList; }
throw new RetryException(attemptNumber, attempt); } else { long sleepTime = waitStrategy.computeSleepTime(attempt); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RetryException(attemptNumber, attempt);
logger.error(e.getMessage(), e); } catch (RetryException e) { logger.error(e.getMessage(), e);
private byte[] retrieveBytes(String url) { MutableInt retry = new MutableInt(0); try { return retryer.call(() -> request(url, retry)); } catch (ExecutionException e) { throw Throwables.propagate(e.getCause()); } catch (RetryException e) { if (e.getLastFailedAttempt().hasException()) { throw new RuntimeException("Max retries exceeded", e.getLastFailedAttempt().getExceptionCause()); } else { throw new RuntimeException("Max retries exceeded", e); } } }
} catch (RetryException e) { LOG.warn("Tried to update session 10 times, but still failed. This is likely because of https://jira.mongodb.org/browse/SERVER-14322", e); throw new RuntimeException(e.getCause());
private BulkResult runBulkRequest(final Bulk request, int count) { try { return BULK_REQUEST_RETRYER.call(() -> client.execute(request)); } catch (ExecutionException | RetryException e) { if (e instanceof RetryException) { LOG.error("Could not bulk index {} messages. Giving up after {} attempts.", count, ((RetryException) e).getNumberOfFailedAttempts()); } else { LOG.error("Couldn't bulk index " + count + " messages.", e); } throw new RuntimeException(e); } }
throw new RetryException(attempt); } else { long sleepTime = waitStrategy.computeSleepTime(attempt);
private void handleException(final String request, final String type, final List<String> ids, final Exception exception, final String metricName) { log.error("Failed {} metadata of type {} with ids {}. {}", request, type, ids, exception); String exceptionName = exception.getClass().getSimpleName(); if (exception instanceof RetryException) { final Throwable error = ((RetryException) exception).getLastFailedAttempt().getExceptionCause(); if (error != null) { exceptionName = error.getClass().getSimpleName(); } } final Map<String, String> tags = ImmutableMap .<String, String>builder().put("status", "failure").put("exception", exceptionName).build(); registry.counter(registry.createId(metricName).withTags(tags)).increment(); log(request, type, ids.toString(), null, exception.getMessage(), exception, true); }
} catch (RetryException e) { throw new DirectiveExecutionException( String.format("Issue in retrieving schema from schema registry. %s", e.getCause()) );
public void forPredicate(Elements elements, Duration timeout, Duration interval, Predicate<? super Elements> predicate) { Configuration configuration = elements.as(HasConfiguration.class).configure(); if (timeout == null) { timeout = configuration.defaultTimeout(); } if (interval == null) { interval = configuration.defaultInterval(); } Retryer<Elements> retrier = getRetryer(predicate, timeout, interval); try { retrier.call(Callables.returning(elements)); } catch (RetryException e) { // if interrupted, we need to propagate it with the thread marked as interrupted if (Thread.interrupted()) { Thread.currentThread().interrupt(); throw Throwables.propagate(e); } throw new TimeoutException(predicate, elements, e.getNumberOfFailedAttempts()); } catch (ExecutionException e) { throw Throwables.propagate(e.getCause()); } }
private void handleException(final String request, final String type, final String id, final Exception exception, final String metricName) { log.error("Failed {} metadata of type {} with id {}. {}", request, type, id, exception); String exceptionName = exception.getClass().getSimpleName(); if (exception instanceof RetryException) { final Throwable error = ((RetryException) exception).getLastFailedAttempt().getExceptionCause(); if (error != null) { exceptionName = error.getClass().getSimpleName(); } } final Map<String, String> tags = ImmutableMap .<String, String>builder().put("status", "failure").put("name", id).put("exception", exceptionName).build(); registry.counter(registry.createId(metricName).withTags(tags)).increment(); log(request, type, id, null, exception.getMessage(), exception, true); }
} catch (RetryException e) { throw new DirectiveExecutionException( String.format("Issue in retrieving protobuf descriptor from schema registry. %s", e.getCause()) );
@Test public void testWithStopStrategy() throws Exception { Callable<Boolean> callable = notNullAfter5Attempts(); Retryer retryer = RetryerBuilder.newBuilder() .withStopStrategy(StopStrategies.stopAfterAttempt(3)) .retryIfResult(Objects::isNull) .build(); try { retryer.call(callable); fail("RetryException expected"); } catch (RetryException e) { assertEquals(3, e.getNumberOfFailedAttempts()); } }
String errorMessage = String.format("Operation '%s:%s' failed after retrying %d times, retry limit %d", operationName, shortDescription, internalNumberOfRetries.get(), 3); logger.debug(errorMessage, retryException.getLastFailedAttempt().getExceptionCause()); throw new RuntimeException(errorMessage, retryException.getLastFailedAttempt().getExceptionCause());