]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: implement Beacon::send_and_wait
authorJohn Spray <john.spray@redhat.com>
Wed, 18 Mar 2015 17:42:54 +0000 (17:42 +0000)
committerJohn Spray <john.spray@redhat.com>
Mon, 23 Mar 2015 10:55:08 +0000 (10:55 +0000)
For callers that want to send a beacon, and then
wait up to some timeout for a response
from the mon.  Specifically, shutdown handlers.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mds/Beacon.cc
src/mds/Beacon.h

index 5d6084391b7c4422d26be388d7b774765fda1240..e56a6362083e338f900e4dbb61565a690e2cb89a 100644 (file)
@@ -32,7 +32,8 @@
 
 
 Beacon::Beacon(CephContext *cct_, MonClient *monc_, std::string name_) :
-  Dispatcher(cct_), lock("Beacon"), monc(monc_), timer(g_ceph_context, lock), name(name_)
+  Dispatcher(cct_), lock("Beacon"), monc(monc_), timer(g_ceph_context, lock),
+  name(name_), awaiting_seq(-1)
 {
   want_state = MDSMap::STATE_NULL;
   last_seq = 0;
@@ -131,6 +132,11 @@ void Beacon::handle_mds_beacon(MMDSBeacon *m)
     while (!seq_stamp.empty() &&
           seq_stamp.begin()->first <= seq)
       seq_stamp.erase(seq_stamp.begin());
+
+    // Wake a waiter up if present
+    if (awaiting_seq == seq) {
+      waiting_cond.Signal();
+    }
   } else {
     dout(10) << "handle_mds_beacon " << ceph_mds_state_name(m->get_state())
             << " seq " << m->get_seq() << " dne" << dendl;
@@ -145,6 +151,25 @@ void Beacon::send()
 }
 
 
+void Beacon::send_and_wait(const double duration)
+{
+  Mutex::Locker l(lock);
+  _send();
+  awaiting_seq = last_seq;
+  dout(20) << __func__ << ": awaiting " << awaiting_seq
+           << " for up to " << duration << "s" << dendl;
+
+  utime_t timeout;
+  timeout.set_from_double(ceph_clock_now(cct) + duration);
+  while ((!seq_stamp.empty() && seq_stamp.begin()->first <= awaiting_seq)
+         && ceph_clock_now(cct) < timeout) {
+    waiting_cond.WaitUntil(lock, timeout);
+  }
+
+  awaiting_seq = -1;
+}
+
+
 /**
  * Call periodically, or when you have updated the desired state
  */
index d229ae292fac36e963127452c08c7050b30121b0..ba2cb46c77f5d2ce5ba97c8bf22bf21fec8e4453 100644 (file)
@@ -78,6 +78,9 @@ class Beacon : public Dispatcher
   void _notify_mdsmap(MDSMap const *mdsmap);
   void _send();
 
+  version_t awaiting_seq;
+  Cond waiting_cond;
+
 public:
   Beacon(CephContext *cct_, MonClient *monc_, std::string name);
   ~Beacon();
@@ -99,6 +102,13 @@ public:
   void handle_mds_beacon(MMDSBeacon *m);
   void send();
 
+  /**
+   * Send a beacon, and block until the ack is received from the mon
+   * or `duration` seconds pass, whichever happens sooner.  Useful
+   * for emitting a last message on shutdown.
+   */
+  void send_and_wait(const double duration);
+
   bool is_laggy();
   utime_t get_laggy_until() const;
 };