kundera icon indicating copy to clipboard operation
kundera copied to clipboard

Please add the ability to configure the Cassandra consitency level

Open dansomething opened this issue 14 years ago • 18 comments

We'd like to have the ability to configure the Cassandra consistency level. Ideally we'd be able to do this per query or at the very least be able to configure it at the entity level.

Thanks,

Dan

dansomething avatar Apr 10 '12 14:04 dansomething

target for 2.0.7

mevivs avatar Apr 18 '12 09:04 mevivs

Guys, in this matter, what is the current default custom level used by Kundera in reads and in persists? I could not find this information in the documentation. Regards.

cballock avatar Jun 01 '12 03:06 cballock

Current it is defaulted to ConsistenceLevel.ONE.

-Vivek

mevivs avatar Jun 01 '12 05:06 mevivs

Right, Cassanrda leaves the default value up to the client and that is typically ONE.

dansomething avatar Jun 01 '12 19:06 dansomething

Fixed and releasing in 2.0.7.

-Vivek

mevivs avatar Jul 24 '12 07:07 mevivs

I can't seem to find any documentation on how to specify the consistency level per query. Nor can I find a clear example in any of the unit tests. Is there an example that explains how to do it somewhere?

masha256 avatar Nov 15 '12 22:11 masha256

Give below code snippet should help you out: (For example)

 Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();
        PelopsClient pc = (PelopsClient)clientMap.get("cassandra");
        pc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);
        pc.setConsistencyLevel(ConsistencyLevel.ALL);

Not sure, there was a test case earlier. I will have a look on it.

-Vivek

mevivs avatar Nov 16 '12 12:11 mevivs

Hi, Is there any way to change CQL version using Spring?

Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();

map always empty for me.

eld0 avatar Mar 25 '13 16:03 eld0

Yes. You can change CQL version as:

    Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();
    ThriftClient tc = (ThriftClient) clientMap.get("cassandra");
    tc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);

-Vivek

mevivs avatar Mar 25 '13 16:03 mevivs

But clientMap is always empty for me and

clientMap.get("cassandra")

returns null

eld0 avatar Mar 25 '13 16:03 eld0

clientMap.get("cassandra") => replace "cassandra" with configured persistence unit.

-Vivek

mevivs avatar Mar 25 '13 16:03 mevivs

Unfortunately, but not working for me. I've sent you a project with a test.

eld0 avatar Mar 25 '13 16:03 eld0

On which id?

Not sure why is it not working for you. You can refer: https://github.com/impetus-opensource/Kundera/blob/trunk/kundera-cassandra/src/test/java/com/impetus/client/crud/compositeType/CompositeDataTypeTest.java

for sample test case as well.

-Vivek

mevivs avatar Mar 25 '13 17:03 mevivs

So as per your project:

I guess,

  Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();
    ThriftClient tc = (ThriftClient) clientMap.get("mto_pu");
    tc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);

should work for you. Also you have annotated your EntityManager with @PersistenceContext but no unit name specified.

-Vivek

mevivs avatar Mar 25 '13 17:03 mevivs

Thanks for you advices, but it doesn't work for me. Did you tried to run TestCQLVersion from the my test project?

@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ContextConfiguration(locations = {"classpath:application-context.xml"})
public class TestCQLVersion {

    @PersistenceContext(unitName="mto_pu")
    private EntityManager entityManager;

    @Test
    public void testCqlVersionSet(){
        Map<String, Client> clientMap = (Map<String, Client>) entityManager.getDelegate();
        ThriftClient tc = (ThriftClient) clientMap.get("mto_pu");
        assertNotNull(tc);
        assertTrue("Map is empty",0 < clientMap.size());
        assertNotNull("Cassandra client is null",clientMap.get("cassandra"));
        assertNotNull("Cassandra client by persistence unit name is null",clientMap.get("mto_pu"));

    }

}

This test will be failed, because tc is null

eld0 avatar Mar 26 '13 08:03 eld0

I have not tried it yet. In your persistence.xml replace:

<persistence-unit name="mto_pu">

with

<persistence-unit name="mto_pu" transaction-type="JTA">

As you are initializing entity manager with @PersistenceContext, means container managed .

-Vivek

Thanks for your help, but test still fail, because clientMap is empty and tc is null. :(

eld0 avatar Mar 26 '13 09:03 eld0

Assigning to Amresh. He will be looking into this.

-Vivek

mevivs avatar Mar 26 '13 09:03 mevivs