From d4abe4793a31c2f9fee91bbe2a07b76b790ea560 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 08 Apr 2015 11:29:49 +0000
Subject: [PATCH] (CR-6590) Remove code specific to extensible indexes in Importer and VerifyJob 

---
 opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VerifyJob.java      |   10 +-
 opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java |   65 ----------------
 opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java       |  146 +++++++-----------------------------
 3 files changed, 34 insertions(+), 187 deletions(-)

diff --git a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java
index a5bf2e8..f23473d 100644
--- a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java
+++ b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java
@@ -29,7 +29,6 @@
 
 import static org.opends.messages.JebMessages.*;
 import static org.opends.server.backends.pluggable.EntryIDSet.*;
-import static org.opends.server.util.ServerConstants.*;
 import static org.opends.server.util.StaticUtils.*;
 
 import java.io.Closeable;
@@ -243,11 +242,6 @@
   /** The attribute type for which this instance will generate index keys. */
   private final AttributeType attributeType;
 
-  /**
-   * The mapping from extensible index types (e.g. "substring" or "shared") to list of indexes.
-   */
-  private Map<String, Collection<MatchingRuleIndex>> extensibleIndexesMapping;
-
   AttributeIndex(BackendIndexCfg config, State state, EntryContainer entryContainer, WriteableTransaction txn)
       throws ConfigException
   {
@@ -264,7 +258,6 @@
     buildExtensibleIndexes(txn);
 
     indexingOptions = new IndexingOptionsImpl(config.getSubstringLength());
-    extensibleIndexesMapping = computeExtensibleIndexesMapping();
   }
 
   private void buildPresenceIndex(WriteableTransaction txn)
@@ -761,7 +754,6 @@
         }
       });
 
-      extensibleIndexesMapping = computeExtensibleIndexesMapping();
       config = cfg;
     }
     catch(Exception e)
@@ -998,68 +990,11 @@
         + config.getAttribute().getNameOrOID();
   }
 
-  /**
-   * Return the mapping of extensible index types and indexes.
-   *
-   * @return The map containing entries (extensible index type, list of indexes)
-   */
-  Map<String, Collection<MatchingRuleIndex>> getExtensibleIndexes()
-  {
-    return extensibleIndexesMapping;
-  }
-
-  private Map<String, Collection<MatchingRuleIndex>> computeExtensibleIndexesMapping()
-  {
-    final Collection<MatchingRuleIndex> substring = new ArrayList<MatchingRuleIndex>();
-    final Collection<MatchingRuleIndex> shared = new ArrayList<MatchingRuleIndex>();
-    for (Map.Entry<String, MatchingRuleIndex> entry : nameToIndexes.entrySet())
-    {
-      final String indexId = entry.getKey();
-      if (isDefaultIndex(indexId)) {
-        continue;
-      }
-      if (indexId.endsWith(EXTENSIBLE_INDEXER_ID_SUBSTRING))
-      {
-        substring.add(entry.getValue());
-      }
-      else
-      {
-        shared.add(entry.getValue());
-      }
-    }
-    final Map<String, Collection<MatchingRuleIndex>> indexMap = new HashMap<String, Collection<MatchingRuleIndex>>();
-    indexMap.put(EXTENSIBLE_INDEXER_ID_SUBSTRING, substring);
-    indexMap.put(EXTENSIBLE_INDEXER_ID_SHARED, shared);
-    return Collections.unmodifiableMap(indexMap);
-  }
-
-  private boolean isDefaultIndex(String indexId)
-  {
-    return indexId.equals(IndexType.EQUALITY.toString())
-        || indexId.equals(IndexType.PRESENCE.toString())
-        || indexId.equals(IndexType.SUBSTRING.toString())
-        || indexId.equals(IndexType.ORDERING.toString())
-        || indexId.equals(IndexType.APPROXIMATE.toString());
-  }
-
   Map<String, MatchingRuleIndex> getNameToIndexes()
   {
     return nameToIndexes;
   }
 
-  Map<String, MatchingRuleIndex> getDefaultNameToIndexes()
-  {
-    final Map<String, MatchingRuleIndex> result = new HashMap<String, MatchingRuleIndex>(nameToIndexes);
-    for (Iterator<String> it = result.keySet().iterator(); it.hasNext();)
-    {
-      if (!isDefaultIndex(it.next()))
-      {
-        it.remove();
-      }
-    }
-    return result;
-  }
-
   /**
    * Retrieve the entry IDs that might match an extensible filter.
    *
diff --git a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java
index 6c8e043..0172b6c 100644
--- a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java
+++ b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java
@@ -2804,29 +2804,21 @@
     /** Map of index keys to indexes. */
     private final Map<IndexKey, MatchingRuleIndex> indexMap =
         new LinkedHashMap<IndexKey, MatchingRuleIndex>();
