OPENDJ-1800 Find a better way to manage database prefix names in a Storage
We now use TreeNames all along and derive the databasePrefix from the suffix instead of passing it as parameter to a new EntryContainer.
The storage will mangle names as needed by itself.
| | |
| | | { |
| | | try |
| | | { |
| | | final Tree tree = volume.getTree(treeName.toString(), true); |
| | | final Tree tree = volume.getTree(mangleTreeName(treeName), true); |
| | | trees.put(treeName, tree); |
| | | } |
| | | catch (final PersistitException e) |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void renameTree(final TreeName oldTreeName, |
| | | final TreeName newTreeName) |
| | | public void renameTree(final TreeName oldTreeName, final TreeName newTreeName) |
| | | { |
| | | throw new UnsupportedOperationException(); |
| | | } |
| | |
| | | } |
| | | exchanges.clear(); |
| | | } |
| | | |
| | | private Exchange getNewExchange(final TreeName treeName, final boolean create) |
| | | throws PersistitException |
| | | { |
| | | return db.getExchange(volume, mangleTreeName(treeName), create); |
| | | } |
| | | } |
| | | |
| | | private static void clearAndCreateDbDir(final File dbDir) |
| | |
| | | return new ImporterImpl(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | public String toSafeSuffixName(final String suffix) |
| | | private String mangleTreeName(final TreeName treeName) |
| | | { |
| | | return suffix.replaceAll("[,=]", "_"); |
| | | StringBuilder mangled = new StringBuilder(); |
| | | String name = treeName.toString(); |
| | | |
| | | for (int idx = 0; idx < name.length(); idx++) |
| | | { |
| | | char ch = name.charAt(idx); |
| | | if (ch == '=' || ch == ',') |
| | | { |
| | | ch = '_'; |
| | | } |
| | | mangled.append(ch); |
| | | } |
| | | return mangled.toString(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | return value; |
| | | } |
| | | |
| | | private Exchange getNewExchange(final TreeName treeName, final boolean create) |
| | | throws PersistitException |
| | | { |
| | | return db.getExchange(volume, treeName.toString(), create); |
| | | } |
| | | |
| | | private ByteString keyToBytes(final Key key) |
| | | { |
| | | return ByteString.wrap(key.reset().decodeByteArray()); |
| | |
| | | try |
| | | { |
| | | // The base DN was added. |
| | | EntryContainer ec = rootContainer.openEntryContainer(baseDN, null, txn); |
| | | EntryContainer ec = rootContainer.openEntryContainer(baseDN, txn); |
| | | rootContainer.registerEntryContainer(baseDN, ec); |
| | | DirectoryServer.registerBaseDN(baseDN, this, false); |
| | | } |
| | |
| | | * |
| | | * @param baseDN The baseDN this entry container will be responsible for |
| | | * storing on disk. |
| | | * @param databasePrefix The prefix to use in the database names used by |
| | | * this entry container. |
| | | * @param backend A reference to the JE backend that is creating this entry |
| | | * container. It is needed by the Directory Server entry cache |
| | | * methods. |
| | |
| | | * @param rootContainer The root container this entry container is in. |
| | | * @throws ConfigException if a configuration related error occurs. |
| | | */ |
| | | EntryContainer(DN baseDN, String databasePrefix, Backend<?> backend, |
| | | PluggableBackendCfg config, Storage env, RootContainer rootContainer) |
| | | throws ConfigException |
| | | EntryContainer(DN baseDN, Backend<?> backend, PluggableBackendCfg config, Storage env, RootContainer rootContainer) |
| | | throws ConfigException |
| | | { |
| | | this.backend = backend; |
| | | this.baseDN = baseDN; |
| | | this.config = config; |
| | | this.storage = env; |
| | | this.rootContainer = rootContainer; |
| | | this.databasePrefix = databasePrefix; |
| | | this.databasePrefix = baseDN.toIrreversibleReadableString(); |
| | | |
| | | config.addPluggableChangeListener(this); |
| | | |
| | |
| | | { |
| | | // Create a temp entry container |
| | | sourceEntryContainer = entryContainer; |
| | | final String name = baseDN.toIrreversibleReadableString() + "_importTmp"; |
| | | entryContainer = rootContainer.openEntryContainer(baseDN, name, txn); |
| | | entryContainer = createEntryContainer(txn, baseDN); |
| | | } |
| | | } |
| | | } |
| | | return new Suffix(entryContainer, sourceEntryContainer, includeBranches, excludeBranches); |
| | | } |
| | | |
| | | private EntryContainer createEntryContainer(WriteableStorage txn, DN baseDN) throws ConfigException |
| | | { |
| | | DN tempDN; |
| | | try |
| | | { |
| | | tempDN = baseDN.child(DN.valueOf("dc=importTmp")); |
| | | } |
| | | catch (DirectoryException e) |
| | | { |
| | | throw new ConfigException(e.getMessageObject()); |
| | | } |
| | | return rootContainer.openEntryContainer(tempDN, txn); |
| | | } |
| | | |
| | | private void clearSuffix(EntryContainer entryContainer) |
| | | { |
| | | entryContainer.lock(); |
| | |
| | | * |
| | | * @param baseDN |
| | | * The base DN of the entry container to open. |
| | | * @param name |
| | | * The name of the entry container or <CODE>NULL</CODE> to open the |
| | | * default entry container for the given base DN. |
| | | * @param txn |
| | | * The database transaction |
| | | * @return The opened entry container. |
| | |
| | | * @throws ConfigException |
| | | * If an configuration error occurs while opening the entry container. |
| | | */ |
| | | EntryContainer openEntryContainer(DN baseDN, String name, WriteableStorage txn) |
| | | EntryContainer openEntryContainer(DN baseDN, WriteableStorage txn) |
| | | throws StorageRuntimeException, ConfigException |
| | | { |
| | | String databasePrefix; |
| | | if (name == null || "".equals(name)) |
| | | { |
| | | databasePrefix = baseDN.toIrreversibleReadableString(); |
| | | } |
| | | else |
| | | { |
| | | databasePrefix = name; |
| | | } |
| | | |
| | | EntryContainer ec = |
| | | new EntryContainer(baseDN, storage.toSafeSuffixName(databasePrefix), backend, config, storage, this); |
| | | EntryContainer ec = new EntryContainer(baseDN, backend, config, storage, this); |
| | | ec.open(txn); |
| | | return ec; |
| | | } |
| | |
| | | EntryID highestID = null; |
| | | for (DN baseDN : baseDNs) |
| | | { |
| | | EntryContainer ec = openEntryContainer(baseDN, null, txn); |
| | | EntryContainer ec = openEntryContainer(baseDN, txn); |
| | | EntryID id = ec.getHighestEntryID(txn); |
| | | registerEntryContainer(baseDN, ec); |
| | | if (highestID == null || id.compareTo(highestID) > 0) |
| | |
| | | * @param config The VLV index config object to use for this VLV |
| | | * index. |
| | | * @param state The state database to persist vlvIndex state info. |
| | | * @param env The JE Storage |
| | | * @param storage The storage currently in use |
| | | * @param entryContainer The database entryContainer holding this vlvIndex. the sort order |
| | | * @param txn The transaction to use when creating this object |
| | | * @throws StorageRuntimeException |
| | |
| | | * @throws ConfigException if a error occurs while reading the VLV index |
| | | * configuration |
| | | */ |
| | | VLVIndex(BackendVLVIndexCfg config, State state, Storage env, EntryContainer entryContainer, WriteableStorage txn) |
| | | VLVIndex(BackendVLVIndexCfg config, State state, Storage storage, EntryContainer entryContainer, WriteableStorage txn) |
| | | throws StorageRuntimeException, ConfigException |
| | | { |
| | | super(new TreeName(entryContainer.getDatabasePrefix(), "vlv." + config.getName()), env, entryContainer); |
| | | super(new TreeName(entryContainer.getDatabasePrefix(), "vlv." + config.getName()), storage, entryContainer); |
| | | |
| | | this.config = config; |
| | | this.baseDN = config.getBaseDN(); |
| | |
| | | * @throws StorageRuntimeException if removal fails |
| | | */ |
| | | void removeStorageFiles() throws StorageRuntimeException; |
| | | |
| | | /** |
| | | * Replace reserved characters with an underscore character. |
| | | * |
| | | * @param databasePrefix |
| | | * the suffix name to convert |
| | | * @return a new String suitable for use as a suffix name |
| | | */ |
| | | String toSafeSuffixName(String databasePrefix); |
| | | } |