src/dird/job.c
bool allow_duplicate_job(JCR *jcr)
{
   JOB *job = jcr->job;
   JCR *djcr;                /* possible duplicate job */

   /* Is AllowDuplicateJobs is set or is duplicate checking
    *  disabled for this job? */
   if (job->AllowDuplicateJobs || jcr->IgnoreDuplicateJobChecking) {
      return true;
   }
   Dmsg0(800, "Enter allow_duplicate_job\n");
   /*
    * After this point, we do not want to allow any duplicate
    * job to run.
    */

   foreach_jcr(djcr) {
      if (jcr == djcr || djcr->is_internal_job() || !djcr->job) {
         continue;                   /* do not cancel this job or consoles */
      }
      /* Does Job has the IgnoreDuplicateJobChecking flag set,
       * if so do not check it against other jobs */
      if (djcr->IgnoreDuplicateJobChecking) {
         continue;
      }
      if ((strcmp(job->name(), djcr->job->name()) == 0) &&
          djcr->getJobType() == jcr->getJobType()) /* A duplicate is about the same name and the same type */
      {
         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) {
               continue;               /* not really a duplicate */
            }
         }
         if (job->CancelLowerLevelDuplicates &&
             djcr->getJobType() == 'B' && jcr->getJobType() == 'B') {
            switch (jcr->getJobLevel()) {
            case L_FULL:
            case L_VIRTUAL_FULL:
               if (djcr->getJobLevel() == L_DIFFERENTIAL ||
                   djcr->getJobLevel() == L_INCREMENTAL) {
                  cancel_dup = true;
               }
               break;
            case L_DIFFERENTIAL:
               if (djcr->getJobLevel() == L_INCREMENTAL) {
                  cancel_dup = true;
               }
               if (djcr->getJobLevel() == L_FULL) {
                  cancel_me = true;
               }
               break;
            case L_INCREMENTAL:
               if (djcr->getJobLevel() == L_FULL ||
                   djcr->getJobLevel() == L_DIFFERENTIAL) {
                  cancel_me = true;
               }
            }
            /*
             * cancel_dup will be done below
             */
            if (cancel_me) {
              /* Zap current job */
              jcr->setJobStatus(JS_Canceled);
              Jmsg(jcr, M_FATAL, 0, _("JobId %d already running. Duplicate job not allowed.\n"),
                 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 */
         if (job->CancelQueuedDuplicates) {
             switch (djcr->JobStatus) {
             case JS_Created:
             case JS_WaitJobRes:
             case JS_WaitClientRes:
             case JS_WaitStoreRes:
             case JS_WaitPriority:
             case JS_WaitMaxJobs:
             case JS_WaitStartTime:
             case JS_WaitDevice:
                cancel_dup = true;  /* cancel queued duplicate */
                break;
             default:
                break;
             }
         }
         if (cancel_dup || job->CancelRunningDuplicates) {
            /* 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, 60);
            bmicrosleep(0, 500000);
            djcr->setJobStatus(JS_Canceled);
            cancel_job(ua, djcr, 60);
            free_ua_context(ua);
            Dmsg2(800, "Cancel dup %p JobId=%d\n", djcr, djcr->JobId);
         } else {
             /* Zap current job */
            jcr->setJobStatus(JS_Canceled);
            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);
         }
         Dmsg4(800, "curJobId=%d use_cnt=%d dupJobId=%d use_cnt=%d\n",
               jcr->JobId, jcr->use_count(), djcr->JobId, djcr->use_count());
         break;                 /* did our work, get out of foreach loop */
      }
   }
   endeach_jcr(djcr);

   return true;
}
/*
 * Check for duplicate jobs.
 *  Returns: true  if current job should continue
 *           false if current job should terminate
 */
Check for duplicate jobs.
Returns: true  if current job should continue
false if current job should terminate
Check for duplicate jobs . Returns : true if current job should continue false if current job should terminate
bool allow_duplicate_job(JCR *jcr)
{
   JOB *job = jcr->job;
   JCR *djcr;                
   if (job->AllowDuplicateJobs || jcr->IgnoreDuplicateJobChecking) {
      return true;
   }
   Dmsg0(800, "Enter allow_duplicate_job\n");
   foreach_jcr(djcr) {
      if (jcr == djcr || djcr->is_internal_job() || !djcr->job) {
         continue;                   
      }
      if (djcr->IgnoreDuplicateJobChecking) {
         continue;
      }
      if ((strcmp(job->name(), djcr->job->name()) == 0) &&
          djcr->getJobType() == jcr->getJobType()) 
      {
         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) {
               continue;               
            }
         }
         if (job->CancelLowerLevelDuplicates &&
             djcr->getJobType() == 'B' && jcr->getJobType() == 'B') {
            switch (jcr->getJobLevel()) {
            case L_FULL:
            case L_VIRTUAL_FULL:
               if (djcr->getJobLevel() == L_DIFFERENTIAL ||
                   djcr->getJobLevel() == L_INCREMENTAL) {
                  cancel_dup = true;
               }
               break;
            case L_DIFFERENTIAL:
               if (djcr->getJobLevel() == L_INCREMENTAL) {
                  cancel_dup = true;
               }
               if (djcr->getJobLevel() == L_FULL) {
                  cancel_me = true;
               }
               break;
            case L_INCREMENTAL:
               if (djcr->getJobLevel() == L_FULL ||
                   djcr->getJobLevel() == L_DIFFERENTIAL) {
                  cancel_me = true;
               }
            }
            if (cancel_me) {
              jcr->setJobStatus(JS_Canceled);
              Jmsg(jcr, M_FATAL, 0, _("JobId %d already running. Duplicate job not allowed.\n"),
                 djcr->JobId);
              break;     
            }
         }
         if (job->CancelQueuedDuplicates) {
             switch (djcr->JobStatus) {
             case JS_Created:
             case JS_WaitJobRes:
             case JS_WaitClientRes:
             case JS_WaitStoreRes:
             case JS_WaitPriority:
             case JS_WaitMaxJobs:
             case JS_WaitStartTime:
             case JS_WaitDevice:
                cancel_dup = true;  
                break;
             default:
                break;
             }
         }
         if (cancel_dup || job->CancelRunningDuplicates) {
            UAContext *ua = new_ua_context(jcr);
            Jmsg(jcr, M_INFO, 0, _("Cancelling duplicate JobId=%d.\n"), djcr->JobId);
            cancel_job(ua, djcr, 60);
            bmicrosleep(0, 500000);
            djcr->setJobStatus(JS_Canceled);
            cancel_job(ua, djcr, 60);
            free_ua_context(ua);
            Dmsg2(800, "Cancel dup %p JobId=%d\n", djcr, djcr->JobId);
         } else {
            jcr->setJobStatus(JS_Canceled);
            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);
         }
         Dmsg4(800, "curJobId=%d use_cnt=%d dupJobId=%d use_cnt=%d\n",
               jcr->JobId, jcr->use_count(), djcr->JobId, djcr->use_count());
         break;                 
      }
   }
   endeach_jcr(djcr);
   return true;
}
bool allow_duplicate_job ( JCR * jcr ) { JOB * job = jcr -> job ; JCR * djcr ; if ( job -> AllowDuplicateJobs || jcr -> IgnoreDuplicateJobChecking ) { return true ; } Dmsg0 ( 800 , " \n " ) ; foreach_jcr ( djcr ) { if ( jcr == djcr || djcr -> is_internal_job ( ) || ! djcr -> job ) { continue ; } if ( djcr -> IgnoreDuplicateJobChecking ) { continue ; } if ( ( strcmp ( job -> name ( ) , djcr -> job -> name ( ) ) == 0 ) && djcr -> getJobType ( ) == jcr -> getJobType ( ) ) { 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 ) { continue ; } } if ( job -> CancelLowerLevelDuplicates && djcr -> getJobType ( ) == ' ' && jcr -> getJobType ( ) == ' ' ) { switch ( jcr -> getJobLevel ( ) ) { case L_FULL : case L_VIRTUAL_FULL : if ( djcr -> getJobLevel ( ) == L_DIFFERENTIAL || djcr -> getJobLevel ( ) == L_INCREMENTAL ) { cancel_dup = true ; } break ; case L_DIFFERENTIAL : if ( djcr -> getJobLevel ( ) == L_INCREMENTAL ) { cancel_dup = true ; } if ( djcr -> getJobLevel ( ) == L_FULL ) { cancel_me = true ; } break ; case L_INCREMENTAL : if ( djcr -> getJobLevel ( ) == L_FULL || djcr -> getJobLevel ( ) == L_DIFFERENTIAL ) { cancel_me = true ; } } if ( cancel_me ) { jcr -> setJobStatus ( JS_Canceled ) ; Jmsg ( jcr , M_FATAL , 0 , _ ( " \n " ) , djcr -> JobId ) ; break ; } } if ( job -> CancelQueuedDuplicates ) { switch ( djcr -> JobStatus ) { case JS_Created : case JS_WaitJobRes : case JS_WaitClientRes : case JS_WaitStoreRes : case JS_WaitPriority : case JS_WaitMaxJobs : case JS_WaitStartTime : case JS_WaitDevice : cancel_dup = true ; break ; default : break ; } } if ( cancel_dup || job -> CancelRunningDuplicates ) { UAContext * ua = new_ua_context ( jcr ) ; Jmsg ( jcr , M_INFO , 0 , _ ( " \n " ) , djcr -> JobId ) ; cancel_job ( ua , djcr , 60 ) ; bmicrosleep ( 0 , 500000 ) ; djcr -> setJobStatus ( JS_Canceled ) ; cancel_job ( ua , djcr , 60 ) ; free_ua_context ( ua ) ; Dmsg2 ( 800 , " \n " , djcr , djcr -> JobId ) ; } else { jcr -> setJobStatus ( JS_Canceled ) ; Jmsg ( jcr , M_FATAL , 0 , _ ( " \n " ) , djcr -> JobId ) ; Dmsg2 ( 800 , " \n " , jcr , jcr -> JobId ) ; } Dmsg4 ( 800 , " \n " , jcr -> JobId , jcr -> use_count ( ) , djcr -> JobId , djcr -> use_count ( ) ) ; break ; } } endeach_jcr ( djcr ) ; return true ; }
Check for duplicate jobs.
Check for duplicate jobs .
/* possible duplicate job */ /* Is AllowDuplicateJobs is set or is duplicate checking
    *  disabled for this job? */ /*
    * After this point, we do not want to allow any duplicate
    * job to run.
    */ /* do not cancel this job or consoles */ /* Does Job has the IgnoreDuplicateJobChecking flag set,
       * if so do not check it against other jobs */ /* A duplicate is about the same name and the same type */ /* not really a duplicate */ /*
             * cancel_dup will be done below
             */ /* Zap current job */ /* 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 queued duplicate */ /* Zap the duplicated job djcr */ /* Zap current job */ /* did our work, get out of foreach loop */