Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update the accounting of partial batch mutations #2149

Merged
merged 32 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tests
  • Loading branch information
ron-gal committed Mar 6, 2024
commit e6485ee4ae322ab66d5eeb1826102db3d27e7f56
Expand Up @@ -17,16 +17,10 @@

import static com.google.cloud.bigtable.data.v2.stub.CookiesHolder.COOKIES_HOLDER_KEY;

import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.gax.grpc.GrpcCallContext;
import com.google.api.gax.rpc.ApiCallContext;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.bigtable.v2.MutateRowsRequest;
import com.google.cloud.bigtable.data.v2.models.MutateRowsException;
import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsAttemptResult;
import com.google.common.util.concurrent.MoreExecutors;

/**
* The cookie holder will act as operation scoped storage for all retry attempts. Each attempt's
Expand All @@ -48,4 +42,3 @@ public ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext context)
grpcCallContext.getCallOptions().withOption(COOKIES_HOLDER_KEY, new CookiesHolder())));
}
}

@@ -1,3 +1,18 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.bigtable.data.v2.stub;

import com.google.api.core.ApiFuture;
Expand Down
Expand Up @@ -120,11 +120,7 @@ public Object getTransportCode() {

// Simple wrappers for handling result futures
private final ApiFunction<List<MutateRowsResponse>, MutateRowsAttemptResult>
attemptSuccessfulCallback =
responses -> {
handleAttemptSuccess(responses);
return null;
};
attemptSuccessfulCallback = responses -> handleAttemptSuccess(responses);
igorbernstein2 marked this conversation as resolved.
Show resolved Hide resolved

private final ApiFunction<Throwable, List<MutateRowsResponse>> attemptFailedCallback =
throwable -> {
Expand Down
Expand Up @@ -23,10 +23,12 @@ public class MutateRowsAttemptResult {

public boolean isRetryable;
public List<FailedMutation> failedMutations;
public MutateRowsAttemptResult(){
this.failedMutations = new ArrayList<>();
this.isRetryable = false;
}

public MutateRowsAttemptResult() {
this.failedMutations = new ArrayList<>();
this.isRetryable = false;
}

public MutateRowsAttemptResult(List<FailedMutation> failedMutations, boolean isRetryable) {
this.failedMutations = failedMutations;
this.isRetryable = isRetryable;
Expand Down
Expand Up @@ -26,7 +26,6 @@
import com.google.api.gax.rpc.UnaryCallable;
import com.google.bigtable.v2.MutateRowsRequest;
import com.google.bigtable.v2.MutateRowsResponse;
import com.google.cloud.bigtable.data.v2.models.MutateRowsException;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import java.util.Set;
Expand Down
Expand Up @@ -21,7 +21,6 @@
import com.google.api.client.json.webtoken.JsonWebSignature;
import com.google.api.gax.batching.Batcher;
import com.google.api.gax.batching.BatcherImpl;
import com.google.api.gax.batching.BatchingException;
import com.google.api.gax.batching.BatchingSettings;
import com.google.api.gax.batching.FlowControlSettings;
import com.google.api.gax.batching.FlowController.LimitExceededBehavior;
Expand Down Expand Up @@ -58,8 +57,6 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.BytesValue;
import com.google.protobuf.StringValue;
import com.google.rpc.Code;
import com.google.rpc.Status;
import io.grpc.Context;
import io.grpc.Deadline;
import io.grpc.ManagedChannel;
Expand Down Expand Up @@ -96,7 +93,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mockito;
import org.threeten.bp.Duration;

@RunWith(JUnit4.class)
Expand Down Expand Up @@ -616,7 +612,8 @@ public void testReadChangeStreamWaitTimeoutIsSet() throws Exception {
// .addEntries(
// MutateRowsResponse.Entry.newBuilder()
// .setIndex(1)
// .setStatus(Status.newBuilder().setCode(Code.PERMISSION_DENIED_VALUE))
//
// .setStatus(Status.newBuilder().setCode(Code.PERMISSION_DENIED_VALUE))
// .build())
// .build());
// observer.onCompleted();
Expand Down Expand Up @@ -656,7 +653,8 @@ public void testReadChangeStreamWaitTimeoutIsSet() throws Exception {
// Assert.assertThrows(BatchingException.class, () -> batcher.close());
//
// // Overall RPC status was PERMISSION_DENIED, so the error message should be something like
// // Batching finished with 1 batches failed to apply due to: 1 ApiException(1 PERMISSION_DENIED)
// // Batching finished with 1 batches failed to apply due to: 1 ApiException(1
// PERMISSION_DENIED)
// assertThat(batchingException).hasMessageThat().contains("PERMISSION_DENIED");
// }

igorbernstein2 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Expand Up @@ -44,8 +44,6 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -101,14 +99,18 @@ public void singleEntrySuccessTest() throws Exception {
attemptCallable.setExternalFuture(parentFuture);
attemptCallable.call();

// Attempt completed successfully and the useless response has been suppressed
assertThat(parentFuture.attemptFuture.get()).isNull();
// Attempt completed successfully
MutateRowsAttemptResult result = parentFuture.attemptFuture.get();

assertThat(result).isNotNull();
assertThat(result.failedMutations).hasSize(0);
assertThat(result.isRetryable).isFalse();
// innerCallable received the request
assertThat(innerCallable.lastRequest).isEqualTo(request);
}

@Test
public void missingEntry() {
public void missingEntry() throws Exception {
MutateRowsRequest request =
MutateRowsRequest.newBuilder()
.addEntries(Entry.getDefaultInstance())
Expand All @@ -125,14 +127,10 @@ public void missingEntry() {
attemptCallable.setExternalFuture(parentFuture);
attemptCallable.call();

ExecutionException executionException =
Assert.assertThrows(ExecutionException.class, () -> parentFuture.attemptFuture.get());
assertThat(executionException).hasCauseThat().isInstanceOf(MutateRowsException.class);
MutateRowsException e = (MutateRowsException) executionException.getCause();
MutateRowsAttemptResult result = parentFuture.attemptFuture.get();

assertThat(e).hasMessageThat().contains("Some mutations failed to apply");
assertThat(e.getFailedMutations()).hasSize(1);
FailedMutation failedMutation = e.getFailedMutations().get(0);
assertThat(result.failedMutations).hasSize(1);
FailedMutation failedMutation = result.failedMutations.get(0);
assertThat(failedMutation.getIndex()).isEqualTo(1);
assertThat(failedMutation.getError())
.hasMessageThat()
Expand Down Expand Up @@ -163,7 +161,7 @@ public void testNoRpcTimeout() {
}

@Test
public void mixedTest() {
public void mixedTest() throws Exception {
// Setup the request & response
MutateRowsRequest request =
MutateRowsRequest.newBuilder()
Expand Down Expand Up @@ -194,20 +192,11 @@ public void mixedTest() {
// 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();
MutateRowsAttemptResult result = parentFuture.attemptFuture.get();

// Entry expectations
@SuppressWarnings("ConstantConditions")
List<FailedMutation> failedMutations = ((MutateRowsException) actualError).getFailedMutations();
List<FailedMutation> failedMutations = result.failedMutations;
assertThat(failedMutations).hasSize(2);

assertThat(failedMutations.get(0).getIndex()).isEqualTo(1);
Expand All @@ -222,7 +211,7 @@ public void mixedTest() {
}

@Test
public void nextAttemptTest() {
public void nextAttemptTest() throws Exception {
// Setup the request & response for the first call
MutateRowsRequest request =
MutateRowsRequest.newBuilder()
Expand Down Expand Up @@ -267,19 +256,11 @@ public void nextAttemptTest() {
assertThat(innerCallable.lastRequest.getEntries(0).getRowKey())
.isEqualTo(ByteString.copyFromUtf8("1-unavailable"));

// 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()).isFalse();
MutateRowsAttemptResult result = parentFuture.attemptFuture.get();

// Entry expectations
@SuppressWarnings("ConstantConditions")
List<FailedMutation> failedMutations = ((MutateRowsException) actualError).getFailedMutations();
List<FailedMutation> failedMutations = result.failedMutations;
assertThat(failedMutations).hasSize(1);

assertThat(failedMutations.get(0).getIndex()).isEqualTo(2);
Expand Down