Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Expose Spanner failIfPoolExhausted property #1889

Merged
merged 1 commit into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/main/asciidoc/spanner.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ The schema for the tables will be "ON DELETE NO ACTION" if `false`. | No | `true
| `spring.cloud.gcp.spanner.maxIdleSessions` | Maximum number of idle sessions session pool will maintain | No | 0 - Determined by Cloud Spanner client library
| `spring.cloud.gcp.spanner.writeSessionsFraction` | Fraction of sessions to be kept prepared for write transactions | No | 0.2 - Determined by Cloud Spanner client library
| `spring.cloud.gcp.spanner.keepAliveIntervalMinutes` | How long to keep idle sessions alive | No | 30 - Determined by Cloud Spanner client library
| `spring.cloud.gcp.spanner.failIfPoolExhausted` | If all sessions are in use, fail the request by throwing an exception. Otherwise, by default, block until a session becomes available. | No | `false`
|===

==== Repository settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ static class CoreSpannerAutoConfiguration {

private final boolean createInterleavedTableDdlOnDeleteCascade;

private final boolean failIfPoolExhausted;

CoreSpannerAutoConfiguration(GcpSpannerProperties gcpSpannerProperties,
GcpProjectIdProvider projectIdProvider,
CredentialsProvider credentialsProvider) throws IOException {
Expand All @@ -116,6 +118,7 @@ static class CoreSpannerAutoConfiguration {
.getKeepAliveIntervalMinutes();
this.createInterleavedTableDdlOnDeleteCascade = gcpSpannerProperties
.isCreateInterleavedTableDdlOnDeleteCascade();
this.failIfPoolExhausted = gcpSpannerProperties.isFailIfPoolExhausted();
}

@Bean
Expand Down Expand Up @@ -158,6 +161,11 @@ public SessionPoolOptions sessionPoolOptions() {
if (this.keepAliveIntervalMinutes >= 0) {
builder.setKeepAliveIntervalMinutes(this.keepAliveIntervalMinutes);
}

if (this.failIfPoolExhausted) {
builder.setFailIfPoolExhausted();
}

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public class GcpSpannerProperties implements CredentialsSupplier {
// Default value is negative to indicate to use Cloud Spanner default number.
private int keepAliveIntervalMinutes = -1;

// When {@code true}, if all sessions are in use, fail the request by throwing an exception.
// Otherwise, by default, block until a session becomes available.
private boolean failIfPoolExhausted = false;

public Credentials getCredentials() {
return this.credentials;
}
Expand Down Expand Up @@ -159,4 +163,12 @@ public void setCreateInterleavedTableDdlOnDeleteCascade(
this.createInterleavedTableDdlOnDeleteCascade =
createInterleavedTableDdlOnDeleteCascade;
}

public boolean isFailIfPoolExhausted() {
return failIfPoolExhausted;
}

public void setFailIfPoolExhausted(boolean failIfPoolExhausted) {
this.failIfPoolExhausted = failIfPoolExhausted;
}
}