Search in sources :

Example 1 with RetryAlgorithm

use of com.google.api.gax.retrying.RetryAlgorithm 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 RetryAlgorithm

use of com.google.api.gax.retrying.RetryAlgorithm 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)

Example 3 with RetryAlgorithm

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

the class AwaitReplicationCallable method create.

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);
}
Also used : ScheduledRetryingExecutor(com.google.api.gax.retrying.ScheduledRetryingExecutor) CheckConsistencyResponse(com.google.bigtable.admin.v2.CheckConsistencyResponse) RetryAlgorithm(com.google.api.gax.retrying.RetryAlgorithm) ResultRetryAlgorithm(com.google.api.gax.retrying.ResultRetryAlgorithm) ExponentialPollAlgorithm(com.google.api.gax.retrying.ExponentialPollAlgorithm)

Aggregations

RetryAlgorithm (com.google.api.gax.retrying.RetryAlgorithm)3 ExponentialRetryAlgorithm (com.google.api.gax.retrying.ExponentialRetryAlgorithm)2 ScheduledRetryingExecutor (com.google.api.gax.retrying.ScheduledRetryingExecutor)2 DirectRetryingExecutor (com.google.api.gax.retrying.DirectRetryingExecutor)1 ExponentialPollAlgorithm (com.google.api.gax.retrying.ExponentialPollAlgorithm)1 ResultRetryAlgorithm (com.google.api.gax.retrying.ResultRetryAlgorithm)1 CheckConsistencyResponse (com.google.bigtable.admin.v2.CheckConsistencyResponse)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