Skip to content

Commit 289e4e5

Browse files
committed
Add config options for advanced shard awareness
Adds config options for toggling the feature on and defining port ranges to use. By default the feature will be enabled.
1 parent d975001 commit 289e4e5

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ public enum DefaultDriverOption implements DriverOption {
141141
* <p>Value-type: boolean
142142
*/
143143
CONNECTION_WARN_INIT_ERROR("advanced.connection.warn-on-init-error"),
144+
/**
145+
* Whether to use advanced shard awareness.
146+
*
147+
* <p>Value-type: boolean
148+
*/
149+
CONNECTION_ADVANCED_SHARD_AWARENESS_ENABLED(
150+
"advanced.connection.advanced-shard-awareness.enabled"),
151+
/** Inclusive lower bound of port range to use in advanced shard awareness */
152+
ADVANCED_SHARD_AWARENESS_PORT_LOW("advanced.connection.advanced-shard-awareness.port-low"),
153+
/** Inclusive upper bound of port range to use in advanced shard awareness */
154+
ADVANCED_SHARD_AWARENESS_PORT_HIGH("advanced.connection.advanced-shard-awareness.port-high"),
144155
/**
145156
* The number of connections in the LOCAL pool.
146157
*

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ protected static void fillWithDriverDefaults(OptionsMap map) {
276276
map.put(TypedDriverOption.CONNECTION_MAX_REQUESTS, 1024);
277277
map.put(TypedDriverOption.CONNECTION_MAX_ORPHAN_REQUESTS, 256);
278278
map.put(TypedDriverOption.CONNECTION_WARN_INIT_ERROR, true);
279+
map.put(TypedDriverOption.CONNECTION_ADVANCED_SHARD_AWARENESS_ENABLED, true);
280+
map.put(TypedDriverOption.ADVANCED_SHARD_AWARENESS_PORT_LOW, 10000);
281+
map.put(TypedDriverOption.ADVANCED_SHARD_AWARENESS_PORT_HIGH, 60000);
279282
map.put(TypedDriverOption.RECONNECT_ON_INIT, false);
280283
map.put(TypedDriverOption.RECONNECTION_POLICY_CLASS, "ExponentialReconnectionPolicy");
281284
map.put(TypedDriverOption.RECONNECTION_BASE_DELAY, Duration.ofSeconds(1));

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ public String toString() {
175175
/** Whether to log non-fatal errors when the driver tries to open a new connection. */
176176
public static final TypedDriverOption<Boolean> CONNECTION_WARN_INIT_ERROR =
177177
new TypedDriverOption<>(DefaultDriverOption.CONNECTION_WARN_INIT_ERROR, GenericType.BOOLEAN);
178+
/** Whether to use advanced shard awareness */
179+
public static final TypedDriverOption<Boolean> CONNECTION_ADVANCED_SHARD_AWARENESS_ENABLED =
180+
new TypedDriverOption<>(
181+
DefaultDriverOption.CONNECTION_ADVANCED_SHARD_AWARENESS_ENABLED, GenericType.BOOLEAN);
182+
/** Inclusive lower bound of port range to use in advanced shard awareness */
183+
public static final TypedDriverOption<Integer> ADVANCED_SHARD_AWARENESS_PORT_LOW =
184+
new TypedDriverOption<>(
185+
DefaultDriverOption.ADVANCED_SHARD_AWARENESS_PORT_LOW, GenericType.INTEGER);
186+
/** Inclusive upper bound of port range to use in advanced shard awareness */
187+
public static final TypedDriverOption<Integer> ADVANCED_SHARD_AWARENESS_PORT_HIGH =
188+
new TypedDriverOption<>(
189+
DefaultDriverOption.ADVANCED_SHARD_AWARENESS_PORT_HIGH, GenericType.INTEGER);
178190
/** The number of connections in the LOCAL pool. */
179191
public static final TypedDriverOption<Integer> CONNECTION_POOL_LOCAL_SIZE =
180192
new TypedDriverOption<>(DefaultDriverOption.CONNECTION_POOL_LOCAL_SIZE, GenericType.INTEGER);

core/src/main/resources/reference.conf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,35 @@ datastax-java-driver {
535535
# change.
536536
# Overridable in a profile: no
537537
warn-on-init-error = true
538+
539+
540+
advanced-shard-awareness {
541+
# Whether to use advanced shard awareness when trying to open new connections.
542+
#
543+
# If set to false the driver will not attempt to use this feature.
544+
# If set to true the driver will attempt to use it but depending on result may fall back to
545+
# not using it.
546+
# TODO: expand this description a bit with examples
547+
# Required: yes
548+
# Modifiable at runtime: yes, the new value will be used for connections created after the
549+
# change.
550+
# Overridable in a profile: no
551+
enabled = true
552+
553+
# Inclusive lower bound of port range to use in advanced shard awareness
554+
# The driver will attempt to reserve ports for connection only within the range.
555+
# Required: yes
556+
# Modifiable at runtime: yes, the new value will be used for calls after the
557+
# change.
558+
port-low = 10000
559+
560+
# Inclusive upper bound of port range to use in advanced shard awareness.
561+
# The driver will attempt to reserve ports for connection only within the range.
562+
# Required: yes
563+
# Modifiable at runtime: yes, the new value will be used for calls after the
564+
# change.
565+
port-high = 60000
566+
}
538567
}
539568

540569
# Advanced options for the built-in load-balancing policies.

0 commit comments

Comments
 (0)