void mon_info_t::encode(bufferlist& bl, uint64_t features) const
{
- uint8_t v = 3;
+ uint8_t v = 4;
if (!HAVE_FEATURE(features, SERVER_NAUTILUS)) {
v = 2;
}
encode(public_addrs, bl, features);
}
encode(priority, bl);
+ encode(weight, bl);
ENCODE_FINISH(bl);
}
void mon_info_t::decode(bufferlist::const_iterator& p)
{
- DECODE_START(3, p);
+ DECODE_START(4, p);
decode(name, p);
decode(public_addrs, p);
if (struct_v >= 2) {
decode(priority, p);
}
+ if (struct_v >= 4) {
+ decode(weight, p);
+ }
DECODE_FINISH(p);
}
{
out << "mon." << name
<< " addrs " << public_addrs
- << " priority " << priority;
+ << " priority " << priority
+ << " weight " << weight;
}
namespace {
entity_addrvec_t local_pub_addr;
local_pub_addr.parse(local_pub_addr_s, &end_p);
- m->add(mon_info_t("filled_pub_addr", entity_addrvec_t(local_pub_addr), 1));
+ m->add(mon_info_t("filled_pub_addr", entity_addrvec_t(local_pub_addr), 1, 1));
m->add("empty_addr_zero", entity_addrvec_t());
}
// when that happens we need to try them both (unless we can
// reasonably infer from the port number which it is).
void MonMap::_add_ambiguous_addr(const string& name,
- entity_addr_t addr,
- int priority,
- bool for_mkfs)
+ entity_addr_t addr,
+ int priority,
+ int weight,
+ bool for_mkfs)
{
if (addr.get_type() != entity_addr_t::TYPE_ANY) {
// a v1: or v2: prefix was specified
return;
}
if (!contains(addr)) {
- add(name, entity_addrvec_t(addr), priority);
+ add(name, entity_addrvec_t(addr), priority, weight);
}
} else {
if (!contains(addr)) {
- add(name, entity_addrvec_t(addr), priority);
+ add(name, entity_addrvec_t(addr), priority, weight);
}
}
} else {
addr.set_type(entity_addr_t::TYPE_LEGACY);
if (!contains(addr)) {
if (!for_mkfs) {
- add(name + "-legacy", entity_addrvec_t(addr), priority);
+ add(name + "-legacy", entity_addrvec_t(addr), priority, weight);
} else {
- add(name, entity_addrvec_t(addr), priority);
+ add(name, entity_addrvec_t(addr), priority, weight);
}
}
} else if (addr.get_port() == CEPH_MON_PORT_IANA) {
// iana port implies msgr2 addr
addr.set_type(entity_addr_t::TYPE_MSGR2);
if (!contains(addr)) {
- add(name, entity_addrvec_t(addr), priority);
+ add(name, entity_addrvec_t(addr), priority, weight);
}
} else if (addr.get_port() == 0) {
// no port; include both msgr2 and legacy ports
addr.set_type(entity_addr_t::TYPE_MSGR2);
addr.set_port(CEPH_MON_PORT_IANA);
if (!contains(addr)) {
- add(name, entity_addrvec_t(addr), priority);
+ add(name, entity_addrvec_t(addr), priority, weight);
}
addr.set_type(entity_addr_t::TYPE_LEGACY);
addr.set_port(CEPH_MON_PORT_LEGACY);
if (!contains(addr)) {
- add(name + "-legacy", entity_addrvec_t(addr), priority);
+ add(name + "-legacy", entity_addrvec_t(addr), priority, weight);
}
} else {
entity_addrvec_t av;
addr.set_port(CEPH_MON_PORT_LEGACY);
av.v.push_back(addr);
if (!contains(av)) {
- add(name, av, priority);
+ add(name, av, priority, weight);
}
}
} else {
addr.set_type(entity_addr_t::TYPE_MSGR2);
if (!contains(addr)) {
- add(name, entity_addrvec_t(addr), priority);
+ add(name, entity_addrvec_t(addr), priority, weight);
}
if (!for_mkfs) {
// try legacy on same port too
addr.set_type(entity_addr_t::TYPE_LEGACY);
if (!contains(addr)) {
- add(name + "-legacy", entity_addrvec_t(addr), priority);
+ add(name + "-legacy", entity_addrvec_t(addr), priority, weight);
}
}
}
name = prefix;
name += n;
if (addrs[i].v.size() == 1) {
- _add_ambiguous_addr(name, addrs[i].front(), 0, for_mkfs);
+ _add_ambiguous_addr(name, addrs[i].front(), 0, DEFAULT_WEIGHT, for_mkfs);
} else {
// they specified an addrvec, so let's assume they also specified
// the addr *type* and *port*. (we could possibly improve this?)
string name = prefix;
name += n;
if (addrs[i].v.size() == 1) {
- _add_ambiguous_addr(name, addrs[i].front(), 0);
+ _add_ambiguous_addr(name, addrs[i].front(), 0, DEFAULT_WEIGHT, false);
} else {
add(name, addrs[i], 0);
}
continue;
}
}
+ uint16_t weight = 0;
+ if (!conf.get_val_from_conf_file(sections, "mon weight", val, false)) {
+ try {
+ weight = std::stoul(val);
+ } catch (std::logic_error&) {
+ errout << "unable to parse weight for mon." << mon_name
+ << ": weight='" << val << "'"
+ << std::endl;
+ continue;
+ }
+ }
- // the make sure this mon isn't already in the map
+ // make sure this mon isn't already in the map
if (contains(addr))
remove(get_name(addr));
if (contains(mon_name))
remove(mon_name);
- _add_ambiguous_addr(mon_name, addr, priority);
+ _add_ambiguous_addr(mon_name, addr, priority, weight, false);
}
return 0;
}
addr.in6_addr().sin6_addr = a;
break;
}
- _add_ambiguous_addr(record.target, addr, record.priority);
+ _add_ambiguous_addr(record.target,
+ addr,
+ record.priority,
+ record.weight,
+ false);
});
});
}).handle_exception_type([](const std::system_error& e) {
} else {
for (auto& record : records) {
record.second.addr.set_type(entity_addr_t::TYPE_ANY);
- _add_ambiguous_addr(record.first, record.second.addr,
- record.second.priority);
+ _add_ambiguous_addr(record.first,
+ record.second.addr,
+ record.second.priority,
+ record.second.weight,
+ false);
}
return 0;
}
class Formatter;
}
+constexpr uint16_t DEFAULT_WEIGHT = 10;
+
struct mon_info_t {
/**
* monitor name
* the priority of the mon, the lower value the more preferred
*/
uint16_t priority{0};
+ uint16_t weight{DEFAULT_WEIGHT};
// <REMOVE ME>
mon_info_t(const string& n, const entity_addr_t& p_addr, uint16_t p)
{}
// </REMOVE ME>
- mon_info_t(const string& n, const entity_addrvec_t& p_addrs, uint16_t p)
- : name(n), public_addrs(p_addrs), priority(p)
+ mon_info_t(const string& n, const entity_addrvec_t& p_addrs,
+ uint16_t p, uint16_t w)
+ : name(n), public_addrs(p_addrs), priority(p), weight(w)
{}
mon_info_t(const string &n, const entity_addrvec_t& p_addrs)
: name(n), public_addrs(p_addrs)
uint8_t min_mon_release = 0;
void _add_ambiguous_addr(const string& name,
- entity_addr_t addr,
- int priority,
- bool for_mkfs=false);
+ entity_addr_t addr,
+ int priority,
+ int weight,
+ bool for_mkfs);
public:
void calc_legacy_ranks();
* @param addr Monitor's public address
*/
void add(const string &name, const entity_addrvec_t &addrv,
- int priority=0) {
- add(mon_info_t(name, addrv, priority));
+ int priority=0, int weight=DEFAULT_WEIGHT) {
+ add(mon_info_t(name, addrv, priority, weight));
}
/**