]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add tryIncNumConcurrentJobs for CLIENT and STORE class
authorEric Bollengier <eric@baculasystems.com>
Tue, 8 Aug 2023 12:46:25 +0000 (14:46 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:01 +0000 (13:57 +0200)
bacula/src/dird/dird_conf.c
bacula/src/dird/dird_conf.h
bacula/src/dird/store_mngr.c

index 75bf27d9e37a4a41a7a195dac9b4d3946ff8c2e3..1626690b7c8bdae6c056be799b49e69474a3d94b 100644 (file)
@@ -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);
index 5cafee6318599c06f157ced1a72460af4c34a0c3..59a9d6638f47da831ea2e437bc61b8f878a69838 100644 (file)
@@ -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);
 };
index 7143029bc27272c456ead4ea6d2c0c68454fa2af..1338de764df15d7d0dc0a65474c9a7daad0fc227 100644 (file)
@@ -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) {