Skip to content

Commit b930c89

Browse files
Update spanner version and fix hanging issue
1 parent 1222ae5 commit b930c89

6 files changed

Lines changed: 45 additions & 31 deletions

File tree

buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ class BeamModulePlugin implements Plugin<Project> {
614614
def google_clients_version = "2.0.0"
615615
def google_cloud_bigdataoss_version = "2.2.26"
616616
// [bomupgrader] determined by: com.google.cloud:google-cloud-spanner, consistent with: google_cloud_platform_libraries_bom
617-
def google_cloud_spanner_version = "6.104.0"
617+
def google_cloud_spanner_version = "6.107.0"
618618
def google_code_gson_version = "2.10.1"
619619
def google_oauth_clients_version = "1.34.1"
620620
// [bomupgrader] determined by: io.grpc:grpc-netty, consistent with: google_cloud_platform_libraries_bom
@@ -763,8 +763,6 @@ class BeamModulePlugin implements Plugin<Project> {
763763
// libraries-bom version on sdks/java/container/license_scripts/dep_urls_java.yaml
764764
google_cloud_platform_libraries_bom : "com.google.cloud:libraries-bom:26.74.0",
765765
google_cloud_secret_manager : "com.google.cloud:google-cloud-secretmanager", // google_cloud_platform_libraries_bom sets version
766-
// TODO(#35868) remove pinned google_cloud_spanner_bom after tests or upstream fixed
767-
google_cloud_spanner_bom : "com.google.cloud:google-cloud-spanner-bom:$google_cloud_spanner_version",
768766
google_cloud_spanner : "com.google.cloud:google-cloud-spanner", // google_cloud_platform_libraries_bom sets version
769767
google_cloud_spanner_test : "com.google.cloud:google-cloud-spanner:$google_cloud_spanner_version:tests",
770768
google_cloud_tink : "com.google.crypto.tink:tink:1.19.0",

sdks/java/bom/gcp/build.gradle

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,7 @@ apply from: '../common.gradle'
2020

2121
dependencies {
2222
api platform(project(":sdks:java:bom"))
23-
api platform(project.library.java.google_cloud_spanner_bom)
24-
api platform(project.library.java.google_cloud_platform_libraries_bom) {
25-
// TODO(https://github.com/apache/beam/issues/37328) remove exclude and google_cloud_spanner_bom after upstream and/or tests fixed
26-
exclude group: "com.google.cloud", module: "google-cloud-spanner"
27-
exclude group: "com.google.api.grpc", module: "proto-google-cloud-spanner-v1"
28-
exclude group: "com.google.api.grpc", module: "proto-google-cloud-spanner-admin-instance-v1"
29-
exclude group: "com.google.api.grpc", module: "proto-google-cloud-spanner-admin-database-v1"
30-
exclude group: "com.google.api.grpc", module: "grpc-google-cloud-spanner-v1"
31-
exclude group: "com.google.api.grpc", module: "grpc-google-cloud-spanner-admin-instance-v1"
32-
exclude group: "com.google.api.grpc", module: "grpc-google-cloud-spanner-admin-database-v1"
33-
}
23+
api platform(project.library.java.google_cloud_platform_libraries_bom)
3424
constraints {
3525
api project.library.java.guava
3626
}
@@ -42,4 +32,4 @@ publishing {
4232
artifactId = 'beam-sdks-java-google-cloud-platform-bom'
4333
}
4434
}
45-
}
35+
}

sdks/java/io/google-cloud-platform/build.gradle

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,7 @@ description = "Apache Beam :: SDKs :: Java :: IO :: Google Cloud Platform"
3131
ext.summary = "IO library to read and write Google Cloud Platform systems from Beam."
3232

3333
dependencies {
34-
implementation(enforcedPlatform(library.java.google_cloud_platform_libraries_bom)) {
35-
// TODO(https://github.com/apache/beam/issues/35868) remove exclude after upstream and/or tests fixed
36-
exclude group: "com.google.cloud", module: "google-cloud-spanner"
37-
exclude group: "com.google.api.grpc", module: "proto-google-cloud-spanner-v1"
38-
exclude group: "com.google.api.grpc", module: "proto-google-cloud-spanner-admin-instance-v1"
39-
exclude group: "com.google.api.grpc", module: "proto-google-cloud-spanner-admin-database-v1"
40-
exclude group: "com.google.api.grpc", module: "grpc-google-cloud-spanner-v1"
41-
exclude group: "com.google.api.grpc", module: "grpc-google-cloud-spanner-admin-instance-v1"
42-
exclude group: "com.google.api.grpc", module: "grpc-google-cloud-spanner-admin-database-v1"
43-
}
44-
implementation(enforcedPlatform(library.java.google_cloud_spanner_bom))
34+
implementation(enforcedPlatform(library.java.google_cloud_platform_libraries_bom))
4535
implementation project(path: ":model:pipeline", configuration: "shadow")
4636
implementation project(":runners:core-java")
4737
implementation project(path: ":sdks:java:core", configuration: "shadow")
@@ -362,4 +352,4 @@ task postCommit {
362352
description = "Integration tests of GCP connectors using the DirectRunner."
363353
dependsOn integrationTest
364354
dependsOn integrationTestKms
365-
}
355+
}

sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerAccessor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.google.cloud.spanner.DatabaseAdminClient;
3131
import com.google.cloud.spanner.DatabaseClient;
3232
import com.google.cloud.spanner.DatabaseId;
33+
import com.google.cloud.spanner.SessionPoolOptions;
3334
import com.google.cloud.spanner.Spanner;
3435
import com.google.cloud.spanner.SpannerOptions;
3536
import com.google.cloud.spanner.v1.stub.SpannerStubSettings;
@@ -38,6 +39,7 @@
3839
import com.google.spanner.v1.ExecuteSqlRequest;
3940
import com.google.spanner.v1.PartialResultSet;
4041
import java.util.HashSet;
42+
import java.util.Optional;
4143
import java.util.Set;
4244
import java.util.concurrent.ConcurrentHashMap;
4345
import org.apache.beam.sdk.options.ValueProvider;
@@ -61,6 +63,8 @@ public class SpannerAccessor implements AutoCloseable {
6163
*/
6264
private static final String USER_AGENT_PREFIX = "Apache_Beam_Java";
6365

66+
private static final java.time.Duration DEFAULT_SESSION_WAIT_DURATION = java.time.Duration.ofMinutes(5);
67+
6468
/** Instance ID to use when connecting to an experimental host. */
6569
public static final String EXPERIMENTAL_HOST_INSTANCE_ID = "default";
6670

@@ -113,6 +117,9 @@ public static SpannerAccessor getOrCreate(SpannerConfig spannerConfig) {
113117
static SpannerOptions buildSpannerOptions(SpannerConfig spannerConfig) {
114118
SpannerOptions.Builder builder = SpannerOptions.newBuilder();
115119

120+
// Disable gRPC gcp extension which was causing the application thread to stall.
121+
builder.disableGrpcGcpExtension();
122+
116123
Set<Code> retryableCodes = new HashSet<>();
117124
if (spannerConfig.getRetryableCodes() != null) {
118125
retryableCodes.addAll(spannerConfig.getRetryableCodes());
@@ -265,6 +272,14 @@ static SpannerOptions buildSpannerOptions(SpannerConfig spannerConfig) {
265272
builder.setCredentials(credentials.get());
266273
}
267274

275+
ValueProvider<java.time.Duration> waitForSessionCreationDuration =
276+
spannerConfig.getWaitForSessionCreationDuration();
277+
java.time.Duration waitDuration = Optional.ofNullable(waitForSessionCreationDuration)
278+
.map(ValueProvider::get)
279+
.orElse(DEFAULT_SESSION_WAIT_DURATION);
280+
builder.setSessionPoolOption(
281+
SessionPoolOptions.newBuilder().setWaitForMinSessionsDuration(waitDuration).build());
282+
268283
return builder.build();
269284
}
270285

sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerConfig.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public String getHostValue() {
104104

105105
public abstract @Nullable ValueProvider<Credentials> getCredentials();
106106

107+
public abstract @Nullable ValueProvider<java.time.Duration> getWaitForSessionCreationDuration();
108+
107109
abstract Builder toBuilder();
108110

109111
public static SpannerConfig create() {
@@ -189,6 +191,8 @@ abstract Builder setExecuteStreamingSqlRetrySettings(
189191

190192
abstract Builder setPlainText(ValueProvider<Boolean> plainText);
191193

194+
abstract Builder setWaitForSessionCreationDuration(ValueProvider<java.time.Duration> waitForSessionCreationDuration);
195+
192196
public abstract SpannerConfig build();
193197
}
194198

@@ -389,4 +393,22 @@ public SpannerConfig withUsingPlainTextChannel(ValueProvider<Boolean> plainText)
389393
public SpannerConfig withUsingPlainTextChannel(boolean plainText) {
390394
return withUsingPlainTextChannel(ValueProvider.StaticValueProvider.of(plainText));
391395
}
396+
397+
/**
398+
* @param waitForSessionCreationDuration
399+
* @return {@link SpannerConfig}
400+
* <p>Sets the wait time for multiplexed session to be available while creating a database
401+
* client. Setting this will block the {@link com.google.cloud.spanner.DatabaseClient}
402+
* creation. By default, We will be setting 5 mins as minimum wait time.
403+
*/
404+
public SpannerConfig withWaitForSessionCreationDuration(
405+
ValueProvider<java.time.Duration> waitForSessionCreationDuration) {
406+
return toBuilder().setWaitForSessionCreationDuration(waitForSessionCreationDuration).build();
407+
}
408+
409+
public SpannerConfig withWaitForSessionCreationDuration(
410+
java.time.Duration waitForSessionCreationDuration) {
411+
return withWaitForSessionCreationDuration(
412+
ValueProvider.StaticValueProvider.of(waitForSessionCreationDuration));
413+
}
392414
}

sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerIO.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,10 +2109,9 @@ private static Dialect getDialect(SpannerConfig spannerConfig, PipelineOptions p
21092109
// Allow passing the credential from pipeline options to the getDialect() call.
21102110
SpannerConfig spannerConfigWithCredential =
21112111
buildSpannerConfigWithCredential(spannerConfig, pipelineOptions);
2112-
try (SpannerAccessor sa = SpannerAccessor.getOrCreate(spannerConfigWithCredential)) {
2113-
DatabaseClient databaseClient = sa.getDatabaseClient();
2114-
return databaseClient.getDialect();
2115-
}
2112+
SpannerAccessor sa = SpannerAccessor.getOrCreate(spannerConfigWithCredential);
2113+
DatabaseClient databaseClient = sa.getDatabaseClient();
2114+
return databaseClient.getDialect();
21162115
}
21172116

21182117
/**

0 commit comments

Comments
 (0)