Add additional timeout settings

This commit expands the `spring.couchbase.env.timeouts` configuration
namespace with timeouts for disconnect, key-value operations with a
durability level, search, analytics and management.

Closes gh-19893

Co-authored-by: Michael Nitschinger <michael@nitschinger.at>
pull/20557/head
Stephane Nicoll 5 years ago
parent abe43b2e83
commit 58eb0ba4d3

@ -75,8 +75,11 @@ public class CouchbaseAutoConfiguration {
private ClusterEnvironment.Builder initializeEnvironmentBuilder(CouchbaseProperties properties) {
ClusterEnvironment.Builder builder = ClusterEnvironment.builder();
Timeouts timeouts = properties.getEnv().getTimeouts();
builder.timeoutConfig(TimeoutConfig.kvTimeout(timeouts.getKeyValue()).queryTimeout(timeouts.getQuery())
.viewTimeout(timeouts.getView()).connectTimeout(timeouts.getConnect()));
builder.timeoutConfig(TimeoutConfig.kvTimeout(timeouts.getKeyValue()).analyticsTimeout(timeouts.getAnalytics())
.kvDurableTimeout(timeouts.getKeyValueDurable()).queryTimeout(timeouts.getQuery())
.viewTimeout(timeouts.getView()).searchTimeout(timeouts.getSearch())
.managementTimeout(timeouts.getManagement()).connectTimeout(timeouts.getConnect())
.disconnectTimeout(timeouts.getDisconnect()));
CouchbaseProperties.Io io = properties.getEnv().getIo();
builder.ioConfig(IoConfig.maxHttpConnections(io.getMaxEndpoints()).numKvConnections(io.getMinEndpoints())
.idleHttpConnectionTimeout(io.getIdleHttpConnectionTimeout()));

@ -192,15 +192,25 @@ public class CouchbaseProperties {
public static class Timeouts {
/**
* Bucket connect timeouts.
* Bucket connect timeout.
*/
private Duration connect = Duration.ofSeconds(10);
/**
* operations performed on a specific key timeout.
* Bucket disconnect timeout.
*/
private Duration disconnect = Duration.ofSeconds(10);
/**
* Timeout for operations on a specific key-value.
*/
private Duration keyValue = Duration.ofMillis(2500);
/**
* Timeout for operations on a specific key-value with a durability level.
*/
private Duration keyValueDurable = Duration.ofSeconds(10);
/**
* N1QL query operations timeout.
*/
@ -211,6 +221,21 @@ public class CouchbaseProperties {
*/
private Duration view = Duration.ofSeconds(75);
/**
* Timeout for the search service.
*/
private Duration search = Duration.ofSeconds(75);
/**
* Timeout for the analytics service.
*/
private Duration analytics = Duration.ofSeconds(75);
/**
* Timeout for the management operations.
*/
private Duration management = Duration.ofSeconds(75);
public Duration getConnect() {
return this.connect;
}
@ -219,6 +244,14 @@ public class CouchbaseProperties {
this.connect = connect;
}
public Duration getDisconnect() {
return this.disconnect;
}
public void setDisconnect(Duration disconnect) {
this.disconnect = disconnect;
}
public Duration getKeyValue() {
return this.keyValue;
}
@ -227,6 +260,14 @@ public class CouchbaseProperties {
this.keyValue = keyValue;
}
public Duration getKeyValueDurable() {
return this.keyValueDurable;
}
public void setKeyValueDurable(Duration keyValueDurable) {
this.keyValueDurable = keyValueDurable;
}
public Duration getQuery() {
return this.query;
}
@ -243,6 +284,30 @@ public class CouchbaseProperties {
this.view = view;
}
public Duration getSearch() {
return this.search;
}
public void setSearch(Duration search) {
this.search = search;
}
public Duration getAnalytics() {
return this.analytics;
}
public void setAnalytics(Duration analytics) {
this.analytics = analytics;
}
public Duration getManagement() {
return this.management;
}
public void setManagement(Duration management) {
this.management = management;
}
}
}

@ -76,11 +76,19 @@ class CouchbaseAutoConfigurationTests {
testClusterEnvironment((env) -> {
TimeoutConfig timeoutConfig = env.timeoutConfig();
assertThat(timeoutConfig.connectTimeout()).isEqualTo(Duration.ofSeconds(1));
assertThat(timeoutConfig.disconnectTimeout()).isEqualTo(Duration.ofSeconds(2));
assertThat(timeoutConfig.kvTimeout()).isEqualTo(Duration.ofMillis(500));
assertThat(timeoutConfig.kvDurableTimeout()).isEqualTo(Duration.ofMillis(750));
assertThat(timeoutConfig.queryTimeout()).isEqualTo(Duration.ofSeconds(3));
assertThat(timeoutConfig.viewTimeout()).isEqualTo(Duration.ofSeconds(4));
}, "spring.couchbase.env.timeouts.connect=1s", "spring.couchbase.env.timeouts.key-value=500ms",
"spring.couchbase.env.timeouts.query=3s", "spring.couchbase.env.timeouts.view=4s");
assertThat(timeoutConfig.searchTimeout()).isEqualTo(Duration.ofSeconds(5));
assertThat(timeoutConfig.analyticsTimeout()).isEqualTo(Duration.ofSeconds(6));
assertThat(timeoutConfig.managementTimeout()).isEqualTo(Duration.ofSeconds(7));
}, "spring.couchbase.env.timeouts.connect=1s", "spring.couchbase.env.timeouts.disconnect=2s",
"spring.couchbase.env.timeouts.key-value=500ms",
"spring.couchbase.env.timeouts.key-value-durable=750ms", "spring.couchbase.env.timeouts.query=3s",
"spring.couchbase.env.timeouts.view=4s", "spring.couchbase.env.timeouts.search=5s",
"spring.couchbase.env.timeouts.analytics=6s", "spring.couchbase.env.timeouts.management=7s");
}
@Test

@ -44,9 +44,14 @@ class CouchbasePropertiesTests {
void timeoutsHaveConsistentDefaults() {
Timeouts timeouts = new CouchbaseProperties().getEnv().getTimeouts();
assertThat(timeouts.getConnect()).isEqualTo(TimeoutConfig.DEFAULT_CONNECT_TIMEOUT);
assertThat(timeouts.getDisconnect()).isEqualTo(TimeoutConfig.DEFAULT_DISCONNECT_TIMEOUT);
assertThat(timeouts.getKeyValue()).isEqualTo(TimeoutConfig.DEFAULT_KV_TIMEOUT);
assertThat(timeouts.getKeyValueDurable()).isEqualTo(TimeoutConfig.DEFAULT_KV_DURABLE_TIMEOUT);
assertThat(timeouts.getQuery()).isEqualTo(TimeoutConfig.DEFAULT_QUERY_TIMEOUT);
assertThat(timeouts.getView()).isEqualTo(TimeoutConfig.DEFAULT_VIEW_TIMEOUT);
assertThat(timeouts.getSearch()).isEqualTo(TimeoutConfig.DEFAULT_SEARCH_TIMEOUT);
assertThat(timeouts.getAnalytics()).isEqualTo(TimeoutConfig.DEFAULT_ANALYTICS_TIMEOUT);
assertThat(timeouts.getManagement()).isEqualTo(TimeoutConfig.DEFAULT_MANAGEMENT_TIMEOUT);
}
}

Loading…
Cancel
Save