RE: Improve locking DB operations

Jan Tošovský, modified 1 Year ago. Liferay Master Posts: 576 Join Date: 7/22/10 Recent Posts

From time to time I can see this issue in the server log:
 

2024-06-07 01:24:14.994 ERROR [liferay/async_service-1491][BatchingBatch:134] HHH000315: Exception executing batch [java.sql.BatchUpdateException: Batch entry 0 insert into Lock_ (mvccVersion, uuid_, companyId, userId, userName, createDate, className, key_, owner, inheritable, expirationDate, lockId) values (0, 'df69853e-e63a-cf96-f7cc-0c3c5a8ad12c', 10131, 0, NULL, '2024-06-07 01:24:14.978+00', 'com.liferay.social.kernel.model.SocialActivityCounter', '10719#10046#12904074#user.activities#1', '10719#10046#12904074#user.activities#1', 'FALSE', NULL, 103982867) was aborted: ERROR: duplicate key value violates unique constraint "ix_228562ad"
  Detail: Key (classname, key_)=(com.liferay.social.kernel.model.SocialActivityCounter, 10719#10046#12904074#user.activities#1) already exists.

We have enabled measuring social activities. Social Activity counters in LR are created asynchronously by multiple threads so the core method uses the lock service to guard against multiple threads trying to insert the same counter (a quote from SocialActivityCounterLocalServiceImpl.java).

However, the current implementation seems to be suboptimal:
 

SocialActivityCounter activityCounter = this.fetchLatestActivityCounter(...);
if (activityCounter == null) {
   activityCounter = this.lockProtectedAddActivityCounter(...);
}

It prevents creating duplicate counters, but it doesn't prevent creating duplicate locks. The related stack traces are quite huge and I'd like to eliminate it.

thumbnail
Jamie Sammons, modified 1 Year ago. Expert Posts: 367 Join Date: 9/5/14 Recent Posts

Feature Request Created: https://liferay.atlassian.net/browse/LPD-28272