use of com.google.bigtable.v2.MutateRowsRequest in project java-bigtable by googleapis.
the class EnhancedBigtableStub method createBulkMutateRowsCallable.
/**
* Creates a callable chain to handle MutatesRows RPCs. This is meant to be used for manual
* batching. The chain will:
*
* <ul>
* <li>Convert a {@link BulkMutation} into a {@link MutateRowsRequest}.
* <li>Process the response and schedule retries. At the end of each attempt, entries that have
* been applied, are filtered from the next attempt. Also, any entries that failed with a
* nontransient error, are filtered from the next attempt. This will continue until there
* are no more entries or there are no more retry attempts left.
* <li>Wrap batch failures in a {@link
* com.google.cloud.bigtable.data.v2.models.MutateRowsException}.
* <li>Add tracing & metrics.
* </ul>
*/
private UnaryCallable<BulkMutation, Void> createBulkMutateRowsCallable() {
UnaryCallable<MutateRowsRequest, Void> baseCallable = createMutateRowsBaseCallable();
UnaryCallable<MutateRowsRequest, Void> flowControlCallable = null;
if (settings.bulkMutateRowsSettings().isLatencyBasedThrottlingEnabled()) {
flowControlCallable = new DynamicFlowControlCallable(baseCallable, bulkMutationFlowController, bulkMutationDynamicFlowControlStats, settings.bulkMutateRowsSettings().getTargetRpcLatencyMs(), FLOW_CONTROL_ADJUSTING_INTERVAL_MS);
}
UnaryCallable<BulkMutation, Void> userFacing = new BulkMutateRowsUserFacingCallable(flowControlCallable != null ? flowControlCallable : baseCallable, requestContext);
SpanName spanName = getSpanName("MutateRows");
UnaryCallable<BulkMutation, Void> tracedBatcher = new TracedBatcherUnaryCallable<>(userFacing);
UnaryCallable<BulkMutation, Void> withHeaderTracer = new HeaderTracerUnaryCallable<>(tracedBatcher);
UnaryCallable<BulkMutation, Void> traced = new TracedUnaryCallable<>(withHeaderTracer, clientContext.getTracerFactory(), spanName);
return traced.withDefaultCallContext(clientContext.getDefaultCallContext());
}
use of com.google.bigtable.v2.MutateRowsRequest 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());
}
use of com.google.bigtable.v2.MutateRowsRequest in project java-bigtable by googleapis.
the class RowMutationTest method toBulkProtoTest.
@Test
public void toBulkProtoTest() {
long timestampMin = System.currentTimeMillis() * 1_000;
RowMutation rowMutation = RowMutation.create("fake-table", "fake-key").setCell("fake-family", "fake-qualifier", "fake-value");
MutateRowsRequest actualRowMutation = rowMutation.toBulkProto(REQUEST_CONTEXT);
com.google.common.collect.Range<Long> timestampRange = com.google.common.collect.Range.closed(timestampMin, System.currentTimeMillis() * 1_000);
assertThat(actualRowMutation.getTableName()).isEqualTo(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID));
assertThat(actualRowMutation.getAppProfileId()).isEqualTo(APP_PROFILE_ID);
assertThat(actualRowMutation.getEntriesList()).hasSize(1);
assertThat(actualRowMutation.getEntries(0).getMutationsList()).hasSize(1);
assertThat(actualRowMutation.getEntries(0).getMutations(0).getSetCell().getValue()).isEqualTo(ByteString.copyFromUtf8("fake-value"));
assertThat(actualRowMutation.getEntries(0).getMutations(0).getSetCell().getTimestampMicros()).isIn(timestampRange);
}
use of com.google.bigtable.v2.MutateRowsRequest in project java-bigtable by googleapis.
the class MutateRowsAttemptCallableTest method singleEntrySuccessTest.
@Test
public void singleEntrySuccessTest() throws Exception {
MutateRowsRequest request = MutateRowsRequest.newBuilder().addEntries(Entry.getDefaultInstance()).build();
innerCallable.response.add(MutateRowsResponse.newBuilder().addEntries(MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(OK_STATUS_PROTO)).build());
MutateRowsAttemptCallable attemptCallable = new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes);
attemptCallable.setExternalFuture(parentFuture);
attemptCallable.call();
// Attempt completed successfully and the useless response has been suppressed
assertThat(parentFuture.attemptFuture.get()).isNull();
// innerCallable received the request
assertThat(innerCallable.lastRequest).isEqualTo(request);
}
use of com.google.bigtable.v2.MutateRowsRequest in project java-bigtable by googleapis.
the class MutateRowsAttemptCallableTest method mixedTest.
@Test
public void mixedTest() {
// Setup the request & response
MutateRowsRequest request = MutateRowsRequest.newBuilder().addEntries(Entry.getDefaultInstance()).addEntries(Entry.getDefaultInstance()).addEntries(Entry.getDefaultInstance()).build();
innerCallable.response.add(MutateRowsResponse.newBuilder().addEntries(MutateRowsResponse.Entry.newBuilder().setIndex(0).setStatus(OK_STATUS_PROTO)).addEntries(MutateRowsResponse.Entry.newBuilder().setIndex(1).setStatus(TRANSIENT_ERROR_STATUS_PROTO)).addEntries(MutateRowsResponse.Entry.newBuilder().setIndex(2).setStatus(PERMENANT_ERROR_STATUS_PROTO)).build());
MutateRowsAttemptCallable attemptCallable = new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes);
attemptCallable.setExternalFuture(parentFuture);
// Make the only call
attemptCallable.call();
// Overall error expectations
Throwable actualError = null;
try {
parentFuture.attemptFuture.get();
} catch (Throwable t) {
actualError = t.getCause();
}
assertThat(actualError).isInstanceOf(MutateRowsException.class);
assertThat(((MutateRowsException) actualError).isRetryable()).isTrue();
// Entry expectations
@SuppressWarnings("ConstantConditions") List<FailedMutation> failedMutations = ((MutateRowsException) actualError).getFailedMutations();
assertThat(failedMutations).hasSize(2);
assertThat(failedMutations.get(0).getIndex()).isEqualTo(1);
assertThat(failedMutations.get(0).getError().getStatusCode().getCode()).isEqualTo(Code.UNAVAILABLE);
assertThat(failedMutations.get(0).getError().isRetryable()).isTrue();
assertThat(failedMutations.get(1).getIndex()).isEqualTo(2);
assertThat(failedMutations.get(1).getError().getStatusCode().getCode()).isEqualTo(Code.INVALID_ARGUMENT);
assertThat(failedMutations.get(1).getError().isRetryable()).isFalse();
}
Aggregations