1. Overview
1.概述
In this tutorial, we’ll learn about the job of a snitch and how Cassandra uses it to efficiently route requests. We’ll also look at various types of snitches available in Cassandra.
在本教程中,我们将了解snitch的工作以及Cassandra如何使用它来有效地路由请求。我们还将了解 Cassandra 中可用的各种类型的告密者。
2. What Is a Snitch?
2.什么是告密者?
A snitch simply reports the rack and datacenter to which each node belongs – essentially, it determines and informs Cassandra about the network topology of the cluster.
告密者只是报告每个节点所属的机架和数据中心–本质上,它确定并通知Cassandra关于集群的网络拓扑结构。
With this knowledge of the cluster’s topology, including relative proximity between nodes, Cassandra is able to efficiently route requests to the appropriate nodes within the cluster.
有了对集群拓扑结构的了解,包括节点之间的相对接近性,Cassandra能够有效地将请求路由到集群中的适当节点。
2.1. Snitch on Write Operation
2.1.写入操作的告密者
Cassandra uses information from the snitch to group nodes into racks and datacenters. So in order to avoid correlated failures during a write operation, Cassandra makes every effort not to store replicas in the same rack.
Cassandra使用来自snitch的信息将节点分组到机架和数据中心。因此,为了避免在写操作期间出现相关的故障,Cassandra会尽力不将副本存储在同一个机架上。
2.2. Snitch on Read Operation
2.2.告密读操作
We know that, during a read operation, Cassandra must contact a number of nodes and replicas based on their consistency levels. In order to make the read operation efficient, Cassandra uses information from the snitch to identify the node that will return a replica fastest.
我们知道,在读取操作期间,Cassandra 必须根据节点和副本的一致性水平来联系一些节点和副本。为了使读取操作高效,Cassandra使用来自告密者的信息来识别将最快返回副本的节点。
This node is then queried for full row information. Then, Cassandra queries other replica nodes for hash values to ensure the latest data is returned.
然后这个节点被查询到完整的行信息。然后,Cassandra查询其他复制节点的哈希值,以确保返回最新的数据。
3. Types of Snitches
3.告密者的类型
The default snitch, SimpleSnitch, is not topology-aware. That is, it doesn’t know the racks and datacenters for the cluster. Therefore, it’s not suitable for multiple-datacenter deployments.
默认的snitch,SimpleSnitch,是没有拓扑意识的。也就是说,它不知道集群的机架和数据中心。因此,它不适合于多数据中心的部署。
For this reason, Cassandra has come up with various types of snitches that meet our requirements. Normally, we can configure the type of snitch in the configuration file cassandra.yml file via the property name endpoint_snitch.
为此,Cassandra提出了各种类型的snitch,以满足我们的要求。通常,我们可以在配置文件cassandra.yml文件中通过属性名endpoint_snitch来配置snitch的类型。
Let’s look at a few types of snitches and how they work.
让我们看看几种类型的告密者和他们的工作方式。
3.1. PropertyFileSnitch
3.1.PropertyFileSnitch</em
The PropertyFileSnitch is a rack-aware snitch. We can provide the cluster topology information as key-value properties in the file called cassandra-topology.properties. In this property file, we provide the rack and datacenter names, each node belongs to.
PropertyFileSnitch是一个机架感知的告警。我们可以在名为cassandra-topology.property的文件中以键值属性的形式提供集群拓扑信息。在这个属性文件中,我们提供每个节点所属的机架和数据中心名称。
Moreover, we can use any name for the rack and the datacenter. But we need to make sure datacenter names match the ones defined as the NetworkTopologyStrategy in the keyspace definition.
此外,我们可以为机架和数据中心使用任何名称。但是我们需要确保数据中心的名称与关键空间定义中作为网络拓扑策略的名称相匹配。
Here is an example content of cassandra-topology.properties:
下面是一个cassandra-topology.properties的内容示例。
# Cassandra Node IP=Data Center:Rack
172.86.22.125=DC1:RAC1
172.80.23.120=DC1:RAC1
172.84.25.127=DC1:RAC1
192.53.34.122=DC1:RAC2
192.55.36.134=DC1:RAC2
192.57.302.112=DC1:RAC2
# default for unknown nodes
default=DC1:RAC1
In the above example, there are two racks (RAC1, RAC2) and one datacenter (DC1). Any node IP not covered will fall into the default datacenter (DC1) and rack (RAC1).
在上述例子中,有两个机架(RAC1,RAC2)和一个数据中心(DC1)。任何未被覆盖的节点IP将落入默认的数据中心(DC1)和机架(RAC1)。
One drawback with this snitch is that we need to make sure the cassandra-topology.properties file is in sync with all the nodes in a cluster.
这个狙击手的一个缺点是,我们需要确保cassandra-topology.properties文件与集群中的所有节点保持同步。
3.2. GossipingPropertyFileSnitch
3.2.GossipingPropertyFileSnitch
GossipingPropertyFileSnitch is also a rack-aware snitch. To avoid manual syncing of the racks and datacenters as required in PropertyFileSnitch, in this snitch, we just define the rack and datacenter name individually for each node in the cassandra-rackdc.properties file.
GossipingPropertyFileSnitch也是一个机架感知的告警。为了避免像PropertyFileSnitch中要求的那样手动同步机架和数据中心,在这个告警中,我们只是在cassandra-rackdc.properties文件中为每个节点单独定义机架和数据中心名称。
And these racks’ and datacenters’ information are exchanged with all nodes using the gossip protocol.
而这些机架和数据中心的信息则通过八卦协议与所有节点进行交流。
Here’s an example content of the cassandra-rackdc.properties file:
下面是一个cassandra-rackdc.properties文件的内容示例。
dc=DC1
rack=RAC1
3.3. Ec2Snitch
3.3.Ec2Snitch[/em
As the name suggests, Ec2Snitch is related to cluster deployment in Amazon Web Service (AWS) EC2. Within a single AWS region deployment, the region name is treated as the datacenter and the availability zone name is considered the rack.
顾名思义,Ec2Snitch与集群在亚马逊网络服务(AWS)EC2的部署有关。在一个单一的AWS区域部署中,区域名称被视为数据中心,可用区名称被视为机架。
If we only need a single-datacenter deployment, no property configuration is required. Whereas, in the case of multiple-datacenter deployments, we can specify the dc_suffix in the cassandra-rackdc.properties file.
如果我们只需要一个单数据中心的部署,则不需要任何属性配置。而在多数据中心部署的情况下,我们可以在cassandra-rackdc.properties 文件中指定dc_suffix。
For example, in the us-east region, if we need a couple of datacenters, we can provide the dc_suffix configuration as:
例如,在us-east地区,如果我们需要几个数据中心,我们可以提供dc_suffix配置为。
dc_suffix=_1_DC1
dc_suffix=_1_DC2
Each configuration given above goes into two different nodes. Consequently, it results in us_east_1_DC1 and us_east_1_DC2 as the names of datacenters.
上面给出的每个配置都进入了两个不同的节点。因此,它的结果是us_east_1_DC1和us_east_1_DC2作为数据中心的名称。
3.4. Ec2MultiRegionSnitch
3.4.Ec2MultiRegionSnitch
In the case of multi-region cluster deployment in AWS, we should use the Ec2MultiRegionSnitch. Moreover, we need to configure both cassandra.yaml and cassandra-rackdc.properties.
在AWS的多区域集群部署中,我们应该使用Ec2MultiRegionSnitch。此外,我们还需要配置cassandra.yaml和cassandra-rackdc.properties.。
We have to configure the public IP address as the broadcast_address and also, if needed, use it as a seed node in cassandra.yaml. Additionally, we must configure a private IP address as the listen_address. Finally, we have to open up the session_port or ssl_session_port on the public IP firewall.
我们必须将公共IP地址配置为broadcast_address,如果需要,还可以在cassandra.yaml中将其作为种子节点。此外,我们必须配置一个私有 IP 地址作为 listen_address。 最后,我们必须在公共 IP 防火墙上打开 session_port 或 ssl_session_port。
These configurations allow the nodes to communicate across the AWS regions, thus enabling multiple-datacenter deployments across regions. In the case of a single region, Cassandra nodes switch to the private IP address for communication after the connection is made.
这些配置允许节点跨AWS区域进行通信,从而实现跨区域的多数据中心部署。在单一区域的情况下,Cassandra节点在连接完成后会切换到私有IP地址进行通信。
The dc_suffix datacenter configuration in cassandra_rackdc.properties for each node across the region is similar to Ec2Snitch.
在cassandra_rackdc.properties中,整个区域的每个节点的dc_suffix数据中心配置与Ec2Snitch类似。
3.5. GoogleCloudSnitch
3.5.GoogleCloudSnitch
As the name suggests, GoogleCloudSnitch is for cluster deployments in the Google Cloud Platform across one or more regions. Similar to AWS, the region name is considered the datacenter and the availability zone is the rack.
顾名思义,GoogleCloudSnitch是用于在Google云平台上跨一个或多个区域的集群部署。与AWS类似,区域名称被认为是数据中心,可用性区域是机架。
We don’t need any configuration in the case of a single-datacenter deployment. Conversely, in the case of multiple-datacenter deployments, similar to Ec2Snitch, we can set the dc_suffix in the cassandra-rackdc.properties file.
在单数据中心部署的情况下,我们不需要任何配置。相反,在多数据中心部署的情况下,与Ec2Snitch类似,我们可以在cassandra-rackdc.properties文件中设置dc_suffix。
3.6. RackInferringSnitch
3.6.RackInferringSnitch
RackInferringSnitch infers proximity of nodes into racks and datacenters from the third and second octets of the nodes’ IP addresses.
RackInferringSnitch从节点的IP地址的第三个和第二个八位字节推断节点与机架和数据中心的接近程度。
4. Dynamic Snitching
4.动态告密
By default, Cassandra wraps any snitch type that we configure in the cassandra.yml file with another type of snitch called the DynamicEndpointSnitch. This dynamic snitch gets the basic information of the cluster topology from the underlying snitch, which is already configured. It then monitors the read latency of nodes, even keeping track of the compaction operations in any nodes.
默认情况下,Cassandra将我们在cassandra.yml文件中配置的任何snitch类型与另一种叫做DynamicEndpointSnitch.的snitch进行包装。这种动态snitch从已经配置好的底层snitch获得集群拓扑结构的基本信息。然后,它监测节点的读取延迟,甚至跟踪任何节点的压实操作。
This performance data is then used by the dynamic snitch to select the best replica node for any read query. This way, Cassandra avoids rerouting read requests to bad or busy (slow-performing) replica nodes.
这些性能数据然后被动态狙击手用来为任何读取查询选择最佳复制节点。这样,Cassandra避免将读取请求转发到糟糕或繁忙(性能缓慢)的复制节点。
The dynamic snitch uses a modified version of the Phi accrual failure detection mechanism used by gossip to determine the best replica node on the read request. The badness threshold is a configurable parameter that determines how badly a preferred node must perform, compared to the best performing node, in order to lose its preferential status.
动态告密者使用gossip使用的Phi累加失败检测机制的修改版,以确定读取请求上的最佳复制节点。坏境阈值是一个可配置的参数,它决定了一个优先节点必须比表现最好的节点表现得更糟糕,才能失去其优先地位。
Cassandra resets the performance scores of each node periodically to allow the bad performing node to recover and perform better so as to reclaim its preferential status.
Cassandra定期重置每个节点的性能分数,让性能不好的节点恢复并表现得更好,从而重新获得其优先地位。
5. Conclusion
5.总结
In this tutorial, we learned what a Snitch is and also went through some of the Snitch types available for us to configure in a Cassandra cluster deployment.
在本教程中,我们了解了什么是Snitch,还经历了一些可供我们在Cassandra集群部署中配置的Snitch类型。