-
-    /** Map of index keys to extensible indexes. */
-    private final Map<IndexKey, Collection<MatchingRuleIndex>> extensibleIndexMap =
-        new LinkedHashMap<IndexKey, Collection<MatchingRuleIndex>>();
-
     /** List of VLV indexes. */
     private final List<VLVIndex> vlvIndexes = new LinkedList<VLVIndex>();
 
     /** The DN2ID index. */
     private DN2ID dn2id;
-
     /** The DN2URI index. */
     private DN2URI dn2uri;
 
     /** Total entries to be processed. */
     private long totalEntries;
-
     /** Total entries processed. */
     private final AtomicLong entriesProcessed = new AtomicLong(0);
 
     /** The suffix instance. */
     private Suffix suffix;
-
     /** The entry container. */
     private EntryContainer entryContainer;
 
@@ -3051,60 +3043,23 @@
     private void rebuildAttributeIndexes(WriteableTransaction txn, AttributeIndex attrIndex, AttributeType attrType,
         boolean onlyDegraded) throws StorageRuntimeException
     {
-      for (Map.Entry<String, MatchingRuleIndex> mapEntry : attrIndex.getDefaultNameToIndexes().entrySet())
+      for (Map.Entry<String, MatchingRuleIndex> mapEntry : attrIndex.getNameToIndexes().entrySet())
       {
         ImportIndexType indexType = toImportIndexType(mapEntry.getKey());
         fillIndexMap(txn, attrType, mapEntry.getValue(), indexType, onlyDegraded);
       }
-
-      final Map<String, Collection<MatchingRuleIndex>> extensibleMap = attrIndex.getExtensibleIndexes();
-      if (!extensibleMap.isEmpty())
-      {
-        final Collection<MatchingRuleIndex> subIndexes = extensibleMap.get(EXTENSIBLE_INDEXER_ID_SUBSTRING);
-        fillIndexMap(txn, attrType, subIndexes, ImportIndexType.EX_SUBSTRING, onlyDegraded);
-        final Collection<MatchingRuleIndex> sharedIndexes = extensibleMap.get(EXTENSIBLE_INDEXER_ID_SHARED);
-        fillIndexMap(txn, attrType, sharedIndexes, ImportIndexType.EX_SHARED, onlyDegraded);
-      }
-    }
-
-    private void fillIndexMap(WriteableTransaction txn, AttributeType attrType, Collection<MatchingRuleIndex> indexes,
-        ImportIndexType importIndexType, boolean onlyDegraded)
-    {
-      if (indexes != null && !indexes.isEmpty())
-      {
-        final List<MatchingRuleIndex> mutableCopy = new LinkedList<MatchingRuleIndex>(indexes);
-        for (final Iterator<MatchingRuleIndex> it = mutableCopy.iterator(); it.hasNext();)
-        {
-          final Index index = it.next();
-          if (!onlyDegraded || !index.isTrusted())
-          {
-            if (!rebuildConfig.isClearDegradedState() || index.getRecordCount(txn) == 0)
-            {
-              putInIdContainerMap(index);
-            }
-          }
-          else
-          {
-            // This index is not a candidate for rebuilding.
-            it.remove();
-          }
-        }
-        if (!mutableCopy.isEmpty())
-        {
-          extensibleIndexMap.put(new IndexKey(attrType, importIndexType, 0), mutableCopy);
-        }
-      }
     }
 
     private void fillIndexMap(WriteableTransaction txn, AttributeType attrType, MatchingRuleIndex index,
         ImportIndexType importIndexType, boolean onlyDegraded)
     {
-      if (index != null
-          && (!onlyDegraded || !index.isTrusted())
+      if ((!onlyDegraded || !index.isTrusted())
           && (!rebuildConfig.isClearDegradedState() || index.getRecordCount(txn) == 0))
       {
         putInIdContainerMap(index);
-        final IndexKey key = new IndexKey(attrType, importIndexType, index.getIndexEntryLimit());
+
+        int indexEntryLimit = !importIndexType.isExtensible ? index.getIndexEntryLimit() : 0;
+        final IndexKey key = new IndexKey(attrType, importIndexType, indexEntryLimit);
         indexMap.put(key, index);
       }
     }
@@ -3127,28 +3082,13 @@
         entryContainer.clearDatabase(txn, entryContainer.getID2Subtree());
       }
 
-      if (!indexMap.isEmpty())
+      for (Map.Entry<IndexKey, MatchingRuleIndex> mapEntry : indexMap.entrySet())
       {
-        for (final Index index : indexMap.values())
+        final ImportIndexType indexType = mapEntry.getKey().getIndexType();
+        final Index index = mapEntry.getValue();
+        if (indexType.isExtensible || !onlyDegraded || !index.isTrusted())
         {
-          if (!onlyDegraded || !index.isTrusted())
-          {
-            entryContainer.clearDatabase(txn, index);
-          }
-        }
-      }
-
-      if (!extensibleIndexMap.isEmpty())
-      {
-        for (final Collection<MatchingRuleIndex> subIndexes : extensibleIndexMap.values())
-        {
-          if (subIndexes != null)
-          {
-            for (final Index subIndex : subIndexes)
-            {
-              entryContainer.clearDatabase(txn, subIndex);
-            }
-          }
+          entryContainer.clearDatabase(txn, index);
         }
       }
 
