Reputation: 2238
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.
Upvotes: 4
Views: 2734
Reputation: 9150
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.
Upvotes: 3
Reputation: 298
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.
Cassandra batch statements memory leak issue
Upvotes: 1