Skip to content

Commit e26f3e2

Browse files
committed
Review Cassandra's timeout options
This commit reviews the current timeout options. It creates a connection and request sub-namespace to separate concerns a bit more. Closes gh-19673
1 parent 01aa5d9 commit e26f3e2

File tree

3 files changed

+219
-112
lines changed

3 files changed

+219
-112
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
import org.springframework.beans.factory.ObjectProvider;
4141
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
42+
import org.springframework.boot.autoconfigure.cassandra.CassandraProperties.Connection;
43+
import org.springframework.boot.autoconfigure.cassandra.CassandraProperties.Request;
4244
import org.springframework.boot.autoconfigure.cassandra.CassandraProperties.Throttler;
4345
import org.springframework.boot.autoconfigure.cassandra.CassandraProperties.ThrottlerType;
4446
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -115,10 +117,9 @@ private Config cassandraConfiguration(CassandraProperties properties) {
115117
.add(DefaultDriverOption.AUTH_PROVIDER_PASSWORD, properties.getPassword()));
116118
map.from(properties::getCompression).whenNonNull()
117119
.to((compression) -> options.add(DefaultDriverOption.PROTOCOL_COMPRESSION, compression));
118-
mapQueryOptions(properties, options);
119-
mapSocketOptions(properties, options);
120+
mapConnectionOptions(properties, options);
120121
mapPoolingOptions(properties, options);
121-
mapThrottlingOptions(properties, options);
122+
mapRequestOptions(properties, options);
122123
map.from(mapContactPoints(properties))
123124
.to((contactPoints) -> options.add(DefaultDriverOption.CONTACT_POINTS, contactPoints));
124125
map.from(properties.getLocalDatacenter()).to(
@@ -128,22 +129,13 @@ private Config cassandraConfiguration(CassandraProperties properties) {
128129
.withFallback(ConfigFactory.defaultReference()).resolve();
129130
}
130131

131-
private void mapQueryOptions(CassandraProperties properties, CassandraDriverOptions options) {
132-
PropertyMapper map = PropertyMapper.get();
133-
map.from(properties::getConsistencyLevel).whenNonNull()
134-
.to(((consistency) -> options.add(DefaultDriverOption.REQUEST_CONSISTENCY, consistency)));
135-
map.from(properties::getSerialConsistencyLevel).whenNonNull().to(
136-
(serialConsistency) -> options.add(DefaultDriverOption.REQUEST_SERIAL_CONSISTENCY, serialConsistency));
137-
map.from(properties::getPageSize)
138-
.to((pageSize) -> options.add(DefaultDriverOption.REQUEST_PAGE_SIZE, pageSize));
139-
}
140-
141-
private void mapSocketOptions(CassandraProperties properties, CassandraDriverOptions options) {
142-
PropertyMapper map = PropertyMapper.get();
143-
map.from(properties::getConnectTimeout).whenNonNull().asInt(Duration::toMillis)
144-
.to((connectTimeout) -> options.add(DefaultDriverOption.CONNECTION_INIT_QUERY_TIMEOUT, connectTimeout));
145-
map.from(properties::getReadTimeout).whenNonNull().asInt(Duration::toMillis)
146-
.to((readTimeout) -> options.add(DefaultDriverOption.REQUEST_TIMEOUT, readTimeout));
132+
private void mapConnectionOptions(CassandraProperties properties, CassandraDriverOptions options) {
133+
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
134+
Connection connectionProperties = properties.getConnection();
135+
map.from(connectionProperties::getConnectTimeout).asInt(Duration::toMillis)
136+
.to((connectTimeout) -> options.add(DefaultDriverOption.CONNECTION_CONNECT_TIMEOUT, connectTimeout));
137+
map.from(connectionProperties::getInitQueryTimeout).asInt(Duration::toMillis).to(
138+
(initQueryTimeout) -> options.add(DefaultDriverOption.CONNECTION_INIT_QUERY_TIMEOUT, initQueryTimeout));
147139
}
148140

149141
private void mapPoolingOptions(CassandraProperties properties, CassandraDriverOptions options) {
@@ -155,9 +147,18 @@ private void mapPoolingOptions(CassandraProperties properties, CassandraDriverOp
155147
.to((heartBeatInterval) -> options.add(DefaultDriverOption.HEARTBEAT_INTERVAL, heartBeatInterval));
156148
}
157149

158-
private void mapThrottlingOptions(CassandraProperties properties, CassandraDriverOptions options) {
150+
private void mapRequestOptions(CassandraProperties properties, CassandraDriverOptions options) {
159151
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
160-
Throttler throttlerProperties = properties.getThrottler();
152+
Request requestProperties = properties.getRequest();
153+
map.from(requestProperties::getTimeout).asInt(Duration::toMillis)
154+
.to(((timeout) -> options.add(DefaultDriverOption.REQUEST_TIMEOUT, timeout)));
155+
map.from(requestProperties::getConsistency)
156+
.to(((consistency) -> options.add(DefaultDriverOption.REQUEST_CONSISTENCY, consistency)));
157+
map.from(requestProperties::getSerialConsistency).to(
158+
(serialConsistency) -> options.add(DefaultDriverOption.REQUEST_SERIAL_CONSISTENCY, serialConsistency));
159+
map.from(requestProperties::getPageSize)
160+
.to((pageSize) -> options.add(DefaultDriverOption.REQUEST_PAGE_SIZE, pageSize));
161+
Throttler throttlerProperties = requestProperties.getThrottler();
161162
map.from(throttlerProperties::getType).as(ThrottlerType::type)
162163
.to((type) -> options.add(DefaultDriverOption.REQUEST_THROTTLER_CLASS, type));
163164
map.from(throttlerProperties::getMaxQueueSize)
@@ -168,7 +169,6 @@ private void mapThrottlingOptions(CassandraProperties properties, CassandraDrive
168169
.add(DefaultDriverOption.REQUEST_THROTTLER_MAX_REQUESTS_PER_SECOND, maxRequestsPerSecond));
169170
map.from(throttlerProperties::getDrainInterval).asInt(Duration::toMillis).to(
170171
(drainInterval) -> options.add(DefaultDriverOption.REQUEST_THROTTLER_DRAIN_INTERVAL, drainInterval));
171-
172172
}
173173

174174
private List<String> mapContactPoints(CassandraProperties properties) {

0 commit comments

Comments
 (0)