Code simplification in AttributeIndex
Code review: Matthew Swift
AttributeIndex.java:
Removed getEqualityIndex(), getApproximateIndex(), getOrderingIndex(), getSubstringIndex(), getPresenceIndex() and getIndexById() methods, all replaced with the new getNameToIndexes() and getDefaultNameToIndexes() methods.
Importer.java, IndexQueryFactoryImpl.java, Suffix.java, VerifyJob.java:
Consequence of the change to AttributeIndex + added toImportIndexType(String IndexID)
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | | { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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) |
| | |
| | | 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. |
| | | * |
| | |
| | | { |
| | | 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()) |
| | | { |
| | |
| | | { |
| | | 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()) |
| | |
| | | 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()) |
| | |
| | | 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 |
| | |
| | | { |
| | | // 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) |
| | |
| | | @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) |
| | |
| | | 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) |
| | |
| | | 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()) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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; |
| | |
| | | { |
| | | 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) |
| | |
| | | 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) |
| | |
| | | { |
| | | 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) |