Maintenance Primitives: Updated master local state upon recovery. Note: Tests will be added with the related HTTP endpoints and registrar operations, later in this review chain.
Review: https://reviews.apache.org/r/37314 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/691a40e7 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/691a40e7 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/691a40e7 Branch: refs/heads/master Commit: 691a40e7e1c9d5db8d1869d0f61b7bac7bfdc915 Parents: 50344bc Author: Joseph Wu <[email protected]> Authored: Sun Aug 30 13:55:21 2015 -0400 Committer: Joris Van Remoortere <[email protected]> Committed: Mon Aug 31 13:09:33 2015 -0400 ---------------------------------------------------------------------- include/mesos/type_utils.hpp | 33 +++++++++++++++++++++++++++++++++ src/master/master.cpp | 10 ++++++++++ src/master/master.hpp | 11 +++++++++++ 3 files changed, 54 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/691a40e7/include/mesos/type_utils.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/type_utils.hpp b/include/mesos/type_utils.hpp index 1c8f95b..4fb0037 100644 --- a/include/mesos/type_utils.hpp +++ b/include/mesos/type_utils.hpp @@ -31,6 +31,7 @@ #include <stout/hashmap.hpp> #include <stout/stringify.hpp> +#include <stout/strings.hpp> #include <stout/uuid.hpp> // This file includes definitions for operators on public protobuf @@ -143,6 +144,21 @@ inline bool operator==(const TaskID& left, const std::string& right) } +/** + * For machines to match, both the `hostname` and `ip` must be equivalent. + * Hostname is not case sensitive, so it is lowercased before comparison. + */ +inline bool operator==(const MachineID& left, const MachineID& right) +{ + // NOTE: Both fields default to the empty string if they are not specified, + // so the string comparisons are safe. + return left.has_hostname() == right.has_hostname() && + strings::lower(left.hostname()) == strings::lower(right.hostname()) && + left.has_ip() == right.has_ip() && + left.ip() == right.ip(); +} + + inline bool operator!=(const ContainerID& left, const ContainerID& right) { return left.value() != right.value(); @@ -570,6 +586,23 @@ struct hash<std::pair<mesos::FrameworkID, mesos::ExecutorID>> } }; + +template <> +struct hash<mesos::MachineID> +{ + typedef size_t result_type; + + typedef mesos::MachineID argument_type; + + result_type operator()(const argument_type& machineId) const + { + size_t seed = 0; + boost::hash_combine(seed, strings::lower(machineId.hostname())); + boost::hash_combine(seed, machineId.ip()); + return seed; + } +}; + } // namespace std { #endif // __MESOS_TYPE_UTILS_H__ http://git-wip-us.apache.org/repos/asf/mesos/blob/691a40e7/src/master/master.cpp ---------------------------------------------------------------------- diff --git a/src/master/master.cpp b/src/master/master.cpp index b824f96..564fbcb 100644 --- a/src/master/master.cpp +++ b/src/master/master.cpp @@ -1331,6 +1331,16 @@ Future<Nothing> Master::_recover(const Registry& registry) &Self::recoveredSlavesTimeout, registry); + // Save the maintenance schedule. + foreach (const mesos::maintenance::Schedule& schedule, registry.schedules()) { + maintenance.schedules.push_back(schedule); + } + + // Save the machine info for each machine. + foreach (const Registry::Machine& machine, registry.machines().machines()) { + machineInfos[machine.info().id()] = machine.info(); + } + // Recovery is now complete! LOG(INFO) << "Recovered " << registry.slaves().slaves().size() << " slaves" << " from the Registry (" << Bytes(registry.ByteSize()) << ")" http://git-wip-us.apache.org/repos/asf/mesos/blob/691a40e7/src/master/master.hpp ---------------------------------------------------------------------- diff --git a/src/master/master.hpp b/src/master/master.hpp index 36c6759..edcbeed 100644 --- a/src/master/master.hpp +++ b/src/master/master.hpp @@ -28,6 +28,7 @@ #include <boost/circular_buffer.hpp> +#include <mesos/maintenance/maintenance.hpp> #include <mesos/mesos.hpp> #include <mesos/resources.hpp> #include <mesos/scheduler/scheduler.hpp> @@ -888,6 +889,16 @@ private: MasterInfo info_; + // Holds some info which affects how a machine behaves. + // See the `MachineInfo` protobuf for more information. + hashmap<MachineID, MachineInfo> machineInfos; + + struct Maintenance + { + // Holds the maintenance schedule, as given by the operator. + std::list<mesos::maintenance::Schedule> schedules; + } maintenance; + // Indicates when recovery is complete. Recovery begins once the // master is elected as a leader. Option<process::Future<Nothing>> recovered;
