Uh oh!
There was an error while loading. Please reload this page.
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()#5187olavloite wants to merge 2 commits into
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 8607Continue 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
d2c1746Comparesnehashah16
commented
May 15, 2019
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. |
olavloite
commented
May 15, 2019
There's no real cache in this case. The default behavior is defined in the base class of SpannerOptions, publicServiceTgetService() {
if (service == null) {
service = serviceFactory.create((OptionsT) this);
}
returnservice;
}Overriding this method and returning a new instance instead of an existing (closed) instance, is possible. |
kolea2
left a comment
There was a problem hiding this comment.
Can we explore something like what Sneha is suggesting and not throw an error back to the user?
olavloite
commented
May 17, 2019
The
A quick scan of other |
kolea2
commented
May 17, 2019
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). |
snehashah16
commented
May 18, 2019
via email
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>
.
|
olavloite
commented
May 18, 2019
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. |
ajaaym
commented
May 24, 2019
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. |
sduskis
commented
May 27, 2019
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. |
olavloite
commented
May 27, 2019
@sduskis@ajaaym@kolea2
|
sduskis
commented
May 27, 2019
@olavloite, I don't see how the service is cached after the initial service is closed. Perhaps we can do a VC. |
kolea2
commented
Jun 19, 2019
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.