-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(bigtable): route single-entry MutateRows through a point-write c… #14028
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
Merged
mutianf
merged 2 commits into
googleapis:main
from
mutianf:add-maybe-point-write-callable
Aug 11, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../main/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MaybePointWriteCallable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Copyright 2026 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.mutaterows; | ||
|
|
||
| import com.google.api.core.ApiFuture; | ||
| import com.google.api.core.InternalApi; | ||
| import com.google.api.gax.rpc.ApiCallContext; | ||
| import com.google.api.gax.rpc.UnaryCallable; | ||
| import com.google.bigtable.v2.MutateRowRequest; | ||
| import com.google.bigtable.v2.MutateRowsRequest; | ||
| import com.google.cloud.bigtable.data.v2.internal.RequestContext; | ||
| import com.google.cloud.bigtable.data.v2.models.BulkMutation; | ||
| import com.google.cloud.bigtable.data.v2.models.RowMutation; | ||
|
|
||
| /** | ||
| * Routes {@link BulkMutation}s that carry a single entry through a unary point-write callable, | ||
| * letting them benefit from the same session-shim diversion as {@code MutateRow}. Bulk mutations | ||
| * with more than one entry fall through to the classic {@code MutateRows} callable. | ||
| * | ||
| * <p>When the session diversion does not apply, the point-write callable falls back to the bulk | ||
| * {@code MutateRows} RPC (as a single-entry batch), retaining the bulk operation's retry behavior, | ||
| * so the single entry travels over the wire and retries exactly as it would have as part of a | ||
| * {@code MutateRows} call. | ||
| */ | ||
| @InternalApi | ||
| public class MaybePointWriteCallable extends UnaryCallable<BulkMutation, Void> { | ||
| private final UnaryCallable<BulkMutation, Void> classic; | ||
| private final UnaryCallable<RowMutation, Void> pointWriter; | ||
| private final RequestContext requestContext; | ||
|
|
||
| public MaybePointWriteCallable( | ||
| UnaryCallable<BulkMutation, Void> classic, | ||
| UnaryCallable<RowMutation, Void> pointWriter, | ||
| RequestContext requestContext) { | ||
| this.classic = classic; | ||
| this.pointWriter = pointWriter; | ||
| this.requestContext = requestContext; | ||
| } | ||
|
|
||
| @Override | ||
| public ApiFuture<Void> futureCall(BulkMutation request, ApiCallContext context) { | ||
| if (request.getEntryCount() != 1) { | ||
| return classic.futureCall(request, context); | ||
| } | ||
| return pointWriter.futureCall(toRowMutation(request), context); | ||
| } | ||
|
|
||
| private RowMutation toRowMutation(BulkMutation request) { | ||
| MutateRowsRequest proto = request.toProto(requestContext); | ||
| MutateRowsRequest.Entry entry = proto.getEntries(0); | ||
| MutateRowRequest mutateRowRequest = | ||
| MutateRowRequest.newBuilder() | ||
| .setAppProfileId(proto.getAppProfileId()) | ||
| .setTableName(proto.getTableName()) | ||
| .setAuthorizedViewName(proto.getAuthorizedViewName()) | ||
| .setRowKey(entry.getRowKey()) | ||
| .addAllMutations(entry.getMutationsList()) | ||
| .build(); | ||
| return RowMutation.fromProto(mutateRowRequest); | ||
| } | ||
| } |
128 changes: 128 additions & 0 deletions
128
...t/java/com/google/cloud/bigtable/data/v2/stub/mutaterows/MaybePointWriteCallableTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /* | ||
| * Copyright 2026 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.mutaterows; | ||
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import com.google.api.core.ApiFuture; | ||
| import com.google.api.core.SettableApiFuture; | ||
| import com.google.api.gax.rpc.ApiCallContext; | ||
| import com.google.api.gax.rpc.UnaryCallable; | ||
| import com.google.cloud.bigtable.data.v2.internal.RequestContext; | ||
| import com.google.cloud.bigtable.data.v2.models.BulkMutation; | ||
| import com.google.cloud.bigtable.data.v2.models.Mutation; | ||
| import com.google.cloud.bigtable.data.v2.models.RowMutation; | ||
| import com.google.cloud.bigtable.data.v2.models.TableId; | ||
| import java.util.concurrent.ExecutionException; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class MaybePointWriteCallableTest { | ||
|
|
||
| private static final RequestContext REQUEST_CONTEXT = | ||
| RequestContext.create("my-project", "my-instance", "my-profile"); | ||
| private static final TableId TABLE_ID = TableId.of("fake-table"); | ||
|
|
||
| private FakeBulkCallable classic; | ||
| private FakePointWriter pointWriter; | ||
| private MaybePointWriteCallable callable; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| classic = new FakeBulkCallable(); | ||
| pointWriter = new FakePointWriter(); | ||
| callable = new MaybePointWriteCallable(classic, pointWriter, REQUEST_CONTEXT); | ||
| } | ||
|
|
||
| @Test | ||
| public void singleEntry_routesToPointWriter() throws Exception { | ||
| BulkMutation request = | ||
| BulkMutation.create(TABLE_ID).add("row-key", Mutation.create().deleteRow()); | ||
|
|
||
| ApiFuture<Void> future = callable.futureCall(request, null); | ||
| pointWriter.response.set(null); | ||
|
|
||
| assertThat(future.get()).isNull(); | ||
| assertThat(classic.request).isNull(); | ||
| assertThat(pointWriter.request).isNotNull(); | ||
| // The single entry is converted back into a RowMutation targeting the same row. | ||
| assertThat(pointWriter.request.getTargetId()).isEqualTo(TABLE_ID); | ||
| } | ||
|
|
||
| @Test | ||
| public void multipleEntries_fallsThroughToClassic() { | ||
| BulkMutation request = | ||
| BulkMutation.create(TABLE_ID) | ||
| .add("row-a", Mutation.create().deleteRow()) | ||
| .add("row-b", Mutation.create().deleteRow()); | ||
|
|
||
| callable.futureCall(request, null); | ||
|
|
||
| assertThat(pointWriter.request).isNull(); | ||
| assertThat(classic.request).isEqualTo(request); | ||
| } | ||
|
|
||
| @Test | ||
| public void pointWriterFails_propagates() { | ||
| BulkMutation request = | ||
| BulkMutation.create(TABLE_ID).add("row-key", Mutation.create().deleteRow()); | ||
| RuntimeException failure = new RuntimeException("point boom"); | ||
|
|
||
| ApiFuture<Void> future = callable.futureCall(request, null); | ||
| pointWriter.response.setException(failure); | ||
|
|
||
| ExecutionException thrown = assertThrows(ExecutionException.class, future::get); | ||
| assertThat(thrown).hasCauseThat().isSameInstanceAs(failure); | ||
| } | ||
|
|
||
| @Test | ||
| public void classicFailure_propagates() { | ||
| BulkMutation request = | ||
| BulkMutation.create(TABLE_ID) | ||
| .add("row-a", Mutation.create().deleteRow()) | ||
| .add("row-b", Mutation.create().deleteRow()); | ||
| RuntimeException failure = new RuntimeException("classic boom"); | ||
| classic.response.setException(failure); | ||
|
|
||
| ApiFuture<Void> future = callable.futureCall(request, null); | ||
|
|
||
| ExecutionException thrown = assertThrows(ExecutionException.class, future::get); | ||
| assertThat(thrown).hasCauseThat().isSameInstanceAs(failure); | ||
| } | ||
|
|
||
| private static class FakeBulkCallable extends UnaryCallable<BulkMutation, Void> { | ||
| BulkMutation request; | ||
| final SettableApiFuture<Void> response = SettableApiFuture.create(); | ||
|
|
||
| @Override | ||
| public ApiFuture<Void> futureCall(BulkMutation request, ApiCallContext context) { | ||
| this.request = request; | ||
| return response; | ||
| } | ||
| } | ||
|
|
||
| private static class FakePointWriter extends UnaryCallable<RowMutation, Void> { | ||
| RowMutation request; | ||
| final SettableApiFuture<Void> response = SettableApiFuture.create(); | ||
|
|
||
| @Override | ||
| public ApiFuture<Void> futureCall(RowMutation request, ApiCallContext context) { | ||
| this.request = request; | ||
| return response; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test case to verify that a BulkMutation with zero entries is correctly routed to the classic bulk mutation path instead of the point-write path.