[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bacula-devel] Multiple storage daemons - multiple scratch pools?


On Thu, Dec 11, 2008 at 10:22:42AM +0100, Eric Bollengier wrote:
> So, please, provide your patch against the current trunk... We need also a 
> documentation patch for this feature. You can send it to me in a text format 
> if you are not a LaTeX user. A regress script that tests all new options is 
> also welcome.
...
> But i think that your patch can be more simple, let me explain
> 
> I think that you want that a pool (dedicated to a storage) takes media from a 
> specific Scratch pool. So, it's a pool attribute. (We have the ScratchPoolId 
> field in the Media table, but it's not a reason to use it).
> 
> It's not like the RecyclePool attribute that is a Volume attribute (for life).
> The ScratchPool is used to select a volume from a pool, and the RecyclePool
> is used to put a volume in a pool.
> 
> If i'm not wrong and you are ok, can you cleanup your patch in this way ?

OK, I've now got a new patch that should apply to latest SVN trunk, and
only uses the Pool ScratchPool attribute. It is attached.
I don't have a regress test for it. I'm not sure what sort of documentation
is needed for it, as it is quite simple.
The 'ScratchPool' attribute can be added to a Pool. It will then use that
'ScratchPool' from which to take volumes.
Index: WORK/src/cats/cats.h
===================================================================
RCS file: /cvs/netpilot/GPL/bacula-2.5.16/WORK/src/cats/cats.h,v
retrieving revision 1.1
diff -u -r1.1 cats.h
--- WORK/src/cats/cats.h	11 Dec 2008 16:00:10 -0000	1.1
+++ WORK/src/cats/cats.h	17 Dec 2008 15:25:50 -0000
@@ -910,6 +910,7 @@
    uint32_t MaxVolJobs;               /* Max Jobs on Volume */
    uint32_t MaxVolFiles;              /* Max files on Volume */
    uint64_t MaxVolBytes;              /* Max bytes on Volume */
+   DBId_t ScratchPoolId;              /* ScratchPool source */
    DBId_t RecyclePoolId;              /* RecyclePool destination when media is purged */
    char PoolType[MAX_NAME_LENGTH];
    char LabelFormat[MAX_NAME_LENGTH];
Index: WORK/src/cats/sql_create.c
===================================================================
RCS file: /cvs/netpilot/GPL/bacula-2.5.16/WORK/src/cats/sql_create.c,v
retrieving revision 1.1
diff -u -r1.1 sql_create.c
--- WORK/src/cats/sql_create.c	11 Dec 2008 16:00:10 -0000	1.1
+++ WORK/src/cats/sql_create.c	17 Dec 2008 15:25:50 -0000
@@ -170,7 +170,7 @@
 db_create_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
 {
    bool stat;        
-   char ed1[30], ed2[30], ed3[50], ed4[50];
+   char ed1[30], ed2[30], ed3[50], ed4[50], ed5[50];
 
    Dmsg0(200, "In create pool\n");
    db_lock(mdb);
@@ -192,8 +192,8 @@
    Mmsg(mdb->cmd,
 "INSERT INTO Pool (Name,NumVols,MaxVols,UseOnce,UseCatalog,"
 "AcceptAnyVolume,AutoPrune,Recycle,VolRetention,VolUseDuration,"
-"MaxVolJobs,MaxVolFiles,MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId) "
-"VALUES ('%s',%u,%u,%d,%d,%d,%d,%d,%s,%s,%u,%u,%s,'%s',%d,'%s',%s)",
+"MaxVolJobs,MaxVolFiles,MaxVolBytes,PoolType,LabelType,LabelFormat,ScratchPoolId,RecyclePoolId) "
+"VALUES ('%s',%u,%u,%d,%d,%d,%d,%d,%s,%s,%u,%u,%s,'%s',%d,'%s',%s,%s)",
                   pr->Name,
                   pr->NumVols, pr->MaxVols,
                   pr->UseOnce, pr->UseCatalog,
@@ -204,7 +204,8 @@
                   pr->MaxVolJobs, pr->MaxVolFiles,
                   edit_uint64(pr->MaxVolBytes, ed3),
                   pr->PoolType, pr->LabelType, pr->LabelFormat,
-                  edit_int64(pr->RecyclePoolId,ed4));
+                  edit_int64(pr->ScratchPoolId,ed4),
+                  edit_int64(pr->RecyclePoolId,ed5));
    Dmsg1(200, "Create Pool: %s\n", mdb->cmd);
    if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create db Pool record %s failed: ERR=%s\n"),
