Code cleanup
IndexOutputBuffer.java:
Removed comparator field + setter, directly used Importer.indexComparator instead.
VerifyJob.java, jeb.DBTest.java:
Consequence of the changes to Index.
Index.java:
Made indexer field private + added indexEntry() as a consequence.
Removed comparator and bsComparator fields (jeb only).
Importer.java:
Consequence of the changes to Index and IndexOutputBuffer.
| | |
| | | if (oldEntry != null) |
| | | { |
| | | deleteKeySet.clear(); |
| | | index.indexer.indexEntry(oldEntry, deleteKeySet, options); |
| | | index.indexEntry(oldEntry, deleteKeySet, options); |
| | | for (ByteString delKey : deleteKeySet) |
| | | { |
| | | processKey(index, delKey.toByteArray(), entryID, indexComparator, indexKey, false); |
| | | processKey(index, delKey.toByteArray(), entryID, indexKey, false); |
| | | } |
| | | } |
| | | insertKeySet.clear(); |
| | | index.indexer.indexEntry(entry, insertKeySet, options); |
| | | index.indexEntry(entry, insertKeySet, options); |
| | | for (ByteString key : insertKeySet) |
| | | { |
| | | processKey(index, key.toByteArray(), entryID, indexComparator, indexKey, true); |
| | | processKey(index, key.toByteArray(), entryID, indexKey, true); |
| | | } |
| | | } |
| | | } |
| | |
| | | IndexKey indexKey) throws DatabaseException, InterruptedException |
| | | { |
| | | insertKeySet.clear(); |
| | | index.indexer.indexEntry(entry, insertKeySet, options); |
| | | index.indexEntry(entry, insertKeySet, options); |
| | | for (ByteString key : insertKeySet) |
| | | { |
| | | processKey(index, key.toByteArray(), entryID, indexComparator, indexKey, true); |
| | | processKey(index, key.toByteArray(), entryID, indexKey, true); |
| | | } |
| | | } |
| | | |
| | |
| | | IndexKey indexKey = e.getKey(); |
| | | IndexOutputBuffer indexBuffer = e.getValue(); |
| | | it.remove(); |
| | | indexBuffer.setComparator(indexComparator); |
| | | indexBuffer.setIndexKey(indexKey); |
| | | indexBuffer.discard(); |
| | | futures.add(bufferSortService.submit(new SortTask(indexBuffer))); |
| | |
| | | } |
| | | |
| | | int processKey(DatabaseContainer container, byte[] key, EntryID entryID, |
| | | IndexOutputBuffer.ComparatorBuffer<byte[]> comparator, |
| | | IndexKey indexKey, boolean insert) throws InterruptedException |
| | | { |
| | | int sizeNeeded = IndexOutputBuffer.getRequiredSize(key.length, entryID.longValue()); |
| | |
| | | else if (!indexBuffer.isSpaceAvailable(key, entryID.longValue())) |
| | | { |
| | | // complete the current buffer... |
| | | indexBuffer.setComparator(comparator); |
| | | indexBuffer.setIndexKey(indexKey); |
| | | bufferSortService.submit(new SortTask(indexBuffer)); |
| | | // ... and get a new one |
| | |
| | | return indexBuffer; |
| | | } |
| | | |
| | | void processDN2ID(Suffix suffix, DN dn, EntryID entryID) |
| | | throws InterruptedException |
| | | void processDN2ID(Suffix suffix, DN dn, EntryID entryID) throws InterruptedException |
| | | { |
| | | DN2ID dn2id = suffix.getDN2ID(); |
| | | byte[] dnBytes = JebFormat.dnToDNKey(dn, suffix.getBaseDN().size()); |
| | | int id = processKey(dn2id, dnBytes, entryID, indexComparator, dnIndexKey, true); |
| | | int id = processKey(dn2id, dnBytes, entryID, dnIndexKey, true); |
| | | idECMap.putIfAbsent(id, suffix.getEntryContainer()); |
| | | } |
| | | |
| | | void processDN2URI(Suffix suffix, Entry oldEntry, Entry newEntry) |
| | | throws DatabaseException |
| | | void processDN2URI(Suffix suffix, Entry oldEntry, Entry newEntry) throws DatabaseException |
| | | { |
| | | DN2URI dn2uri = suffix.getDN2URI(); |
| | | if (oldEntry != null) |
| | |
| | | import java.util.*; |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.spi.IndexingOptions; |
| | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** The indexer object to construct index keys from LDAP attribute values. */ |
| | | public Indexer indexer; |
| | | |
| | | /** The comparator for index keys. */ |
| | | private final Comparator<byte[]> comparator; |
| | | /** The comparator for index keys. */ |
| | | private final Comparator<ByteSequence> bsComparator; |
| | | private Indexer indexer; |
| | | |
| | | /** The limit on the number of entry IDs that may be indexed by one key. */ |
| | | private int indexEntryLimit; |
| | |
| | | { |
| | | super(name, env, entryContainer); |
| | | this.indexer = indexer; |
| | | this.comparator = indexer.getComparator(); |
| | | this.bsComparator = indexer.getBSComparator(); |
| | | this.indexEntryLimit = indexEntryLimit; |
| | | this.cursorEntryLimit = cursorEntryLimit; |
| | | this.maintainCount = maintainCount; |
| | |
| | | this.dbConfig = JEBUtils.toDatabaseConfigNoDuplicates(env); |
| | | this.dbConfig.setOverrideBtreeComparator(true); |
| | | this.dbConfig.setBtreeComparator((Class<? extends Comparator<byte[]>>) |
| | | comparator.getClass()); |
| | | indexer.getComparator().getClass()); |
| | | |
| | | this.state = state; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | void indexEntry(Entry entry, Set<ByteString> keys, IndexingOptions options) |
| | | { |
| | | indexer.indexEntry(entry, keys, options); |
| | | } |
| | | |
| | | /** |
| | | * Add an add entry ID operation into a index buffer. |
| | | * |
| | |
| | | |
| | | private BufferedIndexValues getBufferedIndexValues(IndexBuffer buffer, ByteString keyBytes) |
| | | { |
| | | return buffer.getBufferedIndexValues(this, keyBytes, bsComparator); |
| | | return buffer.getBufferedIndexValues(this, keyBytes, indexer.getBSComparator()); |
| | | } |
| | | |
| | | /** |
| | |
| | | Cursor cursor = openCursor(null, CursorConfig.READ_COMMITTED); |
| | | try |
| | | { |
| | | final Comparator<byte[]> comparator = indexer.getComparator(); |
| | | OperationStatus status; |
| | | // Set the lower bound if necessary. |
| | | if(lower.length > 0) |
| | |
| | | */ |
| | | public Comparator<byte[]> getComparator() |
| | | { |
| | | return this.comparator; |
| | | return indexer.getComparator(); |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.opends.server.backends.jeb; |
| | | |
| | | import static org.opends.server.backends.jeb.Importer.indexComparator; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.DataOutputStream; |
| | | import java.io.IOException; |
| | |
| | | /** Used to iterate over the buffer when writing to a scratch file. */ |
| | | private int position; |
| | | |
| | | /** The comparator to use sort the keys. */ |
| | | private ComparatorBuffer<byte[]> comparator; |
| | | |
| | | /** |
| | | * Used to make sure that an instance of this class is put on the |
| | | * correct scratch file writer work queue for processing. |
| | |
| | | recordOffset = size - 1; |
| | | keys = 0; |
| | | position = 0; |
| | | comparator = null; |
| | | indexKey = null; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * Set the comparator to be used in the buffer processing to the specified |
| | | * comparator. |
| | | * |
| | | * @param comparator The comparator to set the buffer's comparator to. |
| | | */ |
| | | public void setComparator(ComparatorBuffer<byte[]> comparator) |
| | | { |
| | | this.comparator = comparator; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return a buffer's current position value. |
| | | * |
| | | * @return The buffer's current position value. |
| | |
| | | return position; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Set a buffer's position value to the specified position. |
| | | * |
| | |
| | | this.position = position; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Sort the buffer. |
| | | */ |
| | |
| | | sort(0, keys); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Add the specified key byte array and EntryID to the buffer. |
| | | * |
| | |
| | | int yKeyLen = PackedInteger.readInt(buffer, yoffSet); |
| | | int yKey = PackedInteger.getReadIntLength(buffer, yoffSet) + yoffSet; |
| | | |
| | | int cmp = comparator.compare(buffer, xKey, xKeyLen, xIndexID, yKey, yKeyLen, yIndexID); |
| | | int cmp = indexComparator.compare(buffer, xKey, xKeyLen, xIndexID, yKey, yKeyLen, yIndexID); |
| | | return evaluateReturnCode(cmp, op); |
| | | } |
| | | |
| | |
| | | int xKeyLen = PackedInteger.readInt(buffer, xoffSet); |
| | | int xKey = PackedInteger.getReadIntLength(buffer, xoffSet) + xoffSet; |
| | | |
| | | int cmp = comparator.compare(buffer, xKey, xKeyLen, xIndexID, yKey, yKey.length, yIndexID); |
| | | int cmp = indexComparator.compare(buffer, xKey, xKeyLen, xIndexID, yKey, yKey.length, yIndexID); |
| | | return evaluateReturnCode(cmp, op); |
| | | } |
| | | |
| | |
| | | offset += PackedInteger.getReadLongLength(buffer, offset); |
| | | int keyLen = PackedInteger.readInt(buffer, offset); |
| | | int key = PackedInteger.getReadIntLength(buffer, offset) + offset; |
| | | return comparator.compare(buffer, key, keyLen, b, b.length) == 0 |
| | | return indexComparator.compare(buffer, key, keyLen, b, b.length) == 0 |
| | | && indexID == bIndexID; |
| | | } |
| | | |
| | |
| | | int keyLen = PackedInteger.readInt(buffer, offset); |
| | | int key = PackedInteger.getReadIntLength(buffer, offset) + offset; |
| | | |
| | | final int cmp = comparator.compare(buffer, key, keyLen, keyBuf.array(), keyBuf.limit()); |
| | | final int cmp = indexComparator.compare(buffer, key, keyLen, keyBuf.array(), keyBuf.limit()); |
| | | if (cmp != 0) |
| | | { |
| | | return cmp; |
| | |
| | | |
| | | }; |
| | | |
| | | index.indexer.indexEntry(entry, dummySet, options); |
| | | index.indexEntry(entry, dummySet, options); |
| | | |
| | | if (!foundMatchingKey.get()) |
| | | { |
| | |
| | | if (oldEntry != null) |
| | | { |
| | | deleteKeySet.clear(); |
| | | index.indexer.indexEntry(oldEntry, deleteKeySet, options); |
| | | index.indexEntry(oldEntry, deleteKeySet, options); |
| | | for (ByteString delKey : deleteKeySet) |
| | | { |
| | | processKey(index, delKey, entryID, indexComparator, indexKey, false); |
| | | processKey(index, delKey, entryID, indexKey, false); |
| | | } |
| | | } |
| | | insertKeySet.clear(); |
| | | index.indexer.indexEntry(entry, insertKeySet, options); |
| | | index.indexEntry(entry, insertKeySet, options); |
| | | for (ByteString key : insertKeySet) |
| | | { |
| | | processKey(index, key, entryID, indexComparator, indexKey, true); |
| | | processKey(index, key, entryID, indexKey, true); |
| | | } |
| | | } |
| | | } |
| | |
| | | IndexKey indexKey) throws StorageRuntimeException, InterruptedException |
| | | { |
| | | insertKeySet.clear(); |
| | | index.indexer.indexEntry(entry, insertKeySet, options); |
| | | index.indexEntry(entry, insertKeySet, options); |
| | | for (ByteString key : insertKeySet) |
| | | { |
| | | processKey(index, key, entryID, indexComparator, indexKey, true); |
| | | processKey(index, key, entryID, indexKey, true); |
| | | } |
| | | } |
| | | |
| | |
| | | IndexKey indexKey = e.getKey(); |
| | | IndexOutputBuffer indexBuffer = e.getValue(); |
| | | it.remove(); |
| | | indexBuffer.setComparator(indexComparator); |
| | | indexBuffer.setIndexKey(indexKey); |
| | | indexBuffer.discard(); |
| | | futures.add(bufferSortService.submit(new SortTask(indexBuffer))); |
| | |
| | | } |
| | | |
| | | int processKey(DatabaseContainer container, ByteString key, EntryID entryID, |
| | | IndexOutputBuffer.ComparatorBuffer<byte[]> comparator, |
| | | IndexKey indexKey, boolean insert) throws InterruptedException |
| | | { |
| | | int sizeNeeded = IndexOutputBuffer.getRequiredSize(key.length(), entryID.longValue()); |
| | |
| | | else if (!indexBuffer.isSpaceAvailable(key, entryID.longValue())) |
| | | { |
| | | // complete the current buffer... |
| | | indexBuffer.setComparator(comparator); |
| | | indexBuffer.setIndexKey(indexKey); |
| | | bufferSortService.submit(new SortTask(indexBuffer)); |
| | | // ... and get a new one |
| | |
| | | { |
| | | DN2ID dn2id = suffix.getDN2ID(); |
| | | ByteString dnBytes = JebFormat.dnToDNKey(dn, suffix.getBaseDN().size()); |
| | | int id = processKey(dn2id, dnBytes, entryID, indexComparator, dnIndexKey, true); |
| | | int id = processKey(dn2id, dnBytes, entryID, dnIndexKey, true); |
| | | idECMap.putIfAbsent(id, suffix.getEntryContainer()); |
| | | } |
| | | |
| | |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.TreeMap; |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** The indexer object to construct index keys from LDAP attribute values. */ |
| | | Indexer indexer; |
| | | private Indexer indexer; |
| | | |
| | | /** The limit on the number of entry IDs that may be indexed by one key. */ |
| | | private int indexEntryLimit; |
| | |
| | | } |
| | | } |
| | | |
| | | void indexEntry(Entry entry, Set<ByteString> keys, IndexingOptions options) |
| | | { |
| | | indexer.indexEntry(entry, keys, options); |
| | | } |
| | | |
| | | final void insertID(IndexBuffer buffer, ByteString keyBytes, EntryID entryID) |
| | | { |
| | | getBufferedIndexValues(buffer, keyBytes).addEntryID(keyBytes, entryID); |
| | |
| | | */ |
| | | package org.opends.server.backends.pluggable; |
| | | |
| | | import static org.opends.server.backends.pluggable.Importer.indexComparator; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.DataOutputStream; |
| | | import java.io.IOException; |
| | |
| | | /** Used to iterate over the buffer when writing to a scratch file. */ |
| | | private int position; |
| | | |
| | | /** The comparator to use sort the keys. */ |
| | | private ComparatorBuffer<byte[]> comparator; |
| | | |
| | | /** |
| | | * Used to make sure that an instance of this class is put on the |
| | | * correct scratch file writer work queue for processing. |
| | |
| | | recordOffset = size - 1; |
| | | keys = 0; |
| | | position = 0; |
| | | comparator = null; |
| | | indexKey = null; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * Set the comparator to be used in the buffer processing to the specified |
| | | * comparator. |
| | | * |
| | | * @param comparator The comparator to set the buffer's comparator to. |
| | | */ |
| | | public void setComparator(ComparatorBuffer<byte[]> comparator) |
| | | { |
| | | this.comparator = comparator; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Return a buffer's current position value. |
| | | * |
| | | * @return The buffer's current position value. |
| | |
| | | return position; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Set a buffer's position value to the specified position. |
| | | * |
| | |
| | | this.position = position; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Sort the buffer. |
| | | */ |
| | |
| | | sort(0, keys); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Add the specified key byte array and EntryID to the buffer. |
| | | * |
| | |
| | | int yKeyLen = readInt(buffer, yoffSet); |
| | | int yKey = INT_SIZE + yoffSet; |
| | | |
| | | int cmp = comparator.compare(buffer, xKey, xKeyLen, xIndexID, yKey, yKeyLen, yIndexID); |
| | | int cmp = indexComparator.compare(buffer, xKey, xKeyLen, xIndexID, yKey, yKeyLen, yIndexID); |
| | | return evaluateReturnCode(cmp, op); |
| | | } |
| | | |
| | |
| | | int xKeyLen = readInt(buffer, xoffSet); |
| | | int xKey = INT_SIZE + xoffSet; |
| | | |
| | | int cmp = comparator.compare(buffer, xKey, xKeyLen, xIndexID, yKey, yKey.length, yIndexID); |
| | | int cmp = indexComparator.compare(buffer, xKey, xKeyLen, xIndexID, yKey, yKey.length, yIndexID); |
| | | return evaluateReturnCode(cmp, op); |
| | | } |
| | | |
| | |
| | | offset += REC_OVERHEAD + LONG_SIZE; |
| | | int keyLen = readInt(buffer, offset); |
| | | int key = INT_SIZE + offset; |
| | | return comparator.compare(buffer, key, keyLen, b, b.length) == 0 |
| | | return indexComparator.compare(buffer, key, keyLen, b, b.length) == 0 |
| | | && indexID == bIndexID; |
| | | } |
| | | |
| | |
| | | int keyLen = readInt(buffer, offset); |
| | | int key = INT_SIZE + offset; |
| | | |
| | | final int cmp = comparator.compare(buffer, key, keyLen, keyBuf.array(), keyBuf.limit()); |
| | | final int cmp = indexComparator.compare(buffer, key, keyLen, keyBuf.array(), keyBuf.limit()); |
| | | if (cmp != 0) |
| | | { |
| | | return cmp; |
| | |
| | | |
| | | }; |
| | | |
| | | index.indexer.indexEntry(entry, dummySet, options); |
| | | index.indexEntry(entry, dummySet, options); |
| | | |
| | | if (!foundMatchingKey.get()) |
| | | { |
| | |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | | import java.text.ParseException; |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Comparator; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | |
| | | import org.opends.server.admin.std.server.BackendCfg; |
| | | import org.opends.server.admin.std.server.LocalDBBackendCfg; |
| | | import org.opends.server.api.Backend; |
| | | import org.opends.server.backends.jeb.*; |
| | | import org.opends.server.backends.jeb.BackendImpl; |
| | | import org.opends.server.backends.jeb.DN2ID; |
| | | import org.opends.server.backends.jeb.DN2URI; |
| | | import org.opends.server.backends.jeb.DatabaseContainer; |
| | | import org.opends.server.backends.jeb.EntryContainer; |
| | | import org.opends.server.backends.jeb.EntryID; |
| | | import org.opends.server.backends.jeb.EntryIDSet; |
| | | import org.opends.server.backends.jeb.ID2Entry; |
| | | import org.opends.server.backends.jeb.Index; |
| | | import org.opends.server.backends.jeb.JebFormat; |
| | | import org.opends.server.backends.jeb.RootContainer; |
| | | import org.opends.server.backends.jeb.SortValuesSet; |
| | | import org.opends.server.backends.jeb.VLVIndex; |
| | | import org.opends.server.core.CoreConfigManager; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler; |
| | |
| | | { |
| | | if(databaseContainer instanceof Index) |
| | | { |
| | | return ((Index)databaseContainer).indexer.getComparator(); |
| | | return ((Index) databaseContainer).getComparator(); |
| | | } |
| | | else if(databaseContainer instanceof VLVIndex) |
| | | { |