From 5a92d951296cae7ad72e45f84c92d40a6d41ad40 Mon Sep 17 00:00:00 2001
From: patrick diligent <patrick.diligent@forgerock.com>
Date: Mon, 21 Sep 2015 16:29:34 +0000
Subject: [PATCH] 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.
---
opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java | 69 +++++++++++++++++++++++++++++++++-
1 files changed, 66 insertions(+), 3 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java
index 3b81e76..ba6c5ee 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/LDAPReplicationDomain.java
+++ b/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;
+
}
/**
--
Gitblit v1.10.0