uint32_t MaxVolFiles; /* Max files on Volume */
uint64_t MaxVolBytes; /* Max bytes on Volume */
DBId_t RecyclePoolId; /* RecyclePool destination when media is purged */
+ DBId_t ScratchPoolId; /* ScratchPool source when media is needed */
char PoolType[MAX_NAME_LENGTH];
char LabelFormat[MAX_NAME_LENGTH];
/* Extra stuff not in DB */
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);
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,"
+"RecyclePoolId,ScratchPoolId) "
+"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,
pr->MaxVolJobs, pr->MaxVolFiles,
edit_uint64(pr->MaxVolBytes, ed3),
pr->PoolType, pr->LabelType, pr->LabelFormat,
- edit_int64(pr->RecyclePoolId,ed4));
+ edit_int64(pr->RecyclePoolId,ed4),
+ edit_int64(pr->ScratchPoolId,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"),
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);
}
-
if (QUERY_DB(jcr, mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
if (mdb->num_rows > 1) {
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;
}
}
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",
"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',RecyclePoolId=%s,"
+"ScratchPoolId=%s WHERE PoolId=%s",
pr->NumVols, pr->MaxVols, pr->UseOnce, pr->UseCatalog,
pr->AcceptAnyVolume, edit_uint64(pr->VolRetention, ed1),
edit_uint64(pr->VolUseDuration, ed2),
edit_uint64(pr->MaxVolBytes, ed3),
pr->Recycle, pr->AutoPrune, pr->LabelType,
pr->LabelFormat, edit_int64(pr->RecyclePoolId,ed5),
- ed4);
-
+ edit_int64(pr->ScratchPoolId,ed6),ed4);
stat = UPDATE_DB(jcr, mdb, mdb->cmd);
db_unlock(mdb);
return stat;
} else {
ed2[0] = 0;
}
- Dmsg1(100, "Scratch pool=%s\n", ed2);
+
+ if(mr->ScratchPoolId) {
+ edit_int64(mr->ScratchPoolId, ed3);
+ bstrncat(ed2, ed3, sizeof(ed2));
+ bstrncat(ed2, ",", sizeof(ed2));
+ }
+
+ Dmsg1(100, "Scratch pool(s)=%s\n", ed2);
/*
* ed2 ends up with scratch poolid and current poolid or
* just current poolid if there is no scratch pool
if (ok) {
mr.PoolId = pr.PoolId;
mr.StorageId = jcr->wstore->StorageId;
+ mr.ScratchPoolId = pr.ScratchPoolId;
ok = find_next_volume_for_append(jcr, &mr, index, fnv_create_vol, fnv_prune);
Dmsg3(050, "find_media ok=%d idx=%d vol=%s\n", ok, index, mr.VolumeName);
}
* in that catalog.
*/
if (!pool->catalog || pool->catalog == catalog) {
- update_pool_recyclepool(NULL, db, pool);
+ update_pool_references(NULL, db, pool);
}
}
{"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}
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());
}
/* 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;
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 source when requesting media */
alist *CopyPool; /* List of copy pools */
CAT *catalog; /* Catalog to be used */
/* Methods */
* Items needed:
* mr.PoolId must be set
* mr.StorageId should also be set
+ * mr.ScratchPoolId could be set (used if create==true)
* jcr->wstore
* jcr->db
* jcr->pool
P(mutex);
/*
* Get Pool record for Scratch Pool
+ * choose between ScratchPoolId and Scratch
+ * db_get_pool_record will first try ScratchPoolId,
+ * and then try the pool named Scratch
*/
memset(&spr, 0, sizeof(spr));
bstrncpy(spr.Name, "Scratch", sizeof(spr.Name));
+ spr.PoolId = mr->ScratchPoolId;
if (db_get_pool_record(jcr, jcr->db, &spr)) {
memset(&smr, 0, sizeof(smr));
smr.PoolId = spr.PoolId;
};
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_recyclepoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool);
+bool set_pooldbr_references(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_recyclepool(JCR *jcr, B_DB *db, POOL *pool);
+int update_pool_references(JCR *jcr, B_DB *db, POOL *pool);
/* ua_input.c */
int get_cmd(UAContext *ua, const char *prompt);
}
}
-/* set/update Pool.RecyclePoolId in Catalog */
-int update_pool_recyclepool(JCR *jcr, B_DB *db, POOL *pool)
+/* set/update Pool.RecyclePoolId and Pool.ScratchPoolId in Catalog */
+int update_pool_references(JCR *jcr, B_DB *db, POOL *pool)
{
POOL_DBR pr;
- if (!pool->RecyclePool) {
+ if (!pool->RecyclePool && !pool->ScratchPool) {
return 1;
}
set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE);
- if (!set_pooldbr_recyclepoolid(jcr, db, &pr, pool)) {
+ if (!set_pooldbr_references(jcr, db, &pr, pool)) {
return -1; /* error */
}
return 1;
}
-/* set POOL_DBR.RecyclePoolId from Pool resource
+/* set POOL_DBR.RecyclePoolId and POOL_DBR.ScratchPoolId from Pool resource
* works with set_pooldbr_from_poolres
*/
-bool set_pooldbr_recyclepoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool)
+bool set_pooldbr_references(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool)
{
POOL_DBR rpool;
bool ret = true;
} else { /* no RecyclePool used, set it to 0 */
pr->RecyclePoolId = 0;
}
+
+ 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;
}
/* Pool Exists */
if (op == POOL_OP_UPDATE) { /* update request */
set_pooldbr_from_poolres(&pr, pool, op);
+ set_pooldbr_references(jcr, db, &pr, pool);
db_update_pool_record(jcr, db, &pr);
}
return 0; /* exists */
}
set_pooldbr_from_poolres(&pr, pool, op);
+ set_pooldbr_references(jcr, db, &pr, pool);
if (!db_create_pool_record(jcr, db, &pr)) {
return -1; /* error */
mr.PoolId = jcr->jr.PoolId;
get_job_storage(&store, job, run);
mr.StorageId = store.store->StorageId;
+ /* no need to set ScratchPoolId, since we use fnv_no_create_vol */
if (!find_next_volume_for_append(jcr, &mr, 1, fnv_no_create_vol, fnv_prune)) {
ua->error_msg(_("Could not find next Volume for Job %s (Pool=%s, Level=%s).\n"),
job->name(), pr.Name, level_to_str(run->level));
mr.StorageId = sp->store->StorageId;
jcr->wstore = sp->store;
Dmsg0(250, "call find_next_volume_for_append\n");
+ /* no need to set ScratchPoolId, since we use fnv_no_create_vol */
ok = find_next_volume_for_append(jcr, &mr, 1, fnv_no_create_vol, fnv_no_prune);
}
if (!ok) {
}
set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE); /* update */
- set_pooldbr_recyclepoolid(ua->jcr, ua->db, &pr, pool);
+ set_pooldbr_references(ua->jcr, ua->db, &pr, pool);
id = db_update_pool_record(ua->jcr, ua->db, &pr);
if (id <= 0) {
General:
28Jan09
+ebl Add new ScratchPool directive to Pool. Thanks to Graham
ebl Turn on db_get_file_list() single SQL because the failure
was due to a full FS. And the accurate test fails with the
other code.