Redis transaction Problem with AOP

109 views
Skip to first unread message

Hank Zhu

unread,
Feb 27, 2014, 3:02:41 PM2/27/14
to kundera...@googlegroups.com
Hi,

We are migrating JPA provider from Hibernate to Kundera-redis and get problem with AOP, for instance, Guice-JPA.

Here is how we use it:
--------
    @Transactional
    public void initDatabase() {
        em.createQuery("DELETE FROM Employee").executeUpdate();   // 1
        em.createQuery("DELETE FROM Company").executeUpdate();    // 2
        // insert new data
    }
--------

Line 1 execute successfully but line 2 failed with following exception:
--------
redis.clients.jedis.exceptions.JedisDataException: ERR DISCARD without MULTI
at redis.clients.jedis.Protocol.processError(Protocol.java:54)
at redis.clients.jedis.Protocol.process(Protocol.java:61)
at redis.clients.jedis.Protocol.read(Protocol.java:122)
at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:152)
at redis.clients.jedis.BinaryTransaction.discard(BinaryTransaction.java:41)
at com.impetus.client.redis.RedisTransaction.onRollback(RedisTransaction.java:87)
at com.impetus.kundera.persistence.Coordinator.coordinate(Coordinator.java:86)
at com.impetus.kundera.persistence.KunderaEntityTransaction.onTransaction(KunderaEntityTransaction.java:128)
at com.impetus.kundera.persistence.KunderaEntityTransaction.rollback(KunderaEntityTransaction.java:120)
at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.rollbackIfNecessary(JpaLocalTxnInterceptor.java:152)
at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
--------

I traced into Kundera source code and found this:
1. At "RedisTransaction.bindResource(Jedis)", line 134, the first execute fire "tx = resource.multi();"
2. At "RedisClient.onExecuteQuery(RedisQueryInterpreter, Class)", line 1543, RedisTransaction is committed by "((Transaction) connection).exec();"
3. Section execute, at "RedisTransaction.bindResource(Jedis)", line 139, tx is reused without calling multi(). I guess this is where the problem happens.

Is it a bug or do I miss something here?

BTW, I am using Kundera 2.10. I clone the code from Github but failed to run the testcase on my local Machine. 
--------
[WARNING] The POM for com.impetus.kundera.core:kundera-core:jar:2.11-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for com.impetus.kundera.core:kundera-core:jar:tests:2.11-SNAPSHOT is missing, no dependency information available
--------
And I couldn't found a way to switch the branch to 2.10.

Please help. Thanks in advance.

Regards
Hank

Hank Zhu

unread,
Feb 28, 2014, 6:14:30 AM2/28/14
to kundera...@googlegroups.com
I think I know the reason. Is it because Kundera-redis transaction only supports em.persist() at the moment?

Hank

Vivek Mishra

unread,
Feb 28, 2014, 6:22:17 AM2/28/14
to kundera...@googlegroups.com
I have not yet looked into this issue. But did not get your point regarding em.persist(). It does support transaction over all em operations.
You may want to refer https://github.com/impetus-opensource/Kundera/blob/trunk/src/kundera-redis/src/test/java/com/impetus/client/RedisTransactionTest.java
for more.

Still i need to dig in to this issue.Just to share with you queries such as :

em.createQuery("DELETE FROM Employee").executeUpdate(); // 1

would read data from database and then issue a delete for the same.


-Vivek

________________________________________
From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Hank Zhu [tru...@gmail.com]
Sent: 28 February 2014 16:44
To: kundera...@googlegroups.com
Subject: {kundera-discuss} Re: Redis transaction Problem with AOP

I think I know the reason. Is it because Kundera-redis transaction only supports em.persist() at the moment?

Hank

On Friday, February 28, 2014 4:02:41 AM UTC+8, Hank Zhu wrote:
Hi,

We are migrating JPA provider from Hibernate to Kundera-redis and get problem with AOP, for instance, Guice-JPA<https://code.google.com/p/google-guice/wiki/GuicePersistMultiModules>.
--
You received this message because you are subscribed to the Google Groups "kundera-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kundera-discu...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

________________________________






NOTE: This message may contain information that is confidential, proprietary, privileged or otherwise protected by law. The message is intended solely for the named addressee. If received in error, please destroy and notify the sender. Any use of this email is prohibited when received in error. Impetus does not represent, warrant and/or guarantee, that the integrity of this communication has been maintained nor that the communication is free of errors, virus, interception or interference.

Vivek Mishra

