Cassandra Java Driver 4.X可用哪些负载平衡政策?

发布于 2025-02-08 09:56:15 字数 1091 浏览 1 评论 0原文

我们正在将DataStax Cassandra Java驱动程序从3.2升级到4.x,以支持DSE 6.8。 负载平衡政策我们的应用程序当前支持是Roundrobinpolicy和Dcawareroundrobinpolicy。 这些政策在Java-Driver-Core 4.12中没有。 我们如何支持上述政策。请帮助。 使用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;
    }

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;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冧九 2025-02-15 09:56:15

在Cassandra Java驱动程序的4.x版本中,负载平衡已大大简化。您不再需要在彼此之间嵌套多个政策来实现高可用性。

我们认为,最好的策略是defaultloadbalancing -policy,默认情况下启用,并将所有最佳属性作为较旧版本的策略实现。

defaultloadbalancingpolicy生成一个查询计划,该查询计划默认情况下是象征性的,因此拥有数据首先出现并优先于本地DC中的其他节点。为了使令牌意识工作,您必须通过键空间(使用getRoutingKeySpace())提供路由信息,或者通过路由键(带有getRoutingKey())。

如果没有提供路由信息,则defaultloadBalancingPolicy生成了一个查询计划,该计划是本地DC中可用节点的简单圆形旋转shuffle。

我们了解到,习惯于在较旧版本中配置DCAWAREROUNDROBINPOLICY的开发人员希望继续使用它,但我们不建议它。我们认为,故障转移应在基础架构层,而不是应用程序层进行。

我们的观点是,在所有情况下,defaultloadbalancingpolicy都是正确的选择。如果您希望配置DC Failover,请确保您完全理解含义,并知道我们认为这是错误的选择。

有关详细信息,请参阅以下文档:

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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文