Improve locking DB operations

تم تعديل Jan Tošovský منذ 1 سنة من الدقائق. Liferay Master المشاركات: 576 تاريخ الإنضمام: 22‏/7‏/10 المشاركات الحديثة

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 منذ 1 سنة من الدقائق. Expert المشاركات: 367 تاريخ الإنضمام: 5‏/9‏/14 المشاركات الحديثة

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