Rack aware whitelisting or rackaware load balancing policy
Description
With the way applications are now used, where appA is in availability zone A with rackA, there should be a rack aware load balancing policy or some way to prefer rackA nodes over rackB nodes. In this case, we’d like to use appA with rackA and appB with rackB, but we also would like failover capability in case rackA stops responding. I know it’s an unlikely scenario where appA is working, but several nodes in rackA are down, but it’s still a possibility, thus the request for failover capability.
With the way applications are now used, where appA is in availability zone A with rackA, there should be a rack aware load balancing policy or some way to prefer rackA nodes over rackB nodes. In this case, we’d like to use appA with rackA and appB with rackB, but we also would like failover capability in case rackA stops responding. I know it’s an unlikely scenario where appA is working, but several nodes in rackA are down, but it’s still a possibility, thus the request for failover capability.
We are using something like this:
Set<Node> whitelistedNodes = Set.of(); try (CqlSession session = CqlSession .builder() .addContactPoint(new InetSocketAddress(localhost, 9042)) .withLocalDatacenter("datacenter1") .withNodeDistanceEvaluator((node,localDc) -> { return whitelistedNodes.contains(node) ? null : NodeDistance.IGNORED; }) .build()) { ResultSet rs = session.execute("select count(*) from system_schema.keyspaces"); Row row = rs.one(); System.out.println(String.format("Answer: %s keyspaces", row.getLong("count"))); }
In this case, it might work if we could do the above, but weight the nodes instead of ignoring. Like:
rackA (node 1,2,3) weight = 1
rackB (node 4,5,6) weight = .75
rackC (node 7,8,9) weight = .25
Thus, we’d prefer anything with a higher weight, unless it was unavailable.