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(); }
@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(); } }
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; }
.bulkMutationsSettings() .getRetrySettings() .toBuilder() .setMaxAttempts(MAX_ATTEMPTS) .setInitialRetryDelay(Duration.ofMillis(10)) .setRetryDelayMultiplier(2) .setMaxRetryDelay(Duration.ofMillis(100)) .build()) .setBatchingSettings( settings
@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);
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(); }
FakeRetryingFuture(ServerStreamingAttemptCallable<String, String> attemptCallable) { this.attemptCallable = attemptCallable; attemptSettings = TimedAttemptSettings.newBuilder() .setGlobalSettings( RetrySettings.newBuilder().setTotalTimeout(Duration.ofHours(1)).build()) .setFirstAttemptStartTimeNanos(0) .setAttemptCount(0) .setOverallAttemptCount(0) .setRandomizedRetryDelay(Duration.ofMillis(1)) .setRetryDelay(Duration.ofMillis(1)) .setRpcTimeout(Duration.ofMinutes(1)) .build(); }
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); } }
Publisher.Builder.DEFAULT_BATCHING_SETTINGS .toBuilder() .setDelayThreshold(Duration.ofMillis(1)) .build()); try { .toBuilder() .setInitialRpcTimeout(Publisher.Builder.MIN_RPC_TIMEOUT) .build()); try { builder.setRetrySettings( Publisher.Builder.DEFAULT_RETRY_SETTINGS .toBuilder() .setInitialRpcTimeout(Publisher.Builder.MIN_RPC_TIMEOUT.minusMillis(1)) .build()); fail("Should have thrown an IllegalArgumentException"); } catch (IllegalArgumentException expected) { .toBuilder() .setTotalTimeout(Publisher.Builder.MIN_TOTAL_TIMEOUT) .build()); try { builder.setRetrySettings( .setTotalTimeout(Publisher.Builder.MIN_TOTAL_TIMEOUT.minusMillis(1)) .build()); fail("Should have thrown an IllegalArgumentException"); } catch (IllegalArgumentException expected) {
/** * <p>createBackoff.</p> * * @return a {@link ExponentialRetryAlgorithm} object. */ private ExponentialRetryAlgorithm createRetryAlgorithm(ApiClock clock) { long timeoutMs = retryOptions.getMaxElapsedBackoffMillis(); Deadline deadline = getOperationCallOptions().getDeadline(); if (deadline != null) { timeoutMs = deadline.timeRemaining(TimeUnit.MILLISECONDS); } RetrySettings retrySettings = RetrySettings.newBuilder() .setJittered(true) // How long should the sleep be between RPC failure and the next RPC retry? .setInitialRetryDelay(toDuration(retryOptions.getInitialBackoffMillis())) // How fast should the retry delay increase? .setRetryDelayMultiplier(retryOptions.getBackoffMultiplier()) // What is the maximum amount of sleep time between retries? // There needs to be some sane number for max retry delay, and it's unclear what that // number ought to be. 1 Minute time was chosen because some number is needed. .setMaxRetryDelay(Duration.of(1, ChronoUnit.MINUTES)) // How long should we wait before giving up retries after the first failure? .setTotalTimeout(toDuration(timeoutMs)) .build(); return new ExponentialRetryAlgorithm(retrySettings, clock); }
if (retrySettings.getMaxAttempts() == 0) { retrySettings = retrySettings.toBuilder().setMaxAttempts(Integer.MAX_VALUE).build();
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: builder.setMaxRetryDelay((Duration) option.value); break; case MAX_ATTEMPTS: builder.setMaxAttempts((Integer) option.value); break; case JITTERED: builder.setJittered((Boolean) option.value); break; default: return builder.build();
public static Builder newBuilder() { return new AutoValue_RetrySettings.Builder() .setTotalTimeout(Duration.ZERO) .setInitialRetryDelay(Duration.ZERO) .setRetryDelayMultiplier(1.0) .setMaxRetryDelay(Duration.ZERO) .setMaxAttempts(0) .setJittered(true) .setInitialRpcTimeout(Duration.ZERO) .setRpcTimeoutMultiplier(1.0) .setMaxRpcTimeout(Duration.ZERO); }
public static Builder newBuilder() { return new AutoValue_RetrySettings.Builder() .setTotalTimeout(Duration.ZERO) .setInitialRetryDelay(Duration.ZERO) .setRetryDelayMultiplier(1.0) .setMaxRetryDelay(Duration.ZERO) .setMaxAttempts(0) .setJittered(true) .setInitialRpcTimeout(Duration.ZERO) .setRpcTimeoutMultiplier(1.0) .setMaxRpcTimeout(Duration.ZERO); }
public RetrySettings.Builder merge(RetrySettings.Builder newSettings) { if (newSettings.getTotalTimeout() != null) { setTotalTimeout(newSettings.getTotalTimeout()); } if (newSettings.getInitialRetryDelay() != null) { setInitialRetryDelay(newSettings.getInitialRetryDelay()); } if (newSettings.getRetryDelayMultiplier() >= 1) { setRetryDelayMultiplier(newSettings.getRetryDelayMultiplier()); } if (newSettings.getMaxRetryDelay() != null) { setMaxRetryDelay(newSettings.getMaxRetryDelay()); } setMaxAttempts(newSettings.getMaxAttempts()); setJittered(newSettings.isJittered()); if (newSettings.getInitialRpcTimeout() != null) { setInitialRpcTimeout(newSettings.getInitialRpcTimeout()); } if (newSettings.getRpcTimeoutMultiplier() >= 1) { setRpcTimeoutMultiplier(newSettings.getRpcTimeoutMultiplier()); } if (newSettings.getMaxRpcTimeout() != null) { setMaxRpcTimeout(newSettings.getMaxRpcTimeout()); } return this; } }
public RetrySettings.Builder merge(RetrySettings.Builder newSettings) { if (newSettings.getTotalTimeout() != null) { setTotalTimeout(newSettings.getTotalTimeout()); } if (newSettings.getInitialRetryDelay() != null) { setInitialRetryDelay(newSettings.getInitialRetryDelay()); } if (newSettings.getRetryDelayMultiplier() >= 1) { setRetryDelayMultiplier(newSettings.getRetryDelayMultiplier()); } if (newSettings.getMaxRetryDelay() != null) { setMaxRetryDelay(newSettings.getMaxRetryDelay()); } setMaxAttempts(newSettings.getMaxAttempts()); setJittered(newSettings.isJittered()); if (newSettings.getInitialRpcTimeout() != null) { setInitialRpcTimeout(newSettings.getInitialRpcTimeout()); } if (newSettings.getRpcTimeoutMultiplier() >= 1) { setRpcTimeoutMultiplier(newSettings.getRpcTimeoutMultiplier()); } if (newSettings.getMaxRpcTimeout() != null) { setMaxRpcTimeout(newSettings.getMaxRpcTimeout()); } return this; } }