ChangeNotesParser: Skip parsing meta data of deleted patch sets

ChangeNotesParser parses the commits in a change meta ref starting from
the most recent commit. While doing so it keeps track of patch set
creations. If during the parsing we observe meta data for a patch set in
a meta commit that was created before the patch set got created we fail
with a ConfigInvalidException. This works well, unless a patch set got
deleted and then recreated. In this case both patch sets have the same
patch set ID and when we hit the meta data for the deleted patch set we
find that it was created before the patch got created the second time,
and hence the exception is thrown. This means we currently cannot load
any change for which a patch set got deleted and then recreated. This
can affect all kind of operations that need to load such a change. To
fix this we are now skipping the parsing of meta data for deleted patch
sets completely, since it's anyway of no relevance.

Patch set deletions are no longer possible via the REST API, but they
were possible when we supported draft patch sets. Hence this bug affects
mostly old changes. Still even nowadays it can happen that a patch set
is marked as deleted. This happens if the ConsistencyChecker is run to
fix change inconsistencies. If the ConsistencyChecker finds a patch set
for which the commit is not found, the patch set is marked as deleted.

At Google we observed more than 200 exceptions that are caused by this,
just in the last month.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I4cd9f9a1787f41469a6515890b1c919017b24e01
(cherry picked from commit 4b9f792153)
This commit is contained in:
Edwin Kempin
2019-10-29 16:49:10 +01:00
parent fb61c069bd
commit b803c4f16c
2 changed files with 41 additions and 8 deletions

View File

@@ -363,6 +363,15 @@ class ChangeNotesParser {
submissionId = parseSubmissionId(commit);
}
if (lastUpdatedOn == null || ts.after(lastUpdatedOn)) {
lastUpdatedOn = ts;
}
if (deletedPatchSets.contains(psId)) {
// Do not update PS details as PS was deleted and this meta data is of no relevance.
return;
}
// Parse mutable patch set fields first so they can be recorded in the PendingPatchSetFields.
parseDescription(psId, commit);
parseGroups(psId, commit);
@@ -410,10 +419,6 @@ class ChangeNotesParser {
previousWorkInProgressFooter = null;
parseWorkInProgress(commit);
if (lastUpdatedOn == null || ts.after(lastUpdatedOn)) {
lastUpdatedOn = ts;
}
}
private String parseSubmissionId(ChangeNotesCommit commit) throws ConfigInvalidException {
@@ -487,10 +492,6 @@ class ChangeNotesParser {
throw parseException("patch set %s requires an identified user as uploader", psId.get());
}
if (patchSetCommitParsed(psId)) {
if (deletedPatchSets.contains(psId)) {
// Do not update PS details as PS was deleted and this meta data is of no relevance.
return;
}
ObjectId commitId = patchSets.get(psId).commitId().orElseThrow(IllegalStateException::new);
throw new ConfigInvalidException(
String.format(

View File

@@ -3062,6 +3062,38 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
assertThat(newNotes(c).getUpdateCount()).isEqualTo(3);
}
@Test
public void createPatchSetAfterPatchSetDeletion() throws Exception {
Change c = newChange();
assertThat(newNotes(c).getChange().currentPatchSetId().get()).isEqualTo(1);
// Create PS2.
incrementCurrentPatchSetFieldOnly(c);
RevCommit commit = tr.commit().message("PS" + c.currentPatchSetId().get()).create();
ChangeUpdate update = newUpdate(c, changeOwner);
update.setCommit(rw, commit);
update.setGroups(ImmutableList.of(commit.name()));
update.commit();
assertThat(newNotes(c).getChange().currentPatchSetId().get()).isEqualTo(2);
// Delete PS2.
update = newUpdate(c, changeOwner);
update.setPatchSetState(PatchSetState.DELETED);
update.commit();
c = newNotes(c).getChange();
assertThat(c.currentPatchSetId().get()).isEqualTo(1);
// Create another PS2
incrementCurrentPatchSetFieldOnly(c);
commit = tr.commit().message("PS" + c.currentPatchSetId().get()).create();
update = newUpdate(c, changeOwner);
update.setPatchSetState(PatchSetState.PUBLISHED);
update.setCommit(rw, commit);
update.setGroups(ImmutableList.of(commit.name()));
update.commit();
assertThat(newNotes(c).getChange().currentPatchSetId().get()).isEqualTo(2);
}
private String readNote(ChangeNotes notes, ObjectId noteId) throws Exception {
ObjectId dataId = notes.revisionNoteMap.noteMap.getNote(noteId).getData();
return new String(rw.getObjectReader().open(dataId, OBJ_BLOB).getCachedBytes(), UTF_8);