cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: MySQL deadlock exceptions
Date Tue, 05 Aug 2014 14:42:58 GMT
Nice. That’s a good way to handle it outside the framework. Thanks for confirming. 

Andrus

On Aug 5, 2014, at 5:05 PM, Ramiro Aparicio <ramiro.aparicio@prot-on.com> wrote:

> El 05/08/2014 15:54, Andrus Adamchik escribió:
>> After years working with MySQL I stumbled on a problem for the first time that seems
rather old and common. MySQL would throw when 2 InnoDB transactions are trying to update the
same row:
>> 
>> com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found
when trying to get lock; try restarting transaction
>> 
>> I am wondering whether we should add a “catch/restart tx” to Cayenne to handle
that. The purpose of this message is to ask how often if ever folks in the community have
to deal with this exception?
>> 
>> Thanks,
>> Andrus
>> 
>> 
>> 
> I have been seen that error for a while, we use an abstract Dao inherited by all daos
so all commits use this funcion:
> 
>        public void commitChanges() {
>            this.commitChanges(0);
>        }
> 
>        public void commitChanges(int level) {
>            try {
>                getThreadDataContext().commitChanges();
>            } catch (RuntimeException cre) {
>                if (level < 3 &&
>                        (cre.getCause() instanceof
>   MySQLTransactionRollbackException
>                        || cre.getCause() instanceof
>   com.mysql.jdbc.exceptions.MySQLTransactionRollbackException)) {
>                    commitChanges(level+1);
>                } else {
>                    CayenneCommitException cce = new
>   CayenneCommitException(cre, getThreadDataContext());
>                    rollbackChanges();
>                    throw cce;
>                }
>            }
>        }
> 
> 
> Not sure if this helps or not but currently we only see like 1 of those errors per month
and I think that previously it was more frequent.


Mime
View raw message