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 08:40:55 UTC

svn commit: r1131949 - in /incubator/mesos/trunk/src: ./ tests/ third_party/libprocess/

Author: benh
Date: Sun Jun  5 06:40:55 2011
New Revision: 1131949

URL: http://svn.apache.org/viewvc?rev=1131949&view=rev
Log:
Removed redundant ways to get the PID of a process instance and to wait on a process instance, and modified usage in the code base as necessary.

Modified:
    incubator/mesos/trunk/src/lxc_isolation_module.cpp
    incubator/mesos/trunk/src/mesos_exec.cpp
    incubator/mesos/trunk/src/mesos_local.cpp
    incubator/mesos/trunk/src/mesos_sched.cpp
    incubator/mesos/trunk/src/process_based_isolation_module.cpp
    incubator/mesos/trunk/src/slave.cpp
    incubator/mesos/trunk/src/tests/test_master.cpp
    incubator/mesos/trunk/src/third_party/libprocess/process.cpp
    incubator/mesos/trunk/src/third_party/libprocess/process.hpp
    incubator/mesos/trunk/src/third_party/libprocess/reliable.cpp
    incubator/mesos/trunk/src/zookeeper.cpp

Modified: incubator/mesos/trunk/src/lxc_isolation_module.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/lxc_isolation_module.cpp?rev=1131949&r1=1131948&r2=1131949&view=diff
==============================================================================
--- incubator/mesos/trunk/src/lxc_isolation_module.cpp (original)
+++ incubator/mesos/trunk/src/lxc_isolation_module.cpp Sun Jun  5 06:40:55 2011
@@ -49,8 +49,8 @@ LxcIsolationModule::~LxcIsolationModule(
   // could thus lead to a seg fault!
   if (initialized) {
     CHECK(reaper != NULL);
-    Process::post(reaper->getPID(), SHUTDOWN_REAPER);
-    Process::wait(reaper);
+    Process::post(reaper->self(), SHUTDOWN_REAPER);
+    Process::wait(reaper->self());
     delete reaper;
   }
 }
