mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Yannick Lecaillez
21.42.2015 f7fe6c1339f1a7da5723036cbae27ab74e13a9a2
OPENDJ-1763: verify-index fails with InitializationException when the server is started
1 files added
14 files modified
204 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java 18 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/BackendImpl.java 48 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeBufferImporter.java 5 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/RootContainer.java 9 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/TracedStorage.java 7 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/spi/Storage.java 15 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/spi/StorageInUseException.java 70 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/spi/StorageRuntimeException.java 2 ●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/extensions/FIFOEntryCache.java 5 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/VerifyIndex.java 6 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/CacheEntry.java 6 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/messages/org/opends/messages/backend.properties 2 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/DN2IDTest.java 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/ID2CountTest.java 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/StateTest.java 5 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java
@@ -27,7 +27,6 @@
import static com.persistit.Transaction.CommitPolicy.*;
import static java.util.Arrays.*;
import static org.opends.messages.BackendMessages.*;
import static org.opends.messages.ConfigMessages.*;
import static org.opends.messages.UtilityMessages.*;
@@ -55,6 +54,7 @@
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.util.Reject;
import org.opends.server.admin.server.ConfigurationChangeListener;
import org.opends.server.admin.std.server.PersistitBackendCfg;
import org.opends.server.api.Backupable;
@@ -63,6 +63,7 @@
import org.opends.server.backends.pluggable.spi.Importer;
import org.opends.server.backends.pluggable.spi.ReadOperation;
import org.opends.server.backends.pluggable.spi.Storage;
import org.opends.server.backends.pluggable.spi.StorageInUseException;
import org.opends.server.backends.pluggable.spi.StorageRuntimeException;
import org.opends.server.backends.pluggable.spi.StorageStatus;
import org.opends.server.backends.pluggable.spi.TreeName;
@@ -90,6 +91,7 @@
import com.persistit.Value;
import com.persistit.Volume;
import com.persistit.VolumeSpecification;
import com.persistit.exception.InUseException;
import com.persistit.exception.PersistitException;
import com.persistit.exception.RollbackException;
@@ -580,13 +582,13 @@
    cfg.addPersistitChangeListener(this);
  }
  private Configuration buildConfiguration()
  private Configuration buildConfiguration(AccessMode accessMode)
  {
    final Configuration dbCfg = new Configuration();
    dbCfg.setLogFile(new File(backendDirectory, VOLUME_NAME + ".log").getPath());
    dbCfg.setJournalPath(new File(backendDirectory, JOURNAL_NAME).getPath());
    dbCfg.setVolumeList(asList(new VolumeSpecification(new File(backendDirectory, VOLUME_NAME).getPath(), null,
        BUFFER_SIZE, 4096, Long.MAX_VALUE / BUFFER_SIZE, 2048, true, false, false)));
        BUFFER_SIZE, 4096, Long.MAX_VALUE / BUFFER_SIZE, 2048, true, false, accessMode.equals(AccessMode.READ_ONLY))));
    final BufferPoolConfiguration bufferPoolCfg = getBufferPoolCfg(dbCfg);
    bufferPoolCfg.setMaximumCount(Integer.MAX_VALUE);
@@ -642,9 +644,10 @@
  /** {@inheritDoc} */
  @Override
  public void open() throws ConfigException, StorageRuntimeException
  public void open(AccessMode accessMode) throws ConfigException, StorageRuntimeException
  {
    open0(buildConfiguration());
    Reject.ifNull(accessMode, "accessMode must not be null");
    open0(buildConfiguration(accessMode));
  }
  private void open0(final Configuration dbCfg) throws ConfigException
