From 991178c44056e8dd7ed0df74cb0a54b9b84ac785 Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Thu, 27 May 2010 14:47:42 +0000
Subject: [PATCH] Fix issue #4384, a performance problem in replication monitoring

---
 opendj-sdk/opends/src/server/org/opends/server/replication/server/DataServerHandler.java                              |    2 
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/service/ReplicationDomainTest.java |   17 +++++---
 opendj-sdk/opends/src/server/org/opends/server/replication/server/MonitoringPublisher.java                            |    4 +-
 opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java                        |   35 +++++++++++++----
 opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServerHandler.java                       |    2 
 opendj-sdk/opends/src/server/org/opends/server/replication/server/LightweightServerHandler.java                       |    4 +-
 6 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/server/DataServerHandler.java b/opendj-sdk/opends/src/server/org/opends/server/replication/server/DataServerHandler.java
index 272b583..f4ed036 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/server/DataServerHandler.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/server/DataServerHandler.java
@@ -309,7 +309,7 @@
 
     try
     {
-      MonitorData md = replicationServerDomain.computeMonitorData();
+      MonitorData md = replicationServerDomain.computeMonitorData(true);
 
       // Oldest missing update
       Long approxFirstMissingDate = md.getApproxFirstMissingDate(serverId);
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/server/LightweightServerHandler.java b/opendj-sdk/opends/src/server/org/opends/server/replication/server/LightweightServerHandler.java
index e3b4ffc..d2a5a4d 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/server/LightweightServerHandler.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/server/LightweightServerHandler.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008-2009 Sun Microsystems, Inc.
+ *      Copyright 2008-2010 Sun Microsystems, Inc.
  */
 package org.opends.server.replication.server;
 
@@ -269,7 +269,7 @@
     MonitorData md;
     try
     {
-      md = rsDomain.computeMonitorData();
+      md = rsDomain.computeMonitorData(true);
 
       ServerState remoteState = md.getLDAPServerState(serverId);
       if (remoteState == null)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/server/MonitoringPublisher.java b/opendj-sdk/opends/src/server/org/opends/server/replication/server/MonitoringPublisher.java
index eb773bf..71c652a 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/server/MonitoringPublisher.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/server/MonitoringPublisher.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2009 Sun Microsystems, Inc.
+ *      Copyright 2009-2010 Sun Microsystems, Inc.
  */
 package org.opends.server.replication.server;
 
@@ -110,7 +110,7 @@
 
       // Send global topology information to peer DSs
       MonitorMsg monitorMsg =
-        replicationServerDomain.createGlobalTopologyMonitorMsg(0, 0);
+        replicationServerDomain.createGlobalTopologyMonitorMsg(0, 0, true);
       int localServerId =
           replicationServerDomain.getReplicationServer().getServerId();
       if (monitorMsg != null)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java b/opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
index 46a9031..e92d185 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServerDomain.java
@@ -1615,8 +1615,8 @@
         {
           // Monitoring information requested by a DS
           MonitorMsg monitorMsg =
-            createGlobalTopologyMonitorMsg(msg.getDestination(),
-            msg.getsenderID());
+            createGlobalTopologyMonitorMsg(
+                msg.getDestination(), msg.getsenderID(), false);
 
            if (monitorMsg != null)
           {
@@ -1763,10 +1763,18 @@
    * whole topology.
    * @param sender The sender of this message.
    * @param destination The destination of this message.
+   * @param  updateMonitorData A boolean indicating if the monitor data should
+   *                           be updated. If false the last monitoring data
+   *                           that was computed will be returned. This is
+   *                           acceptable for most cases because the monitoring
+   *                           thread computes the monitoring data frequently.
+   *                           If true is used the calling thread may be
+   *                           blocked for a while.
    * @return The newly created and filled MonitorMsg. Null if a problem occurred
    * during message creation.
    */
-  public MonitorMsg createGlobalTopologyMonitorMsg(int sender, int destination)
+  public MonitorMsg createGlobalTopologyMonitorMsg(
+      int sender, int destination, boolean updateMonitorData)
   {
     MonitorMsg returnMsg =
       new MonitorMsg(sender, destination);
@@ -1776,7 +1784,7 @@
       returnMsg.setReplServerDbState(getDbServerState());
       // Update the information we have about all servers
       // in the topology.
-      MonitorData md = computeMonitorData();
+      MonitorData md = computeMonitorData(updateMonitorData);
 
       // Add the informations about the Replicas currently in
       // the topology.
@@ -2549,14 +2557,25 @@
    */
   /**
    * Retrieves the global monitor data.
+   * @param  updateMonitorData A boolean indicating if the monitor data should
+   *                           be updated. If false the last monitoring data
+   *                           that was computed will be returned. This is
+   *                           acceptable for most cases because the monitoring
+   *                           thread computes the monitoring data frequently.
+   *                           If true is used the calling thread may be
+   *                           blocked for a while.
    * @return The monitor data.
    * @throws DirectoryException When an error occurs.
    */
-  synchronized protected MonitorData computeMonitorData()
+  synchronized protected MonitorData computeMonitorData(
+      boolean updateMonitorData)
     throws DirectoryException
   {
-    // Update the monitorData of ALL domains if this was necessary.
-    replicationServer.computeMonitorData();
+    if (updateMonitorData)
+    {
+      // Update the monitorData of ALL domains if this was necessary.
+      replicationServer.computeMonitorData();
+    }
 
     // Returns the monitorData of THIS domain
     return monitorData;
@@ -3053,7 +3072,7 @@
 
     try
     {
-      MonitorData md = computeMonitorData();
+      MonitorData md = computeMonitorData(true);
 
       // Missing changes
       long missingChanges =
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServerHandler.java b/opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServerHandler.java
index db31ee0..d98d333 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServerHandler.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServerHandler.java
@@ -780,7 +780,7 @@
     try
     {
       MonitorData md;
-      md = replicationServerDomain.computeMonitorData();
+      md = replicationServerDomain.computeMonitorData(true);
 
       // Missing changes
       long missingChanges = md.getMissingChangesRS(serverId);
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/service/ReplicationDomainTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/service/ReplicationDomainTest.java
index 6991dcc..756297a 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/service/ReplicationDomainTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/service/ReplicationDomainTest.java
@@ -197,6 +197,16 @@
               assertTrue(serverInfo.getStatus() == ServerStatus.NORMAL_STATUS);
             }
           }
+
+          Map<Integer, ServerState> states1 = domain1.getReplicaStates();
+          ServerState state2 = states1.get(domain2ServerId);
+          assertNotNull(state2, "getReplicaStates is not showing DS2");
+
+          Map<Integer, ServerState> states2 = domain2.getReplicaStates();
+          ServerState state1 = states2.get(domain1ServerId);
+          assertNotNull(state1, "getReplicaStates is not showing DS1");
+
+          // if we reach this point all tests are OK
           break;
         }
         catch (AssertionError e)
@@ -210,13 +220,6 @@
             throw e;
         }
       }
-      Map<Integer, ServerState> states1 = domain1.getReplicaStates();
-      ServerState state2 = states1.get(domain2ServerId);
-      assertNotNull(state2, "getReplicaStates is not showing DS2");
-
-      Map<Integer, ServerState> states2 = domain2.getReplicaStates();
-      ServerState state1 = states2.get(domain1ServerId);
-      assertNotNull(state1, "getReplicaStates is not showing DS1");
 
     }
     finally

--
Gitblit v1.10.0