You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by nn...@apache.org on 2014/04/14 20:52:44 UTC

git commit: Changed Executor::resources to option type.

Repository: mesos
Updated Branches:
  refs/heads/master 9e9bf44c7 -> 857b2e09d


Changed Executor::resources to option type.

Yet another split out of the task-info RR (r19795/r18403) which turns
Executor::resources into an option type. It is needed when the
executor info isn't known up-front (the main motivation behind the
task-info RR) and the executor resources therefore cannot be known
until after the containerizer has launched the container.

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


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

Branch: refs/heads/master
Commit: 857b2e09d7ae7e88e8de106d0c19ae92d2ec0051
Parents: 9e9bf44
Author: Niklas Q. Nielsen <ni...@mesosphere.io>
Authored: Mon Apr 14 11:11:16 2014 -0700
Committer: Niklas Q. Nielsen <ni...@mesosphere.io>
Committed: Mon Apr 14 11:32:17 2014 -0700

----------------------------------------------------------------------
 src/slave/http.cpp  |  5 ++++-
 src/slave/slave.cpp | 23 ++++++++++++++++-------
 src/slave/slave.hpp |  6 +++++-
 3 files changed, 25 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/857b2e09/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index 594032d..70e409a 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -148,7 +148,10 @@ JSON::Object model(const Executor& executor)
   object.values["source"] = executor.info.source();
   object.values["container"] = executor.containerId.value();
   object.values["directory"] = executor.directory;
-  object.values["resources"] = model(executor.resources);
+
+  if (executor.resources.isSome()) {
+    object.values["resources"] = model(executor.resources.get());
+  }
 
   JSON::Array tasks;
   foreach (Task* task, executor.launchedTasks.values()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/857b2e09/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index cddb241..19c5f0d 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -990,7 +990,8 @@ void Slave::_runTask(
       // TODO(Charles Reiss): The isolator is not guaranteed to update
       // the resources before the executor acts on its RunTaskMessage.
       // TODO(idownes): Wait until this completes.
-      containerizer->update(executor->containerId, executor->resources);
+      CHECK_SOME(executor->resources);
+      containerizer->update(executor->containerId, executor->resources.get());
 
       LOG(INFO) << "Sending task '" << task.task_id()
                 << "' to executor '" << executorId
@@ -1546,7 +1547,8 @@ void Slave::registerExecutor(
       // that this will be delivered or (where necessary) acted on
       // before the executor gets its RunTaskMessages.
       // TODO(idownes): Wait until this completes.
-      containerizer->update(executor->containerId, executor->resources);
+      CHECK_SOME(executor->resources);
+      containerizer->update(executor->containerId, executor->resources.get());
 
       // Tell executor it's registered and give it any queued tasks.
       ExecutorRegisteredMessage message;
@@ -1664,7 +1666,8 @@ void Slave::reregisterExecutor(
 
       // Tell the containerizer to update the resources.
       // TODO(idownes): Wait until this completes.
-      containerizer->update(executor->containerId, executor->resources);
+      CHECK_SOME(executor->resources);
+      containerizer->update(executor->containerId, executor->resources.get());
 
       hashmap<TaskID, TaskInfo> unackedTasks;
       foreach (const TaskInfo& task, tasks) {
@@ -1851,7 +1854,8 @@ void Slave::statusUpdate(const StatusUpdate& update, const UPID& pid)
 
     // Tell the isolator to update the resources.
     // TODO(idownes): Wait until this completes.
-    containerizer->update(executor->containerId, executor->resources);
+    CHECK_SOME(executor->resources);
+    containerizer->update(executor->containerId, executor->resources.get());
   }
 
   if (executor->checkpoint) {
@@ -3246,7 +3250,10 @@ Task* Executor::addTask(const TaskInfo& task)
       protobuf::createTask(task, TASK_STAGING, id, frameworkId));
 
   launchedTasks[task.task_id()] = t;
-  resources += task.resources();
+
+  CHECK_SOME(resources);
+  resources = resources.get() + task.resources();
+
   return t;
 }
 
@@ -3266,8 +3273,9 @@ void Executor::terminateTask(
   } else if (launchedTasks.contains(taskId)) {
     // Update the resources if it's been launched.
     task = launchedTasks[taskId];
+    CHECK_SOME(resources);
     foreach (const Resource& resource, task->resources()) {
-      resources -= resource;
+      resources = resources.get() - resource;
     }
     launchedTasks.erase(taskId);
   }
@@ -3323,7 +3331,8 @@ void Executor::recoverTask(const TaskState& state)
   // slave was down, the executor resources we capture here is an
   // upper-bound. The actual resources needed (for live tasks) by
   // the isolator will be calculated when the executor re-registers.
-  resources += state.info.get().resources();
+  CHECK_SOME(resources);
+  resources = resources.get() + state.info.get().resources();
 
   // Read updates to get the latest state of the task.
   foreach (const StatusUpdate& update, state.updates) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/857b2e09/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index 08f6005..1e98795 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -418,7 +418,11 @@ struct Executor
 
   process::UPID pid;
 
-  Resources resources; // Currently consumed resources.
+  // Currently consumed resources. It is an option type as the
+  // executor info will not be known up-front and the executor
+  // resources therefore cannot be known until after the containerizer
+  // has launched the container.
+  Option<Resources> resources;
 
   // Tasks can be found in one of the following four data structures: