]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix bug #1751 Make duplicate checking somewhat less naiv.
authorMarco van Wieringen <mvw@planets.elm.net>
Wed, 3 Aug 2011 12:44:50 +0000 (14:44 +0200)
committerMarco van Wieringen <mvw@planets.elm.net>
Wed, 3 Aug 2011 15:40:40 +0000 (17:40 +0200)
We were almost there with excluding duplicate checks for Copy and
Migration jobs. We only used the wrong variable. Now allocated a
new one and made the naming somewhat more comprehensible. And extra
check is added that jobs inserted by Migration and Copy and which
have the flag set are also not compared against normal jobs in the
normal canceling process so you should be able to run a copy job
now and start the normal backup job without it being canceled as
reported by alltech in the bug report.

bacula/src/dird/dird_conf.h
bacula/src/dird/job.c
bacula/src/dird/migrate.c
bacula/src/dird/ua_run.c
bacula/src/jcr.h

index 73a17fb8744b99a26cb880b9e9076daf02617bce..272516f18ef54b6f96972acc687a16176e94f499 100644 (file)
@@ -439,6 +439,7 @@ public:
    bool CancelQueuedDuplicates;       /* Cancel queued jobs */
    bool CancelRunningDuplicates;      /* Cancel Running jobs */
    bool PurgeMigrateJob;              /* Purges source job on completion */
+   bool IgnoreDuplicateJobChecking;   /* Ignore Duplicate Job Checking */
 
    alist *base;                       /* Base jobs */   
 
index 476ee755fef4f1fb72c9625af9f5c76601028915..65fc720f61b2e3d0418b6b0b17667872d69ad204 100644 (file)
@@ -696,11 +696,19 @@ bool allow_duplicate_job(JCR *jcr)
 {
    JOB *job = jcr->job;
    JCR *djcr;                /* possible duplicate job */
+   bool cancel_dup = false;
+   bool cancel_me = false;
 
-   if (jcr->no_check_duplicates || job->AllowDuplicateJobs) {
+   /*
+    * See if AllowDuplicateJobs is set or
+    * if duplicate checking is disabled for this job.
+    */
+   if (job->AllowDuplicateJobs || job->IgnoreDuplicateJobChecking) {
       return true;
    }
+
    Dmsg0(800, "Enter allow_duplicate_job\n");
+
    /*
     * After this point, we do not want to allow any duplicate
     * job to run.
@@ -710,9 +718,16 @@ bool allow_duplicate_job(JCR *jcr)
       if (jcr == djcr || djcr->JobId == 0) {
          continue;                   /* do not cancel this job or consoles */
       }
+
+      /*
+       * See if this Job has the IgnoreDuplicateJobChecking flag set, ignore it for any
+       * checking against other jobs.
+       */
+      if (djcr->job && djcr->job->IgnoreDuplicateJobChecking) {
+         continue;
+      }
+
       if (strcmp(job->name(), djcr->job->name()) == 0) {
-         bool cancel_dup = false;
-         bool cancel_me = false; 
          if (job->DuplicateJobProximity > 0) {
             utime_t now = (utime_t)time(NULL);
             if ((now - djcr->start_time) > job->DuplicateJobProximity) {
@@ -751,9 +766,12 @@ bool allow_duplicate_job(JCR *jcr)
                  djcr->JobId);
               break;     /* get out of foreach_jcr */
             }
-         }   
-         /* Cancel one of the two jobs (me or dup) */
-         /* If CancelQueuedDuplicates is set do so only if job is queued */
+         }
+
+         /*
+          * Cancel one of the two jobs (me or dup)
+          * If CancelQueuedDuplicates is set do so only if job is queued.
+          */
          if (job->CancelQueuedDuplicates) {
              switch (djcr->JobStatus) {
              case JS_Created:
@@ -769,8 +787,11 @@ bool allow_duplicate_job(JCR *jcr)
                 break;
              }
          }
+
          if (cancel_dup || job->CancelRunningDuplicates) {
-            /* Zap the duplicated job djcr */
+            /*
+             * Zap the duplicated job djcr
+             */
             UAContext *ua = new_ua_context(jcr);
             Jmsg(jcr, M_INFO, 0, _("Cancelling duplicate JobId=%d.\n"), djcr->JobId);
             cancel_job(ua, djcr);
@@ -779,7 +800,9 @@ bool allow_duplicate_job(JCR *jcr)
             free_ua_context(ua);
             Dmsg2(800, "Cancel dup %p JobId=%d\n", djcr, djcr->JobId);
          } else {
-            /* Zap current job */
+            /*
+             * Zap current job
+             */
             Jmsg(jcr, M_FATAL, 0, _("JobId %d already running. Duplicate job not allowed.\n"),
                djcr->JobId);
             Dmsg2(800, "Cancel me %p JobId=%d\n", jcr, jcr->JobId);
index f39fd1b15ac6f492814f1eb0b2fad25b15eafc29..43abf952588cd664818842b28d4b1fd677de5674 100644 (file)
@@ -213,8 +213,10 @@ bool do_migration_init(JCR *jcr)
    /* Don't let WatchDog checks Max*Time value on this Job */
    mig_jcr->no_maxtime = true;
 
-   /* Don't check for duplicates on migration and copy jobs */
-   mig_jcr->no_check_duplicates = true;
+   /*
+    * Don't check for duplicates on migration and copy jobs
+    */
+   mig_jcr->job->IgnoreDuplicateJobChecking = true;
 
    Dmsg4(dbglevel, "mig_jcr: Name=%s JobId=%d Type=%c Level=%c\n",
       mig_jcr->jr.Name, (int)mig_jcr->jr.JobId, 
@@ -915,7 +917,7 @@ static void start_migration_job(JCR *jcr)
    UAContext *ua = new_ua_context(jcr);
    char ed1[50];
    ua->batch = true;
-   Mmsg(ua->cmd, "run job=\"%s\" jobid=%s allowduplicates=yes", jcr->job->name(),
+   Mmsg(ua->cmd, "run job=\"%s\" jobid=%s ignoreduplicatecheck=yes", jcr->job->name(),
         edit_uint64(jcr->MigrateJobId, ed1));
    Dmsg2(dbglevel, "=============== %s cmd=%s\n", jcr->get_OperationName(), ua->cmd);
    parse_ua_args(ua);                 /* parse command */
index 856de446f7a3e3462de04159a5c769ed4749b356..af374c724d688d0b2e22cc7182bd27ccc42f729d 100644 (file)
@@ -61,8 +61,8 @@ public:
    bool mod;
    int spool_data;
    bool spool_data_set;
-   int allow_duplicates;
-   bool allow_duplicates_set;
+   int ignoreduplicatecheck;
+   bool ignoreduplicatecheck_set;
 
    /* Methods */
    run_ctx() { memset(this, 0, sizeof(run_ctx)); 
@@ -1186,7 +1186,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
       "pluginoptions",                /* 25 */
       "spooldata",                    /* 26 */
       "comment",                      /* 27 */
-      "allowduplicates",              /* 28 */
+      "ignoreduplicatecheck",         /* 28 */
       NULL
    };
 
@@ -1202,7 +1202,7 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
    rc.verify_job_name = NULL;
    rc.previous_job_name = NULL;
    rc.spool_data_set = false;
-   rc.allow_duplicates_set = false;
+   rc.ignoreduplicatecheck = false;
    rc.comment = NULL;
 
    for (i=1; i<ua->argc; i++) {
@@ -1421,16 +1421,16 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
                rc.comment = ua->argv[i];
                kw_ok = true;
                break;
-            case 28: /* allowduplicates */
-               if (rc.allow_duplicates_set) {
-                  ua->send_msg(_("AllowDuplicates flag specified twice.\n"));
+            case 28: /* ignoreduplicatecheck */
+               if (rc.ignoreduplicatecheck_set) {
+                  ua->send_msg(_("IgnoreDuplicateCheck flag specified twice.\n"));
                   return false;
                }
-               if (is_yesno(ua->argv[i], &rc.allow_duplicates)) {
-                  rc.allow_duplicates_set = true;
+               if (is_yesno(ua->argv[i], &rc.ignoreduplicatecheck)) {
+                  rc.ignoreduplicatecheck_set = true;
                   kw_ok = true;
                } else {
-                  ua->send_msg(_("Invalid allowduplicates flag.\n"));
+                  ua->send_msg(_("Invalid ignoreduplicatecheck flag.\n"));
                }
                break;
             default:
@@ -1522,10 +1522,10 @@ static bool scan_command_line_arguments(UAContext *ua, run_ctx &rc)
    }
    Dmsg1(900, "Spooling data: %s\n", (rc.job->spool_data ? "Yes" : "No"));
 
-   if (rc.allow_duplicates_set) {
-      rc.job->AllowDuplicateJobs = rc.allow_duplicates;
+   if (rc.ignoreduplicatecheck) {
+      rc.job->IgnoreDuplicateJobChecking = rc.ignoreduplicatecheck;
    }
-   Dmsg1(900, "Allow Duplicate Jobs: %s\n", (rc.job->AllowDuplicateJobs ? "Yes" : "No"));
+   Dmsg1(900, "Ignore Duplicate Job Check: %s\n", (rc.job->IgnoreDuplicateJobChecking ? "Yes" : "No"));
 
    if (rc.store_name) {
       rc.store->store = GetStoreResWithName(rc.store_name);
index d520bbad271726e661bba9ef878ae77e8b958435..3ee29e44c0c9ef0d93470ded3813628e72324b8c 100644 (file)
@@ -356,7 +356,6 @@ public:
    bool Encrypt;                      /* Encryption used by FD */
    bool stats_enabled;                /* Keep all job records in a table for long term statistics */
    bool no_maxtime;                   /* Don't check Max*Time for this JCR */
-   bool no_check_duplicates;          /* Don't check duplicates for this JCR */
    bool keep_sd_auth_key;             /* Clear or not the SD auth key after connection*/
    bool use_accurate_chksum;          /* Use or not checksum option in accurate code */
    bool run_pool_override;