hhughes commented on code in PR #1743:
URL: 
https://github.com/apache/cassandra-java-driver/pull/1743#discussion_r1393221979


##########
core/src/main/java/com/datastax/oss/driver/internal/core/loadbalancing/DefaultLoadBalancingPolicy.java:
##########
@@ -96,14 +100,39 @@ public class DefaultLoadBalancingPolicy extends 
BasicLoadBalancingPolicy impleme
   private static final int MAX_IN_FLIGHT_THRESHOLD = 10;
   private static final long RESPONSE_COUNT_RESET_INTERVAL_NANOS = 
MILLISECONDS.toNanos(200);
 
-  protected final Map<Node, AtomicLongArray> responseTimes = new 
ConcurrentHashMap<>();
+  protected final LoadingCache<Node, AtomicLongArray> responseTimes;
   protected final Map<Node, Long> upTimes = new ConcurrentHashMap<>();
   private final boolean avoidSlowReplicas;
 
   public DefaultLoadBalancingPolicy(@NonNull DriverContext context, @NonNull 
String profileName) {
     super(context, profileName);
     this.avoidSlowReplicas =
         
profile.getBoolean(DefaultDriverOption.LOAD_BALANCING_POLICY_SLOW_AVOIDANCE, 
true);
+    CacheLoader<Node, AtomicLongArray> cacheLoader =
+        new CacheLoader<Node, AtomicLongArray>() {
+          @Override
+          public AtomicLongArray load(Node key) throws Exception {
+            // The array stores at most two timestamps, since we don't need 
more;
+            // the first one is always the least recent one, and hence the one 
to inspect.
+            long now = nanoTime();
+            AtomicLongArray array =
+                responseTimes.asMap().containsKey(key) ? 
responseTimes.get(key) : null;

Review Comment:
   consider refactoring to `responseTimes.getIfPresent()` to avoid conversion 
to a map and potential race between contains and get



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to