You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ne...@apache.org on 2017/05/24 21:45:01 UTC

[6/7] mesos git commit: Introduced `DRFSorter::Node::isLeaf()`.

Introduced `DRFSorter::Node::isLeaf()`.

This helps clarify code that wants to distinguish between leaves and
internal nodes in the sorter.

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


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

Branch: refs/heads/master
Commit: fd58fa149fad807232eb68fed2a4fc22c8a08f54
Parents: dcb0b7c
Author: Neil Conway <ne...@gmail.com>
Authored: Tue May 23 10:36:17 2017 -0700
Committer: Neil Conway <ne...@gmail.com>
Committed: Wed May 24 14:40:34 2017 -0700

----------------------------------------------------------------------
 src/master/allocator/sorter/drf/sorter.cpp | 22 ++++++----------------
 src/master/allocator/sorter/drf/sorter.hpp | 10 ++++++++++
 2 files changed, 16 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/fd58fa14/src/master/allocator/sorter/drf/sorter.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/sorter/drf/sorter.cpp b/src/master/allocator/sorter/drf/sorter.cpp
index 74da5b1..1d8959d 100644
--- a/src/master/allocator/sorter/drf/sorter.cpp
+++ b/src/master/allocator/sorter/drf/sorter.cpp
@@ -99,13 +99,7 @@ void DRFSorter::add(const string& clientPath)
     // leaf node into an internal node, we need to create an
     // additional child node: `current` must have been associated with
     // a client and clients must always be associated with leaf nodes.
-    //
-    // There are two exceptions: if `current` is the root node or it
-    // was just created by the current `add()` call, it does not
-    // correspond to a client, so we don't create an extra child.
-    if (current->children.empty() &&
-        current != root &&
-        current != lastCreatedNode) {
+    if (current->isLeaf()) {
       Node* parent = CHECK_NOTNULL(current->parent);
 
       parent->removeChild(current);
@@ -122,9 +116,10 @@ void DRFSorter::add(const string& clientPath)
       // `internal`.
       current->name = ".";
       current->parent = internal;
-      internal->addChild(current);
       current->path = strings::join("/", parent->path, current->name);
 
+      internal->addChild(current);
+
       CHECK_EQ(internal->path, current->clientPath());
 
       current = internal;
@@ -155,8 +150,7 @@ void DRFSorter::add(const string& clientPath)
   }
 
   // `current` is the newly created node associated with the last
-  // element of the path. `current` should be an inactive node with no
-  // children.
+  // element of the path. `current` should be an inactive leaf node.
   CHECK(current->children.empty());
   CHECK(current->kind == Node::INACTIVE_LEAF);
 
@@ -228,9 +222,7 @@ void DRFSorter::remove(const string& clientPath)
       Node* child = *(current->children.begin());
 
       if (child->name == ".") {
-        CHECK(child->children.empty());
-        CHECK(child->kind == Node::ACTIVE_LEAF ||
-              child->kind == Node::INACTIVE_LEAF);
+        CHECK(child->isLeaf());
         CHECK(clients.contains(current->path));
         CHECK_EQ(child, clients.at(current->path));
 
@@ -578,9 +570,7 @@ DRFSorter::Node* DRFSorter::find(const string& clientPath) const
 
   Node* client = client_.get();
 
-  CHECK(client->kind == Node::ACTIVE_LEAF ||
-        client->kind == Node::INACTIVE_LEAF);
-  CHECK(client->children.empty());
+  CHECK(client->isLeaf());
 
   return client;
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/fd58fa14/src/master/allocator/sorter/drf/sorter.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/sorter/drf/sorter.hpp b/src/master/allocator/sorter/drf/sorter.hpp
index f76d2f7..67700d5 100644
--- a/src/master/allocator/sorter/drf/sorter.hpp
+++ b/src/master/allocator/sorter/drf/sorter.hpp
@@ -267,6 +267,16 @@ struct DRFSorter::Node
     return path;
   }
 
+  bool isLeaf() const
+  {
+    if (kind == ACTIVE_LEAF || kind == INACTIVE_LEAF) {
+      CHECK(children.empty());
+      return true;
+    }
+
+    return false;
+  }
+
   void removeChild(const Node* child)
   {
     auto it = std::find(children.begin(), children.end(), child);