From b8a4d35f03b7fa5cf0d80a9424224f6ddeb3b3f9 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Mon, 19 Oct 2026 08:52:10 +0000
Subject: [PATCH] [#1206] Take a late handler of a replication server back to its queue only once its consumer has every change the queue lacks (#1219)

---
 opendj-server-legacy/src/main/java/org/opends/server/replication/server/MsgQueue.java |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/MsgQueue.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/MsgQueue.java
index 2564dcc..6d84ebd 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/MsgQueue.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/MsgQueue.java
@@ -20,6 +20,7 @@
 import static org.opends.messages.ReplicationMessages.*;
 
 import java.util.TreeMap;
+import java.util.function.Predicate;
 
 import net.jcip.annotations.ThreadSafe;
 
@@ -178,6 +179,32 @@
     }
   }
 
+  /**
+   * Returns whether this queue holds, before the given UpdateMsg, an UpdateMsg which carries the
+   * CSN of a change and matches the given condition: a replica offline message, for one, does not
+   * carry the CSN of a change, and no state ever covers its CSN.
+   *
+   * @param msg
+   *          the UpdateMsg the ones to check come before
+   * @param condition
+   *          the condition the CSN of a change must match
+   * @return {@code true} if a change of this queue before the given UpdateMsg matches the condition
+   */
+  public boolean holdsAChangeBefore(UpdateMsg msg, Predicate<CSN> condition)
+  {
+    synchronized (lock)
+    {
+      for (UpdateMsg before : map.headMap(msg.getCSN()).values())
+      {
+        if (before.contributesToDomainState() && condition.test(before.getCSN()))
+        {
+          return true;
+        }
+      }
+      return false;
+    }
+  }
+
   /** Removes all UpdateMsg form this queue. */
   public void clear()
   {

--
Gitblit v1.10.0