Skip to content

Commit 44ccd12

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 44ccd12

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,41 @@ 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+
# Having this enabled makes sense only for ScyllaDB clusters.
544+
# Results in smaller connection storms in multi-client settings.
545+
# If set to false the driver will not attempt to use this feature.
546+
# If set to true the driver will attempt to use it and will log warnings each time something
547+
# makes it not possible.
548+
# If the node for some reason does not report it's sharding info the driver
549+
# will log a warning and create connection the same way as if this feature was disabled.
550+
# If the cluster ignores the request for specific shard warning will also be logged,
551+
# although the local port will be chosen according to advanced shard awareness rules.
552+
#
553+
# Required: yes
554+
# Modifiable at runtime: yes, the new value will be used for connections created after the
555+
# change.
556+
# Overridable in a profile: no
557+
enabled = true
558+
559+
# Inclusive lower bound of port range to use in advanced shard awareness
560+
# The driver will attempt to reserve ports for connection only within the range.
561+
# Required: yes
562+
# Modifiable at runtime: yes, the new value will be used for calls after the
563+
# change.
564+
port-low = 10000
565+
566+
# Inclusive upper bound of port range to use in advanced shard awareness.
567+
# The driver will attempt to reserve ports for connection only within the range.
568+
# Required: yes
569+
# Modifiable at runtime: yes, the new value will be used for calls after the
570+
# change.
571+
port-high = 60000
572+
}
538573
}
539574

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

0 commit comments

Comments
 (0)