From: Eric Bollengier Date: Tue, 8 Aug 2023 12:46:25 +0000 (+0200) Subject: Add tryIncNumConcurrentJobs for CLIENT and STORE class X-Git-Tag: Beta-15.0.0~142 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78eae7917111fe4c481876537d03504ee92b1e21;p=thirdparty%2Fbacula.git Add tryIncNumConcurrentJobs for CLIENT and STORE class --- diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 75bf27d9e..1626690b7 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -103,6 +103,21 @@ void CLIENT::create_client_globals() client_globals.append(globals); } +int32_t CLIENT::tryIncNumConcurrentJobs(int32_t val, int32_t inc) +{ + LOCK_GUARD(globals_mutex); + if (globals == NULL) { + return 0; + } + if (globals->NumConcurrentJobs < val) { + globals->NumConcurrentJobs += inc; + + } else { + return 0; + } + return globals->NumConcurrentJobs; +} + int32_t CLIENT::getNumConcurrentJobs() { LOCK_GUARD(globals_mutex); @@ -262,6 +277,21 @@ void STORE::create_store_globals() store_globals.append(globals); } +int32_t STORE::tryIncNumConcurrentJobs(int32_t val, int32_t inc) +{ + LOCK_GUARD(globals_mutex); + if (globals == NULL) { + return 0; + } + if (globals->NumConcurrentJobs < val) { + globals->NumConcurrentJobs += inc; + + } else { + return 0; + } + return globals->NumConcurrentJobs; +} + int32_t STORE::getNumConcurrentReadJobs() { LOCK_GUARD(globals_mutex); diff --git a/bacula/src/dird/dird_conf.h b/bacula/src/dird/dird_conf.h index 5cafee631..59a9d6638 100644 --- a/bacula/src/dird/dird_conf.h +++ b/bacula/src/dird/dird_conf.h @@ -309,6 +309,7 @@ public: void create_client_globals(); int32_t getNumConcurrentJobs(); int32_t incNumConcurrentJobs(int32_t inc); + int32_t tryIncNumConcurrentJobs(int32_t val, int32_t inc); char *address(POOLMEM *&buf); void setAddress(char *addr); bool is_enabled(); @@ -376,6 +377,7 @@ public: int32_t getNumConcurrentReadJobs(); int32_t incNumConcurrentJobs(int32_t inc); int32_t incNumConcurrentReadJobs(int32_t inc); + int32_t tryIncNumConcurrentJobs(int32_t val, int32_t inc); bool is_enabled(); void setEnabled(bool val); }; diff --git a/bacula/src/dird/store_mngr.c b/bacula/src/dird/store_mngr.c index 7143029bc..1338de764 100644 --- a/bacula/src/dird/store_mngr.c +++ b/bacula/src/dird/store_mngr.c @@ -154,15 +154,9 @@ bool storage::set_current_storage(STORE *storage) { /* Returns true if it was possible to increment Storage's write counter, * returns false otherwise */ static bool inc_wstore(STORE *wstore) { - Dmsg1(dbglvl, "Wstore=%s\n", wstore->name()); - int num = wstore->getNumConcurrentJobs(); - if (num < wstore->MaxConcurrentJobs) { - num = wstore->incNumConcurrentJobs(1); - Dmsg2(dbglvl, "Store: %s Inc wncj=%d\n", wstore->name(), num); - return true; - } - - return false; + //Dmsg1(dbglvl, "Wstore=%s\n", wstore->name()); + int num = wstore->tryIncNumConcurrentJobs(wstore->MaxConcurrentJobs, 1); + return num > 0; } /* Returns true if it was possible to increment Storage's read counter, @@ -196,7 +190,7 @@ bool storage::inc_stores(JCR *jcr) { } /* Create a temp copy of the store list */ - alist *tmp_list = New(alist(10, not_owned_by_alist)); + alist *tmp_list = New(alist(MAX(10, list->size()), not_owned_by_alist)); if (!tmp_list) { Dmsg1(dbglvl, "Failed to allocate tmp list for jobid: %d\n", jcr->JobId); return false; @@ -208,7 +202,7 @@ bool storage::inc_stores(JCR *jcr) { /* Reset list */ list->destroy(); - list->init(10, not_owned_by_alist); + list->init(MAX(10, tmp_list->size()), not_owned_by_alist); foreach_alist(tmp_store, tmp_list) { if (write) {