]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: OSDMonitor: only share osdmap with up OSDs
authorJoao Eduardo Luis <joao.luis@inktank.com>
Sat, 12 Jan 2013 01:06:36 +0000 (01:06 +0000)
committerJoao Eduardo Luis <joao.luis@inktank.com>
Sat, 12 Jan 2013 01:09:01 +0000 (01:09 +0000)
Try to share the map with a randomly picked OSD; if the picked monitor is
not 'up', then try to find the nearest 'up' OSD in the map by doing a
backward and a forward linear search on the map -- this would be O(n) in
the worst case scenario, as we only do a single iteration starting on the
picked position, incrementing and decrementing two different iterators
until we find an appropriate OSD or we exhaust the map.

Fixes: #3629
Backport: bobtail

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
Reviewed-by: Sage Weil <sage@inktank.com>
src/mon/OSDMonitor.cc
src/mon/Session.h

index ad17d1aa2a4e018f04617d77bd789bc58aad478a..c21a014a33d2ff27e8e8a1e22dfc4f8a8776afd3 100644 (file)
@@ -461,13 +461,21 @@ void OSDMonitor::encode_pending(bufferlist &bl)
 
 void OSDMonitor::share_map_with_random_osd()
 {
-  // tell any osd
-  MonSession *s = mon->session_map.get_random_osd_session();
-  if (s) {
-    dout(10) << "committed, telling random " << s->inst << " all about it" << dendl;
-    MOSDMap *m = build_incremental(osdmap.get_epoch() - 1, osdmap.get_epoch());  // whatev, they'll request more if they need it
-    mon->messenger->send_message(m, s->inst);
+  if (osdmap.get_num_up_osds() == 0) {
+    dout(10) << __func__ << " no up osds, don't share with anyone" << dendl;
+    return;
   }
+
+  MonSession *s = mon->session_map.get_random_osd_session(&osdmap);
+  if (!s) {
+    dout(10) << __func__ << " no up osd on our session map" << dendl;
+    return;
+  }
+
+  dout(10) << "committed, telling random " << s->inst << " all about it" << dendl;
+  // whatev, they'll request more if they need it
+  MOSDMap *m = build_incremental(osdmap.get_epoch() - 1, osdmap.get_epoch());
+  mon->messenger->send_message(m, s->inst);
 }
 
 
index edf5d66ef6fa7b7baf3ff02b099ca7d13f0c432f..bbdc3e50615cddc5c0c56dfe9b2d39ff1180ba8c 100644 (file)
@@ -19,6 +19,7 @@
 #include "msg/msg_types.h"
 
 #include "auth/AuthServiceHandler.h"
+#include "osd/OSDMap.h"
 
 #include "MonCaps.h"
 
@@ -118,19 +119,50 @@ struct MonSessionMap {
     s->get();  // caller gets a ref
     return s;
   }
-  
-  MonSession *get_random_osd_session() {
+
+  MonSession *get_random_osd_session(OSDMap *osdmap) {
     // ok, this isn't actually random, but close enough.
     if (by_osd.empty())
       return 0;
     int n = by_osd.rbegin()->first + 1;
     int r = rand() % n;
+
     multimap<int,MonSession*>::iterator p = by_osd.lower_bound(r);
     if (p == by_osd.end())
       p--;
-    return p->second;
-  }
 
+    if (!osdmap) {
+      return p->second;
+    }
+
+    MonSession *s = NULL;
+
+    multimap<int,MonSession*>::iterator b = p, f = p;
+    bool backward = true, forward = true;
+    while (backward || forward) {
+      if (backward) {
+        if (osdmap->is_up(b->first)) {
+          s = b->second;
+          break;
+        }
+        if (b != by_osd.begin())
+          --b;
+        else
+          backward = false;
+      }
+
+      forward = (f != by_osd.end());
+      if (forward) {
+        if (osdmap->is_up(f->first)) {
+          s = f->second;
+          break;
+        }
+        ++f;
+      }
+    }
+
+    return s;
+  }
 
   void add_update_sub(MonSession *s, const string& what, version_t start, bool onetime, bool incremental_onetime) {
     Subscription *sub = 0;