Index: WORK/src/cats/sql_get.c
===================================================================
RCS file: /cvs/netpilot/GPL/bacula-2.5.16/WORK/src/cats/sql_get.c,v
retrieving revision 1.1
diff -u -r1.1 sql_get.c
--- WORK/src/cats/sql_get.c	11 Dec 2008 16:00:10 -0000	1.1
+++ WORK/src/cats/sql_get.c	17 Dec 2008 15:25:50 -0000
@@ -582,13 +582,13 @@
       Mmsg(mdb->cmd,
 "SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,"
 "AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
-"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId FROM Pool WHERE Pool.PoolId=%s", 
+"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId,ScratchPoolId FROM Pool WHERE Pool.PoolId=%s", 
          edit_int64(pdbr->PoolId, ed1));
    } else {                           /* find by name */
       Mmsg(mdb->cmd,
 "SELECT PoolId,Name,NumVols,MaxVols,UseOnce,UseCatalog,AcceptAnyVolume,"
 "AutoPrune,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
-"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId FROM Pool WHERE Pool.Name='%s'", 
+"MaxVolBytes,PoolType,LabelType,LabelFormat,RecyclePoolId,ScratchPoolId FROM Pool WHERE Pool.Name='%s'", 
          pdbr->Name);
    }
 
@@ -622,6 +622,7 @@
             pdbr->LabelType = str_to_int64(row[15]);
             bstrncpy(pdbr->LabelFormat, row[16]!=NULL?row[16]:"", sizeof(pdbr->LabelFormat));
             pdbr->RecyclePoolId = str_to_int64(row[17]);
+            pdbr->ScratchPoolId = str_to_int64(row[18]);
             ok = true;
          }
       }
@@ -637,6 +638,7 @@
          pdbr->NumVols = NumVols;
          db_update_pool_record(jcr, mdb, pdbr);
       }
+      Mmsg(mdb->errmsg, _("Pool %s: %d %d\n"), pdbr->Name, pdbr->RecyclePoolId, pdbr->ScratchPoolId);
    } else {
       Mmsg(mdb->errmsg, _("Pool record not found in Catalog.\n"));
    }
Index: WORK/src/cats/sql_update.c
===================================================================
RCS file: /cvs/netpilot/GPL/bacula-2.5.16/WORK/src/cats/sql_update.c,v
retrieving revision 1.2
diff -u -r1.2 sql_update.c
--- WORK/src/cats/sql_update.c	11 Dec 2008 16:19:49 -0000	1.2
+++ WORK/src/cats/sql_update.c	17 Dec 2008 15:25:50 -0000
@@ -310,7 +310,7 @@
 int db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
 {
    int stat;
-   char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50];
+   char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50], ed6[50];
 
    db_lock(mdb);
    Mmsg(mdb->cmd, "SELECT count(*) from Media WHERE PoolId=%s",
@@ -322,14 +322,16 @@
 "UPDATE Pool SET NumVols=%u,MaxVols=%u,UseOnce=%d,UseCatalog=%d,"
 "AcceptAnyVolume=%d,VolRetention='%s',VolUseDuration='%s',"
 "MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s,Recycle=%d,"
-"AutoPrune=%d,LabelType=%d,LabelFormat='%s',RecyclePoolId=%s WHERE PoolId=%s",
+"AutoPrune=%d,LabelType=%d,LabelFormat='%s',ScratchPoolId=%s,RecyclePoolId=%s WHERE PoolId=%s",
       pr->NumVols, pr->MaxVols, pr->UseOnce, pr->UseCatalog,
       pr->AcceptAnyVolume, edit_uint64(pr->VolRetention, ed1),
       edit_uint64(pr->VolUseDuration, ed2),
       pr->MaxVolJobs, pr->MaxVolFiles,
       edit_uint64(pr->MaxVolBytes, ed3),
       pr->Recycle, pr->AutoPrune, pr->LabelType,
-      pr->LabelFormat, edit_int64(pr->RecyclePoolId,ed5),
+      pr->LabelFormat,
+      edit_int64(pr->ScratchPoolId,ed5),
+      edit_int64(pr->RecyclePoolId,ed6),
       ed4);
 
    stat = UPDATE_DB(jcr, mdb, mdb->cmd);
