Do not notify failures on collisions

Currently, when a replication task is rescheduled due to a collision, it
is not marked as a retry.

However, the failure notification logic only suppresses notifications
for tasks explicitly flagged as retries.

This change adds an additional check to prevent failure notifications
for tasks that are rescheduled because of collisions.

The same logic was applied to the replication plugin with change Ibf1ca6247.

Bug: Issue 418811956
Change-Id: If489f6b9ac4cdb307a4332bbf23dcf2b51f5178a
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java
index 472d64d..4b3749d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java
@@ -95,6 +95,7 @@
   private final Set<TransportException> fetchFailures = Sets.newHashSetWithExpectedSize(4);
   private boolean fetchAllRefs;
   private Repository git;
+  private boolean isCollision;
   private boolean retrying;
   private int retryCount;
   private final int maxRetries;
@@ -292,7 +293,7 @@
   }
 
   private void statesCleanUp() {
-    if (!stateMap.isEmpty() && !isRetrying()) {
+    if (!stateMap.isEmpty() && !isRetrying() && !isCollision) {
       for (Map.Entry<FetchRefSpec, ReplicationState> entry : stateMap.entries()) {
         entry
             .getValue()
@@ -348,6 +349,7 @@
     // we start replication (instead a new instance, with the same URI, is
     // created and scheduled for a future point in time.)
     //
+    isCollision = false;
     if (replicationType == ReplicationType.ASYNC && !pool.requestRunway(this)) {
       if (!canceled) {
         repLog.info(
@@ -357,6 +359,7 @@
             uri,
             pool.getInFlight(getURI()).map(FetchOne::getTaskIdHex).orElse("<unknown>"));
         pool.reschedule(this, Source.RetryReason.COLLISION);
+        isCollision = true;
       }
       return;
     }