1

我们的 Cassandra 2.0.6 有问题。簇。我们的设置如下:

  • 2个数据中心,命名为:DC1、DC2
  • 每个 DC 中的两个节点
  • 使用 NetworkTopologyStrategy 进行复制
  • 客户端正在连接 Datastax Java Driver v. 1.0.3

首先,我创建了包含一个表的键空间。

CREATE KEYSPACE test 
WITH replication = {
  'class': 'NetworkTopologyStrategy',
  'DC1': '1',
  'DC2': '1'
};

CREATE TABLE account (
  id text,
  code text,
  alias text,
  PRIMARY KEY (id, code)
);

然后在运行此语句之前关闭 DC2:

INSERT INTO test.account (id, code, alias) VALUES ( '1', '2', '3') if not exists;

这导致了错误消息:

>>>> 无法完成请求:一个或多个节点不可用。

使用相同的环境,运行这条语句就OK了:

INSERT INTO test.account (id, code, alias) VALUES ( '1', '2', '3')

我找到了DC-local CAS 的 Cassandra 票证,所以我认为这种情况下的 CQL 必须只在本地数据中心处理,但事实并非如此。

我对轻量交易的理解有什么问题?

4

1 回答 1

5

The DataStax documentation explains (emphasis added):

Cassandra 2.0 uses the Paxos consensus protocol, which resembles 2-phase commit, to support linearizable consistency. All operations are quorum-based and updates will incur a performance hit ...

By default, your CAS operation (IF NOT EXISTS) uses a SERIAL isolation level for Paxos and needs to contact a quorum of all replicas. When you have only two replicas, as in your case (one in each data center), quorum requires both replicas. If you try your non-CAS insert with QUORUM consistency level, it too will fail.

CASSANDRA-5797 introduces the concept of LOCAL_SERIAL isolation level but it is not the default and must be explicitly specified in order to be used. How to do that will depend on how you are interfacing with Cassandra, e.g. the cqlsh client vs the DataStax Java Driver.

于 2014-04-26T05:39:01.177 回答