]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
* get_rand_in_mds
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Fri, 13 Jul 2007 13:43:00 +0000 (13:43 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Fri, 13 Jul 2007 13:43:00 +0000 (13:43 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1494 29311d96-e01e-0410-9327-a35deaab8ce9

trunk/ceph/client/Client.cc
trunk/ceph/mds/MDSMap.h

index a0ad42ee10c72f320440ced3124348e840fb9ca4..d61bf4696ccbe7b010077784ea0d59f3aacd23fc 100644 (file)
@@ -513,7 +513,8 @@ int Client::choose_target_mds(MClientRequest *req)
   // pick mds
   if (!diri || g_conf.client_use_random_mds) {
     // no root info, pick a random MDS
-    mds = rand() % mdsmap->get_num_mds();
+    mds = mdsmap->get_random_in_mds();
+    if (mds < 0) mds = 0;
   } else {
     if (req->auth_is_best()) {
       // pick the actual auth (as best we can)
index 0c7f5697310ad9756c99d41e12cc2fb46005ef6d..d72e6a1f21cca2da7e09ce65b36af4ba2082be9b 100644 (file)
@@ -186,6 +186,18 @@ class MDSMap {
        s.insert(p->first);
   }
 
+  int get_random_in_mds() {
+    vector<int> v;
+    for (map<int,int>::const_iterator p = mds_state.begin();
+        p != mds_state.end();
+        p++)
+      if (p->second > 0) v.push_back(p->first);
+    if (v.empty())
+      return -1;
+    else 
+      return v[rand() % v.size()];
+  }
+
 
   // mds states
   bool is_down(int m) { return is_dne(m) || is_stopped(m) || is_failed(m); }