Search in sources :

Example 1 with ExponentialRetryAlgorithm

use of com.google.api.gax.retrying.ExponentialRetryAlgorithm in project google-cloud-java by GoogleCloudPlatform.

the class RetryHelper method runWithRetries.

public static <V> V runWithRetries(Callable<V> callable, RetrySettings retrySettings, ExceptionHandler exceptionRetryAlgorithm, ApiClock clock) throws RetryHelperException {
    try {
        RetryAlgorithm retryAlgorithm = new RetryAlgorithm(exceptionRetryAlgorithm, new ExponentialRetryAlgorithm(retrySettings, clock));
        RetryingExecutor<V> executor = new DirectRetryingExecutor<>(retryAlgorithm);
        RetryingFuture<V> retryingFuture = executor.createFuture(callable);
        executor.submit(retryingFuture);
        return retryingFuture.get();
    } catch (Exception e) {
        throw new RetryHelperException(e.getCause());
    }
}
Also used : DirectRetryingExecutor(com.google.api.gax.retrying.DirectRetryingExecutor) RetryAlgorithm(com.google.api.gax.retrying.RetryAlgorithm) ExponentialRetryAlgorithm(com.google.api.gax.retrying.ExponentialRetryAlgorithm) ExponentialRetryAlgorithm(com.google.api.gax.retrying.ExponentialRetryAlgorithm)

Example 2 with ExponentialRetryAlgorithm

use of com.google.api.gax.retrying.ExponentialRetryAlgorithm in project java-bigtable by googleapis.

the class EnhancedBigtableStub method createMutateRowsBaseCallable.

/**
 * Internal helper to create the base MutateRows callable chain. The chain is responsible for
 * retrying individual entry in case of error.
 *
 * <p>NOTE: the caller is responsible for adding tracing & metrics.
 *
 * @see MutateRowsRetryingCallable for more details
 */
private UnaryCallable<MutateRowsRequest, Void> createMutateRowsBaseCallable() {
    ServerStreamingCallable<MutateRowsRequest, MutateRowsResponse> base = GrpcRawCallableFactory.createServerStreamingCallable(GrpcCallSettings.<MutateRowsRequest, MutateRowsResponse>newBuilder().setMethodDescriptor(BigtableGrpc.getMutateRowsMethod()).setParamsExtractor(new RequestParamsExtractor<MutateRowsRequest>() {

        @Override
        public Map<String, String> extract(MutateRowsRequest mutateRowsRequest) {
            return ImmutableMap.of("table_name", mutateRowsRequest.getTableName(), "app_profile_id", mutateRowsRequest.getAppProfileId());
        }
    }).build(), settings.bulkMutateRowsSettings().getRetryableCodes());
    ServerStreamingCallable<MutateRowsRequest, MutateRowsResponse> withStatsHeaders = new StatsHeadersServerStreamingCallable<>(base);
    RetryAlgorithm<Void> retryAlgorithm = new RetryAlgorithm<>(new ApiResultRetryAlgorithm<Void>(), new ExponentialRetryAlgorithm(settings.bulkMutateRowsSettings().getRetrySettings(), clientContext.getClock()));
    RetryingExecutorWithContext<Void> retryingExecutor = new ScheduledRetryingExecutor<>(retryAlgorithm, clientContext.getExecutor());
    return new MutateRowsRetryingCallable(clientContext.getDefaultCallContext(), withStatsHeaders, retryingExecutor, settings.bulkMutateRowsSettings().getRetryableCodes());
}
Also used : RetryAlgorithm(com.google.api.gax.retrying.RetryAlgorithm) ExponentialRetryAlgorithm(com.google.api.gax.retrying.ExponentialRetryAlgorithm) ApiResultRetryAlgorithm(com.google.cloud.bigtable.gaxx.retrying.ApiResultRetryAlgorithm) ExponentialRetryAlgorithm(com.google.api.gax.retrying.ExponentialRetryAlgorithm) StatsHeadersServerStreamingCallable(com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersServerStreamingCallable) ScheduledRetryingExecutor(com.google.api.gax.retrying.ScheduledRetryingExecutor) MutateRowsResponse(com.google.bigtable.v2.MutateRowsResponse) MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) MutateRowsRetryingCallable(com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsRetryingCallable)

Aggregations

ExponentialRetryAlgorithm (com.google.api.gax.retrying.ExponentialRetryAlgorithm)2 RetryAlgorithm (com.google.api.gax.retrying.RetryAlgorithm)2 DirectRetryingExecutor (com.google.api.gax.retrying.DirectRetryingExecutor)1 ScheduledRetryingExecutor (com.google.api.gax.retrying.ScheduledRetryingExecutor)1 MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)1 MutateRowsResponse (com.google.bigtable.v2.MutateRowsResponse)1 StatsHeadersServerStreamingCallable (com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersServerStreamingCallable)1 MutateRowsRetryingCallable (com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsRetryingCallable)1 ApiResultRetryAlgorithm (com.google.cloud.bigtable.gaxx.retrying.ApiResultRetryAlgorithm)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1