@@ -240,7 +240,7 @@ LxcIsolationModule::Reaper::Reaper(LxcIs
   
 void LxcIsolationModule::Reaper::operator () ()
 {
-  link(module->slave->getPID());
+  link(module->slave->self());
   while (true) {
     switch (receive(1)) {
     case PROCESS_TIMEOUT: {

Modified: incubator/mesos/trunk/src/mesos_exec.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/mesos_exec.cpp?rev=1131949&r1=1131948&r2=1131949&view=diff
==============================================================================
--- incubator/mesos/trunk/src/mesos_exec.cpp (original)
+++ incubator/mesos/trunk/src/mesos_exec.cpp Sun Jun  5 06:40:55 2011
@@ -181,7 +181,7 @@ MesosExecutorDriver::~MesosExecutorDrive
   pthread_mutex_destroy(&mutex);
   pthread_cond_destroy(&cond);
 
-  Process::wait(process);
+  Process::wait(process->self());
   delete process;
 }
 

Modified: incubator/mesos/trunk/src/mesos_local.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/mesos_local.cpp?rev=1131949&r1=1131948&r2=1131949&view=diff
==============================================================================
--- incubator/mesos/trunk/src/mesos_local.cpp (original)
+++ incubator/mesos/trunk/src/mesos_local.cpp Sun Jun  5 06:40:55 2011
@@ -100,8 +100,8 @@ PID launch(const Params& conf, bool init
 
 void shutdown()
 {
-  Process::post(master->getPID(), M2M_SHUTDOWN);
-  Process::wait(master->getPID());
+  Process::post(master->self(), M2M_SHUTDOWN);
+  Process::wait(master->self());
   delete master;
   master = NULL;
 
@@ -112,8 +112,8 @@ void shutdown()
   // we have stopped the slave.
 
   foreachpair (IsolationModule *isolationModule, Slave *slave, slaves) {
-    Process::post(slave->getPID(), S2S_SHUTDOWN);
-    Process::wait(slave);
+    Process::post(slave->self(), S2S_SHUTDOWN);
+    Process::wait(slave->self());
     delete isolationModule;
     delete slave;
   }

Modified: incubator/mesos/trunk/src/mesos_sched.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/mesos_sched.cpp?rev=1131949&r1=1131948&r2=1131949&view=diff
==============================================================================
--- incubator/mesos/trunk/src/mesos_sched.cpp (original)
+++ incubator/mesos/trunk/src/mesos_sched.cpp Sun Jun  5 06:40:55 2011
@@ -284,8 +284,8 @@ protected:
 	unordered_map <TaskID, RbReply *>::iterator it = rbReplies.find(tid);
 	if (it != rbReplies.end()) {
 	  RbReply *rr = it->second;
-	  send(rr->getPID(), pack<F2F_TASK_RUNNING_STATUS>());
-	  wait(rr->getPID());
+	  send(rr->self(), pack<F2F_TASK_RUNNING_STATUS>());
+	  wait(rr->self());
 	  rbReplies.erase(tid);
 	  delete rr;
 	}
@@ -304,8 +304,8 @@ protected:
 	unordered_map <TaskID, RbReply *>::iterator it = rbReplies.find(tid);
 	if (it != rbReplies.end()) {
 	  RbReply *rr = it->second;
-	  send(rr->getPID(), pack<F2F_TASK_RUNNING_STATUS>());
-	  wait(rr->getPID());
+	  send(rr->self(), pack<F2F_TASK_RUNNING_STATUS>());
+	  wait(rr->self());
 	  rbReplies.erase(tid);
 	  delete rr;
 	}
@@ -502,7 +502,7 @@ MesosSchedulerDriver::~MesosSchedulerDri
   // not this was about to be deadlock, and possibly report this back
   // to the user somehow.
   if (process != NULL) {
-    Process::wait(process);
+    Process::wait(process->self());
     delete process;
   }
 

Modified: incubator/mesos/trunk/src/process_based_isolation_module.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/process_based_isolation_module.cpp?rev=1131949&r1=1131948&r2=1131949&view=diff
==============================================================================
--- incubator/mesos/trunk/src/process_based_isolation_module.cpp (original)
+++ incubator/mesos/trunk/src/process_based_isolation_module.cpp Sun Jun  5 06:40:55 2011
@@ -33,8 +33,8 @@ ProcessBasedIsolationModule::~ProcessBas
   // could thus lead to a seg fault!
   if (initialized) {
     CHECK(reaper != NULL);
-    Process::post(reaper->getPID(), SHUTDOWN_REAPER);
-    Process::wait(reaper);
+    Process::post(reaper->self(), SHUTDOWN_REAPER);
+    Process::wait(reaper->self());
     delete reaper;
   }
 }
@@ -137,7 +137,7 @@ ProcessBasedIsolationModule::Reaper::Rea
 
 void ProcessBasedIsolationModule::Reaper::operator () ()
 {
-  link(module->slave->getPID());
+  link(module->slave->self());
   while (true) {
     switch (receive(1)) {
     case PROCESS_TIMEOUT: {

Modified: incubator/mesos/trunk/src/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave.cpp?rev=1131949&r1=1131948&r2=1131949&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave.cpp Sun Jun  5 06:40:55 2011
@@ -190,7 +190,7 @@ void Slave::operator () ()
 	double interval = 0;
         unpack<M2S_REGISTER_REPLY>(this->id, interval);
         LOG(INFO) << "Registered with master; given slave ID " << this->id;
-        link(spawn(new Heart(master, this->getPID(), this->id, interval)));
+        link(spawn(new Heart(master, self(), this->id, interval)));
         break;
       }
       
@@ -201,7 +201,7 @@ void Slave::operator () ()
         LOG(INFO) << "RE-registered with master; given slave ID " << tmpfid << " had "<< this->id;
         if (this->id == "")
           this->id = tmpfid;
-        link(spawn(new Heart(master, getPID(), this->id, interval)));
+        link(spawn(new Heart(master, self(), this->id, interval)));
         break;
       }
       

Modified: incubator/mesos/trunk/src/tests/test_master.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/test_master.cpp?rev=1131949&r1=1131948&r2=1131949&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/test_master.cpp (original)
+++ incubator/mesos/trunk/src/tests/test_master.cpp Sun Jun  5 06:40:55 2011
@@ -630,7 +630,7 @@ public:
   virtual ~LocalIsolationModule() {}
 
   virtual void initialize(Slave *slave) {
-    pid = slave->getPID();
+    pid = slave->self();
   }
 
   virtual void startExecutor(Framework *framework) {

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=1131949&r1=1131948&r2=1131949&view=diff
==============================================================================
--- incubator/mesos/trunk/src/third_party/libprocess/process.cpp (original)
+++ incubator/mesos/trunk/src/third_party/libprocess/process.cpp Sun Jun  5 06:40:55 2011
@@ -1639,7 +1639,7 @@ void LinkManager::exited(Process *proces
     foreachpair (_, set<Process *> &processes, links)
       processes.erase(process);
 
-    const PID &pid = process->getPID();
+    const PID &pid = process->self();
 
     /* Look up all linked processes. */
     map<PID, set<Process *> >::iterator it = links.find(pid);
@@ -2530,23 +2530,14 @@ struct msg * Process::dequeue()
 }
 
 
-PID Process::self() const
-{
-  return pid;
-}
-
-
-PID Process::from() const
-{
-  return current != NULL ? current->from : PID();
-}
-
-
 void Process::inject(const PID &from, MSGID id, const char *data, size_t length)
 {
   if (replaying)
     return;
 
+  if (!from)
+    return;
+
   /* Disallow sending messages using an internal id. */
   if (id < PROCESS_MSGID)
     return;
@@ -2587,6 +2578,9 @@ void Process::send(const PID &to, MSGID 
 {
   if (replaying)
     return;
+
+  if (!to)
+    return;
   
   /* Disallow sending messages using an internal id. */
   if (id < PROCESS_MSGID)
@@ -2718,7 +2712,11 @@ void Process::pause(double secs)
 
 PID Process::link(const PID &to)
 {
+  if (!to)
+    return to;
+
   process_manager->link(this, to);
+
   return to;
 }
 
@@ -2797,6 +2795,9 @@ void Process::post(const PID &to, MSGID 
   if (replaying)
     return;
 
+  if (!to)
+    return;
+
   /* Disallow sending messages using an internal id. */
   if (id < PROCESS_MSGID)
     return;
@@ -2855,6 +2856,9 @@ bool Process::wait(const PID &pid)
 {
   initialize();
 
+  if (!pid)
+    return false;
+
   // N.B. This could result in a deadlock! We could check if such was
   // the case by doing:
   //
@@ -2874,15 +2878,6 @@ bool Process::wait(const PID &pid)
 }
 
 
-bool Process::wait(Process *process)
-{
-  if (process == NULL)
-    return false;
-
-  return wait(process->getPID());
-}
-
-
 void Process::invoke(const std::tr1::function<void (void)> &thunk)
 {
   initialize();

Modified: incubator/mesos/trunk/src/third_party/libprocess/process.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/third_party/libprocess/process.hpp?rev=1131949&r1=1131948&r2=1131949&view=diff
==============================================================================
--- incubator/mesos/trunk/src/third_party/libprocess/process.hpp (original)
+++ incubator/mesos/trunk/src/third_party/libprocess/process.hpp Sun Jun  5 06:40:55 2011
@@ -49,7 +49,7 @@ public:
 class Process {
 public:
   /* Returns pid of process; valid even before calling spawn. */
-  PID getPID() const;
+  PID self() const;
 
   /* Sends a message to PID without a return address. */
   static void post(const PID &to, MSGID id);
@@ -63,9 +63,6 @@ public:
   /* Wait for PID to exit (returns true if actually waited on a process). */
   static bool wait(const PID &pid);
 
-  /* Wait for PID to exit (returns true if actually waited on a process). */
-  static bool wait(Process *process);
-
   /* Invoke the thunk in a legacy safe way. */
   static void invoke(const std::tr1::function<void (void)> &thunk);
 
@@ -79,13 +76,10 @@ protected:
   /* Function run when process spawned. */
   virtual void operator() () = 0;
 
-  /* Returns the PID describing this process. */
-  PID self() const;
-
   /* Returns the sender's PID of the last dequeued (current) message. */
   PID from() const;
 
-  /* Returns the id of the current message. */
+  /* Returns the id of the last dequeued (current) message. */
   MSGID msgid() const;
 
   /* Returns pointer and length of body of last dequeued (current) message. */
@@ -186,6 +180,18 @@ private:
 };
 
 
+inline PID Process::self() const
+{
+  return pid;
+}
+
+
+inline PID Process::from() const
+{
+  return current != NULL ? current->from : PID();
+}
+
+
 inline MSGID Process::msgid() const
 {
   return current != NULL ? current->id : PROCESS_ERROR;
@@ -217,12 +223,6 @@ inline MSGID Process::receive()
 }
 
 
-inline PID Process::getPID() const
-{
-  return self();
-}
-
-
 inline void Process::post(const PID &to, MSGID id)
 {
   post(to, id, NULL, 0);

Modified: incubator/mesos/trunk/src/third_party/libprocess/reliable.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/third_party/libprocess/reliable.cpp?rev=1131949&r1=1131948&r2=1131949&view=diff
==============================================================================
--- incubator/mesos/trunk/src/third_party/libprocess/reliable.cpp (original)
+++ incubator/mesos/trunk/src/third_party/libprocess/reliable.cpp Sun Jun  5 06:40:55 2011
@@ -85,7 +85,7 @@ ReliableProcess::~ReliableProcess()
   }
 
   foreachpair (const PID &pid, ReliableSender *sender, senders) {
-    assert(pid == sender->getPID());
+    assert(pid == sender->self());
     // Shut it down by sending it an ack.
     send(pid, RELIABLE_ACK);
     wait(pid);
@@ -205,7 +205,7 @@ MSGID ReliableProcess::receive(double se
 
 	// TODO(benh): Is this really the way we want to do acks?
 	foreachpair (const PID &pid, ReliableSender *sender, senders) {
-	  assert(pid == sender->getPID());
+	  assert(pid == sender->self());
 	  // TODO(benh): Don't look into sender's class like this ... HACK!
 	  if (rmsg->seq == sender->rmsg->seq &&
 	      rmsg->msg.to == sender->rmsg->msg.to) {
@@ -259,7 +259,7 @@ void ReliableProcess::redirect(const PID
 {
   // Send a redirect to all running senders and update internal mapping.
   foreachpair (const PID &pid, ReliableSender *sender, senders) {
-    assert(pid == sender->getPID());
+    assert(pid == sender->self());
     // TODO(benh): Don't look into sender's class like this ... HACK!
     if (existing == sender->rmsg->msg.to)
       send(pid, RELIABLE_REDIRECT, (char *) &updated, sizeof(PID));
@@ -270,7 +270,7 @@ void ReliableProcess::redirect(const PID
 void ReliableProcess::cancel(int seq)
 {
   foreachpair (const PID &pid, ReliableSender *sender, senders) {
-    assert(pid == sender->getPID());
+    assert(pid == sender->self());
     // Shut it down by sending it an ack. It will get cleaned up via
     // the PROCESS_EXIT above.
     // TODO(benh): Don't look into sender's class like this ... HACK!

Modified: incubator/mesos/trunk/src/zookeeper.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/zookeeper.cpp?rev=1131949&r1=1131948&r2=1131949&view=diff
==============================================================================
--- incubator/mesos/trunk/src/zookeeper.cpp (original)
+++ incubator/mesos/trunk/src/zookeeper.cpp Sun Jun  5 06:40:55 2011
@@ -233,8 +233,8 @@ protected:
 	    *reinterpret_cast<Watcher **>(const_cast<char *>(body(NULL)));
 	  if (watchers.find(watcher) != watchers.end()) {
 	    WatcherProcess *process = watchers[watcher];
-	    PID pid = process->getPID();
-	    send(from(), OK, reinterpret_cast<char *>(&pid), sizeof(pid));
+	    const PID &pid = process->self();
+	    send(from(), OK, reinterpret_cast<const char *>(&pid), sizeof(pid));
 	  } else {
 	    send(from(), ERROR);
 	  }
@@ -281,8 +281,8 @@ Watcher::~Watcher()
 	fatal("failed to deallocate resources associated with Watcher");
       WatcherProcess *process =
 	*reinterpret_cast<WatcherProcess **>(const_cast<char *>(body(NULL)));
-      send(process->getPID(), TERMINATE);
-      wait(process->getPID());
+      send(process->self(), TERMINATE);
+      wait(process->self());
       delete process;
     }
 
@@ -603,8 +603,8 @@ ZooKeeper::ZooKeeper(const string &hosts
 
 ZooKeeper::~ZooKeeper()
 {
-  Process::post(impl->getPID(), TERMINATE);
-  Process::wait(impl->getPID());
+  Process::post(impl->self(), TERMINATE);
+  Process::wait(impl->self());
   delete impl;
 }
 
@@ -638,7 +638,7 @@ int ZooKeeper::create(const string &path
   protected:
     void operator () ()
     {
-      if (call(zooKeeperProcess->getPID(),
+      if (call(zooKeeperProcess->self(),
 	       CREATE,
 	       reinterpret_cast<char *>(&createCall),
 	       sizeof(CreateCall *)) != COMPLETED)
@@ -676,7 +676,7 @@ int ZooKeeper::remove(const string &path
   protected:
     void operator () ()
     {
-      if (call(zooKeeperProcess->getPID(),
+      if (call(zooKeeperProcess->self(),
 	       REMOVE,
 	       reinterpret_cast<char *>(&removeCall),
 	       sizeof(RemoveCall *)) != COMPLETED)
@@ -716,7 +716,7 @@ int ZooKeeper::exists(const string &path
   protected:
     void operator () ()
     {
-      if (call(zooKeeperProcess->getPID(),
+      if (call(zooKeeperProcess->self(),
 	       EXISTS,
 	       reinterpret_cast<char *>(&existsCall),
 	       sizeof(ExistsCall *)) != COMPLETED)
@@ -758,7 +758,7 @@ int ZooKeeper::get(const string &path,
   protected:
     void operator () ()
     {
-      if (call(zooKeeperProcess->getPID(),
+      if (call(zooKeeperProcess->self(),
 	       GET,
 	       reinterpret_cast<char *>(&getCall),
 	       sizeof(GetCall *)) != COMPLETED)
@@ -798,7 +798,7 @@ int ZooKeeper::getChildren(const string 
   protected:
     void operator () ()
     {
-      if (call(zooKeeperProcess->getPID(),
+      if (call(zooKeeperProcess->self(),
 	       GET_CHILDREN,
 	       reinterpret_cast<char *>(&getChildrenCall),
 	       sizeof(GetChildrenCall *)) != COMPLETED)
@@ -838,7 +838,7 @@ int ZooKeeper::set(const string &path,
   protected:
     void operator () ()
     {
-      if (call(zooKeeperProcess->getPID(),
+      if (call(zooKeeperProcess->self(),
 	       SET,
 	       reinterpret_cast<char *>(&setCall),
 	       sizeof(SetCall *)) != COMPLETED)