/** * Discovers all shards of this file using the provided {@link Sleeper} and {@link BackOff}. * * <p>Because of eventual consistency, reads may discover no files or fewer files than the * explicit list of files implies. In this case, the read is considered to have failed. */ @Override public List<String> readFilesWithRetries(Sleeper sleeper, BackOff backOff) throws IOException, InterruptedException { if (files.isEmpty()) { return Collections.emptyList(); } IOException lastException = null; do { try { // Read data from file paths return readLines(files); } catch (IOException e) { // Ignore and retry lastException = e; LOG.warn("Error in file reading. Ignore and retry."); } } while (BackOffUtils.next(sleeper, backOff)); // Failed after max retries throw new IOException( String.format("Unable to read file(s) after retrying %d times", MAX_READ_RETRIES), lastException); }
LOG.warn("Error in file reading. Ignore and retry."); } while (BackOffUtils.next(sleeper, backOff));
LOG.warn("Error in file reading. Ignore and retry."); } while (BackOffUtils.next(sleeper, backOff));
if (!BackOffUtils.next(sleeper, backoff)) {
private RunQueryResponse runQueryWithRetries(RunQueryRequest request) throws Exception { Sleeper sleeper = Sleeper.DEFAULT; BackOff backoff = RUNQUERY_BACKOFF.backoff(); while (true) { try { RunQueryResponse response = datastore.runQuery(request); rpcSuccesses.inc(); return response; } catch (DatastoreException exception) { rpcErrors.inc(); if (NON_RETRYABLE_ERRORS.contains(exception.getCode())) { throw exception; } if (!BackOffUtils.next(sleeper, backoff)) { LOG.error("Aborting after {} retries.", MAX_RETRIES); throw exception; } } } }
/** retry request based on retry configuration policy. */ private HttpEntity handleRetry( String method, String endpoint, Map<String, String> params, HttpEntity requestBody) throws IOException, InterruptedException { Response response; HttpEntity responseEntity; Sleeper sleeper = Sleeper.DEFAULT; BackOff backoff = retryBackoff.backoff(); int attempt = 0; //while retry policy exists while (BackOffUtils.next(sleeper, backoff)) { LOG.warn(String.format(RETRY_ATTEMPT_LOG, ++attempt)); response = restClient.performRequest(method, endpoint, params, requestBody); responseEntity = new BufferedHttpEntity(response.getEntity()); //if response has no 429 errors if (!spec.getRetryConfiguration().getRetryPredicate().test(responseEntity)) { return responseEntity; } } throw new IOException(String.format(RETRY_FAILED_LOG, attempt)); }
/** * Sets up external resources that are required by the example, such as Pub/Sub topics and * BigQuery tables. * * @throws IOException if there is a problem setting up the resources */ public void setup() throws IOException { Sleeper sleeper = Sleeper.DEFAULT; BackOff backOff = FluentBackoff.DEFAULT.withMaxRetries(3).withInitialBackoff(Duration.millis(200)).backoff(); Throwable lastException = null; try { do { try { setupPubsub(); setupBigQueryTable(); return; } catch (GoogleJsonResponseException e) { lastException = e; } } while (BackOffUtils.next(sleeper, backOff)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); // Ignore InterruptedException } throw new RuntimeException(lastException); }
if (!BackOffUtils.next(sleeper, backoff)) { throw new IOException( String.format(
if (!BackOffUtils.next(sleeper, backoff)) { throw new IOException( String.format(
throw exception; if (!BackOffUtils.next(sleeper, backoff)) { LOG.error("Aborting after {} retries.", MAX_RETRIES); throw exception;
exception.getCode(), exception.getMessage()); if (!BackOffUtils.next(sleeper, backoff)) { LOG.error("Aborting after {} retries.", MAX_RETRIES); throw exception;