From 15431da536e99d58dce3dc1bf9c7ab94d1f096a2 Mon Sep 17 00:00:00 2001
From: Fabio Pistolesi <fabio.pistolesi@forgerock.com>
Date: Mon, 04 Jan 2016 13:53:08 +0000
Subject: [PATCH] OPENDJ-2118 Changelog purge does not seem to work anymore after changelog indexer is disabled

---
 opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationServer.java              |   13 +++++++++++--
 opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/file/FileChangelogDB.java |   24 +++++++++---------------
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationServer.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationServer.java
index 9f244c0..58b34db 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationServer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationServer.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2011-2015 ForgeRock AS
+ *      Portions Copyright 2011-2016 ForgeRock AS.
  */
 package org.opends.server.replication.server;
 
@@ -171,7 +171,7 @@
     this.domainPredicate = predicate;
 
     enableExternalChangeLog();
-    this.changelogDB = new FileChangelogDB(this, cfg);
+    this.changelogDB = new FileChangelogDB(this, config.getReplicationDBDirectory());
 
     replSessionSecurity = new ReplSessionSecurity();
     initialize();
@@ -1329,6 +1329,15 @@
     return dsrsShutdownSync;
   }
 
+  /**
+   * Returns whether change-log indexing is enabled for this RS.
+   * @return true if change-log indexing is enabled for this RS.
+   */
+  public boolean isChangeNumberEnabled()
+  {
+    return config.isComputeChangeNumber();
+  }
+
   /** {@inheritDoc} */
   @Override
   public String toString()
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/file/FileChangelogDB.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/file/FileChangelogDB.java
index 1568b4f..1cb539f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/file/FileChangelogDB.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/file/FileChangelogDB.java
@@ -21,7 +21,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2014-2015 ForgeRock AS
+ *      Copyright 2014-2016 ForgeRock AS.
  */
 package org.opends.server.replication.server.changelog.file;
 
@@ -48,7 +48,6 @@
 import org.forgerock.opendj.config.server.ConfigException;
 import org.forgerock.util.Pair;
 import org.forgerock.util.time.TimeService;
-import org.opends.server.admin.std.server.ReplicationServerCfg;
 import org.opends.server.api.DirectoryThread;
 import org.opends.server.backends.ChangelogBackend;
 import org.opends.server.replication.common.CSN;
@@ -97,7 +96,6 @@
   private final ConcurrentSkipListMap<ReplicaId, CopyOnWriteArrayList<ReplicaCursor>> replicaCursors =
       new ConcurrentSkipListMap<>();
   private ReplicationEnvironment replicationEnv;
-  private final ReplicationServerCfg config;
   private final File dbDirectory;
 
   /**
@@ -132,17 +130,16 @@
    *
    * @param replicationServer
    *          the local replication server.
-   * @param config
-   *          the replication server configuration
+   * @param dbDirectoryPath
+   *          the path where the changelog files reside.
    * @throws ConfigException
    *           if a problem occurs opening the supplied directory
    */
-  public FileChangelogDB(final ReplicationServer replicationServer, final ReplicationServerCfg config)
+  public FileChangelogDB(final ReplicationServer replicationServer, String dbDirectoryPath)
       throws ConfigException
   {
-    this.config = config;
     this.replicationServer = replicationServer;
-    this.dbDirectory = makeDir(config.getReplicationDBDirectory());
+    this.dbDirectory = makeDir(dbDirectoryPath);
   }
 
   private File makeDir(final String dbDirName) throws ConfigException
@@ -289,11 +286,10 @@
   {
     try
     {
-      final File dbDir = getFileForPath(config.getReplicationDBDirectory());
-      replicationEnv = new ReplicationEnvironment(dbDir.getAbsolutePath(), replicationServer, TimeService.SYSTEM);
+      replicationEnv = new ReplicationEnvironment(dbDirectory.getAbsolutePath(), replicationServer, TimeService.SYSTEM);
       final ChangelogState changelogState = replicationEnv.getChangelogState();
       initializeToChangelogState(changelogState);
-      if (config.isComputeChangeNumber())
+      if (replicationServer.isChangeNumberEnabled())
       {
         startIndexer();
       }
@@ -625,7 +621,7 @@
 
   void resetChangeNumberIndex(long newFirstCN, DN baseDN, CSN newFirstCSN) throws ChangelogException
   {
-    if (!config.isComputeChangeNumber())
+    if (!replicationServer.isChangeNumberEnabled())
     {
       throw new ChangelogException(ERR_REPLICATION_CHANGE_NUMBER_DISABLED.get(baseDN));
     }
@@ -908,9 +904,7 @@
           final CSN purgeCSN = new CSN(purgeTimestamp, 0, 0);
           final CSN oldestNotPurgedCSN;
 
-          // next code assumes that the compute-change-number config
-          // never changes during the life time of an RS
-          if (!config.isComputeChangeNumber())
+          if (!replicationServer.isChangeNumberEnabled())
           {
             oldestNotPurgedCSN = purgeCSN;
           }

--
Gitblit v1.10.0