@@ -3172,19 +3112,9 @@
           ec.getID2Subtree().setTrusted(txn, trusted);
         }
         setTrusted(txn, indexMap.values(), trusted);
-        if (!vlvIndexes.isEmpty())
+        for (VLVIndex vlvIndex : vlvIndexes)
         {
-          for (VLVIndex vlvIndex : vlvIndexes)
-          {
-            vlvIndex.setTrusted(txn, trusted);
-          }
-        }
-        if (!extensibleIndexMap.isEmpty())
-        {
-          for (Collection<MatchingRuleIndex> subIndexes : extensibleIndexMap.values())
-          {
-            setTrusted(txn, subIndexes, trusted);
-          }
+          vlvIndex.setTrusted(txn, trusted);
         }
       }
       catch (StorageRuntimeException ex)
@@ -3436,7 +3366,6 @@
         processDN2URI(suffix, null, entry);
       }
       processIndexes(entry, entryID);
-      processExtensibleIndexes(entry, entryID);
       processVLVIndexes(entry, entryID);
     }
 
@@ -3451,26 +3380,6 @@
       buffer.flush(txn);
     }
 
-    private void processExtensibleIndexes(Entry entry, EntryID entryID)
-        throws InterruptedException
-    {
-      for (Map.Entry<IndexKey, Collection<MatchingRuleIndex>> mapEntry :
-        this.extensibleIndexMap.entrySet())
-      {
-        IndexKey key = mapEntry.getKey();
-        AttributeType attrType = key.getAttributeType();
-        if (entry.hasAttribute(attrType))
-        {
-          AttributeIndex attributeIndex = entryContainer.getAttributeIndex(attrType);
-          IndexingOptions options = attributeIndex.getIndexingOptions();
-          for (MatchingRuleIndex index : mapEntry.getValue())
-          {
-            processAttribute(index, entry, entryID, options, key);
-          }
-        }
-      }
-    }
-
     private void processIndexes(Entry entry, EntryID entryID)
         throws StorageRuntimeException, InterruptedException
     {
@@ -3726,29 +3635,34 @@
     }
   }
 
-  /**
-   * This class defines the individual index type available.
-   */
-  private enum ImportIndexType
+  /** Defines the individual index type available. */
+  enum ImportIndexType
   {
     /** The DN index type. */
-    DN,
+    DN(false),
     /** The equality index type. */
-    EQUALITY,
+    EQUALITY(false),
     /** The presence index type. */
-    PRESENCE,
+    PRESENCE(false),
     /** The sub-string index type. */
-    SUBSTRING,
+    SUBSTRING(false),
     /** The ordering index type. */
-    ORDERING,
+    ORDERING(false),
     /** The approximate index type. */
-    APPROXIMATE,
+    APPROXIMATE(false),
     /** The extensible sub-string index type. */
-    EX_SUBSTRING,
+    EX_SUBSTRING(true),
     /** The extensible shared index type. */
-    EX_SHARED,
+    EX_SHARED(true),
     /** The vlv index type. */
-    VLV
+    VLV(false);
+
+    private final boolean isExtensible;
+
+    private ImportIndexType(boolean isExtensible)
+    {
+      this.isExtensible = isExtensible;
+    }
   }
 
   static ImportIndexType toImportIndexType(String indexID)
diff --git a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VerifyJob.java b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VerifyJob.java
index 1df6583..80267de 100644
--- a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VerifyJob.java
+++ b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VerifyJob.java
@@ -481,11 +481,10 @@
     {
       AttributeIndex attrIndex = attrIndexList.get(0);
       final IndexingOptions options = attrIndex.getIndexingOptions();
-      for (MatchingRuleIndex index : attrIndex.getDefaultNameToIndexes().values())
+      for (MatchingRuleIndex index : attrIndex.getNameToIndexes().values())
       {
         iterateAttrIndex(txn, index, options);
       }
-     // TODO: Need to iterate through ExtendedMatchingRules indexes.
     }
     else if (vlvIndexList.size() > 0)
     {
@@ -1545,17 +1544,16 @@
         {
           totalCount = id2s.getRecordCount(txn);
         }
-        else if(attrIndexList.size() > 0)
+        else if (!attrIndexList.isEmpty())
         {
           AttributeIndex attrIndex = attrIndexList.get(0);
           totalCount = 0;
-          for (MatchingRuleIndex index : attrIndex.getDefaultNameToIndexes().values())
+          for (MatchingRuleIndex index : attrIndex.getNameToIndexes().values())
           {
             totalCount += getRecordCount(txn, index);
           }
-          // TODO: Add support for Extended Matching Rules indexes.
         }
-        else if (vlvIndexList.size() > 0)
+        else if (!vlvIndexList.isEmpty())
         {
           totalCount = vlvIndexList.get(0).getRecordCount(txn);
         }

--
Gitblit v1.10.0