opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/persistit/PersistItStorage.java
@@ -23,24 +23,19 @@ * * Copyright 2014 ForgeRock AS */ package org.opends.server.backends.persistit; import static org.opends.server.util.StaticUtils.getFileForPath; import static org.opends.server.util.StaticUtils.*; import java.io.File; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.forgerock.opendj.ldap.ByteSequence; import org.forgerock.opendj.ldap.ByteString; import org.opends.server.admin.std.server.LocalDBBackendCfg; import org.opends.server.admin.std.server.PersistitBackendCfg; import org.opends.server.backends.pluggable.spi.Cursor; import org.opends.server.backends.pluggable.spi.Importer; @@ -75,7 +70,6 @@ @Override public void createTree(TreeName treeName) { try { // FIXME: how do we set the comparator? final Tree tree = getVolume(treeName).getTree(treeName.toString(), true); trees.put(treeName, tree); } catch (PersistitException e) { @@ -336,14 +330,14 @@ private File backendDirectory; private PersistitBackendCfg config; private File backendDirectory; private PersistitBackendCfg config; private Persistit db; private final ConcurrentMap<TreeName, Volume> volumes = new ConcurrentHashMap<TreeName, Volume>(); private final ConcurrentMap<String, Volume> volumes = new ConcurrentHashMap<String, Volume>(); private Properties properties; private Volume getVolume(TreeName treeName) { return volumes.get(treeName.getSuffix()); return volumes.get(treeName.getBaseDN()); } @Override @@ -385,8 +379,7 @@ db.initialize(); for (DN baseDN : config.getBaseDN()) { final String volumeName = toSuffixName(baseDN.toString()); final TreeName suffixName = TreeName.of(volumeName); volumes.put(suffixName, db.loadVolume(volumeName)); volumes.put(volumeName, db.loadVolume(volumeName)); } } catch (PersistitException e) { throw new StorageRuntimeException(e); @@ -476,15 +469,6 @@ } } @Override public Cursor openCursor(TreeName treeName) { try { return new CursorImpl(getExchange0(treeName, false));//FIXME JNR we must release the exchange } catch (PersistitException e) { throw new StorageRuntimeException(e); } } private Exchange getExchange0(TreeName treeName, boolean create) throws PersistitException { return db.getExchange(getVolume(treeName), treeName.toString(), create); } opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/AttributeIndex.java
@@ -250,7 +250,8 @@ private TreeName getIndexName(AttributeType attrType, String indexID) { return entryContainer.getDatabasePrefix().child(attrType.getNameOrOID() + "." + indexID); final String attrIndexId = attrType.getNameOrOID() + "." + indexID; return new TreeName(entryContainer.getDatabasePrefix(), attrIndexId); } /** @@ -448,7 +449,7 @@ * to both a lower bound and an upper bound. * * @param indexQueryFactory * The index query factory to use for the evaluation * The index query factory to use for the evaluation * @param filter1 * The first filter, that is either a less-or-equal filter or a * greater-or-equal filter. opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/DbPreloadComparator.java
@@ -46,8 +46,7 @@ */ static private int priority(DatabaseContainer database) { TreeName name = database.getName(); String indexName = name.getIndex().toString(); String indexName = database.getName().getIndexId(); if (indexName.endsWith(SuffixContainer.ID2ENTRY_INDEX_NAME)) { return 1; opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/EntryContainer.java
@@ -168,7 +168,7 @@ * Prevents name clashes for common indexes (like id2entry) across multiple suffixes. * For example when a root container contains multiple suffixes. */ private TreeName databasePrefix; private String databasePrefix; /** * This class is responsible for managing the configuration for attribute @@ -440,7 +440,7 @@ * @param rootContainer The root container this entry container is in. * @throws ConfigException if a configuration related error occurs. */ public EntryContainer(DN baseDN, TreeName databasePrefix, Backend<?> backend, public EntryContainer(DN baseDN, String databasePrefix, Backend<?> backend, PersistitBackendCfg config, Storage env, RootContainer rootContainer) throws ConfigException { @@ -462,6 +462,11 @@ config.addBackendVLVIndexDeleteListener(vlvJEIndexCfgManager); } private TreeName getIndexName(String indexId) { return new TreeName(databasePrefix, indexId); } /** * Opens the entryContainer for reading and writing. * @@ -477,14 +482,13 @@ config.isCompactEncoding(), rootContainer.getCompressedSchema()); id2entry = new ID2Entry(databasePrefix.child(ID2ENTRY_DATABASE_NAME), entryDataConfig, storage, this); id2entry = new ID2Entry(getIndexName(ID2ENTRY_DATABASE_NAME), entryDataConfig, storage, this); id2entry.open(txn); dn2id = new DN2ID(databasePrefix.child(DN2ID_DATABASE_NAME), storage, this); dn2id = new DN2ID(getIndexName(DN2ID_DATABASE_NAME), storage, this); dn2id.open(txn); state = new State(databasePrefix.child(STATE_DATABASE_NAME), storage, this); state = new State(getIndexName(STATE_DATABASE_NAME), storage, this); state.open(txn); if (config.isSubordinateIndexesEnabled()) @@ -495,12 +499,12 @@ { // Use a null index and ensure that future attempts to use the real // subordinate indexes will fail. id2children = new NullIndex(databasePrefix.child(ID2CHILDREN_DATABASE_NAME), id2children = new NullIndex(getIndexName(ID2CHILDREN_DATABASE_NAME), new ID2CIndexer(), state, storage, txn, this); state.putIndexTrustState(txn, id2children, false); id2children.open(txn); // No-op id2subtree = new NullIndex(databasePrefix.child(ID2SUBTREE_DATABASE_NAME), id2subtree = new NullIndex(getIndexName(ID2SUBTREE_DATABASE_NAME), new ID2SIndexer(), state, storage, txn, this); state.putIndexTrustState(txn, id2subtree, false); id2subtree.open(txn); // No-op @@ -508,7 +512,7 @@ logger.info(NOTE_JEB_SUBORDINATE_INDEXES_DISABLED, backend.getBackendID()); } dn2uri = new DN2URI(databasePrefix.child(REFERRAL_DATABASE_NAME), storage, this); dn2uri = new DN2URI(getIndexName(REFERRAL_DATABASE_NAME), storage, this); dn2uri.open(txn); for (String idx : config.listBackendIndexes()) @@ -2901,7 +2905,7 @@ * * @return The container name for the base DN. */ public TreeName getDatabasePrefix() public String getDatabasePrefix() { return databasePrefix; } @@ -2910,10 +2914,10 @@ * Sets a new database prefix for this entry container and rename all * existing databases in use by this entry container. * * @param newDatabasePrefix The new database prefix to use. * @param newBaseDN The new database prefix to use. * @throws StorageRuntimeException If an error occurs in the JE database. */ public void setDatabasePrefix(final TreeName newDatabasePrefix) throws StorageRuntimeException public void setDatabasePrefix(final String newBaseDN) throws StorageRuntimeException { final List<DatabaseContainer> databases = new ArrayList<DatabaseContainer>(); listDatabases(databases); @@ -2934,7 +2938,7 @@ for(DatabaseContainer db : databases) { TreeName oldName = db.getName(); TreeName newName = oldName.replaceSuffix(newDatabasePrefix); TreeName newName = oldName.replaceBaseDN(newBaseDN); txn.renameTree(oldName, newName); } } @@ -2947,7 +2951,7 @@ for (DatabaseContainer db : databases) { TreeName oldName = db.getName(); TreeName newName = oldName.replaceSuffix(newDatabasePrefix); TreeName newName = oldName.replaceBaseDN(newBaseDN); db.setName(newName); } } @@ -3051,13 +3055,13 @@ // Disabling subordinate indexes. Use a null index and ensure that // future attempts to use the real indexes will fail. id2children.close(); id2children = new NullIndex(databasePrefix.child(ID2CHILDREN_DATABASE_NAME), id2children = new NullIndex(getIndexName(ID2CHILDREN_DATABASE_NAME), new ID2CIndexer(), state, storage, txn, EntryContainer.this); state.putIndexTrustState(txn, id2children, false); id2children.open(txn); // No-op id2subtree.close(); id2subtree = new NullIndex(databasePrefix.child(ID2SUBTREE_DATABASE_NAME), id2subtree = new NullIndex(getIndexName(ID2SUBTREE_DATABASE_NAME), new ID2SIndexer(), state, storage, txn, EntryContainer.this); state.putIndexTrustState(txn, id2subtree, false); id2subtree.open(txn); // No-op @@ -3229,7 +3233,7 @@ private Index newIndex(WriteableStorage txn, String name, Indexer indexer) { final Index index = new Index(databasePrefix.child(name), final Index index = new Index(getIndexName(name), indexer, state, config.getIndexEntryLimit(), 0, true, storage, txn, this); index.open(txn); if (!index.isTrusted()) opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/RootContainer.java
@@ -34,7 +34,6 @@ import org.forgerock.i18n.LocalizableMessage; import org.forgerock.i18n.slf4j.LocalizedLogger; import org.forgerock.opendj.config.server.ConfigException; import org.opends.messages.UtilityMessages; import org.opends.server.admin.server.ConfigurationChangeListener; import org.opends.server.admin.std.server.PersistitBackendCfg; import org.opends.server.api.Backend; @@ -43,7 +42,6 @@ import org.opends.server.backends.pluggable.spi.ReadOperation; import org.opends.server.backends.pluggable.spi.ReadableStorage; import org.opends.server.backends.pluggable.spi.StorageRuntimeException; import org.opends.server.backends.pluggable.spi.TreeName; import org.opends.server.backends.pluggable.spi.WriteOperation; import org.opends.server.backends.pluggable.spi.WriteableStorage; import org.opends.server.core.DefaultCompressedSchema; @@ -64,8 +62,8 @@ import static org.opends.messages.BackendMessages.*; import static org.opends.messages.ConfigMessages.*; import static org.opends.messages.JebMessages.*; import static org.opends.messages.UtilityMessages.ERR_LDIF_SKIP; import static org.opends.server.core.DirectoryServer.getServerErrorResultCode; import static org.opends.messages.UtilityMessages.*; import static org.opends.server.core.DirectoryServer.*; import static org.opends.server.util.StaticUtils.*; /** @@ -373,26 +371,13 @@ databasePrefix = name; } EntryContainer ec = new EntryContainer(baseDN, toSuffixName(databasePrefix), EntryContainer ec = new EntryContainer(baseDN, storage.toSuffixName(databasePrefix), backend, config, storage, this); ec.open(txn); return ec; } /** * Transform a database prefix string to one usable by the DB. * * @param databasePrefix * the database prefix * @return a new string when non letter or digit characters have been replaced * with underscore */ private TreeName toSuffixName(String databasePrefix) { return TreeName.of(storage.toSuffixName(databasePrefix)); } /** * Registers the entry container for a base DN. * * @param baseDN The base DN of the entry container to close. opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/VLVIndex.java
@@ -50,6 +50,7 @@ import org.opends.server.backends.pluggable.spi.ReadableStorage; import org.opends.server.backends.pluggable.spi.Storage; import org.opends.server.backends.pluggable.spi.StorageRuntimeException; import org.opends.server.backends.pluggable.spi.TreeName; import org.opends.server.backends.pluggable.spi.WriteOperation; import org.opends.server.backends.pluggable.spi.WriteableStorage; import org.opends.server.controls.ServerSideSortRequestControl; @@ -132,8 +133,7 @@ EntryContainer entryContainer, ReadableStorage txn) throws StorageRuntimeException, ConfigException { super(entryContainer.getDatabasePrefix().child("vlv."+config.getName()), env, entryContainer); super(new TreeName(entryContainer.getDatabasePrefix(), "vlv." + config.getName()), env, entryContainer); this.config = config; this.baseDN = config.getBaseDN(); @@ -719,7 +719,7 @@ { debugBuilder.append("vlv="); debugBuilder.append("[INDEX:"); debugBuilder.append(treeName.getIndex()); debugBuilder.append(treeName.getIndexId()); debugBuilder.append("]"); } opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/TreeName.java
@@ -25,90 +25,33 @@ */ package org.opends.server.backends.pluggable.spi; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; /** Assumes name components don't contain a '/'. */ public final class TreeName { public static TreeName of(final String... names) { return new TreeName(Arrays.asList(names)); } private final List<String> names; private final String baseDN; private final String indexId; private final String s; public TreeName(final List<String> names) public TreeName(String baseDN, String indexId) { this.names = names; final StringBuilder builder = new StringBuilder(); for (final String name : names) { builder.append('/'); builder.append(name); } this.s = builder.toString(); this.baseDN = baseDN; this.indexId = indexId; this.s = '/' + baseDN + '/' + indexId; } public List<String> getNames() public String getBaseDN() { return names; return baseDN; } public TreeName child(final String name) public TreeName replaceBaseDN(String newBaseDN) { final List<String> newNames = new ArrayList<String>(names.size() + 1); newNames.addAll(names); newNames.add(name); return new TreeName(newNames); return new TreeName(newBaseDN, indexId); } public TreeName getSuffix() public String getIndexId() { if (names.size() == 0) { throw new IllegalStateException(); } return new TreeName(Collections.singletonList(names.get(0))); } public TreeName replaceSuffix(TreeName newSuffix) { if (names.size() == 0) { throw new IllegalStateException(); } final ArrayList<String> newNames = new ArrayList<String>(names); newNames.set(0, newSuffix.names.get(0)); return new TreeName(newNames); } public boolean isSuffixOf(TreeName treeName) { if (names.size() > treeName.names.size()) { return false; } for (int i = 0; i < names.size(); i++) { if (!treeName.names.get(i).equals(names.get(i))) { return false; } } return true; } public TreeName getIndex() { if (names.size() == 1) { return null; } return new TreeName(names.subList(1, names.size())); return indexId; } @Override