Michal
Michal

Reputation: 2238

Cassandra how to set default consistency - cluster level

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

Answers (2)

Eugen Constantin Dinca
Eugen Constantin Dinca

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 ExecutionProfiles.

In cqlsh use the CONSISTENCY command.

Upvotes: 3

Suleyman Arslan
Suleyman Arslan

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

Related Questions