<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Improve locking DB operations</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=122706934" />
  <subtitle>Improve locking DB operations</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=122706934</id>
  <updated>2026-04-27T12:37:11Z</updated>
  <dc:date>2026-04-27T12:37:11Z</dc:date>
  <entry>
    <title>RE: Improve locking DB operations</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122713801" />
    <author>
      <name>Jamie Sammons</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122713801</id>
    <updated>2024-06-11T17:19:12Z</updated>
    <published>2024-06-11T17:19:12Z</published>
    <summary type="html">&lt;p&gt;Feature Request Created: https://liferay.atlassian.net/browse/LPD-28272&lt;/p&gt;</summary>
    <dc:creator>Jamie Sammons</dc:creator>
    <dc:date>2024-06-11T17:19:12Z</dc:date>
  </entry>
  <entry>
    <title>Improve locking DB operations</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122706933" />
    <author>
      <name>Jan Tošovský</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=122706933</id>
    <updated>2024-06-07T10:44:38Z</updated>
    <published>2024-06-07T10:44:38Z</published>
    <summary type="html">&lt;p&gt;From time to time I can see this issue in the server log:&lt;br&gt; &amp;nbsp;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;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"
&amp;nbsp; Detail: Key (classname, key_)=(com.liferay.social.kernel.model.SocialActivityCounter, 10719#10046#12904074#user.activities#1) already exists.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;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).&lt;/p&gt;
&lt;p&gt;However, the current implementation seems to be suboptimal:&lt;br&gt; &amp;nbsp;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-java"&gt;SocialActivityCounter activityCounter = this.fetchLatestActivityCounter(...);
if (activityCounter == null) {
   activityCounter = this.lockProtectedAddActivityCounter(...);
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;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.&lt;/p&gt;</summary>
    <dc:creator>Jan Tošovský</dc:creator>
    <dc:date>2024-06-07T10:44:38Z</dc:date>
  </entry>
</feed>
