You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/12/06 02:25:30 UTC

[2/3] mesos git commit: Added path helpers for checkpointing the io switchboard pid.

Added path helpers for checkpointing the io switchboard pid.

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


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

Branch: refs/heads/master
Commit: a1db860ac5a60887d7241da552d925158362bf8b
Parents: 543533f
Author: Kevin Klues <kl...@gmail.com>
Authored: Mon Dec 5 17:39:42 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Dec 5 18:25:25 2016 -0800

----------------------------------------------------------------------
 src/slave/containerizer/mesos/paths.cpp | 41 ++++++++++++++++++++++++++++
 src/slave/containerizer/mesos/paths.hpp | 13 +++++++++
 2 files changed, 54 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a1db860a/src/slave/containerizer/mesos/paths.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/paths.cpp b/src/slave/containerizer/mesos/paths.cpp
index e090392..784e60c 100644
--- a/src/slave/containerizer/mesos/paths.cpp
+++ b/src/slave/containerizer/mesos/paths.cpp
@@ -139,6 +139,47 @@ Result<int> getContainerStatus(
 
 
 #ifndef __WINDOWS__
+string getContainerIOSwitchboardPidPath(
+    const string& runtimeDir,
+    const ContainerID& containerId)
+{
+  return path::join(
+      getRuntimePath(runtimeDir, containerId),
+      IO_SWITCHBOARD_PID_FILE);
+}
+
+
+Result<pid_t> getContainerIOSwitchboardPid(
+    const std::string& runtimeDir,
+    const ContainerID& containerId)
+{
+  const string path = getContainerIOSwitchboardPidPath(
+      runtimeDir, containerId);
+
+  if (!os::exists(path)) {
+    // This is possible because we don't atomically create the
+    // directory and write the 'pid' file and thus we might
+    // terminate/restart after we've created the directory but
+    // before we've written the file.
+    return None();
+  }
+
+  Try<string> read = os::read(path);
+  if (read.isError()) {
+    return Error("Failed to recover pid of io switchboard: " + read.error());
+  }
+
+  Try<pid_t> pid = numify<pid_t>(read.get());
+  if (pid.isError()) {
+    return Error(
+        "Failed to numify pid '" + read.get() +
+        "' of io switchboard at '" + path + "': " + pid.error());
+  }
+
+  return pid.get();
+}
+
+
 string getContainerIOSwitchboardSocketPath(
     const string& runtimeDir,
     const ContainerID& containerId)

http://git-wip-us.apache.org/repos/asf/mesos/blob/a1db860a/src/slave/containerizer/mesos/paths.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/paths.hpp b/src/slave/containerizer/mesos/paths.hpp
index c0fe2a4..8712484 100644
--- a/src/slave/containerizer/mesos/paths.hpp
+++ b/src/slave/containerizer/mesos/paths.hpp
@@ -41,6 +41,7 @@ constexpr char PID_FILE[] = "pid";
 constexpr char STATUS_FILE[] = "status";
 constexpr char TERMINATION_FILE[] = "termination";
 constexpr char IO_SWITCHBOARD_SOCKET_FILE[] = "io_switchboard.sock";
+constexpr char IO_SWITCHBOARD_PID_FILE[] = "io_switchboard.pid";
 constexpr char CONTAINER_DIRECTORY[] = "containers";
 
 
@@ -97,6 +98,18 @@ Result<int> getContainerStatus(
 
 
 #ifndef __WINDOWS__
+// The helper method to get the io switchboard pid file path.
+std::string getContainerIOSwitchboardPidPath(
+    const std::string& runtimeDir,
+    const ContainerID& containerId);
+
+
+// The helper method to get the io switchboard pid.
+Result<pid_t> getContainerIOSwitchboardPid(
+    const std::string& runtimeDir,
+    const ContainerID& containerId);
+
+
 // The helper method to get the socket file path.
 std::string getContainerIOSwitchboardSocketPath(
     const std::string& runtimeDir,