From 5c87cce021cba14003f8371f8e496aefe68724bc Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Thu, 09 Jun 2011 21:24:05 +0000
Subject: [PATCH] Fix issue OPENDJ-67: Investigate ECL change number consistency across replications servers which have been subjected to different purging policies.

---
 opendj-sdk/opends/src/server/org/opends/server/replication/server/DraftCNDB.java |   63 +++++++++++++------------------
 1 files changed, 26 insertions(+), 37 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/server/DraftCNDB.java b/opendj-sdk/opends/src/server/org/opends/server/replication/server/DraftCNDB.java
index d060a5b..c9f23e5 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/server/DraftCNDB.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/server/DraftCNDB.java
@@ -321,7 +321,7 @@
     private final Transaction txn;
     private final DatabaseEntry key;
     private final DatabaseEntry entry;
-
+    private DraftCNData seqnumData = null;
     private boolean isClosed = false;
 
 
@@ -367,18 +367,22 @@
             }
             else
             {
-              // We can move close to the startingChangeNumber.
-              // Let's create a cursor from that point.
-              DatabaseEntry key = new DatabaseEntry();
-              DatabaseEntry data = new DatabaseEntry();
-              if (localCursor.getPrev(
-                  key, data, LockMode.DEFAULT) != OperationStatus.SUCCESS)
+              if (localCursor.getPrev(key, entry, LockMode.DEFAULT)
+                      != OperationStatus.SUCCESS)
               {
                 localCursor.close();
                 localCursor = db.openCursor(localTxn, null);
               }
+              else
+              {
+                 seqnumData =  new DraftCNData(entry.getData());
+              }
             }
           }
+          else
+          {
+            seqnumData = new DraftCNData(entry.getData());
+          }
         }
 
         this.txn = localTxn;
@@ -514,15 +518,10 @@
     {
       try
       {
-        OperationStatus status =
-          cursor.getCurrent(key, entry, LockMode.DEFAULT);
-
-        if (status != OperationStatus.SUCCESS)
+        if (seqnumData != null)
         {
-          return null;
+          return seqnumData.getValue();
         }
-        DraftCNData seqnumData = new DraftCNData(entry.getData());
-        return seqnumData.getValue();
       }
       catch(Exception e)
       {
@@ -539,15 +538,10 @@
     {
       try
       {
-        OperationStatus status =
-          cursor.getCurrent(key, entry, LockMode.DEFAULT);
-
-        if (status != OperationStatus.SUCCESS)
+        if (seqnumData != null)
         {
-          return null;
+          return seqnumData.getServiceID();
         }
-        DraftCNData seqnumData = new DraftCNData(entry.getData());
-        return seqnumData.getServiceID();
       }
       catch(Exception e)
       {
@@ -557,7 +551,7 @@
     }
 
     /**
-     * Getter for the integer value of the current curson, representing
+     * Getter for the integer value of the current cursor, representing
      * the current DraftChangeNumber being processed.
      *
      * @return the current DraftCN as an integer.
@@ -566,13 +560,6 @@
     {
        try
       {
-        OperationStatus status =
-          cursor.getCurrent(key, entry, LockMode.DEFAULT);
-
-        if (status != OperationStatus.SUCCESS)
-        {
-          return -1;
-        }
         String str = decodeUTF8(key.getData());
         int draftCN = new Integer(str);
         return draftCN;
@@ -592,16 +579,10 @@
     {
       try
       {
-        OperationStatus status =
-          cursor.getCurrent(key, entry, LockMode.DEFAULT);
-
-        if (status != OperationStatus.SUCCESS)
+        if (seqnumData != null)
         {
-          return null;
+          return seqnumData.getChangeNumber();
         }
-        DraftCNData seqnumData =
-          new DraftCNData(entry.getData());
-        return seqnumData.getChangeNumber();
       }
       catch(Exception e)
       {
@@ -620,8 +601,16 @@
       OperationStatus status = cursor.getNext(key, entry, LockMode.DEFAULT);
       if (status != OperationStatus.SUCCESS)
       {
+        seqnumData = null;
         return false;
       }
+      try {
+        seqnumData = new DraftCNData(entry.getData());
+      }
+      catch(Exception e)
+      {
+        TRACER.debugCaught(DebugLogLevel.ERROR, e);
+      }
       return true;
     }
 

--
Gitblit v1.10.0