Note that there are some explanatory texts on larger screens.

plurals
  1. POBest practice for managing different consistency levels using the Datastax Cassandra native java client
    primarykey
    data
    text
    <p>Using CQL3, the Cassandra consistency level is now set at the session level. The Datastax documentation for the native Java client states:</p> <blockquote> <p>Session instances are thread-safe and usually a single instance is all you need per application</p> </blockquote> <p>But I struggle to see how a single Session instance can handle multiple consistency levels (for example writes with QUORUM and reads with ONE). I see potential race conditions all over the place.</p> <p>An obvious solution would be to create separate sessions for reads and writes, each with the appropriate consistency level set. But this doesn't fully solve the problem. What if a class modified the consistency level for one of the two sessions? All subsequent users of the Session instance would then, unknowingly, be using the new CL.</p> <p>So, as far as I can see, the safest option is to create a new Session instance each time Cassandra needs to be accessed, with the CL explicitly set upon creation.</p> <p>What is not clear to me is whether this approach would entail a performance penalty. For example, would either <code>session = cluster.connect()</code> or <code>session.execute("CONSISTENCY [cl]")</code> involve a trip to the server?</p> <p>Am I missing something here? Has anybody got any relevant experience to share? Thanks.</p> <p>UPDATE: I see <code>com.datastax.driver.core.Query</code> has a method for setting the consistency level. So perhaps the simplest option is stick with a single Session instance and set the CL for each query.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload