Skip to content

Commit

Permalink
Merge branch 'googleapis:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
arpan14 authored Apr 9, 2024
2 parents 07434eb + 5de1d87 commit 92953f1
Show file tree
Hide file tree
Showing 16 changed files with 842 additions and 177 deletions.
15 changes: 15 additions & 0 deletions .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ integration-directpath-enabled)
verify
RETURN_CODE=$?
;;
integration-multiplexed-sessions-enabled)
mvn -B ${INTEGRATION_TEST_ARGS} \
-ntp \
-Penable-integration-tests \
-Djava.net.preferIPv4Stack=true \
-DtrimStackTrace=false \
-Dclirr.skip=true \
-Denforcer.skip=true \
-Dmaven.main.skip=true \
-Dspanner.gce.config.project_id=gcloud-devel \
-Dspanner.testenv.instance=projects/gcloud-devel/instances/java-client-integration-tests-multiplexed-sessions \
-fae \
verify
RETURN_CODE=$?
;;
integration-cloud-devel)
mvn -B ${INTEGRATION_TEST_ARGS} \
-ntp \
Expand Down
38 changes: 38 additions & 0 deletions .kokoro/presubmit/integration-multiplexed-sessions-enabled.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/java8"
}

env_vars: {
key: "JOB_TYPE"
value: "integration-multiplexed-sessions-enabled"
}

# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_CLOUD_PROJECT"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "secret_manager/java-it-service-account"
}

env_vars: {
key: "SECRET_MANAGER_KEYS"
value: "java-it-service-account"
}

env_vars: {
key: "GOOGLE_CLOUD_SPANNER_ENABLE_MULTIPLEXED_SESSIONS"
value: "true"
}
6 changes: 6 additions & 0 deletions google-cloud-spanner/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<differenceType>8001</differenceType>
<className>com/google/cloud/spanner/connection/StatementParser</className>
</difference>
<!-- (Remove since prepareReadWriteTransaction() has no usage. Session interface is annotated as internal API) -->
<difference>
<differenceType>7002</differenceType>
<className>com/google/cloud/spanner/Session</className>
<method>void prepareReadWriteTransaction()</method>
</difference>
<difference>
<differenceType>7002</differenceType>
<className>com/google/cloud/spanner/SpannerOptions</className>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.api.core.ApiFuture;
import com.google.api.core.InternalApi;
import com.google.cloud.spanner.Options.TransactionOption;
import com.google.protobuf.Empty;

/**
Expand Down Expand Up @@ -48,16 +47,6 @@ public interface Session extends DatabaseClient, AutoCloseable {
/** Returns the resource name associated with this session. */
String getName();

/**
* Prepares a transaction for use by a subsequent {@link
* DatabaseClient#readWriteTransaction(TransactionOption...)} or {@link #write(Iterable)} call. It
* is not necessary to call this method before running a transaction or performing a write, but
* doing so may allow one round trip of the protocol to be performed in advance; calling this
* method on an idle session that is expected to execute a transaction or write in the near future
* may reduce the latency of the subsequent transaction/write.
*/
void prepareReadWriteTransaction();

@Override
void close();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public void run() {
}

/**
* Callback interface to be used for BatchCreateSessions. When sessions become available or
* session creation fails, one of the callback methods will be called.
* Callback interface to be used for Sessions. When sessions become available or session creation
* fails, one of the callback methods will be called.
*/
interface SessionConsumer {
/** Called when a session has been created and is ready for use. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ interface SessionTransaction {
private final String name;
private final DatabaseId databaseId;
private SessionTransaction activeTransaction;
ByteString readyTransactionId;
private final Map<SpannerRpc.Option, ?> options;
private volatile Instant lastUseTime;
@Nullable private final Instant createTime;
Expand Down Expand Up @@ -378,12 +377,6 @@ public AsyncTransactionManagerImpl transactionManagerAsync(TransactionOption...
return new AsyncTransactionManagerImpl(this, currentSpan, options);
}

@Override
public void prepareReadWriteTransaction() {
setActive(null);
readyTransactionId = beginTransaction(true);
}

@Override
public ApiFuture<Empty> asyncClose() {
return spanner.getRpc().asyncDeleteSession(name, options);
Expand All @@ -402,20 +395,6 @@ public void close() {
}
}

ByteString beginTransaction(boolean routeToLeader) {
try {
return beginTransactionAsync(routeToLeader).get();
} catch (ExecutionException e) {
throw SpannerExceptionFactory.newSpannerException(e.getCause() == null ? e : e.getCause());
} catch (InterruptedException e) {
throw SpannerExceptionFactory.propagateInterrupt(e);
}
}

ApiFuture<ByteString> beginTransactionAsync(boolean routeToLeader) {
return beginTransactionAsync(Options.fromTransactionOptions(), routeToLeader);
}

ApiFuture<ByteString> beginTransactionAsync(Options transactionOptions, boolean routeToLeader) {
final SettableApiFuture<ByteString> res = SettableApiFuture.create();
final ISpan span = tracer.spanBuilder(SpannerImpl.BEGIN_TRANSACTION);
Expand Down Expand Up @@ -463,7 +442,7 @@ TransactionContextImpl newTransaction(Options options) {
return TransactionContextImpl.newBuilder()
.setSession(this)
.setOptions(options)
.setTransactionId(readyTransactionId)
.setTransactionId(null)
.setOptions(options)
.setTrackTransactionStarter(spanner.getOptions().isTrackTransactionStarter())
.setRpc(spanner.getRpc())
Expand All @@ -484,17 +463,12 @@ <T extends SessionTransaction> T setActive(@Nullable T ctx) {
activeTransaction.invalidate();
}
activeTransaction = ctx;
readyTransactionId = null;
if (activeTransaction != null) {
activeTransaction.setSpan(currentSpan);
}
return ctx;
}

boolean hasReadyTransaction() {
return readyTransactionId != null;
}

TraceWrapper getTracer() {
return tracer;
}
Expand Down
Loading

0 comments on commit 92953f1

Please sign in to comment.