]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: do one-time subscriptions, too
authorSage Weil <sage@newdream.net>
Mon, 31 Aug 2009 22:27:13 +0000 (15:27 -0700)
committerSage Weil <sage@newdream.net>
Mon, 31 Aug 2009 22:27:13 +0000 (15:27 -0700)
src/client/Client.cc
src/messages/MMonSubscribe.h
src/mon/MDSMonitor.cc
src/mon/MonClient.h
src/mon/Monitor.cc
src/mon/OSDMonitor.cc
src/mon/SubscriptionMap.h
src/vstart.sh

index bdf15642be0c5dd99c8a2e477598a86b814e6781..e792ef6ba15376c2b6719eec676e72c9fa73262a 100644 (file)
@@ -1202,7 +1202,7 @@ void Client::handle_mds_map(MMDSMap* m)
   delete oldmap;
   delete m;
 
-  monclient->update_sub("mdsmap", mdsmap->get_epoch());
+  monclient->sub_got("mdsmap", mdsmap->get_epoch());
 }
 
 void Client::send_reconnect(int mds)
@@ -2554,7 +2554,8 @@ int Client::mount()
          << " and mdsmap " << mdsmap->get_epoch() 
          << dendl;
 
-  monclient->update_sub("mdsmap", mdsmap->get_epoch());
+  monclient->sub_want("mdsmap", mdsmap->get_epoch());
+  monclient->renew_subs();
 
   
   // hack: get+pin root inode.
index be9426b725192c7b6178b17a00990011ed97afff..05fca342ee7fde0e7035e0e73eec006d003c98c8 100644 (file)
 #include "msg/Message.h"
 
 struct MMonSubscribe : public Message {
-  map<nstring, version_t> what;
+  struct sub_rec {
+    version_t have;
+    bool onetime;    // just one version, or keep sending them?
+    
+    void encode(bufferlist& bl) const {
+      ::encode(have, bl);
+      ::encode(onetime, bl);
+    }
+    void decode(bufferlist::iterator& bl) {
+      ::decode(have, bl);
+      ::decode(onetime, bl);
+    }
+  };
+  WRITE_CLASS_ENCODER(sub_rec)
+
+  map<nstring, sub_rec> what;
   
   MMonSubscribe() : Message(CEPH_MSG_MON_SUBSCRIBE) {}
   
+  void sub_onetime(const char *w, version_t have) {
+    what[w].onetime = true;
+    what[w].have = have;
+  }
+  void sub_persistent(const char *w, version_t have) {
+    what[w].onetime = false;
+    what[w].have = have;
+  }
+
   const char *get_type_name() { return "mon_subscribe"; }
   void print(ostream& o) {
     o << "mon_subscribe(" << what << ")";
@@ -35,5 +59,11 @@ struct MMonSubscribe : public Message {
     ::encode(what, payload);
   }
 };
+WRITE_CLASS_ENCODER(MMonSubscribe::sub_rec)
+
+static inline ostream& operator<<(ostream& out, const MMonSubscribe::sub_rec& r)
+{
+  return out << r.have << (r.onetime ? "(onetime)":"(persistent)");
+}
 
 #endif
index d9b6a3cff898224bb0c860aeab20a7d35e55c065..0dc0b5f8a9778d34a9ef6f274f36e5374ce283e1 100644 (file)
@@ -563,7 +563,8 @@ void MDSMonitor::check_subs()
       send_full(p->first);
       p->second.last = mdsmap.get_epoch();
     }
-  }      
+  }
+  subs.trim_onetime();
 }
 
 
index a7a925f8dc5bd8aa9853b0ef92801cffb0b0d309..f2eb81e8531333329a820a1e264842c8b566b517 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "common/Timer.h"
 
+#include "messages/MMonSubscribe.h"
 
 class MonMap;
 class MMonMap;
@@ -67,16 +68,26 @@ private:
 
   // mon subscriptions
 private:
