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/02/19 20:45:16 UTC

git commit: Fixed comparator in tasks endpoint.

Repository: mesos
Updated Branches:
  refs/heads/master 83a39931e -> db3b5ed86


Fixed comparator in tasks endpoint.

Related to MESOS-979, the tasks.json endpoint would sporadically cause the
master process to SEGFAULT. The code failed during the subsequent sort
(after gathering running and completed tasks) deferencing garbage pointer
values. The issue turns out to be an issue with std::sort and strict weak-
ordering. Descending order (which was default) was implemented as !ascending()
which is not a strict greather-than equal. This patch expands the descending
implementation and reenables endpoint.

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


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

Branch: refs/heads/master
Commit: db3b5ed86b7f5a8d10fd8fc3fd59eb6faec2fe20
Parents: 83a3993
Author: Niklas Q. Nielsen <ni...@mesosphere.io>
Authored: Wed Feb 19 11:38:21 2014 -0800
Committer: Niklas Q. Nielsen <ni...@mesosphere.io>
Committed: Wed Feb 19 11:40:07 2014 -0800

----------------------------------------------------------------------
 src/master/http.cpp   | 28 +++++++++++++++++++++++++---
 src/master/master.cpp |  9 +++------
 2 files changed, 28 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/db3b5ed8/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 6aeb257..c941274 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -619,11 +619,18 @@ struct TaskComparator
 {
   static bool ascending(const Task* lhs, const Task* rhs)
   {
-    if (lhs->statuses().size() == 0) {
+    size_t lhsSize = lhs->statuses().size();
+    size_t rhsSize = rhs->statuses().size();
+
+    if ((lhsSize == 0) && (rhsSize == 0)) {
+      return false;
+    }
+
+    if (lhsSize == 0) {
       return true;
     }
 
-    if (rhs->statuses().size() == 0) {
+    if (rhsSize == 0) {
       return false;
     }
 
@@ -632,7 +639,22 @@ struct TaskComparator
 
   static bool descending(const Task* lhs, const Task* rhs)
   {
-    return !ascending(lhs, rhs);
+    size_t lhsSize = lhs->statuses().size();
+    size_t rhsSize = rhs->statuses().size();
+
+    if ((lhsSize == 0) && (rhsSize == 0)) {
+      return false;
+    }
+
+    if (rhsSize == 0) {
+      return true;
+    }
+
+    if (lhsSize == 0) {
+      return false;
+    }
+
+    return (lhs->statuses(0).timestamp() > rhs->statuses(0).timestamp());
   }
 };
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/db3b5ed8/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index f4f5e04..cb46869 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -477,12 +477,9 @@ void Master::initialize()
   route("/stats.json",
         None(),
         lambda::bind(&Http::roles, http, lambda::_1));
-
-  // TODO(vinod): This route has been temporarily disabled due to
-  // MESOS-979.
-//  route("/tasks.json",
-//        Http::TASKS_HELP,
-//        lambda::bind(&Http::tasks, http, lambda::_1));
+  route("/tasks.json",
+        Http::TASKS_HELP,
+        lambda::bind(&Http::tasks, http, lambda::_1));
 
   // Provide HTTP assets from a "webui" directory. This is either
   // specified via flags (which is necessary for running out of the