]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix minor logic error in recycling code
authorKern Sibbald <kern@sibbald.com>
Sat, 5 Jul 2003 13:03:54 +0000 (13:03 +0000)
committerKern Sibbald <kern@sibbald.com>
Sat, 5 Jul 2003 13:03:54 +0000 (13:03 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@618 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/catreq.c
bacula/src/dird/recycle.c
bacula/src/dird/ua_purge.c

index 2ffc82b5f71bd477037c533f700bbb4564a7907e..b2453e5cc40e589c3e4821f03465b8c608017df4 100644 (file)
@@ -89,69 +89,72 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
       /*
        * Find the Next Volume for Append
        */
-next_volume:
-      strcpy(mr.VolStatus, "Append");  /* want only appendable volumes */
-      ok = db_find_next_volume(jcr, jcr->db, index, &mr);  
-      Dmsg2(100, "catreq after find_next_vol ok=%d FW=%d\n", ok, mr.FirstWritten);
-      if (!ok) {
-        /* Well, try finding recycled tapes */
-        ok = find_recycled_volume(jcr, &mr);
-         Dmsg2(100, "find_recycled_volume1 %d FW=%d\n", ok, mr.FirstWritten);
+      for ( ;; ) {
+         strcpy(mr.VolStatus, "Append");  /* want only appendable volumes */
+        ok = db_find_next_volume(jcr, jcr->db, index, &mr);  
+         Dmsg2(100, "catreq after find_next_vol ok=%d FW=%d\n", ok, mr.FirstWritten);
         if (!ok) {
-           prune_volumes(jcr);  
-           ok = recycle_oldest_purged_volume(jcr, &mr);
-            Dmsg2(200, "find_recycled_volume2 %d FW=%d\n", ok, mr.FirstWritten);
+           /* Well, try finding recycled volumes */
+           ok = find_recycled_volume(jcr, &mr);
+            Dmsg2(100, "find_recycled_volume %d FW=%d\n", ok, mr.FirstWritten);
            if (!ok) {
-              /* See if we can create a new Volume */
-              ok = newVolume(jcr, &mr);
+              prune_volumes(jcr);  
+              ok = recycle_oldest_purged_volume(jcr, &mr);
+               Dmsg2(200, "find_recycled_volume2 %d FW=%d\n", ok, mr.FirstWritten);
+              if (!ok) {
+                 /* See if we can create a new Volume */
+                 ok = newVolume(jcr, &mr);
+              }
            }
-        }
 
-        if (!ok && jcr->pool->purge_oldest_volume) {
-            Dmsg1(200, "No next volume found. PurgeOldest=%d\n",
-               jcr->pool->purge_oldest_volume);
-           /* Find oldest volume to recycle */
-           ok = db_find_next_volume(jcr, jcr->db, -1, &mr);
-            Dmsg1(400, "Find oldest=%d\n", ok);
-           if (ok) {
-              UAContext *ua;
-               Dmsg0(400, "Try purge.\n");
-              /* Try to purge oldest volume */
-              ua = new_ua_context(jcr);
-               Jmsg(jcr, M_INFO, 0, _("Purging oldest volume \"%s\"\n"), mr.VolumeName);
-              ok = purge_jobs_from_volume(ua, &mr);
-              free_ua_context(ua);
+           if (!ok && jcr->pool->purge_oldest_volume) {
+               Dmsg1(200, "No next volume found. PurgeOldest=%d\n",
+                  jcr->pool->purge_oldest_volume);
+              /* Find oldest volume to recycle */
+              ok = db_find_next_volume(jcr, jcr->db, -1, &mr);
+               Dmsg1(400, "Find oldest=%d\n", ok);
               if (ok) {
-                 ok = recycle_oldest_purged_volume(jcr, &mr);
-                  Dmsg1(400, "Recycle after recycle oldest=%d\n", ok);
+                 UAContext *ua;
+                  Dmsg0(400, "Try purge.\n");
+                 /* Try to purge oldest volume */
+                 ua = new_ua_context(jcr);
+                  Jmsg(jcr, M_INFO, 0, _("Purging oldest volume \"%s\"\n"), mr.VolumeName);
+                 ok = purge_jobs_from_volume(ua, &mr);
+                 free_ua_context(ua);
+                 if (ok) {
+                    ok = recycle_oldest_purged_volume(jcr, &mr);
+                     Dmsg1(400, "Recycle after recycle oldest=%d\n", ok);
+                 }
               }
            }
         }
-      }
-      /* Check if use duration has expired */
-      Dmsg2(100, "VolJobs=%d FirstWritten=%d\n", mr.VolJobs, mr.FirstWritten);
-      if (ok && mr.VolJobs > 0 && mr.VolUseDuration > 0 && 
-           strcmp(mr.VolStatus, "Append") == 0) {
-        utime_t now = time(NULL);
-        if (mr.VolUseDuration <= (now - mr.FirstWritten)) {
-            Dmsg4(100, "Duration=%d now=%d start=%d now-start=%d\n",
-              (int)mr.VolUseDuration, (int)now, (int)mr.FirstWritten, 
-              (int)(now-mr.FirstWritten));
-            Jmsg(jcr, M_INFO, 0, _("Max configured use duration exceeded. "       
-               "Marking Volume \"%s\" as Used.\n"), mr.VolumeName);
-            strcpy(mr.VolStatus, "Used");  /* yes, mark as used */
-           if (!db_update_media_record(jcr, jcr->db, &mr)) {
-               Jmsg(jcr, M_ERROR, 0, _("Catalog error updating Media record. %s"),
-                   db_strerror(jcr->db));
-           } else if (retry++ < 200) {     /* sanity check */
-              goto next_volume;
-           } else {
-              Jmsg(jcr, M_ERROR, 0, _(
-"We seem to be looping trying to find the next volume. I give up. Ask operator.\n"));
+        /* Check if use duration applies, then if it has expired */
+         Dmsg2(100, "VolJobs=%d FirstWritten=%d\n", mr.VolJobs, mr.FirstWritten);
+        if (ok && mr.VolJobs > 0 && mr.VolUseDuration > 0 && 
+              strcmp(mr.VolStatus, "Append") == 0) {
+           utime_t now = time(NULL);
+           if (mr.VolUseDuration <= (now - mr.FirstWritten)) {
+              ok = FALSE;
+               Dmsg4(100, "Duration=%d now=%d start=%d now-start=%d\n",
+                 (int)mr.VolUseDuration, (int)now, (int)mr.FirstWritten, 
+                 (int)(now-mr.FirstWritten));
+               Jmsg(jcr, M_INFO, 0, _("Max configured use duration exceeded. "       
+                  "Marking Volume \"%s\" as Used.\n"), mr.VolumeName);
+               strcpy(mr.VolStatus, "Used");  /* yes, mark as used */
+              if (!db_update_media_record(jcr, jcr->db, &mr)) {
+                  Jmsg(jcr, M_ERROR, 0, _("Catalog error updating volume \"%s\". ERR=%s"),
+                      mr.VolumeName, db_strerror(jcr->db));
+              }           
+              if (retry++ < 200) {            /* sanity check */
+                 continue;                    /* try again from the top */
+              } else {
+                 Jmsg(jcr, M_ERROR, 0, _(
+"We seem to be looping trying to find the next volume. I give up.\n"));
+              }
            }
-           ok = FALSE;               /* give up */
         }
-      }
+        break;
+      } /* end for loop */
 
       /*
        * Send Find Media response to Storage daemon 
index fcfaf2e8ffa60693627919d4a36cf14f448d5723..6da0b13369dbcbb4819b7b5a09fba0def00249c6 100644 (file)
@@ -82,7 +82,7 @@ int recycle_oldest_purged_volume(JCR *jcr, MEDIA_DBR *mr)
 
    Dmsg0(100, "Enter recycle_oldest_purged_volume\n");
    oldest.MediaId = 0;
-   strcpy(oldest.LastWritten, "9999-99-99 99:99:99");
+   bstrncpy(oldest.LastWritten, "9999-99-99 99:99:99", sizeof(oldest.LastWritten));
    Mmsg(&query, select, mr->PoolId, mr->MediaType);
    if (!db_sql_query(jcr->db, query, oldest_handler, (void *)&oldest)) {
       Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
index 237511dcaa823afac53d6e6b56ef9d9f496ecf03..c0ce011d358696664e4921c53d014941302f00df 100644 (file)
@@ -429,10 +429,10 @@ void purge_files_from_job(UAContext *ua, JOB_DBR *jr)
 {
    char *query = (char *)get_pool_memory(PM_MESSAGE);
    
-   Mmsg(&query, "DELETE FROM File WHERE JobId=%d", jr->JobId);
+   Mmsg(&query, "DELETE FROM File WHERE JobId=%u", jr->JobId);
    db_sql_query(ua->db, query, NULL, (void *)NULL);
 
-   Mmsg(&query, "UPDATE Job Set PurgedFiles=1 WHERE JobId=%d", jr->JobId);
+   Mmsg(&query, "UPDATE Job Set PurgedFiles=1 WHERE JobId=%u", jr->JobId);
    db_sql_query(ua->db, query, NULL, (void *)NULL);
 
    free_pool_memory(query);