From 41bef7c0b619c7bc925326451a56071b5736580a Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 19 Jun 2013 08:36:16 +0000
Subject: [PATCH] Fix OPENDJ-986: Exception when reading messages from Replication server RS

---
 opends/src/server/org/opends/server/replication/server/ECLServerHandler.java |   78 ++++++++++++++------------------------
 1 files changed, 29 insertions(+), 49 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/server/ECLServerHandler.java b/opends/src/server/org/opends/server/replication/server/ECLServerHandler.java
index 69663a1..4e35589 100644
--- a/opends/src/server/org/opends/server/replication/server/ECLServerHandler.java
+++ b/opends/src/server/org/opends/server/replication/server/ECLServerHandler.java
@@ -30,6 +30,7 @@
 import static org.opends.messages.ReplicationMessages.*;
 import static org.opends.server.loggers.ErrorLogger.logError;
 import static org.opends.server.loggers.debug.DebugLogger.debugEnabled;
+import static org.opends.server.replication.protocol.ProtocolVersion.*;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -325,13 +326,12 @@
   {
     try
     {
-      protocolVersion = ProtocolVersion.minWithCurrent(
-          inECLStartMsg.getVersion());
-      generationId = inECLStartMsg.getGenerationId();
+      session.setProtocolVersion(getCompatibleVersion(inECLStartMsg
+          .getVersion()));
       serverURL = inECLStartMsg.getServerURL();
       setInitialServerState(inECLStartMsg.getServerState());
       setSendWindowSize(inECLStartMsg.getWindowSize());
-      if (protocolVersion > ProtocolVersion.REPLICATION_PROTOCOL_V1)
+      if (getProtocolVersion() > ProtocolVersion.REPLICATION_PROTOCOL_V1)
       {
         // We support connection from a V1 RS
         // Only V2 protocol has the group id in repl server start message
@@ -347,59 +347,38 @@
   }
 
   /**
-   * Send the ReplServerStartDSMsg to the remote ECL server.
-   * @param requestedProtocolVersion The provided protocol version.
+   * Sends a start message to the remote ECL server.
+   *
    * @return The StartMsg sent.
-   * @throws IOException When an exception occurs.
+   * @throws IOException
+   *           When an exception occurs.
    */
-  private StartMsg sendStartToRemote(short requestedProtocolVersion)
-  throws IOException
+  private StartMsg sendStartToRemote() throws IOException
   {
+    final StartMsg startMsg;
+
     // Before V4 protocol, we sent a ReplServerStartMsg
-    if (protocolVersion < ProtocolVersion.REPLICATION_PROTOCOL_V4)
+    if (getProtocolVersion() < ProtocolVersion.REPLICATION_PROTOCOL_V4)
     {
-
       // Peer DS uses protocol < V4 : send it a ReplServerStartMsg
-      ReplServerStartMsg outReplServerStartMsg
-      = new ReplServerStartMsg(
-          replicationServerId,
-          replicationServerURL,
-          getServiceId(),
-          maxRcvWindow,
+      startMsg = new ReplServerStartMsg(replicationServerId,
+          replicationServerURL, getServiceId(), maxRcvWindow,
           replicationServerDomain.getDbServerState(),
-          protocolVersion,
-          localGenerationId,
-          sslEncryption,
-          getLocalGroupId(),
-          replicationServerDomain.
-          getReplicationServer().getDegradedStatusThreshold());
-
-      session.publish(outReplServerStartMsg, requestedProtocolVersion);
-
-      return outReplServerStartMsg;
+          localGenerationId, sslEncryption, getLocalGroupId(),
+          replicationServerDomain.getReplicationServer()
+              .getDegradedStatusThreshold());
     }
     else
     {
       // Peer DS uses protocol V4 : send it a ReplServerStartDSMsg
-      ReplServerStartDSMsg outReplServerStartDSMsg
-      = new ReplServerStartDSMsg(
-          replicationServerId,
-          replicationServerURL,
-          getServiceId(),
-          maxRcvWindow,
-          new ServerState(),
-          protocolVersion,
-          localGenerationId,
-          sslEncryption,
-          getLocalGroupId(),
-          0,
-          replicationServer.getWeight(),
-          0);
-
-
-      session.publish(outReplServerStartDSMsg);
-      return outReplServerStartDSMsg;
+      startMsg = new ReplServerStartDSMsg(replicationServerId,
+          replicationServerURL, getServiceId(), maxRcvWindow,
+          new ServerState(), localGenerationId, sslEncryption,
+          getLocalGroupId(), 0, replicationServer.getWeight(), 0);
     }
+
+    send(startMsg);
+    return startMsg;
   }
 
   /**
@@ -476,14 +455,15 @@
         processStartFromRemote(inECLStartMsg);
 
       // lock with timeout
-      if (this.replicationServerDomain != null)
+      if (replicationServerDomain != null)
+      {
         lockDomain(true);
+      }
 
-      this.localGenerationId = -1;
+      localGenerationId = -1;
 
       // send start to remote
-      StartMsg outStartMsg =
-        sendStartToRemote(protocolVersion);
+      StartMsg outStartMsg = sendStartToRemote();
 
       // log
       logStartHandshakeRCVandSND(inECLStartMsg, outStartMsg);

--
Gitblit v1.10.0