Complete comment identity with the associated serverId in comments Change note-db /meta ref contains the list of change notes associated, including all the comments were added to files and commit messages. The remapping of account-ids performed with I4b0fe6689 has correctly adapted the comment's author account-ids to the local associated accounts, however, it failed to update the comment serverId, leaving the rest of Gerrit with an inconsistent identity. Even though the identity was not causing apparent damage, mostly because the serverId was ignored mainly by Gerrit; it left the cached entities with the incorrect data and, in some cases, persisted back to NoteDb (see Issue 318745940). Rectify the situation by updating the serverId when accounts are remapped. Release-Notes: Fix serverId in identity parsing for imported human comments Forward-Compatible: checked Bug: Issue 318745940 Change-Id: I5904dc46120858beb54e20ac339f10a02d785d3a
diff --git a/java/com/google/gerrit/server/notedb/ChangeNotesParser.java b/java/com/google/gerrit/server/notedb/ChangeNotesParser.java index f964d4e..e8b75b1 100644 --- a/java/com/google/gerrit/server/notedb/ChangeNotesParser.java +++ b/java/com/google/gerrit/server/notedb/ChangeNotesParser.java
@@ -893,7 +893,11 @@ noteDbUtil .parseIdent(String.format("%s@%s", c.author.getId(), c.serverId)) - .ifPresent(id -> c.author = new Comment.Identity(id)); + .ifPresent( + id -> { + c.author = new Comment.Identity(id); + c.serverId = noteDbUtil.serverId; + }); humanComments.put(e.getKey(), c); }
diff --git a/java/com/google/gerrit/server/notedb/NoteDbUtil.java b/java/com/google/gerrit/server/notedb/NoteDbUtil.java index 0c0238d..3b467c4 100644 --- a/java/com/google/gerrit/server/notedb/NoteDbUtil.java +++ b/java/com/google/gerrit/server/notedb/NoteDbUtil.java
@@ -35,7 +35,7 @@ @Singleton public class NoteDbUtil { - private final String serverId; + final String serverId; private final ExternalIdCache externalIdCache; @Inject
diff --git a/javatests/com/google/gerrit/server/notedb/ImportedChangeNotesTest.java b/javatests/com/google/gerrit/server/notedb/ImportedChangeNotesTest.java index 57be12c..366cbf7 100644 --- a/javatests/com/google/gerrit/server/notedb/ImportedChangeNotesTest.java +++ b/javatests/com/google/gerrit/server/notedb/ImportedChangeNotesTest.java
@@ -133,6 +133,7 @@ assertThat(comments).hasSize(1); HumanComment gotComment = comments.entries().asList().get(0).getValue(); assertThat(gotComment.author.getId()).isEqualTo(otherUser.getAccountId()); + assertThat(gotComment.serverId).isEqualTo(LOCAL_SERVER_ID); } @Test