Run UCDetector on package org.opends.server.backends.pluggable
| | |
| | | * Collects all necessary interaction interfaces with either a Backend using TreeNames |
| | | * or a storage using Trees. |
| | | */ |
| | | interface TreeKeyValue |
| | | private interface TreeKeyValue |
| | | { |
| | | /** |
| | | * Returns a key given a string representation of it. |
| | |
| | | } |
| | | |
| | | /** Stays at the storage level when cursoring Trees. */ |
| | | static class StorageTreeKeyValue implements TreeKeyValue |
| | | private static class StorageTreeKeyValue implements TreeKeyValue |
| | | { |
| | | private TreeName treeName; |
| | | private final TreeName treeName; |
| | | |
| | | public StorageTreeKeyValue(TreeName treeName) |
| | | private StorageTreeKeyValue(TreeName treeName) |
| | | { |
| | | this.treeName = treeName; |
| | | } |
| | |
| | | } |
| | | |
| | | /** Delegate key semantics to the backend. */ |
| | | static class BackendTreeKeyValue implements TreeKeyValue |
| | | private static class BackendTreeKeyValue implements TreeKeyValue |
| | | { |
| | | private TreeName name; |
| | | private Tree tree; |
| | | private final TreeName name; |
| | | private final Tree tree; |
| | | |
| | | public BackendTreeKeyValue(Tree tree) |
| | | private BackendTreeKeyValue(Tree tree) |
| | | { |
| | | this.tree = tree; |
| | | this.name = tree.getName(); |
| | |
| | | } |
| | | |
| | | /** Statistics collector. */ |
| | | class TreeStats |
| | | private class TreeStats |
| | | { |
| | | final long count; |
| | | final long totalKeySize; |
| | | final long totalDataSize; |
| | | private final long count; |
| | | private final long totalKeySize; |
| | | private final long totalDataSize; |
| | | |
| | | TreeStats(long count, long tks, long tds) |
| | | private TreeStats(long count, long tks, long tds) |
| | | { |
| | | this.count = count; |
| | | this.totalKeySize = tks; |
| | |
| | | import org.opends.server.backends.pluggable.spi.SequentialCursor; |
| | | import org.opends.server.backends.pluggable.spi.StorageRuntimeException; |
| | | import org.opends.server.backends.pluggable.spi.TreeName; |
| | | import org.opends.server.backends.pluggable.spi.UpdateFunction; |
| | | import org.opends.server.backends.pluggable.spi.WriteableTransaction; |
| | | import org.opends.server.types.CanceledOperationException; |
| | | import org.opends.server.types.DN; |
| | |
| | | txn.put(getName(), toKey(dn), toValue(entryID)); |
| | | } |
| | | |
| | | boolean insert(final WriteableTransaction txn, DN dn, final EntryID entryID) throws StorageRuntimeException |
| | | { |
| | | return txn.update(getName(), toKey(dn), new UpdateFunction() |
| | | { |
| | | @Override |
| | | public ByteSequence computeNewValue(ByteSequence oldEntryID) |
| | | { |
| | | if (oldEntryID != null) |
| | | { |
| | | // no change |
| | | return oldEntryID; |
| | | } |
| | | // it did not exist before, insert the new value |
| | | return toValue(entryID); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | ByteString toKey(DN dn) |
| | | private ByteString toKey(DN dn) |
| | | { |
| | | return dnToDNKey(dn, baseDN.size()); |
| | | } |
| | | |
| | | ByteString toValue(final EntryID entryID) |
| | | private ByteString toValue(final EntryID entryID) |
| | | { |
| | | // TODO JNR do we want to use compacted longs? |
| | | return entryID.toByteString(); |
| | |
| | | |
| | | @Override |
| | | Iterator<EntryID> iterator(); |
| | | |
| | | Iterator<EntryID> iterator(EntryID begin); |
| | | } |
| | | |
| | | /** Define serialization contract for EntryIDSet. */ |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Iterator<EntryID> iterator(EntryID begin) |
| | | { |
| | | return new IDSetIterator(entryIDs, begin == null ? 0 : begin.longValue()); |
| | | } |
| | | |
| | | @Override |
| | | public long[] getRange() |
| | | { |
| | | if (entryIDs.length != 0) |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Iterator<EntryID> iterator(EntryID begin) |
| | | { |
| | | return Iterators.emptyIterator(); |
| | | } |
| | | |
| | | @Override |
| | | public long[] getRange() |
| | | { |
| | | return NO_ENTRY_IDS_RANGE; |
| | |
| | | this.entryIDSet = entryIDSet; |
| | | } |
| | | |
| | | IDSetIterator(long[] entryIDSet, long begin) |
| | | { |
| | | this(entryIDSet); |
| | | currentIndex = Math.max(0, Arrays.binarySearch(entryIDSet, begin)); |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasNext() |
| | | { |
| | |
| | | return concreteImpl.iterator(); |
| | | } |
| | | |
| | | /** |
| | | * Creates an iterator over the set or an empty iterator if the set is not defined. |
| | | * |
| | | * @param begin |
| | | * The entry ID of the first entry to return in the list. |
| | | * @return An EntryID iterator. |
| | | */ |
| | | public Iterator<EntryID> iterator(EntryID begin) |
| | | { |
| | | return concreteImpl.iterator(begin); |
| | | } |
| | | |
| | | private long[] getIDs() |
| | | { |
| | | return concreteImpl.getIDs(); |
| | |
| | | import static org.forgerock.util.Reject.*; |
| | | import static org.forgerock.util.Utils.*; |
| | | import static org.opends.messages.BackendMessages.*; |
| | | import static org.opends.server.core.DirectoryServer.*; |
| | | import static org.opends.server.backends.pluggable.CursorTransformer.transformKeysAndValues; |
| | | import static org.opends.server.core.DirectoryServer.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Remove a record from the entry tree. |
| | | * |
| | | * @param txn a non null transaction |
| | | * @param entryID The entry ID which forms the key. |
| | | * @return true if the entry was removed, false if it was not. |
| | | * @throws StorageRuntimeException If an error occurs in the storage. |
| | | */ |
| | | boolean remove(WriteableTransaction txn, EntryID entryID) throws StorageRuntimeException |
| | | { |
| | | return txn.delete(getName(), entryID.toByteString()); |
| | | } |
| | | |
| | | /** |
| | | * Fetch a record from the entry tree. |
| | | * |
| | | * @param txn a non null transaction |
| | |
| | | package org.opends.server.backends.pluggable; |
| | | |
| | | import static java.nio.channels.FileChannel.*; |
| | | |
| | | import static org.forgerock.util.Utils.*; |
| | | import static org.opends.messages.BackendMessages.*; |
| | | import static org.opends.server.util.DynamicConstants.*; |
| | |
| | | visitIndexes(entryContainer, setTrust(true, importer)); |
| | | } |
| | | |
| | | final void clearEntryContainerTrees(EntryContainer entryContainer) |
| | | { |
| | | for(Tree tree : entryContainer.listTrees()) |
| | | { |
| | | importer.clearTree(tree.getName()); |
| | | } |
| | | } |
| | | |
| | | final Chunk newExternalSortChunk(TreeName treeName) throws Exception |
| | | { |
| | | return new ExternalSortChunk(tempDir, treeName.toString(), bufferPool, |
| | |
| | | * Cursor that returns unique keys and null values. Ensure that {@link #getKey()} will return a different key after |
| | | * each {@link #next()}. |
| | | */ |
| | | static final class UniqueKeysCursor<K> implements SequentialCursor<K, Void> |
| | | private static final class UniqueKeysCursor<K> implements SequentialCursor<K, Void> |
| | | { |
| | | private final Cursor<K, ?> delegate; |
| | | private boolean isDefined; |
| | | private K key; |
| | | |
| | | UniqueKeysCursor(Cursor<K, ?> cursor) |
| | | private UniqueKeysCursor(Cursor<K, ?> cursor) |
| | | { |
| | | this.delegate = cursor; |
| | | if (!delegate.isDefined()) |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | @Test(groups = { "precommit", "pluggablebackend", "unit" }, sequential=true) |
| | | public class EntryIDSetTest extends DirectoryServerTestCase |
| | | { |
| | |
| | | assertIdsEquals(newDefinedSet(4, 6, 8, 10, 12).iterator(), 4, 6, 8, 10, 12); |
| | | } |
| | | |
| | | @Test |
| | | public void testDefinedIteratorWithBegin() |
| | | { |
| | | final EntryIDSet set = newDefinedSet(4, 6, 8, 10, 12); |
| | | |
| | | assertIdsEquals(set.iterator(id(4)), 4, 6, 8, 10, 12); |
| | | assertIdsEquals(set.iterator(id(8)), 8, 10, 12); |
| | | assertIdsEquals(set.iterator(id(12)), 12); |
| | | assertIdsEquals(set.iterator(id(13)), 4, 6, 8, 10, 12); |
| | | } |
| | | |
| | | @Test(dataProvider = "codecs") |
| | | public void testCodecs(EntryIDSetCodec codec) |
| | | { |
| | |
| | | } |
| | | |
| | | @Test |
| | | public void testUndefinedIteratorWithBegin() |
| | | { |
| | | assertThat(newUndefinedSet().iterator(id(8)).hasNext()).isFalse(); |
| | | } |
| | | |
| | | @Test |
| | | public void testNewEmptySet() |
| | | { |
| | | assertThat(newDefinedSet().isDefined()).isTrue(); |
| | |
| | | */ |
| | | package org.opends.server.tasks; |
| | | |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.opends.server.backends.task.Task; |
| | | import org.opends.server.backends.task.TaskState; |
| | | import org.opends.server.types.Attribute; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | |
| | |
| | | * This class provides an implementation of a Directory Server task always |
| | | * completes successfully. It is intended only for testing purposes. |
| | | */ |
| | | public class DummyTask |
| | | extends Task |
| | | public class DummyTask extends Task |
| | | { |
| | | /** The length of time that the task should sleep before completing. */ |
| | | private long sleepTime; |
| | |
| | | */ |
| | | private volatile TaskState interruptedState; |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public LocalizableMessage getDisplayName() { |
| | | return LocalizableMessage.raw("Dummy"); |
| | | } |
| | | |
| | | @Override |
| | | public void initializeTask() |
| | | throws DirectoryException |
| | | public void initializeTask() throws DirectoryException |
| | | { |
| | | sleepTime = 0; |
| | | interruptedState = null; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | protected TaskState runTask() |
| | | { |
| | | long stopTime = System.currentTimeMillis() + sleepTime; |
| | |
| | | try |
| | | { |
| | | Thread.sleep(10); |
| | | } catch (Exception e) {} |
| | | } catch (InterruptedException e) {} |
| | | } |
| | | |
| | | if (interruptedState != null) |
| | |
| | | return TaskState.COMPLETED_SUCCESSFULLY; |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isInterruptable() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void interruptTask(TaskState taskState, LocalizableMessage interruptMessage) |
| | | { |
| | |
| | | setTaskInterruptState(taskState); |
| | | } |
| | | } |
| | | |