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

patrick diligent
16.19.2015 5a92d951296cae7ad72e45f84c92d40a6d41ad40
OPENDJ-49 - disable replication domain when backend offline.
The domain is now listening to backend events. For this purpose, two new events are added to the backend listener, and the existing ones renamed to have pre/post initialisation, and pre/post finalization. This is to ensure that the replication domain receive a backend event AFTER it has been completely initialised, or BEFORE the finalization phase is started.
9 files modified
226 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/api/BackendInitializationListener.java 25 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciListenerManager.java 15 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/BackendConfigManager.java 47 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java 15 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/GroupManager.java 13 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/SubentryManager.java 14 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerSync.java 14 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/extensions/DefaultEntryCache.java 14 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java 69 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/api/BackendInitializationListener.java
@@ -49,7 +49,27 @@
   * @param  backend  The backend that has been initialized and is
   *                  about to be put into service.
   */
  void performBackendInitializationProcessing(Backend<?> backend);
  void performBackendPreInitializationProcessing(Backend<?> backend);
  /**
   * Performs any processing that may be required
   * after the Initialisation cycle has been completed, that is
   * all listeners have received the initialisation event, and the
   * backend has been put into service,.
   *
   * @param  backend  The backend that has been initialized and has been
   *                  put into service.
   */
  void performBackendPostInitializationProcessing(Backend<?> backend);
  /**
   * Performs any processing that may be required before starting
   * the finalisation cycle, that is invoked before any listener receive
   * the Finalization event.
   *
   * @param  backend  The backend that is about to be finalized.
   */
  void performBackendPreFinalizationProcessing(Backend<?> backend);
  /**
   * Performs any processing that may be required whenever a backend
@@ -59,6 +79,7 @@
   * @param  backend  The backend that has been taken out of service
   *                  and is about to be finalized.
   */
  void performBackendFinalizationProcessing(Backend<?> backend);
  void performBackendPostFinalizationProcessing(Backend<?> backend);
}
opendj-server-legacy/src/main/java/org/opends/server/authorization/dseecompat/AciListenerManager.java
@@ -358,7 +358,7 @@
    Map<String, Backend> backendMap = DirectoryServer.getBackends();
    if (backendMap != null) {
      for (Backend backend : backendMap.values()) {
        performBackendInitializationProcessing(backend);
        performBackendPreInitializationProcessing(backend);
      }
    }
