|
19 | 19 | import static com.google.cloud.spanner.SpannerExceptionFactory.newSpannerException;
|
20 | 20 |
|
21 | 21 | import com.google.api.core.ApiFuture;
|
| 22 | +import com.google.api.core.InternalApi; |
22 | 23 | import com.google.api.core.NanoClock;
|
23 | 24 | import com.google.api.gax.core.CredentialsProvider;
|
24 | 25 | import com.google.api.gax.core.ExecutorProvider;
|
|
54 | 55 | import com.google.cloud.spanner.admin.instance.v1.stub.InstanceAdminStub;
|
55 | 56 | import com.google.cloud.spanner.v1.stub.GrpcSpannerStub;
|
56 | 57 | import com.google.cloud.spanner.v1.stub.SpannerStub;
|
| 58 | +import com.google.cloud.spanner.v1.stub.SpannerStubSettings; |
57 | 59 | import com.google.common.annotations.VisibleForTesting;
|
58 | 60 | import com.google.common.base.Function;
|
59 | 61 | import com.google.common.base.MoreObjects;
|
|
153 | 155 | import org.threeten.bp.Duration;
|
154 | 156 |
|
155 | 157 | /** Implementation of Cloud Spanner remote calls using Gapic libraries. */
|
| 158 | +@InternalApi |
156 | 159 | public class GapicSpannerRpc implements SpannerRpc {
|
157 | 160 | /**
|
158 | 161 | * {@link ExecutorProvider} that keeps track of the executors that are created and shuts these
|
@@ -207,6 +210,7 @@ private synchronized void shutdown() {
|
207 | 210 | private final ManagedInstantiatingExecutorProvider executorProvider;
|
208 | 211 | private boolean rpcIsClosed;
|
209 | 212 | private final SpannerStub spannerStub;
|
| 213 | +private final SpannerStub partitionedDmlStub; |
210 | 214 | private final InstanceAdminStub instanceAdminStub;
|
211 | 215 | private final DatabaseAdminStubSettings databaseAdminStubSettings;
|
212 | 216 | private final DatabaseAdminStub databaseAdminStub;
|
@@ -326,6 +330,22 @@ public GapicSpannerRpc(final SpannerOptions options) {
|
326 | 330 | .setCredentialsProvider(credentialsProvider)
|
327 | 331 | .setStreamWatchdogProvider(watchdogProvider)
|
328 | 332 | .build());
|
| 333 | +SpannerStubSettings.Builder pdmlSettings = options.getSpannerStubSettings().toBuilder(); |
| 334 | +pdmlSettings |
| 335 | +.setTransportChannelProvider(channelProvider) |
| 336 | +.setCredentialsProvider(credentialsProvider) |
| 337 | +.setStreamWatchdogProvider(watchdogProvider) |
| 338 | +.executeSqlSettings() |
| 339 | +.setRetrySettings( |
| 340 | +options |
| 341 | +.getSpannerStubSettings() |
| 342 | +.executeSqlSettings() |
| 343 | +.getRetrySettings() |
| 344 | +.toBuilder() |
| 345 | +.setInitialRpcTimeout(options.getPartitionedDmlTimeout()) |
| 346 | +.setMaxRpcTimeout(options.getPartitionedDmlTimeout()) |
| 347 | +.build()); |
| 348 | +this.partitionedDmlStub = GrpcSpannerStub.create(pdmlSettings.build()); |
329 | 349 |
|
330 | 350 | this.instanceAdminStub =
|
331 | 351 | GrpcInstanceAdminStub.create(
|
@@ -1029,9 +1049,9 @@ public ResultSet executeQuery(ExecuteSqlRequest request, @Nullable Map<Option, ?
|
1029 | 1049 |
|
1030 | 1050 | @Override
|
1031 | 1051 | public ResultSet executePartitionedDml(
|
1032 |
| -ExecuteSqlRequest request, @Nullable Map<Option, ?> options, Duration timeout) { |
1033 |
| -GrpcCallContext context = newCallContext(options, request.getSession(), timeout); |
1034 |
| -return get(spannerStub.executeSqlCallable().futureCall(request, context)); |
| 1052 | +ExecuteSqlRequest request, @Nullable Map<Option, ?> options) { |
| 1053 | +GrpcCallContext context = newCallContext(options, request.getSession()); |
| 1054 | +return get(partitionedDmlStub.executeSqlCallable().futureCall(request, context)); |
1035 | 1055 | }
|
1036 | 1056 |
|
1037 | 1057 | @Override
|
@@ -1191,19 +1211,11 @@ private static <T> T get(final Future<T> future) throws SpannerException {
|
1191 | 1211 |
|
1192 | 1212 | @VisibleForTesting
|
1193 | 1213 | GrpcCallContext newCallContext(@Nullable Map<Option, ?> options, String resource) {
|
1194 |
| -return newCallContext(options, resource, null); |
1195 |
| -} |
1196 |
| - |
1197 |
| -private GrpcCallContext newCallContext( |
1198 |
| -@Nullable Map<Option, ?> options, String resource, Duration timeout) { |
1199 | 1214 | GrpcCallContext context = GrpcCallContext.createDefault();
|
1200 | 1215 | if (options != null) {
|
1201 | 1216 | context = context.withChannelAffinity(Option.CHANNEL_HINT.getLong(options).intValue());
|
1202 | 1217 | }
|
1203 | 1218 | context = context.withExtraHeaders(metadataProvider.newExtraHeaders(resource, projectName));
|
1204 |
| -if (timeout != null) { |
1205 |
| -context = context.withTimeout(timeout); |
1206 |
| -} |
1207 | 1219 | if (callCredentialsProvider != null) {
|
1208 | 1220 | CallCredentials callCredentials = callCredentialsProvider.getCallCredentials();
|
1209 | 1221 | if (callCredentials != null) {
|
|
0 commit comments