From bc87d238830e350bcb18799697d6e7648261abb8 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Mon, 10 Nov 2008 10:27:47 +0000 Subject: [PATCH] ebl Fix maxwaittime to fit documentation, this time is now counted from the job start and group all wait periods. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8026 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/job.c | 11 +++++- bacula/src/jcr.h | 3 +- bacula/src/lib/jcr.c | 90 ++++++++++++++++++++++++++----------------- bacula/technotes-2.5 | 2 + 4 files changed, 67 insertions(+), 39 deletions(-) diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 2fb91119be..8e3f66b160 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -545,13 +545,20 @@ static bool job_check_maxwaittime(JCR *jcr) { bool cancel = false; JOB *job = jcr->job; + utime_t current=0; if (!job_waiting(jcr)) { return false; } - Dmsg3(200, "check maxwaittime %u - %u >= %u\n", watchdog_time, jcr->wait_time, job->MaxWaitTime); + + if (jcr->wait_time) { + current = watchdog_time - jcr->wait_time; + } + + Dmsg3(200, "check maxwaittime %u >= %u\n", + current + jcr->wait_time_sum, job->MaxWaitTime); if (job->MaxWaitTime != 0 && - (watchdog_time - jcr->wait_time) >= job->MaxWaitTime) { + (current + jcr->wait_time_sum) >= job->MaxWaitTime) { cancel = true; } diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index e100a26a6a..386335eba0 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -216,7 +216,8 @@ public: time_t start_time; /* when job actually started */ time_t run_time; /* used for computing speed */ time_t end_time; /* job end time */ - time_t wait_time; /* when job have started to wait */ + time_t wait_time_sum; /* cumulative wait time since job start */ + time_t wait_time; /* timestamp when job have started to wait */ POOLMEM *client_name; /* client name */ POOLMEM *RestoreBootstrap; /* Bootstrap file to restore */ POOLMEM *stime; /* start time for incremental/differential */ diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index 2bad20da40..48d366ed49 100644 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -738,41 +738,29 @@ static int get_status_priority(int JobStatus) return priority; } -void set_jcr_job_status(JCR *jcr, int JobStatus) + +static void update_wait_time(JCR *jcr, int newJobStatus) { - bool set_waittime = false; - int oldJobStatus = jcr->JobStatus; - int priority, old_priority; - - priority = get_status_priority(JobStatus); - old_priority = get_status_priority(oldJobStatus); - - Dmsg2(800, "set_jcr_job_status(%s, %c)\n", jcr->Job, JobStatus); - /* if wait state is new, we keep current time for watchdog MaxWaitTime */ - switch (JobStatus) { - case JS_WaitFD: - case JS_WaitSD: - case JS_WaitMedia: - case JS_WaitMount: - case JS_WaitStoreRes: - case JS_WaitJobRes: - case JS_WaitClientRes: - case JS_WaitMaxJobs: - case JS_WaitPriority: - set_waittime = true; - default: - break; - } - - /* - * For a set of errors, ... keep the current status - * so it isn't lost. For all others, set it. - */ - Dmsg3(300, "jid=%u OnEntry JobStatus=%c set=%c\n", (uint32_t)jcr->JobId, - jcr->JobStatus, JobStatus); - if (priority >= old_priority) { - jcr->JobStatus = JobStatus; /* replace with new priority */ + bool enter_in_waittime; + int oldJobStatus = jcr->JobStatus; + + switch (newJobStatus) { + case JS_WaitFD: + case JS_WaitSD: + case JS_WaitMedia: + case JS_WaitMount: + case JS_WaitStoreRes: + case JS_WaitJobRes: + case JS_WaitClientRes: + case JS_WaitMaxJobs: + case JS_WaitPriority: + enter_in_waittime = true; + break; + default: + enter_in_waittime = false; /* not a Wait situation */ + break; } + /* * If we were previously waiting and are not any more * we want to update the wait_time variable, which is @@ -788,13 +776,43 @@ void set_jcr_job_status(JCR *jcr, int JobStatus) case JS_WaitClientRes: case JS_WaitMaxJobs: case JS_WaitPriority: - set_waittime = false; /* keep old time */ + if (!enter_in_waittime) { /* we get out the wait time */ + jcr->wait_time_sum += (time(NULL) - jcr->wait_time); + jcr->wait_time = 0; + } + break; + + /* if wait state is new, we keep current time for watchdog MaxWaitTime */ default: - if (set_waittime) { - Dmsg0(800, "Setting wait_time\n"); + if (enter_in_waittime) { jcr->wait_time = time(NULL); } + break; + } +} + +void set_jcr_job_status(JCR *jcr, int JobStatus) +{ + int priority, old_priority; + int oldJobStatus = jcr->JobStatus; + priority = get_status_priority(JobStatus); + old_priority = get_status_priority(oldJobStatus); + + Dmsg2(800, "set_jcr_job_status(%s, %c)\n", jcr->Job, JobStatus); + + /* Update wait_time depending on newJobStatus and oldJobStatus */ + update_wait_time(jcr, JobStatus); + + /* + * For a set of errors, ... keep the current status + * so it isn't lost. For all others, set it. + */ + Dmsg3(300, "jid=%u OnEntry JobStatus=%c set=%c\n", (uint32_t)jcr->JobId, + jcr->JobStatus, JobStatus); + if (priority >= old_priority) { + jcr->JobStatus = JobStatus; /* replace with new priority */ } + if (oldJobStatus != jcr->JobStatus) { Dmsg3(200, "jid=%u leave set_old_job_status=%c new_set=%c\n", (uint32_t)jcr->JobId, oldJobStatus, JobStatus); diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index e33c92717d..d8af59b567 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -11,6 +11,8 @@ mixed priorities General: 10Nov08 +ebl Fix maxwaittime to fit documentation, this time is now counted + from the job start and group all wait periods. ebl Add tips for postgresql to improve performance when having multiple batch insert at the same time. 09Nov08 -- 2.39.5