Repository: mesos Updated Branches: refs/heads/master 2fb0fb03e -> bf94296c9
Ignore terminal task resources in the Master's Framework struct. Review: https://reviews.apache.org/r/25844 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/fd202698 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/fd202698 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/fd202698 Branch: refs/heads/master Commit: fd2026980c3f1b14876e0c81bde08ec0fe851d8c Parents: 2fb0fb0 Author: Benjamin Mahler <[email protected]> Authored: Fri Sep 19 12:41:58 2014 -0700 Committer: Benjamin Mahler <[email protected]> Committed: Fri Sep 19 12:44:14 2014 -0700 ---------------------------------------------------------------------- src/master/http.cpp | 2 +- src/master/master.cpp | 3 +-- src/master/master.hpp | 38 +++++++++++++++++++++++++------------- 3 files changed, 27 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/fd202698/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index 8db4d9a..3f5a01d 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -116,7 +116,7 @@ JSON::Object model(const Framework& framework) object.values["registered_time"] = framework.registeredTime.secs(); object.values["unregistered_time"] = framework.unregisteredTime.secs(); object.values["active"] = framework.active; - object.values["resources"] = model(framework.resources); + object.values["resources"] = model(framework.used()); object.values["hostname"] = framework.info.hostname(); // TODO(benh): Consider making reregisteredTime an Option. http://git-wip-us.apache.org/repos/asf/mesos/blob/fd202698/src/master/master.cpp ---------------------------------------------------------------------- diff --git a/src/master/master.cpp b/src/master/master.cpp index c88d535..24234c2 100644 --- a/src/master/master.cpp +++ b/src/master/master.cpp @@ -3892,8 +3892,7 @@ void Master::addFramework(Framework* framework) message.mutable_master_info()->MergeFrom(info_); send(framework->pid, message); - allocator->frameworkAdded( - framework->id, framework->info, framework->resources); + allocator->frameworkAdded(framework->id, framework->info, framework->used()); // Export framework metrics. http://git-wip-us.apache.org/repos/asf/mesos/blob/fd202698/src/master/master.hpp ---------------------------------------------------------------------- diff --git a/src/master/master.hpp b/src/master/master.hpp index 41da240..f5bf417 100644 --- a/src/master/master.hpp +++ b/src/master/master.hpp @@ -1005,7 +1005,6 @@ struct Framework << " of framework " << task->framework_id(); tasks[task->task_id()] = task; - resources += task->resources(); } void addCompletedTask(const Task& task) @@ -1023,14 +1022,12 @@ struct Framework addCompletedTask(*task); tasks.erase(task->task_id()); - resources -= task->resources(); } void addOffer(Offer* offer) { CHECK(!offers.contains(offer)) << "Duplicate offer " << offer->id(); offers.insert(offer); - resources += offer->resources(); } void removeOffer(Offer* offer) @@ -1039,7 +1036,6 @@ struct Framework << "Unknown offer " << offer->id(); offers.erase(offer); - resources -= offer->resources(); } bool hasExecutor(const SlaveID& slaveId, @@ -1057,9 +1053,6 @@ struct Framework << " on slave " << slaveId; executors[slaveId][executorInfo.executor_id()] = executorInfo; - - // Update our resources to reflect running this executor. - resources += executorInfo.resources(); } void removeExecutor(const SlaveID& slaveId, @@ -1070,15 +1063,36 @@ struct Framework << " of framework " << id << " of slave " << slaveId; - // Update our resources to reflect removing this executor. - resources -= executors[slaveId][executorId].resources(); - executors[slaveId].erase(executorId); if (executors[slaveId].empty()) { executors.erase(slaveId); } } + Resources used() const + { + Resources used; + + foreach (Offer* offer, offers) { + used += offer->resources(); + } + + foreachvalue (const Task* task, tasks) { + if (!protobuf::isTerminalState(task->state())) { + used += task->resources(); + } + } + + foreachkey (const SlaveID& slaveId, executors) { + foreachvalue (const ExecutorInfo& executorInfo, + executors.find(slaveId)->second) { + used += executorInfo.resources(); + } + } + + return used; + } + const FrameworkID id; // TODO(benh): Store this in 'info'. const FrameworkInfo info; @@ -1103,8 +1117,6 @@ struct Framework hashset<Offer*> offers; // Active offers for framework. - Resources resources; // Total resources (tasks + offers + executors). - hashmap<SlaveID, hashmap<ExecutorID, ExecutorInfo> > executors; private: @@ -1133,7 +1145,7 @@ struct Role { Resources resources; foreachvalue (Framework* framework, frameworks) { - resources += framework->resources; + resources += framework->used(); } return resources;
