From: Kefu Chai Date: Fri, 22 Mar 2019 13:36:13 +0000 (+0800) Subject: mon/MonClient: take all-0 weights as a special case X-Git-Tag: v15.0.0~104^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2d113dedf851995e000d3cce136b69bfa94b6fe0;p=ceph.git mon/MonClient: take all-0 weights as a special case if all weights of monitors are 0, it means the administrator want to use uniform distribution for the load balance. see page.2 of https://www.ietf.org/rfc/rfc2782.txt . so remove the default weight of 10. Signed-off-by: Kefu Chai --- diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index 3c361ef59e26..2c36868c13c5 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -730,8 +730,12 @@ void MonClient::_add_conns(uint64_t global_id) weights.push_back(monmap.get_weight(rank_name)); } std::random_device rd; - weighted_shuffle(begin(ranks), end(ranks), begin(weights), end(weights), - std::mt19937{rd()}); + if (std::accumulate(begin(weights), end(weights), 0u) == 0) { + std::shuffle(begin(ranks), end(ranks), std::mt19937{rd()}); + } else { + weighted_shuffle(begin(ranks), end(ranks), begin(weights), end(weights), + std::mt19937{rd()}); + } } ldout(cct, 10) << __func__ << " ranks=" << ranks << dendl; unsigned n = cct->_conf->mon_client_hunt_parallel; diff --git a/src/mon/MonMap.cc b/src/mon/MonMap.cc index 5ec7e8f32dcd..215821d743a9 100644 --- a/src/mon/MonMap.cc +++ b/src/mon/MonMap.cc @@ -466,7 +466,7 @@ int MonMap::init_with_ips(const std::string& ips, name = prefix; name += n; if (addrs[i].v.size() == 1) { - _add_ambiguous_addr(name, addrs[i].front(), 0, DEFAULT_WEIGHT, for_mkfs); + _add_ambiguous_addr(name, addrs[i].front(), 0, 0, for_mkfs); } else { // they specified an addrvec, so let's assume they also specified // the addr *type* and *port*. (we could possibly improve this?) @@ -501,7 +501,7 @@ int MonMap::init_with_hosts(const std::string& hostlist, string name = prefix; name += n; if (addrs[i].v.size() == 1) { - _add_ambiguous_addr(name, addrs[i].front(), 0, DEFAULT_WEIGHT, false); + _add_ambiguous_addr(name, addrs[i].front(), 0, 0, false); } else { add(name, addrs[i], 0); } diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index 97db1e64c1cc..65f933151b60 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -38,8 +38,6 @@ namespace ceph { class Formatter; } -constexpr uint16_t DEFAULT_WEIGHT = 10; - struct mon_info_t { /** * monitor name @@ -58,7 +56,7 @@ struct mon_info_t { * the priority of the mon, the lower value the more preferred */ uint16_t priority{0}; - uint16_t weight{DEFAULT_WEIGHT}; + uint16_t weight{0}; // mon_info_t(const string& n, const entity_addr_t& p_addr, uint16_t p) @@ -210,7 +208,7 @@ public: * @param addr Monitor's public address */ void add(const string &name, const entity_addrvec_t &addrv, - int priority=0, int weight=DEFAULT_WEIGHT) { + uint16_t priority=0, uint16_t weight=0) { add(mon_info_t(name, addrv, priority, weight)); }