问题描述
Cassandra 3.1
NodeJS驱动程序:cassandra-driver 3.0.0
Cassandra 3.1NodeJS driver: cassandra-driver 3.0.0
使用以下语句创建键空间:
Keyspace is created using the following statement:
如果不存在则创建键盘空间xxxxxx
REPLICATION = {'class':'SimpleStrategy','replication_factor':2};
CREATE KEYSPACE IF NOT EXISTS xxxxxx WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 2 };
尽管复制因子为2,但出于一致性目的,我仅运行一个实例以将开发级别设置为ONE。
这是我尝试使用IF NOT EXISTS子句插入任何记录时遇到的问题,我遇到了一致性级别错误。但是没有IF NOT EXISTS的语句就可以正常工作。这是来自cqlsh的日志:
Even though the replication factor is 2 I am running only one instance for development purpose with consistency level set to ONE.Here is the issue when I try to insert any record with IF NOT EXISTS clause I am getting consistency level error. But statements without IF NOT EXISTS work just fine. Here is the log from cqlsh:
cqlsh:xxxxxx> CONSISTENCY;
Current consistency level is ONE.
cqlsh:xxxxxx> insert into accounts(account_id) values('test');
cqlsh:xxxxxx> insert into accounts(account_id) values('test1') if not exists;
Traceback (most recent call last): File "/usr/bin/cqlsh.py", line 1258, in perform_simple_statement result = future.result() File "/usr/share/cassandra/lib/cassandra-driver-internal-only-3.0.0-6af642d.zip/cassandra-driver-3.0.0-6af642d/cassandra/cluster.py", line 3122, in result raise self._final_exception Unavailable: code=1000 [Unavailable exception] message="Cannot achieve consistency level QUORUM" info={'required_replicas': 2, 'alive_replicas': 1, 'consistency': 'QUORUM'}
推荐答案
paxos的如果不存在子句使用不同的一致性设置 SERIAL CONSISTENCY,其值可以为SERIAL或LOCAL_SERIAL。
The "if not exists" clause for paxos uses a different consistency setting of "SERIAL CONSISTENCY", which can have the values SERIAL or LOCAL_SERIAL.
SERIAL设置意味着它将在所有副本中都达到法定人数,而LOCAL_SERIAL意味着它将在本地数据中心中达到法定人数。复制因子为2时,仲裁为2个副本。
The SERIAL setting means it will need a quorum across all replicas, while the LOCAL_SERIAL means it will need a quorum in the local data center. With a replication factor of 2, a quorum is 2 replicas.
不幸的是, SERIAL CONSISTENCY没有LOCAL_ONE或ONE设置,因此您需要两个复制副本,如果不存在,则可以为插入而活着。
Unfortunately there is no LOCAL_ONE or ONE setting for "SERIAL CONSISTENCY", so in your case you would need two replicas to be alive for your insert if not exists to succeed.
这篇关于Cassandra一致性级别和IF NOT EXISTS子句问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!