spanner: Enhance session pool behavior#2026
Conversation
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.
- 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.
|
@tomayles Please take a look |
|
Closed by mistake. |
There was a problem hiding this comment.
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.
This comment was marked as spam.
Sorry, something went wrong.
| * logging and tracking of leaked sessions. | ||
| */ | ||
| ApiFuture<Void> closeAsync(); | ||
| void close(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Thanks for updating the javadocs. I'm still a little uneasy about having blocking RPC calls in the shutdown path though. |
|
Thanks for your comments. It is almost essential that this method be
allowed to finish and delete all the sessions otherwise it can lead to
session lying around on the backend for upto an hour. Since there is a
[hard limit](https://cloud.google.com/spanner/docs/limits) on how many
sessions one can have on the backend, this can lead to one running out of
sessions which will cause requests to fail. That is the reason I removed
the async version. You almost always want to block for this method to
finish.
…On Mon, May 1, 2017 at 3:47 PM, Daniel Compton ***@***.***> wrote:
Thanks for updating the javadocs. I'm still a little uneasy about having
blocking RPC calls in the shutdown path though.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#2026 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ATdefzp5iSCWxKfhSyeI8DA2rGGLmXRTks5r1mDsgaJpZM4NNavX>
.
|
| 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| // 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| void close() { | ||
| scheduledFuture.cancel(false); | ||
| if (!running) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * unused sessions piling up on the backend. | ||
| */ | ||
| ApiFuture<Void> closeAsync(); | ||
| void close(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| throw SpannerExceptionFactory.newSpannerException(e); | ||
| } | ||
| for (ManagedChannel channel : getOptions().getRpcChannels()) { | ||
| channel.shutdown(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| /** 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| /** 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| /** | ||
| * 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@tomayles @vam-google Please take a look again. |
| * unused sessions piling up on the backend. | ||
| */ | ||
| ApiFuture<Void> closeAsync(); | ||
| void close(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Changes Unknown when pulling 2b385eb on vkedia:session-pool-exception into ** on GoogleCloudPlatform:master**. |
|
Changes Unknown when pulling 2b385eb on vkedia:session-pool-exception into ** on GoogleCloudPlatform:master**. |
|
Changes Unknown when pulling 710701b on vkedia:session-pool-exception into ** on GoogleCloudPlatform:master**. |
🤖 I have created a release *beep* *boop* --- ## [2.33.1](https://togithub.com/googleapis/java-bigquerystorage/compare/v2.33.0...v2.33.1) (2023-03-02) ### Dependencies * Update dependency com.google.cloud:google-cloud-bigquery to v2.23.0 ([#2012](https://togithub.com/googleapis/java-bigquerystorage/issues/2012)) ([0651aa6](https://togithub.com/googleapis/java-bigquerystorage/commit/0651aa6f3e83da73da77ae2e9376f6203cd36338)) * Update dependency com.google.cloud:google-cloud-shared-dependencies to v3.4.0 ([#2024](https://togithub.com/googleapis/java-bigquerystorage/issues/2024)) ([9135769](https://togithub.com/googleapis/java-bigquerystorage/commit/91357697f61d3026ae3fb14605e9e3ee94b351d1)) * Update dependency com.google.http-client:google-http-client to v1.43.0 ([#2018](https://togithub.com/googleapis/java-bigquerystorage/issues/2018)) ([6bccd9d](https://togithub.com/googleapis/java-bigquerystorage/commit/6bccd9d21698fa94645bfdda2e7d4e70af612d6b)) * Update dependency org.json:json to v20230227 ([#2020](https://togithub.com/googleapis/java-bigquerystorage/issues/2020)) ([6d6bb76](https://togithub.com/googleapis/java-bigquerystorage/commit/6d6bb76188d4be6beec88c54946d6f9515962c55)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).