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/04/12 02:46:33 UTC

[2/3] mesos git commit: Added logic to validate non-fractional GPU resources in the master.

Added logic to validate non-fractional GPU resources in the master.

We considered adding this logic directly to the
'Resources::validate()' function, but ultimately decided against it.
The primary reason is that the existing 'Resources::validate()'
function doesn't consider the semantics of any particular resource
when performing its validation (it only makes sure that the fields in
the 'Resource' protobuf message are correctly formed). Since a
fractional 'gpus' resources is actually well-formed (and only
semantically incorrect), we decided to push this validation logic up
into the master.

Moreover, the existing logic to construct a 'Resources' object from a
'RepeatedPtrField<Resource>' silently drops any resources that don't
pass 'Resources::validate()'. This means that if we had pushed the
non-fractional 'gpus' validation into 'Resources::validate()', the
'gpus' resources would just have been silently dropped rather than
causing a TASK_ERROR in the master. This is obviously *not* the
desired behaviour.

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


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

Branch: refs/heads/master
Commit: d124e149a8e2ed6fdf898a3d5fab1560b95e2ed7
Parents: e268320
Author: Kevin Klues <kl...@gmail.com>
Authored: Mon Apr 11 17:44:19 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Apr 11 17:44:19 2016 -0700

----------------------------------------------------------------------
 src/master/validation.cpp | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d124e149/src/master/validation.cpp
----------------------------------------------------------------------
diff --git a/src/master/validation.cpp b/src/master/validation.cpp
index 504cd9b..1342343 100644
--- a/src/master/validation.cpp
+++ b/src/master/validation.cpp
@@ -149,6 +149,19 @@ Option<Error> validate(const mesos::scheduler::Call& call)
 
 namespace resource {
 
+// Validates that the `gpus` resource is not fractional.
+// We rely on scalar resources only having 3 digits of precision.
+Option<Error> validateGpus(const RepeatedPtrField<Resource>& resources)
+{
+  double gpus = Resources(resources).gpus().getOrElse(0.0);
+  if (static_cast<long long>(gpus * 1000.0) % 1000 != 0) {
+    return Error("The 'gpus' resource must be an unsigned integer");
+  }
+
+  return None();
+}
+
+
 // Validates the ReservationInfos specified in the given resources (if
 // exist). Returns error if any ReservationInfo is found invalid or
 // unsupported.
@@ -265,6 +278,11 @@ Option<Error> validate(const RepeatedPtrField<Resource>& resources)
     return Error("Invalid resources: " + error.get().message);
   }
 
+  error = validateGpus(resources);
+  if (error.isSome()) {
+    return Error("Invalid 'gpus' resource: " + error.get().message);
+  }
+
   error = validateDiskInfo(resources);
   if (error.isSome()) {
     return Error("Invalid DiskInfo: " + error.get().message);