Hi Amila, >From what I understand, neither should you retry nor let the DB Util handle this. You should generally avoid running into this situation, because if something is deadlocked, ideally the DB Driver itself has already tried to restructure the calls but failed to do so in a timely manner.
To resolve this, you need to find the two operations that get in the way of each other. You already have one, which is the call to authorizeRole() in AppFactoryResourceManagementService class. But, what we need to find is the other one that actually succeeds. In the Registry Kernel, we have some debugging logic in place to identify such deadlock situations, but I'm not sure the same exists in UM Kernel. So, may be you can first try to isolate any other code that updates UM_ROLE_PERMISSION, and try to log them to the console. Then if you can reproduce the same issue once again, you can perhaps track down the most likely victim. I'm also guessing that your call to authorizeRole() in AppFactoryResourceManagementService, seems to be invoked whenever somebody requests for the registry. Now, that does not quite sound right. Ideally you'd authorize somebody before accessing the registry, but just once. Can you check whether that can be fixed as well? If this is the case, may be the fix is much more straightforward. Thanks, Senaka. On Mon, Nov 10, 2014 at 2:05 PM, Amila Maha Arachchi <[email protected]> wrote: > AFAIR, when this issue occurred, it was not under a load. This does not > occur on all execution. This is an intermittent issue. But I am thinking of > a way to code for failures and handle the situation. > > On Mon, Nov 10, 2014 at 5:03 PM, Sumedha Rubasinghe <[email protected]> > wrote: > >> How frequent is this? does this come with a load or even on single >> execution? >> SQL in concern here is following? >> >> DELETE FROM UM_ROLE_PERMISSION WHERE UM_ROLE_NAME=? AND UM_PERMISSION_ID >> = (SELECT UM_ID FROM UM_PERMISSION WHERE UM_RESOURCE_ID = ? AND UM_ACTION = >> ? AND UM_TENANT_ID=?) AND UM_TENANT_ID=? AND UM_DOMAIN_ID=(SELECT >> UM_DOMAIN_ID FROM UM_DOMAIN WHERE UM_TENANT_ID=? AND UM_DOMAIN_NAME=?) >> >> >> >> On Mon, Nov 10, 2014 at 2:55 PM, Amila Maha Arachchi <[email protected]> >> wrote: >> >>> Hi all, >>> >>> I have seen deadlock issues occurring during database transactions >>> within our code. [1] is such a situation. >>> >>> What is the best way to handle such cases? >>> >>> Should we retry from the code where we invoked the authorisation manager >>> in this case (i.e. AF code) or should the authorisation manager do the >>> retry or the DatabaseUtil class should handle this? >>> >>> [1] https://wso2.org/jira/browse/CLOUD-310 >>> >>> TID: [0] [SCC] [2014-10-27 06:56:21,093] ERROR >>> {org.wso2.carbon.user.core.util.DatabaseUtil} - Error! Deadlock found >>> when trying to get lock; try restarting transaction >>> {org.wso2.carbon.user.core.util.DatabaseUtil} >>> >>> com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: >>> Deadlock found when trying to get lock; try restarting transaction >>> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) >>> at >>> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) >>> at >>> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) >>> at java.lang.reflect.Constructor.newInstance(Constructor.java:526) >>> at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) >>> at com.mysql.jdbc.Util.getInstance(Util.java:386) >>> at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1066) >>> at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190) >>> at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122) >>> at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570) >>> at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731) >>> at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2818) >>> at >>> com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2157) >>> at >>> com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2460) >>> at >>> com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2377) >>> at >>> com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2361) >>> at >>> org.wso2.carbon.user.core.util.DatabaseUtil.updateDatabase(DatabaseUtil.java:542) >>> at >>> org.wso2.carbon.user.core.authorization.JDBCAuthorizationManager.addAuthorizationForRole(JDBCAuthorizationManager.java:718) >>> at >>> org.wso2.carbon.user.core.authorization.JDBCAuthorizationManager.authorizeRole(JDBCAuthorizationManager.java:358) >>> at >>> org.wso2.carbon.appfactory.stratos.services.AppFactoryResourceManagementService.authorizeAppIdRole(AppFactoryResourceManagementService.java:351) >>> at >>> org.wso2.carbon.appfactory.stratos.services.AppFactoryResourceManagementService.getRegistry(AppFactoryResourceManagementService.java:246) >>> at >>> org.wso2.carbon.appfactory.stratos.services.AppFactoryResourceManagementService.addOrUpdateResource(AppFactoryResourceManagementService.java:159) >>> at >>> org.wso2.carbon.appfactory.stratos.services.AppFactoryResourceManagementService.addOrUpdateResources(AppFactoryResourceManagementService.java:142) >>> >>> >>> >>> -- >>> *Amila Maharachchi* >>> Senior Technical Lead >>> WSO2, Inc.; http://wso2.com >>> >>> Blog: http://maharachchi.blogspot.com >>> Mobile: +94719371446 >>> >>> >> >> >> -- >> /sumedha >> m: +94 773017743 >> b : bit.ly/sumedha >> > > > > -- > *Amila Maharachchi* > Senior Technical Lead > WSO2, Inc.; http://wso2.com > > Blog: http://maharachchi.blogspot.com > Mobile: +94719371446 > > -- *[image: http://wso2.com] <http://wso2.com>Senaka Fernando* Solutions Architect; WSO2 Inc.; http://wso2.com *Member; Apache Software Foundation; http://apache.org <http://apache.org>E-mail: senaka AT wso2.com <http://wso2.com>**P: +1 408 754 7388; ext: 51736*; *M: +44 782 741 1966Linked-In: http://linkedin.com/in/senakafernando <http://linkedin.com/in/senakafernando>*Lean . Enterprise . Middleware
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
