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

mesos git commit: Restored ordering of --isolation entry processsing.

Repository: mesos
Updated Branches:
  refs/heads/master 807d922bb -> af474a6fa


Restored ordering of --isolation entry processsing.

In 6fb9c024, the ordering of isolators was changed from being
specified by the operator to being specified by the code. It
turns out that the operator ordering was intended to ensure
that isolators can check their ordering requirements. If an
isolator detects that its ordering requirements are not
met, it can inform the operator to adjust the --isolation flag
via a failure message.

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


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

Branch: refs/heads/master
Commit: af474a6fa2d00d04ccc75185845c1ac36ab8f733
Parents: 807d922
Author: Benjamin Mahler <bm...@apache.org>
Authored: Mon Jun 13 18:05:20 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Jun 13 18:43:14 2016 -0700

----------------------------------------------------------------------
 src/slave/containerizer/mesos/containerizer.cpp | 95 +++++++++-----------
 .../isolators/cgroups/devices/gpus/nvidia.cpp   | 22 ++++-
 2 files changed, 60 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/af474a6f/src/slave/containerizer/mesos/containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/containerizer.cpp b/src/slave/containerizer/mesos/containerizer.cpp
index e5a339d..915e4cd 100644
--- a/src/slave/containerizer/mesos/containerizer.cpp
+++ b/src/slave/containerizer/mesos/containerizer.cpp
@@ -15,7 +15,6 @@
 // limitations under the License.
 
 #include <set>
-#include <utility>
 
 #include <mesos/module/isolator.hpp>
 
@@ -34,6 +33,7 @@
 #include <stout/adaptor.hpp>
 #include <stout/foreach.hpp>
 #include <stout/fs.hpp>
+#include <stout/hashmap.hpp>
 #include <stout/lambda.hpp>
 #include <stout/os.hpp>
 #include <stout/path.hpp>
@@ -115,7 +115,6 @@
 
 using std::list;
 using std::map;
-using std::pair;
 using std::set;
 using std::string;
 using std::vector;
@@ -257,31 +256,26 @@ Try<MesosContainerizer*> MesosContainerizer::create(
     return Error("Failed to create provisioner: " + provisioner.error());
   }
 
-  // Create isolators for the MesosContainerizer.
+  // Create the isolators.
   //
-  // The order of elements in the creation vector is used to express
-  // ordering dependencies between isolators. Currently, the `create`
-  // and `prepare` calls for each isolator are run serially in the
-  // order in which they appear in this list, while the `cleanup` call
-  // is serialized in reverse order. The current dependencies are:
+  // Currently, the order of the entries in the --isolation flag
+  // specifies the ordering of the isolators. Specifically, the
+  // `create` and `prepare` calls for each isolator are run serially
+  // in the order in which they appear in the --isolation flag, while
+  // the `cleanup` call is serialized in reverse order.
   //
-  //   (1) The filesystem isolator must be the first isolator so
-  //       that the runtime isolators have a consistent view of
-  //       the prepared filesystem (e.g. volume mounts).
+  // It is the responsibility of each isolator to check its
+  // dependency requirements (if any) during its `create`
+  // execution. This means that if the operator specifies the
+  // flags in the wrong order, it will produce an error during
+  // isolator creation.
   //