@@ -666,6 +669,9 @@
      db.initialize();
      volume = db.loadVolume(VOLUME_NAME);
    }
    catch(final InUseException e) {
      throw new StorageInUseException(e);
    }
    catch (final PersistitException e)
    {
      throw new StorageRuntimeException(e);
@@ -728,7 +734,7 @@
  @Override
  public Importer startImport() throws ConfigException, StorageRuntimeException
  {
    open0(buildConfiguration());
    open0(buildConfiguration(AccessMode.READ_WRITE));
    return new ImporterImpl();
  }
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/BackendImpl.java
@@ -33,7 +33,12 @@
import static org.opends.server.util.StaticUtils.*;
import java.io.IOException;
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
@@ -51,11 +56,33 @@
import org.opends.server.backends.RebuildConfig;
import org.opends.server.backends.VerifyConfig;
import org.opends.server.backends.pluggable.spi.Storage;
import org.opends.server.backends.pluggable.spi.Storage.AccessMode;
import org.opends.server.backends.pluggable.spi.StorageInUseException;
import org.opends.server.backends.pluggable.spi.StorageRuntimeException;
import org.opends.server.backends.pluggable.spi.WriteOperation;
import org.opends.server.backends.pluggable.spi.WriteableTransaction;
import org.opends.server.core.*;
import org.opends.server.types.*;
import org.opends.server.core.AddOperation;
import org.opends.server.core.DeleteOperation;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyDNOperation;
import org.opends.server.core.ModifyOperation;
import org.opends.server.core.SearchOperation;
import org.opends.server.core.ServerContext;
import org.opends.server.types.AttributeType;
import org.opends.server.types.BackupConfig;
import org.opends.server.types.BackupDirectory;
import org.opends.server.types.CanceledOperationException;
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.IndexType;
import org.opends.server.types.InitializationException;
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.LDIFImportResult;
import org.opends.server.types.OpenDsException;
import org.opends.server.types.Operation;
import org.opends.server.types.RestoreConfig;
import org.opends.server.util.LDIFException;
import org.opends.server.util.RuntimeInformation;
@@ -159,7 +186,7 @@
  {
    if (mustOpenRootContainer())
    {
      rootContainer = initializeRootContainer();
      rootContainer = newRootContainer(AccessMode.READ_WRITE);
    }
    // Preload the tree cache.
@@ -653,7 +680,7 @@
        }
      }
      rootContainer = initializeRootContainer();
      rootContainer = newRootContainer(AccessMode.READ_WRITE);
      return getImportStrategy().importLDIF(importConfig, rootContainer, serverContext);
    }
    catch (StorageRuntimeException e)
@@ -765,7 +792,7 @@
    {
      if (openRootContainer)
      {
        rootContainer = initializeRootContainer();
        rootContainer = newRootContainer(AccessMode.READ_WRITE);
      }
      new OnDiskMergeBufferImporter(rootContainer, rebuildConfig, cfg, serverContext).rebuildIndexes();
    }
@@ -953,7 +980,7 @@
  private final RootContainer getReadOnlyRootContainer()
      throws ConfigException, InitializationException
  {
    return initializeRootContainer();
    return newRootContainer(AccessMode.READ_ONLY);
  }
  /**
@@ -977,14 +1004,17 @@
    }
  }
  private RootContainer initializeRootContainer()
  private RootContainer newRootContainer(AccessMode accessMode)
          throws ConfigException, InitializationException {
    // Open the storage
    try {
      final RootContainer rc = new RootContainer(getBackendID(), storage, cfg);
      rc.open();
      rc.open(accessMode);
      return rc;
    }
    catch (StorageInUseException e) {
      throw new InitializationException(ERR_VERIFY_BACKEND_ONLINE.get(), e);
    }
    catch (StorageRuntimeException e)
    {
      throw new InitializationException(ERR_OPEN_ENV_FAIL.get(e.getMessage()), e);
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/OnDiskMergeBufferImporter.java
@@ -107,6 +107,7 @@
import org.opends.server.backends.pluggable.spi.ReadOperation;
import org.opends.server.backends.pluggable.spi.ReadableTransaction;
import org.opends.server.backends.pluggable.spi.Storage;
import org.opends.server.backends.pluggable.spi.Storage.AccessMode;
import org.opends.server.backends.pluggable.spi.StorageRuntimeException;
import org.opends.server.backends.pluggable.spi.TreeName;
import org.opends.server.backends.pluggable.spi.UpdateFunction;
@@ -1120,7 +1121,7 @@
    }
    finally
    {
      storage.open();
      storage.open(AccessMode.READ_WRITE);
    }
    shutdownAll(dbService);
@@ -3419,7 +3420,7 @@
        returnValues.put("dn", DN.valueOf("ds-cfg-backend-id=importDNCache,cn=Backends,cn=config"));
        storage = new PersistItStorage(newPersistitBackendCfgProxy(returnValues),
            DirectoryServer.getInstance().getServerContext());
        storage.open();
        storage.open(AccessMode.READ_WRITE);
        storage.write(new WriteOperation()
        {
          @Override
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/RootContainer.java
@@ -49,6 +49,7 @@
import org.opends.server.backends.pluggable.spi.ReadOperation;
import org.opends.server.backends.pluggable.spi.ReadableTransaction;
import org.opends.server.backends.pluggable.spi.Storage;
import org.opends.server.backends.pluggable.spi.Storage.AccessMode;
import org.opends.server.backends.pluggable.spi.StorageRuntimeException;
import org.opends.server.backends.pluggable.spi.StorageStatus;
import org.opends.server.backends.pluggable.spi.WriteOperation;
@@ -127,11 +128,11 @@
   * @throws ConfigException
   *           If an configuration error occurs while opening the storage.
   */
  void open() throws StorageRuntimeException, ConfigException
  void open(AccessMode accessMode) throws StorageRuntimeException, ConfigException
  {
    try
    {
      storage.open();
      storage.open(accessMode);
      storage.write(new WriteOperation()
      {
        @Override
@@ -142,6 +143,10 @@
        }
      });
    }
    catch(StorageRuntimeException e)
    {
      throw e;
    }
    catch (Exception e)
    {
      throw new StorageRuntimeException(e);
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/TracedStorage.java
@@ -271,12 +271,13 @@
  }
  @Override
  public void open() throws Exception
  public void open(AccessMode accessMode) throws Exception
  {
    storage.open();
    storage.open(accessMode);
    if (logger.isTraceEnabled())
    {
      logger.trace("Storage@%s.open() - Opened storage for backend %s", storageId(), backendId);
      logger
          .trace("Storage@%s.open(accessMode=%s) - Opened storage for backend %s", storageId(), accessMode, backendId);
    }
  }
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/spi/Storage.java
@@ -39,6 +39,15 @@
 */
