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 07:25:55 UTC

svn commit: r1131755 - in /incubator/mesos/trunk: configure.twitter src/config.hpp.in src/master.cpp src/master_detector.cpp src/master_main.cpp src/slave.cpp src/third_party/libprocess/process.cpp src/zookeeper.cpp

Author: benh
Date: Sun Jun  5 05:25:55 2011
New Revision: 1131755

URL: http://svn.apache.org/viewvc?rev=1131755&view=rev
Log:
Updates to get fail-over working correctly ... see details in diff.

Modified:
    incubator/mesos/trunk/configure.twitter
    incubator/mesos/trunk/src/config.hpp.in
    incubator/mesos/trunk/src/master.cpp
    incubator/mesos/trunk/src/master_detector.cpp
    incubator/mesos/trunk/src/master_main.cpp
    incubator/mesos/trunk/src/slave.cpp
    incubator/mesos/trunk/src/third_party/libprocess/process.cpp
    incubator/mesos/trunk/src/zookeeper.cpp

Modified: incubator/mesos/trunk/configure.twitter
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/configure.twitter?rev=1131755&r1=1131754&r2=1131755&view=diff
==============================================================================
--- incubator/mesos/trunk/configure.twitter (original)
+++ incubator/mesos/trunk/configure.twitter Sun Jun  5 05:25:55 2011
@@ -16,5 +16,4 @@ LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" 
   --with-python-headers=/usr/include/python2.6 \
   --with-ruby-headers=/opt/local/lib/ruby/1.8/x86_64-linux \
   --with-java-home=/usr/java/default \
-  --with-webui \
-  --with-zookeeper $@
+  --with-webui $@

Modified: incubator/mesos/trunk/src/config.hpp.in
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/config.hpp.in?rev=1131755&r1=1131754&r2=1131755&view=diff
==============================================================================
--- incubator/mesos/trunk/src/config.hpp.in (original)
+++ incubator/mesos/trunk/src/config.hpp.in Sun Jun  5 05:25:55 2011
@@ -6,7 +6,7 @@
 #include <string>
 
 /* Constants. */
-const std::string ZNODE = "/nxmaster";
+const std::string ZNODE = "/usr/benh/nexus";
 
 #if @WITH_WEBUI@
   #define NEXUS_WEBUI

Modified: incubator/mesos/trunk/src/master.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master.cpp?rev=1131755&r1=1131754&r2=1131755&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master.cpp (original)
+++ incubator/mesos/trunk/src/master.cpp Sun Jun  5 05:25:55 2011
@@ -295,6 +295,8 @@ void Master::operator () ()
     send(self(), pack<GOT_MASTER_SEQ>("0"));
   }
 
