Remove events from beforeStartupEventsQueue in-memory queue
Before pull-replication plugin is fully loaded it can receive
events. These events are stored in an in-memory queue called
`beforeStartupEventsQueue`. After plugin is fully loaded those
events are processed but never removed from the queue. This can
cause issue processing the same event multiple times.
Replication done with apply-object may not be idempotent if
the event generated at a point in time is processed later.
To avoid that remove event from the queue and then process it.
Bug: Issue 307592553
Change-Id: I946deebe15b92bad00e1127e738ef2540ee78983
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationQueue.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationQueue.java
index 5f4f5bc..fe6a17c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationQueue.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationQueue.java
@@ -533,7 +533,8 @@
private void fireBeforeStartupEvents() {
Set<String> eventsReplayed = new HashSet<>();
- for (ReferenceUpdatedEvent event : beforeStartupEventsQueue) {
+ ReferenceUpdatedEvent event;
+ while ((event = beforeStartupEventsQueue.poll()) != null) {
String eventKey = String.format("%s:%s", event.projectName(), event.refName());
if (!eventsReplayed.contains(eventKey)) {
repLog.info("Firing pending task {}", event);