From afcb52d4988031fbfff73eee965f16f04ac6d443 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Thu, 20 Jun 2013 14:43:44 +0000
Subject: [PATCH] Fix OPENDJ-992: JE environment failure (LOG_FILE_NOT_FOUND) after upgrading from OpenDJ 2.4.6 to OpenDJ 2.6.0

---
 opendj-sdk/opends/src/server/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRule.java |   38 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRule.java b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRule.java
index 675cc1f..4250ac3 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRule.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRule.java
@@ -36,7 +36,6 @@
 import org.opends.server.api.AbstractMatchingRule;
 import org.opends.server.api.OrderingMatchingRule;
 import org.opends.server.types.*;
-import org.opends.server.util.StaticUtils;
 
 /**
  * Used to establish an order between historical information and index them.
@@ -162,7 +161,42 @@
    */
   public int compare(byte[] b1, byte[] b2)
   {
-    return StaticUtils.compare(b1, b2);
+    /*
+     * See OPENDJ-992: do not use StaticUtils.compare() because it performs
+     * unsigned comparisons whereas the 2.4 implementation (below) performs
+     * signed comparisons. Changes to indexing comparators require that the
+     * index be rebuilt, otherwise the DB can fail unexpectedly.
+     */
+    int minLength = Math.min(b1.length, b2.length);
+
+    for (int i = 0; i < minLength; i++)
+    {
+      if (b1[i] == b2[i])
+      {
+        continue;
+      }
+      else if (b1[i] < b2[i])
+      {
+        return -1;
+      }
+      else if (b1[i] > b2[i])
+      {
+        return 1;
+      }
+    }
+
+    if (b1.length == b2.length)
+    {
+      return 0;
+    }
+    else if (b1.length < b2.length)
+    {
+      return -1;
+    }
+    else
+    {
+      return 1;
+    }
   }
 
 }

--
Gitblit v1.10.0