Skip to content

Conversation

@olavloite
Copy link
Collaborator

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.

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.
@olavloite olavloite requested a review from arpan14 October 5, 2023 12:44
@olavloite olavloite requested a review from a team as a code owner October 5, 2023 12:44
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: spanner Issues related to the googleapis/java-spanner API. labels Oct 5, 2023

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";
Copy link

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?

Copy link
Collaborator Author

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 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";
Copy link
Contributor

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?

Copy link
Collaborator Author

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);
Copy link
Contributor

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

Suggested change
assertEquals(session4, session1);
assertEquals(session1, session4);

Copy link
Collaborator Author

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:
Copy link
Contributor

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.

Copy link
Collaborator Author

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:
Copy link
Contributor

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?

Copy link
Collaborator Author

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));
Copy link
Contributor

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?

Copy link
Collaborator Author

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).

@olavloite olavloite merged commit 63bcbea into main Oct 5, 2023
@olavloite olavloite deleted the session-pool-order-option branch October 5, 2023 18:36
@c2nes
Copy link

c2nes commented Oct 5, 2023

(retroactive LGTM from me as well)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the googleapis/java-spanner API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants