Skip to content

spanner: Enhance session pool behavior#2026

Merged
vkedia merged 18 commits intogoogleapis:masterfrom
vkedia:session-pool-exception
May 12, 2017
Merged

spanner: Enhance session pool behavior#2026
vkedia merged 18 commits intogoogleapis:masterfrom
vkedia:session-pool-exception

Conversation

@vkedia
Copy link

@vkedia vkedia commented May 1, 2017

  • Change defaults for maxSessions and blockIfExhauseted
  • Added tracking of leaked sessions
  • Changed closeAsync to close leaked sessions as well.
  • Changed closeAsync to close pool maintenance worker as well.
  • Added a SessionPoolStressTester
  • Changed Spanner#closeAsync to be blocking Spanner#close.

vkedia added 7 commits May 1, 2017 10:12
- Change defaults for maxSessions and blockIfExhauseted
- Changed closeAsync to close leaked sessions as well.
- Changed closeAsync to close pool maintenance worker as well.
- Added a SessionPoolStressTester
- Changed Spanner#closeAsync to be blocking Spanner#close.
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 1, 2017
@vkedia vkedia requested a review from vam-google May 1, 2017 20:45
@vkedia
Copy link
Author

vkedia commented May 1, 2017

@tomayles Please take a look

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.006%) to 80.954% when pulling c9d56df on vkedia:session-pool-exception into 9623994 on GoogleCloudPlatform:master.

@vkedia vkedia closed this May 1, 2017
@vkedia vkedia reopened this May 1, 2017
@vkedia
Copy link
Author

vkedia commented May 1, 2017

Closed by mistake.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.009%) to 80.952% when pulling ae8860f on vkedia:session-pool-exception into 9623994 on GoogleCloudPlatform:master.

Copy link

@danielcompton danielcompton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so keen on Spanner changing from closeAsync to close. It is handy to be able to set a timeout when closing the Spanner to handle cases where it gets blocked for whatever reason. At the bottom, this ends up doing (blocking?) RPC calls to deleteSession. Perhaps this is totally safe, if so, it could be good to add a note about this in the implementation notes?

I'm not sure if this is throwing the kitchen sink in, but having close and closeAsync might be useful.

* #getReadWriteSession()} will start throwing {@code IllegalStateException}. The returned {@code
* ListenableFuture} blocks till all the sessions created in this pool have been closed.
* Close all the sessions. Once this method is invoked {@link #getReadSession()} and {@link
* #getReadWriteSession()} will start throwing {@code IllegalStateException}. This method blocks

This comment was marked as spam.

* logging and tracking of leaked sessions.
*/
ApiFuture<Void> closeAsync();
void close();

This comment was marked as spam.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.009%) to 80.952% when pulling 531f73c on vkedia:session-pool-exception into 9623994 on GoogleCloudPlatform:master.

@danielcompton
Copy link

Thanks for updating the javadocs. I'm still a little uneasy about having blocking RPC calls in the shutdown path though.

@vkedia
Copy link
Author

vkedia commented May 1, 2017 via email

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.009%) to 80.952% when pulling 1d867bf on vkedia:session-pool-exception into 9623994 on GoogleCloudPlatform:master.

private static final long serialVersionUID = 1451131180314064914L;

private LeakedSessionException() {
super("Session was checked out from the pool at:");

This comment was marked as spam.

This comment was marked as spam.


// Exception class used just to track the stack trace at the point when a session was handed out
// from the pool.
private final class LeakedSessionException extends Exception {

This comment was marked as spam.

This comment was marked as spam.


void close() {
scheduledFuture.cancel(false);
if (!running) {

This comment was marked as spam.

This comment was marked as spam.

* unused sessions piling up on the backend.
*/
ApiFuture<Void> closeAsync();
void close();

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

throw SpannerExceptionFactory.newSpannerException(e);
}
for (ManagedChannel channel : getOptions().getRpcChannels()) {
channel.shutdown();

This comment was marked as spam.

This comment was marked as spam.

releaseSession(new PooledSession(session));
Preconditions.checkState(totalSessions() <= options.getMaxSessions() - 1);
PooledSession pooledSession = new PooledSession(session);
allSessions.put(session.getName(), pooledSession);

This comment was marked as spam.

This comment was marked as spam.


/** Options for the session pool used by {@code DatabaseClient}. */
public class SessionPoolOptions {
private static final int DEFAULT_MAX_SESSIONS = 2000;

This comment was marked as spam.

This comment was marked as spam.

/** Options for the session pool used by {@code DatabaseClient}. */
public class SessionPoolOptions {
private static final int DEFAULT_MAX_SESSIONS = 2000;
private static final ActionOnExhaustion DEFAULT_ACTION = ActionOnExhaustion.FAIL;

This comment was marked as spam.

This comment was marked as spam.

/**
* An interface for Cloud Spanner. Typically, there would only be one instance of this for the
* lifetime of the application which must be closed by invoking {@link #close()} when it is no
* longer needed.

This comment was marked as spam.

This comment was marked as spam.

* Closes all the clients associated with this instance and frees up all the resources. This
* method does not block. Return future will complete when cleanup is done. TODO(user): Add
* logging and tracking of leaked sessions.
* method will block till it can clean up all the resources. Specifically, it deletes all the

This comment was marked as spam.

This comment was marked as spam.

writePreparedSessions.clear();
for (final PooledSession session : ImmutableList.copyOf(allSessions.values())) {
if (session.leakedException != null) {
logger.log(Level.WARNING, "Leaked session", session.leakedException);

This comment was marked as spam.

This comment was marked as spam.

@vkedia
Copy link
Author

vkedia commented May 8, 2017

@tomayles @vam-google Please take a look again.

Copy link
Contributor

@vam-google vam-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

* unused sessions piling up on the backend.
*/
ApiFuture<Void> closeAsync();
void close();

This comment was marked as spam.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 2b385eb on vkedia:session-pool-exception into ** on GoogleCloudPlatform:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 2b385eb on vkedia:session-pool-exception into ** on GoogleCloudPlatform:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 710701b on vkedia:session-pool-exception into ** on GoogleCloudPlatform:master**.

@vkedia vkedia merged commit 8db50cc into googleapis:master May 12, 2017
@vkedia vkedia deleted the session-pool-exception branch May 12, 2017 17:43
chingor13 pushed a commit that referenced this pull request Feb 20, 2026
suztomo pushed a commit to suztomo/google-cloud-java that referenced this pull request Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants