| | |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.admin.std.server.JEIndexCfg; |
| | | import org.opends.server.admin.std.meta.JEIndexCfgDefn; |
| | | import org.opends.server.admin.std.server.LocalDBIndexCfg; |
| | | import org.opends.server.admin.std.meta.LocalDBIndexCfgDefn; |
| | | import org.opends.server.admin.server.ConfigurationChangeListener; |
| | | import org.opends.server.config.ConfigException; |
| | | import static org.opends.messages.JebMessages.*; |
| | |
| | | * then we would not need a separate ordering index. |
| | | */ |
| | | public class AttributeIndex |
| | | implements ConfigurationChangeListener<JEIndexCfg> |
| | | implements ConfigurationChangeListener<LocalDBIndexCfg> |
| | | { |
| | | /** |
| | | * The tracer object for the debug logger. |
| | |
| | | /** |
| | | * The attribute index configuration. |
| | | */ |
| | | private JEIndexCfg indexConfig; |
| | | private LocalDBIndexCfg indexConfig; |
| | | |
| | | /** |
| | | * The index database for attribute equality. |
| | |
| | | * @throws DatabaseException if a JE database error occurs. |
| | | * @throws ConfigException if a configuration related error occurs. |
| | | */ |
| | | public AttributeIndex(JEIndexCfg indexConfig, State state, Environment env, |
| | | public AttributeIndex(LocalDBIndexCfg indexConfig, State state, |
| | | Environment env, |
| | | EntryContainer entryContainer) |
| | | throws DatabaseException, ConfigException |
| | | { |
| | |
| | | this.indexConfig = indexConfig; |
| | | this.state = state; |
| | | |
| | | AttributeType attrType = indexConfig.getIndexAttribute(); |
| | | AttributeType attrType = indexConfig.getAttribute(); |
| | | String name = |
| | | entryContainer.getDatabasePrefix() + "_" + attrType.getNameOrOID(); |
| | | int indexEntryLimit = indexConfig.getIndexEntryLimit(); |
| | | |
| | | if (indexConfig.getIndexType().contains(JEIndexCfgDefn.IndexType.EQUALITY)) |
| | | if (indexConfig.getIndexType().contains( |
| | | LocalDBIndexCfgDefn.IndexType.EQUALITY)) |
| | | { |
| | | if (attrType.getEqualityMatchingRule() == null) |
| | | { |
| | |
| | | entryContainer); |
| | | } |
| | | |
| | | if (indexConfig.getIndexType().contains(JEIndexCfgDefn.IndexType.PRESENCE)) |
| | | if (indexConfig.getIndexType().contains( |
| | | LocalDBIndexCfgDefn.IndexType.PRESENCE)) |
| | | { |
| | | Indexer presenceIndexer = new PresenceIndexer(attrType); |
| | | this.presenceIndex = new Index(name + ".presence", |
| | |
| | | entryContainer); |
| | | } |
| | | |
| | | if (indexConfig.getIndexType().contains(JEIndexCfgDefn.IndexType.SUBSTRING)) |
| | | if (indexConfig.getIndexType().contains( |
| | | LocalDBIndexCfgDefn.IndexType.SUBSTRING)) |
| | | { |
| | | if (attrType.getSubstringMatchingRule() == null) |
| | | { |
| | |
| | | } |
| | | |
| | | Indexer substringIndexer = new SubstringIndexer(attrType, |
| | | indexConfig.getIndexSubstringLength()); |
| | | indexConfig.getSubstringLength()); |
| | | this.substringIndex = new Index(name + ".substring", |
| | | substringIndexer, |
| | | state, |
| | |
| | | entryContainer); |
| | | } |
| | | |
| | | if (indexConfig.getIndexType().contains(JEIndexCfgDefn.IndexType.ORDERING)) |
| | | if (indexConfig.getIndexType().contains( |
| | | LocalDBIndexCfgDefn.IndexType.ORDERING)) |
| | | { |
| | | if (attrType.getOrderingMatchingRule() == null) |
| | | { |
| | |
| | | entryContainer); |
| | | } |
| | | if (indexConfig.getIndexType().contains( |
| | | JEIndexCfgDefn.IndexType.APPROXIMATE)) |
| | | LocalDBIndexCfgDefn.IndexType.APPROXIMATE)) |
| | | { |
| | | if (attrType.getApproximateMatchingRule() == null) |
| | | { |
| | |
| | | */ |
| | | public AttributeType getAttributeType() |
| | | { |
| | | return indexConfig.getIndexAttribute(); |
| | | return indexConfig.getAttribute(); |
| | | } |
| | | |
| | | /** |
| | | * Get the JE index configuration used by this index. |
| | | * @return The configuration in effect. |
| | | */ |
| | | public JEIndexCfg getConfiguration() |
| | | public LocalDBIndexCfg getConfiguration() |
| | | { |
| | | return indexConfig; |
| | | } |
| | |
| | | // concurrent writers. |
| | | Set<ByteString> set = new HashSet<ByteString>(); |
| | | |
| | | int substrLength = indexConfig.getIndexSubstringLength(); |
| | | int substrLength = indexConfig.getSubstringLength(); |
| | | byte[] keyBytes; |
| | | |
| | | // Example: The value is ABCDE and the substring length is 3. |
| | |
| | | */ |
| | | private EntryIDSet matchSubstring(byte[] bytes) |
| | | { |
| | | int substrLength = indexConfig.getIndexSubstringLength(); |
| | | int substrLength = indexConfig.getSubstringLength(); |
| | | |
| | | // There are two cases, depending on whether the user-provided |
| | | // substring is smaller than the configured index substring length or not. |
| | |
| | | if(debugBuffer != null) |
| | | { |
| | | debugBuffer.append("[INDEX:"); |
| | | debugBuffer.append(indexConfig.getIndexAttribute().getNameOrOID()); |
| | | debugBuffer.append(indexConfig.getAttribute().getNameOrOID()); |
| | | debugBuffer.append("."); |
| | | debugBuffer.append("equality]"); |
| | | } |
| | |
| | | if(debugBuffer != null) |
| | | { |
| | | debugBuffer.append("[INDEX:"); |
| | | debugBuffer.append(indexConfig.getIndexAttribute().getNameOrOID()); |
| | | debugBuffer.append(indexConfig.getAttribute().getNameOrOID()); |
| | | debugBuffer.append("."); |
| | | debugBuffer.append("presence]"); |
| | | } |
| | |
| | | if(debugBuffer != null) |
| | | { |
| | | debugBuffer.append("[INDEX:"); |
| | | debugBuffer.append(indexConfig.getIndexAttribute().getNameOrOID()); |
| | | debugBuffer.append(indexConfig.getAttribute().getNameOrOID()); |
| | | debugBuffer.append("."); |
| | | debugBuffer.append("ordering]"); |
| | | } |
| | |
| | | if(debugBuffer != null) |
| | | { |
| | | debugBuffer.append("[INDEX:"); |
| | | debugBuffer.append(indexConfig.getIndexAttribute().getNameOrOID()); |
| | | debugBuffer.append(indexConfig.getAttribute().getNameOrOID()); |
| | | debugBuffer.append("."); |
| | | debugBuffer.append("ordering]"); |
| | | } |
| | |
| | | if(debugBuffer != null) |
| | | { |
| | | debugBuffer.append("[INDEX:"); |
| | | debugBuffer.append(indexConfig.getIndexAttribute(). |
| | | debugBuffer.append(indexConfig.getAttribute(). |
| | | getNameOrOID()); |
| | | debugBuffer.append("."); |
| | | debugBuffer.append("equality]"); |
| | |
| | | if(debugBuffer != null) |
| | | { |
| | | debugBuffer.append("[INDEX:"); |
| | | debugBuffer.append(indexConfig.getIndexAttribute().getNameOrOID()); |
| | | debugBuffer.append(indexConfig.getAttribute().getNameOrOID()); |
| | | debugBuffer.append("."); |
| | | debugBuffer.append("substring]"); |
| | | } |
| | |
| | | if(debugBuffer != null) |
| | | { |
| | | debugBuffer.append("[INDEX:"); |
| | | debugBuffer.append(indexConfig.getIndexAttribute().getNameOrOID()); |
| | | debugBuffer.append(indexConfig.getAttribute().getNameOrOID()); |
| | | debugBuffer.append("."); |
| | | debugBuffer.append("approximate]"); |
| | | } |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public synchronized boolean isConfigurationChangeAcceptable( |
| | | JEIndexCfg cfg, |
| | | LocalDBIndexCfg cfg, |
| | | List<Message> unacceptableReasons) |
| | | { |
| | | AttributeType attrType = cfg.getIndexAttribute(); |
| | | AttributeType attrType = cfg.getAttribute(); |
| | | |
| | | if (cfg.getIndexType().contains(JEIndexCfgDefn.IndexType.EQUALITY)) |
| | | if (cfg.getIndexType().contains(LocalDBIndexCfgDefn.IndexType.EQUALITY)) |
| | | { |
| | | if (equalityIndex == null && attrType.getEqualityMatchingRule() == null) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | if (cfg.getIndexType().contains(JEIndexCfgDefn.IndexType.SUBSTRING)) |
| | | if (cfg.getIndexType().contains(LocalDBIndexCfgDefn.IndexType.SUBSTRING)) |
| | | { |
| | | if (substringIndex == null && attrType.getSubstringMatchingRule() == null) |
| | | { |
| | |
| | | |
| | | } |
| | | |
| | | if (cfg.getIndexType().contains(JEIndexCfgDefn.IndexType.ORDERING)) |
| | | if (cfg.getIndexType().contains(LocalDBIndexCfgDefn.IndexType.ORDERING)) |
| | | { |
| | | if (orderingIndex == null && attrType.getOrderingMatchingRule() == null) |
| | | { |
| | |
| | | return false; |
| | | } |
| | | } |
| | | if (cfg.getIndexType().contains(JEIndexCfgDefn.IndexType.APPROXIMATE)) |
| | | if (cfg.getIndexType().contains(LocalDBIndexCfgDefn.IndexType.APPROXIMATE)) |
| | | { |
| | | if (approximateIndex == null && |
| | | attrType.getApproximateMatchingRule() == null) |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public synchronized ConfigChangeResult applyConfigurationChange( |
| | | JEIndexCfg cfg) |
| | | LocalDBIndexCfg cfg) |
| | | { |
| | | ConfigChangeResult ccr; |
| | | boolean adminActionRequired = false; |
| | | ArrayList<Message> messages = new ArrayList<Message>(); |
| | | try |
| | | { |
| | | AttributeType attrType = cfg.getIndexAttribute(); |
| | | AttributeType attrType = cfg.getAttribute(); |
| | | String name = |
| | | entryContainer.getDatabasePrefix() + "_" + attrType.getNameOrOID(); |
| | | int indexEntryLimit = cfg.getIndexEntryLimit(); |
| | | |
| | | if (cfg.getIndexType().contains(JEIndexCfgDefn.IndexType.EQUALITY)) |
| | | if (cfg.getIndexType().contains(LocalDBIndexCfgDefn.IndexType.EQUALITY)) |
| | | { |
| | | if (equalityIndex == null) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | if (cfg.getIndexType().contains(JEIndexCfgDefn.IndexType.PRESENCE)) |
| | | if (cfg.getIndexType().contains(LocalDBIndexCfgDefn.IndexType.PRESENCE)) |
| | | { |
| | | if(presenceIndex == null) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | if (cfg.getIndexType().contains(JEIndexCfgDefn.IndexType.SUBSTRING)) |
| | | if (cfg.getIndexType().contains(LocalDBIndexCfgDefn.IndexType.SUBSTRING)) |
| | | { |
| | | if(substringIndex == null) |
| | | { |
| | | Indexer substringIndexer = new SubstringIndexer( |
| | | attrType, cfg.getIndexSubstringLength()); |
| | | attrType, cfg.getSubstringLength()); |
| | | substringIndex = new Index(name + ".substring", |
| | | substringIndexer, |
| | | state, |
| | |
| | | messages.add(message); |
| | | } |
| | | |
| | | if(indexConfig.getIndexSubstringLength() != |
| | | cfg.getIndexSubstringLength()) |
| | | if(indexConfig.getSubstringLength() != |
| | | cfg.getSubstringLength()) |
| | | { |
| | | Indexer substringIndexer = new SubstringIndexer( |
| | | attrType, cfg.getIndexSubstringLength()); |
| | | attrType, cfg.getSubstringLength()); |
| | | this.substringIndex.setIndexer(substringIndexer); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | if (cfg.getIndexType().contains(JEIndexCfgDefn.IndexType.ORDERING)) |
| | | if (cfg.getIndexType().contains(LocalDBIndexCfgDefn.IndexType.ORDERING)) |
| | | { |
| | | if(orderingIndex == null) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | if (cfg.getIndexType().contains(JEIndexCfgDefn.IndexType.APPROXIMATE)) |
| | | if (cfg.getIndexType().contains( |
| | | LocalDBIndexCfgDefn.IndexType.APPROXIMATE)) |
| | | { |
| | | if(approximateIndex == null) |
| | | { |
| | |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.append(entryContainer.getDatabasePrefix()); |
| | | builder.append("_"); |
| | | builder.append(indexConfig.getIndexAttribute().getNameOrOID()); |
| | | builder.append(indexConfig.getAttribute().getNameOrOID()); |
| | | return builder.toString(); |
| | | } |
| | | } |