Do not take draft comments into account for change index up-to-date The change index does not include draft comments. Also, draft comments are not stored with the change notes and are user-specific, therefore do not make sense in the overall computation of the change latest update timestamp. Previously, the status of the change latest ts was calculated with the assumption that adding a draft comment would result in the change status to be modified and therefore needed to be reindexed up to the latest timestamp. In multi-site the draft comments are not even replicated because of the lack of support for draft comments stream events, added only from Gerrit v3.9. The consequence was the creation and indefinite retry of the indexing events, which would have eventally clogged the logs and the executors. TODO: This check needs to be reintroduced after the merging to stable-3.9, with the additional check of the draft comment stream events being enabled or not. Bug: Issue 40014838 Change-Id: I2f7e63bd3a97c4463fb4f5417770cbb429026c2b
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ChangeCheckerImpl.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ChangeCheckerImpl.java index 4ef5b7f..6e8fa15 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ChangeCheckerImpl.java +++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/index/ChangeCheckerImpl.java
@@ -14,10 +14,7 @@ package com.googlesource.gerrit.plugins.multisite.index; -import com.google.gerrit.entities.Change; -import com.google.gerrit.entities.HumanComment; import com.google.gerrit.exceptions.StorageException; -import com.google.gerrit.server.CommentsUtil; import com.google.gerrit.server.change.ChangeFinder; import com.google.gerrit.server.config.GerritInstanceId; import com.google.gerrit.server.git.GitRepositoryManager; @@ -28,7 +25,6 @@ import com.google.inject.assistedinject.Assisted; import com.googlesource.gerrit.plugins.multisite.forwarder.events.ChangeIndexEvent; import java.io.IOException; -import java.sql.Timestamp; import java.util.Objects; import java.util.Optional; import org.eclipse.jgit.errors.MissingObjectException; @@ -42,7 +38,6 @@ public class ChangeCheckerImpl implements ChangeChecker { private static final Logger log = LoggerFactory.getLogger(ChangeCheckerImpl.class); private final GitRepositoryManager gitRepoMgr; - private final CommentsUtil commentsUtil; private final OneOffRequestContext oneOffReqCtx; private final String changeId; private final ChangeFinder changeFinder; @@ -57,14 +52,12 @@ @Inject public ChangeCheckerImpl( GitRepositoryManager gitRepoMgr, - CommentsUtil commentsUtil, ChangeFinder changeFinder, OneOffRequestContext oneOffReqCtx, @GerritInstanceId String instanceId, @Assisted String changeId) { this.changeFinder = changeFinder; this.gitRepoMgr = gitRepoMgr; - this.commentsUtil = commentsUtil; this.oneOffReqCtx = oneOffReqCtx; this.changeId = changeId; this.instanceId = instanceId; @@ -177,20 +170,6 @@ } private Optional<Long> computeLastChangeTs() { - return getChangeNotes().map(notes -> getTsFromChangeAndDraftComments(notes)); - } - - private long getTsFromChangeAndDraftComments(ChangeNotes notes) { - Change change = notes.getChange(); - Timestamp changeTs = change.getLastUpdatedOn(); - try { - for (HumanComment comment : commentsUtil.draftByChange(changeNotes.get())) { - Timestamp commentTs = comment.writtenOn; - changeTs = commentTs.after(changeTs) ? commentTs : changeTs; - } - } catch (StorageException e) { - log.warn("Unable to access draft comments for change {}", change, e); - } - return changeTs.getTime() / 1000; + return getChangeNotes().map(notes -> notes.getChange().getLastUpdatedOn().getTime() / 1000); } }