Class SessionPoolOptions.Builder
- Enclosing class:
- SessionPoolOptions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Build a SessionPoolOption objectsetAcquireSessionTimeout(org.threeten.bp.Duration acquireSessionTimeout) This method is obsolete.setAcquireSessionTimeoutDuration(Duration acquireSessionTimeout) If greater than zero, we wait for said duration when no sessions are available in theSessionPool.setAutoDetectDialect(boolean autoDetectDialect) Sets whether the client should automatically execute a background query to detect the dialect that is used by the database or not.If all sessions are in use and there is no more room for creating new sessions, block for a session to become available.If all sessions are in use and andmaxSessionshas been reached, fail the request by throwing aSpannerExceptionwith the error codeRESOURCE_EXHAUSTED.setKeepAliveIntervalMinutes(int intervalMinutes) How frequently to keep alive idle sessions.setMaxIdleSessions(int maxIdleSessions) Deprecated.setMaxSessions(int maxSessions) Maximum number of sessions that this pool will have.setMinSessions(int minSessions) Minimum number of sessions that this pool will always maintain.setRemoveInactiveSessionAfter(org.threeten.bp.Duration duration) This method is obsolete.setTrackStackTraceOfSessionCheckout(boolean trackStackTraceOfSessionCheckout) Sets whether the session pool should capture the call stack trace when a session is checked out of the pool.setWaitForMinSessions(org.threeten.bp.Duration waitForMinSessions) This method is obsolete.setWaitForMinSessionsDuration(Duration waitForMinSessions) If greater than zero, waits for the session pool to have at leastSessionPoolOptions.minSessionsbefore returning the database client to the caller.If there are inactive transactions, release the resources consumed by such transactions.If there are inactive transactions, log warning messages with the origin of such transactions to aid debugging.setWriteSessionsFraction(float writeSessionsFraction) Deprecated.This configuration value is no longer in use.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
setMinSessions
Minimum number of sessions that this pool will always maintain. These will be created eagerly in parallel. Defaults to 100. -
setMaxSessions
Maximum number of sessions that this pool will have. If current numbers of sessions in the pool is less than this and they are all busy, then a new session will be created for any new operation. If current number of in use sessions is same as this and a new request comes, pool can either block or fail. Defaults to 400. -
setMaxIdleSessions
Deprecated.set a higher value forsetMinSessions(int)instead of using this configuration option. This option will be removed in a future release.Maximum number of idle sessions that this pool will maintain. Pool will close any sessions beyond this but making sure to always have at least as many sessions as specified bysetMinSessions(int). To determine how many sessions are idle we look at maximum number of sessions used concurrently over a window of time. Any sessions beyond that are idle. Defaults to 0. -
setRemoveInactiveSessionAfter
@ObsoleteApi("Use setRemoveInactiveSessionAfterDuration(Duration) instead") public SessionPoolOptions.Builder setRemoveInactiveSessionAfter(org.threeten.bp.Duration duration) This method is obsolete. UsesetRemoveInactiveSessionAfterDuration(Duration)instead. -
setRemoveInactiveSessionAfterDuration
-
setKeepAliveIntervalMinutes
How frequently to keep alive idle sessions. This should be less than 60 since an idle session is automatically closed after 60 minutes. Sessions will be kept alive by sending a dummy query "Select 1". Default value is 30 minutes. -
setFailIfPoolExhausted
If all sessions are in use and andmaxSessionshas been reached, fail the request by throwing aSpannerExceptionwith the error codeRESOURCE_EXHAUSTED. Default behavior is to block the request. -
setBlockIfPoolExhausted
If all sessions are in use and there is no more room for creating new sessions, block for a session to become available. Default behavior is same.By default the requests are blocked for 60s and will fail with a `SpannerException` with error code `ResourceExhausted` if this timeout is exceeded. If you wish to block for a different period use the option
setAcquireSessionTimeoutDuration(Duration)()} -
setWarnIfInactiveTransactions
If there are inactive transactions, log warning messages with the origin of such transactions to aid debugging. A transaction is classified as inactive if it executes for more than a system defined duration.This option won't change the state of the transactions. It only generates warning logs that can be used for debugging.
- Returns:
- this builder for chaining
-
setWarnAndCloseIfInactiveTransactions
If there are inactive transactions, release the resources consumed by such transactions. A transaction is classified as inactive if it executes for more than a system defined duration. The option would also produce necessary warning logs through which it can be debugged as to what resources were released due to this option.Use the option
setWarnIfInactiveTransactions()if you only want to log warnings about long-running transactions.- Returns:
- this builder for chaining
-
setExperimentalHost
-
setAutoDetectDialect
Sets whether the client should automatically execute a background query to detect the dialect that is used by the database or not. Set this option to true if you do not know what the dialect of the database will be.Note that you can always call
DatabaseClient.getDialect()to get the dialect of a database regardless of this setting, but by setting this to true, the value will be pre-populated and cached in the client.- Parameters:
autoDetectDialect- Whether the client should automatically execute a background query to detect the dialect of the underlying database- Returns:
- this builder for chaining
-
setTrackStackTraceOfSessionCheckout
public SessionPoolOptions.Builder setTrackStackTraceOfSessionCheckout(boolean trackStackTraceOfSessionCheckout) Sets whether the session pool should capture the call stack trace when a session is checked out of the pool. This will internally prepare aSessionPool.LeakedSessionExceptionthat will only be thrown if the session is actually leaked. This makes it easier to debug session leaks, as the stack trace of the thread that checked out the session will be available in the exception.Some monitoring tools might log these exceptions even though they are not thrown. This option can be used to suppress the creation and logging of these exceptions.
-
setWriteSessionsFraction
Deprecated.This configuration value is no longer in use. The session pool does not prepare any sessions for read/write transactions. Instead, a transaction will automatically be started by the first statement that is executed by a transaction by including a BeginTransaction option with that statement.This method may be removed in a future release.
-
setWaitForMinSessions
@ObsoleteApi("Use setWaitForMinSessionsDuration(Duration) instead") public SessionPoolOptions.Builder setWaitForMinSessions(org.threeten.bp.Duration waitForMinSessions) This method is obsolete. UsesetWaitForMinSessionsDuration(Duration)instead. -
setWaitForMinSessionsDuration
If greater than zero, waits for the session pool to have at leastSessionPoolOptions.minSessionsbefore returning the database client to the caller. Note that this check is only done during the session pool creation. This is usually done asynchronously in order to provide the client back to the caller as soon as possible. We don't recommend using this option unless you are executing benchmarks and want to guarantee the session pool has min sessions in the pool before continuing.Defaults to zero (initialization is done asynchronously).
-
setAcquireSessionTimeout
@ObsoleteApi("Use setAcquireSessionTimeoutDuration(Duration) instead") public SessionPoolOptions.Builder setAcquireSessionTimeout(org.threeten.bp.Duration acquireSessionTimeout) This method is obsolete. UsesetAcquireSessionTimeoutDuration(Duration)instead. -
setAcquireSessionTimeoutDuration
If greater than zero, we wait for said duration when no sessions are available in theSessionPool. The default is a 60s timeout. Set the value to null to disable the timeout. -
build
Build a SessionPoolOption object
-
setMinSessions(int)instead of using this configuration option.