From 4cd3d75a0c4b165101245c51f7ca4b8f8bdad7dc Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 07 Oct 2013 11:02:10 +0000
Subject: [PATCH] OPENDJ-1116 Introduce abstraction for the changelog DB

---
 opends/src/server/org/opends/server/replication/server/ReplicationServer.java                 |    6 +-
 opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java        |   27 ---------
 opends/src/server/org/opends/server/replication/server/ECLServerHandler.java                  |    5 -
 opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java           |   65 ---------------------
 opends/src/server/org/opends/server/replication/server/changelog/api/ReplicationDomainDB.java |   18 ------
 5 files changed, 5 insertions(+), 116 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/server/ECLServerHandler.java b/opends/src/server/org/opends/server/replication/server/ECLServerHandler.java
index 65ed953..5e3c96e 100644
--- a/opends/src/server/org/opends/server/replication/server/ECLServerHandler.java
+++ b/opends/src/server/org/opends/server/replication/server/ECLServerHandler.java
@@ -716,7 +716,7 @@
         // Assign the start state for the domain
         if (isPersistent == PERSISTENT_CHANGES_ONLY)
         {
-          newDomainCtxt.startState = rsd.getEligibleState(eligibleCSN);
+          newDomainCtxt.startState = rsd.getLatestServerState().duplicate();
           startStatesFromProvidedCookie.remove(rsd.getBaseDN());
         }
         else
@@ -760,8 +760,7 @@
             }
           }
 
-          // Set the stop state for the domain from the eligibleCSN
-          newDomainCtxt.stopState = rsd.getEligibleState(eligibleCSN);
+          newDomainCtxt.stopState = rsd.getLatestServerState().duplicate();
         }
         newDomainCtxt.currentState = new ServerState();
 
diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationServer.java b/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
index 91e9b23..87a58bd 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
+++ b/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -1507,12 +1507,12 @@
     MultiDomainServerState result = new MultiDomainServerState();
     for (ReplicationServerDomain rsd : getReplicationServerDomains())
     {
+      final ServerState latestDBServerState = rsd.getLatestServerState();
       if (contains(excludedBaseDNs, rsd.getBaseDN().toNormalizedString())
-          || rsd.getLatestServerState().isEmpty())
+          || latestDBServerState.isEmpty())
         continue;
 
-      final CSN eligibleCSN = getEligibleCSN(excludedBaseDNs);
-      result.update(rsd.getBaseDN(), rsd.getEligibleState(eligibleCSN));
+      result.update(rsd.getBaseDN(), latestDBServerState);
     }
     return result;
   }
diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java b/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
index 4f3be6f..b7690a2 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
+++ b/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
@@ -2561,71 +2561,6 @@
   }
 
   /**
-   * Computes the eligible server state for the domain.
-   *
-   * <pre>
-   *     s1               s2          s3
-   *     --               --          --
-   *                                 csn31
-   *     csn15
-   *
-   *  ----------------------------------------- eligibleCSN
-   *     csn14
-   *                     csn26
-   *     csn13
-   * </pre>
-   *
-   * The eligibleState is : s1;csn14 / s2;csn26 / s3;csn31
-   *
-   * @param eligibleCSN
-   *          The provided eligible CSN.
-   * @return The computed eligible server state.
-   */
-  public ServerState getEligibleState(CSN eligibleCSN)
-  {
-    ServerState latestState = getLatestServerState();
-
-    // The result is initialized from the dbState.
-    // From it, we don't want to keep the changes newer than eligibleCSN.
-    ServerState result = latestState.duplicate();
-
-    if (eligibleCSN != null)
-    {
-      for (CSN mostRecentDbCSN : latestState)
-      {
-        try {
-          // Is the most recent change in the Db newer than eligible CSN ?
-          // if yes (like csn15 in the example above, then we have to go back
-          // to the Db and look for the change older than eligible CSN (csn14)
-          if (eligibleCSN.olderOrEqual(mostRecentDbCSN))
-          {
-            // let's try to seek the first change <= eligibleCSN
-            CSN newCSN = domainDB.getCSNAfter(baseDN,
-                mostRecentDbCSN.getServerId(), eligibleCSN);
-            result.update(newCSN);
-          }
-          else
-          {
-            // for this serverId, all changes in the ChangelogDb are holder
-            // than eligibleCSN, the most recent in the db is our guy.
-            result.update(mostRecentDbCSN);
-          }
-        } catch (Exception e) {
-          logError(ERR_WRITER_UNEXPECTED_EXCEPTION
-              .get(stackTraceToSingleLineString(e)));
-          TRACER.debugCaught(DebugLogLevel.ERROR, e);
-        }
-      }
-    }
-
-    if (debugEnabled())
-    {
-      debug("getEligibleState() result is " + result);
-    }
-    return result;
-  }
-
-  /**
    * Returns the start state of the domain, made of the oldest CSN stored for
    * each serverId.
    * <p>
diff --git a/opends/src/server/org/opends/server/replication/server/changelog/api/ReplicationDomainDB.java b/opends/src/server/org/opends/server/replication/server/changelog/api/ReplicationDomainDB.java
index 71bfbb4..8e5b22f 100644
--- a/opends/src/server/org/opends/server/replication/server/changelog/api/ReplicationDomainDB.java
+++ b/opends/src/server/org/opends/server/replication/server/changelog/api/ReplicationDomainDB.java
@@ -171,24 +171,6 @@
   long getCount(DN baseDN, int serverId, CSN from, CSN to);
 
   /**
-   * Returns the {@link CSN} situated immediately after the specified
-   * {@link CSN} for the specified serverId and replication domain according to
-   * the order specified by {@link CSN#compareTo(CSN)}. If an Exception occurs
-   * in this method, then it returns the oldest possible CSN for the provided
-   * serverId.
-   *
-   * @param baseDN
-   *          the replication domain baseDN
-   * @param serverId
-   *          the serverId for which we want the information
-   * @param startAfterCSN
-   *          The position where the iterator must start
-   * @return the CSN immediately after startAfterCSN, or null if no CSN exist
-   *         after startAfterCSN
-   */
-  CSN getCSNAfter(DN baseDN, int serverId, CSN startAfterCSN);
-
-  /**
    * Generates a {@link ReplicaDBCursor} for the specified serverId and
    * replication domain starting after the provided CSN.
    * <p>
diff --git a/opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java b/opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java
index 3d42f3e..60a7186 100644
--- a/opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java
+++ b/opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java
@@ -537,33 +537,6 @@
 
   /** {@inheritDoc} */
   @Override
-  public CSN getCSNAfter(DN baseDN, int serverId, CSN startAfterCSN)
-  {
-    final JEReplicaDB replicaDB = getReplicaDB(baseDN, serverId);
-
-    ReplicaDBCursor cursor = null;
-    try
-    {
-      cursor = replicaDB.generateCursorFrom(startAfterCSN);
-      if (cursor != null && cursor.getChange() != null)
-      {
-        return cursor.getChange().getCSN();
-      }
-      return null;
-    }
-    catch (ChangelogException e)
-    {
-      // there's no change older than startAfterCSN
-      return new CSN(0, 0, serverId);
-    }
-    finally
-    {
-      close(cursor);
-    }
-  }
-
-  /** {@inheritDoc} */
-  @Override
   public ChangeNumberIndexDB getChangeNumberIndexDB()
   {
     synchronized (cnIndexDBLock)

--
Gitblit v1.10.0