From 7ebf8f564b27ca8448a9a7365ba73b130ae69c21 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 18 Apr 2004 09:56:51 +0000 Subject: [PATCH] Jobq.c race bug fixed + minor updates git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1233 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/ReleaseNotes | 9 ++++- bacula/kernstodo | 2 + bacula/src/Makefile.in | 1 + bacula/src/console/console.c | 2 +- bacula/src/count-lines | 3 +- bacula/src/dird/backup.c | 2 +- bacula/src/dird/dird.c | 2 +- bacula/src/dird/jobq.c | 64 +++++++++++++++++++------------ bacula/src/dird/restore.c | 6 ++- bacula/src/filed/filed.c | 2 +- bacula/src/stored/stored.c | 2 +- bacula/src/version.h | 4 +- bacula/src/wx-console/Makefile.in | 2 +- 13 files changed, 65 insertions(+), 36 deletions(-) diff --git a/bacula/ReleaseNotes b/bacula/ReleaseNotes index c31ddf8c7f..e3df3e1771 100644 --- a/bacula/ReleaseNotes +++ b/bacula/ReleaseNotes @@ -1,12 +1,19 @@ Release Notes for Bacula 1.34.1 - Bacula code: Total files = 306 Total lines = 91,155 (*.h *.c *.in) + Bacula code: Total files = 343 Total lines = 98,503 (*.h *.c *.in) Changes for 1.34.1: - Autochanger users, please note you must add %d to the end of the changer command line in your Device resource in your bacula-sd.conf file. +- Fixed a major race condition in the job scheduler when multiple + simultaneous jobs is enabled. This occurred only when on job had + blocked another because of resource usage. +- Changed the backup report to indicate "Backup OK -- with warnings + if any warning messages were generated. +- Change output of restore report to indicate: + "Restore OK -- warning file count mismatch" - Make backup report say "Backup OK with warnings" if either FD or SD report any non-fatal errors. - Modify bscan to print some elementary statistics (#Jobs, #Files, ...) diff --git a/bacula/kernstodo b/bacula/kernstodo index 78d649fbc7..81bafc8813 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -42,6 +42,8 @@ For 1.33 Testing/Documentation: - Add multiple-media-types.txt - look at mxt-changer.html +- Why is Files Expected zero on restore from tape? + For version 1.35: - Finish SIGHUP work. - Check that all change in wait status in the SD are diff --git a/bacula/src/Makefile.in b/bacula/src/Makefile.in index c13964aea4..b04ca9c447 100644 --- a/bacula/src/Makefile.in +++ b/bacula/src/Makefile.in @@ -42,6 +42,7 @@ clean: @$(RMF) core core.* a.out *.o *.bak *~ *.intpro *.extpro 1 2 3 @$(RMF) AUTHORS ChangeLog Makefile.am NEWS README acconfig.h autogen.sh @$(RMF) configure.in stamp.h + @$(RMF) -r po (cd gnome-console; $(MAKE) clean) (cd gnome2-console; $(MAKE) clean) diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 93802e8556..f88f80ce8a 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -294,7 +294,7 @@ int main(int argc, char *argv[]) init_stack_dump(); my_name_is(argc, argv, "bconsole"); - textdomain("bacula-console"); + textdomain("bacula"); init_msg(NULL, NULL); working_directory = "/tmp"; args = get_pool_memory(PM_FNAME); diff --git a/bacula/src/count-lines b/bacula/src/count-lines index 0afd52dd4e..cd70669b77 100755 --- a/bacula/src/count-lines +++ b/bacula/src/count-lines @@ -1,7 +1,8 @@ #!/bin/sh rm -f 1 touch 1 -for i in . console gnome-console cats dird filed filed/win32 win32 findlib lib stored tools; do +for i in . console gnome-console cats dird filed filed/win32 \ + win32 win32/compat findlib lib wx-console stored tools; do ls -1 $i/*.c $i/*.cpp $i/*.h $i/*.in 2>/dev/null >>1 done cat 1 | $HOME/bin/lines diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 16f75993a0..1475413f38 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -396,7 +396,7 @@ static void backup_cleanup(JCR *jcr, int TermCode, char *since, FILESET_DBR *fsr switch (jcr->JobStatus) { case JS_Terminated: if (jcr->Errors || jcr->SDErrors) { - term_msg = _("Backup OK with warnings"); + term_msg = _("Backup OK -- with warnings"); } else { term_msg = _("Backup OK"); } diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 71f4bc538d..4274683567 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -105,7 +105,7 @@ int main (int argc, char *argv[]) init_stack_dump(); my_name_is(argc, argv, "bacula-dir"); - textdomain("bacula-dir"); + textdomain("bacula"); init_msg(NULL, NULL); /* initialize message handler */ init_reload(); daemon_start_time = time(NULL); diff --git a/bacula/src/dird/jobq.c b/bacula/src/dird/jobq.c index ebedc4a1f2..a372e720de 100755 --- a/bacula/src/dird/jobq.c +++ b/bacula/src/dird/jobq.c @@ -358,7 +358,7 @@ static void *jobq_server(void *arg) jobq_t *jq = (jobq_t *)arg; jobq_item_t *je; /* job entry in queue */ int stat; - bool timedout; + bool timedout = false; bool work = true; Dmsg0(300, "Start jobq_server\n"); @@ -373,30 +373,31 @@ static void *jobq_server(void *arg) struct timezone tz; Dmsg0(300, "Top of for loop\n"); - timedout = false; - gettimeofday(&tv, &tz); - timeout.tv_nsec = 0; - timeout.tv_sec = tv.tv_sec + 4; - - while (!work && !jq->quit) { - /* - * Wait 4 seconds, then if no more work, exit - */ - Dmsg0(300, "pthread_cond_timedwait()\n"); - stat = pthread_cond_timedwait(&jq->work, &jq->mutex, &timeout); - if (stat == ETIMEDOUT) { - Dmsg0(300, "timedwait timedout.\n"); - timedout = true; + if (!work && !jq->quit) { + gettimeofday(&tv, &tz); + timeout.tv_nsec = 0; + timeout.tv_sec = tv.tv_sec + 4; + + while (!jq->quit) { + /* + * Wait 4 seconds, then if no more work, exit + */ + Dmsg0(300, "pthread_cond_timedwait()\n"); + stat = pthread_cond_timedwait(&jq->work, &jq->mutex, &timeout); + if (stat == ETIMEDOUT) { + Dmsg0(300, "timedwait timedout.\n"); + timedout = true; + break; + } else if (stat != 0) { + /* This shouldn't happen */ + Dmsg0(300, "This shouldn't happen\n"); + jq->num_workers--; + pthread_mutex_unlock(&jq->mutex); + return NULL; + } break; - } else if (stat != 0) { - /* This shouldn't happen */ - Dmsg0(300, "This shouldn't happen\n"); - jq->num_workers--; - pthread_mutex_unlock(&jq->mutex); - return NULL; - } - break; - } + } + } /* * If anything is in the ready queue, run it */ @@ -588,7 +589,20 @@ static void *jobq_server(void *arg) jq->num_workers--; break; } - work = !jq->ready_jobs->empty() || !jq->waiting_jobs->empty(); + work = !jq->ready_jobs->empty() || !jq->waiting_jobs->empty(); + if (work) { + /* + * If a job is waiting on a Resource, don't consume all + * the CPU time looping looking for work, and even more + * important, release the lock so that a job that has + * terminated can give us the resource. + */ + pthread_mutex_unlock(&jq->mutex); + bmicrosleep(2, 0); /* pause for 2 seconds */ + pthread_mutex_unlock(&jq->mutex); + /* Recompute work as something may have changed in last 2 secs */ + work = !jq->ready_jobs->empty() || !jq->waiting_jobs->empty(); + } Dmsg1(300, "Loop again. work=%d\n", work); } /* end of big for loop */ diff --git a/bacula/src/dird/restore.c b/bacula/src/dird/restore.c index 5dc2398f12..082877a878 100644 --- a/bacula/src/dird/restore.c +++ b/bacula/src/dird/restore.c @@ -279,7 +279,11 @@ static void restore_cleanup(JCR *jcr, int TermCode) msg_type = M_INFO; /* by default INFO message */ switch (TermCode) { case JS_Terminated: - term_msg = _("Restore OK"); + if (jcr->ExpectedFiles > jcr->jr.JobFiles) { + term_msg = _("Restore OK -- warning file count mismatch"); + } else { + term_msg = _("Restore OK"); + } break; case JS_FatalError: case JS_ErrorTerminated: diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index 5ebf0c37ba..adf7c3364f 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -97,7 +97,7 @@ int main (int argc, char *argv[]) init_stack_dump(); my_name_is(argc, argv, "bacula-fd"); - textdomain("bacula-fd"); + textdomain("bacula"); init_msg(NULL, NULL); daemon_start_time = time(NULL); diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index 746f3831ae..f910f85e2f 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -94,7 +94,7 @@ int main (int argc, char *argv[]) init_stack_dump(); my_name_is(argc, argv, "bacula-sd"); - textdomain("bacula-sd"); + textdomain("bacula"); init_msg(NULL, NULL); daemon_start_time = time(NULL); diff --git a/bacula/src/version.h b/bacula/src/version.h index b5e80cb33c..aff083a2bb 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -2,8 +2,8 @@ #undef VERSION #define VERSION "1.35.0" #define VSTRING "1" -#define BDATE "16 Apr 2004" -#define LSMDATE "16Apr04" +#define BDATE "18 Apr 2004" +#define LSMDATE "18Apr04" /* Debug flags */ #undef DEBUG diff --git a/bacula/src/wx-console/Makefile.in b/bacula/src/wx-console/Makefile.in index 48f814af84..b3e186d4c5 100644 --- a/bacula/src/wx-console/Makefile.in +++ b/bacula/src/wx-console/Makefile.in @@ -66,7 +66,7 @@ wx-console_private.res: wx-console_private.rc windres.exe -i wx-console_private.rc -I rc -o wx-console_private.res -O coff clean: - @$(RMF) $(OBJ) wx-console $(WIN32RES) + @$(RMF) $(CONSOBJS) wx-console $(WIN32RES) distclean: clean $(RMF) Makefile -- 2.39.2