private static <V> V run( Callable<V> callable, TimedRetryAlgorithm timedAlgorithm, ResultRetryAlgorithm<V> resultAlgorithm) throws ExecutionException, InterruptedException { RetryAlgorithm<V> retryAlgorithm = new RetryAlgorithm<>(resultAlgorithm, timedAlgorithm); RetryingExecutor<V> executor = new DirectRetryingExecutor<>(retryAlgorithm); RetryingFuture<V> retryingFuture = executor.createFuture(callable); executor.submit(retryingFuture); return retryingFuture.get(); }
static AwaitReplicationCallable create( UnaryCallable<GenerateConsistencyTokenRequest, GenerateConsistencyTokenResponse> generateCallable, UnaryCallable<CheckConsistencyRequest, CheckConsistencyResponse> checkCallable, ClientContext clientContext, RetrySettings pollingSettings) { RetryAlgorithm<CheckConsistencyResponse> retryAlgorithm = new RetryAlgorithm<>( new PollResultAlgorithm(), new ExponentialPollAlgorithm(pollingSettings, clientContext.getClock())); RetryingExecutor<CheckConsistencyResponse> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); return new AwaitReplicationCallable(generateCallable, checkCallable, retryingExecutor); }
/** * Internal helper to create the base MutateRows callable chain. The chain is responsible for * retrying individual entry in case of error. * * @see MutateRowsRetryingCallable for more details */ private UnaryCallable<MutateRowsRequest, Void> createMutateRowsBaseCallable() { RetryAlgorithm<Void> retryAlgorithm = new RetryAlgorithm<>( new ApiResultRetryAlgorithm<Void>(), new ExponentialRetryAlgorithm( settings.bulkMutateRowsSettings().getRetrySettings(), clientContext.getClock())); RetryingExecutor<Void> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); return new MutateRowsRetryingCallable( clientContext.getDefaultCallContext(), stub.mutateRowsCallable(), retryingExecutor, settings.bulkMutateRowsSettings().getRetryableCodes()); }
private static <V> V run( Callable<V> callable, TimedRetryAlgorithm timedAlgorithm, ResultRetryAlgorithm<V> resultAlgorithm) throws ExecutionException, InterruptedException { RetryAlgorithm<V> retryAlgorithm = new RetryAlgorithm<>(resultAlgorithm, timedAlgorithm); RetryingExecutor<V> executor = new DirectRetryingExecutor<>(retryAlgorithm); RetryingFuture<V> retryingFuture = executor.createFuture(callable); executor.submit(retryingFuture); return retryingFuture.get(); }
static <RequestT, ResponseT, MetadataT> OperationCallableImpl<RequestT, ResponseT, MetadataT> longRunningOperationImpl( UnaryCallable<RequestT, OperationSnapshot> initialCallable, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings, ClientContext clientContext, LongRunningClient longRunningClient) { RetryAlgorithm<OperationSnapshot> pollingAlgorithm = new RetryAlgorithm<>( new OperationResponsePollAlgorithm(), operationCallSettings.getPollingAlgorithm()); ScheduledRetryingExecutor<OperationSnapshot> scheduler = new ScheduledRetryingExecutor<>(pollingAlgorithm, clientContext.getExecutor()); return new OperationCallableImpl<>( initialCallable, scheduler, longRunningClient, operationCallSettings); } }
static <RequestT, ResponseT, MetadataT> OperationCallableImpl<RequestT, ResponseT, MetadataT> longRunningOperationImpl( UnaryCallable<RequestT, OperationSnapshot> initialCallable, OperationCallSettings<RequestT, ResponseT, MetadataT> operationCallSettings, ClientContext clientContext, LongRunningClient longRunningClient) { RetryAlgorithm<OperationSnapshot> pollingAlgorithm = new RetryAlgorithm<>( new OperationResponsePollAlgorithm(), operationCallSettings.getPollingAlgorithm()); ScheduledRetryingExecutor<OperationSnapshot> scheduler = new ScheduledRetryingExecutor<>(pollingAlgorithm, clientContext.getExecutor()); return new OperationCallableImpl<>( initialCallable, scheduler, longRunningClient, operationCallSettings); } }
static AwaitReplicationCallable create( UnaryCallable<GenerateConsistencyTokenRequest, GenerateConsistencyTokenResponse> generateCallable, UnaryCallable<CheckConsistencyRequest, CheckConsistencyResponse> checkCallable, ClientContext clientContext, RetrySettings pollingSettings) { RetryAlgorithm<CheckConsistencyResponse> retryAlgorithm = new RetryAlgorithm<>( new PollResultAlgorithm(), new ExponentialPollAlgorithm(pollingSettings, clientContext.getClock())); RetryingExecutor<CheckConsistencyResponse> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); return new AwaitReplicationCallable(generateCallable, checkCallable, retryingExecutor); }
public static <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> retrying( UnaryCallable<RequestT, ResponseT> innerCallable, UnaryCallSettings<?, ?> callSettings, ClientContext clientContext) { if (callSettings.getRetryableCodes().isEmpty()) { return innerCallable; } RetryAlgorithm<ResponseT> retryAlgorithm = new RetryAlgorithm<>( new ApiResultRetryAlgorithm<ResponseT>(), new ExponentialRetryAlgorithm( callSettings.getRetrySettings(), clientContext.getClock())); ScheduledRetryingExecutor<ResponseT> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); return new RetryingCallable<>( clientContext.getDefaultCallContext(), innerCallable, retryingExecutor); }
public static <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> retrying( UnaryCallable<RequestT, ResponseT> innerCallable, UnaryCallSettings<?, ?> callSettings, ClientContext clientContext) { if (callSettings.getRetryableCodes().isEmpty()) { return innerCallable; } RetryAlgorithm<ResponseT> retryAlgorithm = new RetryAlgorithm<>( new ApiResultRetryAlgorithm<ResponseT>(), new ExponentialRetryAlgorithm( callSettings.getRetrySettings(), clientContext.getClock())); ScheduledRetryingExecutor<ResponseT> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); return new RetryingCallable<>( clientContext.getDefaultCallContext(), innerCallable, retryingExecutor); }
@Override protected RetryAlgorithm<String> getAlgorithm( RetrySettings retrySettings, int apocalypseCountDown, RuntimeException apocalypseException) { return new RetryAlgorithm<>( new TestResultRetryAlgorithm<String>(apocalypseCountDown, apocalypseException), new ExponentialRetryAlgorithm(retrySettings, CurrentMillisClock.getDefaultClock())); } }
@Override protected RetryAlgorithm<String> getAlgorithm( RetrySettings retrySettings, int apocalypseCountDown, RuntimeException apocalypseException) { return new RetryAlgorithm<>( new TestResultRetryAlgorithm<String>(apocalypseCountDown, apocalypseException), new ExponentialRetryAlgorithm(retrySettings, NanoClock.getDefaultClock())); }
@Test public void testPollExceptionByPollAlgorithm() throws Exception { RetrySettings retrySettings = FAST_RETRY_SETTINGS .toBuilder() .setInitialRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) .setMaxRetryDelay(Duration.ofMillis(Integer.MAX_VALUE)) .build(); RetryAlgorithm<String> retryAlgorithm = new RetryAlgorithm<>( new TestResultRetryAlgorithm<String>(0, null), new ExponentialPollAlgorithm(retrySettings, NanoClock.getDefaultClock())); RetryingExecutorWithContext<String> executor = getExecutor(retryAlgorithm); FailingCallable callable = new FailingCallable(6, "FAILURE", tracer); RetryingFuture<String> future = executor.createFuture(callable, retryingContext); future.setAttemptFuture(executor.submit(future)); assertFutureFail(future, PollException.class); assertTrue(future.getAttemptSettings().getAttemptCount() < 4); verify(tracer, times(1)).attemptStarted(anyInt()); verify(tracer, times(1)).attemptPermanentFailure(any(PollException.class)); verifyNoMoreInteractions(tracer); }
/** * Internal helper to create the base MutateRows callable chain. The chain is responsible for * retrying individual entry in case of error. * * @see MutateRowsRetryingCallable for more details */ private UnaryCallable<MutateRowsRequest, Void> createMutateRowsBaseCallable() { RetryAlgorithm<Void> retryAlgorithm = new RetryAlgorithm<>( new ApiResultRetryAlgorithm<Void>(), new ExponentialRetryAlgorithm( settings.bulkMutateRowsSettings().getRetrySettings(), clientContext.getClock())); RetryingExecutor<Void> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); return new MutateRowsRetryingCallable( clientContext.getDefaultCallContext(), stub.mutateRowsCallable(), retryingExecutor, settings.bulkMutateRowsSettings().getRetryableCodes()); }