You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mz...@apache.org on 2019/08/14 03:40:32 UTC

[mesos] branch master updated (6fcbd99 -> 1310bd0)

This is an automated email from the ASF dual-hosted git repository.

mzhu pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git.


    from 6fcbd99  Fixed agent draining when returning from unreachable state.
     new cb7b70d  Fixed and improved `Sorter::remove` function.
     new 54b4543  Defined constant `DEFAULT_WEIGHT`.
     new 1310bd0  Tracked weight info in the Role struct in the allocator.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/master/allocator/mesos/hierarchical.cpp        |  1 +
 src/master/allocator/mesos/hierarchical.hpp        |  9 +++++++-
 src/master/allocator/mesos/sorter/drf/sorter.cpp   | 26 +++++++++-------------
 .../allocator/mesos/sorter/random/sorter.cpp       | 26 +++++++++-------------
 src/master/constants.hpp                           |  3 +++
 5 files changed, 34 insertions(+), 31 deletions(-)


[mesos] 01/03: Fixed and improved `Sorter::remove` function.

Posted by mz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mzhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit cb7b70db813a8e4d2628e9283e25780cd0ce11b0
Author: Meng Zhu <mz...@mesosphere.io>
AuthorDate: Wed Aug 7 16:11:20 2019 -0700

    Fixed and improved `Sorter::remove` function.
    
    There is a bug in the remove() function where after collapsing
    and turning an internal node into an leaf node, the new node's
    position needs to updated in the parent's children list.
    See MESOS-9930.
    
    This patch fixes the bug and also refactored the function logic.
    
    Review: https://reviews.apache.org/r/71255
---
 src/master/allocator/mesos/sorter/drf/sorter.cpp   | 23 +++++++++-------------
 .../allocator/mesos/sorter/random/sorter.cpp       | 23 +++++++++-------------
 2 files changed, 18 insertions(+), 28 deletions(-)

diff --git a/src/master/allocator/mesos/sorter/drf/sorter.cpp b/src/master/allocator/mesos/sorter/drf/sorter.cpp
index 40397f7..b7da3ff 100644
--- a/src/master/allocator/mesos/sorter/drf/sorter.cpp
+++ b/src/master/allocator/mesos/sorter/drf/sorter.cpp
@@ -207,15 +207,14 @@ void DRFSorter::remove(const string& clientPath)
     }
 
     if (current->children.empty()) {
+      // Simply delete the current node if it has no children.
       parent->removeChild(current);
       delete current;
     } else if (current->children.size() == 1) {
-      // If `current` has only one child that was created to
-      // accommodate inserting `clientPath` (see `DRFSorter::add()`),
-      // we can remove the child node and turn `current` back into a
+      // If `current` has only one virtual node ".", we can collapse
+      // and remove that node, and turn `current` back into a
       // leaf node.
       Node* child = *(current->children.begin());
-
       if (child->name == ".") {
         CHECK(child->isLeaf());
         CHECK(clients.contains(current->path));
@@ -223,20 +222,16 @@ void DRFSorter::remove(const string& clientPath)
 
         current->kind = child->kind;
         current->removeChild(child);
+        delete child;
 
         // `current` has changed kind (from `INTERNAL` to a leaf,
-        // which might be active or inactive). Hence we might need to
-        // change its position in the `children` list.
-        if (current->kind == Node::INTERNAL) {
-          CHECK_NOTNULL(current->parent);
-
-          current->parent->removeChild(current);
-          current->parent->addChild(current);
-        }
+        // which might be active or inactive). We need to change
+        // its position in the `children` list.
+        CHECK_NOTNULL(current->parent);
+        current->parent->removeChild(current);
+        current->parent->addChild(current);
 
         clients[current->path] = current;
-
-        delete child;
       }
     }
 
diff --git a/src/master/allocator/mesos/sorter/random/sorter.cpp b/src/master/allocator/mesos/sorter/random/sorter.cpp
index b480aee..3e93a4a 100644
--- a/src/master/allocator/mesos/sorter/random/sorter.cpp
+++ b/src/master/allocator/mesos/sorter/random/sorter.cpp
@@ -201,15 +201,14 @@ void RandomSorter::remove(const string& clientPath)
     }
 
     if (current->children.empty()) {
+      // Simply delete the current node if it has no children.
       parent->removeChild(current);
       delete current;
     } else if (current->children.size() == 1) {
-      // If `current` has only one child that was created to
-      // accommodate inserting `clientPath` (see `RandomSorter::add()`),
-      // we can remove the child node and turn `current` back into a
+      // If `current` has only one virtual node ".", we can collapse
+      // and remove that node, and turn `current` back into a
       // leaf node.
       Node* child = *(current->children.begin());
-
       if (child->name == ".") {
         CHECK(child->isLeaf());
         CHECK(clients.contains(current->path));
@@ -217,20 +216,16 @@ void RandomSorter::remove(const string& clientPath)
 
         current->kind = child->kind;
         current->removeChild(child);
+        delete child;
 
         // `current` has changed kind (from `INTERNAL` to a leaf,
-        // which might be active or inactive). Hence we might need to
-        // change its position in the `children` list.
-        if (current->kind == Node::INTERNAL) {
-          CHECK_NOTNULL(current->parent);
-
-          current->parent->removeChild(current);
-          current->parent->addChild(current);
-        }
+        // which might be active or inactive). We need to change
+        // its position in the `children` list.
+        CHECK_NOTNULL(current->parent);
+        current->parent->removeChild(current);
+        current->parent->addChild(current);
 
         clients[current->path] = current;
-
-        delete child;
       }
     }
 


