helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject [1/2] git commit: [HELIX-471] Unregister ResourceMonitor on drop
Date Wed, 16 Jul 2014 19:58:13 GMT
Repository: helix
Updated Branches:
  refs/heads/master 6159d8fb4 -> f952cb760


[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/8f90279b
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/8f90279b
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/8f90279b

Branch: refs/heads/master
Commit: 8f90279b062408e08c17aa5473d41506f3e39ba3
Parents: 6159d8f
Author: Kanak Biscuitwala <kanak@apache.org>
Authored: Fri Jul 11 16:12:34 2014 -0700
Committer: Kanak Biscuitwala <kanak@apache.org>
Committed: Wed Jul 16 12:54:11 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/8f90279b/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 b540504..fc247a6 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
@@ -130,6 +130,9 @@ public class ExternalViewComputeStage extends AbstractBaseStage {
           clusterStatusMonitor.setResourceStatus(view,
               cache._idealStateMap.get(view.getResourceName()), stateModelDef);
         }
+      } 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/8f90279b/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 9ea51b1..8249b4c 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,
       StateModelDefinition stateModelDef) {
     String topState = null;

http://git-wip-us.apache.org/repos/asf/helix/blob/8f90279b/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..7c4a094
--- /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(2000);
+    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(2000);
+    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));
+  }
+}


Mime
View raw message