How to set default consistency level in cassandra on cluster level?
Cassandra documentation is mentioning it's possible: "You can configure consistency on a cluster, data center, or individual I/O operation basis" but there's no such option in yaml file.
With the Java Driver you can override the default CL (of ONE) when building the cluster:
QueryOptions qo = new QueryOptions();
qo.setConsistencyLevel(ConsistencyLevel.QUORUM);
cluster = Cluster.builder()
.withQueryOptions(qo)
.addContactPoints(CONTACT_POINTS).withPort(PORT)
.build();
The Python Driver seem to supports this also, via ExecutionProfile
s.
In cqlsh
use the CONSISTENCY command.
Consistency level is set in driver level just before running a query, so there is no such option in Cassandra.yaml file.
If you intend to use a prepared statement (Java Driver example):
PreparedStatement prepStatement = session.prepare("select * from users");
prepStatement.setConsistencyLevel(ConsistencyLevel.ALL);
Our approach setting consistency level in all statements was centralizing statement creation in a utility class. With this approach we also successfully prevent memory leaks in batch statements.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.