]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MonClient: random all ranks then pick first_n 13479/head
authorMingxin Liu <mingxin@xsky.com>
Fri, 17 Feb 2017 10:25:05 +0000 (18:25 +0800)
committerMingxin Liu <mingxin@xsky.com>
Sat, 18 Feb 2017 13:57:45 +0000 (21:57 +0800)
Signed-off-by: Mingxin Liu <mingxin@xsky.com>
src/mon/MonClient.cc

index 93f2223b5a41e2b52da04882d41f58269124ab93..f6233a9b7b19b98b23b5ce07e54317e22fe74378 100644 (file)
@@ -625,17 +625,19 @@ MonConnection& MonClient::_add_conn(unsigned rank)
 
 void MonClient::_add_conns()
 {
-  unsigned n = cct->_conf->mon_client_hunt_parallel;
-  if (n == 0 || n > monmap.size()) {
-    n = monmap.size();
-  }
-  vector<unsigned> ranks(n);
-  for (unsigned i = 0; i < n; i++) {
+  const unsigned num_mons = monmap.size();
+  vector<unsigned> ranks(num_mons);
+  for (unsigned i = 0; i < num_mons; i++) {
     ranks[i] = i;
   }
   std::random_device rd;
   std::mt19937 rng(rd());
   std::shuffle(ranks.begin(), ranks.end(), rng);
+
+  unsigned n = cct->_conf->mon_client_hunt_parallel;
+  if (n == 0 || n > monmap.size()) {
+     n = num_mons;
+  }
   for (unsigned i = 0; i < n; i++) {
     _add_conn(ranks[i]);
   }