Index: WORK/src/dird/autoprune.c
===================================================================
RCS file: /cvs/netpilot/GPL/bacula-2.5.16/WORK/src/dird/autoprune.c,v
retrieving revision 1.2
diff -u -r1.2 autoprune.c
--- WORK/src/dird/autoprune.c	11 Dec 2008 16:19:49 -0000	1.2
+++ WORK/src/dird/autoprune.c	17 Dec 2008 15:25:50 -0000
@@ -96,7 +96,8 @@
    struct del_ctx prune_list;
    POOL_MEM query(PM_MESSAGE);
    UAContext *ua;
-   char ed1[50], ed2[100], ed3[50];
+   char ed1[50], ed2[100], ed3[50], ed4[50];
+   POOL_DBR pr;
    POOL_DBR spr;
 
    Dmsg1(100, "Prune volumes PoolId=%d\n", jcr->jr.PoolId);
@@ -133,6 +134,18 @@
     */
    bstrncat(ed2, ed1, sizeof(ed2));
 
+   /* Also include the ScratchPoolId indicated on the Pool that the volume
+      is a member of, if it is set. */
+   memset(&pr, 0, sizeof(pr));
+   pr.PoolId=mr->PoolId;
+   if (db_get_pool_record(jcr, jcr->db, &pr)) {
+      if(pr.ScratchPoolId) {
+         edit_int64(pr.ScratchPoolId, ed4);
+         bstrncat(ed2, ",", sizeof(ed2));
+   	 bstrncat(ed2, ed4, sizeof(ed2));
+      }
+   }
+
    /*
     * Get the List of all media ids in the current Pool or whose
     *  RecyclePoolId is the current pool or the scratch pool
Index: WORK/src/dird/dird.c
===================================================================
RCS file: /cvs/netpilot/GPL/bacula-2.5.16/WORK/src/dird/dird.c,v
retrieving revision 1.2
diff -u -r1.2 dird.c
--- WORK/src/dird/dird.c	11 Dec 2008 16:19:49 -0000	1.2
+++ WORK/src/dird/dird.c	17 Dec 2008 15:25:50 -0000
@@ -950,6 +950,7 @@
          if (!pool->catalog || pool->catalog == catalog) {
             create_pool(NULL, db, pool, POOL_OP_UPDATE);  /* update request */
             update_pool_recyclepool(NULL, db, pool);
+            update_pool_scratchpool(NULL, db, pool);
          }
       }
 
Index: WORK/src/dird/dird_conf.c
===================================================================
RCS file: /cvs/netpilot/GPL/bacula-2.5.16/WORK/src/dird/dird_conf.c,v
retrieving revision 1.1
diff -u -r1.1 dird_conf.c
--- WORK/src/dird/dird_conf.c	11 Dec 2008 16:00:10 -0000	1.1
+++ WORK/src/dird/dird_conf.c	17 Dec 2008 15:25:50 -0000
@@ -396,6 +396,7 @@
    {"autoprune",     store_bool,      ITEM(res_pool.AutoPrune), 0, ITEM_DEFAULT, true},
    {"recycle",       store_bool,      ITEM(res_pool.Recycle),   0, ITEM_DEFAULT, true},
    {"recyclepool",   store_res,       ITEM(res_pool.RecyclePool), R_POOL, 0, 0},
+   {"scratchpool",   store_res,       ITEM(res_pool.ScratchPool), R_POOL, 0, 0},
    {"copypool",      store_alist_res, ITEM(res_pool.CopyPool), R_POOL, 0, 0},
    {"catalog",       store_res,       ITEM(res_pool.catalog), R_CATALOG, 0, 0},
    {NULL, NULL, {0}, 0, 0, 0}
@@ -950,6 +951,9 @@
       if (res->res_pool.RecyclePool) {
          sendit(sock, _("      RecyclePool=%s\n"), res->res_pool.RecyclePool->name());
       }
+      if (res->res_pool.ScratchPool) {
+         sendit(sock, _("      ScratchPool=%s\n"), res->res_pool.ScratchPool->name());
+      }
       if (res->res_pool.catalog) {
          sendit(sock, _("      Catalog=%s\n"), res->res_pool.catalog->name());
       }
