Cassandra如何找到包含数据的节点? [英] How does cassandra find the node that contains the data?

查看:208
本文介绍了Cassandra如何找到包含数据的节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多关于Cassandra的文章和关于SO的许多问题/答案,但是我仍然无法弄清楚Cassandra在读取数据时如何决定去哪个节点。

I've read quite a few articles and a lot of question/answers on SO about Cassandra but I still can't figure out how Cassandra decides which node(s) to go to when it's reading the data.

首先,对一个虚构簇进行一些假设:

First, some assumptions about an imaginary cluster:


  1. 复制策略=简单

  2. 使用随机分区程序

  3. 10个节点的群集

  4. 复制因子5

  1. Replication Strategy = simple
  2. Using Random Partitioner
  3. Cluster of 10 nodes
  4. Replication Factor of 5

这是我根据我读过的各种Datastax文章和其他博客文章对写法的理解:

Here's my understanding of how writes work based on various Datastax articles and other blog posts I've read:


  • 客户端将数据发送到随机节点

  • 随机节点是基于主键的MD5哈希值确定的。

  • 数据被写入commit_log和memtable,然后传播4次(RF = 5)。

  • Client sends the data to a random node
  • The "random" node is decided based on the MD5 hash of the primary key.
  • Data is written to the commit_log and memtable and then propagated 4 times (with RF = 5).

其中的下四个节点

到目前为止,很好。

现在问题是,当客户端向集群发送读取请求(例如,CL = 3)时,Cassandra如何知道要获取该数据需要联系哪些节点(在最坏的情况下,十分之五)?当然,它不会到达所有10个节点,因为这样效率低下。

Now the question is, when the client sends a read request (say with CL = 3) to the cluster, how does Cassandra know which nodes (5 out of 10 as the worst case scenario) it needs to contact to get this data? Surely it's not going to all 10 nodes as that would be inefficient.

我正确地假设Cassandra将再次对主键(

Am I correct in assuming that Cassandra will again, do an MD5 hash of the primary key (of the request) and choose the node according to that and then walks the ring?

此外,网络拓扑情况如何工作?如果我有多个数据中心,Cassandra如何知道每个DC /机架中的哪些节点包含数据?据我了解,只有第一个节点是显而易见的(因为主键的哈希已显式地导致了该节点)。

Also, how does the network topology case work? if I have multiple data centers, how does Cassandra know which nodes in each DC/Rack contain the data? From what I understand, only the first node is obvious (since the hash of the primary key has resulted in that node explicitly).

很抱歉,问题不是很清楚如果需要有关我的问题的更多详细信息,请添加评论。

Sorry if the question is not very clear and please add a comment if you need more details about my question.

非常感谢,

推荐答案


客户端将数据发送到随机节点

Client sends the data to a random node

,但实际上,驱动程序会选择一种非随机方式来与之对话。该节点称为协调器节点,通常基于具有最小(最接近)网络距离的节点进行选择。客户端请求实际上可以发送到任何节点,首先,它们将发送到驱动程序知道的节点。但是,一旦连接并了解了群集的拓扑,它便可能会变为更紧密的协调器。

It might seem that way, but there is actually a non-random way that your driver picks a node to talk to. This node is called a "coordinator node" and is typically chosen based-on having the least (closest) "network distance." Client requests can really be sent to any node, and at first they will be sent to the nodes which your driver knows about. But once it connects and understands the topology of your cluster, it may change to a "closer" coordinator.

群集中的节点使用以下方式相互交换拓扑信息: 八卦协议。闲聊每秒运行一次,并确保所有节点保持最新状态,而 Snitch 您已配置。告密者会跟踪每个节点属于哪个数据中心和机架。

The nodes in your cluster exchange topology information with each other using the Gossip Protocol. The gossiper runs every second, and ensures that all nodes are kept current with data from whichever Snitch you have configured. The snitch keeps track of which data centers and racks each node belongs to.

通过这种方式,协调器节点还具有有关哪个节点负责每个令牌范围的数据。您可以通过在命令行中运行 nodetool环来查看此信息。尽管如果使用的是vnode,这将很难确定,因为所有256个(默认)虚拟节点上的数据都会在屏幕上快速闪烁。

In this way, the coordinator node also has data about which nodes are responsible for each token range. You can see this information by running a nodetool ring from the command line. Although if you are using vnodes, that will be trickier to ascertain, as data on all 256 (default) virtual nodes will quickly flash by on the screen.

我有一张桌子,用来按船员的名字追踪他们,并假设我要查找Malcolm Reynolds。运行此查询:

So let's say that I have a table that I'm using to keep track of ship crew members by their first name, and let's assume that I want to look-up Malcolm Reynolds. Running this query:

SELECT token(firstname),firstname, id, lastname 
FROM usersbyfirstname  WHERE firstname='Mal';

...返回此行:

 token(firstname)     | firstname | id | lastname
----------------------+-----------+----+-----------
  4016264465811926804 |       Mal |  2 |  Reynolds

通过运行 nodetool环查看哪个节点负责此令牌:

By running a nodetool ring I can see which node is responsible for this token:

192.168.1.22  rack1       Up     Normal  348.31 KB   3976595151390728557                         
192.168.1.22  rack1       Up     Normal  348.31 KB   4142666302960897745                         

或更简单的是,我可以使用 nodetool getendpoints 查看此数据:

Or even easier, I can use nodetool getendpoints to see this data:

$ nodetool getendpoints stackoverflow usersbyfirstname Mal
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 
192.168.1.22

更多信息,请查看上面链接的某些项目,或尝试运行 nodetool闲话信息

For more information, check out some of the items linked above, or try running nodetool gossipinfo.

这篇关于Cassandra如何找到包含数据的节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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