You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2011/06/05 05:32:14 UTC

svn commit: r1131631 - /incubator/mesos/trunk/src/slave.cpp

Author: benh
Date: Sun Jun  5 03:32:13 2011
New Revision: 1131631

URL: http://svn.apache.org/viewvc?rev=1131631&view=rev
Log:
Updated ZooKeeper support to allow a slave to start before the master.

Modified:
    incubator/mesos/trunk/src/slave.cpp

Modified: incubator/mesos/trunk/src/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave.cpp?rev=1131631&r1=1131630&r2=1131631&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave.cpp Sun Jun  5 03:32:13 2011
@@ -48,15 +48,27 @@ private:
 public:
   void process(ZooKeeper *zk, int type, int state, const string &path)
   {
-    if ((state == ZOO_CONNECTED_STATE) && (type == ZOO_SESSION_EVENT)) {
-      // Lookup master.
+    if ((state == ZOO_CONNECTED_STATE) &&
+	((type == ZOO_SESSION_EVENT) || (type == ZOO_CREATED_EVENT))) {
+      // Lookup master PID.
       string znode = "/home/nexus/master";
-      string result;
-      int ret = zk->get(znode, false, &result, NULL);
+      int ret;
+
+      // Check if znode exists, if not, just return and wait.
+      ret = zk->exists(znode, true, NULL);
+
+      if (ret == ZNONODE)
+	return;
 
       if (ret != ZOK)
 	fatal("failed to get %s! (%s)", znode.c_str(), zerror(ret));
 
+      string result;
+      ret = zk->get(znode, false, &result, NULL);
+    
+      if (ret != ZOK)
+	fatal("failed to get %s! (%s)", znode.c_str(), zerror(ret));
+
       PID master;
 
       istringstream iss(result);