Search in sources :

Example 6 with FailedMutation

use of com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation 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 7 with FailedMutation

use of com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation in project java-bigtable by googleapis.

the class MutateRowsBatchingDescriptor method splitException.

/**
 * Marks the entry future with received {@link Throwable}.
 *
 * <p>In case throwable is {@link MutateRowsException}, then it only sets throwable for the
 * entries whose index is mentioned {@link MutateRowsException#getFailedMutations()}.
 */
@Override
public void splitException(Throwable throwable, List<BatchEntry<RowMutationEntry, Void>> entries) {
    if (!(throwable instanceof MutateRowsException)) {
        for (BatchEntry<RowMutationEntry, Void> entry : entries) {
            entry.getResultFuture().setException(throwable);
        }
        return;
    }
    List<FailedMutation> failedMutations = ((MutateRowsException) throwable).getFailedMutations();
    Map<Integer, Throwable> entryErrors = Maps.newHashMap();
    for (FailedMutation failure : failedMutations) {
        entryErrors.put(failure.getIndex(), failure.getError());
    }
    int i = 0;
    for (BatchEntry<RowMutationEntry, Void> entry : entries) {
        Throwable entryError = entryErrors.get(i++);
        if (entryError == null) {
            entry.getResultFuture().set(null);
        } else {
            entry.getResultFuture().setException(entryError);
        }
    }
}
Also used : MutateRowsException(com.google.cloud.bigtable.data.v2.models.MutateRowsException) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) FailedMutation(com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)

Aggregations

MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)7 FailedMutation (com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)7 MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)6 Test (org.junit.Test)4 MutateRowsResponse (com.google.bigtable.v2.MutateRowsResponse)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 ApiException (com.google.api.gax.rpc.ApiException)1 Entry (com.google.bigtable.v2.MutateRowsResponse.Entry)1 RowMutationEntry (com.google.cloud.bigtable.data.v2.models.RowMutationEntry)1 ImmutableList (com.google.common.collect.ImmutableList)1