From 2d735189c834108a2e5f7a795610372eb6d00aed Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Tue, 03 Jun 2014 08:45:08 +0000
Subject: [PATCH] OPENDJ-1467 : File Based Changelog must support replicas temporarily leaving the topology
---
opends/src/server/org/opends/server/replication/server/changelog/je/ReplicationDbEnv.java | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/opends/src/server/org/opends/server/replication/server/changelog/je/ReplicationDbEnv.java b/opends/src/server/org/opends/server/replication/server/changelog/je/ReplicationDbEnv.java
index c259985..df5d0c6 100644
--- a/opends/src/server/org/opends/server/replication/server/changelog/je/ReplicationDbEnv.java
+++ b/opends/src/server/org/opends/server/replication/server/changelog/je/ReplicationDbEnv.java
@@ -505,14 +505,32 @@
*/
static Entry<byte[], byte[]> toReplicaOfflineEntry(DN baseDN, CSN offlineCSN)
{
- final byte[] key =
- toBytes(OFFLINE_TAG + FIELD_SEPARATOR + offlineCSN.getServerId()
- + FIELD_SEPARATOR + baseDN.toNormalizedString());
+ final byte[] key = toReplicaOfflineKey(baseDN, offlineCSN.getServerId());
final ByteStringBuilder data = new ByteStringBuilder(8); // store a long
data.append(offlineCSN.getTime());
return new SimpleImmutableEntry<byte[], byte[]>(key, data.toByteArray());
}
+ /**
+ * Return the key for a replica offline entry in the changelog state database.
+ *
+ * @param baseDN
+ * the replica's baseDN
+ * @param serverId
+ * the replica's serverId
+ * @return the key used in the database to store offline time of the replica
+ */
+ private static byte[] toReplicaOfflineKey(DN baseDN, int serverId)
+ {
+ return toBytes(OFFLINE_TAG + FIELD_SEPARATOR + serverId + FIELD_SEPARATOR + baseDN.toNormalizedString());
+ }
+
+ /** Returns an entry with the provided key and a null value. */
+ private SimpleImmutableEntry<byte[], byte[]> toEntryWithNullValue(byte[] key)
+ {
+ return new SimpleImmutableEntry<byte[], byte[]>(key, null);
+ }
+
private void putInChangelogStateDBIfNotExist(Entry<byte[], byte[]> entry)
throws ChangelogException, RuntimeException
{
@@ -689,7 +707,9 @@
}
/**
- * Add the information about an offline replica to the changelog state DB.
+ * Notify that replica is offline.
+ * <p>
+ * This information is stored in the changelog state DB.
*
* @param baseDN
* the domain of the offline replica
@@ -698,7 +718,7 @@
* @throws ChangelogException
* if a database problem occurred
*/
- public void addOfflineReplica(DN baseDN, CSN offlineCSN)
+ public void notifyReplicaOffline(DN baseDN, CSN offlineCSN)
throws ChangelogException
{
// just overwrite any older entry as it is assumed a newly received offline
@@ -707,6 +727,25 @@
"replicaOffline(baseDN=" + baseDN + ", offlineCSN=" + offlineCSN + ")");
}
+ /**
+ * Notify that replica is online.
+ * <p>
+ * Update the changelog state DB if necessary (ie, replica was known to be
+ * offline).
+ *
+ * @param baseDN
+ * the domain of replica
+ * @param serverId
+ * the serverId of replica
+ * @throws ChangelogException
+ * if a database problem occurred
+ */
+ public void notifyReplicaOnline(DN baseDN, int serverId) throws ChangelogException
+ {
+ deleteFromChangelogStateDB(toEntryWithNullValue(toReplicaOfflineKey(baseDN, serverId)),
+ "removeOfflineReplica(baseDN=" + baseDN + ", serverId=" + serverId + ")");
+ }
+
private void putInChangelogStateDB(Entry<byte[], byte[]> entry,
String methodInvocation) throws ChangelogException
{
--
Gitblit v1.10.0