From 657c7dde306550c55f5d3a8a162077547a6ea3f0 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 15 Jan 2016 11:01:00 +0000
Subject: [PATCH] Code cleanups: renaming, comments, etc.

---
 opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VLVIndex.java       |   23 ++++++-----
 opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java |   91 ++++++++++++++++++++++++---------------------
 2 files changed, 60 insertions(+), 54 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
index ea3da69..a75b37f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2011-2015 ForgeRock AS
+ *      Portions Copyright 2011-2016 ForgeRock AS
  *      Portions copyright 2013 Manuel Gaupp
  */
 package org.opends.server.backends.pluggable;
@@ -751,24 +751,7 @@
           // Handle base-object search first.
           if (searchScope == SearchScope.BASE_OBJECT)
           {
-            final Entry baseEntry = fetchBaseEntry(txn, aBaseDN, searchScope);
-            if (!isManageDsaITOperation(searchOperation))
-            {
-              dn2uri.checkTargetForReferral(baseEntry, searchOperation.getScope());
-            }
-
-            if (searchOperation.getFilter().matchesEntry(baseEntry))
-            {
-              searchOperation.returnEntry(baseEntry, null);
-            }
-
-            if (pageRequest != null)
-            {
-              // Indicate no more pages.
-              Control control = new PagedResultsControl(pageRequest.isCritical(), 0, null);
-              searchOperation.getResponseControls().add(control);
-            }
-
+            searchBaseObject(txn, searchOperation, pageRequest);
             return null;
           }
 
@@ -780,7 +763,7 @@
             debugBuffer = new StringBuilder();
           }
 
