From e1e24ca6c06581aa1b282f4ff64d2dc0af56298a Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 25 Feb 2022 10:14:32 +0100 Subject: [PATCH] Rename `ReadFrom.NEAREST` to `LOWEST_LATENCY` to clarify its functionality #1997 Introduce LOWEST_LATENCY and deprecate NEAREST. --- src/main/java/io/lettuce/core/ReadFrom.java | 23 +++++++++++++++---- .../java/io/lettuce/core/ReadFromImpl.java | 6 +++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/lettuce/core/ReadFrom.java b/src/main/java/io/lettuce/core/ReadFrom.java index 1c89420bad..1b216b6f2d 100644 --- a/src/main/java/io/lettuce/core/ReadFrom.java +++ b/src/main/java/io/lettuce/core/ReadFrom.java @@ -88,9 +88,24 @@ public abstract class ReadFrom { public static final ReadFrom SLAVE = REPLICA; /** - * Setting to read from the nearest node. + * Setting to read from the node with the lowest latency during topology discovery. Note that latency measurements are + * momentary snapshots that can change in rapid succession. Requires dynamic refresh sources to obtain topologies and + * latencies from all nodes in the cluster. + * + * @since 6.1.7 + */ + public static final ReadFrom LOWEST_LATENCY = new ReadFromImpl.ReadFromLowestCommandLatency(); + + /** + * Setting to read from the node with the lowest latency during topology discovery. Note that latency measurements are + * momentary snapshots that can change in rapid succession. Requires dynamic refresh sources to obtain topologies and + * latencies from all nodes in the cluster. + * + * @deprecated since 6.1.7 as we're renaming this setting to {@link #LOWEST_LATENCY} for more clarity what this setting + * actually represents. */ - public static final ReadFrom NEAREST = new ReadFromImpl.ReadFromNearest(); + @Deprecated + public static final ReadFrom NEAREST = LOWEST_LATENCY; /** * Setting to read from any node. @@ -198,8 +213,8 @@ public static ReadFrom valueOf(String name) { return REPLICA_PREFERRED; } - if (name.equalsIgnoreCase("nearest")) { - return NEAREST; + if (name.equalsIgnoreCase("nearest") || name.equalsIgnoreCase("lowestLatency")) { + return LOWEST_LATENCY; } if (name.equalsIgnoreCase("any")) { diff --git a/src/main/java/io/lettuce/core/ReadFromImpl.java b/src/main/java/io/lettuce/core/ReadFromImpl.java index 63724b46da..487138cf9b 100644 --- a/src/main/java/io/lettuce/core/ReadFromImpl.java +++ b/src/main/java/io/lettuce/core/ReadFromImpl.java @@ -94,9 +94,11 @@ static final class ReadFromReplicaPreferred extends OrderedPredicateReadFromAdap } /** - * Read from nearest node. + * Read from the node with the lowest latency during topology discovery. Note that latency measurements are momentary + * snapshots that can change in rapid succession. Requires dynamic refresh sources to obtain topologies and latencies from + * all nodes in the cluster. */ - static final class ReadFromNearest extends ReadFrom { + static final class ReadFromLowestCommandLatency extends ReadFrom { @Override public List select(Nodes nodes) {