| 2157 | |
| 2158 | |
| 2159 | void Master::detected(const Future<Option<MasterInfo>>& _leader) |
| 2160 | { |
| 2161 | CHECK(!_leader.isDiscarded()); |
| 2162 | |
| 2163 | if (_leader.isFailed()) { |
| 2164 | EXIT(EXIT_FAILURE) |
| 2165 | << "Failed to detect the leading master: " << _leader.failure() |
| 2166 | << "; committing suicide!"; |
| 2167 | } |
| 2168 | |
| 2169 | bool wasElected = elected(); |
| 2170 | leader = _leader.get(); |
| 2171 | |
| 2172 | if (elected()) { |
| 2173 | electedTime = Clock::now(); |
| 2174 | |
| 2175 | if (!wasElected) { |
| 2176 | LOG(INFO) << "Elected as the leading master!"; |
| 2177 | |
| 2178 | // Begin the recovery process, bail if it fails or is discarded. |
| 2179 | recover() |
| 2180 | .onFailed(lambda::bind(fail, "Recovery failed", lambda::_1)) |
| 2181 | .onDiscarded(lambda::bind(fail, "Recovery failed", "discarded")); |
| 2182 | } else { |
| 2183 | // This happens if there is a ZK blip that causes a re-election |
| 2184 | // but the same leading master is elected as leader. |
| 2185 | LOG(INFO) << "Re-elected as the leading master"; |
| 2186 | } |
| 2187 | } else if (leader.isSome()) { |
| 2188 | // A different node has been elected as the leading master. |
| 2189 | LOG(INFO) << "The newly elected leader is " << leader->pid() |
| 2190 | << " with id " << leader->id(); |
| 2191 | |
| 2192 | if (wasElected) { |
| 2193 | EXIT(EXIT_FAILURE) << "Conceded leadership to another master..." |
| 2194 | << " committing suicide!"; |
| 2195 | } |
| 2196 | |
| 2197 | // If this master and the current leader both have a configured |
| 2198 | // domain and the current leader is located in a different region, |
| 2199 | // exit with an error message: this indicates a configuration |
| 2200 | // error, since all masters must be in the same region. |
| 2201 | if (leader->has_domain() && info_.has_domain()) { |
| 2202 | const DomainInfo& leaderDomain = leader->domain(); |
| 2203 | const DomainInfo& selfDomain = info_.domain(); |
| 2204 | |
| 2205 | // We currently reject configured domains without fault domains, |
| 2206 | // but that might change in the future. For compatibility with |
| 2207 | // future versions of Mesos, we treat a master with a configured |
| 2208 | // domain but no fault domain as equivalent to a master with no |
| 2209 | // configured domain. |
| 2210 | if (leaderDomain.has_fault_domain() && selfDomain.has_fault_domain()) { |
| 2211 | const DomainInfo::FaultDomain::RegionInfo& leaderRegion = |
| 2212 | leaderDomain.fault_domain().region(); |
| 2213 | const DomainInfo::FaultDomain::RegionInfo& selfRegion = |
| 2214 | selfDomain.fault_domain().region(); |
| 2215 | |
| 2216 | if (leaderRegion != selfRegion) { |