prathyusha magam
prathyusha magam

Reputation: 189

What load balancing policies are available in Cassandra Java driver 4.x?

We are upgrading datastax Cassandra java driver from 3.2 to 4.x to support DSE 6.8. Load balancing policies our application currently supports are RoundRobinPolicy and DCAwareRoundRobinPolicy. These policies aren't available in java-driver-core 4.12. How can we support the above policies.Please help.. Current code in our application using cassandra-driver-core-3.1.0.jar:

public static LoadBalancingPolicy getLoadBalancingPolicy(String loadBalanceStr, boolean isTokenAware) {
        LoadBalancingPolicy loadBalance = null;
        if (isTokenAware) {
            loadBalance = new TokenAwarePolicy(loadBalanceDataConvert(loadBalanceStr));
        } else {
            loadBalance = loadBalanceDataConvert(loadBalanceStr);
        }
        
        return loadBalance;
        
    }
private static LoadBalancingPolicy loadBalanceDataConvert(String loadBalanceStr) {
        if (CassandraConstants.CASSANDRACONNECTION_LOADBALANCEPOLICY_DC.equals(loadBalanceStr)) {
            return new DCAwareRoundRobinPolicy.Builder().build();
        } else if (CassandraConstants.CASSANDRACONNECTION_LOADBALANCEPOLICY_ROUND.equals(loadBalanceStr)) {
            return new RoundRobinPolicy();
        }
        
        return null;
    }

Upvotes: 2

Views: 1759

Answers (1)

Erick Ramirez
Erick Ramirez

Reputation: 16323

The load balancing has been heavily simplified in version 4.x of the Cassandra Java driver. You no longer need to nest multiple policies within each other to achieve high availability.

In our opinion, the best policy is the DefaultLoadBalancingPolicy which is enabled by default and achieves all the best attributes as the policies in older versions.

The DefaultLoadBalancingPolicy generates a query plan that is token-aware by default so replicas which own the data appear first and prioritised over other nodes in the local DC. For token-awareness to work, you must provide routing information either by keyspace (with getRoutingKeyspace()), or by routing key (with getRoutingKey()).

If routing information is not provided, the DefaultLoadBalancingPolicy generates a query plan that is a simple round-robin shuffle of available nodes in the local DC.

We understand that developers who are used to configuring DCAwareRoundRobinPolicy in older versions would like to continue using it but we do not recommend it. It is our opinion that failover should take place at the infrastructure layer, not the application layer.

Our opinion is that the DefaultLoadBalancingPolicy is the right choice in all cases. If you prefer to configure DC-failover, make sure you fully understand the implications and know that we think it is the wrong choice.

For details, see the following documents:

Upvotes: 3

Related Questions