Made it possible to update an operation without mutating resources.

In certain situations it can make sense to update the state of an
operation without also wanting to update resources. In this patch we
modify the master's `updateOperation` function to take an additional
parameter signifying whether resources should be updated, or whether
we only care about updating the operation and tracking of used
resources.

We will use this functionality in a subsequent patch to perform more
contained updates to agent state when processing `UpdateSlaveMessages`
which contain both resources and operations (and where any terminal
operations were already applied to the agent's resources).

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


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

Branch: refs/heads/1.5.x
Commit: 2edd93164d217d5229727582c97db9cd283ad16f
Parents: 62f157a
Author: Benjamin Bannier <[email protected]>
Authored: Fri Jan 12 15:40:37 2018 -0800
Committer: Greg Mann <[email protected]>
Committed: Fri Jan 12 17:17:39 2018 -0800

----------------------------------------------------------------------
 src/master/master.cpp | 43 ++++++++++++++++++++++++++-----------------
 src/master/master.hpp |  9 ++++++---
 2 files changed, 32 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2edd9316/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 07bf76a..32a955e 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -10316,7 +10316,8 @@ void Master::addOperation(
 
 void Master::updateOperation(
     Operation* operation,
-    const UpdateOperationStatusMessage& update)
+    const UpdateOperationStatusMessage& update,
+    bool convertResources)
 {
   CHECK_NOTNULL(operation);
 
@@ -10375,26 +10376,34 @@ void Master::updateOperation(
       const Resources converted =
         operation->latest_status().converted_resources();
 
-      allocator->updateAllocation(
-          operation->framework_id(),
-          operation->slave_id(),
-          consumed.get(),
-          {ResourceConversion(consumed.get(), converted)});
+      if (convertResources) {
+        allocator->updateAllocation(
+            operation->framework_id(),
+            operation->slave_id(),
+            consumed.get(),
+            {ResourceConversion(consumed.get(), converted)});
 
-      allocator->recoverResources(
-          operation->framework_id(),
-          operation->slave_id(),
-          converted,
-          None());
+        allocator->recoverResources(
+            operation->framework_id(),
+            operation->slave_id(),
+            converted,
+            None());
 
-      Resources consumedUnallocated = consumed.get();
-      consumedUnallocated.unallocate();
+        Resources consumedUnallocated = consumed.get();
+        consumedUnallocated.unallocate();
 
-      Resources convertedUnallocated = converted;
-      convertedUnallocated.unallocate();
+        Resources convertedUnallocated = converted;
+        convertedUnallocated.unallocate();
 
-      slave->apply(
-          {ResourceConversion(consumedUnallocated, convertedUnallocated)});
+        slave->apply(
+            {ResourceConversion(consumedUnallocated, convertedUnallocated)});
+      } else {
+        allocator->recoverResources(
+            operation->framework_id(),
+            operation->slave_id(),
+            consumed.get(),
+            None());
+      }
 
       break;
     }

http://git-wip-us.apache.org/repos/asf/mesos/blob/2edd9316/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index b1b4e10..366148b 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -873,11 +873,14 @@ protected:
       Slave* slave,
       Operation* operation);
 
-  // Transitions the operation, and recovers resources if the
-  // operation becomes terminal.
+  // Transitions the operation, and updates and recovers resources if
+  // the operation becomes terminal. If `convertResources` is `false`
+  // only the consumed resources of terminal operations are recovered,
+  // but no resources are converted.
   void updateOperation(
       Operation* operation,
-      const UpdateOperationStatusMessage& update);
+      const UpdateOperationStatusMessage& update,
+      bool convertResources = true);
 
   // Remove the operation.
   void removeOperation(Operation* operation);

Reply via email to