*
*/
/*
- Copyright (C) 2000-2003 Kern Sibbald and John Walker
+ Copyright (C) 2003-2004 Kern Sibbald and John Walker
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
/* Forward referenced functions */
-static void *jobq_server(void *arg);
+extern "C" void *jobq_server(void *arg);
+extern "C" void *sched_wait(void *arg);
+
static int start_server(jobq_t *jq);
/*
* most jobs are put into the job queue only when their
* scheduled time arives.
*/
-static void *sched_wait(void *arg)
+extern "C"
+void *sched_wait(void *arg)
{
JCR *jcr = ((wait_pkt *)arg)->jcr;
jobq_t *jq = ((wait_pkt *)arg)->jq;
return NULL;
}
-
/*
* Add a job to the queue
* jq is a queue that was created with jobq_init
* When all the resources are acquired for the job,
* it will call the user's engine.
*/
-static void *jobq_server(void *arg)
+extern "C"
+void *jobq_server(void *arg)
{
struct timespec timeout;
jobq_t *jq = (jobq_t *)arg;
jq->num_workers--;
return NULL;
}
+
/* Call user's routine here */
Dmsg1(300, "Calling user engine for jobid=%d\n", jcr->JobId);
jq->engine(je->jcr);
+
Dmsg1(300, "Back from user engine jobid=%d.\n", jcr->JobId);
if ((stat = pthread_mutex_lock(&jq->mutex)) != 0) {
- Jmsg1(NULL, M_ERROR, 0, "pthread_mutex_unlock: ERR=%s\n", strerror(stat));
+ Jmsg1(NULL, M_ERROR, 0, "pthread_mutex_lock: ERR=%s\n", strerror(stat));
jq->num_workers--;
free(je); /* release job entry */
return NULL;
*/
if (jcr->acquired_resource_locks) {
jcr->store->NumConcurrentJobs--;
+ if (jcr->JobType == JT_RESTORE) {
+ jcr->store->MaxConcurrentJobs = jcr->saveMaxConcurrentJobs;
+ }
jcr->client->NumConcurrentJobs--;
jcr->job->NumConcurrentJobs--;
}
jcr->JobStatus != JS_Canceled &&
jcr->job->RescheduleTimes > 0 &&
jcr->reschedule_count < jcr->job->RescheduleTimes) {
+ char dt[50];
/*
* Reschedule this job by cleaning it up, but
jcr->sched_time = time(NULL) + jcr->job->RescheduleInterval;
Dmsg2(300, "Rescheduled Job %s to re-run in %d seconds.\n", jcr->Job,
(int)jcr->job->RescheduleInterval);
+ bstrftime(dt, sizeof(dt), time(NULL));
+ Jmsg(jcr, M_INFO, 0, _("Rescheduled Job %s at %s to re-run in %d seconds.\n"),
+ jcr->Job, dt, (int)jcr->job->RescheduleInterval);
jcr->JobStatus = JS_Created; /* force new status */
dird_free_jcr(jcr); /* partial cleanup old stuff */
if (jcr->JobBytes == 0) {
jobq_item_t *re = (jobq_item_t *)jq->running_jobs->first();
if (re) {
Priority = re->jcr->JobPriority;
- Dmsg2(300, "JobId %d is running. Set pri=%d\n", re->jcr->JobId, Priority);
+ Dmsg2(300, "JobId %d is running. Look for pri=%d\n", re->jcr->JobId, Priority);
} else {
Priority = je->jcr->JobPriority;
- Dmsg1(300, "No job running. Set Job pri=%d\n", Priority);
+ Dmsg1(300, "No job running. Look for Job pri=%d\n", Priority);
}
/*
* Walk down the list of waiting jobs and attempt
set_jcr_job_status(jcr, JS_WaitPriority);
break;
}
- if (jcr->store->NumConcurrentJobs < jcr->store->MaxConcurrentJobs) {
+ if (jcr->JobType == JT_RESTORE) {
+ /* Let only one Restore job run at a time regardless of MaxConcurrentJobs */
+ if (jcr->store->NumConcurrentJobs == 0) {
+ jcr->store->NumConcurrentJobs++;
+ jcr->saveMaxConcurrentJobs = jcr->store->MaxConcurrentJobs;
+ jcr->store->MaxConcurrentJobs = 1;
+ } else {
+ set_jcr_job_status(jcr, JS_WaitStoreRes);
+ je = jn;
+ continue;
+ }
+ } else if (jcr->store->NumConcurrentJobs < jcr->store->MaxConcurrentJobs) {
jcr->store->NumConcurrentJobs++;
} else {
set_jcr_job_status(jcr, JS_WaitStoreRes);
je = jn;
continue;
}
+
if (jcr->client->NumConcurrentJobs < jcr->client->MaxConcurrentJobs) {
jcr->client->NumConcurrentJobs++;
} else {
+ /* Back out previous locks */
jcr->store->NumConcurrentJobs--;
+ if (jcr->JobType == JT_RESTORE) {
+ jcr->store->MaxConcurrentJobs = jcr->saveMaxConcurrentJobs;
+ }
set_jcr_job_status(jcr, JS_WaitClientRes);
je = jn;
continue;
if (jcr->job->NumConcurrentJobs < jcr->job->MaxConcurrentJobs) {
jcr->job->NumConcurrentJobs++;
} else {
+ /* Back out previous locks */
jcr->store->NumConcurrentJobs--;
+ if (jcr->JobType == JT_RESTORE) {
+ jcr->store->MaxConcurrentJobs = jcr->saveMaxConcurrentJobs;
+ }
jcr->client->NumConcurrentJobs--;
set_jcr_job_status(jcr, JS_WaitJobRes);
je = jn;
jq->num_workers--;
break;
}
+
work = !jq->ready_jobs->empty() || !jq->waiting_jobs->empty();
if (work) {
/*
* important, release the lock so that a job that has
* terminated can give us the resource.
*/
- pthread_mutex_unlock(&jq->mutex);
+ if ((stat = pthread_mutex_unlock(&jq->mutex)) != 0) {
+ Jmsg1(NULL, M_ERROR, 0, "pthread_mutex_unlock: ERR=%s\n", strerror(stat));
+ jq->num_workers--;
+ return NULL;
+ }
bmicrosleep(2, 0); /* pause for 2 seconds */
- pthread_mutex_unlock(&jq->mutex);
+ if ((stat = pthread_mutex_lock(&jq->mutex)) != 0) {
+ Jmsg1(NULL, M_ERROR, 0, "pthread_mutex_lock: ERR=%s\n", strerror(stat));
+ jq->num_workers--;
+ return NULL;
+ }
/* Recompute work as something may have changed in last 2 secs */
work = !jq->ready_jobs->empty() || !jq->waiting_jobs->empty();
}
} /* end of big for loop */
Dmsg0(200, "unlock mutex\n");
- pthread_mutex_unlock(&jq->mutex);
+ if ((stat = pthread_mutex_unlock(&jq->mutex)) != 0) {
+ Jmsg1(NULL, M_ERROR, 0, "pthread_mutex_unlock: ERR=%s\n", strerror(stat));
+ }
Dmsg0(300, "End jobq_server\n");
return NULL;
}