Skip to content
Permalink
Browse files
feat: attempt DirectPath by default (#770)
* chore: add DirectPath fallback integration test

* feat: attemp DirectPath by default

* feat: attemp DirectPath by default
  • Loading branch information
mohanli-ml committed Jan 6, 2021
1 parent f26d552 commit dc02244d5ad29715f0c5d4c0ba8070659744c512
@@ -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 <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> 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,
@@ -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);
}

0 comments on commit dc02244

Please sign in to comment.