From: Eric Bollengier Date: Thu, 17 Sep 2015 17:07:35 +0000 (+0200) Subject: Modify find_next_volume_for_append() to not send the same volume twice X-Git-Tag: Release-7.4.0~97 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=42ac2e8104efa8b526cfd1bbdc13c0542cf52cd8;p=bacula%2Fbacula Modify find_next_volume_for_append() to not send the same volume twice --- diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index e21a838e42..2908f152f5 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -370,6 +370,7 @@ public: char cLastWritten[MAX_TIME_LENGTH]; /* LastWritten returned from DB */ char cLabelDate[MAX_TIME_LENGTH]; /* LabelData returned from DB */ char cInitialWrite[MAX_TIME_LENGTH]; /* InitialWrite returned from DB */ + char *exclude_list; /* Optionnal exclude list for db_find_next_volume() */ bool set_first_written; bool set_label_date; }; diff --git a/bacula/src/cats/sql_find.c b/bacula/src/cats/sql_find.c index 1c41c9cc04..16c8c3e770 100644 --- a/bacula/src/cats/sql_find.c +++ b/bacula/src/cats/sql_find.c @@ -343,11 +343,19 @@ int BDB::bdb_find_next_volume(JCR *jcr, int item, bool InChanger, MEDIA_DBR *mr) } else { POOL_MEM changer(PM_FNAME); POOL_MEM voltype(PM_FNAME); + POOL_MEM exclude(PM_FNAME); /* Find next available volume */ if (InChanger) { Mmsg(changer, " AND InChanger=1 AND StorageId=%s ", edit_int64(mr->StorageId, ed1)); } + /* Volumes will be automatically excluded from the query, we just take the + * first one of the list + */ + if (mr->exclude_list && *mr->exclude_list) { + item = 1; + Mmsg(exclude, " AND MediaId NOT IN (%s) ", mr->exclude_list); + } if (strcmp(mr->VolStatus, "Recycle") == 0 || strcmp(mr->VolStatus, "Purged") == 0) { order = "AND Recycle=1 ORDER BY LastWritten ASC,MediaId"; /* take oldest that can be recycled */ @@ -365,11 +373,12 @@ int BDB::bdb_find_next_volume(JCR *jcr, int item, bool InChanger, MEDIA_DBR *mr) "AND VolStatus='%s' " "%s " "%s " + "%s " "%s LIMIT %d", edit_int64(mr->PoolId, ed1), esc_type, esc_status, voltype.c_str(), - changer.c_str(), order, item); + changer.c_str(), exclude.c_str(), order, item); } Dmsg1(100, "fnextvol=%s\n", cmd); if (!QueryDB(jcr, cmd)) { diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 75840f601c..d45f55ceca 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -1433,6 +1433,7 @@ void dird_free_jcr(JCR *jcr) free_and_null_pool_memory(jcr->rpool_source); free_and_null_pool_memory(jcr->wstore_source); free_and_null_pool_memory(jcr->rstore_source); + free_and_null_pool_memory(jcr->next_vol_list); /* Delete lists setup to hold storage pointers */ free_rwstorage(jcr); @@ -1495,7 +1496,9 @@ void set_jcr_defaults(JCR *jcr, JOB *job) jcr->setJobLevel(job->JobLevel); break; } - + if (!jcr->next_vol_list) { + jcr->next_vol_list = get_pool_memory(PM_FNAME); + } if (!jcr->fname) { jcr->fname = get_pool_memory(PM_FNAME); } diff --git a/bacula/src/dird/next_vol.c b/bacula/src/dird/next_vol.c index 54fa108eb1..522e3234c1 100644 --- a/bacula/src/dird/next_vol.c +++ b/bacula/src/dird/next_vol.c @@ -47,6 +47,29 @@ void set_storageid_in_mr(STORE *store, MEDIA_DBR *mr) mr->StorageId = store->StorageId; } +static void add_volume_to_exclude_list(JCR *jcr, int index, MEDIA_DBR *mr) +{ + char ed1[50]; + if (index == 1) { + *jcr->next_vol_list = 0; + + } else if (*jcr->next_vol_list) { + pm_strcat(jcr->next_vol_list, ","); + } + pm_strcat(jcr->next_vol_list, edit_int64(mr->MediaId, ed1)); + + /* The list is valid only in find_next_volume_for_append() */ + mr->exclude_list = NULL; +} + +static void set_volume_to_exclude_list(JCR *jcr, int index, MEDIA_DBR *mr) +{ + if (index == 1) { + *jcr->next_vol_list = 0; + } + mr->exclude_list = jcr->next_vol_list; +} + /* * Items needed: * mr.PoolId must be set @@ -75,6 +98,9 @@ int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int index, */ InChanger = (store->autochanger)? true : false; + /* Make sure we don't send two times the same volume in the same session */ + set_volume_to_exclude_list(jcr, index, mr); + /* * Find the Next Volume for Append */ @@ -197,6 +223,11 @@ int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int index, } /* end for loop */ db_unlock(jcr->db); Dmsg1(dbglvl, "return ok=%d find_next_vol\n", ok); + + /* We keep the record of all previous volumes requested */ + if (ok) { + add_volume_to_exclude_list(jcr, index, mr);; + } return ok; } diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index e9fc3715b0..154b62cbc4 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -366,6 +366,7 @@ public: POOLMEM *rstore_source; /* Where read storage came from */ POOLMEM *wstore_source; /* Where write storage came from */ POOLMEM *catalog_source; /* Where catalog came from */ + POOLMEM *next_vol_list; /* Volumes previously requested */ uint32_t replace; /* Replace option */ int32_t NumVols; /* Number of Volume used in pool */ int32_t reschedule_count; /* Number of times rescheduled */