From c59e1a1d20a92a318e22141a5d9cfded75f61f89 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Fri, 11 Sep 2026 13:07:08 +0000
Subject: [PATCH] [#951] Keep the persisted position when a domain drops its in-memory ServerState (#970)

---
 opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/PersistentServerState.java |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/PersistentServerState.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/PersistentServerState.java
index 4f2ab78..6b5bba9 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/PersistentServerState.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/PersistentServerState.java
@@ -370,16 +370,20 @@
   }
 
   /**
-   * Empty the ServerState in memory.
+   * Drop the in-memory copy of the ServerState, leaving persistent storage
+   * holding whatever it holds.
    * <p>
-   * The emptied state is marked as not saved, so the next save writes the empty
-   * state out - which is what {@link #clear()} is after. A caller that only
-   * means to drop the in-memory copy, and expects the backend to keep what it
-   * holds, has to keep saves away until it has loaded the state back.
+   * The emptied state is marked as saved, because nothing about it is waiting
+   * to be written: the callers - a domain being disabled, and a domain about to
+   * load its state back - drop the copy in memory without meaning the base
+   * entry to lose its position. Marking it as not saved would have the next
+   * checkpoint, or the last save the state checkpointer runs on its way out,
+   * replace the CSNs on the base entry with nothing.
    */
   public void clearInMemory()
   {
     state.clear();
+    state.setSaved(true);
   }
 
   /**
@@ -388,6 +392,9 @@
   void clear()
   {
     clearInMemory();
+    // Emptying persistent storage too is the point of this method, so the
+    // emptied state does have to be written out.
+    state.setSaved(false);
     save();
   }
 

--
Gitblit v1.10.0