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/69930fe9 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/69930fe9 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/69930fe9 Branch: refs/heads/master Commit: 69930fe93bcb513c16f4f575b504978d6e0d96dc Parents: dd866f9 Author: Benjamin Bannier <[email protected]> Authored: Fri Jan 12 15:40:37 2018 -0800 Committer: Greg Mann <[email protected]> Committed: Fri Jan 12 16:53:50 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/69930fe9/src/master/master.cpp ---------------------------------------------------------------------- diff --git a/src/master/master.cpp b/src/master/master.cpp index 6965514..b3fdc88 100644 --- a/src/master/master.cpp +++ b/src/master/master.cpp @@ -10289,7 +10289,8 @@ void Master::addOperation( void Master::updateOperation( Operation* operation, - const UpdateOperationStatusMessage& update) + const UpdateOperationStatusMessage& update, + bool convertResources) { CHECK_NOTNULL(operation); @@ -10348,26 +10349,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/69930fe9/src/master/master.hpp ---------------------------------------------------------------------- diff --git a/src/master/master.hpp b/src/master/master.hpp index 0c05b20..3d5180b 100644 --- a/src/master/master.hpp +++ b/src/master/master.hpp @@ -878,11 +878,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);