@@ -1384,6 +1388,7 @@
          /* Explicitly copy resource pointers from this pass (res_all) */
          res->res_pool.NextPool = res_all.res_pool.NextPool;
          res->res_pool.RecyclePool = res_all.res_pool.RecyclePool;
+         res->res_pool.ScratchPool = res_all.res_pool.ScratchPool;
          res->res_pool.storage    = res_all.res_pool.storage;
          res->res_pool.catalog    = res_all.res_pool.catalog;
          break;
Index: WORK/src/dird/dird_conf.h
===================================================================
RCS file: /cvs/netpilot/GPL/bacula-2.5.16/WORK/src/dird/dird_conf.h,v
retrieving revision 1.1
diff -u -r1.1 dird_conf.h
--- WORK/src/dird/dird_conf.h	11 Dec 2008 16:00:10 -0000	1.1
+++ WORK/src/dird/dird_conf.h	17 Dec 2008 15:25:50 -0000
@@ -561,6 +561,7 @@
    bool  AutoPrune;                   /* default for pool auto prune */
    bool  Recycle;                     /* default for media recycle yes/no */
    POOL  *RecyclePool;                /* RecyclePool destination when media is purged */
+   POOL  *ScratchPool;                /* ScratchPool */
    alist *CopyPool;                   /* List of copy pools */
    CAT *catalog;                      /* Catalog to be used */
    /* Methods */
Index: WORK/src/dird/next_vol.c
===================================================================
RCS file: /cvs/netpilot/GPL/bacula-2.5.16/WORK/src/dird/next_vol.c,v
retrieving revision 1.1
diff -u -r1.1 next_vol.c
--- WORK/src/dird/next_vol.c	11 Dec 2008 16:00:10 -0000	1.1
+++ WORK/src/dird/next_vol.c	17 Dec 2008 15:25:50 -0000
@@ -342,6 +342,14 @@
     */
    memset(&spr, 0, sizeof(spr));
    bstrncpy(spr.Name, "Scratch", sizeof(spr.Name));
+   /* Also include the ScratchPoolId indicated on the Pool that the volume
+      is a member of, if it is set. */
+   memset(&pr, 0, sizeof(pr));
+   pr.PoolId=mr->PoolId;
+   if (db_get_pool_record(jcr, jcr->db, &pr) && pr.ScratchPoolId)
+	spr.PoolId=pr.ScratchPoolId;
+
+   /* db_get_pool_record will first try ScratchPoolId, and then try the pool named Scratch */
    if (db_get_pool_record(jcr, jcr->db, &spr)) {
       memset(&smr, 0, sizeof(smr));
       smr.PoolId = spr.PoolId;
Index: WORK/src/dird/protos.h
===================================================================
RCS file: /cvs/netpilot/GPL/bacula-2.5.16/WORK/src/dird/protos.h,v
retrieving revision 1.1
diff -u -r1.1 protos.h
--- WORK/src/dird/protos.h	11 Dec 2008 16:00:10 -0000	1.1
+++ WORK/src/dird/protos.h	17 Dec 2008 15:25:50 -0000
@@ -196,8 +196,10 @@
 };
 int create_pool(JCR *jcr, B_DB *db, POOL *pool, e_pool_op op);
 void set_pool_dbr_defaults_in_media_dbr(MEDIA_DBR *mr, POOL_DBR *pr);
+bool set_pooldbr_scratchpoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool);
 bool set_pooldbr_recyclepoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool);
 void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op);
+int update_pool_scratchpool(JCR *jcr, B_DB *db, POOL *pool);
 int update_pool_recyclepool(JCR *jcr, B_DB *db, POOL *pool);
 
 /* ua_input.c */
Index: WORK/src/dird/ua_cmds.c
===================================================================
RCS file: /cvs/netpilot/GPL/bacula-2.5.16/WORK/src/dird/ua_cmds.c,v
retrieving revision 1.1
diff -u -r1.1 ua_cmds.c
--- WORK/src/dird/ua_cmds.c	11 Dec 2008 16:00:10 -0000	1.1
+++ WORK/src/dird/ua_cmds.c	17 Dec 2008 15:25:50 -0000
@@ -530,6 +530,8 @@
  *
  * Caution : RecyclePoolId isn't setup in this function.
  *           You can use set_pooldbr_recyclepoolid();
