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

时间:2016-05-13 18:09:14

标签: cassandra cql

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

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};

然后我创建了一个简单的表用户(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

有谁知道发生了什么?

1 个答案:

答案 0 :(得分:0)

使用nodetool status时显示的数据中心名称在定义键空间策略时必须与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并执行节点修复。