From 0642bd56015b5571ada7bb38b77844c08b574d4c Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 11 Jul 2014 09:43:38 +0000
Subject: [PATCH] Code cleanup.

---
 opendj3-server-dev/src/server/org/opends/server/replication/server/ServerWriter.java |  121 ++++++++++++++++++++--------------------
 1 files changed, 60 insertions(+), 61 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/replication/server/ServerWriter.java b/opendj3-server-dev/src/server/org/opends/server/replication/server/ServerWriter.java
index 1a3aeb0..b071f99 100644
--- a/opendj3-server-dev/src/server/org/opends/server/replication/server/ServerWriter.java
+++ b/opendj3-server-dev/src/server/org/opends/server/replication/server/ServerWriter.java
@@ -36,6 +36,7 @@
 import org.opends.server.replication.protocol.UpdateMsg;
 
 import static org.opends.messages.ReplicationMessages.*;
+import static org.opends.server.replication.common.ServerStatus.*;
 import static org.opends.server.util.StaticUtils.*;
 
 /**
@@ -94,75 +95,19 @@
     {
       while (true)
       {
-        UpdateMsg update = replicationServerDomain.take(this.handler);
-        if (update == null)
+        final UpdateMsg updateMsg = replicationServerDomain.take(this.handler);
+        if (updateMsg == null)
         {
           // this connection is closing
           errMessage = LocalizableMessage.raw(
            "Connection closure: null update returned by domain.");
           return;
         }
-
-        // Ignore updates in some cases
-        long referenceGenerationId = replicationServerDomain.getGenerationId();
-        if (handler.isDataServer())
+        else if (!isUpdateMsgFiltered(updateMsg))
         {
-          /**
-           * Ignore updates to DS in bad BAD_GENID_STATUS or FULL_UPDATE_STATUS
-           *
-           * The RSD lock should not be taken here as it is acceptable to have a
-           * delay between the time the server has a wrong status and the fact
-           * we detect it: the updates that succeed to pass during this time
-           * will have no impact on remote server. But it is interesting to not
-           * saturate uselessly the network if the updates are not necessary so
-           * this check to stop sending updates is interesting anyway. Not
-           * taking the RSD lock allows to have better performances in normal
-           * mode (most of the time).
-           */
-          ServerStatus dsStatus = handler.getStatus();
-          if (dsStatus == ServerStatus.BAD_GEN_ID_STATUS
-              || dsStatus == ServerStatus.FULL_UPDATE_STATUS)
-          {
-            if (dsStatus == ServerStatus.BAD_GEN_ID_STATUS)
-            {
-              logger.warn(WARN_IGNORING_UPDATE_TO_DS_BADGENID, handler.getReplicationServerId(),
-                  update.getCSN(), handler.getBaseDN(), handler.getServerId(),
-                  session.getReadableRemoteAddress(),
-                  handler.getGenerationId(),
-                  referenceGenerationId);
-            }
-            else if (dsStatus == ServerStatus.FULL_UPDATE_STATUS)
-            {
-              logger.warn(WARN_IGNORING_UPDATE_TO_DS_FULLUP, handler.getReplicationServerId(),
-                  update.getCSN(), handler.getBaseDN(), handler.getServerId(),
-                  session.getReadableRemoteAddress());
-            }
-            continue;
-          }
+          // Publish the update to the remote server using a protocol version it supports
+          session.publish(updateMsg);
         }
-        else
-        {
-          /**
-           * Ignore updates to RS with bad gen id
-           * (no system managed status for a RS)
-           */
-          if (referenceGenerationId != handler.getGenerationId()
-              || referenceGenerationId == -1
-              || handler.getGenerationId() == -1)
-          {
-            logger.error(WARN_IGNORING_UPDATE_TO_RS,
-                handler.getReplicationServerId(),
-                update.getCSN(), handler.getBaseDN(), handler.getServerId(),
-                session.getReadableRemoteAddress(),
-                handler.getGenerationId(),
-                referenceGenerationId);
-            continue;
-          }
-        }
-
-        // Publish the update to the remote server using a protocol version he
-        // it supports
-        session.publish(update);
       }
     }
     catch (SocketException e)
@@ -193,4 +138,58 @@
       }
     }
   }
+
+  private boolean isUpdateMsgFiltered(UpdateMsg updateMsg)
+  {
+    if (handler.isDataServer())
+    {
+      /**
+       * Ignore updates to DS in bad BAD_GENID_STATUS or FULL_UPDATE_STATUS
+       *
+       * The RSD lock should not be taken here as it is acceptable to have a delay
+       * between the time the server has a wrong status and the fact we detect it:
+       * the updates that succeed to pass during this time will have no impact on remote server.
+       * But it is interesting to not saturate uselessly the network
+       * if the updates are not necessary so this check to stop sending updates is interesting anyway.
+       * Not taking the RSD lock allows to have better performances in normal mode (most of the time).
+       */
+      final ServerStatus dsStatus = handler.getStatus();
+      if (dsStatus == BAD_GEN_ID_STATUS)
+      {
+        logger.warn(WARN_IGNORING_UPDATE_TO_DS_BADGENID, handler.getReplicationServerId(),
+            updateMsg.getCSN(), handler.getBaseDN(), handler.getServerId(),
+            session.getReadableRemoteAddress(),
+            handler.getGenerationId(),
+            replicationServerDomain.getGenerationId());
+        return true;
+      }
+      else if (dsStatus == FULL_UPDATE_STATUS)
+      {
+        logger.warn(WARN_IGNORING_UPDATE_TO_DS_FULLUP, handler.getReplicationServerId(),
+            updateMsg.getCSN(), handler.getBaseDN(), handler.getServerId(),
+            session.getReadableRemoteAddress());
+        return true;
+      }
+    }
+    else
+    {
+      /**
+       * Ignore updates to RS with bad gen id
+       * (no system managed status for a RS)
+       */
+      final long referenceGenerationId = replicationServerDomain.getGenerationId();
+      if (referenceGenerationId != handler.getGenerationId()
+          || referenceGenerationId == -1 || handler.getGenerationId() == -1)
+      {
+        logger.error(WARN_IGNORING_UPDATE_TO_RS,
+            handler.getReplicationServerId(),
+            updateMsg.getCSN(), handler.getBaseDN(), handler.getServerId(),
+            session.getReadableRemoteAddress(),
+            handler.getGenerationId(),
+            referenceGenerationId);
+        return true;
+      }
+    }
+    return false;
+  }
 }

--
Gitblit v1.10.0