Issue
- A
CannotAcquireLockExceptionis shown several times in the server log:
ERROR [http--10.1.1.133-8080-281][JSONWebServiceServiceAction:97]
org.springframework.dao.CannotAcquireLockException: PreparedStatementCallback;
SQL [INSERT INTO Users_UserGroups (userGroupId, userId) VALUES (?, ?)];
Unknown error 1205; nested exception is java.sql.SQLException: Unknown error 1205
Environment
- Portal 6.2
Resolution
-
If this error appears in the log, it indicates that the database cannot get a lock for
Users_UserGroupstable to execute theINSERTquery.
If MySQL is used as database and manySELECTqueries are being executed on the Users_UserGroups table, the database may prioritize theSELECTqueries and wait for them to be executed before execute theINSERTquery.
If this timeout exceeds the time specified in the MySQL'sinnodb_lock_wait_timeoutproperty, the CannotAcquireLockException error occurs. - It is possible to reduce the number of
SELECTqueries executed on the database by adding the affected table to thetable.mapper.cache.mapping.table.namesproperty in theportal-ext.properties, in which case the queries to this table will be cached by the portal:table.mapper.cache.mapping.table.names=Users_UserGroups
It will be necessary to restart the portal for the new value to be applied.
Additional Information
- As of 6.2 Fix pack Portal 108, this property was changed to
table.mapper.cacheless.mapping.table.names, being by default the opposite behavior, i.e., all tables are cached and only the tables specified in this property will be executed against the database.