尝试将数据插入 cassandra 集群时出现一致性级别错误

Consistency level error while trying to insert data to cassandra cluster

我有以下集群,由两个不同数据中心的两个节点组成:

Datacenter: 168
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address         Load       Owns (effective)  Host ID                               Token                                    Rack
UN  10.168.92.13    47.44 KB   100.0%            70e6fb88-60d3-4f19-b4a7-4eacc6790042  -9223372036854775808                     92
Datacenter: 186
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address         Load       Owns (effective)  Host ID                               Token                                    Rack
UN  10.186.163.119  73.33 KB   100.0%            19714869-3d7a-434b-9c41-e7d90f14205c  0                                        163

我使用 NetworkTopologyStrategy 创建了一个键空间来在节点之间传播数据。假设这将在每个数据中心复制数据,如下所示:

Create KEYSPACE demo WITH replication = {'class':'NetworkTopologyStrategy','DC1':1,'DC2':1};

然后我创建了一个简单的 table 用户 (id,name,last_name) 但是当我尝试向其中导入或插入数据时出现以下错误:

Traceback (most recent call last):
  File "./bin/cqlsh", line 1108, in perform_simple_statement
    rows = self.session.execute(statement, trace=self.tracing_enabled)
  File "/home/ubuntu/cassandra/bin/../lib/cassandra-driver-internal-only-2.7.2.zip/cassandra-driver-2.7.2/cassandra/cluster.py", line 1602, in execute
    result = future.result()
  File "/home/ubuntu/cassandra/bin/../lib/cassandra-driver-internal-only-2.7.2.zip/cassandra-driver-2.7.2/cassandra/cluster.py", line 3347, in result
    raise self._final_exception
Unavailable: code=1000 [Unavailable exception] message="Cannot achieve consistency level ONE" info={'required_replicas': 1, 'alive_replicas': 0, 'consistency': 'ONE'}

我也在cassandra.yaml文件里设置了endpoint_snitch: RackInferringSnitch

有人知道这是怎么回事吗?

在使用nodetool status时出现的datacenters名称必须与定义keyspace策略时dcs的名称相匹配,例如:

Create KEYSPACE demo WITH replication = {'class':'NetworkTopologyStrategy','DC1':1,'DC2':1};

应该是:

Create KEYSPACE demo WITH replication = {'class':'NetworkTopologyStrategy','168':1,'186':1};

或者将数据中心重命名为 DC1 和 DC2 并执行节点修复。