Refine search
private static RetrySettings retrySettings() { return RetrySettings.newBuilder() .setMaxRetryDelay(Duration.ofMillis(30000L)) .setTotalTimeout(Duration.ofMillis(120000L)) .setInitialRetryDelay(Duration.ofMillis(250L)) .setRetryDelayMultiplier(1.0) .setInitialRpcTimeout(Duration.ofMillis(120000L)) .setRpcTimeoutMultiplier(1.0) .setMaxRpcTimeout(Duration.ofMillis(120000L)) .build(); }
@Test public void testCreateFromStream() { RemoteComputeHelper helper = RemoteComputeHelper.create(PROJECT_ID, JSON_KEY_STREAM); ComputeOptions options = helper.getOptions(); assertEquals(PROJECT_ID, options.getProjectId()); assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getConnectTimeout()); assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getReadTimeout()); assertEquals(10, options.getRetrySettings().getMaxAttempts()); assertEquals(Duration.ofMillis(30000), options.getRetrySettings().getMaxRetryDelay()); assertEquals(Duration.ofMillis(120000), options.getRetrySettings().getTotalTimeout()); assertEquals(Duration.ofMillis(250), options.getRetrySettings().getInitialRetryDelay()); }
return settings; RetrySettings.Builder builder = settings.toBuilder(); for (RetryOption option : options) { switch (option.type) { case TOTAL_TIMEOUT: builder.setTotalTimeout((Duration) option.value); break; case INITIAL_RETRY_DELAY: builder.setInitialRetryDelay((Duration) option.value); break; case RETRY_DELAY_MULTIPLIER: builder.setRetryDelayMultiplier((Double) option.value); break; case MAX_RETRY_DELAY:
/** Configures the Publisher's retry parameters. */ public Builder setRetrySettings(RetrySettings retrySettings) { Preconditions.checkArgument( retrySettings.getTotalTimeout().compareTo(MIN_TOTAL_TIMEOUT) >= 0); Preconditions.checkArgument( retrySettings.getInitialRpcTimeout().compareTo(MIN_RPC_TIMEOUT) >= 0); this.retrySettings = retrySettings; return this; }
private void verifyRetrySettings(Set<Code> retryCodes, RetrySettings retrySettings) { assertThat(retryCodes).containsAllOf(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE); assertThat(retrySettings.getTotalTimeout()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getInitialRetryDelay()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRetryDelayMultiplier()).isAtLeast(1.0); assertThat(retrySettings.getMaxRetryDelay()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getInitialRpcTimeout()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRpcTimeoutMultiplier()).isAtLeast(1.0); assertThat(retrySettings.getMaxRpcTimeout()).isGreaterThan(Duration.ZERO); } }
@Test public void testReadRowsSettings() { ServerStreamingCallSettings.Builder<ReadRowsRequest, ReadRowsResponse> builder = EnhancedBigQueryStorageStubSettings.newBuilder().readRowsSettings(); assertThat(builder.getRetryableCodes()).containsAllOf(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE); RetrySettings retrySettings = builder.getRetrySettings(); assertThat(retrySettings.getInitialRetryDelay()).isEqualTo(Duration.ofMillis(100L)); assertThat(retrySettings.getRetryDelayMultiplier()).isWithin(1e-6).of(1.3); assertThat(retrySettings.getMaxRetryDelay()).isEqualTo(Duration.ofMinutes(1L)); assertThat(retrySettings.getInitialRpcTimeout()).isEqualTo(Duration.ofDays(1L)); assertThat(retrySettings.getRpcTimeoutMultiplier()).isWithin(1e-6).of(1.0); assertThat(retrySettings.getMaxRpcTimeout()).isEqualTo(Duration.ofDays(1L)); assertThat(retrySettings.getTotalTimeout()).isEqualTo(Duration.ofDays(1L)); assertThat(builder.getIdleTimeout()).isEqualTo(Duration.ZERO); }
.bulkMutationsSettings() .getRetrySettings() .toBuilder() .setMaxAttempts(MAX_ATTEMPTS) .setInitialRetryDelay(Duration.ofMillis(10)) .setRetryDelayMultiplier(2) .setMaxRetryDelay(Duration.ofMillis(100)) .build()) .setBatchingSettings(
long newRetryDelay = settings.getInitialRetryDelay().toMillis(); if (prevSettings.getAttemptCount() > 0) { newRetryDelay = (long) (settings.getRetryDelayMultiplier() * prevSettings.getRetryDelay().toMillis()); newRetryDelay = Math.min(newRetryDelay, settings.getMaxRetryDelay().toMillis()); (long) (settings.getRpcTimeoutMultiplier() * prevSettings.getRpcTimeout().toMillis()); newRpcTimeout = Math.min(newRpcTimeout, settings.getMaxRpcTimeout().toMillis());
public RetrySettings build() { RetrySettings params = autoBuild(); if (params.getTotalTimeout().toMillis() < 0) { throw new IllegalStateException("total timeout must not be negative"); } if (params.getInitialRetryDelay().toMillis() < 0) { throw new IllegalStateException("initial retry delay must not be negative"); } if (params.getRetryDelayMultiplier() < 1.0) { throw new IllegalStateException("retry delay multiplier must be at least 1"); } if (params.getMaxRetryDelay().compareTo(params.getInitialRetryDelay()) < 0) { throw new IllegalStateException("max retry delay must not be shorter than initial delay"); } if (params.getMaxAttempts() < 0) { throw new IllegalStateException("max attempts must be non-negative"); } if (params.getInitialRpcTimeout().toMillis() < 0) { throw new IllegalStateException("initial rpc timeout must not be negative"); } if (params.getMaxRpcTimeout().compareTo(params.getInitialRpcTimeout()) < 0) { throw new IllegalStateException("max rpc timeout must not be shorter than initial timeout"); } if (params.getRpcTimeoutMultiplier() < 1.0) { throw new IllegalStateException("rpc timeout multiplier must be at least 1"); } return params; }
public Publisher getPublisherWithCustomRetrySettings(ProjectTopicName topicName) throws Exception { // [START pubsub_publisher_retry_settings] // Retry settings control how the publisher handles retryable failures Duration retryDelay = Duration.ofMillis(100); // default : 1 ms double retryDelayMultiplier = 2.0; // back off for repeated failures Duration maxRetryDelay = Duration.ofSeconds(5); // default : 10 seconds Duration totalTimeout = Duration.ofSeconds(1); // default: 0 Duration initialRpcTimeout = Duration.ofSeconds(1); // default: 0 Duration maxRpcTimeout = Duration.ofSeconds(10); // default: 0 RetrySettings retrySettings = RetrySettings.newBuilder() .setInitialRetryDelay(retryDelay) .setRetryDelayMultiplier(retryDelayMultiplier) .setMaxRetryDelay(maxRetryDelay) .setTotalTimeout(totalTimeout) .setInitialRpcTimeout(initialRpcTimeout) .setMaxRpcTimeout(maxRpcTimeout) .build(); Publisher publisher = Publisher.newBuilder(topicName).setRetrySettings(retrySettings).build(); // [END pubsub_publisher_retry_settings] return publisher; }
@Test public void retrySettingsMerge() { RetrySettings.Builder builder = RetrySettings.newBuilder() .setTotalTimeout(Duration.ofMillis(45000)) .setInitialRpcTimeout(Duration.ofMillis(2000)) .setRpcTimeoutMultiplier(1.5) .setMaxRpcTimeout(Duration.ofMillis(30000)) .setInitialRetryDelay(Duration.ofMillis(100)) .setRetryDelayMultiplier(1.2) .setMaxRetryDelay(Duration.ofMillis(1000)); RetrySettings.Builder mergedBuilder = RetrySettings.newBuilder(); mergedBuilder.merge(builder); RetrySettings settingsA = builder.build(); RetrySettings settingsB = mergedBuilder.build(); Truth.assertThat(settingsA.getTotalTimeout()).isEqualTo(settingsB.getTotalTimeout()); Truth.assertThat(settingsA.getInitialRetryDelay()).isEqualTo(settingsB.getInitialRetryDelay()); Truth.assertThat(settingsA.getRpcTimeoutMultiplier()) .isWithin(0) .of(settingsB.getRpcTimeoutMultiplier()); Truth.assertThat(settingsA.getMaxRpcTimeout()).isEqualTo(settingsB.getMaxRpcTimeout()); Truth.assertThat(settingsA.getInitialRetryDelay()).isEqualTo(settingsB.getInitialRetryDelay()); Truth.assertThat(settingsA.getRetryDelayMultiplier()) .isWithin(0) .of(settingsB.getRetryDelayMultiplier()); Truth.assertThat(settingsA.getMaxRetryDelay()).isEqualTo(settingsB.getMaxRetryDelay()); }
RetrySettings.newBuilder() .setMaxAttempts(10) .setTotalTimeout(Duration.ofHours(1)) .setInitialRpcTimeout(Duration.ofSeconds(10)) .setRpcTimeoutMultiplier(1) .setMaxRpcTimeout(Duration.ofSeconds(10)) .setJittered(true) .build();
private AwaitReplicationCallable createAwaitReplicationCallable() { // TODO(igorbernstein2): expose polling settings RetrySettings pollingSettings = RetrySettings.newBuilder() // use overall timeout from checkConsistencyCallable // NOTE: The overall timeout might exceed this value due to underlying retries .setTotalTimeout( settings.checkConsistencySettings().getRetrySettings().getTotalTimeout()) // Use constant polling with jitter .setInitialRetryDelay(Duration.ofSeconds(10)) .setRetryDelayMultiplier(1.0) .setMaxRetryDelay(Duration.ofSeconds(10)) .setJittered(true) // These rpc timeouts are ignored, instead the rpc timeouts defined for // generateConsistencyToken and checkConsistency callables will be used. .setInitialRpcTimeout(Duration.ZERO) .setMaxRpcTimeout(Duration.ZERO) .setRpcTimeoutMultiplier(1.0) .build(); return AwaitReplicationCallable.create( generateConsistencyTokenCallable(), checkConsistencyCallable(), clientContext, pollingSettings); }
@Test public void testMergeToSettings() { RetrySettings defRetrySettings = RetrySettings.newBuilder().build(); defRetrySettings.toBuilder().setTotalTimeout(Duration.ofMillis(420L)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, TOTAL_TIMEOUT); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings.toBuilder().setMaxRetryDelay(Duration.ofMillis(100)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, MAX_RETRY_DELAY); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings.toBuilder().setInitialRetryDelay(Duration.ofMillis(42L)).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, INITIAL_RETRY_DELAY); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = defRetrySettings.toBuilder().setRetryDelayMultiplier(1.5).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, RETRY_DELAY_MULTIPLIER); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = defRetrySettings.toBuilder().setMaxAttempts(100).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, MAX_ATTEMPTS); assertEquals(defRetrySettings, mergedRetrySettings); defRetrySettings = defRetrySettings.toBuilder().setJittered(false).build(); mergedRetrySettings = RetryOption.mergeToSettings(defRetrySettings, JITTERED); assertEquals(defRetrySettings, mergedRetrySettings);
OperationTimedPollAlgorithm.create( FAST_RECHECKING_SETTINGS .toBuilder() .setInitialRpcTimeout(Duration.ofMillis(100)) .setMaxRpcTimeout(Duration.ofSeconds(1)) .setRpcTimeoutMultiplier(2) .build(), clock); Lists.newArrayList(Duration.ofMillis(100), Duration.ofMillis(200), Duration.ofMillis(400)); assertThat(actualTimeouts).isEqualTo(expectedTimeouts);
RetrySettings.newBuilder() .setMaxAttempts(10) .setTotalTimeout(Duration.ofHours(1)) .setInitialRpcTimeout(Duration.ofSeconds(10)) .setRpcTimeoutMultiplier(1) .setMaxRpcTimeout(Duration.ofSeconds(10)) .setJittered(true) .build();
@Test(expected = ExecutionException.class) public void testPublishFailureRetries_retriesDisabled() throws Exception { Publisher publisher = getTestPublisherBuilder() .setExecutorProvider(SINGLE_THREAD_EXECUTOR) .setRetrySettings( Publisher.Builder.DEFAULT_RETRY_SETTINGS .toBuilder() .setTotalTimeout(Duration.ofSeconds(10)) .setMaxAttempts(1) .build()) .build(); testPublisherServiceImpl.addPublishError(new Throwable("Transiently failing")); ApiFuture<String> publishFuture1 = sendTestMessage(publisher, "A"); try { publishFuture1.get(); } finally { assertSame(testPublisherServiceImpl.getCapturedRequests().size(), 1); publisher.shutdown(); publisher.awaitTermination(1, TimeUnit.MINUTES); } }
MockRetryingFuture(Duration totalTimeout) { this.timedAttemptSettings = TimedAttemptSettings.newBuilder() .setRpcTimeout(Duration.ofSeconds(1)) .setRetryDelay(Duration.ZERO) .setRandomizedRetryDelay(Duration.ZERO) .setAttemptCount(0) .setFirstAttemptStartTimeNanos(0) .setGlobalSettings(RetrySettings.newBuilder().setTotalTimeout(totalTimeout).build()) .build(); }
@Override protected StorageOptions getServiceOptions(ProcessContext context, GoogleCredentials credentials) { final String projectId = context.getProperty(PROJECT_ID).evaluateAttributeExpressions().getValue(); final Integer retryCount = context.getProperty(RETRY_COUNT).asInteger(); StorageOptions.Builder storageOptionsBuilder = StorageOptions.newBuilder() .setCredentials(credentials) .setRetrySettings(RetrySettings.newBuilder() .setMaxAttempts(retryCount) .build()); if (!projectId.isEmpty()) { storageOptionsBuilder.setProjectId(projectId); } return storageOptionsBuilder.setTransportOptions(getTransportOptions(context)).build(); } }
protected Long getNextBackoff() { if (currentBackoff == null) { // Historically, the client waited for "total timeout" after the first failure. For now, // that behavior is preserved, even though that's not the ideal. // // TODO: Think through retries, and create policy that works with the mental model most // users would have of relating to retries. That would likely involve updating some // default settings in addition to changing the algorithm. currentBackoff = exponentialRetryAlgorithm.createFirstAttempt(); } currentBackoff = exponentialRetryAlgorithm.createNextAttempt(currentBackoff); if (!exponentialRetryAlgorithm.shouldRetry(currentBackoff)) { // TODO: consider creating a subclass of exponentialRetryAlgorithm to encapsulate this logic long timeLeftNs = currentBackoff.getGlobalSettings().getTotalTimeout().toNanos() - (clock.nanoTime() - currentBackoff.getFirstAttemptStartTimeNanos()); long timeLeftMs = TimeUnit.NANOSECONDS.toMillis(timeLeftNs); if (timeLeftMs > currentBackoff.getGlobalSettings().getInitialRetryDelay().toMillis()) { // The backoff algorithm doesn't always wait until the timeout is achieved. Wait // one final time so that retries hit return timeLeftMs; } else { // Finish for real. return null; } } else { return currentBackoff.getRetryDelay().toMillis(); } }