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/11/30 21:51:13 UTC

mesos git commit: Avoid empty `Resources` entries in `Master::Slave::usedResources`.

Repository: mesos
Updated Branches:
  refs/heads/master ec0546e17 -> b008beb2e


Avoid empty `Resources` entries in `Master::Slave::usedResources`.

When removing the last task from the agent struct in the master,
we ensure that we do not leave an empty `Resources` entry for its
framework. When removing the last executor, on the other hand, we
may leave an empty `Resources`! This patch ensures that we always
clean up `usedResources[frameworkId]` if the `Resources` are empty.

This patch also simplifies the condition to more directly look
for empty resources (previously this was inferred from there
being no tasks or executors remaining).

Along the way, replace using `[]` to access a hashmap in a `CHECK` with
`at`. Because `[]` can modify the map, we should generally prefer using
`at` for accesses that are intended to be read-only.

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


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

Branch: refs/heads/master
Commit: b008beb2e9c543708dae06a6d1ec67d75afeb07f
Parents: ec0546e
Author: Neil Conway <ne...@gmail.com>
Authored: Wed Nov 30 13:32:23 2016 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Wed Nov 30 13:32:23 2016 -0800

----------------------------------------------------------------------
 src/master/master.hpp | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b008beb2/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index b6c610b..877ca90 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -175,11 +175,11 @@ struct Slave
     const FrameworkID& frameworkId = task->framework_id();
 
     CHECK(protobuf::isTerminalState(task->state()));
-    CHECK(tasks[frameworkId].contains(taskId))
+    CHECK(tasks.at(frameworkId).contains(taskId))
       << "Unknown task " << taskId << " of framework " << frameworkId;
 
     usedResources[frameworkId] -= task->resources();
-    if (!tasks.contains(frameworkId) && !executors.contains(frameworkId)) {
+    if (usedResources[frameworkId].empty()) {
       usedResources.erase(frameworkId);
     }
   }
@@ -189,12 +189,12 @@ struct Slave
     const TaskID& taskId = task->task_id();
     const FrameworkID& frameworkId = task->framework_id();
 
-    CHECK(tasks[frameworkId].contains(taskId))
+    CHECK(tasks.at(frameworkId).contains(taskId))
       << "Unknown task " << taskId << " of framework " << frameworkId;
 
     if (!protobuf::isTerminalState(task->state())) {
       usedResources[frameworkId] -= task->resources();
-      if (!tasks.contains(frameworkId) && !executors.contains(frameworkId)) {
+      if (usedResources[frameworkId].empty()) {
         usedResources.erase(frameworkId);
       }
     }
@@ -265,6 +265,9 @@ struct Slave
 
     usedResources[frameworkId] -=
       executors[frameworkId][executorId].resources();
+    if (usedResources[frameworkId].empty()) {
+      usedResources.erase(frameworkId);
+    }
 
     executors[frameworkId].erase(executorId);
     if (executors[frameworkId].empty()) {