From 4cd06b3633e335f68d6cad0ad2483246076775b4 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 07 Apr 2015 15:43:34 +0000
Subject: [PATCH] Code simplification in AttributeIndex
---
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/IndexQueryFactoryImpl.java | 7 -
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Suffix.java | 18 ---
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VerifyJob.java | 30 +++---
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java | 51 +++++++++---
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java | 86 ++++----------------
5 files changed, 76 insertions(+), 116 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java
index a151ad9..ba40a2f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java
@@ -109,7 +109,7 @@
}
/**
- * This class implements an attribute indexer for matching rules in JE Backend.
+ * This class implements an attribute indexer for matching rules in a Backend.
*/
final class MatchingRuleIndex extends DefaultIndex
{
@@ -999,72 +999,6 @@
}
/**
- * Return the equality index.
- *
- * @return The equality index.
- */
- MatchingRuleIndex getEqualityIndex()
- {
- return getIndexById(IndexType.EQUALITY.toString());
- }
-
- /**
- * Return the approximate index.
- *
- * @return The approximate index.
- */
- MatchingRuleIndex getApproximateIndex()
- {
- return getIndexById(IndexType.APPROXIMATE.toString());
- }
-
- /**
- * Return the ordering index.
- *
- * @return The ordering index.
- */
- MatchingRuleIndex getOrderingIndex()
- {
- return getIndexById(IndexType.ORDERING.toString());
- }
-
- /**
- * Return the substring index.
- *
- * @return The substring index.
- */
- MatchingRuleIndex getSubstringIndex()
- {
- return getIndexById(IndexType.SUBSTRING.toString());
- }
-
- /**
- * Return the presence index.
- *
- * @return The presence index.
- */
- MatchingRuleIndex getPresenceIndex()
- {
- return getIndexById(IndexType.PRESENCE.toString());
- }
-
- /**
- * Return the index identified by the provided identifier.
- * <p>
- * Common index identifiers are "presence", "equality", "substring",
- * "ordering" and "approximate".
- *
- * @param indexId
- * the identifier of the requested index
- * @return The index identified by the provided identifier, or null if no such
- * index exists
- */
- MatchingRuleIndex getIndexById(String indexId)
- {
- return nameToIndexes.get(indexId);
- }
-
- /**
* Return the mapping of extensible index types and indexes.
*
* @return The map containing entries (extensible index type, list of indexes)
@@ -1119,6 +1053,24 @@
return new LinkedHashSet<Index>(nameToIndexes.values());
}
+ 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-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java
index 820e074..a4f5796 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java
@@ -657,11 +657,7 @@
{
for (AttributeIndex attributeIndex : suffix.getAttrIndexMap().values())
{
- putInIdContainerMap(attributeIndex.getEqualityIndex());
- putInIdContainerMap(attributeIndex.getPresenceIndex());
- putInIdContainerMap(attributeIndex.getSubstringIndex());
- putInIdContainerMap(attributeIndex.getOrderingIndex());
- putInIdContainerMap(attributeIndex.getApproximateIndex());
+ putInIdContainerMap(attributeIndex.getDefaultNameToIndexes().values());
Map<String, Collection<MatchingRuleIndex>> extensibleMap = attributeIndex.getExtensibleIndexes();
if (!extensibleMap.isEmpty())
{
@@ -1680,11 +1676,11 @@
{
final IndexingOptions options = attrIndex.getIndexingOptions();
- processAttribute(attrIndex.getEqualityIndex(), ImportIndexType.EQUALITY, entry, attrType, entryID, options);
- processAttribute(attrIndex.getPresenceIndex(), ImportIndexType.PRESENCE, entry, attrType, entryID, options);
- processAttribute(attrIndex.getSubstringIndex(), ImportIndexType.SUBSTRING, entry, attrType, entryID, options);
- processAttribute(attrIndex.getOrderingIndex(), ImportIndexType.ORDERING, entry, attrType, entryID, options);
- processAttribute(attrIndex.getApproximateIndex(), ImportIndexType.APPROXIMATE, entry, attrType, entryID, options);
+ for (Map.Entry<String, MatchingRuleIndex> mapEntry : attrIndex.getDefaultNameToIndexes().entrySet())
+ {
+ ImportIndexType indexType = toImportIndexType(mapEntry.getKey());
+ processAttribute(mapEntry.getValue(), indexType, entry, attrType, entryID, options);
+ }
Map<String, Collection<MatchingRuleIndex>> extensibleMap = attrIndex.getExtensibleIndexes();
if (!extensibleMap.isEmpty())
@@ -3090,11 +3086,11 @@
private void rebuildAttributeIndexes(WriteableTransaction txn, AttributeIndex attrIndex, AttributeType attrType,
boolean onlyDegraded) throws StorageRuntimeException
{
- fillIndexMap(txn, attrType, attrIndex.getSubstringIndex(), ImportIndexType.SUBSTRING, onlyDegraded);
- fillIndexMap(txn, attrType, attrIndex.getOrderingIndex(), ImportIndexType.ORDERING, onlyDegraded);
- fillIndexMap(txn, attrType, attrIndex.getEqualityIndex(), ImportIndexType.EQUALITY, onlyDegraded);
- fillIndexMap(txn, attrType, attrIndex.getPresenceIndex(), ImportIndexType.PRESENCE, onlyDegraded);
- fillIndexMap(txn, attrType, attrIndex.getApproximateIndex(), ImportIndexType.APPROXIMATE, onlyDegraded);
+ for (Map.Entry<String, MatchingRuleIndex> mapEntry : attrIndex.getDefaultNameToIndexes().entrySet())
+ {
+ ImportIndexType indexType = toImportIndexType(mapEntry.getKey());
+ fillIndexMap(txn, attrType, mapEntry.getValue(), indexType, onlyDegraded);
+ }
final Map<String, Collection<MatchingRuleIndex>> extensibleMap = attrIndex.getExtensibleIndexes();
if (!extensibleMap.isEmpty())
@@ -3789,6 +3785,31 @@
VLV
}
+ static ImportIndexType toImportIndexType(String indexID)
+ {
+ if (IndexType.EQUALITY.toString().equals(indexID))
+ {
+ return ImportIndexType.EQUALITY;
+ }
+ else if (IndexType.PRESENCE.toString().equals(indexID))
+ {
+ return ImportIndexType.PRESENCE;
+ }
+ else if (IndexType.SUBSTRING.toString().equals(indexID))
+ {
+ return ImportIndexType.SUBSTRING;
+ }
+ else if (IndexType.ORDERING.toString().equals(indexID))
+ {
+ return ImportIndexType.ORDERING;
+ }
+ else if (IndexType.APPROXIMATE.toString().equals(indexID))
+ {
+ return ImportIndexType.APPROXIMATE;
+ }
+ throw new IllegalArgumentException("Unsupported indexID: " + indexID);
+ }
+
/**
* This class is used as an index key for hash maps that need to process
* multiple suffix index elements into a single queue and/or maps based on
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/IndexQueryFactoryImpl.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/IndexQueryFactoryImpl.java
index 577e8d6..d9d6073 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/IndexQueryFactoryImpl.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/IndexQueryFactoryImpl.java
@@ -81,7 +81,7 @@
{
// Read the database and get Record for the key.
// Select the right index to be used.
- final Index index = attributeIndex.getIndexById(indexID);
+ final Index index = attributeIndex.getNameToIndexes().get(indexID);
if (index == null)
{
if(debugMessage != null)
@@ -117,8 +117,7 @@
@Override
public EntryIDSet evaluate(LocalizableMessageBuilder debugMessage)
{
- // Find the right index.
- final Index index = attributeIndex.getIndexById(indexID);
+ final Index index = attributeIndex.getNameToIndexes().get(indexID);
if (index == null)
{
if (debugMessage != null)
@@ -265,7 +264,7 @@
public EntryIDSet evaluate(LocalizableMessageBuilder debugMessage)
{
final String indexID = PRESENCE_INDEX_KEY;
- final Index index = attributeIndex.getIndexById(indexID);
+ final Index index = attributeIndex.getNameToIndexes().get(indexID);
if (index == null)
{
if(debugMessage != null)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Suffix.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Suffix.java
index 9f94194..af06d45 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Suffix.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Suffix.java
@@ -263,11 +263,7 @@
entryContainer.getID2Subtree().setTrusted(txn, trusted);
for (AttributeIndex attributeIndex : entryContainer.getAttributeIndexes())
{
- setTrusted(txn, attributeIndex.getEqualityIndex(), trusted);
- setTrusted(txn, attributeIndex.getPresenceIndex(), trusted);
- setTrusted(txn, attributeIndex.getSubstringIndex(), trusted);
- setTrusted(txn, attributeIndex.getOrderingIndex(), trusted);
- setTrusted(txn, attributeIndex.getApproximateIndex(), trusted);
+ setTrusted(txn, attributeIndex.getDefaultNameToIndexes().values(), trusted);
Map<String, Collection<MatchingRuleIndex>> exIndexes = attributeIndex.getExtensibleIndexes();
if(!exIndexes.isEmpty())
{
@@ -280,21 +276,13 @@
}
}
- private void setTrusted(WriteableTransaction txn, Index index, boolean trusted)
- {
- if (index != null)
- {
- index.setTrusted(txn, trusted);
- }
- }
-
private void setTrusted(WriteableTransaction txn, Collection<MatchingRuleIndex> indexes, boolean trusted)
{
if (indexes != null)
{
- for (Index subIndex : indexes)
+ for (Index index : indexes)
{
- subIndex.setTrusted(txn, trusted);
+ index.setTrusted(txn, trusted);
}
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VerifyJob.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VerifyJob.java
index b97484c..1df6583 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VerifyJob.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VerifyJob.java
@@ -53,6 +53,7 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.schema.MatchingRule;
import org.forgerock.opendj.ldap.spi.IndexingOptions;
+import org.opends.server.admin.std.meta.BackendIndexCfgDefn.IndexType;
import org.opends.server.backends.VerifyConfig;
import org.opends.server.backends.pluggable.AttributeIndex.MatchingRuleIndex;
import org.opends.server.backends.pluggable.spi.Cursor;
@@ -480,11 +481,10 @@
{
AttributeIndex attrIndex = attrIndexList.get(0);
final IndexingOptions options = attrIndex.getIndexingOptions();
- iterateAttrIndex(txn, attrIndex.getEqualityIndex(), options);
- iterateAttrIndex(txn, attrIndex.getPresenceIndex(), options);
- iterateAttrIndex(txn, attrIndex.getSubstringIndex(), options);
- iterateAttrIndex(txn, attrIndex.getOrderingIndex(), options);
- iterateAttrIndex(txn, attrIndex.getApproximateIndex(), options);
+ for (MatchingRuleIndex index : attrIndex.getDefaultNameToIndexes().values())
+ {
+ iterateAttrIndex(txn, index, options);
+ }
// TODO: Need to iterate through ExtendedMatchingRules indexes.
}
else if (vlvIndexList.size() > 0)
@@ -1381,11 +1381,12 @@
return;
}
- Index equalityIndex = attrIndex.getEqualityIndex();
- Index presenceIndex = attrIndex.getPresenceIndex();
- Index substringIndex = attrIndex.getSubstringIndex();
- Index orderingIndex = attrIndex.getOrderingIndex();
- Index approximateIndex = attrIndex.getApproximateIndex();
+ final Map<String, MatchingRuleIndex> nameToIndexes = attrIndex.getNameToIndexes();
+ Index equalityIndex = nameToIndexes.get(IndexType.EQUALITY.toString());
+ Index presenceIndex = nameToIndexes.get(IndexType.PRESENCE.toString());
+ Index substringIndex = nameToIndexes.get(IndexType.SUBSTRING.toString());
+ Index orderingIndex = nameToIndexes.get(IndexType.ORDERING.toString());
+ Index approximateIndex = nameToIndexes.get(IndexType.APPROXIMATE.toString());
// TODO: Add support for Extended Matching Rules indexes.
if (presenceIndex != null)
@@ -1548,11 +1549,10 @@
{
AttributeIndex attrIndex = attrIndexList.get(0);
totalCount = 0;
- totalCount += getRecordCount(txn, attrIndex.getEqualityIndex());
- totalCount += getRecordCount(txn, attrIndex.getPresenceIndex());
- totalCount += getRecordCount(txn, attrIndex.getSubstringIndex());
- totalCount += getRecordCount(txn, attrIndex.getOrderingIndex());
- totalCount += getRecordCount(txn, attrIndex.getApproximateIndex());
+ for (MatchingRuleIndex index : attrIndex.getDefaultNameToIndexes().values())
+ {
+ totalCount += getRecordCount(txn, index);
+ }
// TODO: Add support for Extended Matching Rules indexes.
}
else if (vlvIndexList.size() > 0)
--
Gitblit v1.10.0