0

Our application currently uses cassandra-driver-core-3.1.0 and it implements token-aware load balancing policy. We are upgrading the driver to java-driver-core-4.13.0, token-aware policy isn't available with the driver. In Datastax docs,it's mentioned token-aware is the default policy. Should we've to write some code for it or if we use the default load balancing policy, DefaultLoadBalancingPolicy token-aware will be taken care of? I'm new to Cassandra. Can anyone please help..

import com.datastax.driver.core.policies.RoundRobinPolicy;
import com.datastax.driver.core.policies.TokenAwarePolicy;
import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
import com.datastax.driver.core.policies.LoadBalancingPolicy;
    
    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;
    }
    

https://docs.datastax.com/en/developer/java-driver/4.2/manual/core/load_balancing/

1 Answer 1

0

You don't need to implement anything yourself, just use default load balancing policy - it's token-aware by default, as described in the documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

Can you please let me know if we can try connecting to remote nodes after all nodes in local datacenter has been tried and failed as in DCAwareRoundRobin policy.We donot have this option in datastax 4.0,as using the driver we can only connect to a single datacenter and in datastax docs,it's mentioned load-balancing policy is local-only.docs.datastax.com/en/developer/java-driver/4.0/upgrade_guide

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.