+ * Caution : ScratchPoolId isn't setup in this function.
+ *           You can use set_pooldbr_scratchpoolid();
  *
  */
 void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op)
@@ -564,6 +566,34 @@
    }
 }
 
+/* set/update Pool.ScratchPoolId in Catalog */
+int update_pool_scratchpool(JCR *jcr, B_DB *db, POOL *pool)
+{
+   POOL_DBR  pr;
+
+   if (!pool->ScratchPool) {
+      return 1;
+   }
+
+   memset(&pr, 0, sizeof(POOL_DBR));
+   bstrncpy(pr.Name, pool->name(), sizeof(pr.Name));
+
+   if (!db_get_pool_record(jcr, db, &pr)) {
+      return -1;                       /* not exists in database */
+   }
+
+   set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE);
+
+   if (!set_pooldbr_scratchpoolid(jcr, db, &pr, pool)) {
+      return -1;                      /* error */
+   }
+
+   if (!db_update_pool_record(jcr, db, &pr)) {
+      return -1;                      /* error */
+   }
+   return 1;
+}
+
 /* set/update Pool.RecyclePoolId in Catalog */
 int update_pool_recyclepool(JCR *jcr, B_DB *db, POOL *pool)
 {
@@ -592,6 +622,34 @@
    return 1;
 }
 
+/* set POOL_DBR.ScratchPoolId from Pool resource 
+ * works with set_pooldbr_from_poolres
+ */
+bool set_pooldbr_scratchpoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool)
+{
+   POOL_DBR rpool;
+   bool ret = true;
+
+   if (pool->ScratchPool) {
+      memset(&rpool, 0, sizeof(POOL_DBR));
+
+      bstrncpy(rpool.Name, pool->ScratchPool->name(), sizeof(rpool.Name));
+      if (db_get_pool_record(jcr, db, &rpool)) {
+        pr->ScratchPoolId = rpool.PoolId;
+      } else {
+        Jmsg(jcr, M_WARNING, 0,
+        _("Can't set %s ScratchPool to %s, %s is not in database.\n" \
+          "Try to update it with 'update pool=%s'\n"),
+        pool->name(), rpool.Name, rpool.Name,pool->name());
+
+        ret = false;
+      }
+   } else {                    /* no ScratchPool used, set it to 0 */
+      pr->ScratchPoolId = 0;
+   }
+   return ret;
+}
+
 /* set POOL_DBR.RecyclePoolId from Pool resource 
  * works with set_pooldbr_from_poolres
  */
@@ -641,12 +699,16 @@
       /* Pool Exists */
       if (op == POOL_OP_UPDATE) {  /* update request */
          set_pooldbr_from_poolres(&pr, pool, op);
+         update_pool_scratchpool(jcr, db, pool);
+         update_pool_recyclepool(jcr, db, pool);
          db_update_pool_record(jcr, db, &pr);
       }
       return 0;                       /* exists */
    }
 
    set_pooldbr_from_poolres(&pr, pool, op);
+   update_pool_scratchpool(jcr, db, pool);
+   update_pool_recyclepool(jcr, db, pool);
 
    if (!db_create_pool_record(jcr, db, &pr)) {
       return -1;                      /* error */
Index: WORK/src/dird/ua_update.c
===================================================================
RCS file: /cvs/netpilot/GPL/bacula-2.5.16/WORK/src/dird/ua_update.c,v
retrieving revision 1.2
diff -u -r1.2 ua_update.c
--- WORK/src/dird/ua_update.c	11 Dec 2008 16:19:49 -0000	1.2
+++ WORK/src/dird/ua_update.c	17 Dec 2008 15:25:50 -0000
@@ -880,6 +880,7 @@
    }
 
    set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE); /* update */
+   set_pooldbr_scratchpoolid(ua->jcr, ua->db, &pr, pool);
    set_pooldbr_recyclepoolid(ua->jcr, ua->db, &pr, pool);
 
    id = db_update_pool_record(ua->jcr, ua->db, &pr);
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Bacula-devel mailing list
Bacula-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/bacula-devel


This mailing list archive is a service of Copilotco.