You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2014/01/15 23:10:44 UTC

git commit: Added an option to StartMaster() wait for leader election result before returning.

Updated Branches:
  refs/heads/master bef470090 -> 054154b75


Added an option to StartMaster() wait for leader election result before
returning.

From: Jiang Yan Xu <ya...@jxu.me>
Review: https://reviews.apache.org/r/16742


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

Branch: refs/heads/master
Commit: 054154b757f6a147f927703eb9cdeb9b59e0fa5f
Parents: bef4700
Author: Vinod Kone <vi...@twitter.com>
Authored: Wed Jan 15 14:03:20 2014 -0800
Committer: Vinod Kone <vi...@twitter.com>
Committed: Wed Jan 15 14:03:20 2014 -0800

----------------------------------------------------------------------
 src/master/master.hpp |  7 ++++---
 src/tests/mesos.cpp   | 36 ++++++++++++++++++++++++++++++++----
 src/tests/mesos.hpp   | 16 ++++++++++++++--
 3 files changed, 50 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/054154b7/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 6e89149..18a6cc4 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -173,6 +173,10 @@ public:
       const process::UPID& from,
       const process::UPID& pid);
 
+  // Invoked when there is a newly elected leading master.
+  // Made public for testing purposes.
+  void detected(const Future<Option<UPID> >& pid);
+
 protected:
   virtual void initialize();
   virtual void finalize();
@@ -200,9 +204,6 @@ protected:
   // Invoked when the contender has lost the candidacy.
   void lostCandidacy(const Future<Nothing>& lost);
 
-  // Invoked when there is a newly elected leading master.
-  void detected(const Future<Option<UPID> >& pid);
-
   // Process a launch tasks request (for a non-cancelled offer) by
   // launching the desired tasks (if the offer contains a valid set of
   // tasks) and reporting any unused resources to the allocator.

http://git-wip-us.apache.org/repos/asf/mesos/blob/054154b7/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index 5359394..1b1b4cc 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -15,6 +15,8 @@
 
 using namespace process;
 
+using testing::_;
+
 namespace mesos {
 namespace internal {
 namespace tests {
@@ -73,19 +75,45 @@ slave::Flags MesosTest::CreateSlaveFlags()
 
 
 Try<process::PID<master::Master> > MesosTest::StartMaster(
-    const Option<master::Flags>& flags)
+    const Option<master::Flags>& flags,
+    bool wait)
 {
-  return cluster.masters.start(
+  Future<Nothing> detected = FUTURE_DISPATCH(_, &master::Master::detected);
+
+  Try<process::PID<master::Master> > master = cluster.masters.start(
       flags.isNone() ? CreateMasterFlags() : flags.get());
+
+  // Wait until the leader is detected because otherwise this master
+  // may reject authentication requests because it doesn't know it's
+  // the leader yet [MESOS-881].
+  if (wait && master.isSome() && !detected.await(Seconds(10))) {
+    return Error("Failed to wait " + stringify(Seconds(10)) +
+                 " for master to detect the leader");
+  }
+
+  return master;
 }
 
 
 Try<process::PID<master::Master> > MesosTest::StartMaster(
     master::allocator::AllocatorProcess* allocator,
-    const Option<master::Flags>& flags)
+    const Option<master::Flags>& flags,
+    bool wait)
 {
-  return cluster.masters.start(
+  Future<Nothing> detected = FUTURE_DISPATCH(_, &master::Master::detected);
+
+  Try<process::PID<master::Master> > master = cluster.masters.start(
       allocator, flags.isNone() ? CreateMasterFlags() : flags.get());
+
+  // Wait until the leader is detected because otherwise this master
+  // may reject authentication requests because it doesn't know it's
+  // the leader yet [MESOS-881].
+  if (wait && master.isSome() && !detected.await(Seconds(10))) {
+    return Error("Failed to wait " + stringify(Seconds(10)) +
+                 " for master to detect the leader");
+  }
+
+  return master;
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/054154b7/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index b1239a6..d7bdaee 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -79,13 +79,25 @@ protected:
   virtual slave::Flags CreateSlaveFlags();
 
   // Starts a master with the specified flags.
+  // Waits for the master to detect a leader (could be itself) before
+  // returning if 'wait' is set to true.
+  // TODO(xujyan): Return a future which becomes ready when the
+  // master detects a leader (when wait == true) and have the tests
+  // do AWAIT_READY.
   virtual Try<process::PID<master::Master> > StartMaster(
-      const Option<master::Flags>& flags = None());
+      const Option<master::Flags>& flags = None(),
+      bool wait = true);
 
   // Starts a master with the specified allocator process and flags.
+  // Waits for the master to detect a leader (could be itself) before
+  // returning if 'wait' is set to true.
+  // TODO(xujyan): Return a future which becomes ready when the
+  // master detects a leader (when wait == true) and have the tests
+  // do AWAIT_READY.
   virtual Try<process::PID<master::Master> > StartMaster(
       master::allocator::AllocatorProcess* allocator,
-      const Option<master::Flags>& flags = None());
+      const Option<master::Flags>& flags = None(),
+      bool wait = true);
 
   // Starts a slave with the specified flags.
   virtual Try<process::PID<slave::Slave> > StartSlave(