|
64 | 64 | import com.google.cloud.grpc.GrpcTransportOptions;
|
65 | 65 | import com.google.cloud.spanner.AdminRequestsPerMinuteExceededException;
|
66 | 66 | import com.google.cloud.spanner.BackupId;
|
67 |
| -import com.google.cloud.spanner.BuiltInMetricsConstant; |
68 | 67 | import com.google.cloud.spanner.ErrorCode;
|
69 | 68 | import com.google.cloud.spanner.Restore;
|
70 | 69 | import com.google.cloud.spanner.SpannerException;
|
|
80 | 79 | import com.google.cloud.spanner.admin.instance.v1.stub.InstanceAdminStub;
|
81 | 80 | import com.google.cloud.spanner.admin.instance.v1.stub.InstanceAdminStubSettings;
|
82 | 81 | import com.google.cloud.spanner.encryption.EncryptionConfigProtoMapper;
|
83 |
| -import com.google.cloud.spanner.v1.stub.GrpcSpannerStubWrapper; |
84 | 82 | import com.google.cloud.spanner.v1.stub.SpannerStub;
|
85 | 83 | import com.google.cloud.spanner.v1.stub.SpannerStubSettings;
|
86 | 84 | import com.google.common.annotations.VisibleForTesting;
|
87 | 85 | import com.google.common.base.Function;
|
88 | 86 | import com.google.common.base.MoreObjects;
|
89 | 87 | import com.google.common.base.Preconditions;
|
| 88 | +import com.google.common.base.Supplier; |
| 89 | +import com.google.common.base.Suppliers; |
90 | 90 | import com.google.common.collect.ImmutableList;
|
91 | 91 | import com.google.common.collect.ImmutableSet;
|
92 | 92 | import com.google.common.io.Resources;
|
@@ -278,6 +278,11 @@ public class GapicSpannerRpc implements SpannerRpc {
|
278 | 278 | private final int numChannels;
|
279 | 279 | private final boolean isGrpcGcpExtensionEnabled;
|
280 | 280 |
|
| 281 | + private Supplier<Boolean> directPathEnabledSupplier = |
| 282 | + () -> { |
| 283 | + return false; |
| 284 | + };; |
| 285 | + |
281 | 286 | public static GapicSpannerRpc create(SpannerOptions options) {
|
282 | 287 | return new GapicSpannerRpc(options);
|
283 | 288 | }
|
@@ -353,7 +358,9 @@ public GapicSpannerRpc(final SpannerOptions options) {
|
353 | 358 | SpannerInterceptorProvider.create(
|
354 | 359 | MoreObjects.firstNonNull(
|
355 | 360 | options.getInterceptorProvider(),
|
356 |
| - SpannerInterceptorProvider.createDefault(options.getOpenTelemetry()))) |
| 361 | + SpannerInterceptorProvider.createDefault( |
| 362 | + options.getOpenTelemetry(), |
| 363 | + (() -> directPathEnabledSupplier.get())))) |
357 | 364 | // This sets the trace context headers.
|
358 | 365 | .withTraceContext(endToEndTracingEnabled, options.getOpenTelemetry())
|
359 | 366 | // This sets the response compressor (Server -> Client).
|
@@ -410,10 +417,15 @@ public GapicSpannerRpc(final SpannerOptions options) {
|
410 | 417 | /* isAdminClient = */ false, isEmulatorEnabled(options, emulatorHost)))
|
411 | 418 | .build();
|
412 | 419 | ClientContext clientContext = ClientContext.create(spannerStubSettings);
|
413 |
| - this.spannerStub = GrpcSpannerStubWrapper.create(spannerStubSettings, clientContext); |
414 |
| - BuiltInMetricsConstant.DIRECT_PATH_ENABLED = |
415 |
| - ((GrpcTransportChannel) clientContext.getTransportChannel()).isDirectPath() |
416 |
| - && isAttemptDirectPathXds; |
| 420 | + this.spannerStub = |
| 421 | + GrpcSpannerStubWithStubSettingsAndClientContext.create( |
| 422 | + spannerStubSettings, clientContext); |
| 423 | + this.directPathEnabledSupplier = |
| 424 | + Suppliers.memoize( |
| 425 | + () -> { |
| 426 | + return ((GrpcTransportChannel) clientContext.getTransportChannel()).isDirectPath() |
| 427 | + && isAttemptDirectPathXds; |
| 428 | + }); |
417 | 429 | this.readRetrySettings =
|
418 | 430 | options.getSpannerStubSettings().streamingReadSettings().getRetrySettings();
|
419 | 431 | this.readRetryableCodes =
|
@@ -461,7 +473,8 @@ public GapicSpannerRpc(final SpannerOptions options) {
|
461 | 473 | .getStreamWatchdogProvider()
|
462 | 474 | .withCheckInterval(pdmlSettings.getStreamWatchdogCheckInterval()));
|
463 | 475 | }
|
464 |
| - this.partitionedDmlStub = GrpcSpannerStubWrapper.create(pdmlSettings.build()); |
| 476 | + this.partitionedDmlStub = |
| 477 | + GrpcSpannerStubWithStubSettingsAndClientContext.create(pdmlSettings.build()); |
465 | 478 | this.instanceAdminStubSettings =
|
466 | 479 | options
|
467 | 480 | .getInstanceAdminStubSettings()
|
|
0 commit comments