]> git.sur5r.net Git - bacula/bacula/commitdiff
Add heartbeat FD -> Dir
authorKern Sibbald <kern@sibbald.com>
Sun, 4 May 2003 11:29:17 +0000 (11:29 +0000)
committerKern Sibbald <kern@sibbald.com>
Sun, 4 May 2003 11:29:17 +0000 (11:29 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@486 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/getmsg.c
bacula/src/filed/backup.c
bacula/src/stored/askdir.c
bacula/src/version.h

index 8383a7ab5b7e139731db5c908383a07b1ae3c7af..b53fad0346fac613cfef512cfe641d925d19d521 100644 (file)
@@ -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;
index 49f47a708b32b179ee7bfd8a60efbbccd4d37bac..81a54507ab7861912b622aba4bf63302640c1af2 100644 (file)
 
 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 */
 }
 
 /* 
index 2283834f929479eb821645dc6a63f708e0a841da..de681521b3bf44d8136dc7736244a8ef13f20df3 100644 (file)
@@ -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;
index dd31484f940765212a71da3d1a4ffc463b5c9baa..abc03071fb59bd29b971a60a39b6345b839b9547 100644 (file)
@@ -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