-  //   (2) The Nvidia GPU isolator must come after the cgroups
-  //       devices isolator, as it relies on the 'devices' cgroup
-  //       being set up.
-  //
-  // TODO(bmahler): De-centralize the ordering enforcement so that
-  // each isolator is responsible for validating that it is
-  // ordered correctly within the --isolation flag. This gives the
-  // operator control over the isolator ordering. If the operator
-  // specifies an invalid ordering, it will produce an error
-  // during the creation of an isolator and we will inform the
-  // operator to adjust the --isolation flag accordingly.
-
-  const vector<pair<string, lambda::function<Try<Isolator*>(const Flags&)>>>
+  // NOTE: We ignore the placement of the filesystem isolator in
+  // the --isolation flag and place it at the front of the isolator
+  // list. This is a temporary hack until isolators are able to
+  // express and validate their ordering requirements.
+
+  const hashmap<string, lambda::function<Try<Isolator*>(const Flags&)>>
     creators = {
     // Filesystem isolators.
 #ifndef __WINDOWS__
@@ -331,44 +325,39 @@ Try<MesosContainerizer*> MesosContainerizer::create(
 #endif
   };
 
-  vector<Owned<Isolator>> isolators;
-
-  const vector<string> tokens = strings::tokenize(flags_.isolation, ",");
-  set<string> isolations(tokens.begin(), tokens.end());
+  const vector<string> isolations = strings::tokenize(flags_.isolation, ",");
 
-  if (isolations.size() != tokens.size()) {
+  if (isolations.size() !=
+      set<string>(isolations.begin(), isolations.end()).size()) {
     return Error("Duplicate entries found in --isolation flag"
-                 " '" + stringify(tokens) + "'");
+                 " '" + stringify(isolations) + "'");
   }
 
-  // Create the first class isolators.
-  foreach (const auto& creator, creators) {
-    if (isolations.count(creator.first) > 0) {
-      Try<Isolator*> isolator = creator.second(flags_);
-      if (isolator.isError()) {
-        return Error("Failed to create isolator '" + creator.first + "': " +
-                     isolator.error());
-      }
-      isolators.emplace_back(isolator.get());
-      isolations.erase(creator.first);
-    }
-  }
+  vector<Owned<Isolator>> isolators;
 
-  // Create the module isolators.
   foreach (const string& isolation, isolations) {
-    if (ModuleManager::contains<Isolator>(isolation)) {
-      Try<Isolator*> isolator = ModuleManager::create<Isolator>(isolation);
-      if (isolator.isError()) {
-        return Error("Failed to create isolator module '" + isolation + "': " +
-                     isolator.error());
+    Try<Isolator*> isolator = [&]() -> Try<Isolator*> {
+      if (creators.contains(isolation)) {
+        return creators.at(isolation)(flags_);
+      } else if (ModuleManager::contains<Isolator>(isolation)) {
+        return ModuleManager::create<Isolator>(isolation);
       }
-      isolators.emplace_back(isolator.get());
-      isolations.erase(isolation);
+      return Error("Unknown or unsupported isolator");
+    }();
+
+    if (isolator.isError()) {
+      return Error("Failed to create isolator '" + isolation + "': " +
+                   isolator.error());
     }
-  }
 
-  if (!isolations.empty()) {
-    return Error("Unknown --isolation entries '" + stringify(isolations) + "'");
+    // NOTE: The filesystem isolator must be the first isolator used
+    // so that the runtime isolators can have a consistent view on the
+    // prepared filesystem (e.g., any volume mounts are performed).
+    if (strings::contains(isolation, "filesystem/")) {
+      isolators.insert(isolators.begin(), Owned<Isolator>(isolator.get()));
+    } else {
+      isolators.push_back(Owned<Isolator>(isolator.get()));
+    }
   }
 
   return new MesosContainerizer(

http://git-wip-us.apache.org/repos/asf/mesos/blob/af474a6f/src/slave/containerizer/mesos/isolators/cgroups/devices/gpus/nvidia.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/devices/gpus/nvidia.cpp b/src/slave/containerizer/mesos/isolators/cgroups/devices/gpus/nvidia.cpp
index d7557a0..78ba420 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/devices/gpus/nvidia.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/devices/gpus/nvidia.cpp
@@ -16,6 +16,7 @@
 
 #include <stdint.h>
 
+#include <algorithm>
 #include <list>
 #include <map>
 #include <set>
@@ -122,14 +123,27 @@ CgroupsNvidiaGpuIsolatorProcess::~CgroupsNvidiaGpuIsolatorProcess()
 
 Try<Isolator*> CgroupsNvidiaGpuIsolatorProcess::create(const Flags& flags)
 {
-  // Make sure the `cgroups/devices` isolator is present.
-  vector<string> isolators_ = strings::tokenize(flags.isolation, ",");
-  set<string> isolators = set<string>(isolators_.begin(), isolators_.end());
-  if (isolators.count("cgroups/devices") == 0) {
+  // Make sure the 'cgroups/devices' isolator is present and
+  // precedes the GPU isolator.
+  vector<string> tokens = strings::tokenize(flags.isolation, ",");
+
+  auto gpuIsolator =
+    std::find(tokens.begin(), tokens.end(), "gpu/nvidia");
+  auto devicesIsolator =
+    std::find(tokens.begin(), tokens.end(), "cgroups/devices");
+
+  CHECK(gpuIsolator != tokens.end());
+
+  if (devicesIsolator == tokens.end()) {
     return Error("The 'cgroups/devices' isolator must be enabled in"
                  " order to use the gpu/devices isolator");
   }
 
+  if (devicesIsolator > gpuIsolator) {
+    return Error("'cgroups/devices' must precede 'gpu/nvidia'"
+                 " in the --isolation flag");
+  }
+
   // Initialize NVML.
   nvmlReturn_t result = nvmlInit();
   if (result != NVML_SUCCESS) {