Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 public methods to use autogenerated admin clients. #2878
feat: support public methods to use autogenerated admin clients. #2878
Changes from 21 commits
edc5bbf
49a85df
4cd497b
4a6aa8e
b2aa09d
8d6d71e
77e6e7d
e8b7fad
8aa84e1
57fd405
1253563
d4f6a60
3efaf7c
f41b39f
7e3287f
5d090ea
5c9c2e4
bd4156b
8b5d800
500fd02
832077e
0be2719
ab05f88
bb41cf7
3e8caa2
f71a4c1
8330718
d7f70fa
07c9cd1
447ec3a
3dd7017
543fed9
53d4c7b
d8d6a5b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
This method returns an instance of
com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient
. That interface implementsAutoCloseable
. That again means that most users will be inclined to put it in atry-with-resources
block, or in some other way close it when they are done. If they do that, then the underlyingstub
that is used by the client will be closed, which again is a shared object, and means that all existing and also future instances that will be returned by this method will use a closed stub.So we need to make a choice here whether:
close()
on the instance that is returned.close()
behavior. The modified behavior could either be to do nothing, or to throw an exception that indicates that this instance is managed by theSpanner
instance that created it.I think that option 3 is the safest option.
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.
Thanks for the catch!
Thinking a bit more on the issue, I think its due to the dependency on the
stub
making it a shared resource when it should not have been one. Another approach which I explored was to make use of the sharedDatabaseAdminStubSettings
andInstanceAdminStubSettings
objects and creating a newstub
objects from these settings by doing something likegapicRpc.getDatabaseAdminStubSettings().createStub()
. This will ensure we avoid the coupling and at the same time are able to re-use all the code ofGapicSpannerRpc
for creating the settings.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.
Based on offline conversations, we found an additional issue. For ex - refer the below snippet where we would still up see the shared stub behavior.
I explored two other approaches based on @olavloite 's suggestion
ManagedDatabaseAdminClient
which extends theDatabaseAdminClient
class and overrides theclose()
method. This is not possible to implement since the method is marked as final and hence we cannot override it.DatabaseAdminClient
does not implement any interface that can supply all its methods.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.
We are settling for an approach where we return a new instance each time a client object is requested. This makes sure we don't run into any edge cases (like discussed above). At the same time, we have captured in the method documentation that customers may choose to cache the instances based on their application side code.