[mesos] 02/03: Defined constant `DEFAULT_WEIGHT`.

Posted by mz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mzhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 54b45433e13579f6ab84fb955ee5248d9737ffd8
Author: Meng Zhu <mz...@mesosphere.io>
AuthorDate: Tue Aug 6 12:28:04 2019 -0700

    Defined constant `DEFAULT_WEIGHT`.
    
    A role's default weight == 1.0. This affects the sorting
    precedence during resource allocation.
    
    Review: https://reviews.apache.org/r/71257
---
 src/master/allocator/mesos/sorter/drf/sorter.cpp    | 3 ++-
 src/master/allocator/mesos/sorter/random/sorter.cpp | 3 ++-
 src/master/constants.hpp                            | 3 +++
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/master/allocator/mesos/sorter/drf/sorter.cpp b/src/master/allocator/mesos/sorter/drf/sorter.cpp
index b7da3ff..09889cd 100644
--- a/src/master/allocator/mesos/sorter/drf/sorter.cpp
+++ b/src/master/allocator/mesos/sorter/drf/sorter.cpp
@@ -15,6 +15,7 @@
 // limitations under the License.
 
 #include "master/allocator/mesos/sorter/drf/sorter.hpp"
+#include "master/constants.hpp"
 
 #include <iterator>
 #include <set>
@@ -654,7 +655,7 @@ double DRFSorter::calculateShare(const Node* node) const
 double DRFSorter::getWeight(const Node* node) const
 {
   if (node->weight.isNone()) {
-    node->weight = weights.get(node->path).getOrElse(1.0);
+    node->weight = weights.get(node->path).getOrElse(DEFAULT_WEIGHT);
   }
 
   return CHECK_NOTNONE(node->weight);
diff --git a/src/master/allocator/mesos/sorter/random/sorter.cpp b/src/master/allocator/mesos/sorter/random/sorter.cpp
index 3e93a4a..60a5797 100644
--- a/src/master/allocator/mesos/sorter/random/sorter.cpp
+++ b/src/master/allocator/mesos/sorter/random/sorter.cpp
@@ -16,6 +16,7 @@
 
 #include "master/allocator/mesos/sorter/random/sorter.hpp"
 #include "master/allocator/mesos/sorter/random/utils.hpp"
+#include "master/constants.hpp"
 
 #include <set>
 #include <string>
@@ -494,7 +495,7 @@ size_t RandomSorter::count() const
 double RandomSorter::getWeight(const Node* node) const
 {
   if (node->weight.isNone()) {
-    node->weight = weights.get(node->path).getOrElse(1.0);
+    node->weight = weights.get(node->path).getOrElse(DEFAULT_WEIGHT);
   }
 
   return CHECK_NOTNONE(node->weight);
diff --git a/src/master/constants.hpp b/src/master/constants.hpp
index 26afa35..c384b68 100644
--- a/src/master/constants.hpp
+++ b/src/master/constants.hpp
@@ -176,6 +176,9 @@ std::vector<MasterInfo::Capability> MASTER_CAPABILITIES();
 // A role's default quota: no guarantees and no limits.
 const Quota DEFAULT_QUOTA;
 
+// Default weight for a role.
+constexpr double DEFAULT_WEIGHT = 1.0;
+
 } // namespace master {
 } // namespace internal {
 } // namespace mesos {


[mesos] 03/03: Tracked weight info in the Role struct in the allocator.

Posted by mz...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mzhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 1310bd0dfb826ed6dac80ef26a9bd5b6a9229752
Author: Meng Zhu <mz...@mesosphere.io>
AuthorDate: Tue Aug 6 12:35:23 2019 -0700

    Tracked weight info in the Role struct in the allocator.
    
    Review: https://reviews.apache.org/r/71258
---
 src/master/allocator/mesos/hierarchical.cpp | 1 +
 src/master/allocator/mesos/hierarchical.hpp | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index 87b03d3..580d35a 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -1415,6 +1415,7 @@ void HierarchicalAllocatorProcess::updateWeights(
 
   foreach (const WeightInfo& weightInfo, weightInfos) {
     CHECK(weightInfo.has_role());
+    roles[weightInfo.role()].weight = weightInfo.weight();
     roleSorter->updateWeight(weightInfo.role(), weightInfo.weight());
   }
 
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index dee5baf..8be8dce 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -111,6 +111,8 @@ struct Framework
 
 struct Role
 {
+  Role() : weight(DEFAULT_WEIGHT) {}
+
   // IDs of the frameworks susbscibed to the role, if any.
   hashset<FrameworkID> frameworks;
 
@@ -124,11 +126,16 @@ struct Role
   // this role. By default, a role has no guarantee and no limit.
   Quota quota;
 
+  // Configured weight for the role. This affects sorting precedence.
+  // By default, weights == DEFAULT_WEIGHT == 1.0.
+  double weight;
+
   bool isEmpty() const
   {
     return frameworks.empty() &&
            reservationScalarQuantities.empty() &&
-           quota == DEFAULT_QUOTA;
+           quota == DEFAULT_QUOTA &&
+           weight == DEFAULT_WEIGHT;
   }
 };