docs: add sample for setting timeout and retry settings#3445
Conversation
| // Set custom timeout and retry settings for the ExecuteSql RPC. | ||
| builder | ||
| .getSpannerStubSettingsBuilder() | ||
| .executeSqlSettings() | ||
| // Configure which errors should be retried. | ||
| .setRetryableCodes(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE) | ||
| .setRetrySettings( | ||
| RetrySettings.newBuilder() | ||
| // Configure retry delay settings. | ||
| .setInitialRetryDelay(Duration.ofMillis(500)) | ||
| .setMaxRetryDelay(Duration.ofSeconds(64)) | ||
| .setRetryDelayMultiplier(1.5) | ||
|
|
||
| // Configure RPC and total timeout settings. | ||
| .setInitialRpcTimeout(Duration.ofSeconds(60)) | ||
| .setMaxRpcTimeout(Duration.ofSeconds(60)) | ||
| .setRpcTimeoutMultiplier(1.0) | ||
| .setTotalTimeout(Duration.ofSeconds(60)) | ||
| .build()); |
There was a problem hiding this comment.
This just looks weird, it took me a while to understand what was going on. I'm not sure how you fix it, but, I wonder if the .setProjectId(projectId) shouldn't be the first thing in this group, or, if you should do all the options on the SpannerOptions.Builder builder = line(s).
There was a problem hiding this comment.
The problem here is that the setRetryableCodes(..) and setRetrySettings(..) methods return a UnaryCallSettings.Builder instance, and not a SpannerOptions.Builder, and that cannot (easily) be changed as it is part of the generated gapic client. What we are really doing here is exposing a part of the generated gapic client (builder) for the end user to be able to specify timeout and retry settings. That means that it is not possible to create the SpannerOptions instance in one single chain when this option is used, but that it must have at least one separate chain that sets the custom retry and/or timeout settings.
Adding the .setProjectId(projectId) to this group is possible, but I don't feel that it makes it more readable. I added a comment to clarify why the retry settings are set in a separate chain.
lesv
left a comment
There was a problem hiding this comment.
LGTM - but I have one question.
|
Odd - I changed the question before I sent the review and it sent the old question. Please see in the PR. |
lesv
left a comment
There was a problem hiding this comment.
That's why I ask questions, I wasn't expecting that answer. Good that you explain it.
Adds an example for how to set custom timeout and retry settings for the Spanner client.