Skip to content

Commit

Permalink
Merge branch 'main' into gfe_latency
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhigarg92 authored Jan 31, 2025
2 parents d336d39 + f4560e5 commit 37d2089
Show file tree
Hide file tree
Showing 20 changed files with 611 additions and 24 deletions.
6 changes: 1 addition & 5 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@
# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax

# The @googleapis/api-spanner-java is the default owner for changes in this repo
* @googleapis/yoshi-java @googleapis/api-spanner-java
**/*.java @googleapis/api-spanner-java

# The java-samples-reviewers team is the default owner for samples changes
samples/**/*.java @googleapis/java-samples-reviewers @googleapis/api-spanner-java
* @googleapis/yoshi-java @googleapis/spanner-client-libraries-java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ env_vars: {
}

env_vars: {
key: "GOOGLE_CLOUD_ENABLE_DIRECT_PATH_XDS"
key: "GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS"
value: "true"
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ env_vars: {
}

env_vars: {
key: "GOOGLE_CLOUD_ENABLE_DIRECT_PATH_XDS"
key: "GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS"
value: "true"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ env_vars: {
}

env_vars: {
key: "GOOGLE_CLOUD_ENABLE_DIRECT_PATH_XDS"
key: "GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS"
value: "true"
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ env_vars: {
}

env_vars: {
key: "GOOGLE_CLOUD_ENABLE_DIRECT_PATH_XDS"
key: "GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS"
value: "true"
}
2 changes: 1 addition & 1 deletion .kokoro/nightly/integration-directpath-enabled.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ env_vars: {
}

env_vars: {
key: "GOOGLE_CLOUD_ENABLE_DIRECT_PATH_XDS"
key: "GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS"
value: "true"
}
4 changes: 2 additions & 2 deletions .kokoro/presubmit/integration-directpath-enabled.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ env_vars: {
}

env_vars: {
key: "GOOGLE_CLOUD_ENABLE_DIRECT_PATH_XDS"
key: "GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS"
value: "true"
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-spanner/tree/
| Create Instance Config Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceConfigSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceConfigSample.java) |
| Create Instance Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceExample.java) |
| Create Instance Partition Sample | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstancePartitionSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstancePartitionSample.java) |
| Create Instance With Asymmetric Autoscaling Config Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceWithAsymmetricAutoscalingConfigExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceWithAsymmetricAutoscalingConfigExample.java) |
| Create Instance With Autoscaling Config Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceWithAutoscalingConfigExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceWithAutoscalingConfigExample.java) |
| Create Instance With Processing Units Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceWithProcessingUnitsExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceWithProcessingUnitsExample.java) |
| Create Instance Without Default Backup Schedules Example | [source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/CreateInstanceWithoutDefaultBackupSchedulesExample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/CreateInstanceWithoutDefaultBackupSchedulesExample.java) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

package com.google.cloud.spanner;

import com.google.api.gax.rpc.ServerStream;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.Options.TransactionOption;
import com.google.spanner.v1.BatchWriteResponse;

/**
* Base class for the Multiplexed Session {@link DatabaseClient} implementation. Throws {@link
Expand All @@ -43,11 +40,4 @@ public String getDatabaseRole() {
public Timestamp writeAtLeastOnce(Iterable<Mutation> mutations) throws SpannerException {
return writeAtLeastOnceWithOptions(mutations).getCommitTimestamp();
}

@Override
public ServerStream<BatchWriteResponse> batchWriteAtLeastOnce(
Iterable<MutationGroup> mutationGroups, TransactionOption... options)
throws SpannerException {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ public ServerStream<BatchWriteResponse> batchWriteAtLeastOnce(
throws SpannerException {
ISpan span = tracer.spanBuilder(READ_WRITE_TRANSACTION, commonAttributes, options);
try (IScope s = tracer.withSpan(span)) {
if (canUseMultiplexedSessionsForRW() && getMultiplexedSessionDatabaseClient() != null) {
return getMultiplexedSessionDatabaseClient().batchWriteAtLeastOnce(mutationGroups, options);
}
return runWithSessionRetry(session -> session.batchWriteAtLeastOnce(mutationGroups, options));
} catch (RuntimeException e) {
span.setStatus(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@

import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.gax.rpc.ServerStream;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.DelayedReadContext.DelayedReadOnlyTransaction;
import com.google.cloud.spanner.MultiplexedSessionDatabaseClient.MultiplexedSessionTransaction;
import com.google.cloud.spanner.Options.TransactionOption;
import com.google.cloud.spanner.Options.UpdateOption;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.spanner.v1.BatchWriteResponse;
import java.util.concurrent.ExecutionException;

/**
Expand Down Expand Up @@ -164,6 +166,22 @@ public CommitResponse writeWithOptions(Iterable<Mutation> mutations, Transaction
}
}

/**
* This is a blocking method, as the interface that it implements is also defined as a blocking
* method.
*/
@Override
public ServerStream<BatchWriteResponse> batchWriteAtLeastOnce(
Iterable<MutationGroup> mutationGroups, TransactionOption... options)
throws SpannerException {
SessionReference sessionReference = getSessionReference();
try (MultiplexedSessionTransaction transaction =
new MultiplexedSessionTransaction(
client, span, sessionReference, NO_CHANNEL_HINT, /* singleUse = */ true)) {
return transaction.batchWriteAtLeastOnce(mutationGroups, options);
}
}

