Remove events from beforeStartupEventsQueue after fire()
The plugin was removing the event before firing it from the
beforeStartupEventsQueue. This could have caused a message
loss in case the configuration was changed before firing the event.
Now after the plugin is fully loaded each event is
removed from the the in-memory queue after being fired.
Follow up of change 393036.
Plese see comment [1]
[1]: https://gerrit-review.googlesource.com/c/plugins/replication/+/393036/comment/f9aed6f7_5c06661a/
Change-Id: I83abb264be3deae2f5b2330c70727e8f7b6cd3d3
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java
index 4663702..29c4950 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java
@@ -304,13 +304,14 @@
private void fireBeforeStartupEvents() {
Set<String> eventsReplayed = new HashSet<>();
ReferencesUpdatedEvent event;
- while ((event = beforeStartupEventsQueue.poll()) != null) {
+ while ((event = beforeStartupEventsQueue.peek()) != null) {
String eventKey = String.format("%s:%s", event.projectName(), event.getRefNames());
if (!eventsReplayed.contains(eventKey)) {
repLog.atInfo().log("Firing pending task %s", event);
fire(event.projectName(), event.updatedRefs());
eventsReplayed.add(eventKey);
}
+ beforeStartupEventsQueue.remove(event);
}
}