-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to specify Spanner connect timeout? #3616
Comments
Hello, SpannerSettings.java has timeout settings, and there is a sample code snippet in the class javadoc as an example. |
Hi @meltsufin , Can you be more specific about in what situation Spanner hangs indefinitely? (i.e., which api call/calls) If it's for the LRO methods (e.g., create a database), you could specify a timeout when making the call: Operation<Database, CreateDatabaseMetadata> op =
dbAdminClient.createDatabase(
instanceId,
databaseId,
Arrays.asList(
"CREATE TABLE Singers (\n"
+ " SingerId INT64 NOT NULL,\n"
+ " FirstName STRING(1024),\n"
+ " LastName STRING(1024),\n"
+ " SingerInfo BYTES(MAX)\n"
+ ") PRIMARY KEY (SingerId)",
"CREATE TABLE Albums (\n"
+ " SingerId INT64 NOT NULL,\n"
+ " AlbumId INT64 NOT NULL,\n"
+ " AlbumTitle STRING(MAX)\n"
+ ") PRIMARY KEY (SingerId, AlbumId),\n"
+ " INTERLEAVE IN PARENT Singers ON DELETE CASCADE"));
Database db = op.waitFor(RetryOption.totalTimeout(Duration.ofSeconds(5))).getResult(); We are also working on migrating the spanner library to use gax-java types and there would be timeout/retry settings for all API calls. |
I think the issue is happening on creation of the session. What is the current timeout? Whatever it is, currently there is no way to change it, right? |
@nithinsujir - could u please help here. Could u please verify behavior (infinite retry attempts w/ exponential sleep ?) when it is a retry-able SpannerException ? |
Will take a look. |
@snehashah16 Is this the intended design? I can imagine for transactions where this might be intentional. Do we want to set a retry limit for createSession()? |
@hzyi-google - does the SpannerSettings work in this case (when the client is using the new library) ? Since this is a corner case (of netw issues ), I would be inclined to wait and adopt the new library v/s fixing code that we are in the process of deprecating. |
@snehashah16 Edit: I feel I need to be more clear about this. The gapic migration work does not touch |
@hzyi-google Can you elaborate for my knowledge what is different in the new library? Is there anything from my side to be done? |
@nithinsujir The migrated library will be using the runtime library gax-java to make gRPC calls. Gax also provides a lot of helper utilities to give callers control over the settings of the gRPC calls. For example, As for what needs to be done, please refer to the previous comment I just updated. The tl;dr is to deprecate |
If this problem occurs consistently on one specific VM or server, then there's a good chance that it is the same problem as in #3889 where an SSLHandshakeException is thrown. The first call to Spanner that needs a session will try to create one. That call would end up in an infinite retry loop in the createSession(...) method. This code hangs indefinitely before the fix of #3889 when the client computer does not accept the SSL certificate of the server, and throws an SSLHandshakeException after the fix. SpannerOptions options = SpannerOptions.newBuilder()
.setProjectId("test-project").build();
Spanner spanner = options.getService();
DatabaseClient client = spanner.getDatabaseClient(
DatabaseId.of("test-project", "static-test-instance", "test-db"));
client.singleUse().executeQuery(Statement.of("SELECT 1")); I'll also look into whether it is possible to add a timeout setting for the clients that are using |
…able) The method SpannerImpl#runWithRetries(Callable) did not consider the retry settings that had been set on the SpannerOptions that created it. This could cause certain calls to wait indefinitely without ever breaking off with an exception.
Returning to the original question: It is now possible to specify timeout settings for grpc calls for a final RetrySettings retrySettings =
RetrySettings.newBuilder()
.setInitialRpcTimeout(Duration.ofSeconds(10L))
.setMaxRpcTimeout(Duration.ofSeconds(20L))
.setMaxAttempts(5)
.setTotalTimeout(Duration.ofSeconds(30L))
.build();
SpannerOptions.Builder builder =
SpannerOptions.newBuilder()
.setProjectId("[PROJECT]"));
builder
.getSpannerStubSettingsBuilder()
.applyToAllUnaryMethods(
new ApiFunction<UnaryCallSettings.Builder<?, ?>, Void>() {
@Override
public Void apply(Builder<?, ?> input) {
input.setRetrySettings(retrySettings);
return null;
}
});
Spanner spanner = builder.build().getService(); |
@olavloite I experienced the same situation. I tried to delete 1 billion rows with Partitioned DML, but it failed with [deadline exceeded] error. It seemed like timeout problem. The code is like following
` |
Hi @FengnaLiu SpannerOptions.newBuilder().setPartitionedDmlTimeout(Duration.ofMinutes(60L)).build(); I'm not sure why your code example is giving an error. The following example does not return any errors for me (although it's not the way you should set the timeout for Partitioned DML, use the example above): final RetrySettings retrySettings =
RetrySettings.newBuilder()
.setInitialRpcTimeout(Duration.ofMinutes(60L))
.setMaxRpcTimeout(Duration.ofMinutes(60L))
.setMaxAttempts(5)
.setTotalTimeout(Duration.ofMinutes(60L))
.build();
SpannerOptions.Builder builder = SpannerOptions.newBuilder().setProjectId("my project");
builder
.getSpannerStubSettingsBuilder()
.applyToAllUnaryMethods(
new ApiFunction<UnaryCallSettings.Builder<?, ?>, Void>() {
@Override
public Void apply(Builder<?, ?> input) {
input.setRetrySettings(retrySettings);
return null;
}
});
Spanner spanner = builder.build().getService();
SpannerOptions options = builder.build(); |
@olavloite And the code example you provided is running right and it does seem like not the right way to set timeout for PartitionedDML. Thanks a lot for your useful information. |
That is strange. Would you mind opening a new issue in https://github.com/googleapis/java-spanner/issues for this problem? That makes it easier for others to also chime in if they have any ideas, and to track the progress of this specific problem. |
@olavloite I will open a new issue about this problem. Thanks a lot. |
If the client has some kind of network issue connecting to Spanner, it seems to hang indefinitely. Is there a way to specify the timeout? I don't see anything in
SpannerOptions
.The text was updated successfully, but these errors were encountered: