【问题标题】:Understanding Cassandra system.peers Query using C# Driver使用 C# 驱动程序了解 Cassandra system.peers 查询
【发布时间】:2015-11-05 06:32:15
【问题描述】:

当我从节点 1 查询 peers 表时,我不确定为什么会得到与联络点相同的 peer。

当我将 ip 更改为 46(node2) 我得到 45(node1) ,但是从 45(node1) 查询我得到 45(node1)

        Cluster clusterconn = Cluster.Builder().WithCredentials(txtuser.Text, txtsec.Text).AddContactPoint("192.168.0.45).Build();
        ISession Conn_session = clusterconn.Connect("system");

        var con_result = Conn_session.Execute("select peer FROM system.peers");


     //   lstnode.Items.Add(txt_pip.Text);


        foreach (var rows in con_result)
        {

            //var value = row.GetValue<int>("id");

            lstnode.Items.Add(rows["peer"].ToString());



        }

【问题讨论】:

    标签: c# cassandra cassandra-2.0


    【解决方案1】:

    您正在看到驱动程序负载平衡策略的效果。 system.peers 是每个节点上不同的本地表。当您使用驱动程序执行查询时,它会在节点之间进行负载平衡,每次都会给出不同的结果。

    如果您多次执行并打印结果,您应该会看到节点之间交替出现对等节点。

    阅读一些关于负载平衡策略的内容here

    【讨论】:

    • 我该怎么做才能始终点击选定的节点之一?而不是使用驱动程序负载平衡策略
    • 一些驱动程序有一个叫做白名单负载平衡策略的东西,可以用来限制连接的节点。这不是针对 C# 实现的。两个选项: - 运行两次查询(命中两个不同的节点)并合并结果 - 如果您只对集群发现感兴趣,只需使用驱动元数据 API:docs.datastax.com/en/drivers/csharp/2.5/html/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-26
    • 2023-03-21
    • 2014-03-31
    • 2019-11-08
    • 2012-03-04
    • 2020-04-12
    • 2021-01-04
    相关资源
    最近更新 更多