helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [3/7] helix git commit: Prevent ClusterControllerManager from starting multiple times
Date Wed, 04 Oct 2017 01:49:44 GMT
Prevent ClusterControllerManager from starting multiple times

ClusterControllerManager is a runnable wrapper for a Helix Controller that could run on a
separate thread for testing purpose. Since HelixManager.connect() should not be called more
than once, this Controller should not be started more than once, either.


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

Branch: refs/heads/master
Commit: 94f3961842263d04eef89019a1955e4c49e3305c
Parents: d5a2395
Author: Weihan Kong <wkong@linkedin.com>
Authored: Wed Feb 8 23:38:49 2017 -0800
Committer: Junkai Xue <jxue@linkedin.com>
Committed: Tue Oct 3 15:07:52 2017 -0700

----------------------------------------------------------------------
 .../integration/manager/ClusterControllerManager.java    | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/94f39618/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterControllerManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterControllerManager.java
b/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterControllerManager.java
index 9e10771..92ed52b 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterControllerManager.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/ClusterControllerManager.java
@@ -36,6 +36,8 @@ public class ClusterControllerManager extends ZKHelixManager implements
Runnable
   private final CountDownLatch _stopCountDown = new CountDownLatch(1);
   private final CountDownLatch _waitStopFinishCountDown = new CountDownLatch(1);
 
+  private boolean _started = false;
+
   public ClusterControllerManager(String zkAddr, String clusterName) {
     this(zkAddr, clusterName, "controller");
   }
@@ -48,13 +50,20 @@ public class ClusterControllerManager extends ZKHelixManager implements
Runnable
     _stopCountDown.countDown();
     try {
       _waitStopFinishCountDown.await();
+      _started = false;
     } catch (InterruptedException e) {
       LOG.error("Interrupted waiting for finish", e);
     }
   }
 
+  // This should not be called more than once because HelixManager.connect() should not be
called more than once.
   public void syncStart() {
-    // TODO: prevent start multiple times
+    if (_started) {
+      throw new RuntimeException("Helix Controller already started. Do not call syncStart()
more than once.");
+    } else {
+      _started = true;
+    }
+
     new Thread(this).start();
     try {
       _startCountDown.await();


Mime
View raw message