Search in sources :

Example 21 with Builder

use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable by googleapis.

the class QueryTest method limitTest.

@Test
public void limitTest() {
    Query query = Query.create(TABLE_ID).limit(10);
    Builder expectedProto = expectedProtoBuilder().setRowsLimit(10);
    ReadRowsRequest actualProto = query.toProto(requestContext);
    assertThat(actualProto).isEqualTo(expectedProto.build());
}
Also used : Builder(com.google.bigtable.v2.ReadRowsRequest.Builder) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Test(org.junit.Test)

Example 22 with Builder

use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable by googleapis.

the class MutateRowsAttemptCallable method handleAttemptSuccess.

/**
 * Handle entry level failures. All new response entries are inspected for failure. If any
 * transient failures are found, their corresponding mutations are scheduled for the next RPC. The
 * caller is notified of both new found errors and pre-existing permanent errors in the thrown
 * {@link MutateRowsException}. If no errors exist, then the attempt future is successfully
 * completed.
 */
private void handleAttemptSuccess(List<MutateRowsResponse> responses) {
    List<FailedMutation> allFailures = Lists.newArrayList(permanentFailures);
    MutateRowsRequest lastRequest = currentRequest;
    Builder builder = lastRequest.toBuilder().clearEntries();
    List<Integer> newOriginalIndexes = Lists.newArrayList();
    for (MutateRowsResponse response : responses) {
        for (Entry entry : response.getEntriesList()) {
            if (entry.getStatus().getCode() == Code.OK_VALUE) {
                continue;
            }
            int origIndex = getOriginalIndex((int) entry.getIndex());
            FailedMutation failedMutation = FailedMutation.create(origIndex, createEntryError(entry.getStatus()));
            allFailures.add(failedMutation);
            if (!failedMutation.getError().isRetryable()) {
                permanentFailures.add(failedMutation);
            } else {
                // Schedule the mutation entry for the next RPC by adding it to the request builder and
                // recording it's original index
                newOriginalIndexes.add(origIndex);
                builder.addEntries(lastRequest.getEntries((int) entry.getIndex()));
            }
        }
    }
    currentRequest = builder.build();
    originalIndexes = newOriginalIndexes;
    if (!allFailures.isEmpty()) {
        boolean isRetryable = builder.getEntriesCount() > 0;
        throw new MutateRowsException(null, allFailures, isRetryable);
    }
}
Also used : Entry(com.google.bigtable.v2.MutateRowsResponse.Entry) MutateRowsResponse(com.google.bigtable.v2.MutateRowsResponse) MutateRowsException(com.google.cloud.bigtable.data.v2.models.MutateRowsException) MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) Builder(com.google.bigtable.v2.MutateRowsRequest.Builder) FailedMutation(com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)

Example 23 with Builder

use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable by googleapis.

the class MutateRowsAttemptCallable method handleAttemptError.

/**
 * Handle an RPC level failure by generating a {@link FailedMutation} for each expected entry. The
 * newly generated {@link FailedMutation}s will be combined with the permanentFailures to give the
 * caller the whole picture since the first call. This method will always throw a {@link
 * MutateRowsException}.
 */
private void handleAttemptError(Throwable rpcError) {
    ApiException entryError = createSyntheticErrorForRpcFailure(rpcError);
    ImmutableList.Builder<FailedMutation> allFailures = ImmutableList.builder();
    MutateRowsRequest lastRequest = currentRequest;
    allFailures.addAll(permanentFailures);
    Builder builder = lastRequest.toBuilder().clearEntries();
    List<Integer> newOriginalIndexes = Lists.newArrayList();
    for (int i = 0; i < currentRequest.getEntriesCount(); i++) {
        int origIndex = getOriginalIndex(i);
        FailedMutation failedMutation = FailedMutation.create(origIndex, entryError);
        allFailures.add(failedMutation);
        if (!failedMutation.getError().isRetryable()) {
            permanentFailures.add(failedMutation);
        } else {
            // Schedule the mutation entry for the next RPC by adding it to the request builder and
            // recording its original index
            newOriginalIndexes.add(origIndex);
            builder.addEntries(lastRequest.getEntries(i));
        }
    }
    currentRequest = builder.build();
    originalIndexes = newOriginalIndexes;
    throw new MutateRowsException(rpcError, allFailures.build(), entryError.isRetryable());
}
Also used : MutateRowsException(com.google.cloud.bigtable.data.v2.models.MutateRowsException) MutateRowsRequest(com.google.bigtable.v2.MutateRowsRequest) ImmutableList(com.google.common.collect.ImmutableList) Builder(com.google.bigtable.v2.MutateRowsRequest.Builder) FailedMutation(com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation) ApiException(com.google.api.gax.rpc.ApiException)

Aggregations

Test (org.junit.Test)16 RowSet (com.google.bigtable.v2.RowSet)14 RowKeyWrapper (com.google.cloud.bigtable.hbase.util.RowKeyWrapper)12 ByteString (com.google.protobuf.ByteString)12 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)6 Builder (com.google.bigtable.v2.ReadRowsRequest.Builder)4 Column (com.google.bigtable.v2.Column)3 Family (com.google.bigtable.v2.Family)3 MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)2 Builder (com.google.bigtable.v2.MutateRowsRequest.Builder)2 DeleteFromRow (com.google.bigtable.v2.Mutation.DeleteFromRow)2 Row (com.google.bigtable.v2.Row)2 RowFilter (com.google.bigtable.v2.RowFilter)2 Builder (com.google.bigtable.v2.RowFilter.Chain.Builder)2 MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)2 FailedMutation (com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)2 ExecutionException (java.util.concurrent.ExecutionException)2 ByteArrayByteIterator (site.ycsb.ByteArrayByteIterator)2 InternalApi (com.google.api.core.InternalApi)1 InstantiatingGrpcChannelProvider (com.google.api.gax.grpc.InstantiatingGrpcChannelProvider)1