+  std::cout << "before here" << std::endl;
+
   // Don't do anything until we get a sequence identifier.
   bool waitingForSeq = true;
   do {
@@ -317,9 +319,21 @@ void Master::operator () ()
   link(spawn(new AllocatorTimer(self())));
   //link(spawn(new SharesPrinter(self())));
 
+  std::cout << "here" << std::endl;
+
   while (true) {
     switch (receive()) {
 
+    case NEW_MASTER_DETECTED: {
+      LOG(INFO) << "new master detected ... maybe it's us!";
+      break;
+    }
+
+    case NO_MASTER_DETECTED: {
+      LOG(INFO) << "no master detected ... maybe we're next!";
+      break;
+    }
+
     case F2M_REGISTER_FRAMEWORK: {
       FrameworkID fid = lexical_cast<string>(masterId) + "-" + lexical_cast<string>(nextFrameworkId++);
 

Modified: incubator/mesos/trunk/src/master_detector.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master_detector.cpp?rev=1131755&r1=1131754&r2=1131755&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master_detector.cpp (original)
+++ incubator/mesos/trunk/src/master_detector.cpp Sun Jun  5 05:25:55 2011
@@ -45,13 +45,21 @@ void MasterDetector::process(ZooKeeper *
   static const string delimiter = "/";
 
   if ((state == ZOO_CONNECTED_STATE) && (type == ZOO_SESSION_EVENT)) {
+    // Assume the znode that was created does not end with a "/".
+    CHECK(znode.at(znode.length() - 1) != '/');
+
     // Create directory path znodes as necessary.
     size_t index = znode.find(delimiter, 0);
+
     while (index < string::npos) {
-      index = znode.find(delimiter, index+1);
+      // Get out the prefix to create.
+      index = znode.find(delimiter, index + 1);
       string prefix = znode.substr(0, index);
+
+      // Create the node (even if it already exists).
       ret = zk->create(prefix, "", ZOO_CREATOR_ALL_ACL,
 		       0, &result);
+
       if (ret != ZOK && ret != ZNODEEXISTS)
 	fatal("failed to create ZooKeeper znode! (%s)", zk->error(ret));
     }
@@ -66,7 +74,7 @@ void MasterDetector::process(ZooKeeper *
 
     if (contend) {
       // We use the contend with the pid given in constructor.
-      ret = zk->create(znode, pid, ZOO_CREATOR_ALL_ACL,
+      ret = zk->create(znode + "/", pid, ZOO_CREATOR_ALL_ACL,
 		       ZOO_SEQUENCE | ZOO_EPHEMERAL, &result);
 
       if (ret != ZOK)
@@ -82,8 +90,11 @@ void MasterDetector::process(ZooKeeper *
       Process::post(pid, GOT_MASTER_SEQ, s.data(), s.size());
     }
 
+    // Now determine who the master is (it may be us).
     detectMaster();
   } else if ((state == ZOO_CONNECTED_STATE) && (type == ZOO_CHILD_EVENT)) {
+    // A new master might have showed up and created a sequence
+    // identifier or a master may have died, determine who the master is now!
     detectMaster();
   } else {
     LOG(INFO) << "Unimplemented watch event: (state is "
@@ -102,7 +113,7 @@ void MasterDetector::detectMaster()
     LOG(ERROR) << "failed to get masters: " << zk->error(ret);
   else
     LOG(INFO) << "found " << results.size() << " registered masters";
-  
+
   string masterSeq;
   long min = LONG_MAX;
   foreach (const string &result, results) {
@@ -144,7 +155,7 @@ PID MasterDetector::lookupMasterPID(cons
   int ret;
   string result;
 
-  ret = zk->get(znode + seq, false, &result, NULL);
+  ret = zk->get(znode + "/" + seq, false, &result, NULL);
 
   if (ret != ZOK)
     LOG(ERROR) << "failed to fetch new master pid: " << zk->error(ret);

Modified: incubator/mesos/trunk/src/master_main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master_main.cpp?rev=1131755&r1=1131754&r2=1131755&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master_main.cpp (original)
+++ incubator/mesos/trunk/src/master_main.cpp Sun Jun  5 05:25:55 2011
@@ -17,11 +17,11 @@ void usage(const char* programName)
        << " [--port PORT]"
        << " [--allocator ALLOCATOR]"
        << " [--zookeeper ZOO_SERVERS]"
-       << " [--quiet]"
+       << " [--quiet]" << endl
        << endl
-       << "ZOO_SERVERS is a url of the form:"
-       << "  zoo://host1:port1,host2:port2,..., or"
-       << "  zoofile://file where file contains a host:port pair per line"
+       << "ZOO_SERVERS is a url of the form: "
+       << "zoo://host1:port1,host2:port2,... or "
+       << "zoofile://file where file contains a host:port pair per line"
        << endl;
 }
 

Modified: incubator/mesos/trunk/src/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave.cpp?rev=1131755&r1=1131754&r2=1131755&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave.cpp Sun Jun  5 05:25:55 2011
@@ -210,7 +210,7 @@ void Slave::operator () ()
       }
 	
       case NO_MASTER_DETECTED: {
-	// TODO(alig): Do anything here?
+	LOG(INFO) << "Lost master(s) ... waiting";
 	break;
       }
 

Modified: incubator/mesos/trunk/src/third_party/libprocess/process.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/third_party/libprocess/process.cpp?rev=1131755&r1=1131754&r2=1131755&view=diff
==============================================================================
--- incubator/mesos/trunk/src/third_party/libprocess/process.cpp (original)
+++ incubator/mesos/trunk/src/third_party/libprocess/process.cpp Sun Jun  5 05:25:55 2011
@@ -53,6 +53,7 @@
 #include <deque>
 #include <fstream>
 #include <iostream>
+#include <iomanip>
 #include <list>
 #include <map>
 #include <queue>
@@ -1660,7 +1661,7 @@ public:
 
       /* Attempt to cancel the timer if necessary. */
       if (secs > 0 && process->state != Process::TIMEDOUT)
-	  cancel_timeout(timeout);
+	cancel_timeout(timeout);
 
       if (process->state == Process::INTERRUPTED)
 	interrupted = true;
@@ -1760,13 +1761,17 @@ public:
     /* Add the timer. */
     acquire(timers);
     {
-      (*timers)[tstamp].push_back(timeout);
-
-      /* Interrupt the loop if there isn't an adequate timer running. */
-      if (timers->size() == 1 || tstamp < timers->begin()->first) {
-	update_timer = true;
-	ev_async_send(loop, &async_watcher);
+      if (timers->size() == 0 || tstamp < timers->begin()->first) {
+        // Need to interrupt the loop to update/set timer repeat.
+        (*timers)[tstamp].push_back(timeout);
+        update_timer = true;
+        ev_async_send(loop, &async_watcher);
+      } else {
+        // Timer repeat is adequate, just add the timeout.
+        assert(timers->size() >= 1);
+        (*timers)[tstamp].push_back(timeout);
       }
+
     }
     release(timers);
   }

Modified: incubator/mesos/trunk/src/zookeeper.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/zookeeper.cpp?rev=1131755&r1=1131754&r2=1131755&view=diff
==============================================================================
--- incubator/mesos/trunk/src/zookeeper.cpp (original)
+++ incubator/mesos/trunk/src/zookeeper.cpp Sun Jun  5 05:25:55 2011
@@ -361,7 +361,7 @@ private:
     GetCall *getCall =
       static_cast<GetCall *>(const_cast<void *>((data)));
     getCall->ret = ret;
-    if (getCall->result != NULL && value != NULL)
+    if (getCall->result != NULL && value != NULL && value_len > 0)
       getCall->result->assign(value, value_len);
     if (getCall->stat != NULL && stat != NULL)
       *(getCall->stat) = *(stat);
@@ -792,9 +792,9 @@ int ZooKeeper::getChildren(const string 
     void operator () ()
     {
       if (call(zooKeeperProcess->getPID(),
-	       GET,
+	       GET_CHILDREN,
 	       reinterpret_cast<char *>(&getChildrenCall),
-	       sizeof(GetCall *)) != COMPLETED)
+	       sizeof(GetChildrenCall *)) != COMPLETED)
 	getChildrenCall->ret = ZSYSTEMERROR;
     }