]> git.sur5r.net Git - bacula/bacula/commitdiff
- Fix scheduler to handle time skew (eg daylight savings).
authorKern Sibbald <kern@sibbald.com>
Thu, 20 Apr 2006 14:33:06 +0000 (14:33 +0000)
committerKern Sibbald <kern@sibbald.com>
Thu, 20 Apr 2006 14:33:06 +0000 (14:33 +0000)
- Fix scheduler to use lock_jobs() to avoid most problems
  with reload. Window is now milliseconds.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2949 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/kes-1.39
bacula/src/dird/scheduler.c
bacula/src/lib/jcr.c
bacula/src/version.h

index b379c2c425e5f40ed42dfcb7ed6cf9cfe0e377ce..20a508ed19e5a3fafb1e1c4531b10e2ccb09dbf6 100644 (file)
@@ -2,6 +2,10 @@
                         Kern Sibbald
 
 General:
+20Apr06
+- Fix scheduler to handle time skew (eg daylight savings).
+- Fix scheduler to use lock_jobs() to avoid most problems
+  with reload. Window is now milliseconds.
 19Apr06
 - Apply patch from Christopher Hull
   - Allow multiple connections to database with different
index 8dc27249f3c3ef2d4c8887d46147db15ac91a8e9..8d3266ca2b06521acd1c4855336a92c4ea6631b3 100644 (file)
@@ -50,7 +50,7 @@ struct job_item {
 static dlist *jobs_to_run;               /* list of jobs to be run */
 
 /* Time interval in secs to sleep if nothing to be run */
-static int const NEXT_CHECK_SECS = 60;
+static int const next_check_secs = 60;
 
 /* Forward referenced subroutines */
 static void find_runs();
@@ -85,7 +85,7 @@ JCR *wait_for_next_job(char *one_shot_job_to_run)
    JCR *jcr;
    JOB *job;
    RUN *run;
-   time_t now;
+   time_t now, prev;
    static bool first = true;
    job_item *next_job = NULL;
 
@@ -114,7 +114,7 @@ again:
       if (!jobs_to_run->empty()) {
          break;
       }
-      bmicrosleep(NEXT_CHECK_SECS, 0); /* recheck once per minute */
+      bmicrosleep(next_check_secs, 0); /* recheck once per minute */
    }
 
 #ifdef  list_chain
@@ -139,7 +139,9 @@ again:
    /* Now wait for the time to run the job */
    for (;;) {
       time_t twait;
-      if (schedules_invalidated) { /** discard scheduled queue and rebuild with new schedule objects. **/
+      /** discard scheduled queue and rebuild with new schedule objects. **/
+      lock_jobs();
+      if (schedules_invalidated) { 
           dump_job(next_job, "Invalidated job");
           free(next_job);
           while (!jobs_to_run->empty()) {
@@ -151,13 +153,23 @@ again:
           schedules_invalidated = false;
           goto again;
       }
-      now = time(NULL);
+      unlock_jobs();
+      prev = now = time(NULL);
       twait = next_job->runtime - now;
       if (twait <= 0) {               /* time to run it */
          break;
       }
-      bmicrosleep((NEXT_CHECK_SECS<twait)?NEXT_CHECK_SECS:twait, 0); /* recheck at least once per minute */      
+      /* Recheck at least once per minute */
+      bmicrosleep((next_check_secs < twait)?next_check_secs:twait, 0);
+      /* Attempt to handle clock shift from/to daylight savings time
+       * we allow a skew of 10 seconds before invalidating everything.
+       */
+      now = time(NULL);
+      if (now < prev+10 || now > (prev+next_check_secs+10)) {
+         schedules_invalidated = true;
+      }
    }
+   jcr = new_jcr(sizeof(JCR), dird_free_jcr);
    run = next_job->run;               /* pick up needed values */
    job = next_job->job;
    if (job->enabled) {
@@ -165,11 +177,11 @@ again:
    }
    free(next_job);
    if (!job->enabled) {
+      free_jcr(jcr);
       goto again;                     /* ignore this job */
    }
    run->last_run = now;               /* mark as run now */
 
-   jcr = new_jcr(sizeof(JCR), dird_free_jcr);
    ASSERT(job);
    set_jcr_defaults(jcr, job);
    if (run->level) {
index d49ee3c0ee7feb14ca52019bab6839efad84cf25..551a84176d8e17826377da9b7678ea05515b681f 100755 (executable)
@@ -231,7 +231,6 @@ JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
    jcr->daemon_free_jcr = daemon_free_jcr;    /* plug daemon free routine */
    jcr->init_mutex();
    jcr->inc_use_count();   
-   set_jcr_job_status(jcr, JS_Created);       /* ready to run */
    jcr->VolumeName = get_pool_memory(PM_FNAME);
    jcr->VolumeName[0] = 0;
    jcr->errmsg = get_pool_memory(PM_MESSAGE);
@@ -241,7 +240,7 @@ JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
    jcr->JobId = 0;
    jcr->JobType = JT_SYSTEM;          /* internal job until defined */
    jcr->JobLevel = L_NONE;
-   jcr->JobStatus = JS_Created;
+   set_jcr_job_status(jcr, JS_Created);       /* ready to run */
 
    sigtimer.sa_flags = 0;
    sigtimer.sa_handler = timeout_handler;
index 9e934c13660cac8bdb19b2b1d813c510455139d5..b3097e87e599e7bba7df206158f615846487636d 100644 (file)
@@ -4,8 +4,8 @@
 
 #undef  VERSION
 #define VERSION "1.39.9"
-#define BDATE   "19 April 2006"
-#define LSMDATE "19Apr06"
+#define BDATE   "20 April 2006"
+#define LSMDATE "20Apr06"
 
 /* Debug flags */
 #undef  DEBUG