setting consistecny level Quorum
Hi, I see that the WITH CONSISTENCY clause has been removed from CQL 3 commands. I am using kunedra-cassandra for my project. In terminal i am able to set the consistency level to Quorum using the command:-CONSISTENCY QUORUM. But as soon as i log out of that Cql it is again set to ONE. Is there any way i can set the consistency level to QUORUM using kundera-Cassandra?
For example, if persistence unit name is "cassandra_pu", then you can set it using Kundera as (on operation level for each session):
Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();
ThriftClient tc = (ThriftClient) clientMap.get("cassandra_pu");
tc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);
tc.setConsistencyLevel(ConsistencyLevel.QUORUM);
Also, it is possible to set it via external xml configuration file as well.
-Vivek
Thanks a lot.
Can i get any example for the external xml configuration file
https://github.com/impetus-opensource/Kundera/wiki/Cassandra-Specific-Features.
Also, please look https://github.com/impetus-opensource/Kundera/blob/trunk/kundera-cassandra/src/test/resources/META-INF/persistence.xml, for:
<property name="kundera.client.property" value="kunderaTest.xml" />
for reference.
-Vivek
thanks
Whats the string name for setting the consistency level?I could set the CQL version using the external config file but the consistency level doesn't seem to be working.
--""xml version="1.0" encoding="UTF-8"?>
--
My Bad. consistencyLevel is only possible at operation level. So you can set it only via previously mentioned way for each read/write consistency level.
-Vivek
The WITH CONSISTENCY clause has been removed from CQL 3 commands in the release version of CQL 3. I am setting my configurations using : Map<String, String> propertyMap = new HashMap<String, String>(); propertyMap.put(CassandraConstants.CQL_VERSION, CassandraConstants.CQL_VERSION_3_0); how can we set consistency level in this ?
propertyMap.put("consistency.level",ConsistencyLevel.QUORUM);
The method put(String, String) in the type Map<String,String> is not applicable for the arguments (String, ConsistencyLevel) :(
Change map generics parameter as:
Map<String, Object> props = new HashMap<String, Object>();
props.put("consistency.level",ConsistencyLevel.QUORUM);
props.put(CassandraConstants.CQL_VERSION,CassandraConstants.CQL_VERSION_3_0);
import org.apache.cassandra.db.ConsistencyLevel;
Hope this helps.
-Vivek
Thanks Vivek.Got some generics class also ;) this works perfectly fine. Was wondering if this becomes configurable in external file things will be easy to change in a production env and really VERY NICE feature which kundera can provide.
I have this kind of code :
@PersistenceContext(unitName = "cassandra_pu", type = PersistenceContextType.EXTENDED)
private EntityManager em;
with the external configs for setting the cql version .
was wondering how to get this work with the solution u gave.
As for JPA, you can set additional properties within @PersistenceContext annotation:
@PersistenceContext(type = PersistenceContextType.EXTENDED, properties = {
@PersistenceProperty(name = "consistency.level", value="QUORUM")
})
private EntityManager em;
but i have found, that CassandraClientProperties class for now accepts only enum value for consistency.level option.
public void populateClientProperties(Client client, Map<String, Object> properties) {
CassandraClientBase cassandraClientBase = (CassandraClientBase) client;
if (properties != null) {
for (String key : properties.keySet()) {
Object value = properties.get(key);
if (key.equals(CONSISTENCY_LEVEL) && value instanceof ConsistencyLevel) {
cassandraClientBase.setConsistencyLevel((ConsistencyLevel) value);
}
else if (key.equals(CQL_VERSION) && value instanceof String) {
cassandraClientBase.setCqlVersion((String) value);
}
...
May be this should be created as an issue?
:+1: for relaxing enum constraint. Will discuss alternate solutions and as well as @PersistenceProperty option.
-Vivek
@dtuzikov
Out of context, 1 question. Using Kundera for?
-Vivek
@dtuzikov Thanks a lot for the solution. @mevivs thanks for your support
@mevivs I'm using Kundera for working with historical database on Cassandra 1.2. (Financial app)
@dtuzikov Thanks. Could you please spare couple of minutes to provide your feedback? Here it is: http://www.surveymonkey.com/s/BMB9PWG
-Vivek
Hi,
@PersistenceContext(type = PersistenceContextType.EXTENDED, properties = {
@PersistenceProperty(name = "consistency.level", value="QUORUM")
})
I was also going to use something like this to set the consistency.level, is it working ?
Yes this is working for me.