opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/EntryContainer.java
@@ -607,15 +607,6 @@ } /** * Return attribute index map. * * @return The attribute index map. */ public Map<AttributeType, AttributeIndex> getAttributeIndexMap() { return attrIndexMap; } /** * Look for an VLV index for the given index name. * * @param vlvIndexName The vlv index name for which an vlv index is needed. opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/Importer.java
@@ -246,7 +246,7 @@ /** Map of container ids to database containers. */ private final ConcurrentHashMap<Integer, Index> idContainerMap = new ConcurrentHashMap<>(); /** Map of container ids to entry containers. */ private final ConcurrentHashMap<Integer, EntryContainer> idECMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Integer, Suffix> idSuffixMap = new ConcurrentHashMap<>(); /** Used to synchronize when a scratch file index writer is first setup. */ private final Object synObj = new Object(); @@ -670,7 +670,6 @@ if (suffix != null) { dnSuffixMap.put(ec.getBaseDN(), suffix); generateIndexID(suffix); } } } @@ -681,7 +680,7 @@ */ private void generateIndexID(Suffix suffix) { for (AttributeIndex attributeIndex : suffix.getAttrIndexMap().values()) for (AttributeIndex attributeIndex : suffix.getAttributeIndexes()) { for(Index index : attributeIndex.getAllIndexes()) { putInIdContainerMap(index); @@ -904,7 +903,7 @@ logger.info(NOTE_IMPORT_STARTING, DirectoryServer.getVersionString(), BUILD_ID, REVISION_NUMBER); logger.info(NOTE_IMPORT_THREAD_COUNT, threadCount); initializeSuffixes(); setIndexesTrusted(false); setupIndexesForImport(); final long startTime = System.currentTimeMillis(); phaseOne(); @@ -928,7 +927,7 @@ } final long phaseTwoFinishTime = System.currentTimeMillis(); setIndexesTrusted(true); setIndexesTrusted(); switchEntryContainers(); recursiveDelete(tempDir); final long finishTime = System.currentTimeMillis(); @@ -1011,13 +1010,13 @@ } } private void setIndexesTrusted(boolean trusted) throws JebException private void setIndexesTrusted() throws JebException { try { for (Suffix s : dnSuffixMap.values()) { s.setIndexesTrusted(trusted); s.setIndexesTrusted(); } } catch (DatabaseException ex) @@ -1026,6 +1025,15 @@ } } private void setupIndexesForImport() { for (Suffix s : dnSuffixMap.values()) { s.setIndexesNotTrusted(importConfiguration.appendToExistingData()); generateIndexID(s); } } private void phaseOne() throws InterruptedException, ExecutionException { initializeIndexBuffers(); @@ -1459,10 +1467,9 @@ void processAllIndexes(Suffix suffix, Entry entry, EntryID entryID) throws DatabaseException, DirectoryException, JebException, InterruptedException { for (Map.Entry<AttributeType, AttributeIndex> mapEntry : suffix.getAttrIndexMap().entrySet()) for (AttributeIndex attrIndex : suffix.getAttributeIndexes()) { AttributeType attributeType = mapEntry.getKey(); fillIndexKey(suffix, mapEntry.getValue(), entry, attributeType, entryID); fillIndexKey(suffix, attrIndex, entry, attrIndex.getAttributeType(), entryID); } } @@ -1585,12 +1592,12 @@ void processIndexes(Suffix suffix, Entry entry, EntryID entryID) throws DatabaseException, DirectoryException, JebException, InterruptedException { for (Map.Entry<AttributeType, AttributeIndex> mapEntry : suffix.getAttrIndexMap().entrySet()) for (AttributeIndex attrIndex : suffix.getAttributeIndexes()) { AttributeType attributeType = mapEntry.getKey(); AttributeType attributeType = attrIndex.getAttributeType(); if (entry.hasAttribute(attributeType)) { fillIndexKey(suffix, mapEntry.getValue(), entry, attributeType, entryID); fillIndexKey(suffix, attrIndex, entry, attributeType, entryID); } } } @@ -1712,7 +1719,7 @@ DN2ID dn2id = suffix.getDN2ID(); byte[] dnBytes = JebFormat.dnToDNKey(dn, suffix.getBaseDN().size()); int id = processKey(dn2id, dnBytes, entryID, dnIndexKey, true); idECMap.putIfAbsent(id, suffix.getEntryContainer()); idSuffixMap.putIfAbsent(id, suffix); } void processDN2URI(Suffix suffix, Entry oldEntry, Entry newEntry) throws DatabaseException @@ -2074,7 +2081,7 @@ DNState dnState; if (!dnStateMap.containsKey(indexID)) { dnState = new DNState(idECMap.get(indexID)); dnState = new DNState(idSuffixMap.get(indexID)); dnStateMap.put(indexID, dnState); } else @@ -2107,25 +2114,32 @@ private final EntryContainer entryContainer; private final boolean isSubordinatesEnabled; // Fields below are only needed if the isSubordinatesEnabled boolean is true. private final Map<byte[], ImportIDSet> id2childTree; private final Map<byte[], ImportIDSet> id2subtreeTree; private final int childLimit, subTreeLimit; private final boolean childDoCount, subTreeDoCount; private Map<byte[], ImportIDSet> id2childTree; private Map<byte[], ImportIDSet> id2subtreeTree; private int childLimit, subTreeLimit; private boolean childDoCount, subTreeDoCount; private boolean updateID2Children, updateID2Subtree; DNState(EntryContainer entryContainer) DNState(Suffix suffix) { this.entryContainer = entryContainer; this.entryContainer = suffix.getEntryContainer(); parentIDMap = new TreeMap<>(); isSubordinatesEnabled = backendConfiguration.isSubordinateIndexesEnabled(); Comparator<byte[]> childComparator = entryContainer.getID2Children().getComparator(); id2childTree = new TreeMap<>(childComparator); childLimit = entryContainer.getID2Children().getIndexEntryLimit(); childDoCount = isSubordinatesEnabled && entryContainer.getID2Children().getMaintainCount(); Comparator<byte[]> subComparator = entryContainer.getID2Subtree().getComparator(); subTreeLimit = entryContainer.getID2Subtree().getIndexEntryLimit(); subTreeDoCount = isSubordinatesEnabled && entryContainer.getID2Subtree().getMaintainCount(); id2subtreeTree = new TreeMap<>(subComparator); if (suffix.isProcessID2Children()) { childLimit = entryContainer.getID2Children().getIndexEntryLimit(); childDoCount = isSubordinatesEnabled && entryContainer.getID2Children().getMaintainCount(); id2childTree = new TreeMap<>(entryContainer.getID2Children().getComparator()); updateID2Children = true; } if (suffix.isProcessID2Subtree()) { subTreeLimit = entryContainer.getID2Subtree().getIndexEntryLimit(); subTreeDoCount = isSubordinatesEnabled && entryContainer.getID2Subtree().getMaintainCount(); id2subtreeTree = new TreeMap<>(entryContainer.getID2Subtree().getComparator()); updateID2Subtree = true; } dnKey = new DatabaseEntry(); dnValue = new DatabaseEntry(); lastDN = ByteBuffer.allocate(BYTE_BUFFER_CAPACITY); @@ -2343,8 +2357,14 @@ indexMgr.addTotDNCount(1); if (isSubordinatesEnabled && parentDN != null) { id2child(entryID); id2SubTree(entryID); if (updateID2Children) { id2child(entryID); } if (updateID2Subtree) { id2SubTree(entryID); } } } @@ -2366,9 +2386,16 @@ public void flush() { if (isSubordinatesEnabled) { flushMapToDB(id2childTree, entryContainer.getID2Children(), false); flushMapToDB(id2subtreeTree, entryContainer.getID2Subtree(), false); if (isSubordinatesEnabled) { if (updateID2Children) { flushMapToDB(id2childTree, entryContainer.getID2Children(), false); } if (updateID2Subtree) { flushMapToDB(id2subtreeTree, entryContainer.getID2Subtree(), false); } } } } @@ -3105,10 +3132,9 @@ { // rebuildList contains the user-selected index(in USER_DEFINED mode). final List<String> rebuildList = rebuildConfig.getRebuildList(); for (final Map.Entry<AttributeType, AttributeIndex> mapEntry : suffix.getAttrIndexMap().entrySet()) for (AttributeIndex attributeIndex : entryContainer.getAttributeIndexes()) { final AttributeType attributeType = mapEntry.getKey(); final AttributeIndex attributeIndex = mapEntry.getValue(); final AttributeType attributeType = attributeIndex.getAttributeType(); if (rebuildConfig.getRebuildMode() == RebuildMode.ALL || rebuildConfig.getRebuildMode() == RebuildMode.DEGRADED) { @@ -3204,9 +3230,7 @@ { if (reBuildDN2ID) { EntryContainer ec = suffix.getEntryContainer(); ec.getID2Children().setTrusted(null, trusted); ec.getID2Subtree().setTrusted(null, trusted); suffix.forceTrustedDN2IDRelated(trusted); } setTrusted(indexMap.values(), trusted); if (!vlvIndexes.isEmpty()) opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/Suffix.java
@@ -34,7 +34,6 @@ import org.forgerock.i18n.slf4j.LocalizedLogger; import org.opends.server.backends.jeb.Importer.DNCache; import org.opends.server.types.AttributeType; import org.opends.server.types.DN; import com.sleepycat.je.DatabaseException; @@ -59,6 +58,9 @@ private static final int PARENT_ID_SET_SIZE = 16 * 1024; private final ConcurrentHashMap<DN, CountDownLatch> pendingMap = new ConcurrentHashMap<>(); private final Set<DN> parentSet = new HashSet<>(PARENT_ID_SET_SIZE); private final List<AttributeIndex> attributeIndexes = new ArrayList<>(); private final List<VLVIndex> vlvIndexes = new ArrayList<>(); private boolean processID2Children, processID2Subtree; /** * Creates a suffix instance using the specified parameters. @@ -139,16 +141,25 @@ /** * Return the Attribute Type - Index map used to map an attribute type to an * index instance. * Returns a map associating the attribute types with their corresponding attribute indexes. * The map contains only trusted indexes. * * @return A suffixes Attribute Type - Index map. * @return a map associating the attribute types with their corresponding trusted attribute indexes. */ public Map<AttributeType, AttributeIndex> getAttrIndexMap() public List<AttributeIndex> getAttributeIndexes() { return entryContainer.getAttributeIndexMap(); return attributeIndexes; } /** * Returns the list of trusted VLV indexes. * * @return the list of trusted VLV indexes. */ public List<VLVIndex> getVLVIndexes() { return vlvIndexes; } /** * Make sure the specified parent DN is not in the pending map. @@ -248,38 +259,114 @@ } final boolean isProcessID2Children() { return processID2Children; } final boolean isProcessID2Subtree() { return processID2Subtree; } /** * Sets the trusted status of all of the indexes, vlvIndexes, id2children * and id2subtree indexes. * * @param trusted True if the indexes should be trusted or false * otherwise. * * @throws DatabaseException If an error occurred setting the indexes to * trusted. */ public void setIndexesTrusted(boolean trusted) throws DatabaseException public void setIndexesTrusted() throws DatabaseException { entryContainer.getID2Children().setTrusted(null,trusted); entryContainer.getID2Subtree().setTrusted(null, trusted); for (AttributeIndex attributeIndex : entryContainer.getAttributeIndexes()) if (processID2Children) { for (Index index : attributeIndex.getAllIndexes()) { setTrusted(index, trusted); } entryContainer.getID2Children().setTrusted(null, true); } for (VLVIndex vlvIdx : entryContainer.getVLVIndexes()) if (processID2Subtree) { vlvIdx.setTrusted(null, trusted); entryContainer.getID2Subtree().setTrusted(null, true); } for (AttributeIndex attrIndex : attributeIndexes) { setTrusted(attrIndex, true); } for (VLVIndex vlvIdx : vlvIndexes) { vlvIdx.setTrusted(null, true); } } private void setTrusted(Index index, boolean trusted) /** * Build the lists of indexes to process and set their status as not trusted. * ID2Children and ID2Subtree are also considered, albeit as special cases. * * @param onlyDegraded * true if currently untrusted indexes should be processed as well. * @throws DatabaseException * If an error occurred setting the indexes to trusted. */ public void setIndexesNotTrusted(boolean onlyDegraded) throws DatabaseException { if (index != null) setNotTrustedDN2IDRelatedIndexes(onlyDegraded); for (AttributeIndex attributeIndex : entryContainer.getAttributeIndexes()) { index.setTrusted(null, trusted); if (!onlyDegraded || attributeIndex.isTrusted()) { attributeIndexes.add(attributeIndex); setTrusted(attributeIndex, false); } } for (VLVIndex vlvIndex : entryContainer.getVLVIndexes()) { if (!onlyDegraded || vlvIndex.isTrusted()) { vlvIndex.setTrusted(null, false); vlvIndexes.add(vlvIndex); } } } private void setNotTrustedDN2IDRelatedIndexes(boolean onlyDegraded) { if (setNotTrustedDN2IDRelated(entryContainer.getID2Children(), onlyDegraded)) { processID2Children = true; } if (setNotTrustedDN2IDRelated(entryContainer.getID2Subtree(), onlyDegraded)) { processID2Subtree = true; } } private boolean setNotTrustedDN2IDRelated(Index auxIndex, boolean onlyDegraded) { if (!onlyDegraded || auxIndex.isTrusted()) { auxIndex.setTrusted(null, false); return true; } return false; } private void setTrusted(AttributeIndex attrIndex, boolean trusted) { for (Index index : attrIndex.getAllIndexes()) { if (index != null) { index.setTrusted(null, trusted); } } } void forceTrustedDN2IDRelated(boolean trusted) { entryContainer.getID2Children().setTrusted(null, trusted); entryContainer.getID2Subtree().setTrusted(null, trusted); if (!trusted) { processID2Subtree = true; processID2Children = true; } } opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
@@ -603,16 +603,6 @@ } /** * Return attribute index map. * * @return The attribute index map. */ Map<AttributeType, AttributeIndex> getAttributeIndexMap() { return attrIndexMap; } /** * Look for an VLV index for the given index name. * * @param vlvIndexName The vlv index name for which an vlv index is needed. opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeBufferImporter.java
@@ -600,14 +600,13 @@ if (suffix != null) { dnSuffixMap.put(ec.getBaseDN(), suffix); generateIndexIDs(suffix); } } } private void generateIndexIDs(Suffix suffix) { for (AttributeIndex attributeIndex : suffix.getAttrIndexMap().values()) for (AttributeIndex attributeIndex : suffix.getAttributeIndexes()) { for (Index index : attributeIndex.getNameToIndexes().values()) { @@ -774,7 +773,7 @@ public void run(WriteableTransaction txn) throws Exception { initializeSuffixes(txn); setIndexesTrusted(txn, false); setupIndexesForImport(txn); } }); @@ -804,7 +803,7 @@ @Override public void run(WriteableTransaction txn) throws Exception { setIndexesTrusted(txn, true); setIndexesTrusted(txn); switchEntryContainers(txn); } }); @@ -859,18 +858,34 @@ } } private void setIndexesTrusted(WriteableTransaction txn, boolean trusted) throws StorageRuntimeException private void setIndexesTrusted(WriteableTransaction txn) throws StorageRuntimeException { try { for (Suffix s : dnSuffixMap.values()) { s.setIndexesTrusted(txn, trusted); s.setIndexesTrusted(txn); } } catch (StorageRuntimeException ex) { throw new StorageRuntimeException(NOTE_IMPORT_LDIF_TRUSTED_FAILED.get(ex.getMessage()).toString()); throw new StorageRuntimeException(NOTE_IMPORT_LDIF_TRUSTED_FAILED.get(ex.getMessage()).toString(), ex); } } private void setupIndexesForImport(WriteableTransaction txn) throws StorageRuntimeException { try { for (Suffix s : dnSuffixMap.values()) { s.setIndexesNotTrusted(txn, importCfg.appendToExistingData()); generateIndexIDs(s); } } catch (StorageRuntimeException ex) { throw new StorageRuntimeException(NOTE_IMPORT_LDIF_NOT_TRUSTED_FAILED.get(ex.getMessage()).toString(), ex); } } @@ -897,8 +912,7 @@ execService.submit(new MigrateExistingTask(storage)).get(); final List<Callable<Void>> tasks = new ArrayList<>(threadCount); if (importCfg.appendToExistingData() && importCfg.replaceExistingEntries()) if (importCfg.appendToExistingData() && importCfg.replaceExistingEntries()) { for (int i = 0; i < threadCount; i++) { @@ -1400,10 +1414,9 @@ void processIndexes(Suffix suffix, Entry entry, EntryID entryID, boolean allIndexes) throws StorageRuntimeException, InterruptedException { for (Map.Entry<AttributeType, AttributeIndex> mapEntry : suffix.getAttrIndexMap().entrySet()) for (AttributeIndex attrIndex : suffix.getAttributeIndexes()) { AttributeType attrType = mapEntry.getKey(); AttributeIndex attrIndex = mapEntry.getValue(); AttributeType attrType = attrIndex.getAttributeType(); if (allIndexes || entry.hasAttribute(attrType)) { for (Map.Entry<String, MatchingRuleIndex> mapEntry2 : attrIndex.getNameToIndexes().entrySet()) @@ -1421,9 +1434,8 @@ void processVLVIndexes(WriteableTransaction txn, Suffix suffix, Entry entry, EntryID entryID) throws DirectoryException { final EntryContainer entryContainer = suffix.getEntryContainer(); final IndexBuffer buffer = new IndexBuffer(entryContainer); for (VLVIndex vlvIdx : entryContainer.getVLVIndexes()) final IndexBuffer buffer = new IndexBuffer(suffix.getEntryContainer()); for (VLVIndex vlvIdx : suffix.getVLVIndexes()) { vlvIdx.addEntry(buffer, entryID, entry); } @@ -2619,10 +2631,9 @@ private void rebuildIndexMap(WriteableTransaction txn, boolean onlyDegraded) { for (final Map.Entry<AttributeType, AttributeIndex> mapEntry : suffix.getAttrIndexMap().entrySet()) for (AttributeIndex attributeIndex : entryContainer.getAttributeIndexes()) { final AttributeType attributeType = mapEntry.getKey(); final AttributeIndex attributeIndex = mapEntry.getValue(); final AttributeType attributeType = attributeIndex.getAttributeType(); if (mustRebuild(attributeType)) { rebuildAttributeIndexes(txn, attributeIndex, attributeType, onlyDegraded); @@ -2959,7 +2970,7 @@ throws StorageRuntimeException, DirectoryException { final IndexBuffer buffer = new IndexBuffer(entryContainer); for (VLVIndex vlvIdx : suffix.getEntryContainer().getVLVIndexes()) for (VLVIndex vlvIdx : suffix.getVLVIndexes()) { vlvIdx.addEntry(buffer, entryID, entry); } opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeStorageImporter.java
@@ -1557,7 +1557,14 @@ { for (Suffix s : dnSuffixMap.values()) { s.setIndexesTrusted(txn, trusted); if (trusted) { s.setIndexesTrusted(txn); } else { s.setIndexesNotTrusted(txn, importCfg.appendToExistingData()); } } } catch (StorageRuntimeException ex) @@ -2208,10 +2215,9 @@ void processIndexes(Suffix suffix, Entry entry, EntryID entryID) throws StorageRuntimeException, InterruptedException { for (Map.Entry<AttributeType, AttributeIndex> mapEntry : suffix.getAttrIndexMap().entrySet()) for (AttributeIndex attrIndex : suffix.getAttributeIndexes()) { final AttributeType attrType = mapEntry.getKey(); final AttributeIndex attrIndex = mapEntry.getValue(); final AttributeType attrType = attrIndex.getAttributeType(); if (entry.hasAttribute(attrType)) { for (MatchingRuleIndex index : attrIndex.getNameToIndexes().values()) opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Suffix.java
@@ -37,7 +37,6 @@ import org.opends.server.backends.pluggable.OnDiskMergeBufferImporter.DNCache; import org.opends.server.backends.pluggable.spi.StorageRuntimeException; import org.opends.server.backends.pluggable.spi.WriteableTransaction; import org.opends.server.types.AttributeType; import org.opends.server.types.DN; /** @@ -71,6 +70,8 @@ private static final int PARENT_ID_SET_SIZE = 16 * 1024; private final ConcurrentHashMap<DN, CountDownLatch> pendingMap = new ConcurrentHashMap<>(); private final Set<DN> parentSet = new HashSet<>(PARENT_ID_SET_SIZE); private final List<AttributeIndex> attributeIndexes = new ArrayList<>(); private final List<VLVIndex> vlvIndexes = new ArrayList<>(); Suffix(EntryContainer entryContainer) { @@ -155,9 +156,14 @@ * * @return A suffixes Attribute Type - Index map. */ Map<AttributeType, AttributeIndex> getAttrIndexMap() List<AttributeIndex> getAttributeIndexes() { return entryContainer.getAttributeIndexMap(); return attributeIndexes; } List<VLVIndex> getVLVIndexes() { return vlvIndexes; } /** @@ -246,21 +252,44 @@ } /** * Sets the trusted status of all of the indexes and vlvIndexes. * Builds the lists of Attribute and VLV indexes to process, setting their status as not trusted. * * @param txn a non null transaction * @param trusted True if the indexes should be trusted or false otherwise. * @throws StorageRuntimeException If an error occurred setting the indexes to trusted. * @param txn * a non null transaction * @param OnlyCurrentlyTrusted * true if currently untrusted indexes should be processed as well. * @throws StorageRuntimeException * If an error occurred setting the indexes to trusted. */ void setIndexesTrusted(WriteableTransaction txn, boolean trusted) throws StorageRuntimeException void setIndexesNotTrusted(WriteableTransaction txn, boolean onlyCurrentlyTrusted) throws StorageRuntimeException { for (AttributeIndex attributeIndex : entryContainer.getAttributeIndexes()) for (AttributeIndex attrIndex : entryContainer.getAttributeIndexes()) { setTrusted(txn, attributeIndex.getNameToIndexes().values(), trusted); if (!onlyCurrentlyTrusted || attrIndex.isTrusted()) { setTrusted(txn, attrIndex.getNameToIndexes().values(), false); attributeIndexes.add(attrIndex); } } for (VLVIndex vlvIdx : entryContainer.getVLVIndexes()) for (VLVIndex vlvIndex : entryContainer.getVLVIndexes()) { vlvIdx.setTrusted(txn, trusted); if (!onlyCurrentlyTrusted || vlvIndex.isTrusted()) { vlvIndex.setTrusted(txn, false); vlvIndexes.add(vlvIndex); } } } void setIndexesTrusted(WriteableTransaction txn) throws StorageRuntimeException { for (AttributeIndex attrIndex : attributeIndexes) { setTrusted(txn, attrIndex.getNameToIndexes().values(), true); } for (VLVIndex vlvIdx : vlvIndexes) { vlvIdx.setTrusted(txn, true); } } opendj-server-legacy/src/messages/org/opends/messages/backend.properties
@@ -1338,4 +1338,6 @@ verification process can start ERR_IMPORT_UNSUPPORTED_WITH_BRANCH_580=Import operation is not supported \ when exclude or include sub-branches have been specified ERR_IMPORT_UNKNOWN_SUFFIX_COMMAND_STRATEGY_581=Unknown suffix strategy while importing suffix "%s" ERR_IMPORT_UNKNOWN_SUFFIX_COMMAND_STRATEGY_581=Unknown suffix strategy while importing suffix "%s" NOTE_IMPORT_LDIF_NOT_TRUSTED_FAILED_582= Setting indexes to not trusted failed \ for the following reason: %s