<< " extract the monmap from the local monitor store and exit\n"
<< " --mon-data <directory>\n"
<< " where the mon store and keyring are located\n"
+ << " --set-crush-location <bucket>=<foo>"
+ << " sets monitor's crush bucket location (only for stretch mode)"
<< std::endl;
generic_server_usage();
}
bool compact = false;
bool force_sync = false;
bool yes_really = false;
- std::string osdmapfn, inject_monmap, extract_monmap;
+ std::string osdmapfn, inject_monmap, extract_monmap, crush_loc;
vector<const char*> args;
argv_to_vec(argc, argv, args);
inject_monmap = val;
} else if (ceph_argparse_witharg(args, i, &val, "--extract-monmap", (char*)NULL)) {
extract_monmap = val;
+ } else if (ceph_argparse_witharg(args, i, &val, "--set-crush-location", (char*)NULL)) {
+ crush_loc = val;
} else {
++i;
}
msgr->start();
mgr_msgr->start();
+ mon->set_mon_crush_location(crush_loc);
mon->init();
register_async_signal_handler_oneshot(SIGINT, handle_mon_signal);
<< " vs my version " << paxos->get_version()
<< " (ok)"
<< dendl;
-
- if (monmap->contains(name) &&
- !monmap->get_addrs(name).front().is_blank_ip()) {
+ bool in_map = false;
+ const auto my_info = monmap->mon_info.find(name);
+ const map<string,string> *map_crush_loc{nullptr};
+ if (my_info != monmap->mon_info.end()) {
+ in_map = true;
+ map_crush_loc = &my_info->second.crush_loc;
+ }
+ if (in_map &&
+ !monmap->get_addrs(name).front().is_blank_ip() &&
+ (!need_set_crush_loc || (*map_crush_loc == crush_loc))) {
// i'm part of the cluster; just initiate a new election
start_election();
} else {
- dout(10) << " ready to join, but i'm not in the monmap or my addr is blank, trying to join" << dendl;
- send_mon_message(
- new MMonJoin(monmap->fsid, name, messenger->get_myaddrs()),
- *m->quorum.begin());
+ dout(10) << " ready to join, but i'm not in the monmap/"
+ "my addr is blank/location is wrong, trying to join" << dendl;
+ send_mon_message(new MMonJoin(monmap->fsid, name,
+ messenger->get_myaddrs(), crush_loc,
+ need_set_crush_loc),
+ *m->quorum.begin());
}
} else {
if (monmap->contains(m->name)) {
authmon()->_set_mon_num_rank(monmap->size(), rank);
}
- // am i named properly?
+ // am i named and located properly?
string cur_name = monmap->get_name(messenger->get_myaddrs());
- if (cur_name != name) {
- dout(10) << " renaming myself from " << cur_name << " -> " << name << dendl;
- send_mon_message(
- new MMonJoin(monmap->fsid, name, messenger->get_myaddrs()),
- *quorum.begin());
+ const auto my_infop = monmap->mon_info.find(cur_name);
+ const map<string,string>& map_crush_loc = my_infop->second.crush_loc;
+
+ if (cur_name != name ||
+ (need_set_crush_loc && map_crush_loc != crush_loc)) {
+ dout(10) << " renaming/moving myself from " << cur_name << "/"
+ << map_crush_loc <<" -> " << name << "/" << crush_loc << dendl;
+ send_mon_message(new MMonJoin(monmap->fsid, name, messenger->get_myaddrs(),
+ crush_loc, need_set_crush_loc),
+ *quorum.begin());
return;
}
do_stretch_mode_election_work();
return ret;
}
+void Monitor::set_mon_crush_location(const string& loc)
+{
+ if (loc.empty()) {
+ return;
+ }
+ vector<string> loc_vec;
+ loc_vec.push_back(loc);
+ CrushWrapper::parse_loc_map(loc_vec, &crush_loc);
+ need_set_crush_loc = true;
+}
+
void Monitor::notify_new_monmap(bool can_change_external_state)
{
+ if (need_set_crush_loc) {
+ auto my_info_i = monmap->mon_info.find(name);
+ if (my_info_i != monmap->mon_info.end() &&
+ my_info_i->second.crush_loc == crush_loc) {
+ need_set_crush_loc = false;
+ }
+ }
elector.notify_strategy_maybe_changed(monmap->strategy);
dout(30) << __func__ << "we have " << monmap->removed_ranks.size() << " removed ranks" << dendl;
for (auto i = monmap->removed_ranks.rbegin();
bool session_stretch_allowed(MonSession *s, MonOpRequestRef& op);
void disconnect_disallowed_stretch_sessions();
void set_elector_disallowed_leaders(bool allow_election);
+
+ map <string,string> crush_loc;
+ bool need_set_crush_loc{false};
public:
bool is_stretch_mode() { return stretch_mode_engaged; }
bool is_degraded_stretch_mode() { return degraded_stretch_mode; }
void trigger_healthy_stretch_mode();
void set_healthy_stretch_mode();
void enable_stretch_mode();
+ void set_mon_crush_location(const string& loc);
private: