From a477de90947f945cd597c0b03e7cc78005406fec Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 4 May 2003 11:29:17 +0000 Subject: [PATCH] Add heartbeat FD -> Dir git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@486 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/getmsg.c | 6 ++++-- bacula/src/filed/backup.c | 31 ++++++++++++++++++------------- bacula/src/stored/askdir.c | 10 +++++----- bacula/src/version.h | 6 +++--- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/bacula/src/dird/getmsg.c b/bacula/src/dird/getmsg.c index 8383a7ab5b..b53fad0346 100644 --- a/bacula/src/dird/getmsg.c +++ b/bacula/src/dird/getmsg.c @@ -95,15 +95,17 @@ int32_t bget_msg(BSOCK *bs, int rtn) bnet_fsend(bs, OK_msg); /* send response */ break; case BNET_HEARTBEAT: + /* Dmsg0(000, "Got heartbeat.\n"); */ + break; case BNET_HB_RESPONSE: break; case BNET_STATUS: - /* *****FIXME***** Implement */ + /* *****FIXME***** Implement more completely */ bnet_fsend(bs, "Status OK\n"); bnet_sig(bs, BNET_EOD); break; default: - Emsg1(M_WARNING, 0, _("bget_msg: unknown signal %d\n"), bs->msglen); + Emsg1(M_WARNING, 0, _("bget_msg: unknown bnet signal %d\n"), bs->msglen); return n; } continue; diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index 49f47a708b..81a54507ab 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -32,13 +32,21 @@ static int save_file(FF_PKT *ff_pkt, void *pkt); +#define HB_TIME (20*60) +/* + * Listen on the SD socket for heartbeat signals. + * Send heartbeats to the Director every HB_TIME + * seconds. + */ static void *heartbeat_thread(void *arg) { int32_t n; JCR *jcr = (JCR *)arg; BSOCK *sd, *dir; + time_t last_heartbeat = time(NULL); + time_t now; - jcr->heartbeat_id = pthread_self(); + pthread_detach(pthread_self()); /* Get our own local copy */ sd = dup_bsock(jcr->store_bsock); @@ -52,12 +60,13 @@ static void *heartbeat_thread(void *arg) */ for ( ; !is_bnet_stop(sd); ) { n = bnet_wait_data_intr(sd, 60); - if (n != 1) { - continue; - } - n = bnet_recv(sd); - if (n == BNET_SIGNAL && sd->msglen == BNET_HEARTBEAT) { + now = time(NULL); + if (now-last_heartbeat >= HB_TIME) { bnet_sig(dir, BNET_HEARTBEAT); + last_heartbeat = now; + } + if (n == 1) { /* input waiting */ + bnet_recv(sd); /* read it -- probably heartbeat */ } } bnet_close(sd); @@ -69,27 +78,23 @@ static void *heartbeat_thread(void *arg) /* Startup the heartbeat thread -- see above */ static void start_heartbeat_monitor(JCR *jcr) { - pthread_t hbtid; jcr->duped_sd = NULL; - pthread_create(&hbtid, NULL, heartbeat_thread, (void *)jcr); + pthread_create(&jcr->heartbeat_id, NULL, heartbeat_thread, (void *)jcr); } /* Terminate the heartbeat thread */ static void stop_heartbeat_monitor(JCR *jcr) { - pthread_t hbtid = jcr->heartbeat_id; - while (jcr->duped_sd == NULL) { - bmicrosleep(0, 500); /* avoid race */ + bmicrosleep(0, 50); /* avoid race */ } jcr->duped_sd->timed_out = 1; /* set timed_out to terminate read */ jcr->duped_sd->terminated = 1; /* set to terminate read */ while (jcr->duped_sd) { - pthread_kill(hbtid, TIMEOUT_SIGNAL); /* make heartbeat thread go away */ + pthread_kill(jcr->heartbeat_id, TIMEOUT_SIGNAL); /* make heartbeat thread go away */ bmicrosleep(0, 20); } - pthread_join(hbtid, NULL); /* wait for him to clean up */ } /* diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index 2283834f92..de681521b3 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -52,7 +52,7 @@ static char OK_media[] = "1000 OK VolName=%127s VolJobs=%u VolFiles=%u\ static char OK_update[] = "1000 OK UpdateMedia\n"; /* Forward referenced functions */ -static int device_wait(JCR *jcr, DEVICE *dev, int wait_sec); +static int wait_for_sysop(JCR *jcr, DEVICE *dev, int wait_sec); /* * Send current JobStatus to Director @@ -302,7 +302,7 @@ Please use the \"label\" command to create a new Volume for:\n\ jcr->JobStatus = jstat; dir_send_job_status(jcr); - stat = device_wait(jcr, dev, wait_sec); + stat = wait_for_sysop(jcr, dev, wait_sec); if (stat == ETIMEDOUT) { wait_sec *= 2; /* double wait time */ @@ -394,7 +394,7 @@ int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev) jcr->JobStatus = JS_WaitMount; dir_send_job_status(jcr); - stat = device_wait(jcr, dev, wait_sec); /* wait on device */ + stat = wait_for_sysop(jcr, dev, wait_sec); /* wait on device */ if (stat == ETIMEDOUT) { wait_sec *= 2; /* double wait time */ @@ -434,9 +434,9 @@ int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev) return 1; } -#define HB_TIME 20*60 /* send a heatbeat once every 20 minutes while waiting */ +#define HB_TIME (20*60) /* send a heatbeat once every 20 minutes while waiting */ -static int device_wait(JCR *jcr, DEVICE *dev, int wait_sec) +static int wait_for_sysop(JCR *jcr, DEVICE *dev, int wait_sec) { struct timeval tv; struct timezone tz; diff --git a/bacula/src/version.h b/bacula/src/version.h index dd31484f94..abc03071fb 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ -#define VERSION "1.30a" +#define VERSION "1.31" #define VSTRING "1" -#define BDATE "03 May 2003" -#define LSMDATE "03May03" +#define BDATE "04 May 2003" +#define LSMDATE "04May03" /* Debug flags */ #define DEBUG 1 -- 2.39.5