public interface Storage extends Closeable
{
  /** Defines access modes of a Storage. */
  public enum AccessMode {
    /** Constant used to open the Storage in read-only mode. */
    READ_ONLY,
    /** Constant used to open the Storage in read-write mode. */
    READ_WRITE;
  }
  /**
   * Starts the import operation.
   *
@@ -54,11 +63,15 @@
  /**
   * Opens the storage engine to allow executing operations on it.
   *
   * @param accessMode
   *           Specify the access mode to this storage.
   * @throws NullPointerException
   *           if accessMode is null.
   * @throws Exception
   *           if a problem occurs with the underlying storage engine
   * @see #close() to release all resources once import is finished
   */
  void open() throws Exception;
  void open(AccessMode accessMode) throws Exception;
  /**
   * Executes a read operation. In case of a read operation rollback, implementations must ensure
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/spi/StorageInUseException.java
New file
@@ -0,0 +1,70 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2015 ForgeRock AS
 */
package org.opends.server.backends.pluggable.spi;
/**
 * Runtime exception for storage supporting single access only.
 */
@SuppressWarnings("serial")
public final class StorageInUseException extends StorageRuntimeException
{
  /**
   * Constructor with a message and a cause.
   *
   * @param message
   *          the exception message
   * @param cause
   *          the cause of the exception
   */
  public StorageInUseException(String message, Throwable cause)
  {
    super(message, cause);
  }
  /**
   * Constructor with a message.
   *
   * @param message
   *          the exception message
   */
  public StorageInUseException(String message)
  {
    super(message);
  }
  /**
   * Constructor with a cause.
   *
   * @param cause
   *          the cause of the exception
   */
  public StorageInUseException(Throwable cause)
  {
    super(cause);
  }
}
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/spi/StorageRuntimeException.java
@@ -29,7 +29,7 @@
 * Runtime exception for problems happening in the storage engine.
 */
@SuppressWarnings("serial")
public final class StorageRuntimeException extends RuntimeException
public class StorageRuntimeException extends RuntimeException
{
  /**
opendj-server-legacy/src/main/java/org/opends/server/extensions/FIFOEntryCache.java
@@ -967,8 +967,9 @@
    // See if there is anything on idMap that is not reflected on
    // dnMap in case maps went out of sync.
    for (String backendID : idMapCopy.keySet()) {
      for (Map.Entry<Long, CacheEntry> entry : idMapCopy.get(backendID).entrySet()) {
    for (Map.Entry<String,  Map<Long, CacheEntry>> backendCache : idMapCopy.entrySet()) {
      final String backendID = backendCache.getKey();
      for (Map.Entry<Long, CacheEntry> entry : backendCache.getValue().entrySet()) {
        final CacheEntry cacheEntry = entry.getValue();
        if (cacheEntry == null || !dnMapCopy.containsKey(cacheEntry.getDN())) {
          sb.append(cacheEntry != null ? cacheEntry.getDN() : null);
opendj-server-legacy/src/main/java/org/opends/server/tools/VerifyIndex.java
@@ -460,6 +460,12 @@
        }
      }
    }
    catch (InitializationException e)
    {
      err.println(wrapText(ERR_VERIFYINDEX_ERROR_DURING_VERIFY.get(e.getMessage()),
          MAX_LINE_WIDTH));
      returnCode = 1;
    }
    catch (Exception e)
    {
      err.println(wrapText(ERR_VERIFYINDEX_ERROR_DURING_VERIFY.get(stackTraceToSingleLineString(e)),
opendj-server-legacy/src/main/java/org/opends/server/types/CacheEntry.java
@@ -38,7 +38,7 @@
     notes="This should only be used within a backend")
public final class CacheEntry
{
  /** The backend with which this cache entry is associated. */
  /** ID of the backend with which this cache entry is associated. */
  private final String backendID;
  /** The entry itself. */
@@ -72,9 +72,9 @@
  }
  /**
   * Retrieves the backend for this cache entry.
   * Retrieves the backend ID for this cache entry.
   *
   * @return  The backend for this cache entry.
   * @return  ID of the backend for this cache entry.
   */
  public String getBackendID()
  {
opendj-server-legacy/src/messages/org/opends/messages/backend.properties
@@ -1334,3 +1334,5 @@
ERR_PARENT_ENTRY_IS_MISSING_577=Parent entry is missing
WARN_BACKUPDB_INCREMENTAL_NOT_FOUND_DOING_NORMAL_578=Could not find any \
 backup in '%s'. A full backup will be executed
ERR_VERIFY_BACKEND_ONLINE_579=The backend must be disabled before \
 verification process can start
opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/DN2IDTest.java
@@ -44,6 +44,7 @@
import org.opends.server.backends.pluggable.spi.ReadOperation;
import org.opends.server.backends.pluggable.spi.ReadableTransaction;
import org.opends.server.backends.pluggable.spi.SequentialCursor;
import org.opends.server.backends.pluggable.spi.Storage.AccessMode;
import org.opends.server.backends.pluggable.spi.TreeName;
import org.opends.server.backends.pluggable.spi.WriteOperation;
import org.opends.server.backends.pluggable.spi.WriteableTransaction;
@@ -91,7 +92,7 @@
      importer.createTree(dn2IDTreeName);
    }
    storage.open();
    storage.open(AccessMode.READ_WRITE);
    baseDN = dn("dc=example, dc=com");
    dn2ID = new DN2ID(dn2IDTreeName, baseDN);
opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/ID2CountTest.java
@@ -45,6 +45,7 @@
import org.opends.server.backends.persistit.PersistItStorage;
import org.opends.server.backends.pluggable.spi.ReadOperation;
import org.opends.server.backends.pluggable.spi.ReadableTransaction;
import org.opends.server.backends.pluggable.spi.Storage.AccessMode;
import org.opends.server.backends.pluggable.spi.TreeName;
import org.opends.server.backends.pluggable.spi.WriteOperation;
import org.opends.server.backends.pluggable.spi.WriteableTransaction;
@@ -90,7 +91,7 @@
      importer.createTree(id2CountTreeName);
    }
    storage.open();
    storage.open(AccessMode.READ_WRITE);
    id2Count = new ID2Count(id2CountTreeName);
opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/StateTest.java
@@ -41,6 +41,7 @@
import org.opends.server.backends.pluggable.State.IndexFlag;
import org.opends.server.backends.pluggable.spi.ReadOperation;
import org.opends.server.backends.pluggable.spi.ReadableTransaction;
import org.opends.server.backends.pluggable.spi.Storage.AccessMode;
import org.opends.server.backends.pluggable.spi.TreeName;
import org.opends.server.backends.pluggable.spi.WriteOperation;
import org.opends.server.backends.pluggable.spi.WriteableTransaction;
@@ -89,8 +90,8 @@
    try(final org.opends.server.backends.pluggable.spi.Importer importer = storage.startImport()) {
      importer.createTree(stateTreeName);
    }
    storage.open();
    storage.open(AccessMode.READ_WRITE);
    state = new State(stateTreeName);
  }