You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ka...@apache.org on 2014/07/15 20:19:30 UTC

git commit: [HELIX-471] Unregister ResourceMonitor on drop

Repository: helix
Updated Branches:
  refs/heads/helix-0.6.2-release 450d9fea9 -> 521893217


[HELIX-471] Unregister ResourceMonitor on drop


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/52189321
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/52189321
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/52189321

Branch: refs/heads/helix-0.6.2-release
Commit: 521893217ba149f9fb659e9448836cf83e154e86
Parents: 450d9fe
Author: Kanak Biscuitwala <ka...@apache.org>
Authored: Fri Jul 11 16:12:34 2014 -0700
Committer: Kanak Biscuitwala <ka...@apache.org>
Committed: Fri Jul 11 16:12:34 2014 -0700

----------------------------------------------------------------------
 .../stages/ExternalViewComputeStage.java        |   3 +
 .../monitoring/mbeans/ClusterStatusMonitor.java |  18 ++++
 .../mbeans/TestDropResourceMetricsReset.java    | 106 +++++++++++++++++++
 3 files changed, 127 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/52189321/helix-core/src/main/java/org/apache/helix/controller/stages/ExternalViewComputeStage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/ExternalViewComputeStage.java b/helix-core/src/main/java/org/apache/helix/controller/stages/ExternalViewComputeStage.java
index f427f3d..008b116 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/stages/ExternalViewComputeStage.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/stages/ExternalViewComputeStage.java
@@ -113,6 +113,9 @@ public class ExternalViewComputeStage extends AbstractBaseStage {
           clusterStatusMonitor.setResourceStatus(view,
               cache._idealStateMap.get(view.getResourceName()));
         }
+      } else {
+        // Drop the metrics for the dropped resource
+        clusterStatusMonitor.unregisterResource(view.getResourceName());
       }
 
       // compare the new external view with current one, set only on different

http://git-wip-us.apache.org/repos/asf/helix/blob/52189321/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/ClusterStatusMonitor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/ClusterStatusMonitor.java b/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/ClusterStatusMonitor.java
index 5389e76..4270fe7 100644
--- a/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/ClusterStatusMonitor.java
+++ b/helix-core/src/main/java/org/apache/helix/monitoring/mbeans/ClusterStatusMonitor.java
@@ -312,6 +312,24 @@ public class ClusterStatusMonitor implements ClusterStatusMonitorMBean {
     }
   }
 
+  /**
+   * Indicate that a resource has been dropped, thus making it OK to drop its metrics
+   * @param resourceName the resource that has been dropped
+   */
+  public void unregisterResource(String resourceName) {
+    if (_resourceMbeanMap.containsKey(resourceName)) {
+      synchronized (this) {
+        if (_resourceMbeanMap.containsKey(resourceName)) {
+          try {
+            unregisterResources(Arrays.asList(resourceName));
+          } catch (MalformedObjectNameException e) {
+            LOG.error("Could not unregister beans for " + resourceName, e);
+          }
+        }
+      }
+    }
+  }
+
   public void setResourceStatus(ExternalView externalView, IdealState idealState) {
     try {
       String resourceName = externalView.getId();

http://git-wip-us.apache.org/repos/asf/helix/blob/52189321/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java b/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java
new file mode 100644
index 0000000..850294d
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java
@@ -0,0 +1,106 @@
+package org.apache.helix.monitoring.mbeans;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.lang.management.ManagementFactory;
+import java.util.Date;
+
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.helix.TestHelper;
+import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.integration.manager.ClusterControllerManager;
+import org.apache.helix.integration.manager.MockParticipantManager;
+import org.apache.helix.model.IdealState.RebalanceMode;
+import org.apache.helix.tools.ClusterSetup;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TestDropResourceMetricsReset extends ZkUnitTestBase {
+  private static final MBeanServerConnection SERVER = ManagementFactory.getPlatformMBeanServer();
+
+  @Test
+  public void testBasic() throws Exception {
+    final int NUM_PARTICIPANTS = 4;
+    final int NUM_PARTITIONS = 64;
+    final int NUM_REPLICAS = 1;
+    final String RESOURCE_NAME = "TestDB0";
+
+    String className = TestHelper.getTestClassName();
+    String methodName = TestHelper.getTestMethodName();
+    String clusterName = className + "_" + methodName;
+    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
+
+    // Set up cluster
+    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+        "localhost", // participant name prefix
+        "TestDB", // resource name prefix
+        1, // resources
+        NUM_PARTITIONS, // partitions per resource
+        NUM_PARTICIPANTS, // number of nodes
+        NUM_REPLICAS, // replicas
+        "MasterSlave", RebalanceMode.FULL_AUTO, // use FULL_AUTO mode to test node tagging
+        true); // do rebalance
+
+    // Start participants and controller
+    ClusterSetup setupTool = new ClusterSetup(_gZkClient);
+    MockParticipantManager[] participants = new MockParticipantManager[NUM_PARTICIPANTS];
+    for (int i = 0; i < NUM_PARTICIPANTS; i++) {
+      participants[i] =
+          new MockParticipantManager(ZK_ADDR, clusterName, "localhost_" + (12918 + i));
+      participants[i].syncStart();
+    }
+    ClusterControllerManager controller =
+        new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
+    controller.syncStart();
+
+    // Verify that the bean was created
+    Thread.sleep(1000);
+    ObjectName objectName = getObjectName(RESOURCE_NAME, clusterName);
+    Assert.assertTrue(SERVER.isRegistered(objectName));
+
+    // Drop the resource
+    setupTool.dropResourceFromCluster(clusterName, RESOURCE_NAME);
+
+    // Verify that the bean was removed
+    Thread.sleep(1000);
+    Assert.assertFalse(SERVER.isRegistered(objectName));
+
+    // Clean up
+    controller.syncStop();
+    for (MockParticipantManager participant : participants) {
+      participant.syncStop();
+    }
+    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
+  }
+
+  private ObjectName getObjectName(String resourceName, String clusterName)
+      throws MalformedObjectNameException {
+    String clusterBeanName =
+        String.format("%s=%s", ClusterStatusMonitor.CLUSTER_DN_KEY, clusterName);
+    String resourceBeanName =
+        String.format("%s,%s=%s", clusterBeanName, ClusterStatusMonitor.RESOURCE_DN_KEY,
+            resourceName);
+    return new ObjectName(String.format("%s: %s", ClusterStatusMonitor.CLUSTER_STATUS_KEY,
+        resourceBeanName));
+  }
+}