-          EntryIDSet entryIDSet = null;
+          EntryIDSet candidateEntryIDs = null;
           boolean candidatesAreInScope = false;
           if (sortRequest != null)
           {
@@ -788,8 +771,8 @@
             {
               try
               {
-                entryIDSet = vlvIndex.evaluate(txn, searchOperation, sortRequest, vlvRequest, debugBuffer);
-                if (entryIDSet != null)
+                candidateEntryIDs = vlvIndex.evaluate(txn, searchOperation, sortRequest, vlvRequest, debugBuffer);
+                if (candidateEntryIDs != null)
                 {
                   searchOperation.addResponseControl(newServerSideSortControl(SUCCESS));
                   candidatesAreInScope = true;
@@ -806,8 +789,8 @@
           // Combining server-side sort with paged result controls
           // requires us to use an entryIDSet where the entryIDs are ordered
           // so further paging can restart where it previously stopped
-          long[] entryIDReorderedSet;
-          if (entryIDSet == null)
+          long[] reorderedCandidateEntryIDs;
+          if (candidateEntryIDs == null)
           {
             if (processSearchWithVirtualAttributeRule(searchOperation, true))
             {
@@ -819,17 +802,12 @@
                 EntryContainer.this, txn, searchOperation, debugBuffer, rootContainer.getMonitorProvider());
 
             // Evaluate the filter against the attribute indexes.
-            entryIDSet = indexFilter.evaluate();
-
-            if (!isBelowFilterThreshold(entryIDSet))
+            candidateEntryIDs = indexFilter.evaluate();
+            if (!isBelowFilterThreshold(candidateEntryIDs))
             {
-              final int lookThroughLimit = searchOperation.getClientConnection().getLookthroughLimit();
-              final int indexLimit =
-                  config.getIndexEntryLimit() == 0 ? CURSOR_ENTRY_LIMIT : config.getIndexEntryLimit();
-              final int idSetLimit = lookThroughLimit > 0 ? Math.min(indexLimit, lookThroughLimit) : indexLimit;
-
+              final int idSetLimit = getEntryIDSetLimit(searchOperation);
               final EntryIDSet scopeSet = getIDSetFromScope(txn, aBaseDN, searchScope, idSetLimit);
-              entryIDSet.retainAll(scopeSet);
+              candidateEntryIDs.retainAll(scopeSet);
               if (debugBuffer != null)
               {
                 debugBuffer.append(" scope=").append(searchScope);
@@ -850,11 +828,11 @@
               try
               {
                 SortOrder sortOrder = sortRequest.getSortOrder();
-                entryIDReorderedSet = sort(txn, entryIDSet, searchOperation, sortOrder, vlvRequest);
+                reorderedCandidateEntryIDs = sort(txn, candidateEntryIDs, searchOperation, sortOrder, vlvRequest);
               }
               catch (DirectoryException de)
               {
-                entryIDReorderedSet = entryIDSet.toLongArray();
+                reorderedCandidateEntryIDs = candidateEntryIDs.toLongArray();
                 serverSideSortControlError(searchOperation, sortRequest, de);
               }
               try
@@ -882,12 +860,12 @@
             }
             else
             {
-              entryIDReorderedSet = entryIDSet.toLongArray();
+              reorderedCandidateEntryIDs = candidateEntryIDs.toLongArray();
             }
           }
           else
           {
-            entryIDReorderedSet = entryIDSet.toLongArray();
+            reorderedCandidateEntryIDs = candidateEntryIDs.toLongArray();
           }
 
           // If requested, construct and return a fictitious entry containing
@@ -895,17 +873,17 @@
           if (debugBuffer != null)
           {
             debugBuffer.append(" final=");
-            entryIDSet.toString(debugBuffer);
+            candidateEntryIDs.toString(debugBuffer);
 
             Entry debugEntry = buildDebugSearchIndexEntry(debugBuffer);
             searchOperation.returnEntry(debugEntry, null);
             return null;
           }
 
-          if (entryIDReorderedSet != null)
+          if (reorderedCandidateEntryIDs != null)
           {
             rootContainer.getMonitorProvider().incrementIndexedSearchCount();
-            searchIndexed(txn, entryIDReorderedSet, candidatesAreInScope, searchOperation, pageRequest);
+            searchIndexed(txn, reorderedCandidateEntryIDs, candidatesAreInScope, searchOperation, pageRequest);
           }
           else
           {
@@ -927,10 +905,8 @@
 
             if (sortRequest != null)
             {
-              // FIXME -- Add support for sorting unindexed searches using indexes
-              // like DSEE currently does.
+              // FIXME OPENDJ-2628: Add support for sorting unindexed searches using indexes like DSEE currently does
               searchOperation.addResponseControl(newServerSideSortControl(UNWILLING_TO_PERFORM));
-
               if (sortRequest.isCritical())
               {
                 throw new DirectoryException(
@@ -943,6 +919,35 @@
           return null;
         }
 
+        private int getEntryIDSetLimit(final SearchOperation searchOperation)
+        {
+          final int lookThroughLimit = searchOperation.getClientConnection().getLookthroughLimit();
+          final int indexLimit = config.getIndexEntryLimit() == 0 ? CURSOR_ENTRY_LIMIT : config.getIndexEntryLimit();
+          return lookThroughLimit > 0 ? Math.min(indexLimit, lookThroughLimit) : indexLimit;
+        }
+
+        private void searchBaseObject(ReadableTransaction txn, SearchOperation searchOperation,
+            PagedResultsControl pageRequest) throws DirectoryException
+        {
+          final Entry baseEntry = fetchBaseEntry(txn, searchOperation.getBaseDN(), searchOperation.getScope());
+          if (!isManageDsaITOperation(searchOperation))
+          {
+            dn2uri.checkTargetForReferral(baseEntry, searchOperation.getScope());
+          }
+
+          if (searchOperation.getFilter().matchesEntry(baseEntry))
+          {
+            searchOperation.returnEntry(baseEntry, null);
+          }
+
+          if (pageRequest != null)
+          {
+            // Indicate no more pages.
+            Control control = new PagedResultsControl(pageRequest.isCritical(), 0, null);
+            searchOperation.getResponseControls().add(control);
+          }
+        }
+
         private void serverSideSortControlError(final SearchOperation searchOperation,
             ServerSideSortRequestControl sortRequest, DirectoryException de) throws DirectoryException
         {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VLVIndex.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VLVIndex.java
index ca052f2..24c48a8 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VLVIndex.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VLVIndex.java
@@ -517,6 +517,7 @@
     return null;
   }
 
+  /** Returns the total number of entries (a.k.a records, a.k.a keys) indexed by this VLV index. */
   private int getEntryCount(final ReadableTransaction txn)
   {
     return (int) counter.getCount(txn, COUNT_KEY);
@@ -710,10 +711,7 @@
       do
       {
         final ByteString key = definedCursor.getKey();
-        if (logger.isTraceEnabled())
-        {
-          logSearchKeyResult(key);
-        }
+        logSearchKeyResult(key);
         selectedIDs[selectedPos++] = decodeEntryIDFromVLVKey(key);
       }
       while (selectedPos < count && definedCursor.next());
@@ -729,7 +727,7 @@
     if (debugBuilder != null)
     {
       debugBuilder.append("[COUNT:");
-      debugBuilder.append(selectedPos);
+      debugBuilder.append(selectedIDs.length);
       debugBuilder.append("]");
     }
     return selectedIDs;
@@ -743,12 +741,15 @@
 
   private void logSearchKeyResult(final ByteString key)
   {
-    final StringBuilder searchKeyHex = new StringBuilder();
-    byteArrayToHexPlusAscii(searchKeyHex, key.toByteArray(), 4);
-    final StringBuilder foundKeyHex = new StringBuilder();
-    byteArrayToHexPlusAscii(foundKeyHex, key.toByteArray(), 4);
-    logger.trace("Retrieved a sort values set in VLV vlvIndex %s\n" + "Search Key:%s\nFound Key:%s\n",
-        config.getName(), searchKeyHex, foundKeyHex);
+    if (logger.isTraceEnabled())
+    {
+      final StringBuilder searchKeyHex = new StringBuilder();
+      byteArrayToHexPlusAscii(searchKeyHex, key.toByteArray(), 4);
+      final StringBuilder foundKeyHex = new StringBuilder();
+      byteArrayToHexPlusAscii(foundKeyHex, key.toByteArray(), 4);
+      logger.trace("Retrieved a sort values set in VLV vlvIndex %s\n" + "Search Key:%s\nFound Key:%s\n",
+          config.getName(), searchKeyHex, foundKeyHex);
+    }
   }
 
   boolean verifyEntry(final ReadableTransaction txn, final EntryID entryID, final Entry entry)

--
Gitblit v1.10.0