lukasz-antoniak commented on code in PR #336:
URL: https://github.com/apache/cassandra-sidecar/pull/336#discussion_r3091541829


##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/driver/SidecarLoadBalancingPolicy.java:
##########
@@ -79,108 +81,69 @@ public SidecarLoadBalancingPolicy(List<InetSocketAddress> 
localHostAddresses,
     }
 
     @Override
-    public void init(Cluster cluster, Collection<Host> hosts)
+    public void init(Map<UUID, Node> nodes, @NotNull DistanceReporter 
distanceReporter)
     {
-        this.cluster = cluster;
-        this.allHosts.addAll(hosts);
+        this.allHosts.addAll(nodes.values());
         recalculateSelectedHosts();
-        childPolicy.init(cluster, hosts);
+        super.init(nodes, distanceReporter);
     }
 
     @Override
-    public HostDistance distance(Host host)
+    protected NodeDistance computeNodeDistance(@NotNull Node node)
     {
-        if (selectedHosts.contains(host) || isLocalHost(host))
+        if (selectedHosts.contains(node) || isLocalHost(node))
         {
-            return childPolicy.distance(host);
+            return super.computeNodeDistance(node);
         }
-        return HostDistance.IGNORED;
+        return NodeDistance.IGNORED;
     }
 
     @Override
-    public Iterator<Host> newQueryPlan(String loggedKeyspace, Statement 
statement)
+    public @NotNull Queue<Node> newQueryPlan(Request request, Session session)
     {
-        Iterator<Host> child = childPolicy.newQueryPlan(loggedKeyspace, 
statement);
-        // Filter the child policy to only selected hosts
-        return Iterators.filter(child, selectedHosts::contains);
+        Queue<Node> plan = super.newQueryPlan(request, session);
+        plan.removeIf(n -> !selectedHosts.contains(n));
+        return plan;
     }
 
     @Override
-    public synchronized void onAdd(Host host)
+    public synchronized void onUp(@NotNull Node node)
     {
-        onUp(host);
-        childPolicy.onAdd(host);
-    }
-
-    @Override
-    public synchronized void onUp(Host host)
-    {
-        this.allHosts.add(host); // replace existing reference if there is one
+        this.allHosts.add(node); // replace existing reference if there is one
         if (selectedHosts.size() < totalRequestedConnections)
         {
             recalculateSelectedHosts();
         }
-        childPolicy.onUp(host);
+        super.onUp(node);
     }
 
     @Override
-    public synchronized void onDown(Host host)
+    public synchronized void onDown(@NotNull Node node)
     {
         // Don't remove local addresses from the selected host list
-        if (localHostAddresses.contains(driverUtils.getSocketAddress(host)))
+        if (localHostAddresses.contains(resolveEndpoint(node)))
         {
-            LOGGER.debug("Local Node {} has been marked down.", host);
+            LOGGER.debug("Local Node {} has been marked down.", node);
             return;
         }
-
-        boolean wasSelected = selectedHosts.remove(host);
-        if (!wasSelected)
-        {
-            // Non-selected nodes have been marked with HostDistance.IGNORED
-            // even if they may otherwise be useful. This has a side effect
-            // of preventing the driver from trying to reconnect to them
-            // if we miss the `onUp` event, so we need to schedule reconnects
-            // for these hosts explicitly unless we have active connections.
-            driverUtils.startPeriodicReconnectionAttempt(cluster, host);

Review Comment:
   Still to be analysed.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to