]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: move scrub schedule random backoff to seperate helper
authorSage Weil <sage@inktank.com>
Mon, 14 Jan 2013 04:25:39 +0000 (20:25 -0800)
committerSage Weil <sage@inktank.com>
Wed, 23 Jan 2013 14:20:03 +0000 (06:20 -0800)
Separate this from the load check, which will soon vary dependon on the
PG.

Signed-off-by: Sage Weil <sage@inktank.com>
(cherry picked from commit a148120776d0930b265411332a60e93abfbf0423)

src/osd/OSD.cc
src/osd/OSD.h

index 4a49b3d803ddac323c877955c0dd4486942e45dc..14be6665a784d80c7e328b268be1affe0db57a19 100644 (file)
@@ -2226,7 +2226,9 @@ void OSD::tick()
     // periodically kick recovery work queue
     recovery_tp.wake();
 
-    sched_scrub();
+    if (!scrub_random_backoff()) {
+      sched_scrub();
+    }
 
     map_lock.get_read();
 
@@ -3520,16 +3522,19 @@ void OSD::handle_scrub(MOSDScrub *m)
   m->put();
 }
 
-bool OSDService::scrub_should_schedule()
+bool OSD::scrub_random_backoff()
 {
-  double loadavgs[1];
-
-  // TODOSAM: is_active should be conveyed to OSDService
-  /*
-  if (!is_active())
-    return false;
-  */
+  bool coin_flip = (rand() % 3) == whoami % 3;
+  if (!coin_flip) {
+    dout(20) << "scrub_random_backoff lost coin flip, randomly backing off" << dendl;
+    return true;
+  }
+  return false;
+}
 
+bool OSD::scrub_should_schedule()
+{
+  double loadavgs[1];
   if (getloadavg(loadavgs, 1) != 1) {
     dout(10) << "scrub_should_schedule couldn't read loadavgs\n" << dendl;
     return false;
@@ -3542,15 +3547,6 @@ bool OSDService::scrub_should_schedule()
     return false;
   }
 
-  bool coin_flip = (rand() % 3) == whoami % 3;
-  if (!coin_flip) {
-    dout(20) << "scrub_should_schedule loadavg " << loadavgs[0]
-            << " < max " << g_conf->osd_scrub_load_threshold
-            << " = no, randomly backing off"
-            << dendl;
-    return false;
-  }
-  
   dout(20) << "scrub_should_schedule loadavg " << loadavgs[0]
           << " < max " << g_conf->osd_scrub_load_threshold
           << " = yes" << dendl;
@@ -3561,7 +3557,7 @@ void OSD::sched_scrub()
 {
   assert(osd_lock.is_locked());
 
-  bool should = service.scrub_should_schedule();
+  bool should = scrub_should_schedule();
 
   dout(20) << "sched_scrub should=" << (int)should << dendl;
 
@@ -3575,7 +3571,7 @@ void OSD::sched_scrub()
     utime_t t = pos.first;
     pg_t pgid = pos.second;
 
-    if (t > min) {
+    if (t > max) {
       dout(10) << " " << pgid << " at " << t
               << " > " << max << " (" << g_conf->osd_scrub_max_interval << " seconds ago)" << dendl;
       break;
index 88b24dfa1fba4d9eef9217c520b0233175aba77c..a47b5495e9804ebe61108520d12c1684372c1f6c 100644 (file)
@@ -248,8 +248,6 @@ public:
   int scrubs_active;
   set< pair<utime_t,pg_t> > last_scrub_pg;
 
-  bool scrub_should_schedule();
-
   void reg_last_pg_scrub(pg_t pgid, utime_t t) {
     Mutex::Locker l(sched_scrub_lock);
     last_scrub_pg.insert(pair<utime_t,pg_t>(t, pgid));
@@ -1176,8 +1174,10 @@ protected:
 
   // -- scrubbing --
   void sched_scrub();
-  xlist<PG*> scrub_queue;
+  bool scrub_random_backoff();
+  bool scrub_should_schedule();
 
+  xlist<PG*> scrub_queue;
 
   struct ScrubWQ : public ThreadPool::WorkQueue<PG> {
     OSD *osd;