@@ -388,7 +388,7 @@
   * to the ACI list.
   */
  @Override
  public void performBackendInitializationProcessing(Backend<?> backend)
  public void performBackendPreInitializationProcessing(Backend<?> backend)
  {
    // Check to make sure that the backend has a presence index defined
    // for the ACI attribute. If it does not, then log a warning message
@@ -461,11 +461,20 @@
   * backend.
   */
  @Override
  public void performBackendFinalizationProcessing(Backend<?> backend)
  public void performBackendPostFinalizationProcessing(Backend<?> backend)
  {
    aciList.removeAci(backend);
  }
  @Override
  public void performBackendPostInitializationProcessing(Backend<?> backend) {
    // Nothing to do.
  }
  @Override
  public void performBackendPreFinalizationProcessing(Backend<?> backend) {
    // nothing to do.
  }
  /**
opendj-server-legacy/src/main/java/org/opends/server/core/BackendConfigManager.java
@@ -258,10 +258,9 @@
        for (BackendInitializationListener listener : getBackendInitializationListeners())
        {
          listener.performBackendInitializationProcessing(backend);
          listener.performBackendPreInitializationProcessing(backend);
        }
        // Register the backend with the server.
        try
        {
@@ -275,6 +274,10 @@
          // FIXME -- Do we need to send an admin alert?
        }
        for (BackendInitializationListener listener : getBackendInitializationListeners())
        {
          listener.performBackendPostInitializationProcessing(backend);
        }
        // Put this backend in the hash so that we will be able to find it if it
        // is altered.
@@ -418,11 +421,17 @@
          // It isn't disabled, so we will do so now and deregister it from the
          // Directory Server.
          registeredBackends.remove(backendDN);
          for (BackendInitializationListener listener : getBackendInitializationListeners())
          {
            listener.performBackendPreFinalizationProcessing(backend);
          }
          DirectoryServer.deregisterBackend(backend);
          for (BackendInitializationListener listener : getBackendInitializationListeners())
          {
            listener.performBackendFinalizationProcessing(backend);
            listener.performBackendPostFinalizationProcessing(backend);
          }
          backend.finalizeBackend();
@@ -572,10 +581,9 @@
      for (BackendInitializationListener listener : getBackendInitializationListeners())
      {
        listener.performBackendInitializationProcessing(backend);
        listener.performBackendPreInitializationProcessing(backend);
      }
      // Register the backend with the server.
      try
      {
@@ -595,6 +603,10 @@
        return ccr;
      }
      for (BackendInitializationListener listener : getBackendInitializationListeners())
      {
        listener.performBackendPostInitializationProcessing(backend);
      }
      registeredBackends.put(backendDN, backend);
    }
@@ -792,7 +804,7 @@
    for (BackendInitializationListener listener : getBackendInitializationListeners())
    {
      listener.performBackendInitializationProcessing(backend);
      listener.performBackendPreInitializationProcessing(backend);
    }
    // At this point, the backend should be online.  Add it as one of the
@@ -815,6 +827,11 @@
      return ccr;
    }
    for (BackendInitializationListener listener : getBackendInitializationListeners())
    {
      listener.performBackendPostInitializationProcessing(backend);
    }
    registeredBackends.put(backendDN, backend);
    return ccr;
  }
@@ -936,8 +953,20 @@
      return ccr;
    }
    for (BackendInitializationListener listener : getBackendInitializationListeners())
    {
      listener.performBackendPreFinalizationProcessing(backend);
    }
    registeredBackends.remove(backendDN);
    DirectoryServer.deregisterBackend(backend);
    for (BackendInitializationListener listener : getBackendInitializationListeners())
    {
      listener.performBackendPostFinalizationProcessing(backend);
    }
    try
    {
      backend.finalizeBackend();
@@ -947,12 +976,6 @@
      logger.traceException(e);
    }
    for (BackendInitializationListener listener : getBackendInitializationListeners())
    {
      listener.performBackendFinalizationProcessing(backend);
    }
    DirectoryServer.deregisterBackend(backend);
    configEntry.removeChangeListener(this);
    // Remove the shared lock for this backend.
opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
@@ -1396,8 +1396,8 @@
      // Initialize both subentry manager and group manager
      // for the configuration backend.
      // TODO : why do we initialize these now ? Can't we do them after backend initialization ?
      subentryManager.performBackendInitializationProcessing(configHandler);
      groupManager.performBackendInitializationProcessing(configHandler);
      subentryManager.performBackendPreInitializationProcessing(configHandler);
      groupManager.performBackendPreInitializationProcessing(configHandler);
      AccessControlConfigManager.getInstance().initializeAccessControl(serverContext);
@@ -2019,7 +2019,7 @@
    // so we need to handle it explicitly.
    // Because subentryManager may depend on the groupManager, let's
    // delay this.
    // groupManager.performBackendInitializationProcessing(configHandler);
    // groupManager.performBackendPreInitializationProcessing(configHandler);
  }
  /**
@@ -2119,7 +2119,7 @@
      // at this point so we need to handle it explicitly here.
      // However, subentryManager may have dependencies on the
      // groupManager. So lets delay the backend initialization until then.
      // subentryManager.performBackendInitializationProcessing(
      // subentryManager.performBackendPreInitializationProcessing(
      //        configHandler);
    }
    catch (DirectoryException de)
@@ -6320,6 +6320,11 @@
    {
      try
      {
        for (BackendInitializationListener listener : getBackendInitializationListeners())
        {
          listener.performBackendPreFinalizationProcessing(backend);
        }
        // Deregister all the local backend workflow elements that have been
        // registered with the server.
        LocalBackendWorkflowElement.removeAll();
@@ -6327,7 +6332,7 @@
        for (BackendInitializationListener listener :
             directoryServer.backendInitializationListeners)
        {
          listener.performBackendFinalizationProcessing(backend);
          listener.performBackendPostFinalizationProcessing(backend);
        }
        backend.finalizeBackend();
opendj-server-legacy/src/main/java/org/opends/server/core/GroupManager.java
@@ -580,7 +580,7 @@
   * manager.
   */
  @Override
  public void performBackendInitializationProcessing(Backend<?> backend)
  public void performBackendPreInitializationProcessing(Backend<?> backend)
  {
    InternalClientConnection conn = getRootConnection();
@@ -671,7 +671,7 @@
   * instances associated with entries in the provided backend.
   */
  @Override
  public void performBackendFinalizationProcessing(Backend<?> backend)
  public void performBackendPostFinalizationProcessing(Backend<?> backend)
  {
    lock.writeLock().lock();
    try
@@ -693,6 +693,15 @@
    }
  }
  @Override
  public void performBackendPostInitializationProcessing(Backend<?> backend) {
    // Nothing to do.
  }
  @Override
  public void performBackendPreFinalizationProcessing(Backend<?> backend) {
    // Nothing to do.
  }
  /**
opendj-server-legacy/src/main/java/org/opends/server/core/SubentryManager.java
@@ -300,7 +300,7 @@
   * all subentries that it may contain and register them with this manager.
   */
  @Override
  public void performBackendInitializationProcessing(Backend<?> backend)
  public void performBackendPreInitializationProcessing(Backend<?> backend)
  {
    InternalClientConnection conn = getRootConnection();
    SubentriesControl control = new SubentriesControl(true, true);
@@ -611,7 +611,7 @@
   * all subentries associated with the provided backend.
   */
  @Override
  public void performBackendFinalizationProcessing(Backend<?> backend)
  public void performBackendPostFinalizationProcessing(Backend<?> backend)
  {
    lock.writeLock().lock();
    try
@@ -694,6 +694,16 @@
    }
  }
  @Override
  public void performBackendPostInitializationProcessing(Backend<?> backend) {
    // Nothing to do.
  }
  @Override
  public void performBackendPreFinalizationProcessing(Backend<?> backend) {
    // Nothing to do.
  }
  private void doPostAdd(Entry entry)
  {
    if (entry.isSubentry() || entry.isLDAPSubentry())
opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerSync.java
@@ -222,7 +222,7 @@
  /** {@inheritDoc} */
  @Override
  public void performBackendInitializationProcessing(Backend<?> backend)
  public void performBackendPreInitializationProcessing(Backend<?> backend)
  {
    DN[] baseDNs = backend.getBaseDNs();
    if (baseDNs != null)
@@ -239,11 +239,21 @@
  /** {@inheritDoc} */
  @Override
  public void performBackendFinalizationProcessing(Backend<?> backend)
  public void performBackendPostFinalizationProcessing(Backend<?> backend)
  {
    // No implementation required.
  }
  @Override
  public void performBackendPostInitializationProcessing(Backend<?> backend) {
    // Nothing to do.
  }
  @Override
  public void performBackendPreFinalizationProcessing(Backend<?> backend) {
    // Nothing to do.
  }
  private void handleInternalSearchEntry(SearchResultEntry searchEntry)
       throws DirectoryException
  {
opendj-server-legacy/src/main/java/org/opends/server/extensions/DefaultEntryCache.java
@@ -385,7 +385,7 @@
   *                  about to be put into service.
   */
  @Override
  public void performBackendInitializationProcessing(Backend<?> backend)
  public void performBackendPreInitializationProcessing(Backend<?> backend)
  {
    // Do nothing.
  }
@@ -401,7 +401,7 @@
   *                  and is about to be finalized.
   */
  @Override
  public void performBackendFinalizationProcessing(Backend<?> backend)
  public void performBackendPostFinalizationProcessing(Backend<?> backend)
  {
    // Do not clear any backends if the server is shutting down.
    if (!DirectoryServer.getInstance().isShuttingDown())
@@ -409,4 +409,14 @@
      clearBackend(backend.getBackendID());
    }
  }
  @Override
  public void performBackendPostInitializationProcessing(Backend<?> backend) {
    // Nothing to do.
  }
  @Override
  public void performBackendPreFinalizationProcessing(Backend<?> backend) {
    // Nothing to do.
  }
}
opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java
@@ -64,11 +64,13 @@
import org.opends.server.admin.std.meta.ReplicationDomainCfgDefn.IsolationPolicy;
import org.opends.server.admin.std.server.ExternalChangelogDomainCfg;
import org.opends.server.admin.std.server.ReplicationDomainCfg;
import org.opends.server.api.DirectoryThread;
import org.opends.server.api.SynchronizationProvider;
import org.opends.server.api.AlertGenerator;
import org.opends.server.api.Backend;
import org.opends.server.api.Backend.BackendOperation;
import org.opends.server.api.DirectoryThread;
import org.opends.server.api.SynchronizationProvider;
import org.opends.server.api.BackendInitializationListener;
import org.opends.server.api.ServerShutdownListener;
import org.opends.server.backends.task.Task;
import org.opends.server.core.*;
import org.opends.server.protocols.internal.InternalClientConnection;
@@ -109,7 +111,7 @@
 */
public final class LDAPReplicationDomain extends ReplicationDomain
       implements ConfigurationChangeListener<ReplicationDomainCfg>,
                  AlertGenerator
                  AlertGenerator, BackendInitializationListener, ServerShutdownListener
{
  /**
   * Set of attributes that will return all the user attributes and the
@@ -119,6 +121,26 @@
      newHashSet(HISTORICAL_ATTRIBUTE_NAME, ENTRYUUID_ATTRIBUTE_NAME, "*");
  /**
   * Initializing replication for the domain initiates backend finalization/initialization
   * This flag prevents the Replication Domain to disable/enable itself when
   * it is the event initiator
   */
  private boolean ignoreBackendInitializationEvent;
  private volatile boolean  serverShutdownRequested;
  @Override
  public String getShutdownListenerName() {
    return "LDAPReplicationDomain " + getBaseDN();
  }
  @Override
  public void processServerShutdown(LocalizableMessage reason) {
    serverShutdownRequested = true;
  }
  /**
   * This class is used in the session establishment phase
   * when no Replication Server with all the local changes has been found
   * and we therefore need to recover them.
@@ -168,6 +190,35 @@
    }
  }
  @Override
  public void performBackendPreInitializationProcessing(Backend<?> backend) {
    // Nothing to do
  }
  @Override
  public void performBackendPostFinalizationProcessing(Backend<?> backend) {
    // Nothing to do
  }
  @Override
  public void performBackendPostInitializationProcessing(Backend<?> backend) {
    if (!ignoreBackendInitializationEvent
            && getBackend().getBackendID().equals(backend.getBackendID())) {
      enable();
    }
  }
  @Override
  public void performBackendPreFinalizationProcessing(Backend<?> backend) {
    // Do not disable itself during a shutdown
    // And ignore the event if this replica is the event trigger (e.g. importing).
    if (!ignoreBackendInitializationEvent
            && !serverShutdownRequested
            && getBackend().getBackendID().equals(backend.getBackendID())) {
      disable();
    }
  }
  /** The fully-qualified name of this class. */
  private static final String CLASS_NAME = LDAPReplicationDomain.class.getName();
@@ -482,6 +533,9 @@
    // register as an AlertGenerator
    DirectoryServer.registerAlertGenerator(this);
    DirectoryServer.registerBackendInitializationListener(this);
    DirectoryServer.registerShutdownListener(this);
    startPublishService();
  }
@@ -2198,6 +2252,8 @@
      }
      DirectoryServer.deregisterAlertGenerator(this);
      DirectoryServer.deregisterBackendInitializationListener(this);
      DirectoryServer.deregisterShutdownListener(this);
      // stop the ReplicationDomain
      disableService();
@@ -3456,6 +3512,9 @@
    // Stop saving state
    stateSavingDisabled = true;
    // Prevent the processing of the backend finalisation event as the import will disable the attached backend
    ignoreBackendInitializationEvent = true;
    // FIXME setBackendEnabled should be part of TaskUtils ?
    TaskUtils.disableBackend(backend.getBackendID());
@@ -3582,6 +3641,10 @@
    }
    TaskUtils.enableBackend(backend.getBackendID());
    // Restore the processing of backend finalization events.
    ignoreBackendInitializationEvent = false;
  }
  /**