From d743cc961c7b4714b1221868f34f56ebd3865e2a Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Tue, 12 May 2015 14:25:10 +0000
Subject: [PATCH] Fix OPENDJ-2018: Wrong number of entries returned in ldapsearch with the new backend. Recent regression with the latest index optimisation. The EntryIDSet returned when cursoring the dn2id index was not sorted. Thanks Yannick for the quick resolution.

---
 opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
index 68f02d5..6eb729f 100644
--- a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
+++ b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
@@ -1028,7 +1028,7 @@
 
   private static EntryIDSet newIDSetFromCursor(SequentialCursor<?, EntryID> cursor, boolean includeCurrent)
   {
-    final long ids[] = new long[SCOPE_IDSET_LIMIT];
+    long ids[] = new long[SCOPE_IDSET_LIMIT];
     int offset = 0;
     if (includeCurrent) {
       ids[offset++] = cursor.getValue().longValue();
@@ -1036,9 +1036,13 @@
     for(; offset < ids.length && cursor.next() ; offset++) {
       ids[offset] = cursor.getValue().longValue();
     }
+
+    ids = Arrays.copyOf(ids, offset);
+    Arrays.sort(ids);
+
     return offset == SCOPE_IDSET_LIMIT
         ? EntryIDSet.newUndefinedSet()
-        : EntryIDSet.newDefinedSet(Arrays.copyOf(ids, offset));
+        : EntryIDSet.newDefinedSet(ids);
   }
 
   private <E1 extends Exception, E2 extends Exception>

--
Gitblit v1.10.0