public static <T> T retryAzureOperation(Task<T> f, int maxTries) throws Exception { return RetryUtils.retry(f, AZURE_RETRY, maxTries); } }
public interface CleanupAfterFailure { /** * This is called once {@link Task#perform()} fails. Retrying is stopped once this method throws an exception, * so errors inside this method should be ignored if you don't want to stop retrying. */ void cleanup(); }
public static void awaitNextRetry( final Throwable e, @Nullable final String messageOnRetry, final int nTry, final int maxRetries, final boolean quiet ) throws InterruptedException { final long sleepMillis = nextRetrySleepMillis(nTry); final String fullMessage; if (messageOnRetry == null) { fullMessage = StringUtils.format("Retrying (%d of %d) in %,dms.", nTry, maxRetries, sleepMillis); } else { fullMessage = StringUtils.format( "%s, retrying (%d of %d) in %,dms.", messageOnRetry, nTry, maxRetries, sleepMillis ); } if (quiet) { log.debug(e, fullMessage); } else { log.warn(e, fullMessage); } Thread.sleep(sleepMillis); }
/** * Retries S3 operations that fail due to io-related exceptions. Service-level exceptions (access denied, file not * found, etc) are not retried. */ public static <T> T retryS3Operation(Task<T> f) throws Exception { final int maxTries = 10; return RetryUtils.retry(f, S3RETRY, maxTries); }
RetryUtils.awaitNextRetry(t, null, nTry + 1, maxRetry, false);
long sleepMillis = Math.min( MAX_RETRY_BACKOFF, RetryUtils.nextRetrySleepMillis(consecutiveFailedAttemptCount) ); log.info("Scheduling next syncup in [%d] millis for server[%s].", sleepMillis, logIdentity);
/** * Retries CloudFiles operations that fail due to io-related exceptions. */ public static <T> T retryCloudFilesOperation(Task<T> f, final int maxTries) throws Exception { return RetryUtils.retry(f, CLOUDFILESRETRY, maxTries); }
public interface CleanupAfterFailure { /** * This is called once {@link Task#perform()} fails. Retrying is stopped once this method throws an exception, * so errors inside this method should be ignored if you don't want to stop retrying. */ void cleanup(); }
public static void awaitNextRetry( final Throwable e, @Nullable final String messageOnRetry, final int nTry, final int maxRetries, final boolean quiet ) throws InterruptedException { final long sleepMillis = nextRetrySleepMillis(nTry); final String fullMessage; if (messageOnRetry == null) { fullMessage = StringUtils.format("Retrying (%d of %d) in %,dms.", nTry, maxRetries, sleepMillis); } else { fullMessage = StringUtils.format( "%s, retrying (%d of %d) in %,dms.", messageOnRetry, nTry, maxRetries, sleepMillis ); } if (quiet) { log.debug(e, fullMessage); } else { log.warn(e, fullMessage); } Thread.sleep(sleepMillis); }
public static <T> T retry( final Task<T> f, final Predicate<Throwable> shouldRetry, final int quietTries, final int maxTries ) throws Exception { return retry(f, shouldRetry, quietTries, maxTries, null, null); }
RetryUtils.awaitNextRetry(t, null, nTry + 1, maxRetry, false);
long sleepMillis = Math.min( MAX_RETRY_BACKOFF, RetryUtils.nextRetrySleepMillis(consecutiveFailedAttemptCount) ); log.info("Scheduling next syncup in [%d] millis for server[%s].", sleepMillis, logIdentity);
public static <T> T retry( final Task<T> f, final Predicate<Throwable> shouldRetry, final CleanupAfterFailure onEachFailure, final int maxTries, final String messageOnRetry ) throws Exception { return retry(f, shouldRetry, 0, maxTries, onEachFailure, messageOnRetry); }
public <T> T retryWithHandle( HandleCallback<T> callback, Predicate<Throwable> myShouldRetry ) { try { return RetryUtils.retry(() -> getDBI().withHandle(callback), myShouldRetry, MAX_RETRIES); } catch (Exception e) { throw new RuntimeException(e); } }
public <T> T retryTransaction(final TransactionCallback<T> callback, final int quietTries, final int maxTries) { try { return RetryUtils.retry(() -> getDBI().inTransaction(TransactionIsolationLevel.READ_COMMITTED, callback), shouldRetry, quietTries, maxTries); } catch (Exception e) { throw Throwables.propagate(e); } }
public static boolean deleteWithRetry(final FileSystem fs, final Path path, final boolean recursive) { try { return RetryUtils.retry( () -> fs.delete(path, recursive), shouldRetryPredicate(), NUM_RETRIES ); } catch (Exception e) { log.error(e, "Failed to cleanup path[%s]", path); throw Throwables.propagate(e); } }
public <T> T retryWithHandle( final HandleCallback<T> callback, final Predicate<Throwable> myShouldRetry ) { try { return RetryUtils.retry(() -> getDBI().withHandle(callback), myShouldRetry, DEFAULT_MAX_TRIES); } catch (Exception e) { throw Throwables.propagate(e); } }
/** * Matches based on a pattern in the file name. Returns the file with the latest timestamp. * * @param uri If it is a file, then the parent is searched. If it is a directory, then the directory is searched. * @param pattern The matching filter to down-select the file names in the directory of interest. Passing `null` * results in matching any file * * @return The URI of the most recently modified file which matches the pattern, or `null` if it cannot be found */ @Override public URI getLatestVersion(URI uri, final @Nullable Pattern pattern) { final File file = new File(uri); try { return RetryUtils.retry( () -> mostRecentInDir( file.isDirectory() ? file.toPath() : file.getParentFile().toPath(), pattern ), shouldRetryPredicate(), DEFAULT_RETRY_COUNT ); } catch (Exception e) { if (e instanceof FileNotFoundException) { return null; } throw Throwables.propagate(e); } }
/** * Downloads an object. It retries downloading {@link #maxFetchRetry} * times and throws an exception. * * @param object an object to be downloaded * @param outFile a file which the object data is stored * * @return number of downloaded bytes */ @Override protected long download(T object, File outFile) throws IOException { try { return RetryUtils.retry( () -> { try (final InputStream is = openObjectFunction.open(object); final OutputStream os = new FileOutputStream(outFile)) { return IOUtils.copyLarge(is, os, buffer); } }, retryCondition, outFile::delete, maxFetchRetry + 1, StringUtils.format("Failed to download object[%s]", object) ); } catch (Exception e) { throw new IOException(e); } }
/** * Returns the latest modified file at the uri of interest. * * @param uri Either a directory or a file on HDFS. If it is a file, the parent directory will be searched. * @param pattern A pattern matcher for file names in the directory of interest. Passing `null` results in matching any file in the directory. * * @return The URI of the file with the most recent modified timestamp. */ @Override public URI getLatestVersion(final URI uri, final @Nullable Pattern pattern) { final Path path = new Path(uri); try { return RetryUtils.retry( () -> { final FileSystem fs = path.getFileSystem(config); if (!fs.exists(path)) { return null; } return mostRecentInDir(fs.isDirectory(path) ? path : path.getParent(), pattern); }, shouldRetryPredicate(), DEFAULT_RETRY_COUNT ); } catch (Exception e) { throw Throwables.propagate(e); } }