Repository: mesos Updated Branches: refs/heads/master 1d24d42ea -> 7b0812e9b
Convert resource format of messages entering master. Review: https://reviews.apache.org/r/64252/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/114519a4 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/114519a4 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/114519a4 Branch: refs/heads/master Commit: 114519a46366b0e19f1ae0c64dcd2493c51a068a Parents: 1d24d42 Author: Benno Evers <bev...@mesosphere.com> Authored: Tue Dec 5 13:55:22 2017 -0800 Committer: Vinod Kone <vinodk...@gmail.com> Committed: Tue Dec 5 13:55:22 2017 -0800 ---------------------------------------------------------------------- src/master/master.cpp | 48 +++++++++++++++++++++++---------- src/master/registry_operations.cpp | 22 ++++++++++++--- 2 files changed, 52 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/114519a4/src/master/master.cpp ---------------------------------------------------------------------- diff --git a/src/master/master.cpp b/src/master/master.cpp index e8257e7..f77a1ed 100644 --- a/src/master/master.cpp +++ b/src/master/master.cpp @@ -6044,6 +6044,20 @@ void Master::registerSlave( slaves.registering.insert(from); + // Update all resources passed by the agent to `POST_RESERVATION_REFINEMENT` + // format. We do this as early as possible so that we only use a single + // format inside master, and downgrade again if necessary when they leave the + // master (e.g. when writing to the registry). + // TODO(bevers): Also convert the resources in `ExecutorInfos` and `Tasks` + // here for consistency. + SlaveInfo _slaveInfo(slaveInfo); + convertResourceFormat( + _slaveInfo.mutable_resources(), POST_RESERVATION_REFINEMENT); + + std::vector<Resource> _checkpointedResources(checkpointedResources); + convertResourceFormat( + &_checkpointedResources, POST_RESERVATION_REFINEMENT); + // Note that the principal may be empty if authentication is not // required. Also it is passed along because it may be removed from // `authenticated` while the authorization is pending. @@ -6052,10 +6066,10 @@ void Master::registerSlave( authorizeSlave(principal) .onAny(defer(self(), &Self::_registerSlave, - slaveInfo, + _slaveInfo, from, principal, - checkpointedResources, + _checkpointedResources, version, agentCapabilities, resourceVersions, @@ -6361,6 +6375,20 @@ void Master::reregisterSlave( Option<Error> error = validation::master::message::reregisterSlave( slaveInfo, tasks, checkpointedResources, executorInfos, frameworks); + // Update all resources passed by the agent to `POST_RESERVATION_REFINEMENT` + // format. We do this as early as possible so that we only use a single + // format inside master, and downgrade again if necessary when they leave the + // master (e.g. when writing to the registry). + // TODO(bevers): Also convert the resources in `ExecutorInfos` and `Tasks` + // here for consistency. + SlaveInfo _slaveInfo(slaveInfo); + convertResourceFormat( + _slaveInfo.mutable_resources(), POST_RESERVATION_REFINEMENT); + + std::vector<Resource> _checkpointedResources(checkpointedResources); + convertResourceFormat( + &_checkpointedResources, POST_RESERVATION_REFINEMENT); + if (error.isSome()) { LOG(WARNING) << "Dropping re-registration of agent at " << from << " because it sent an invalid re-registration: " @@ -6382,10 +6410,10 @@ void Master::reregisterSlave( authorizeSlave(principal) .onAny(defer(self(), &Self::_reregisterSlave, - slaveInfo, + _slaveInfo, from, principal, - checkpointedResources, + _checkpointedResources, executorInfos, tasks, frameworks, @@ -11024,11 +11052,7 @@ Slave::Slave( const vector<Task>& tasks) : master(_master), id(_info.id()), - info([&_info]() { - convertResourceFormat( - _info.mutable_resources(), POST_RESERVATION_REFINEMENT); - return _info; - }()), + info(_info), machineId(_machineId), pid(_pid), version(_version), @@ -11036,11 +11060,7 @@ Slave::Slave( registeredTime(_registeredTime), connected(true), active(true), - checkpointedResources([&_checkpointedResources]() { - convertResourceFormat( - &_checkpointedResources, POST_RESERVATION_REFINEMENT); - return _checkpointedResources; - }()), + checkpointedResources(_checkpointedResources), observer(nullptr), resourceVersions(_resourceVersions) { http://git-wip-us.apache.org/repos/asf/mesos/blob/114519a4/src/master/registry_operations.cpp ---------------------------------------------------------------------- diff --git a/src/master/registry_operations.cpp b/src/master/registry_operations.cpp index 1e1eadb..f9c2162 100644 --- a/src/master/registry_operations.cpp +++ b/src/master/registry_operations.cpp @@ -16,6 +16,8 @@ #include "master/registry_operations.hpp" +#include "common/resources_utils.hpp" + namespace mesos { namespace internal { namespace master { @@ -36,9 +38,15 @@ Try<bool> AdmitSlave::perform(Registry* registry, hashset<SlaveID>* slaveIDs) return Error("Agent already admitted"); } + // Convert the resource format back to `PRE_RESERVATION_REFINEMENT` so + // the data stored in the registry can be read by older master versions. + SlaveInfo _info(info); + convertResourceFormat(_info.mutable_resources(), + PRE_RESERVATION_REFINEMENT); + Registry::Slave* slave = registry->mutable_slaves()->add_slaves(); - slave->mutable_info()->CopyFrom(info); - slaveIDs->insert(info.id()); + slave->mutable_info()->CopyFrom(_info); + slaveIDs->insert(_info.id()); return true; // Mutation. } @@ -133,13 +141,19 @@ Try<bool> MarkSlaveReachable::perform( LOG(WARNING) << "Allowing UNKNOWN agent to reregister: " << info; } + // Convert the resource format back to `PRE_RESERVATION_REFINEMENT` so + // the data stored in the registry can be read by older master versions. + SlaveInfo _info(info); + convertResourceFormat(_info.mutable_resources(), + PRE_RESERVATION_REFINEMENT); + // Add the slave to the admitted list, even if we didn't find it // in the unreachable list. This accounts for when the slave was // unreachable for a long time, was GC'd from the unreachable // list, but then eventually reregistered. Registry::Slave* slave = registry->mutable_slaves()->add_slaves(); - slave->mutable_info()->CopyFrom(info); - slaveIDs->insert(info.id()); + slave->mutable_info()->CopyFrom(_info); + slaveIDs->insert(_info.id()); return true; // Mutation. }