-
Notifications
You must be signed in to change notification settings - Fork 128
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
feat: support setting timeout per RPC #379
Conversation
The Spanner client allows a user to set custom timeouts while creating a SpannerOptions instance, but these timeouts are static and are applied to all invocations of the RPCs. This change introduces the possibility to set custom timeouts and other call options on a per-RPC basis. Fixes #378
@olavloite Do you have any idea why |
google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/SpannerRpc.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpcTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpcTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, using Context looks okay to me. My concerns are:
- Handwritten code need to be maintained. E.g., we need to call different timeout setting methods to different RPCs. If we need to add a new RPC, we need to add the timeout and its related methods here.
- I wonder if there is a way to rely on the underlying
gax-java
and gapic generated code to implement this feature instead of using Context? E.g.,
client
.singleUse()
.executeQuery(
Statement.of(
"SELECT SingerId, FirstName, LastName FROM Singers ORDER BY LastName")
),
callOptions, // This includes timeout and retry policy?
)
The above code is my imagination according to the Ruby version: https://github.com/googleapis/google-cloud-ruby/blob/4dcf29950885d8ac3dec41d219f06b843c638a8e/google-cloud-spanner/lib/google/cloud/spanner/client.rb#L351-L372
Yes, that is correct, but I'm afraid that there is no real way of circumventing that in the Java client. The Java client really hides away most gRPC details, especially for the data client, so if we want to support RPC specific timeouts, it will always include some handwritten code. Note that the
This solution does use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nits: there is an unresolved comment.
Sorry, missed that one, but fixed now. |
if (spannerMethod == null) { | ||
return null; | ||
} | ||
switch (SpannerMethod.valueOf(request, method)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit (don't have to change this, just a suggestion): it might be easier to test this / encapsulate the logic if we use a visitor pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's probably a good idea. We would still need some kind of lookup table for the timeout / method combination (i.e. keeping them in a hash map or something), but it might make it somewhat simpler. I'll do that in a separate PR, as it won't change the public interface of it.
* feat: support setting timeout per RPC The Spanner client allows a user to set custom timeouts while creating a SpannerOptions instance, but these timeouts are static and are applied to all invocations of the RPCs. This change introduces the possibility to set custom timeouts and other call options on a per-RPC basis. Fixes googleapis#378 * fix: change grpc deps from test to compile scope * fix: address review comments * fix: resolve review comment
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
The Spanner client allows a user to set custom timeouts while creating a SpannerOptions instance, but these timeouts are static and are applied to all invocations of the RPCs. This change introduces the possibility to set custom timeouts and other call options on a per-RPC basis.
This feature will also be very useful for the Async Connection API, as it will allow applying the statement timeouts for async calls on a per RPC-invocation basis.
Fixes #378