Indexing failed for Entity - Caused by: java.lang.IllegalStateException: Duplicate key 3

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

The reindex fails due to the following exception: java.lang.IllegalStateException: Duplicate key 3

Environment

8.20.8

.

Diagnosis

The following WARN messages have been observed in the logs. The first one says that the Indexing task failed for an entity. The second shows an IllegalStateException error.

1 2022-05-21 08:06:36,628-0500 JiraTaskExecutionThread-696 WARN none-crowd2 485x6563925x1 8k213q XXX.XXX.XXX.XXX,XXX.X.X.X /secure/admin/IndexReIndex!reindex.jspa [c.a.jira.index.AccumulatingResultBuilder] Indexing failed for Entity - '647038'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 2022-05-21 08:06:36,628-0500 JiraTaskExecutionThread-696 WARN none-crowd2 485x6563925x1 8k213q XXX.XXX.XXX.XXX,XXX.X.X.X /secure/admin/IndexReIndex!reindex.jspa [c.a.jira.index.AccumulatingResultBuilder] java.lang.IllegalStateException: Duplicate key 3 java.lang.RuntimeException: java.lang.IllegalStateException: Duplicate key 3 at com.atlassian.jira.index.DefaultIndex$Failure.<init>(DefaultIndex.java:100) at com.atlassian.jira.issue.index.DefaultIssueIndexer$EntityOperation.perform(DefaultIssueIndexer.java:838) at com.atlassian.jira.issue.index.DefaultIssueIndexer.lambda$null$4(DefaultIssueIndexer.java:513) at com.atlassian.jira.index.SimpleIndexingStrategy.apply(SimpleIndexingStrategy.java:7) at com.atlassian.jira.index.SimpleIndexingStrategy.apply(SimpleIndexingStrategy.java:5) at com.atlassian.jira.index.MultiThreadedIndexingStrategy$1.call(MultiThreadedIndexingStrategy.java:47) at com.atlassian.jira.index.MultiThreadedIndexingStrategy$1.call(MultiThreadedIndexingStrategy.java:43) at com.atlassian.jira.util.concurrent.BoundedExecutor$2.call(BoundedExecutor.java:68) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalStateException: Duplicate key 3 at java.util.stream.Collectors.lambda$throwingMerger$0(Collectors.java:133) at java.util.HashMap.merge(HashMap.java:1254) at java.util.stream.Collectors.lambda$toMap$58(Collectors.java:1320) at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) at com.atlassian.jira.versioning.EntityVersioningManagerImpl.lambda$getRelatedCommentVersions$6(EntityVersioningManagerImpl.java:139) at com.atlassian.jira.transaction.TransactionSupport.execute(TransactionSupport.java:28) at com.atlassian.jira.versioning.TransactionSupportHelper.executeWithRequired(TransactionSupportHelper.java:46) at com.atlassian.jira.versioning.TransactionSupportHelper.execute(TransactionSupportHelper.java:39) at com.atlassian.jira.versioning.EntityVersioningManagerImpl.getRelatedCommentVersions(EntityVersioningManagerImpl.java:137) at com.atlassian.jira.versioning.EntityVersioningManagerWithStats.getRelatedCommentVersions(EntityVersioningManagerWithStats.java:231) at com.atlassian.jira.issue.index.DefaultCommentRetriever.retrieve(DefaultCommentRetriever.java:47) at com.atlassian.jira.issue.index.DefaultIssueIndexer$DefaultDocumentCreationStrategy.lambda$getDocumentBuilder$0(DefaultIssueIndexer.java:1309) at com.atlassian.jira.issue.index.DefaultIssueIndexer$DefaultDocumentCreationStrategy.get(DefaultIssueIndexer.java:1301) at com.atlassian.jira.issue.index.DefaultIssueIndexer$IssuesOperation.createDocument(DefaultIssueIndexer.java:977) at com.atlassian.jira.issue.index.DefaultIssueIndexer$EntityOperation.perform(DefaultIssueIndexer.java:825) ... 10 more

After reviewing the exception, we noticed that the getRelatedCommentVersions() method has been called. This method returns the comment versions for all comments associated with the specified parentIssueId. The comment versions are stored in the comment_version database table.

To check duplicate records in the *comment_version* table, go to the database query tool, and run the following SQL statement:

1 2 3 select cv.comment_id, cv.parent_issue_id, count(*)  from comment_version cv group by cv.comment_id, cv.parent_issue_id having count(*) > 1;

This query should return all comment IDs and their associated parent issue IDs as below:

1 2 3 4 5  comment_id | parent_issue_id | count ------------+-----------------+-------      958769 |          647038 |     2      958785 |          647038 |     2 (2 rows)

Notice that the query output show duplicates, and the parent_issue_id matches the entity ID from the WARN message.

To see the duplicates, query the database by the comment_id:

1 select * from comment_version where comment_id in (958769,958785);

The output will look like:

1 2 3 4 5 6  comment_id | parent_issue_id |         update_time          | index_version | deleted ------------+-----------------+------------------------------+---------------+---------      958769 |          647038 | 2022-04-15 07:56:21.56929-05 |             5 | N      958769 |          647038 | 2022-04-15 07:56:21.56929-05 |             5 | N      958785 |          647038 | 2022-04-15 07:56:21.56929-05 |             3 | N      958785 |          647038 | 2022-04-15 07:56:21.56929-05 |             3 | N

Solution

  1. Stop Jira.

  2. Delete the duplicate records.

  3. Start Jira.

  4. Re-index the instance.

Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.