Datastax卡桑德拉插入与ifNotExists
问题描述:
我创建了一个密钥空间Datastax卡桑德拉插入与ifNotExists
CREATE KEYSPACE xyz WITH replication = {'class': 'NetworkTopologyStrategy', 'DC1': '1', 'datacenter1': '1'} AND durable_writes = true;
我只有两个节点,都DC1以及datacenter1节点都已启动。现在,当我试图执行批量插入语句
Insert insert = QueryBuilder.insertInto(keyspace, table).ifNotExists()
.value("home", fieldsToUpdate.getHome())
.value("subCategoryName", fieldsToUpdate.getSubCategoryName())
.value("id", fieldsToUpdate.getId());
batch.add(insert);
session.execute(batch);
我得到一个异常说
Caused by: com.datastax.driver.core.exceptions.UnavailableException: Not enough replica available for query at consistency QUORUM (2 required but only 1 alive)
当我删除.ifNotExists()第一批执行没有任何异常。
使用datastax驱动程序版本2.1.7。
我应该怎么做来解决这个问题?
编辑: Nodetool状态
abhisheks-MacBook-Pro:bin abhishekagarwal$ sudo ./nodetool status
objc[3398]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns Host ID Rack
UN 192.168.1.111 19.81 MB 256 ? f2651124-abdf-486a-a6d7-53327bc2d98c RAC1
UN 192.168.1.5 5.22 MB 256 ? d0c72798-1186-4bcb-9e0f-634964a3d083 rack1
Note: Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless
答
问题是你已经定义了密钥空间,以保持“datacenter1”一个副本,在数据中心的一个副本“DC1”。但是您没有一个名为'DC1'的数据中心,因此无法在if not exists
子句的两个数据中心中获得法定数量的复制副本。
所以,你应该已经定义了密钥空间是这样的:
CREATE KEYSPACE xyz WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1': '1'}
你能表现出“nodetool状态”的输出。这将有助于诊断问题。 –