]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MonClient: take all-0 weights as a special case 27126/head
authorKefu Chai <kchai@redhat.com>
Fri, 22 Mar 2019 13:36:13 +0000 (21:36 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 22 Mar 2019 14:31:00 +0000 (22:31 +0800)
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 <kchai@redhat.com>
src/mon/MonClient.cc
src/mon/MonMap.cc
src/mon/MonMap.h

index 3c361ef59e263e60aaf44cd88fbea8fed9b97e2a..2c36868c13c56c1d8cb6342251dcae5f874e716b 100644 (file)
@@ -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;
index 5ec7e8f32dcd18650d5aa5cb48a22028fbd886a3..215821d743a9f4c7e32045ca30f46154c71e78dd 100644 (file)
@@ -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);
     }
index 97db1e64c1cc592c84b6a83e2cfbda817eff4be7..65f933151b605f1a6e540034da48e34ab8f0445d 100644 (file)
@@ -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};
 
   // <REMOVE ME>
   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));
   }