|
16 | 16 |
|
17 | 17 | package com.google.cloud.firestore.spi.v1;
|
18 | 18 |
|
19 |
| -import com.google.api.core.ApiFunction; |
20 | 19 | import com.google.api.gax.core.BackgroundResource;
|
21 | 20 | import com.google.api.gax.core.GaxProperties;
|
22 | 21 | import com.google.api.gax.grpc.GrpcCallContext;
|
23 | 22 | import com.google.api.gax.grpc.GrpcTransportChannel;
|
| 23 | +import com.google.api.gax.retrying.RetrySettings; |
24 | 24 | import com.google.api.gax.rpc.BidiStreamingCallable;
|
25 | 25 | import com.google.api.gax.rpc.ClientContext;
|
26 | 26 | import com.google.api.gax.rpc.HeaderProvider;
|
27 | 27 | import com.google.api.gax.rpc.NoHeaderProvider;
|
28 | 28 | import com.google.api.gax.rpc.ServerStreamingCallable;
|
29 | 29 | import com.google.api.gax.rpc.TransportChannel;
|
30 |
| -import com.google.api.gax.rpc.UnaryCallSettings; |
31 | 30 | import com.google.api.gax.rpc.UnaryCallable;
|
32 | 31 | import com.google.cloud.NoCredentials;
|
33 | 32 | import com.google.cloud.ServiceOptions;
|
@@ -126,17 +125,38 @@ public GrpcFirestoreRpc(final FirestoreOptions options) throws IOException {
|
126 | 125 |
|
127 | 126 | clientContext = ClientContext.create(settingsBuilder.build());
|
128 | 127 | }
|
129 |
| - ApiFunction<UnaryCallSettings.Builder<?, ?>, Void> retrySettingsSetter = |
130 |
| - builder -> { |
131 |
| - builder.setRetrySettings(options.getRetrySettings()); |
132 |
| - return null; |
133 |
| - }; |
| 128 | + |
134 | 129 | FirestoreStubSettings.Builder firestoreBuilder =
|
135 |
| - FirestoreStubSettings.newBuilder(clientContext) |
136 |
| - .applyToAllUnaryMethods(retrySettingsSetter); |
137 |
| - // Manually apply the retry settings to streaming methods |
138 |
| - firestoreBuilder.runQuerySettings().setRetrySettings(options.getRetrySettings()); |
139 |
| - firestoreBuilder.batchGetDocumentsSettings().setRetrySettings(options.getRetrySettings()); |
| 130 | + FirestoreStubSettings.newBuilder(clientContext); |
| 131 | + RetrySettings retrySettings = options.getRetrySettings(); |
| 132 | + |
| 133 | + // Override retry settings only if customer provides settings different from default. |
| 134 | + if (retrySettings.equals(ServiceOptions.getDefaultRetrySettings())) { |
| 135 | + // We are manually setting `setMaxAttempts(5)` to follow |
| 136 | + // the `firestore_grpc_service_config.json` configuration. |
| 137 | + // This code should be removed when following issue is fixed: |
| 138 | + // https://github.com/googleapis/sdk-platform-java/issues/2306 |
| 139 | + firestoreBuilder.applyToAllUnaryMethods( |
| 140 | + builder -> { |
| 141 | + builder.retrySettings().setMaxAttempts(5); |
| 142 | + return null; |
| 143 | + }); |
| 144 | + // Manually apply the retry settings to streaming methods |
| 145 | + firestoreBuilder.runQuerySettings().retrySettings().setMaxAttempts(5); |
| 146 | + firestoreBuilder.runAggregationQuerySettings().retrySettings().setMaxAttempts(5); |
| 147 | + firestoreBuilder.batchGetDocumentsSettings().retrySettings().setMaxAttempts(5); |
| 148 | + } else { |
| 149 | + firestoreBuilder.applyToAllUnaryMethods( |
| 150 | + builder -> { |
| 151 | + builder.setRetrySettings(retrySettings); |
| 152 | + return null; |
| 153 | + }); |
| 154 | + // Manually apply the retry settings to streaming methods |
| 155 | + firestoreBuilder.runQuerySettings().setRetrySettings(retrySettings); |
| 156 | + firestoreBuilder.runAggregationQuerySettings().setRetrySettings(retrySettings); |
| 157 | + firestoreBuilder.batchGetDocumentsSettings().setRetrySettings(retrySettings); |
| 158 | + } |
| 159 | + |
140 | 160 | firestoreStub = GrpcFirestoreStub.create(firestoreBuilder.build());
|
141 | 161 | } catch (Exception e) {
|
142 | 162 | throw new IOException(e);
|
|
0 commit comments