Cassandra如何选择节点发送请求? [英] How Cassandra select the node to send request?

查看:259
本文介绍了Cassandra如何选择节点发送请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,Cassandra集群需要由客户端应用程序访问。在Java API中,我们创建一个集群实例,并通过一个Session发送读或写请求。如果我们使用读/写一致性ONE,api如何选择实际节点(协调器节点)以便转发请求。是随机选择吗?请帮助解决这个问题。

Imagine a Cassandra cluster needs to be accessed by a client application. In Java api we create a cluster instance and send the read or write request via a Session. If we use read/write consistency ONE, how the api select the actual node (coordinator node) in order to forward the request. Is it a random selection? please help to figure this out.

推荐答案

Cassandra驱动程序使用gossip协议有关集群的信息。如果节点不可用,则客户端驱动程序自动尝试其他节点并使用死节点安排重新连接时间。根据到DataStax文档

Cassandra drivers use the "gossip" protocol (and a process called node discovery) to gain information about the cluster. If a node becomes unavailable, the client driver automatically tries other nodes and schedules reconnection times with the dead one(s). According to the DataStax docs:


Gossip是对等通信协议,其中节点
周期性地交换关于他们自己和他们知道的其他节点的状态信息。闲话过程每秒运行一次,
与群集中最多三个其他节点交换状态消息。
节点交换关于他们自己以及他们所讨论的其他
节点的信息,所以所有节点快速了解集群中所有其他节点的

Gossip is a peer-to-peer communication protocol in which nodes periodically exchange state information about themselves and about other nodes they know about. The gossip process runs every second and exchanges state messages with up to three other nodes in the cluster. The nodes exchange information about themselves and about the other nodes that they have gossiped about, so all nodes quickly learn about all other nodes in the cluster.

基本上,您为客户端提供连接的节点列表是获取整个集群信息的初始联系点。这是为什么你的客户端可以与群集中的所有节点进行通信(如果需要),即使你只能在连接字符串中提供一小部分节点。

Essentially, the list of nodes that you provide your client to connect to, are the initial contact points for gaining information on the entire cluster. This is why your client can communicate with all nodes in the cluster (if need be) even though you may only provide a small subset of nodes in your connection string.

一次您的驱动程序在群集上有闲话信息,那么它可以做出关于哪个节点运行查询的智能决策。节点选择不是投票或随机选择的过程。根据返回的八卦信息,客户端驱动程序会应用其负载平衡政策。虽然它需要考虑几个因素,基本上它试图选择与客户端具有最低网络距离的节点。

Once your driver has the gossip information on the cluster, it can then make intelligent decisions about which node to run a query on. Node selection is not a process of voting or random selection. Based on the gossip information returned, the client driver applies its Load Balancing Policy. While it does take several factors into consideration, basically it tries to pick the node with the lowest network "distance" from the client.

这篇关于Cassandra如何选择节点发送请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