You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by tn...@apache.org on 2015/04/03 21:58:08 UTC

[2/3] mesos git commit: Kill the executor when docker container is destroyed.

Kill the executor when docker container is destroyed.

Review: https://reviews.apache.org/r/32797


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

Branch: refs/heads/master
Commit: 879044096f80adb1799ce43acc1fc5ae58dfac69
Parents: 591d109
Author: Timothy Chen <tn...@apache.org>
Authored: Wed Apr 1 16:29:54 2015 -0700
Committer: Timothy Chen <tn...@apache.org>
Committed: Fri Apr 3 12:49:39 2015 -0700

----------------------------------------------------------------------
 src/slave/containerizer/docker.cpp | 22 +++++++++++++++++++++-
 src/slave/containerizer/docker.hpp |  5 +++++
 2 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/87904409/src/slave/containerizer/docker.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/docker.cpp b/src/slave/containerizer/docker.cpp
index 76e47cc..f9fb078 100644
--- a/src/slave/containerizer/docker.cpp
+++ b/src/slave/containerizer/docker.cpp
@@ -263,6 +263,8 @@ Try<Nothing> DockerContainerizerProcess::checkpoint(
 
   Container* container = containers_[containerId];
 
+  container->executorPid = pid;
+
   if (container->checkpoint) {
     const string& path =
       slave::paths::getForkedPidPath(
@@ -1225,11 +1227,29 @@ void DockerContainerizerProcess::destroy(
 
   container->state = Container::DESTROYING;
 
+  if (container->executorPid.isSome()) {
+    LOG(INFO) << "Sending SIGTERM to executor with pid: "
+              << container->executorPid.get();
+    // We need to clean up the executor as the executor might not have
+    // received run task due to a failed containerizer update.
+    // We also kill the executor first since container->status below
+    // is waiting for the executor to finish.
+    Try<std::list<os::ProcessTree>> kill =
+      os::killtree(container->executorPid.get(), SIGTERM);
+
+    if (kill.isError()) {
+      // Ignoring the error from killing executor as it can already
+      // have exited.
+      VLOG(1) << "Ignoring error when killing executor pid "
+                << container->executorPid.get() << " in destroy, error: "
+                << kill.error();
+    }
+  }
+
   // Otherwise, wait for Docker::run to succeed, in which case we'll
   // continue in _destroy (calling Docker::kill) or for Docker::run to
   // fail, in which case we'll re-execute this function and cleanup
   // above.
-
   container->status.future()
     .onAny(defer(self(), &Self::_destroy, containerId, killed));
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/87904409/src/slave/containerizer/docker.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/docker.hpp b/src/slave/containerizer/docker.hpp
index 5ae3a9d..6893684 100644
--- a/src/slave/containerizer/docker.hpp
+++ b/src/slave/containerizer/docker.hpp
@@ -432,6 +432,11 @@ private:
     // Once the container is running, this saves the pid of the
     // running container.
     Option<pid_t> pid;
+
+    // The executor pid that was forked to wait on the running
+    // container. This is stored so we can clean up the executor
+    // on destroy.
+    Option<pid_t> executorPid;
   };
 
   hashmap<ContainerID, Container*> containers_;