public static <V> V runWithRetries( Callable<V> callable, RetrySettings retrySettings, ResultRetryAlgorithm<?> resultRetryAlgorithm, ApiClock clock) throws RetryHelperException { try { // Suppressing should be ok as a workaraund. Current and only ResultRetryAlgorithm // implementation does not use response at all, so ignoring its type is ok. @SuppressWarnings("unchecked") ResultRetryAlgorithm<V> algorithm = (ResultRetryAlgorithm<V>) resultRetryAlgorithm; return run(callable, new ExponentialRetryAlgorithm(retrySettings, clock), algorithm); } catch (Exception e) { // TODO: remove RetryHelperException, throw InterruptedException or // ExecutionException#getCause() explicitly throw new RetryHelperException(e.getCause()); } }
/** * @param firestore The Firestore Database client. * @param query The query that is used to order the document snapshots returned by this watch. * @param target A Firestore 'Target' proto denoting the target to listen on. */ private Watch(FirestoreImpl firestore, Query query, Target target) { this.firestore = firestore; this.target = target; this.query = query; this.comparator = query.comparator(); this.backoff = new ExponentialRetryAlgorithm(RETRY_SETTINGS, CurrentMillisClock.getDefaultClock()); this.firestoreExecutor = firestore.getClient().getExecutor(); this.isActive = new AtomicBoolean(); this.nextAttempt = backoff.createFirstAttempt(); }
/** * 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()); }
public static <V> V runWithRetries( Callable<V> callable, RetrySettings retrySettings, ResultRetryAlgorithm<?> resultRetryAlgorithm, ApiClock clock) throws RetryHelperException { try { // Suppressing should be ok as a workaraund. Current and only ResultRetryAlgorithm // implementation does not use response at all, so ignoring its type is ok. @SuppressWarnings("unchecked") ResultRetryAlgorithm<V> algorithm = (ResultRetryAlgorithm<V>) resultRetryAlgorithm; return run(callable, new ExponentialRetryAlgorithm(retrySettings, clock), algorithm); } catch (Exception e) { // TODO: remove RetryHelperException, throw InterruptedException or // ExecutionException#getCause() explicitly throw new RetryHelperException(e.getCause()); } }
/** * @param firestore The Firestore Database client. * @param query The query that is used to order the document snapshots returned by this watch. * @param target A Firestore 'Target' proto denoting the target to listen on. */ private Watch(FirestoreImpl firestore, Query query, Target target) { this.firestore = firestore; this.target = target; this.query = query; this.comparator = query.comparator(); this.backoff = new ExponentialRetryAlgorithm(RETRY_SETTINGS, CurrentMillisClock.getDefaultClock()); this.firestoreExecutor = firestore.getClient().getExecutor(); this.isActive = new AtomicBoolean(); this.nextAttempt = backoff.createFirstAttempt(); }
@Override protected RetryAlgorithm<String> getAlgorithm( RetrySettings retrySettings, int apocalypseCountDown, RuntimeException apocalypseException) { return new RetryAlgorithm<>( new TestResultRetryAlgorithm<String>(apocalypseCountDown, apocalypseException), new ExponentialRetryAlgorithm(retrySettings, CurrentMillisClock.getDefaultClock())); } }
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, NanoClock.getDefaultClock())); }
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); }
@BetaApi("The surface for streaming is not stable yet and may change in the future.") public static <RequestT, ResponseT> ServerStreamingCallable<RequestT, ResponseT> retrying( ServerStreamingCallable<RequestT, ResponseT> innerCallable, ServerStreamingCallSettings<RequestT, ResponseT> callSettings, ClientContext clientContext) { if (callSettings.getRetryableCodes().isEmpty()) { return innerCallable; } StreamingRetryAlgorithm<Void> retryAlgorithm = new StreamingRetryAlgorithm<>( new ApiResultRetryAlgorithm<Void>(), new ExponentialRetryAlgorithm( callSettings.getRetrySettings(), clientContext.getClock())); ScheduledRetryingExecutor<Void> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); return new RetryingServerStreamingCallable<>( innerCallable, retryingExecutor, callSettings.getResumptionStrategy()); }
@BetaApi("The surface for streaming is not stable yet and may change in the future.") public static <RequestT, ResponseT> ServerStreamingCallable<RequestT, ResponseT> retrying( ServerStreamingCallable<RequestT, ResponseT> innerCallable, ServerStreamingCallSettings<RequestT, ResponseT> callSettings, ClientContext clientContext) { if (callSettings.getRetryableCodes().isEmpty()) { return innerCallable; } StreamingRetryAlgorithm<Void> retryAlgorithm = new StreamingRetryAlgorithm<>( new ApiResultRetryAlgorithm<Void>(), new ExponentialRetryAlgorithm( callSettings.getRetrySettings(), clientContext.getClock())); ScheduledRetryingExecutor<Void> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor()); return new RetryingServerStreamingCallable<>( innerCallable, retryingExecutor, callSettings.getResumptionStrategy()); }
/** * 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()); }
/** * <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); }