]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: support schedule scrub between some time defined by users
authorXinze Chi <xmdxcxz@gmail.com>
Fri, 16 Jan 2015 08:30:55 +0000 (08:30 +0000)
committerXinze Chi <xmdxcxz@gmail.com>
Fri, 16 Jan 2015 08:30:55 +0000 (08:30 +0000)
Signed-off-by: Xinze Chi <xmdxcxz@gmail.com>
src/common/config_opts.h
src/osd/OSD.cc
src/osd/OSD.h

index 08739c417205ed546478ce9183a321b229da59ed..970c345fd2092fc86a34af88127a78cf6fce32df 100644 (file)
@@ -564,6 +564,8 @@ OPTION(osd_max_push_cost, OPT_U64, 8<<20)  // max size of push message
 OPTION(osd_max_push_objects, OPT_U64, 10)  // max objects in single push op
 OPTION(osd_recovery_forget_lost_objects, OPT_BOOL, false)   // off for now
 OPTION(osd_max_scrubs, OPT_INT, 1)
+OPTION(osd_scrub_begin_hour, OPT_INT, 0)
+OPTION(osd_scrub_end_hour, OPT_INT, 24)
 OPTION(osd_scrub_load_threshold, OPT_FLOAT, 0.5)
 OPTION(osd_scrub_min_interval, OPT_FLOAT, 60*60*24)    // if load is low
 OPTION(osd_scrub_max_interval, OPT_FLOAT, 7*60*60*24)  // regardless of load
index bc56c7c7f75309336ca2dd4992f984d99abdd95d..84dd4c5e2a0b5bbc71b14901394e6272a20a5eb8 100644 (file)
@@ -5846,8 +5846,38 @@ bool OSD::scrub_random_backoff()
   return false;
 }
 
+bool OSD::scrub_time_permit(utime_t now)
+{
+  struct tm bdt; 
+  time_t tt = now.sec();
+  localtime_r(&tt, &bdt);
+  bool time_permit = false;
+  if (cct->_conf->osd_scrub_begin_hour < cct->_conf->osd_scrub_end_hour) {
+    if (bdt.tm_hour >= cct->_conf->osd_scrub_begin_hour && bdt.tm_hour < cct->_conf->osd_scrub_end_hour) {
+      time_permit = true;
+    }    
+  } else {
+    if (bdt.tm_hour >= cct->_conf->osd_scrub_begin_hour || bdt.tm_hour < cct->_conf->osd_scrub_end_hour) {
+      time_permit = true;
+    }    
+  }
+  if (!time_permit) {
+    dout(20) << "scrub_should_schedule should run between " << cct->_conf->osd_scrub_begin_hour
+            << " - " << cct->_conf->osd_scrub_end_hour
+            << " now " << bdt.tm_hour << " = no" << dendl;
+  } else {
+    dout(20) << "scrub_should_schedule should run between " << cct->_conf->osd_scrub_begin_hour
+            << " - " << cct->_conf->osd_scrub_end_hour
+            << " now " << bdt.tm_hour << " = yes" << dendl;
+  }
+  return time_permit;
+}
+
 bool OSD::scrub_should_schedule()
 {
+  if (!scrub_time_permit(ceph_clock_now(cct))) {
+    return false;
+  }
   double loadavgs[1];
   if (getloadavg(loadavgs, 1) != 1) {
     dout(10) << "scrub_should_schedule couldn't read loadavgs\n" << dendl;
index 5638f39b6a917b8ff36046698d0127a6a1c71391..f0ab31025ff6383b7e1cf76c83fc8420ca1521e8 100644 (file)
@@ -2088,6 +2088,7 @@ protected:
   void sched_scrub();
   bool scrub_random_backoff();
   bool scrub_should_schedule();
+  bool scrub_time_permit(utime_t now);
 
   xlist<PG*> scrub_queue;