|
29 | 29 | import com.google.api.gax.grpc.GrpcCallContext;
|
30 | 30 | import com.google.api.gax.grpc.GrpcCallSettings;
|
31 | 31 | import com.google.api.gax.grpc.GrpcStubCallableFactory;
|
| 32 | +import com.google.api.gax.grpc.GrpcTransportChannel; |
32 | 33 | import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
|
33 | 34 | import com.google.api.gax.longrunning.OperationFuture;
|
34 | 35 | import com.google.api.gax.retrying.ResultRetryAlgorithm;
|
|
78 | 79 | import com.google.cloud.spanner.admin.instance.v1.stub.InstanceAdminStub;
|
79 | 80 | import com.google.cloud.spanner.admin.instance.v1.stub.InstanceAdminStubSettings;
|
80 | 81 | import com.google.cloud.spanner.encryption.EncryptionConfigProtoMapper;
|
81 |
| -import com.google.cloud.spanner.v1.stub.GrpcSpannerStub; |
82 | 82 | import com.google.cloud.spanner.v1.stub.SpannerStub;
|
83 | 83 | import com.google.cloud.spanner.v1.stub.SpannerStubSettings;
|
84 | 84 | import com.google.common.annotations.VisibleForTesting;
|
85 | 85 | import com.google.common.base.Function;
|
86 | 86 | import com.google.common.base.MoreObjects;
|
87 | 87 | import com.google.common.base.Preconditions;
|
| 88 | +import com.google.common.base.Supplier; |
| 89 | +import com.google.common.base.Suppliers; |
88 | 90 | import com.google.common.collect.ImmutableList;
|
89 | 91 | import com.google.common.collect.ImmutableSet;
|
90 | 92 | import com.google.common.io.Resources;
|
@@ -276,6 +278,8 @@ public class GapicSpannerRpc implements SpannerRpc {
|
276 | 278 | private final int numChannels;
|
277 | 279 | private final boolean isGrpcGcpExtensionEnabled;
|
278 | 280 |
|
| 281 | + private Supplier<Boolean> directPathEnabledSupplier = () -> false; |
| 282 | + |
279 | 283 | public static GapicSpannerRpc create(SpannerOptions options) {
|
280 | 284 | return new GapicSpannerRpc(options);
|
281 | 285 | }
|
@@ -351,7 +355,9 @@ public GapicSpannerRpc(final SpannerOptions options) {
|
351 | 355 | SpannerInterceptorProvider.create(
|
352 | 356 | MoreObjects.firstNonNull(
|
353 | 357 | options.getInterceptorProvider(),
|
354 |
| - SpannerInterceptorProvider.createDefault(options.getOpenTelemetry()))) |
| 358 | + SpannerInterceptorProvider.createDefault( |
| 359 | + options.getOpenTelemetry(), |
| 360 | + (() -> directPathEnabledSupplier.get())))) |
355 | 361 | // This sets the trace context headers.
|
356 | 362 | .withTraceContext(endToEndTracingEnabled, options.getOpenTelemetry())
|
357 | 363 | // This sets the response compressor (Server -> Client).
|
@@ -396,18 +402,27 @@ public GapicSpannerRpc(final SpannerOptions options) {
|
396 | 402 | final String emulatorHost = System.getenv("SPANNER_EMULATOR_HOST");
|
397 | 403 |
|
398 | 404 | try {
|
| 405 | + SpannerStubSettings spannerStubSettings = |
| 406 | + options |
| 407 | + .getSpannerStubSettings() |
| 408 | + .toBuilder() |
| 409 | + .setTransportChannelProvider(channelProvider) |
| 410 | + .setCredentialsProvider(credentialsProvider) |
| 411 | + .setStreamWatchdogProvider(watchdogProvider) |
| 412 | + .setTracerFactory( |
| 413 | + options.getApiTracerFactory( |
| 414 | + /* isAdminClient = */ false, isEmulatorEnabled(options, emulatorHost))) |
| 415 | + .build(); |
| 416 | + ClientContext clientContext = ClientContext.create(spannerStubSettings); |
399 | 417 | this.spannerStub =
|
400 |
| - GrpcSpannerStub.create( |
401 |
| - options |
402 |
| - .getSpannerStubSettings() |
403 |
| - .toBuilder() |
404 |
| - .setTransportChannelProvider(channelProvider) |
405 |
| - .setCredentialsProvider(credentialsProvider) |
406 |
| - .setStreamWatchdogProvider(watchdogProvider) |
407 |
| - .setTracerFactory( |
408 |
| - options.getApiTracerFactory( |
409 |
| - /* isAdminClient = */ false, isEmulatorEnabled(options, emulatorHost))) |
410 |
| - .build()); |
| 418 | + GrpcSpannerStubWithStubSettingsAndClientContext.create( |
| 419 | + spannerStubSettings, clientContext); |
| 420 | + this.directPathEnabledSupplier = |
| 421 | + Suppliers.memoize( |
| 422 | + () -> { |
| 423 | + return ((GrpcTransportChannel) clientContext.getTransportChannel()).isDirectPath() |
| 424 | + && isAttemptDirectPathXds; |
| 425 | + }); |
411 | 426 | this.readRetrySettings =
|
412 | 427 | options.getSpannerStubSettings().streamingReadSettings().getRetrySettings();
|
413 | 428 | this.readRetryableCodes =
|
@@ -455,7 +470,8 @@ public GapicSpannerRpc(final SpannerOptions options) {
|
455 | 470 | .getStreamWatchdogProvider()
|
456 | 471 | .withCheckInterval(pdmlSettings.getStreamWatchdogCheckInterval()));
|
457 | 472 | }
|
458 |
| - this.partitionedDmlStub = GrpcSpannerStub.create(pdmlSettings.build()); |
| 473 | + this.partitionedDmlStub = |
| 474 | + GrpcSpannerStubWithStubSettingsAndClientContext.create(pdmlSettings.build()); |
459 | 475 | this.instanceAdminStubSettings =
|
460 | 476 | options
|
461 | 477 | .getInstanceAdminStubSettings()
|
|
0 commit comments