From: Michal Rakowski Date: Wed, 2 Jun 2021 11:31:29 +0000 (+0200) Subject: Fix #7674 About StorageGroups messages cleanup X-Git-Tag: Release-11.3.2~508 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1eaa03232a1dc986131a2bad1aeb35aa76a443f;p=thirdparty%2Fbacula.git Fix #7674 About StorageGroups messages cleanup --- diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 6d20834fd..8f782fdce 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -533,8 +533,12 @@ bool do_backup(JCR *jcr) if (wstore_group) { /* Apply policy for the write storage list */ - jcr->store_mngr->apply_policy(true); - Jmsg(jcr, M_INFO, 0, _("Possible storage choices: %s\n"), jcr->store_mngr->print_wlist()); + jcr->store_mngr->apply_write_policy(); + Dmsg2(100, "Configured storages: %s, source: %s\n", + jcr->store_mngr->print_origin_wlist(), jcr->store_mngr->get_wsource()); + Dmsg2(100, "Possible storage choices after applying \"%s\" policy: %s\n", + jcr->store_mngr->get_policy_name(), + jcr->store_mngr->print_possible_wlist()); iter_no = 2; } @@ -588,14 +592,18 @@ bool do_backup(JCR *jcr) Dmsg1(100, "Failed to start job on the storage: %s\n", jcr->store_mngr->get_wstore()->name()); continue; } else { - Jmsg(jcr, M_INFO, 0, _("Selected storage: %s, device: %s, StorageGroupPolicy: \"%s\"\n"), - jcr->store_mngr->get_wstore()->name(), jcr->write_dev, jcr->store_mngr->get_policy_name()); sd_job_started = true; break; } } if(sd_job_started) { + int group_size = jcr->store_mngr->get_origin_wstore_list()->size(); + Jmsg(jcr, M_INFO, 0, + "Storage \"%s\" was selected out of group of %d available storages. " + "StorageGroupPolicy used: \"%s\"", + jcr->store_mngr->get_wstore()->name(), group_size, + jcr->store_mngr->get_policy_name()); /* We can decrement not-used SDs since job was started against first available storage from the list */ jcr->store_mngr->dec_unused_wstores(); diff --git a/bacula/src/dird/store_mngr.c b/bacula/src/dird/store_mngr.c index 865491203..99abd91f1 100644 --- a/bacula/src/dird/store_mngr.c +++ b/bacula/src/dird/store_mngr.c @@ -25,6 +25,7 @@ static const int dbglvl = 200; storage::storage() { list = New(alist(10, not_owned_by_alist)); + origin_list = New(alist(10, not_owned_by_alist)); source = get_pool_memory(PM_MESSAGE); list_str = get_pool_memory(PM_MESSAGE); *source = 0; @@ -38,6 +39,10 @@ storage::~storage() { delete list; list = NULL; } + if (origin_list) { + delete origin_list; + origin_list = NULL; + } if (source) { free_and_null_pool_memory(source); } @@ -56,6 +61,10 @@ alist *storage::get_list() { return list; } +alist *storage::get_origin_list() { + return origin_list; +} + const char *storage::get_source() const { return source; } @@ -74,6 +83,7 @@ void storage::set(STORE *storage, const char *source) { reset(); list->append(storage); + origin_list->append(storage); store = storage; if (!source) { @@ -95,6 +105,7 @@ void storage::set(alist *storage, const char *source) { STORE *s; foreach_alist(s, storage) { list->append(s); + origin_list->append(s); } store = (STORE *)list->first(); @@ -107,9 +118,13 @@ void storage::set(alist *storage, const char *source) { void storage::reset() { store = NULL; + while (list->size()) { list->remove(0); } + while (origin_list->size()) { + origin_list->remove(0); + } *source = 0; *list_str = 0; } @@ -241,7 +256,7 @@ void storage::dec_stores() { } } -const char *storage::print_list() { +const char *storage::print_list(alist *list) { lock_guard lg(mutex); *list_str = 0; @@ -261,6 +276,14 @@ const char *storage::print_list() { return quote_string(list_str, tmp.addr()); } +const char *storage::print_origin_list() { + return print_list(origin_list); +} + +const char *storage::print_possible_list() { + return print_list(list); +} + void storage::dec_unused_stores() { lock_guard lg(mutex); STORE *tmp_store; @@ -329,6 +352,13 @@ void LeastUsedStore::apply_policy(bool write_store) { } } +void LeastUsedStore::apply_write_policy() { + return apply_policy(true); +} + +void LeastUsedStore::apply_read_policy() { + return apply_policy(false); +} StorageManager::StorageManager(const char *policy) { this->policy = bstrdup(policy); @@ -344,6 +374,10 @@ alist *StorageManager::get_rstore_list() { return rstore.get_list(); } +alist *StorageManager::get_origin_rstore_list() { + return rstore.get_origin_list(); +} + const char *StorageManager::get_rsource() const { return rstore.get_source(); } @@ -356,6 +390,10 @@ alist *StorageManager::get_wstore_list() { return wstore.get_list(); } +alist *StorageManager::get_origin_wstore_list() { + return wstore.get_origin_list(); +} + const char *StorageManager::get_wsource() const { return wstore.get_source(); } @@ -376,8 +414,12 @@ void StorageManager::reset_rstorage() { rstore.reset(); } -const char *StorageManager::print_rlist() { - return rstore.print_list(); +const char *StorageManager::print_possible_rlist() { + return rstore.print_possible_list(); +} + +const char *StorageManager::print_origin_rlist() { + return rstore.print_origin_list(); } bool StorageManager::set_current_wstorage(STORE *storage) { @@ -396,8 +438,12 @@ void StorageManager::reset_wstorage() { wstore.reset(); } -const char *StorageManager::print_wlist() { - return wstore.print_list(); +const char *StorageManager::print_possible_wlist() { + return wstore.print_possible_list(); +} + +const char *StorageManager::print_origin_wlist() { + return wstore.print_origin_list(); } void StorageManager::reset_rwstorage() { diff --git a/bacula/src/dird/store_mngr.h b/bacula/src/dird/store_mngr.h index 13c7b36bb..9febc14af 100644 --- a/bacula/src/dird/store_mngr.h +++ b/bacula/src/dird/store_mngr.h @@ -39,6 +39,7 @@ class storage { private: bool write; /* Write or read storage */ STORE *store; /* Selected storage to be used */ + alist *origin_list; /* Configured Storage (raw list without any policy applied) */ alist *list; /* Storage possibilities */ POOLMEM *source; /* Where the storage came from */ POOLMEM *list_str; /* List of storage names in the list */ @@ -50,6 +51,9 @@ class storage { /* Only when we are a write storage - increment concurrent write counters for all storages on the list */ bool inc_wstores(JCR *jcr); + + const char *print_list(alist *list); + public: storage(); @@ -63,9 +67,14 @@ class storage { return store; } - /* Get list of all possible storages */ + /* Get list of all possible storages. + * This metod can possibly return list with less storages than the original group. + * It's because some of it's elements can ba unavailable at that time (e.g. reached maxConcJobs limit). */ alist *get_list(); + /* Get original list of all storages as assigned by the set() method. */ + alist *get_origin_list(); + /* Get source of the storage (pool, job, commandline, unknown, ...) */ const char *get_source() const; @@ -97,7 +106,8 @@ class storage { void dec_curr_store(); /* Print all elements of the list (sample result of print_list() -> "File1, File2, File3" */ - const char *print_list(); + const char *print_origin_list(); + const char *print_possible_list(); }; @@ -115,9 +125,11 @@ class StorageManager : public SMARTALLOC { storage rstore; /* Read storage */ storage wstore; /* Write storage */ const char *policy; /* Storage Group Policy used */ + virtual void apply_policy(bool write_store) = 0; public: - virtual void apply_policy(bool write_store) = 0; + virtual void apply_write_policy() = 0; + virtual void apply_read_policy() = 0; virtual ~StorageManager() { reset_rwstorage(); @@ -135,6 +147,8 @@ class StorageManager : public SMARTALLOC { alist *get_rstore_list(); + alist *get_origin_rstore_list(); + const char *get_rsource() const; const char *get_rmedia_type() const; @@ -149,7 +163,8 @@ class StorageManager : public SMARTALLOC { void dec_read_stores(); - const char *print_rlist(); + const char *print_possible_rlist(); + const char *print_origin_rlist(); /************ WRITE STORAGE HELPERS ************/ STORE *get_wstore() { @@ -158,6 +173,8 @@ class StorageManager : public SMARTALLOC { alist *get_wstore_list(); + alist *get_origin_wstore_list(); + const char *get_wsource() const; const char *get_wmedia_type() const; @@ -170,7 +187,8 @@ class StorageManager : public SMARTALLOC { void reset_wstorage(); - const char *print_wlist(); + const char *print_possible_wlist(); + const char *print_origin_wlist(); bool inc_write_stores(JCR *jcr); @@ -192,8 +210,11 @@ class StorageManager : public SMARTALLOC { * Least used policy chooses storage from the list which has the least concurrent jobs number. */ class LeastUsedStore : public StorageManager { - public: + private: void apply_policy(bool write_store); + public: + void apply_write_policy(); + void apply_read_policy(); LeastUsedStore() : StorageManager("LeastUsed") { } @@ -207,11 +228,16 @@ class LeastUsedStore : public StorageManager { */ class ListedOrderStore : public StorageManager { private: - - public: void apply_policy(bool write_store) { /* Do nothing for now */ } + public: + void apply_write_policy() { + return apply_policy(true); + } + void apply_read_policy() { + return apply_policy(false); + } ListedOrderStore(): StorageManager("ListedOrder") { }