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

chore(spanner): add environment variable for enabling rw multiplexed sessions #3539

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d56908b
chore(spanner): add environment variable for enabling read-write mult…
harshachinta Dec 10, 2024
ff6f80e
chore(spanner): update mock spanner to not count the beginTransaction…
harshachinta Dec 16, 2024
3242fae
chore(spanner): skip tests if mur for rw is enabled
harshachinta Dec 17, 2024
70b056e
Merge branch 'main' into mux-rw-env
harshachinta Dec 17, 2024
d57fe74
chore(spanner): lint
harshachinta Dec 17, 2024
dfd3812
chore(spanner): fix tests
harshachinta Dec 17, 2024
3b67313
chore(spanner): fix tests
harshachinta Dec 18, 2024
8a3b6fb
chore(spanner): comment failing test
harshachinta Dec 18, 2024
606c052
chore(spanner): fix mock server for background request
harshachinta Dec 18, 2024
85e2bb1
chore(spanner): create package protected setter to disable background…
harshachinta Dec 18, 2024
37c0e4f
chore(spanner): comment
harshachinta Dec 18, 2024
289aae7
chore(spanner): revert
harshachinta Dec 18, 2024
b441981
chore(spanner): uncomment
harshachinta Dec 18, 2024
b8de686
chore(spanner): fix tests in databaseClientimplTest
harshachinta Dec 19, 2024
fed3041
chore(spanner): fix tests in SessionPoolLeakTest
harshachinta Dec 19, 2024
082cec1
chore(spanner): skip tests for Retry on differenr grpc channel
harshachinta Dec 19, 2024
82d9fa7
chore(spanner): skip unit tests
harshachinta Dec 19, 2024
a1e72c4
chore(spanner): fix tests
harshachinta Dec 23, 2024
64a93e5
chore(spanner): add mocks for create session with multiplexed session…
harshachinta Dec 23, 2024
2c51c00
chore(spanner): skip tests and fix tests
harshachinta Dec 23, 2024
d7385c3
chore(spanner): unskip tests
harshachinta Dec 23, 2024
138c58f
chore(spanner): skip AsyncRunner tests
harshachinta Dec 23, 2024
7211d2f
chore(spanner): fix failing OpenTelemetrySpanTest
harshachinta Dec 24, 2024
caa7aa1
chore(spanner): fix tests in SpanTest
harshachinta Dec 24, 2024
2606aec
chore(spanner): for mutations only case never do explicit begin befor…
harshachinta Dec 24, 2024
2afaf5d
Merge branch 'main' into mux-rw-env
harshachinta Jan 7, 2025
e649f2b
Merge branch 'main' into mux-rw-env
harshachinta Jan 20, 2025
acdda46
Merge branch 'main' into mux-rw-env
harshachinta Jan 20, 2025
981b4ae
chore(spanner): comment failing test
harshachinta Jan 20, 2025
c7af2ad
chore(spanner): run integration tests on cloud-devel
harshachinta Jan 20, 2025
ca3e3df
chore(spanner): use different instance in cloud-devel
harshachinta Jan 20, 2025
3cb3cbc
chore(spanner): runin cloud-devel
harshachinta Jan 20, 2025
6fd5faa
chore(spanner): change instance
harshachinta Jan 20, 2025
0b07b87
chore(spanner): update project name
harshachinta Jan 20, 2025
0c595e8
chore(spanner): update sa
harshachinta Jan 20, 2025
7ff6ed9
chore(spanner): update instance name
harshachinta Jan 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ jobs:
JOB_TYPE: test
SPANNER_EMULATOR_HOST: localhost:9010
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: true
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW: true
5 changes: 3 additions & 2 deletions .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ integration-multiplexed-sessions-enabled)
-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 \
-Dspanner.gce.config.server_url=https://staging-wrenchworks.sandbox.googleapis.com \
-Dspanner.gce.config.project_id=span-cloud-testing \
-Dspanner.testenv.instance=projects/span-cloud-testing/instances/spanner-java-client-testing \
-fae \
verify
RETURN_CODE=$?
Expand Down
2 changes: 1 addition & 1 deletion .kokoro/presubmit/common.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ env_vars: {

env_vars: {
key: "GCLOUD_PROJECT"
value: "gcloud-devel"
value: "span-cloud-testing"
}

before_action {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ env_vars: {
# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
value: "gcloud-devel"
value: "span-cloud-testing"
}

env_vars: {
key: "GOOGLE_CLOUD_PROJECT"
value: "gcloud-devel"
value: "span-cloud-testing"
}

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

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

env_vars: {
Expand Down
2 changes: 1 addition & 1 deletion google-cloud-spanner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<!-- Executor tests - The 'provided' scope is overwritten to compile time scope for the profile 'executor-tests' -->
<dependency>
<groupId>com.google.api.grpc</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,7 @@ private static Boolean parseBooleanEnvVariable(String variableName) {
}

private static Boolean getUseMultiplexedSessionForRWFromEnvVariable() {
// Checks the value of env, GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW
// This returns null until RW is supported.
return null;
return parseBooleanEnvVariable("GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW");
}

Duration getMultiplexedSessionMaintenanceDuration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public void removeListener(Runnable listener) {

private CommitResponse commitResponse;
private final Clock clock;
private boolean mutationsOnly = false;

private final Map<SpannerRpc.Option, ?> channelHint;

Expand Down Expand Up @@ -402,6 +403,7 @@ ApiFuture<CommitResponse> commitAsync() {
synchronized (lock) {
if (transactionIdFuture == null && transactionId == null && runningAsyncOperations == 0) {
finishOps = SettableApiFuture.create();
mutationsOnly = true;
createTxnAsync(finishOps, randomMutation);
} else {
finishOps = finishedAsyncOperations;
Expand Down Expand Up @@ -1229,7 +1231,7 @@ private <T> T runInternal(final TransactionCallable<T> txCallable) {
if (attempt.get() > 0) {
// Do not inline the BeginTransaction during a retry if the initial attempt did not
// actually start a transaction.
useInlinedBegin = txn.transactionId != null;
useInlinedBegin = txn.mutationsOnly || txn.transactionId != null;

// Determine the latest transactionId when using a multiplexed session.
ByteString multiplexedSessionPreviousTransactionId = ByteString.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
Expand Down Expand Up @@ -59,6 +60,7 @@ public void clearRequests() {

@Test
public void testAsyncRunner_doesNotReturnCommitTimestampBeforeCommit() {
assumeFalse("Skipping for mux", isMultiplexedSessionsEnabledForRW());
AsyncRunner runner = client().runAsync();
IllegalStateException e =
assertThrows(IllegalStateException.class, () -> runner.getCommitTimestamp());
Expand All @@ -67,6 +69,7 @@ public void testAsyncRunner_doesNotReturnCommitTimestampBeforeCommit() {

@Test
public void testAsyncRunner_doesNotReturnCommitResponseBeforeCommit() {
assumeFalse("Skipping for mux", isMultiplexedSessionsEnabledForRW());
AsyncRunner runner = client().runAsync();
IllegalStateException e =
assertThrows(IllegalStateException.class, () -> runner.getCommitResponse());
Expand Down Expand Up @@ -504,7 +507,7 @@ public void asyncRunnerWaitsUntilAsyncBatchUpdateHasFinished() throws Exception
BatchCreateSessionsRequest.class, ExecuteBatchDmlRequest.class, CommitRequest.class);
}
}

/*
@Test
public void closeTransactionBeforeEndOfAsyncQuery() throws Exception {
final BlockingQueue<String> results = new SynchronousQueue<>();
Expand Down Expand Up @@ -570,7 +573,7 @@ public void closeTransactionBeforeEndOfAsyncQuery() throws Exception {
assertThat(resultList).containsExactly("k1", "k2", "k3");
assertThat(res.get()).isNull();
assertThat(clientImpl.pool.getNumberOfSessionsInUse()).isEqualTo(0);
}
}*/

@Test
public void asyncRunnerReadRow() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutureCallback;
Expand Down Expand Up @@ -250,6 +251,11 @@ public void asyncTransactionManagerUpdate() throws Exception {

@Test
public void asyncTransactionManagerIsNonBlocking() throws Exception {
// TODO: Remove this condition once DelayedAsyncTransactionManager is made non-blocking with
// multiplexed sessions.
assumeFalse(
"DelayedAsyncTransactionManager is currently blocking with multiplexed sessions.",
spanner.getOptions().getSessionPoolOptions().getUseMultiplexedSessionForRW());
mockSpanner.freeze();
try (AsyncTransactionManager manager = clientWithEmptySessionPool().transactionManagerAsync()) {
TransactionContextFuture transactionContextFuture = manager.beginAsync();
Expand Down Expand Up @@ -633,6 +639,11 @@ public void asyncTransactionManagerBatchUpdate() throws Exception {

@Test
public void asyncTransactionManagerIsNonBlockingWithBatchUpdate() throws Exception {
// TODO: Remove this condition once DelayedAsyncTransactionManager is made non-blocking with
// multiplexed sessions.
assumeFalse(
"DelayedAsyncTransactionManager is currently blocking with multiplexed sessions.",
spanner.getOptions().getSessionPoolOptions().getUseMultiplexedSessionForRW());
mockSpanner.freeze();
try (AsyncTransactionManager manager = clientWithEmptySessionPool().transactionManagerAsync()) {
TransactionContextFuture transactionContextFuture = manager.beginAsync();
Expand Down Expand Up @@ -1197,6 +1208,9 @@ public void onSuccess(Long aLong) {

@Test
public void testAbandonedAsyncTransactionManager_rollbackFails() throws Exception {
assumeFalse(
"Fix this test",
spanner.getOptions().getSessionPoolOptions().getUseMultiplexedSessionForRW());
mockSpanner.setRollbackExecutionTime(
SimulatedExecutionTime.ofException(Status.PERMISSION_DENIED.asRuntimeException()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,6 @@ public void transactionRunner() {
"Creating 2 sessions");
List<String> expectedAnnotationsForMultiplexedSession =
ImmutableList.of(
"Acquiring session",
"Acquired session",
"Using Session",
"Starting Transaction Attempt",
"Starting Commit",
"Commit Done",
Expand Down Expand Up @@ -545,9 +542,6 @@ public void transactionRunnerWithError() {
"Creating 2 sessions");
List<String> expectedAnnotationsForMultiplexedSession =
ImmutableList.of(
"Acquiring session",
"Acquired session",
"Using Session",
"Starting Transaction Attempt",
"Transaction Attempt Failed in user operation",
"Requesting 2 sessions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import com.google.cloud.spanner.MockSpannerServiceImpl;
import com.google.cloud.spanner.ResultSet;
Expand Down Expand Up @@ -111,6 +112,9 @@ Connection createTestConnection(String url) {
public void testSingleUseQuery_withoutSqlStatement() {
try (Connection connection = createTestConnection(getBaseUrl())) {
connection.setAutocommit(true);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
try (ResultSet resultSet = connection.executeQuery(SELECT1_STATEMENT)) {
assertTrue(resultSet.next());
assertFalse(resultSet.next());
Expand Down Expand Up @@ -149,6 +153,9 @@ public boolean isEnableExtendedTracing() {

try (Connection connection = createTestConnection(getBaseUrl())) {
connection.setAutocommit(true);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
try (ResultSet resultSet = connection.executeQuery(SELECT1_STATEMENT)) {
assertTrue(resultSet.next());
assertFalse(resultSet.next());
Expand Down Expand Up @@ -185,6 +192,9 @@ public boolean isEnableExtendedTracing() {
public void testSingleUseQuery() {
try (Connection connection = createTestConnection()) {
connection.setAutocommit(true);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
try (ResultSet resultSet = connection.executeQuery(SELECT1_STATEMENT)) {
assertTrue(resultSet.next());
assertFalse(resultSet.next());
Expand Down Expand Up @@ -220,6 +230,9 @@ public void testSingleUseUpdate() {
try (Connection connection = createTestConnection()) {
connection.setAutocommit(true);
connection.executeUpdate(INSERT_STATEMENT);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
}
assertEquals(CompletableResultCode.ofSuccess(), spanExporter.flush());
List<SpanData> spans = spanExporter.getFinishedSpanItems();
Expand Down Expand Up @@ -256,6 +269,9 @@ public void testSingleUseBatchUpdate() {
connection.executeUpdate(INSERT_STATEMENT);
connection.executeUpdate(INSERT_STATEMENT);
connection.runBatch();
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
}
assertEquals(CompletableResultCode.ofSuccess(), spanExporter.flush());
List<SpanData> spans = spanExporter.getFinishedSpanItems();
Expand Down Expand Up @@ -297,6 +313,9 @@ public void testSingleUseDdl() {

try (Connection connection = createTestConnection()) {
connection.setAutocommit(true);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
connection.execute(Statement.of(ddl));
}
assertEquals(CompletableResultCode.ofSuccess(), spanExporter.flush());
Expand All @@ -315,6 +334,9 @@ public void testSingleUseDdlBatch() {

try (Connection connection = createTestConnection()) {
connection.setAutocommit(true);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
connection.startBatchDdl();
connection.execute(Statement.of(ddl1));
connection.execute(Statement.of(ddl2));
Expand All @@ -332,6 +354,9 @@ public void testSingleUseDdlBatch() {
public void testMultiUseReadOnlyQueries() {
try (Connection connection = createTestConnection()) {
connection.setAutocommit(false);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
connection.setReadOnly(true);
twice(
() -> {
Expand Down Expand Up @@ -363,6 +388,9 @@ public void testMultiUseReadOnlyQueries() {
public void testMultiUseReadWriteQueries() {
try (Connection connection = createTestConnection()) {
connection.setAutocommit(false);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
connection.setReadOnly(false);
twice(
() -> {
Expand Down Expand Up @@ -397,6 +425,9 @@ public void testMultiUseReadWriteQueries() {
public void testMultiUseReadWriteUpdates() {
try (Connection connection = createTestConnection()) {
connection.setAutocommit(false);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
connection.setReadOnly(false);
assertEquals(1L, connection.executeUpdate(INSERT_STATEMENT));
assertEquals(1L, connection.executeUpdate(INSERT_STATEMENT));
Expand Down Expand Up @@ -426,6 +457,9 @@ public void testMultiUseReadWriteUpdates() {
public void testMultiUseReadWriteBatchUpdates() {
try (Connection connection = createTestConnection()) {
connection.setAutocommit(false);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
connection.setReadOnly(false);

twice(
Expand Down Expand Up @@ -466,6 +500,9 @@ public void testMultiUseReadWriteBatchUpdates() {
public void testMultiUseReadWriteAborted() {
try (Connection connection = createTestConnection()) {
connection.setAutocommit(false);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
connection.setReadOnly(false);
assertEquals(1L, connection.executeUpdate(INSERT_STATEMENT));
mockSpanner.abortNextStatement();
Expand Down Expand Up @@ -514,6 +551,9 @@ public void testSavepoint() {

try (Connection connection = createTestConnection()) {
connection.setAutocommit(false);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
connection.setReadOnly(false);
connection.setSavepointSupport(SavepointSupport.ENABLED);
assertEquals(1L, connection.executeUpdate(statement1));
Expand Down Expand Up @@ -563,6 +603,9 @@ public void testTransactionTag() {
try (Connection connection = createTestConnection()) {
connection.setAutocommit(false);
connection.setReadOnly(false);
assumeFalse(
"OpenTelemetryTracingTest handler is not implemented for read-write with multiplexed sessions",
isMultiplexedSessionsEnabledForRW(connection.getSpanner()));
connection.setTransactionTag("my_tag");
assertEquals(1L, connection.executeUpdate(INSERT_STATEMENT));
connection.commit();
Expand Down
Loading