Search in sources :

Example 1 with Entry

use of com.google.bigtable.v2.MutateRowsResponse.Entry 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 2 with Entry

use of com.google.bigtable.v2.MutateRowsResponse.Entry in project java-bigtable by googleapis.

the class RowMutationEntryTest method unsafeMutationTest.

@Test
public void unsafeMutationTest() {
    ByteString rowKey = ByteString.copyFromUtf8("row-key");
    RowMutationEntry rowMutationEntry = RowMutationEntry.createUnsafe(rowKey).setCell("family-1", "qualifier-1", 10_000L, "fake-values").deleteFamily("family-2");
    MutateRowsRequest.Entry entry = rowMutationEntry.toProto();
    assertThat(entry.getMutationsCount()).isEqualTo(2);
    assertThat(entry.getMutationsList()).isEqualTo(ImmutableList.of(Mutation.newBuilder().setSetCell(Mutation.SetCell.newBuilder().setFamilyName("family-1").setColumnQualifier(ByteString.copyFromUtf8("qualifier-1")).setTimestampMicros(10_000L).setValue(ByteString.copyFromUtf8("fake-values"))).build(), Mutation.newBuilder().setDeleteFromFamily(Mutation.DeleteFromFamily.newBuilder().setFamilyName("family-2")).build()));
}
Also used : MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 3 with Entry

use of com.google.bigtable.v2.MutateRowsResponse.Entry 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();
}
Also used : MutateRowsException(com.google.cloud.bigtable.data.v2.models.MutateRowsException) MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) FailedMutation(com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation) Test(org.junit.Test)

Example 4 with Entry

use of com.google.bigtable.v2.MutateRowsResponse.Entry in project java-bigtable by googleapis.

the class MutateRowsAttemptCallableTest method rpcPermanentError.

@Test
public void rpcPermanentError() {
    // Setup the request & response
    MutateRowsRequest request = MutateRowsRequest.newBuilder().addEntries(Entry.getDefaultInstance()).addEntries(Entry.getDefaultInstance()).build();
    final UnavailableException rpcError = new UnavailableException("fake error", null, GrpcStatusCode.of(io.grpc.Status.Code.INVALID_ARGUMENT), false);
    UnaryCallable<MutateRowsRequest, List<MutateRowsResponse>> innerCallable = new UnaryCallable<MutateRowsRequest, List<MutateRowsResponse>>() {

        @Override
        public ApiFuture<List<MutateRowsResponse>> futureCall(MutateRowsRequest request, ApiCallContext context) {
            return ApiFutures.immediateFailedFuture(rpcError);
        }
    };
    // Make the call
    MutateRowsAttemptCallable attemptCallable = new MutateRowsAttemptCallable(innerCallable, request, callContext, retryCodes);
    attemptCallable.setExternalFuture(parentFuture);
    attemptCallable.call();
    // Overall expectations: retryable error
    Throwable actualError = null;
    try {
        parentFuture.attemptFuture.get();
    } catch (Throwable t) {
        actualError = t.getCause();
    }
    assertThat(actualError).isInstanceOf(MutateRowsException.class);
    assertThat(((MutateRowsException) actualError).isRetryable()).isFalse();
    // Entry expectations: both entries failed with an error whose cause is the rpc error
    @SuppressWarnings("ConstantConditions") List<FailedMutation> failedMutations = ((MutateRowsException) actualError).getFailedMutations();
    assertThat(failedMutations).hasSize(2);
    assertThat(failedMutations.get(0).getIndex()).isEqualTo(0);
    assertThat(failedMutations.get(0).getError().isRetryable()).isFalse();
    assertThat(failedMutations.get(0).getError().getCause()).isEqualTo(rpcError);
    assertThat(failedMutations.get(1).getIndex()).isEqualTo(1);
    assertThat(failedMutations.get(1).getError().isRetryable()).isFalse();
    assertThat(failedMutations.get(1).getError().getCause()).isEqualTo(rpcError);
}
Also used : UnaryCallable(com.google.api.gax.rpc.UnaryCallable) UnavailableException(com.google.api.gax.rpc.UnavailableException) ApiCallContext(com.google.api.gax.rpc.ApiCallContext) FailedMutation(com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation) MutateRowsResponse(com.google.bigtable.v2.MutateRowsResponse) MutateRowsException(com.google.cloud.bigtable.data.v2.models.MutateRowsException) MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) List(java.util.List) Test(org.junit.Test)

Example 5 with Entry

use of com.google.bigtable.v2.MutateRowsResponse.Entry in project beam by apache.

the class BigtableServiceImplTest method testWrite.

/**
 * This test ensures that protobuf creation and interactions with {@link BulkMutation} work as
 * expected.
 *
 * @throws IOException
 * @throws InterruptedException
 */
@Test
public void testWrite() throws IOException, InterruptedException {
    BigtableService.Writer underTest = new BigtableServiceImpl.BigtableWriterImpl(mockSession, TABLE_NAME);
    Mutation mutation = Mutation.newBuilder().setSetCell(SetCell.newBuilder().setFamilyName("Family").build()).build();
    ByteString key = ByteString.copyFromUtf8("key");
    SettableFuture<MutateRowResponse> fakeResponse = SettableFuture.create();
    when(mockBulkMutation.add(any(MutateRowsRequest.Entry.class))).thenReturn(fakeResponse);
    underTest.writeRecord(KV.of(key, ImmutableList.of(mutation)));
    Entry expected = MutateRowsRequest.Entry.newBuilder().setRowKey(key).addMutations(mutation).build();
    verify(mockBulkMutation, times(1)).add(expected);
    underTest.close();
    verify(mockBulkMutation, times(1)).flush();
}
Also used : MutateRowResponse(com.google.bigtable.v2.MutateRowResponse) Entry(com.google.bigtable.v2.MutateRowsRequest.Entry) ByteString(com.google.protobuf.ByteString) Mutation(com.google.bigtable.v2.Mutation) BulkMutation(com.google.cloud.bigtable.grpc.async.BulkMutation) Test(org.junit.Test)

Aggregations

MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)9 Test (org.junit.Test)7 MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)6 FailedMutation (com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)6 MutateRowsResponse (com.google.bigtable.v2.MutateRowsResponse)4 ByteString (com.google.protobuf.ByteString)3 ApiCallContext (com.google.api.gax.rpc.ApiCallContext)2 UnaryCallable (com.google.api.gax.rpc.UnaryCallable)2 UnavailableException (com.google.api.gax.rpc.UnavailableException)2 Builder (com.google.bigtable.v2.MutateRowsRequest.Builder)2 List (java.util.List)2 ExponentialRetryAlgorithm (com.google.api.gax.retrying.ExponentialRetryAlgorithm)1 RetryAlgorithm (com.google.api.gax.retrying.RetryAlgorithm)1 ScheduledRetryingExecutor (com.google.api.gax.retrying.ScheduledRetryingExecutor)1 ApiException (com.google.api.gax.rpc.ApiException)1 MutateRowResponse (com.google.bigtable.v2.MutateRowResponse)1 Entry (com.google.bigtable.v2.MutateRowsRequest.Entry)1 Entry (com.google.bigtable.v2.MutateRowsResponse.Entry)1 Mutation (com.google.bigtable.v2.Mutation)1 StatsHeadersServerStreamingCallable (com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersServerStreamingCallable)1