如何在 cqlsh 中将 CONSISTENCY 设置为 SERIAL?

How do I set CONSISTENCY to SERIAL in cqlsh?

我正在尝试使用 SERIAL 一致性在 Cassandra 中试验轻量级事务。但是,尝试在 cqlsh 中设置一致性级别会导致错误:

cqlsh:learning> CONSISTENCY SERIAL;
Improper CONSISTENCY command.

WITH CONSISTENCY 语句已从 CQL 中删除,因此我不能使用它。有没有办法从 cqlsh 启用串行一致性?还是我必须使用驱动程序才能完成?

CONSISTENCY 命令在 cqlsh 中应该仍然有效。但此设置的 valid values 是:

  • 任意
  • 一个
  • 两个
  • 三个
  • 法定人数
  • 全部
  • LOCAL_QUORUM
  • EACH_QUORUM

SERIAL 不在该列表中,因此出现您看到的错误。有一个开放的 Jira 票可以解决这个问题:CASSANDRA-8051

这似乎是一个有一些限制的一致性级别,因此很难实施。 Consistency Level descriptions 表示:

You cannot configure this level as a normal consistency level, configured at the driver level using the consistency level field.

Java Driver apparently has a specific method设置此一致性级别:

The serial consistency level of the query, set with Statement.setSerialConsistencyLevel(), is similar to the consistency level, but only used in queries that have conditional updates. That is, it is only used in queries that have the equivalent of the IF condition in CQL.