Skip to content

Commit 6c6919d

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 6c6919d

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-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, 65535);
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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,52 @@ 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+
# Requires passing shard-aware port as contact point (usually 19042 or 19142(ssl)).
544+
# Having this enabled makes sense only for ScyllaDB clusters.
545+
#
546+
# Reduces number of reconnections driver needs to fully initialize connection pool.
547+
# In short it's a feature that allows targeting particular shard when connecting to a node by using specific
548+
# local port number.
549+
# For context see https://www.scylladb.com/2021/04/27/connect-faster-to-scylla-with-a-shard-aware-port/
550+
#
551+
# If set to false the driver will not attempt to use this feature. This means connection's local port
552+
# will be random according to system rules and driver will keep opening connections until it gets right shards.
553+
# In such case non-shard aware port is recommended (by default 9042 or 9142).
554+
# If set to true the driver will attempt to use it and will log warnings each time something
555+
# makes it not possible.
556+
#
557+
# If the node for some reason does not report it's sharding info the driver
558+
# will log a warning and create connection the same way as if this feature was disabled.
559+
# If the cluster ignores the request for specific shard warning will also be logged,
560+
# although the local port will already be chosen according to advanced shard awareness rules.
561+
#
562+
# Required: yes
563+
# Modifiable at runtime: yes, the new value will be used for connections created after the
564+
# change.
565+
# Overridable in a profile: no
566+
enabled = true
567+
568+
# Inclusive lower bound of port range to use in advanced shard awareness
569+
# The driver will attempt to reserve ports for connection only within the range.
570+
# Required: yes
571+
# Modifiable at runtime: yes, the new value will be used for calls after the
572+
# change.
573+
# Overridable in a profile: no
574+
port-low = 10000
575+
576+
# Inclusive upper bound of port range to use in advanced shard awareness.
577+
# The driver will attempt to reserve ports for connection only within the range.
578+
# Required: yes
579+
# Modifiable at runtime: yes, the new value will be used for calls after the
580+
# change.
581+
# Overridable in a profile: no
582+
port-high = 65535
583+
}
538584
}
539585

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

0 commit comments

Comments
 (0)