-
Notifications
You must be signed in to change notification settings - Fork 123
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
chore: add a system property to set session pool ordering #2656
Conversation
Adds support for using a System property to set the default session pool ordering. The default ordering is LIFO. This can be changed to FIFO and RANDOM for users who need/want that.
|
||
private Clock poolMaintainerClock; | ||
|
||
private static Position getReleaseToPositionFromSystemProperty() { | ||
// NOTE: This System property is a beta feature. Support for it can be removed in the future. | ||
String key = "SESSION_POOL_RELEASE_TO_POSITION"; |
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.
Maybe namespace this as com.google.cloud.spanner.session_pool_release_to_position
?
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.
Yes, that is more idiomatic for System properties. All caps is for environment variables.
|
||
private Clock poolMaintainerClock; | ||
|
||
private static Position getReleaseToPositionFromSystemProperty() { | ||
// NOTE: This System property is a beta feature. Support for it can be removed in the future. | ||
String key = "SESSION_POOL_RELEASE_TO_POSITION"; |
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.
Should we name this SPANNER_SESSION_POOL_RELEASE_TO_POSITION
so that its easy for customers to identify that this one is being used for Spanner?
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.
As discussed offline, we'll go for the namespaced name com.google.cloud.spanner.session_pool_release_to_position
.
Session session3 = pool.getSession().get(); | ||
Session session4 = pool.getSession().get(); | ||
assertEquals(session2, session3); | ||
assertEquals(session4, session1); |
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: swap the expected/actual value
assertEquals(session4, session1); | |
assertEquals(session1, session4); |
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.
Done
.collect(Collectors.toList()); | ||
switch (position) { | ||
case FIRST: | ||
// FIFO: |
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.
Isn't this LIFO? Since the last element N
will be added to the first, and we always poll from the front, we would always have the last one polled first.
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.
Eh, yes. Hence my comment about the naming being a bit confusing, I managed to confuse myself as well here.
assertEquals(firstTime, Lists.reverse(secondTime)); | ||
break; | ||
case LAST: | ||
// LIFO: |
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.
Similarly isn't this FIFO? Given everything gets added to the end of the queue, whatever was added first, will be removed first. No?
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.
Yep
String key = "SESSION_POOL_RELEASE_TO_POSITION"; | ||
if (System.getProperties().containsKey(key)) { | ||
try { | ||
return Position.valueOf(System.getProperty(key).toUpperCase(Locale.ENGLISH)); |
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.
Would it be useful to add some logging for the case when this environment variable is set? Just so that if we run into any un-intended cases where a few other customers discover this option and set this, we at-least know if this option got set?
Logging is the minimum we can do, apart from adding to the trace?
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 wouldn't be able to see the logging, except if we add a gRPC header, and I don't think it's worth the latter. I don't worry about anyone finding and enabling this option on their own (and if they do, they probably also turn it off if they feel that it does not work well for them).
(retroactive LGTM from me as well) |
Adds support for using a System property to set the default session pool ordering. The default ordering is LIFO. This can be changed to FIFO and RANDOM for users who need/want that.