Repository navigation
feat: Session support for mutateRows #14644
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
|
|
||
| import com.google.bigtable.v2.FeatureFlags; | ||
| import com.google.bigtable.v2.Mutation; | ||
| import com.google.bigtable.v2.SessionMutateRowsRequest; | ||
| import io.grpc.Metadata; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
|
|
@@ -76,6 +77,15 @@ public static boolean isIdempotent(List<Mutation> mutations) { | |
| return true; | ||
| } | ||
|
|
||
| public static boolean isIdempotent(SessionMutateRowsRequest req) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove this method? on line 192 in tableBase you can do something like: |
||
| for (SessionMutateRowsRequest.Entry entry : req.getEntriesList()) { | ||
| if (!isIdempotent(entry.getMutationsList())) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| private static String urlEncode(String s) { | ||
| try { | ||
| return URLEncoder.encode(s, StandardCharsets.UTF_8.name()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||||||||
| /* | ||||||||||||
| * 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.internal.compat.ops; | ||||||||||||
|
|
||||||||||||
| import com.google.bigtable.v2.OpenAuthorizedViewRequest; | ||||||||||||
| import com.google.bigtable.v2.OpenTableRequest.Permission; | ||||||||||||
| import com.google.bigtable.v2.SessionMutateRowsRequest; | ||||||||||||
| import com.google.cloud.bigtable.data.v2.internal.api.AuthorizedViewAsync; | ||||||||||||
| import com.google.cloud.bigtable.data.v2.internal.api.Client; | ||||||||||||
| import com.google.cloud.bigtable.data.v2.internal.api.TableAsync; | ||||||||||||
| import com.google.cloud.bigtable.data.v2.models.AuthorizedViewId; | ||||||||||||
| import com.google.cloud.bigtable.data.v2.models.BulkMutation; | ||||||||||||
| import com.google.cloud.bigtable.data.v2.models.TableId; | ||||||||||||
| import com.google.cloud.bigtable.data.v2.models.TargetId; | ||||||||||||
| import io.grpc.Deadline; | ||||||||||||
|
Comment on lines
+27
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Import
Suggested change
|
||||||||||||
| import java.io.IOException; | ||||||||||||
| import java.util.concurrent.CompletableFuture; | ||||||||||||
|
|
||||||||||||
| public class MutateRowsShim implements UnaryShim<BulkMutation, Void> { | ||||||||||||
|
|
||||||||||||
| private final SessionPoolMap<TableId, TableAsync> tables; | ||||||||||||
| private final SessionPoolMap<AuthorizedViewId, AuthorizedViewAsync> authViews; | ||||||||||||
|
|
||||||||||||
| public MutateRowsShim(Client client) { | ||||||||||||
| tables = | ||||||||||||
|
Comment on lines
+37
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a defensive null check for the public MutateRowsShim(Client client) {
Preconditions.checkNotNull(client, "client is required");
tables =References
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should consider share the pool with MutateRow. See my PR (although is not approved yet 😂 ) |
||||||||||||
| new SessionPoolMap<>( | ||||||||||||
| k -> client.openTableAsync(k.getTableId(), Permission.PERMISSION_WRITE)); | ||||||||||||
| authViews = | ||||||||||||
| new SessionPoolMap<>( | ||||||||||||
| k -> | ||||||||||||
| client.openAuthorizedViewAsync( | ||||||||||||
| k.getTableId(), | ||||||||||||
| k.getAuthorizedViewId(), | ||||||||||||
| OpenAuthorizedViewRequest.Permission.PERMISSION_WRITE)); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| @Override | ||||||||||||
| public void close() throws IOException { | ||||||||||||
| tables.invalidateAll(); | ||||||||||||
| authViews.invalidateAll(); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| @Override | ||||||||||||
| public boolean supports(BulkMutation request) { | ||||||||||||
| // TODO: enable when server side changes is rolled out | ||||||||||||
| return false; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| @Override | ||||||||||||
| public CompletableFuture<Void> call(BulkMutation request, Deadline deadline) { | ||||||||||||
| TargetId targetId = request.getTargetId(); | ||||||||||||
|
|
||||||||||||
| SessionMutateRowsRequest innerReq = request.toSessionProto(); | ||||||||||||
|
|
||||||||||||
| if (targetId instanceof TableId) { | ||||||||||||
| return tables.apply( | ||||||||||||
| (TableId) targetId, t -> t.mutateRows(innerReq, deadline).thenApply(r -> null)); | ||||||||||||
| } | ||||||||||||
| if (targetId instanceof AuthorizedViewId) { | ||||||||||||
| return authViews.apply( | ||||||||||||
| (AuthorizedViewId) targetId, v -> v.mutateRows(innerReq, deadline).thenApply(r -> null)); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| CompletableFuture<Void> f = new CompletableFuture<>(); | ||||||||||||
| f.completeExceptionally( | ||||||||||||
| new UnsupportedOperationException("Unsupported targetId type: " + targetId)); | ||||||||||||
| return f; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
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.
this comment can be removed. My PR is removing it in all other places.