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

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

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.

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'
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:

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:

 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:

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


The output will look like:

 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.


Last modified on Nov 1, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.