Skip to content

Commit 2bc7afe

Browse files
committed
JAVA-1541: Reorganize configuration
connection.max-frame-length => protocol.max-frame-length auth-provider => protocol.auth-provider pooling.local.connections => connection.pool.local.size pooling.remote.connections => connection.pool.remote.size retry-policy => request.retry-policy speculative-execution-policy => request.speculative-execution-policy timestamp-generator => request.timestamp-generator
1 parent 4db24b5 commit 2bc7afe

10 files changed

Lines changed: 106 additions & 102 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 4.0.0-alpha1 (in progress)
66

7+
- [improvement] JAVA-1541: Reorganize configuration
78
- [improvement] JAVA-1577: Set default consistency level to LOCAL_ONE
89
- [bug] JAVA-1548: Retry idempotent statements on READ_TIMEOUT and UNAVAILABLE
910
- [bug] JAVA-1562: Fix various issues around heart beats

core/src/main/java/com/datastax/oss/driver/api/core/config/CoreDriverOption.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,30 @@
2222
*/
2323
public enum CoreDriverOption implements DriverOption {
2424
CONTACT_POINTS("contact-points", false),
25+
2526
PROTOCOL_VERSION("protocol.version", false),
27+
PROTOCOL_MAX_FRAME_LENGTH("protocol.max-frame-length", true),
28+
2629
CLUSTER_NAME("cluster-name", false),
2730
CONFIG_RELOAD_INTERVAL("config-reload-interval", false),
2831

2932
CONNECTION_INIT_QUERY_TIMEOUT("connection.init-query-timeout", true),
3033
CONNECTION_SET_KEYSPACE_TIMEOUT("connection.set-keyspace-timeout", true),
31-
CONNECTION_MAX_FRAME_LENGTH("connection.max-frame-length", true),
3234
CONNECTION_MAX_REQUESTS("connection.max-requests-per-connection", true),
3335
CONNECTION_HEARTBEAT_INTERVAL("connection.heartbeat.interval", true),
3436
CONNECTION_HEARTBEAT_TIMEOUT("connection.heartbeat.timeout", true),
3537
CONNECTION_MAX_ORPHAN_REQUESTS("connection.max-orphan-requests", true),
38+
CONNECTION_POOL_LOCAL_SIZE("connection.pool.local.size", true),
39+
CONNECTION_POOL_REMOTE_SIZE("connection.pool.remote.size", true),
3640

3741
REQUEST_TIMEOUT("request.timeout", true),
3842
REQUEST_CONSISTENCY("request.consistency", true),
3943
REQUEST_PAGE_SIZE("request.page-size", true),
4044
REQUEST_SERIAL_CONSISTENCY("request.serial-consistency", true),
4145
REQUEST_WARN_IF_SET_KEYSPACE("request.warn-if-set-keyspace", true),
4246
REQUEST_DEFAULT_IDEMPOTENCE("request.default-idempotence", true),
47+
RETRY_POLICY_ROOT("request.retry-policy", true),
48+
SPECULATIVE_EXECUTION_POLICY_ROOT("request.speculative-execution-policy", true),
4349

4450
CONTROL_CONNECTION_TIMEOUT("connection.control-connection.timeout", true),
4551
CONTROL_CONNECTION_PAGE_SIZE("connection.control-connection.page-size", true),
@@ -51,12 +57,8 @@ public enum CoreDriverOption implements DriverOption {
5157
// "Sub-option" for all the policies, etc.
5258
RELATIVE_POLICY_CLASS("class", false),
5359

54-
RETRY_POLICY_ROOT("retry-policy", true),
55-
5660
LOAD_BALANCING_POLICY_ROOT("load-balancing-policy", true),
5761

58-
SPECULATIVE_EXECUTION_POLICY_ROOT("speculative-execution-policy", true),
59-
6062
RECONNECTION_POLICY_ROOT("connection.reconnection-policy", true),
6163
RELATIVE_EXPONENTIAL_RECONNECTION_BASE_DELAY("base-delay", false),
6264
RELATIVE_EXPONENTIAL_RECONNECTION_MAX_DELAY("max-delay", false),
@@ -68,12 +70,9 @@ public enum CoreDriverOption implements DriverOption {
6870
REPREPARE_MAX_PARALLELISM("prepared-statements.reprepare-on-up.max-parallelism", false),
6971
REPREPARE_TIMEOUT("prepared-statements.reprepare-on-up.timeout", false),
7072

71-
POOLING_LOCAL_CONNECTIONS("pooling.local.connections", true),
72-
POOLING_REMOTE_CONNECTIONS("pooling.remote.connections", true),
73-
7473
ADDRESS_TRANSLATOR_ROOT("address-translator", true),
7574

76-
AUTH_PROVIDER_ROOT("auth-provider", false),
75+
AUTH_PROVIDER_ROOT("protocol.auth-provider", false),
7776
RELATIVE_PLAIN_TEXT_AUTH_USERNAME("username", false),
7877
RELATIVE_PLAIN_TEXT_AUTH_PASSWORD("password", false),
7978

@@ -83,7 +82,7 @@ public enum CoreDriverOption implements DriverOption {
8382
METADATA_TOPOLOGY_WINDOW("metadata.topology-event-debouncer.window", true),
8483
METADATA_TOPOLOGY_MAX_EVENTS("metadata.topology-event-debouncer.max-events", true),
8584

86-
TIMESTAMP_GENERATOR_ROOT("timestamp-generator", true),
85+
TIMESTAMP_GENERATOR_ROOT("request.timestamp-generator", true),
8786
RELATIVE_TIMESTAMP_GENERATOR_FORCE_JAVA_CLOCK("force-java-clock", false),
8887
RELATIVE_TIMESTAMP_GENERATOR_DRIFT_WARNING_THRESHOLD("drift-warning.threshold", false),
8988
RELATIVE_TIMESTAMP_GENERATOR_DRIFT_WARNING_INTERVAL("drift-warning.interval", false),

core/src/main/java/com/datastax/oss/driver/internal/core/channel/ChannelFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ protected void initChannel(Channel channel) throws Exception {
182182
.getDuration(CoreDriverOption.CONNECTION_SET_KEYSPACE_TIMEOUT)
183183
.toMillis();
184184
int maxFrameLength =
185-
(int) defaultConfigProfile.getBytes(CoreDriverOption.CONNECTION_MAX_FRAME_LENGTH);
185+
(int) defaultConfigProfile.getBytes(CoreDriverOption.PROTOCOL_MAX_FRAME_LENGTH);
186186
int maxRequestsPerConnection =
187187
defaultConfigProfile.getInt(CoreDriverOption.CONNECTION_MAX_REQUESTS);
188188
int maxOrphanRequests =

core/src/main/java/com/datastax/oss/driver/internal/core/pool/ChannelPool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ private int getConfiguredSize(NodeDistance distance) {
509509
.getDefaultProfile()
510510
.getInt(
511511
(distance == NodeDistance.LOCAL)
512-
? CoreDriverOption.POOLING_LOCAL_CONNECTIONS
513-
: CoreDriverOption.POOLING_REMOTE_CONNECTIONS);
512+
? CoreDriverOption.CONNECTION_POOL_LOCAL_SIZE
513+
: CoreDriverOption.CONNECTION_POOL_REMOTE_SIZE);
514514
}
515515
}
516516
}

core/src/main/resources/reference.conf

Lines changed: 68 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ datastax-java-driver {
4141
# connecting to lower-version nodes later. You should force the lowest common protocol version
4242
# in that case.
4343
// version = V4
44+
45+
# The maximum length of the frames supported by the driver. Beyond that limit, requests will
46+
# fail with an exception
47+
#
48+
# This option can be changed at runtime, the new value will be used for new connections created
49+
# after the change.
50+
max-frame-length = 256 MB
51+
52+
# The components that handles authentication on each new connection.
53+
auth-provider {
54+
# This property is optional; if it is not present, no authentication will occur.
55+
// class = com.datastax.driver.api.core.auth.PlainTextAuthProvider
56+
# Sample configuration for the plain-text provider:
57+
// username = cassandra
58+
// password = cassandra
59+
}
4460
}
4561

4662
# A name that uniquely identifies the driver instance created from this configuration. This is
@@ -58,18 +74,10 @@ datastax-java-driver {
5874
# To disable periodic reloading, set this to 0.
5975
config-reload-interval = 5 minutes
6076

61-
retry-policy {
62-
class = com.datastax.oss.driver.api.core.retry.DefaultRetryPolicy
63-
}
64-
6577
load-balancing-policy {
6678
class = com.datastax.oss.driver.api.core.loadbalancing.RoundRobinLoadBalancingPolicy
6779
}
6880

69-
speculative-execution-policy {
70-
class = com.datastax.oss.driver.api.core.specex.NoSpeculativeExecutionPolicy
71-
}
72-
7381
connection {
7482
# The timeout to use for internal queries that run as part of the initialization process, just
7583
# after we open a connection. If this timeout fires, the initialization of the connection will
@@ -125,12 +133,6 @@ datastax-java-driver {
125133
# issued after the change.
126134
timeout = ${datastax-java-driver.connection.init-query-timeout}
127135
}
128-
# The maximum length of the frames supported by the driver. Beyond that limit, requests will
129-
# fail with an exception
130-
#
131-
# This option can be changed at runtime, the new value will be used for new connections created
132-
# after the change.
133-
max-frame-length = 256 MB
134136

135137
reconnection-policy {
136138
class = com.datastax.oss.driver.api.core.connection.ExponentialReconnectionPolicy
@@ -157,6 +159,21 @@ datastax-java-driver {
157159
# The reschedule interval.
158160
reschedule-interval = 10 microseconds
159161
}
162+
163+
# The driver maintains a connection pool to each node, according to the distance assigned to it
164+
# by the load balancing policy. If the distance is IGNORED, no connections are maintained.
165+
pool {
166+
local {
167+
# The number of connections in the pool.
168+
#
169+
# This option can be changed at runtime; when the change is detected, all active pools will
170+
# adjust their size.
171+
size = 1
172+
}
173+
remote {
174+
size = 1
175+
}
176+
}
160177
}
161178

162179
request {
@@ -213,36 +230,44 @@ datastax-java-driver {
213230
# This option can be changed at runtime, the new value will be used for requests issued after
214231
# the change. It can be overridden in a profile.
215232
default-idempotence = false
216-
}
217233

218-
# The generator that assigns a microsecond timestamp to each query sent by the driver.
219-
timestamp-generator {
220-
# The implementation to use. Built-in options are (all from the package
221-
# com.datastax.oss.driver.api.core.time):
222-
# - AtomicTimestampGenerator: timestamps are guaranteed to be unique across all client threads.
223-
# - ThreadLocalTimestampGenerator: timestamps that are guaranteed to be unique within each
224-
# thread only.
225-
# - ServerSideTimestampGenerator: do not generate timestamps, let the server assign them.
226-
class = com.datastax.oss.driver.api.core.time.AtomicTimestampGenerator
227-
228-
# To guarantee that queries are applied on the server in the same order as the client issued
229-
# them, timestamps must be strictly increasing. But this means that, if the driver sends more
230-
# than one query per microsecond, timestamps will drift in the future. While this could happen
231-
# occasionally under high load, it should not be a regular occurrence. Therefore the built-in
232-
# implementations log a warning to detect potential issues.
233-
drift-warning {
234-
# How far in the future timestamps are allowed to drift before the warning is logged.
235-
# If it is undefined or set to 0, warnings are disabled.
236-
threshold = 1 second
237-
# How often the warning will be logged if timestamps keep drifting above the threshold.
238-
interval = 10 seconds
234+
# The generator that assigns a microsecond timestamp to each request.
235+
timestamp-generator {
236+
# The implementation to use. Built-in options are (all from the package
237+
# com.datastax.oss.driver.api.core.time):
238+
# - AtomicTimestampGenerator: timestamps are guaranteed to be unique across all client threads.
239+
# - ThreadLocalTimestampGenerator: timestamps that are guaranteed to be unique within each
240+
# thread only.
241+
# - ServerSideTimestampGenerator: do not generate timestamps, let the server assign them.
242+
class = com.datastax.oss.driver.api.core.time.AtomicTimestampGenerator
243+
244+
# To guarantee that queries are applied on the server in the same order as the client issued
245+
# them, timestamps must be strictly increasing. But this means that, if the driver sends more
246+
# than one query per microsecond, timestamps will drift in the future. While this could happen
247+
# occasionally under high load, it should not be a regular occurrence. Therefore the built-in
248+
# implementations log a warning to detect potential issues.
249+
drift-warning {
250+
# How far in the future timestamps are allowed to drift before the warning is logged.
251+
# If it is undefined or set to 0, warnings are disabled.
252+
threshold = 1 second
253+
# How often the warning will be logged if timestamps keep drifting above the threshold.
254+
interval = 10 seconds
255+
}
256+
257+
# Whether to force the driver to use Java's millisecond-precision system clock.
258+
# If this is false, the driver will try to access the microsecond-precision OS clock via native
259+
# calls (and fallback to the Java one if the native calls fail).
260+
# Unless you explicitly want to avoid native calls, there's no reason to change this.
261+
force-java-clock = false
262+
}
263+
264+
retry-policy {
265+
class = com.datastax.oss.driver.api.core.retry.DefaultRetryPolicy
239266
}
240267

241-
# Whether to force the driver to use Java's millisecond-precision system clock.
242-
# If this is false, the driver will try to access the microsecond-precision OS clock via native
243-
# calls (and fallback to the Java one if the native calls fail).
244-
# Unless you explicitly want to avoid native calls, there's no reason to change this.
245-
force-java-clock = false
268+
speculative-execution-policy {
269+
class = com.datastax.oss.driver.api.core.specex.NoSpeculativeExecutionPolicy
270+
}
246271
}
247272

248273
prepared-statements {
@@ -308,21 +333,6 @@ datastax-java-driver {
308333
}
309334
}
310335

311-
# The driver maintains a connection pool to each node, according to the distance assigned to it
312-
# by the load balancing policy. If the distance is IGNORED, no connections are maintained.
313-
pooling {
314-
local {
315-
# The number of connections in the pool.
316-
#
317-
# This option can be changed at runtime; when the change is detected, all active pools will
318-
# adjust their size.
319-
connections = 1
320-
}
321-
remote {
322-
connections = 1
323-
}
324-
}
325-
326336
metadata {
327337
# Topology events are external signals that inform the driver of the state of Cassandra nodes
328338
# (by default, they correspond to gossip events received on the control connection).
@@ -340,6 +350,7 @@ datastax-java-driver {
340350
max-events = 20
341351
}
342352
}
353+
343354
# The address translator to use to convert the addresses sent by Cassandra nodes into ones that
344355
# the driver uses to connect.
345356
# This is only needed if the nodes are not directly reachable from the driver (for example, the
@@ -349,14 +360,7 @@ datastax-java-driver {
349360
# This default implementation always returns the same address unchanged.
350361
class = com.datastax.oss.driver.api.core.addresstranslation.PassThroughAddressTranslator
351362
}
352-
# The auth provider that will handle authentication for each new connection to a server.
353-
auth-provider {
354-
# This property is optional; if it is not present, no authentication will occur.
355-
// class = com.datastax.driver.api.core.auth.PlainTextAuthProvider
356-
# Sample configuration for the plain-text provider:
357-
// username = cassandra
358-
// password = cassandra
359-
}
363+
360364
# The SSL engine factory that will initialize an SSL engine for each new connection to a server.
361365
ssl-engine-factory {
362366
# This property is optional; if it is not present, SSL won't be activated.

core/src/test/java/com/datastax/oss/driver/internal/core/pool/ChannelPoolInitTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class ChannelPoolInitTest extends ChannelPoolTestBase {
3838

3939
@Test
4040
public void should_initialize_when_all_channels_succeed() throws Exception {
41-
Mockito.when(defaultProfile.getInt(CoreDriverOption.POOLING_LOCAL_CONNECTIONS)).thenReturn(3);
41+
Mockito.when(defaultProfile.getInt(CoreDriverOption.CONNECTION_POOL_LOCAL_SIZE)).thenReturn(3);
4242

4343
DriverChannel channel1 = newMockDriverChannel(1);
4444
DriverChannel channel2 = newMockDriverChannel(2);
@@ -65,7 +65,7 @@ public void should_initialize_when_all_channels_succeed() throws Exception {
6565

6666
@Test
6767
public void should_initialize_when_all_channels_fail() throws Exception {
68-
Mockito.when(defaultProfile.getInt(CoreDriverOption.POOLING_LOCAL_CONNECTIONS)).thenReturn(3);
68+
Mockito.when(defaultProfile.getInt(CoreDriverOption.CONNECTION_POOL_LOCAL_SIZE)).thenReturn(3);
6969

7070
MockChannelFactoryHelper factoryHelper =
7171
MockChannelFactoryHelper.builder(channelFactory)
@@ -88,7 +88,7 @@ public void should_initialize_when_all_channels_fail() throws Exception {
8888

8989
@Test
9090
public void should_indicate_when_keyspace_failed_on_all_channels() {
91-
Mockito.when(defaultProfile.getInt(CoreDriverOption.POOLING_LOCAL_CONNECTIONS)).thenReturn(3);
91+
Mockito.when(defaultProfile.getInt(CoreDriverOption.CONNECTION_POOL_LOCAL_SIZE)).thenReturn(3);
9292

9393
MockChannelFactoryHelper factoryHelper =
9494
MockChannelFactoryHelper.builder(channelFactory)
@@ -107,7 +107,7 @@ public void should_indicate_when_keyspace_failed_on_all_channels() {
107107

108108
@Test
109109
public void should_fire_force_down_event_when_cluster_name_does_not_match() throws Exception {
110-
Mockito.when(defaultProfile.getInt(CoreDriverOption.POOLING_LOCAL_CONNECTIONS)).thenReturn(3);
110+
Mockito.when(defaultProfile.getInt(CoreDriverOption.CONNECTION_POOL_LOCAL_SIZE)).thenReturn(3);
111111

112112
ClusterNameMismatchException error =
113113
new ClusterNameMismatchException(ADDRESS, "actual", "expected");
@@ -134,7 +134,7 @@ public void should_reconnect_when_init_incomplete() throws Exception {
134134
// Short delay so we don't have to wait in the test
135135
Mockito.when(reconnectionSchedule.nextDelay()).thenReturn(Duration.ofNanos(1));
136136

137-
Mockito.when(defaultProfile.getInt(CoreDriverOption.POOLING_LOCAL_CONNECTIONS)).thenReturn(2);
137+
Mockito.when(defaultProfile.getInt(CoreDriverOption.CONNECTION_POOL_LOCAL_SIZE)).thenReturn(2);
138138

139139
DriverChannel channel1 = newMockDriverChannel(1);
140140
DriverChannel channel2 = newMockDriverChannel(2);

core/src/test/java/com/datastax/oss/driver/internal/core/pool/ChannelPoolKeyspaceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ChannelPoolKeyspaceTest extends ChannelPoolTestBase {
3333

3434
@Test
3535
public void should_switch_keyspace_on_existing_channels() throws Exception {
36-
Mockito.when(defaultProfile.getInt(CoreDriverOption.POOLING_LOCAL_CONNECTIONS)).thenReturn(2);
36+
Mockito.when(defaultProfile.getInt(CoreDriverOption.CONNECTION_POOL_LOCAL_SIZE)).thenReturn(2);
3737

3838
DriverChannel channel1 = newMockDriverChannel(1);
3939
DriverChannel channel2 = newMockDriverChannel(2);
@@ -69,7 +69,7 @@ public void should_switch_keyspace_on_existing_channels() throws Exception {
6969
public void should_switch_keyspace_on_pending_channels() throws Exception {
7070
Mockito.when(reconnectionSchedule.nextDelay()).thenReturn(Duration.ofNanos(1));
7171

72-
Mockito.when(defaultProfile.getInt(CoreDriverOption.POOLING_LOCAL_CONNECTIONS)).thenReturn(2);
72+
Mockito.when(defaultProfile.getInt(CoreDriverOption.CONNECTION_POOL_LOCAL_SIZE)).thenReturn(2);
7373

7474
DriverChannel channel1 = newMockDriverChannel(1);
7575
CompletableFuture<DriverChannel> channel1Future = new CompletableFuture<>();

core/src/test/java/com/datastax/oss/driver/internal/core/pool/ChannelPoolReconnectTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ChannelPoolReconnectTest extends ChannelPoolTestBase {
3737
public void should_reconnect_when_channel_closes() throws Exception {
3838
Mockito.when(reconnectionSchedule.nextDelay()).thenReturn(Duration.ofNanos(1));
3939

40-
Mockito.when(defaultProfile.getInt(CoreDriverOption.POOLING_LOCAL_CONNECTIONS)).thenReturn(2);
40+
Mockito.when(defaultProfile.getInt(CoreDriverOption.CONNECTION_POOL_LOCAL_SIZE)).thenReturn(2);
4141

4242
DriverChannel channel1 = newMockDriverChannel(1);
4343
DriverChannel channel2 = newMockDriverChannel(2);
@@ -88,7 +88,7 @@ public void should_reconnect_when_channel_closes() throws Exception {
8888
public void should_reconnect_when_channel_starts_graceful_shutdown() throws Exception {
8989
Mockito.when(reconnectionSchedule.nextDelay()).thenReturn(Duration.ofNanos(1));
9090

91-
Mockito.when(defaultProfile.getInt(CoreDriverOption.POOLING_LOCAL_CONNECTIONS)).thenReturn(2);
91+
Mockito.when(defaultProfile.getInt(CoreDriverOption.CONNECTION_POOL_LOCAL_SIZE)).thenReturn(2);
9292

9393
DriverChannel channel1 = newMockDriverChannel(1);
9494
DriverChannel channel2 = newMockDriverChannel(2);

0 commit comments

Comments
 (0)