@Provides BackOff provideExponentialBackoff( ExponentialBackOff.Builder builder) { return builder.build(); } }
.setMaxIntervalMillis(Ints.checkedCast(TimeUnit.SECONDS.toMillis(60))) .setMaxElapsedTimeMillis(Ints.checkedCast(timeUnit.toMillis(timeout))) .build();
@ProcessElement public void processElement(DoFn<String, Integer>.ProcessContext context) throws Exception { String variantId = context.element(); // Call the deletion operation via exponential backoff so that "Rate Limit Exceeded" // quota issues do not cause the pipeline to fail. ExponentialBackOff backoff = new ExponentialBackOff.Builder().build(); while (true) { try { genomics.variants().delete(variantId).execute(); Metrics.counter(DeleteVariantFn.class, "Number of variants deleted").inc(); context.output(1); return; } catch (Exception e) { if (e.getMessage().startsWith("429 Too Many Requests")) { LOG.warn("Backing-off per: ", e); long backOffMillis = backoff.nextBackOffMillis(); if (backOffMillis == BackOff.STOP) { throw e; } Thread.sleep(backOffMillis); } else { throw e; } } } } }
.setMultiplier(1.5) .setRandomizationFactor(0.15) .build(); } else { backOff = BackOff.STOP_BACKOFF;
@ProcessElement public void processElement(DoFn<String, Integer>.ProcessContext context) throws Exception { String variantId = context.element(); // Call the deletion operation via exponential backoff so that "Rate Limit Exceeded" // quota issues do not cause the pipeline to fail. ExponentialBackOff backoff = new ExponentialBackOff.Builder().build(); while (true) { try { genomics.variants().delete(variantId).execute(); Metrics.counter(DeleteVariantFn.class, "Number of variants deleted").inc(); context.output(1); return; } catch (Exception e) { if (e.getMessage().startsWith("429 Too Many Requests")) { LOG.warn("Backing-off per: ", e); long backOffMillis = backoff.nextBackOffMillis(); if (backOffMillis == BackOff.STOP) { throw e; } Thread.sleep(backOffMillis); } else { throw e; } } } } }
@Override public void initialize(HttpRequest request) throws IOException { // Set a timeout for hanging-gets. // TODO: Do this exclusively for work requests. request.setReadTimeout(HANGING_GET_TIMEOUT_SEC * 1000); request.setWriteTimeout(this.writeTimeout); LoggingHttpBackOffHandler loggingHttpBackOffHandler = new LoggingHttpBackOffHandler( sleeper, // Back off on retryable http errors and IOExceptions. // A back-off multiplier of 2 raises the maximum request retrying time // to approximately 5 minutes (keeping other back-off parameters to // their default values). new ExponentialBackOff.Builder().setNanoClock(nanoClock).setMultiplier(2).build(), new ExponentialBackOff.Builder().setNanoClock(nanoClock).setMultiplier(2).build(), ignoredResponseCodes); request.setUnsuccessfulResponseHandler(loggingHttpBackOffHandler); request.setIOExceptionHandler(loggingHttpBackOffHandler); // Set response initializer if (responseInterceptor != null) { request.setResponseInterceptor(responseInterceptor); } }
/** * {@inheritDoc} * * <p>If a table with the same name already exists in the dataset, the function simply returns. * In such a case, the existing table doesn't necessarily have the same schema as specified by * the parameter. * * @throws IOException if other error than already existing table occurs. */ @Override public void createTable(Table table) throws InterruptedException, IOException { LOG.info( "Trying to create BigQuery table: {}", BigQueryHelpers.toTableSpec(table.getTableReference())); BackOff backoff = new ExponentialBackOff.Builder() .setMaxElapsedTimeMillis(RETRY_CREATE_TABLE_DURATION_MILLIS) .build(); tryCreateTable(table, backoff, Sleeper.DEFAULT); }
/** * Create a stream iterator that will filter shard data using the predicate, if supplied. * * @param channel The channel. * @param request The request for the shard of data. * @param shardPredicate A predicate used to client-side filter results returned (e.g., enforce a * shard boundary and/or limit to SNPs only) or null for no filtering. */ protected GenomicsStreamIterator(ManagedChannel channel, RequestT request, Predicate<ItemT> shardPredicate) { this.originalRequest = request; this.shardPredicate = shardPredicate; this.genomicsChannel = channel; stub = createStub(genomicsChannel); // Using default backoff settings. For details, see // https://developers.google.com/api-client-library/java/google-http-java-client/reference/1.19.0/com/google/api/client/util/ExponentialBackOff backoff = new ExponentialBackOff.Builder().build(); // RETRY STATE: Initialize settings. delegate = createIterator(originalRequest); lastSuccessfulDataItem = null; idSentinel = null; }
/** {@inheritDoc} */ @Override public void waitForReplication(BigtableTableName tableName, long timeout) throws InterruptedException, TimeoutException { // A backoff that randomizes with an interval of 10s. ExponentialBackOff backOff = new ExponentialBackOff.Builder() .setInitialIntervalMillis(10 * 1000) .setMaxIntervalMillis(10 * 1000) .setMaxElapsedTimeMillis(Ints.checkedCast(timeout * 1000)) .build(); waitForReplication(tableName, backOff); }
/** Creates new generic BackOff used for retries. */ @VisibleForTesting ExponentialBackOff createBackOff() { return new ExponentialBackOff.Builder() .setInitialIntervalMillis(readOptions.getBackoffInitialIntervalMillis()) .setRandomizationFactor(readOptions.getBackoffRandomizationFactor()) .setMultiplier(readOptions.getBackoffMultiplier()) .setMaxIntervalMillis(readOptions.getBackoffMaxIntervalMillis()) .setMaxElapsedTimeMillis(readOptions.getBackoffMaxElapsedTimeMillis()) .setNanoClock(clock) .build(); }
/** * Returns {@link BackOff} instance used for implementing exponential back off for failed * requests. */ @Override public BackOff createBackOffInstance() { return new ExponentialBackOff.Builder() .setInitialIntervalMillis(INITIAL_DELAY_SECONDS * 1000) .setMultiplier(MULTIPLIER) .build(); } }
private static ExponentialBackOff newBackOff() { return new ExponentialBackOff.Builder() .setInitialIntervalMillis(MIN_BACKOFF_MS) .setMaxIntervalMillis(MAX_BACKOFF_MS) .setMaxElapsedTimeMillis(Integer.MAX_VALUE) // Prevent Backoff.STOP from getting returned. .build(); }
public BackOffUtil(boolean isExponential) { if (isExponential) { // aggressive backOff = new ExponentialBackOff.Builder() .setInitialIntervalMillis(2) .setMaxElapsedTimeMillis(Integer.MAX_VALUE) .setMaxIntervalMillis(Integer.MAX_VALUE) .setMultiplier(1.5) .setRandomizationFactor(0) .build(); } else { // conservative backOff = new FixedBackOff(); } }
private static ExponentialBackOff newBackOff() { return new ExponentialBackOff.Builder() .setInitialIntervalMillis(MIN_BACKOFF_MS) .setMaxIntervalMillis(MAX_BACKOFF_MS) .setMaxElapsedTimeMillis(Integer.MAX_VALUE) // Prevent Backoff.STOP from getting returned. .build(); }