Code cleanup
AttributeIndex.java:
Extracted method indexEntry()
Importer.java:
Extracted method indexEntry()
AppendReplaceTask:
- removed insertKeySet and deleteKeySet fields, superseded by ImportTask.insertKeySet field
ImportTask:
- renamed insertKeySet field to keySet
- in processIndexes(), merged AppendReplaceTask.processAllIndexes() + inlined fillIndexKey() and processAttribute()
- extracted method processAttribute0() out of processAttribute()
TestBackendImpl.java:
In assertIndexContainsID(), delegate to the other assertIndexContainsID() method.
AutoRefactor'ed file
| | |
| | | { |
| | | for (MatchingRuleIndex index : indexIdToIndexes.values()) |
| | | { |
| | | final Set<ByteString> keys = new HashSet<>(); |
| | | index.indexEntry(entry, keys); |
| | | for (ByteString key : keys) |
| | | for (ByteString key : indexEntry(index, entry)) |
| | | { |
| | | buffer.put(index, key, entryID); |
| | | } |
| | |
| | | { |
| | | for (MatchingRuleIndex index : indexIdToIndexes.values()) |
| | | { |
| | | HashSet<ByteString> keys = new HashSet<ByteString>(); |
| | | index.indexEntry(entry, keys); |
| | | for (ByteString key : keys) |
| | | for (ByteString key : indexEntry(index, entry)) |
| | | { |
| | | buffer.remove(index, key, entryID); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private Set<ByteString> indexEntry(MatchingRuleIndex index, Entry entry) |
| | | { |
| | | final Set<ByteString> keys = new HashSet<>(); |
| | | index.indexEntry(entry, keys); |
| | | return keys; |
| | | } |
| | | |
| | | /** |
| | | * Update the index to reflect a sequence of modifications in a Modify |
| | | * operation. |
| | |
| | | super(storage); |
| | | } |
| | | |
| | | private final Set<ByteString> insertKeySet = new HashSet<>(); |
| | | private final Set<ByteString> deleteKeySet = new HashSet<>(); |
| | | private Entry oldEntry; |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | suffix.getID2Entry().put(txn, entryID, entry); |
| | | if (oldEntry != null) |
| | | { |
| | | processAllIndexes(suffix, entry, entryID); |
| | | } |
| | | else |
| | | { |
| | | processIndexes(suffix, entry, entryID); |
| | | } |
| | | processIndexes(suffix, entry, entryID, oldEntry != null); |
| | | processVLVIndexes(txn, suffix, entry, entryID); |
| | | importCount.getAndIncrement(); |
| | | } |
| | | |
| | | void processAllIndexes(Suffix suffix, Entry entry, EntryID entryID) throws StorageRuntimeException, |
| | | InterruptedException |
| | | { |
| | | for (Map.Entry<AttributeType, AttributeIndex> mapEntry : suffix.getAttrIndexMap().entrySet()) |
| | | { |
| | | fillIndexKey(mapEntry.getValue(), entry, mapEntry.getKey(), entryID); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | void processAttribute(MatchingRuleIndex index, Entry entry, EntryID entryID, IndexKey indexKey) |
| | | throws StorageRuntimeException, InterruptedException |
| | | { |
| | | if (oldEntry != null) |
| | | { |
| | | deleteKeySet.clear(); |
| | | index.indexEntry(oldEntry, deleteKeySet); |
| | | for (ByteString delKey : deleteKeySet) |
| | | { |
| | | processKey(index, delKey, entryID, indexKey, false); |
| | | processAttribute0(index, oldEntry, entryID, indexKey, false); |
| | | } |
| | | } |
| | | insertKeySet.clear(); |
| | | index.indexEntry(entry, insertKeySet); |
| | | for (ByteString key : insertKeySet) |
| | | { |
| | | processKey(index, key, entryID, indexKey, true); |
| | | } |
| | | processAttribute0(index, entry, entryID, indexKey, true); |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | private final Storage storage; |
| | | private final Map<IndexKey, IndexOutputBuffer> indexBufferMap = new HashMap<>(); |
| | | private final Set<ByteString> insertKeySet = new HashSet<>(); |
| | | private final Set<ByteString> keySet = new HashSet<>(); |
| | | private final IndexKey dnIndexKey = new IndexKey(DN_TYPE, DN2ID_INDEX_NAME, 1); |
| | | |
| | | public ImportTask(final Storage storage) |
| | |
| | | suffix.removePending(entryDN); |
| | | processDN2ID(suffix, entryDN, entryID); |
| | | suffix.getDN2URI().addEntry(txn, entry); |
| | | processIndexes(suffix, entry, entryID); |
| | | processIndexes(suffix, entry, entryID, false); |
| | | processVLVIndexes(txn, suffix, entry, entryID); |
| | | suffix.getID2Entry().put(txn, entryID, entry); |
| | | importCount.getAndIncrement(); |
| | |
| | | return dnCache.insert(entryDN); |
| | | } |
| | | |
| | | void processIndexes(Suffix suffix, Entry entry, EntryID entryID) throws StorageRuntimeException, |
| | | InterruptedException |
| | | void processIndexes(Suffix suffix, Entry entry, EntryID entryID, boolean allIndexes) |
| | | throws StorageRuntimeException, InterruptedException |
| | | { |
| | | for (Map.Entry<AttributeType, AttributeIndex> mapEntry : suffix.getAttrIndexMap().entrySet()) |
| | | { |
| | | AttributeType attributeType = mapEntry.getKey(); |
| | | if (entry.hasAttribute(attributeType)) |
| | | AttributeType attrType = mapEntry.getKey(); |
| | | AttributeIndex attrIndex = mapEntry.getValue(); |
| | | if (allIndexes || entry.hasAttribute(attrType)) |
| | | { |
| | | fillIndexKey(mapEntry.getValue(), entry, attributeType, entryID); |
| | | } |
| | | } |
| | | } |
| | | for (Map.Entry<String, MatchingRuleIndex> mapEntry2 : attrIndex.getNameToIndexes().entrySet()) |
| | | { |
| | | String indexID = mapEntry2.getKey(); |
| | | MatchingRuleIndex index = mapEntry2.getValue(); |
| | | |
| | | void fillIndexKey(AttributeIndex attrIndex, Entry entry, AttributeType attrType, EntryID entryID) |
| | | throws InterruptedException, StorageRuntimeException |
| | | { |
| | | for (Map.Entry<String, MatchingRuleIndex> mapEntry : attrIndex.getNameToIndexes().entrySet()) |
| | | { |
| | | processAttribute(mapEntry.getValue(), mapEntry.getKey(), entry, attrType, entryID); |
| | | IndexKey indexKey = new IndexKey(attrType, indexID, index.getIndexEntryLimit()); |
| | | processAttribute(index, entry, entryID, indexKey); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | buffer.flush(txn); |
| | | } |
| | | |
| | | private void processAttribute(MatchingRuleIndex index, String indexID, Entry entry, |
| | | AttributeType attributeType, EntryID entryID) throws InterruptedException |
| | | { |
| | | if (index != null) |
| | | { |
| | | IndexKey indexKey = new IndexKey(attributeType, indexID, index.getIndexEntryLimit()); |
| | | processAttribute(index, entry, entryID, indexKey); |
| | | } |
| | | } |
| | | |
| | | void processAttribute(MatchingRuleIndex index, Entry entry, EntryID entryID, IndexKey indexKey) |
| | | throws StorageRuntimeException, InterruptedException |
| | | { |
| | | insertKeySet.clear(); |
| | | index.indexEntry(entry, insertKeySet); |
| | | for (ByteString key : insertKeySet) |
| | | processAttribute0(index, entry, entryID, indexKey, true); |
| | | } |
| | | |
| | | void processAttribute0(MatchingRuleIndex index, Entry entry, EntryID entryID, IndexKey indexKey, boolean insert) |
| | | throws InterruptedException |
| | | { |
| | | processKey(index, key, entryID, indexKey, true); |
| | | keySet.clear(); |
| | | index.indexEntry(entry, keySet); |
| | | |
| | | for (ByteString key : keySet) |
| | | { |
| | | processKey(index, key, entryID, indexKey, insert); |
| | | } |
| | | } |
| | | |
| | |
| | | getAll(futures); |
| | | } |
| | | |
| | | int processKey(Tree tree, ByteString key, EntryID entryID, IndexKey indexKey, boolean insert) |
| | | final int processKey(Tree tree, ByteString key, EntryID entryID, IndexKey indexKey, boolean insert) |
| | | throws InterruptedException |
| | | { |
| | | int sizeNeeded = IndexOutputBuffer.getRequiredSize(key.length(), entryID.longValue()); |
| | |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * BackendImpl Tester. |
| | | */ |
| | | /** BackendImpl Tester. */ |
| | | @SuppressWarnings("javadoc") |
| | | public class TestBackendImpl extends JebTestCase { |
| | | |
| | |
| | | */ |
| | | @Test |
| | | public void testAddNoParent() throws Exception { |
| | | |
| | | try |
| | | { |
| | | for (Entry entry : entries) { |
| | |
| | | } |
| | | failBecauseExceptionWasNotThrown(DirectoryException.class); |
| | | } |
| | | catch (DirectoryException e) |
| | | catch (DirectoryException expected) |
| | | { |
| | | // expected |
| | | } |
| | | |
| | | } |
| | | |
| | | @Test(dependsOnMethods = "testAddNoParent") |
| | |
| | | backend.getNumberOfEntriesInBaseDN(DN.valueOf("ou=People,dc=test,dc=com")); |
| | | } |
| | | |
| | | |
| | | @Test(dependsOnMethods = "testAdd") |
| | | public void testSearchIndex() throws Exception { |
| | | Set<String> attribs = new LinkedHashSet<String>(); |
| | | Set<String> attribs = new LinkedHashSet<>(); |
| | | String debugString; |
| | | List<SearchResultEntry> result; |
| | | |
| | |
| | | { |
| | | int finalStartPos = debugString.indexOf("final=") + 13; |
| | | int finalEndPos = debugString.indexOf("]", finalStartPos); |
| | | int finalCount = Integer.valueOf(debugString.substring(finalStartPos, finalEndPos)); |
| | | int finalCount = Integer.parseInt(debugString.substring(finalStartPos, finalEndPos)); |
| | | assertEquals(finalCount, expectedCount); |
| | | } |
| | | |
| | |
| | | @Test(dependsOnMethods = {"testAdd", "testSearchIndex", |
| | | "testSearchScope", "testMatchedDN"}) |
| | | public void testDeleteEntry() throws Exception { |
| | | List<Control> noControls = new ArrayList<Control>(0); |
| | | List<Control> noControls = new ArrayList<>(0); |
| | | EntryContainer ec = |
| | | backend.getRootContainer().getEntryContainer(DN.valueOf("ou=People,dc=test,dc=com")); |
| | | |
| | |
| | | DN.valueOf("uid=user.539,ou=People,dc=test,dc=com")); |
| | | backend.deleteEntry(DN.valueOf("uid=user.539,ou=People,dc=test,dc=com"), delete); |
| | | |
| | | |
| | | assertFalse(ec.entryExists(DN.valueOf("uid=user.539,ou=People,dc=test,dc=com"))); |
| | | assertNull(ec.getDN2ID().get(null, |
| | | DN.valueOf("uid=user.539,ou=People,dc=test,dc=com"), LockMode.DEFAULT)); |
| | |
| | | |
| | | private static List<AttributeIndexer> newAttributeIndexers(AttributeType attrType, MatchingRule matchingRule) |
| | | { |
| | | List<AttributeIndexer> indexers = new ArrayList<AttributeIndexer>(); |
| | | List<AttributeIndexer> indexers = new ArrayList<>(); |
| | | for (org.forgerock.opendj.ldap.spi.Indexer indexer : matchingRule.createIndexers(getOptions())) |
| | | { |
| | | indexers.add(new AttributeIndexer(attrType, indexer)); |
| | |
| | | |
| | | private static void assertIndexContainsID(List<? extends Indexer> indexers, Entry entry, Index index, EntryID entryID) |
| | | { |
| | | for (Indexer indexer : indexers) |
| | | { |
| | | Set<ByteString> addKeys = new HashSet<ByteString>(); |
| | | indexer.indexEntry(entry, addKeys); |
| | | |
| | | DatabaseEntry key = new DatabaseEntry(); |
| | | for (ByteString keyBytes : addKeys) |
| | | { |
| | | key.setData(keyBytes.toByteArray()); |
| | | assertEquals(index.containsID(null, key, entryID), TRUE); |
| | | } |
| | | } |
| | | assertIndexContainsID(indexers, entry, index, entryID, TRUE); |
| | | } |
| | | |
| | | private static void assertIndexContainsID(List<? extends Indexer> indexers, Entry entry, Index index, |
| | |
| | | { |
| | | for (Indexer indexer : indexers) |
| | | { |
| | | Set<ByteString> addKeys = new HashSet<ByteString>(); |
| | | Set<ByteString> addKeys = new HashSet<>(); |
| | | indexer.indexEntry(entry, addKeys); |
| | | |
| | | assertIndexContainsID(addKeys, index, entryID, expected); |
| | |
| | | ec.sharedLock.lock(); |
| | | try |
| | | { |
| | | List<Modification> modifications = new ArrayList<Modification>(); |
| | | List<Modification> modifications = new ArrayList<>(); |
| | | modifications.add(new Modification(ADD, create("title", "debugger"))); |
| | | |
| | | AttributeBuilder builder = new AttributeBuilder("title"); |
| | |
| | | nameIndex = ec.getAttributeIndex(name); |
| | | |
| | | // This current entry in the DB shouldn't be in the presence titleIndex. |
| | | addKeys = new HashSet<ByteString>(); |
| | | addKeys = new HashSet<>(); |
| | | addKeys.add(PresenceIndexer.presenceKey); |
| | | assertIndexContainsID(addKeys, titleIndex.getIndex("presence"), entryID, FALSE); |
| | | |
| | | // This current entry should be in the presence nameIndex. |
| | | addKeys = new HashSet<ByteString>(); |
| | | addKeys = new HashSet<>(); |
| | | addKeys.add(PresenceIndexer.presenceKey); |
| | | assertIndexContainsID(addKeys, nameIndex.getIndex("presence"), entryID, TRUE); |
| | | |
| | | List<Control> noControls = new ArrayList<Control>(0); |
| | | List<Control> noControls = new ArrayList<>(0); |
| | | ModifyOperationBasis modifyOp = new ModifyOperationBasis(getRootConnection(), nextOperationID(), nextMessageID(), |
| | | noControls, DN.valueOf("uid=user.1,ou=People,dc=test,dc=com"), modifications); |
| | | |
| | |
| | | DN.valueOf("ou=People,dc=test,dc=com"), LockMode.DEFAULT); |
| | | assertTrue(newSuperiorID.compareTo(oldID) > 0); |
| | | |
| | | List<Control> noControls = new ArrayList<Control>(0); |
| | | List<Control> noControls = new ArrayList<>(0); |
| | | ModifyDNOperationBasis modifyDN = new ModifyDNOperationBasis( |
| | | getRootConnection(), nextOperationID(), nextMessageID(), |
| | | noControls, |
| | |
| | | assertEquals(backend.getNumberOfChildren(dn), -1); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Provides a set of DNs for the matched DN test case. |
| | | * |
| | |
| | | */ |
| | | @DataProvider(name = "MatchedDNs") |
| | | public Object[][] initMatchedDNs() throws Exception { |
| | | |
| | | ResultCode success = ResultCode.SUCCESS; |
| | | ResultCode noSuchObject = ResultCode.NO_SUCH_OBJECT; |
| | | |
| | |
| | | }; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Executes an internal search operation and check the result code and |
| | | * matched DN field. |
| | |
| | | private static String substringIndexId() { |
| | | return SMR_CASE_IGNORE_NAME + ":" + getOptions().substringKeySize(); |
| | | } |
| | | |
| | | } |