问题
I am trying to experiment with lightweight transactions in Cassandra by using SERIAL
consistency. However, trying to set the consistency level in cqlsh results in an error:
cqlsh:learning> CONSISTENCY SERIAL;
Improper CONSISTENCY command.
The WITH CONSISTENCY
statement has been removed from CQL and so I cannot use that. Is there a way to enable serial consistency from cqlsh? Or do I have to do it using a driver?
回答1:
The CONSISTENCY
command should still work in cqlsh. But valid values for this setting are:
- ANY
- ONE
- TWO
- THREE
- QUORUM
- ALL
- LOCAL_QUORUM
- EACH_QUORUM
SERIAL is not in that list, hence the error you are seeing. There is an open Jira ticket to address this: CASSANDRA-8051
This appears to be a consistency level that has some restrictions around it, thus making this difficult to implement. The Consistency Level descriptions indicate that:
You cannot configure this level as a normal consistency level, configured at the driver level using the consistency level field.
The Java Driver apparently has a specific method to set this consistency level:
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.
来源:https://stackoverflow.com/questions/28591874/how-do-i-set-consistency-to-serial-in-cqlsh