-
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
Spanner: Do not hand out a closed Spanner instance from SpannerOptions.getService() #5187
Spanner: Do not hand out a closed Spanner instance from SpannerOptions.getService() #5187
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5187 +/- ##
=========================================
Coverage 50.4% 50.4%
Complexity 23785 23785
=========================================
Files 2251 2251
Lines 226792 226792
Branches 24966 24966
=========================================
Hits 114320 114320
Misses 103865 103865
Partials 8607 8607 Continue to review full report at Codecov.
|
SpannerOptions caches any Spanner instance that has been created, and hands this cached instance out to all subsequent calls to SpannerOptions.getService(). This also included closed Spanner instances. The getService() method now returns an error if the Spanner instance has already been closed.
1b723dd
to
d2c1746
Compare
I would err on side of caution when returning errors/exception. I would prefer we either evict entries from cache on closing spanner instances OR try getting another entry from the cache if at all it is closed. |
There's no real cache in this case. The default behavior is defined in the base class of SpannerOptions, public ServiceT getService() {
if (service == null) {
service = serviceFactory.create((OptionsT) this);
}
return service;
} Overriding this method and returning a new instance instead of an existing (closed) instance, is possible. |
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.
Can we explore something like what Sneha is suggesting and not throw an error back to the user?
The
A quick scan of other |
I think option 3 is what I'm leaning toward, and I think it is closest to what @snehashah16 suggested (instead of throw an error, have the library manage and handle). |
I vote for #3 as well. Just to be sure, it will return the same instance if
the same Spanner options are passed in.
…On Fri, May 17, 2019, 8:14 AM kolea2 ***@***.***> wrote:
I think option 3 is what I'm leaning toward, and I think it is closest to
what @snehashah16 <https://github.com/snehashah16> suggested (instead of
throw an error, have the library manage and handle).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5187?email_source=notifications&email_token=AGX7VPFZIQXRYFN5XJD3ECLPV3DVJA5CNFSM4HNAHPM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVVBEUY#issuecomment-493490771>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGX7VPCBPHZZVLEA3E6H33LPV3DVJANCNFSM4HNAHPMQ>
.
|
In option 3: SpannerOptions.getService() will return the same Spanner instance as long as the Spanner instance has not been closed. Once the instance has been closed, SpannerOptions.getService() will create a new instance and start returning that instance. This new instance will have the exact same properties and behave the same as the initial instance, but it will not be the same instance. It is not possible to reopen an already closed Spanner instance. The potential downside that I see with this approach is that we 'encourage' opening and closing Spanner instances during the lifetime of an application, while users should normally keep a Spanner instance open during the entire lifetime of the application. Closing a Spanner instance means that its session pool will be closed and all sessions will be deleted. Opening a new Spanner instance means initializing a new session pool. It's a small change, so I'll make a separate PR with option 3 so it can be reviewed. |
I think the correct usage is SpannerOptions.getDefaultInstance().getService() or something like this SpannerOptions.getDefaultInstance().toBuilder().set*().build().getService() once the service returned by the SpannerOption is closed. ServiceOptions is not meant to be a factory for Service. |
Option #3 should cache the service and Rpc, until it's closed. After that, it should create a new Service/Rpc and cache it until it's closed (and repeat). That seems like a straightforward algorithm. |
@sduskis @ajaaym @kolea2
|
@olavloite, I don't see how the service is cached after the initial service is closed. Perhaps we can do a VC. |
Closing in favor of #5200 |
SpannerOptions caches any Spanner instance that has been created, and hands this cached instance out to all subsequent calls to SpannerOptions.getService(). This also included closed Spanner instances. The getService() method now returns an error if the Spanner instance has already been closed.