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 b00b32682daf49182b6e405f7261cdb7523af082
Author: Andrei Sekretenko <[email protected]>
AuthorDate: Wed May 22 16:39:51 2019 +0200

    Refactored `untrackReservations()` method.
    
    This patch gets rid of insertion into the beginning of the vector
    and also of shadowing HierarchicalAllocatorProcess::roles by a local.
    
    Review: https://reviews.apache.org/r/70626/
---
 src/master/allocator/mesos/hierarchical.cpp | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/master/allocator/mesos/hierarchical.cpp 
b/src/master/allocator/mesos/hierarchical.cpp
index 6df9a3b..d8655e9 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -2653,11 +2653,7 @@ void HierarchicalAllocatorProcess::untrackReservations(
       continue; // Do not CHECK for the role if there's nothing to untrack.
     }
 
-    // Untrack it hierarchically up to the top level role.
-    vector<string> roles = roles::ancestors(role);
-    roles.insert(roles.begin(), role);
-
-    for (const string& r : roles) {
+    auto untrack = [&](const string& r) {
       CHECK_CONTAINS(reservationScalarQuantities, r);
 
       ResourceQuantities& currentReservationQuantities =
@@ -2672,6 +2668,12 @@ void HierarchicalAllocatorProcess::untrackReservations(
       if (currentReservationQuantities.empty()) {
         reservationScalarQuantities.erase(r);
       }
+    };
+
+    // Untrack it hierarchically up to the top level role.
+    untrack(role);
+    for (const string& ancestor : roles::ancestors(role)) {
+      untrack(ancestor);
     }
   }
 }

Reply via email to