unread,
Feb 28, 2014, 6:40:00 AM2/28/14
to kundera...@googlegroups.com
1. At "RedisTransaction.bindResource(Jedis)", line 134, the first execute fire "tx = resource.multi();"
2. At "RedisClient.onExecuteQuery(RedisQueryInterpreter, Class)", line 1543, RedisTransaction is committed by "((Transaction) connection).exec();"
3. Section execute, at "RedisTransaction.bindResource(Jedis)", line 139, tx is reused without calling multi(). I guess this is where the problem happens.

This looks to me something random happened with dynamic rollback. There might be some issue.

Could you please share code snippet to reproduce it at my end?

-Vivek

redis.clients.jedis.exceptions.JedisDataException: ERR DISCARD without MULTI
at redis.clients.jedis.Protocol.processError(Protocol.java:54)
at redis.clients.jedis.Protocol.process(Protocol.java:61)
at redis.clients.jedis.Protocol.read(Protocol.java:122)
at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:152)
at redis.clients.jedis.BinaryTransaction.discard(BinaryTransaction.java:41)
at com.impetus.client.redis.RedisTransaction.onRollback(RedisTransaction.java:87)
at com.impetus.kundera.persistence.Coordinator.coordinate(Coordinator.java:86)
at com.impetus.kundera.persistence.KunderaEntityTransaction.onTransaction(KunderaEntityTransaction.java:128)
at com.impetus.kundera.persistence.KunderaEntityTransaction.rollback(KunderaEntityTransaction.java:120)
at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.rollbackIfNecessary(JpaLocalTxnInterceptor.java:152)
at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

________________________________________
From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Vivek Mishra
Sent: 28 February 2014 16:52
To: kundera...@googlegroups.com
Subject: RE: {kundera-discuss} Re: Redis transaction Problem with AOP

Hank Zhu

unread,
Feb 28, 2014, 8:06:59 AM2/28/14
to kundera...@googlegroups.com
Hi Vivek, 

Code is attached. This code works well with HibernateJPA, or simply remove the @Transactional annotation.

Hank

On Friday, February 28, 2014 4:02:41 AM UTC+8, Hank Zhu wrote:
redis-jpa.zip

Vivek Mishra

unread,
Mar 2, 2014, 5:21:10 AM3/2/14
to kundera...@googlegroups.com
Issue raised over github {https://github.com/impetus-opensource/Kundera/issues/540}. Also, fix has been checked-in for the same on latest trunk.
To verify this issue, you need to manually checkout build 2.11-SNAPSHOT.


Thanks,
-Vivek



________________________________________
From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Hank Zhu [tru...@gmail.com]
Sent: 28 February 2014 01:32
To: kundera...@googlegroups.com
Subject: {kundera-discuss} Redis transaction Problem with AOP

Hi,

We are migrating JPA provider from Hibernate to Kundera-redis and get problem with AOP, for instance, Guice-JPA<https://code.google.com/p/google-guice/wiki/GuicePersistMultiModules>.

Hank Zhu

unread,
Mar 5, 2014, 1:19:37 PM3/5/14
to kundera...@googlegroups.com
HI Vivek,

Seems this issue hasn't been fixed thoroughly. If you run executeUpdate() and em.persist() in a single transaction, an exception will be thrown. And the follow transaction wouldn't be created successfully. See my updated test case. 

Hank
redis-jpa.zip

Vivek Mishra

unread,
Mar 6, 2014, 7:45:53 AM3/6/14
to kundera...@googlegroups.com
This seems to be an issue with underlying JedisPool API. If you comment out
<property name="kundera.pool.size.max.active" value="10" />

it should work for you.

Looking into this

-Vivek
________________________________________
From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Hank Zhu [tru...@gmail.com]
Sent: 05 March 2014 23:49
To: kundera...@googlegroups.com
Subject: Re: {kundera-discuss} Redis transaction Problem with AOP
To unsubscribe from this group and stop receiving emails from it, send an email to kundera-discu...@googlegroups.com<mailto:kundera-discu...@googlegroups.com>.

Vivek Mishra

unread,
Apr 4, 2014, 6:46:40 AM4/4/14
to kundera...@googlegroups.com
Fixed on current trunk branch.
https://github.com/impetus-opensource/Kundera/issues/540

-Vivek
________________________________________
From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Vivek Mishra
Sent: 06 March 2014 18:15
To: kundera...@googlegroups.com
Subject: RE: {kundera-discuss} Redis transaction Problem with AOP
Reply all
Reply to author
Forward
0 new messages