Hi all,

The following error was reported when trying to delete a role while running
the MB server (The complete issue can be found at [1])

TID: [-1234] [] [2015-06-29 14:46:08,002] 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:525)
    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:529)
    at
org.wso2.carbon.user.core.hybrid.HybridRoleManager.deleteHybridRole(HybridRoleManager.java:479)
    at
org.wso2.carbon.user.core.common.AbstractUserStoreManager.deleteRole(AbstractUserStoreManager.java:2294)

........

When the stack trace was analized, it was observed that the error was cased
by the following method.

public void deleteHybridRole(String roleName) throws UserStoreException {
    if(UserCoreUtil.isEveryoneRole(roleName, this.realmConfig)) {
        throw new UserStoreException("Invalid operation");
    } else {
        Connection dbConnection = null;

        try {
            dbConnection = this.getDBConnection();
            DatabaseUtil.updateDatabase(dbConnection, "DELETE FROM
UM_HYBRID_USER_ROLE WHERE UM_ROLE_ID=(SELECT UM_ID FROM UM_HYBRID_ROLE
WHERE UM_ROLE_NAME = ? AND UM_TENANT_ID=?) AND UM_TENANT_ID=?", new
Object[]{roleName, Integer.valueOf(this.tenantId),
Integer.valueOf(this.tenantId)});
            DatabaseUtil.updateDatabase(dbConnection, "DELETE FROM
UM_HYBRID_ROLE WHERE UM_ROLE_NAME = ? AND UM_TENANT_ID=?", new
Object[]{roleName, Integer.valueOf(this.tenantId)});
            dbConnection.commit();
        } catch (SQLException var7) {
            log.error(var7.getMessage(), var7);
            throw new UserStoreException(var7.getMessage(), var7);
        } finally {
            DatabaseUtil.closeAllConnections(dbConnection, new
PreparedStatement[0]);
        }

        
this.userRealm.getAuthorizationManager().clearRoleAuthorization(roleName);
    }
}

Could the problem be the fact that the first statement is locking
UM_HYBRID_ROLE which is written to, in the second statement? Any comment
would be highly appreciated.

[1] https://wso2.org/jira/browse/MB-1128

Thank you
-- 
Sasikala Kottegoda
*Software Engineer*
WSO2 Inc., http://wso2.com/
lean. enterprise. middleware
Mobile: +94 774835928/712792401
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to