-  map<nstring,version_t> sub_have;  // my subs, and current versions
+  map<nstring,MMonSubscribe::sub_rec> sub_have;  // my subs, and current versions
   utime_t sub_renew_sent, sub_renew_after;
 
 public:
   void renew_subs();
-  void update_sub(nstring what, version_t have) {
-    bool had = sub_have.count(what);
-    sub_have[what] = have;
-    if (!had)
-      renew_subs();
+  void sub_want(nstring what, version_t have) {
+    sub_have[what].have = have;
+    sub_have[what].onetime = false;
+  }
+  void sub_want_onetime(nstring what, version_t have) {
+    sub_have[what].have = have;
+    sub_have[what].onetime = true;
+  }
+  void sub_got(nstring what, version_t have) {
+    if (sub_have.count(what)) {
+      if (sub_have[what].onetime)
+       sub_have.erase(what);
+      else
+       sub_have[what].have = have;
+    }
   }
   void handle_subscribe_ack(MMonSubscribeAck* m);
 
index 360fcc55328890f08eb0a4badb0b7d9dff331eba..20733acba8dbce655188d8477b0372eb431e1259 100644 (file)
@@ -499,13 +499,13 @@ void Monitor::handle_subscribe(MMonSubscribe *m)
   utime_t until = g_clock.now();
   until += g_conf.mon_subscribe_interval;
 
-  for (map<nstring,version_t>::iterator p = m->what.begin();
+  for (map<nstring,MMonSubscribe::sub_rec>::iterator p = m->what.begin();
        p != m->what.end();
        p++) {
     if (p->first == "osdmap")
-      osdmon()->subscribe(m->get_source_inst(), p->second, until);
+      osdmon()->subscribe(m->get_source_inst(), p->second.have, p->second.onetime ? utime_t() : until);
     else if (p->first == "mdsmap")
-      mdsmon()->subscribe(m->get_source_inst(), p->second, until);
+      mdsmon()->subscribe(m->get_source_inst(), p->second.have, p->second.onetime ? utime_t() : until);
     else
       dout(10) << " ignoring sub for '" << p->first << "'" << dendl;
   }
index da958b5e4a684b65cf85cec8be9943633e8bddc2..e728da894b3ab86a8c91c99af99b0ebff1574dc5 100644 (file)
@@ -856,7 +856,8 @@ void OSDMonitor::check_subs()
       send_latest(p->first, p->second.last);
       p->second.last = osdmap.get_epoch();
     }
-  }      
+  }
+  subs.trim_onetime();
 }
 
 
index fcf32240fe91106e2fa0105f57adda305902d9a6..1f4eec6ec58904fbe999ce499e6ad1f317d09964 100644 (file)
@@ -33,7 +33,16 @@ struct SubscriptionMap {
   void trim(utime_t now) {
     map<entity_inst_t, sub_info>::iterator p = subs.begin();
     while (p != subs.end())
-      if (p->second.until < now)
+      if (p->second.until != utime_t() &&
+         p->second.until < now)
+       subs.erase(p++);
+      else
+       p++;
+  }
+  void trim_onetime() {
+    map<entity_inst_t, sub_info>::iterator p = subs.begin();
+    while (p != subs.end())
+      if (p->second.until == utime_t())
        subs.erase(p++);
       else
        p++;
index f382c3d295e743853def4a1dd27b8c208e22dd9c..40c333e9a579a870397097591f26e27c922471b7 100755 (executable)
@@ -128,7 +128,7 @@ else
         lockdep = 1
        debug mon = 20
         debug paxos = 20
-        debug ms = 1'
+        debug ms = 20'
     COSDDEBUG='
         lockdep = 1
         debug ms = 1
@@ -137,7 +137,7 @@ else
         debug filestore = 10'
     CMDSDEBUG='
         lockdep = 1
-        debug ms = 1
+        debug ms = 20
         debug mds = 20
         mds log max segments = 2'
 fi