]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: use steady clock in prepare_to_stop() 26457/head
authorMohamad Gebai <mgebai@suse.com>
Fri, 15 Feb 2019 19:22:49 +0000 (14:22 -0500)
committerMohamad Gebai <mgebai@suse.com>
Thu, 28 Feb 2019 16:28:33 +0000 (11:28 -0500)
Signed-off-by: Mohamad Gebai <mgebai@suse.com>
src/common/condition_variable_debug.h
src/osd/OSD.cc
src/osd/OSD.h

index 3241502ff812d47e79cedf5027e517200c7495ca..d12e7956fff8d98ad6a03053ec838f9e035061b4 100644 (file)
@@ -50,6 +50,21 @@ public:
     timespec ts = ceph::real_clock::to_timespec(when);
     return _wait_until(lock.mutex(), &ts);
   }
+  template<class Rep, class Period, class Pred>
+  bool wait_for(
+    std::unique_lock<mutex_debug>& lock,
+    const std::chrono::duration<Rep, Period>& awhile,
+    Pred pred) {
+    ceph::real_time when{ceph::real_clock::now()};
+    when += awhile;
+    timespec ts = ceph::real_clock::to_timespec(when);
+    while (!pred()) {
+      if ( _wait_until(lock.mutex(), &ts) == std::cv_status::timeout) {
+        return pred();
+      }
+    }
+    return true;
+  }
   void notify_one();
   void notify_all(bool sloppy = false);
 private:
index 8550064567ec6dd8fa82dd646c90f5c68ab4b113..0cc2a974d6867e1b62b7120dd4af2afd01607a73 100644 (file)
@@ -271,8 +271,7 @@ OSDService::OSDService(OSD *osd) :
   cur_state(NONE),
   cur_ratio(0), physical_ratio(0),
   epoch_lock("OSDService::epoch_lock"),
-  boot_epoch(0), up_epoch(0), bind_epoch(0),
-  is_stopping_lock("OSDService::is_stopping_lock")
+  boot_epoch(0), up_epoch(0), bind_epoch(0)
 #ifdef PG_DEBUG_REFS
   , pgid_lock("OSDService::pgid_lock")
 #endif
@@ -1420,7 +1419,7 @@ void OSDService::set_epochs(const epoch_t *_boot_epoch, const epoch_t *_up_epoch
 
 bool OSDService::prepare_to_stop()
 {
-  std::lock_guard l(is_stopping_lock);
+  std::unique_lock l(is_stopping_lock);
   if (get_state() != NOT_STOPPING)
     return false;
 
@@ -1436,13 +1435,9 @@ bool OSDService::prepare_to_stop()
        osdmap->get_epoch(),
        true  // request ack
        ));
-    utime_t now = ceph_clock_now();
-    utime_t timeout;
-    timeout.set_from_double(now + cct->_conf->osd_mon_shutdown_timeout);
-    while ((ceph_clock_now() < timeout) &&
-       (get_state() != STOPPING)) {
-      is_stopping_cond.WaitUntil(is_stopping_lock, timeout);
-    }
+    const auto timeout = ceph::make_timespan(cct->_conf->osd_mon_shutdown_timeout);
+    is_stopping_cond.wait_for(l, timeout,
+      [this] { return get_state() == STOPPING; });
   }
   dout(0) << __func__ << " starting shutdown" << dendl;
   set_state(STOPPING);
@@ -1451,11 +1446,11 @@ bool OSDService::prepare_to_stop()
 
 void OSDService::got_stop_ack()
 {
-  std::lock_guard l(is_stopping_lock);
+  std::scoped_lock l(is_stopping_lock);
   if (get_state() == PREPARING_TO_STOP) {
     dout(0) << __func__ << " starting shutdown" << dendl;
     set_state(STOPPING);
-    is_stopping_cond.Signal();
+    is_stopping_cond.notify_all();
   } else {
     dout(10) << __func__ << " ignoring msg" << dendl;
   }
index bf054d7011250dc000528fa61b6f969752be670e..9aae481a15153ab6840b6345901d9e8c0b67ab2a 100644 (file)
@@ -1008,8 +1008,8 @@ public:
   void request_osdmap_update(epoch_t e);
 
   // -- stopping --
-  Mutex is_stopping_lock;
-  Cond is_stopping_cond;
+  ceph::mutex is_stopping_lock = ceph::make_mutex("OSDService::is_stopping_lock");
+  ceph::condition_variable is_stopping_cond;
   enum {
     NOT_STOPPING,
     PREPARING_TO_STOP,