@Override
public TransactionRunner readWriteTransaction(TransactionOption... options) {
return new DelayedTransactionRunner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.core.SettableApiFuture;
import com.google.api.gax.rpc.ServerStream;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.Options.TransactionOption;
import com.google.cloud.spanner.Options.UpdateOption;
Expand All @@ -30,6 +31,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.spanner.v1.BatchWriteResponse;
import com.google.spanner.v1.BeginTransactionRequest;
import com.google.spanner.v1.RequestOptions;
import com.google.spanner.v1.Transaction;
Expand Down Expand Up @@ -505,6 +507,14 @@ public CommitResponse writeAtLeastOnceWithOptions(
.writeAtLeastOnceWithOptions(mutations, options);
}

@Override
public ServerStream<BatchWriteResponse> batchWriteAtLeastOnce(
Iterable<MutationGroup> mutationGroups, TransactionOption... options)
throws SpannerException {
return createMultiplexedSessionTransaction(/* singleUse = */ true)
.batchWriteAtLeastOnce(mutationGroups, options);
}

@Override
public ReadContext singleUse() {
return createMultiplexedSessionTransaction(/* singleUse = */ true).singleUse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public ServerStream<BatchWriteResponse> batchWriteAtLeastOnce(
throw SpannerExceptionFactory.newSpannerException(e);
} finally {
span.end();
onTransactionDone();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,19 @@ private void createTxnAsync(
}
res.set(null);
} catch (ExecutionException e) {
SpannerException spannerException = SpannerExceptionFactory.asSpannerException(e);
if (spannerException.getErrorCode() == ErrorCode.ABORTED
&& session.getIsMultiplexed()
&& mutation != null) {
// Begin transaction can return ABORTED errors. This can only happen if it included
// a mutation key, which again means that this is a mutation-only transaction on a
// multiplexed session.
span.addAnnotation(
"Transaction Creation Failed with ABORT. Retrying",
e.getCause() == null ? e : e.getCause());
createTxnAsync(res, mutation);
return;
}
span.addAnnotation(
"Transaction Creation Failed", e.getCause() == null ? e : e.getCause());
res.setException(e.getCause() == null ? e : e.getCause());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,8 @@ private Transaction beginTransaction(
}
if (session.getMultiplexed()
&& options.getModeCase() == ModeCase.READ_WRITE
&& mutationKey != null) {
&& mutationKey != null
&& mutationKey != com.google.spanner.v1.Mutation.getDefaultInstance()) {
// Mutation only case in a read-write transaction.
builder.setPrecommitToken(getTransactionPrecommitToken(transactionId));
}
Expand Down Expand Up @@ -2023,6 +2024,14 @@ public void commit(CommitRequest request, StreamObserver<CommitResponse> respons
return;
}
sessionLastUsed.put(session.getName(), Instant.now());
if (session.getMultiplexed()
&& !request.hasPrecommitToken()
&& !request.hasSingleUseTransaction()) {
throw Status.INVALID_ARGUMENT
.withDescription(
"A Commit request for a read-write transaction on a multiplexed session must specify a precommit token.")
.asRuntimeException();
}
try {
commitExecutionTime.simulateExecutionTime(exceptions, stickyGlobalExceptions, freezeLock);
// Find or start a transaction
Expand Down
Loading

0 comments on commit 37d2089

Please sign in to comment.