kundera icon indicating copy to clipboard operation
kundera copied to clipboard

setting consistecny level Quorum

Open Gargee opened this issue 13 years ago • 22 comments

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?

Gargee avatar Jul 22 '13 19:07 Gargee

    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

mevivs avatar Jul 22 '13 19:07 mevivs

Thanks a lot.

Gargee avatar Jul 22 '13 19:07 Gargee

Can i get any example for the external xml configuration file

Gargee avatar Jul 22 '13 19:07 Gargee

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

mevivs avatar Jul 22 '13 19:07 mevivs

thanks

Gargee avatar Jul 22 '13 19:07 Gargee

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.

--" -- -- "<"datastores">" -- "<"dataStore"> "<"name>cassandra"<"/name> "<"connection">" "<"properties">" "<"property name="cql.version" value="3.0.0">"</"property> "<"/properties> "<"properties> "<"property name="ConsistencyLevel" value="QUORUM"> "</"properties> "</"connection> "</"dataStore> "</"datastores> "</"clientProperties>

Gargee avatar Jul 22 '13 20:07 Gargee

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

mevivs avatar Jul 22 '13 20:07 mevivs

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 ?

Gargee avatar Jul 22 '13 20:07 Gargee

propertyMap.put("consistency.level",ConsistencyLevel.QUORUM);

mevivs avatar Jul 22 '13 20:07 mevivs

The method put(String, String) in the type Map<String,String> is not applicable for the arguments (String, ConsistencyLevel) :(

Gargee avatar Jul 22 '13 20:07 Gargee

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

mevivs avatar Jul 22 '13 20:07 mevivs

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.

Gargee avatar Jul 22 '13 20:07 Gargee

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?

dtuzikov avatar Jul 23 '13 13:07 dtuzikov

:+1: for relaxing enum constraint. Will discuss alternate solutions and as well as @PersistenceProperty option.

-Vivek

mevivs avatar Jul 23 '13 16:07 mevivs

@dtuzikov
Out of context, 1 question. Using Kundera for?

-Vivek

mevivs avatar Jul 23 '13 16:07 mevivs

@dtuzikov Thanks a lot for the solution. @mevivs thanks for your support

Gargee avatar Jul 23 '13 17:07 Gargee

@mevivs I'm using Kundera for working with historical database on Cassandra 1.2. (Financial app)

dtuzikov avatar Jul 23 '13 20:07 dtuzikov

@dtuzikov Thanks. Could you please spare couple of minutes to provide your feedback? Here it is: http://www.surveymonkey.com/s/BMB9PWG

-Vivek

mevivs avatar Jul 24 '13 05:07 mevivs

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 ?

jfgosselin avatar Sep 18 '13 02:09 jfgosselin

Yes this is working for me.

Gargee avatar Sep 18 '13 14:09 Gargee