Skip to content

Commit 0184554

Browse files
HailongWentlhquynh
authored andcommitted
feat: allow attempt direct path xds via env var (googleapis#2950)
To enable Direct Access, [both `setAttemptDirectPath` and `setAttemptDirectPathXds` should be called](https://togithub.com/googleapis/sdk-platform-java/blob/4b44a7851dc1d4fd2ac21a54df6c24db5625223c/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java#L373-L386) for gax to append the correct google-c2p scheme. This PR adds a env var `GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS` to control the enable/disable of Direct Access. When it is true, it calls `setAttemptDirectPathXds` which effectively turns on Direct Access (as `options.isAttemptDirectPath` is by default true and we don't need to call `setAttemptDirectPath` again).
1 parent e505b9e commit 0184554

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java

+5
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ public GapicSpannerRpc(final SpannerOptions options) {
354354
options.isAttemptDirectPath()
355355
&& !Objects.equals(
356356
options.getScopedCredentials(), NoCredentials.getInstance()));
357+
String directPathXdsEnv = System.getenv("GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS");
358+
boolean isAttemptDirectPathXds = Boolean.parseBoolean(directPathXdsEnv);
359+
if (isAttemptDirectPathXds) {
360+
defaultChannelProviderBuilder.setAttemptDirectPathXds();
361+
}
357362
if (options.isUseVirtualThreads()) {
358363
ExecutorService executor =
359364
tryCreateVirtualThreadPerTaskExecutor("spanner-virtual-grpc-executor");

0 commit comments

Comments
 (0)