From dc02244d5ad29715f0c5d4c0ba8070659744c512 Mon Sep 17 00:00:00 2001 From: Mohan Li <67390330+mohanli-ml@users.noreply.github.com> Date: Tue, 5 Jan 2021 18:28:11 -0800 Subject: [PATCH] feat: attempt DirectPath by default (#770) * chore: add DirectPath fallback integration test * feat: attemp DirectPath by default * feat: attemp DirectPath by default --- .../cloud/spanner/spi/v1/GapicSpannerRpc.java | 18 ++++-------------- .../google/cloud/spanner/GceTestEnvConfig.java | 9 +++++++++ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java index efa07fc961..5172fe448f 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java @@ -245,9 +245,6 @@ private void awaitTermination() throws InterruptedException { private static final String USER_AGENT_KEY = "user-agent"; private static final String CLIENT_LIBRARY_LANGUAGE = "spanner-java"; - // TODO(weiranf): Remove this temporary endpoint once DirectPath goes to public beta. - private static final String DIRECT_PATH_ENDPOINT = "aa423245250f2bbf.sandbox.googleapis.com:443"; - private final ManagedInstantiatingExecutorProvider executorProvider; private boolean rpcIsClosed; private final SpannerStub spannerStub; @@ -361,12 +358,10 @@ public GapicSpannerRpc(final SpannerOptions options) { options.getInterceptorProvider(), SpannerInterceptorProvider.createDefault())) .withEncoding(compressorName)) - .setHeaderProvider(headerProviderWithUserAgent); - - // TODO(weiranf): Set to true by default once DirectPath goes to public beta. - if (shouldAttemptDirectPath()) { - defaultChannelProviderBuilder.setEndpoint(DIRECT_PATH_ENDPOINT).setAttemptDirectPath(true); - } + .setHeaderProvider(headerProviderWithUserAgent) + // Attempts direct access to spanner service over gRPC to improve throughput, + // whether the attempt is allowed is totally controlled by service owner. + .setAttemptDirectPath(true); TransportChannelProvider channelProvider = MoreObjects.firstNonNull( @@ -499,11 +494,6 @@ public UnaryCallable createUnaryCalla } } - // TODO(weiranf): Remove this once DirectPath goes to public beta. - private static boolean shouldAttemptDirectPath() { - return Boolean.getBoolean("spanner.attempt_directpath"); - } - private static void checkEmulatorConnection( SpannerOptions options, TransportChannelProvider channelProvider, diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GceTestEnvConfig.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GceTestEnvConfig.java index 62787aa498..c78dfa8f46 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GceTestEnvConfig.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/GceTestEnvConfig.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkState; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.spanner.spi.v1.SpannerInterceptorProvider; import io.grpc.CallOptions; @@ -52,6 +53,8 @@ public class GceTestEnvConfig implements TestEnvConfig { public static final String DP_IPV6_PREFIX = "2001:4860:8040"; public static final String DP_IPV4_PREFIX = "34.126"; + private static final String DIRECT_PATH_ENDPOINT = "aa423245250f2bbf.sandbox.googleapis.com:443"; + private final SpannerOptions options; public GceTestEnvConfig() { @@ -67,6 +70,12 @@ public GceTestEnvConfig() { SpannerOptions.newBuilder() .setAutoThrottleAdministrativeRequests() .setTrackTransactionStarter(); + InstantiatingGrpcChannelProvider.Builder defaultChannelProviderBuilder = + InstantiatingGrpcChannelProvider.newBuilder(); + if (attemptDirectPath) { + builder.setChannelProvider( + defaultChannelProviderBuilder.setEndpoint(DIRECT_PATH_ENDPOINT).build()); + } if (!projectId.isEmpty()) { builder.setProjectId(projectId); }