]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Save memory by not keeping the SQL batch session open during the backup
authorEric Bollengier <eric@baculasystems.com>
Thu, 7 Apr 2022 11:46:53 +0000 (13:46 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:58 +0000 (13:56 +0200)
bacula/src/cats/bdb.h
bacula/src/cats/protos.h
bacula/src/cats/sql.c
bacula/src/cats/sql_create.c
bacula/src/dird/backup.c
bacula/src/dird/job.c
bacula/src/dird/protos.h
bacula/src/dird/vbackup.c

index 12f9c6b58bf991ed8b6f36c7296068e679cb1ad3..ad1bf6eda25714917b80b1139777633336ce0ca6 100644 (file)
@@ -147,7 +147,7 @@ public:
    char *bdb_strerror() { return errmsg; };
    bool bdb_check_version(JCR *jcr);
    bool bdb_check_settings(JCR *jcr, int64_t *starttime, int val1, int64_t val2);
-   bool bdb_open_batch_connexion(JCR *jcr);
+   bool bdb_open_batch_connection(JCR *jcr);
    bool bdb_check_max_connections(JCR *jcr, uint32_t max_concurrent_jobs);
    virtual const char *search_op(JCR *jcr, const char *table_col, char *value, POOLMEM **esc, POOLMEM **dest);
 
index 006324799b6513bc45cd908cbd4eff642303752a..08e69b9fe7789732c08927c6a2f2ffa1ca2e038a 100644 (file)
@@ -92,8 +92,8 @@ int db_int_handler(void *ctx, int num_fields, char **row);
 void bdb_debug_print(JCR *jcr, FILE *fp);
 void db_free_restoreobject_record(JCR *jcr, ROBJECT_DBR *rr);
 
-#define db_open_batch_connexion(jcr, mdb) \
-           mdb->bdb_open_batch_connexion(jcr)
+#define db_open_batch_connection(jcr, mdb) \
+           mdb->bdb_open_batch_connection(jcr)
 #define db_strerror(mdb) \
            mdb->bdb_strerror()
 #define db_debug_print(jcr, fp) \
index 21de0de06e56b51216bc65eb3c0869d658efa568..0689d787ab086b2b2ffcb43294b838bfaaa39097 100644 (file)
@@ -1258,12 +1258,12 @@ json_list:
    json_list_end(send, ctx, 0, "");
    return mdb->sql_num_rows();
 } 
+
 /* 
- * Open a new connexion to mdb catalog. This function is used 
+ * Open a new connection to mdb catalog. This function is used 
  * by batch and accurate mode. 
  */ 
-bool BDB::bdb_open_batch_connexion(JCR *jcr) 
+bool BDB::bdb_open_batch_connection(JCR *jcr) 
 { 
    bool multi_db; 
  
index 7001a616e971ff89040a205fb6ce4c97fdaaefe4..17fd4a8715ca153c85141d212c22977cc74f4ddb 100644 (file)
@@ -930,7 +930,7 @@ bool BDB::bdb_create_batch_file_attributes_record(JCR *jcr, ATTR_DBR *ar)
 
    /* Open the dedicated connexion */
    if (!jcr->batch_started) {
-      if (!bdb_open_batch_connexion(jcr)) {
+      if (!bdb_open_batch_connection(jcr)) {
          return false;     /* error already printed */
       }
       if (!jcr->db_batch->sql_batch_start(jcr)) {
index dc82c8847b4663ceb140785c13feb02e028cc613..fca7177d24dff17716b6ca03c85adbfa935af1d3 100644 (file)
@@ -315,8 +315,8 @@ bool send_accurate_current_files(JCR *jcr)
    Dmsg2(200, "jobids=%s nb=%s\n", jobids.list, nb.list);
    jcr->file_bsock->fsend("accurate files=%s\n", nb.list);
 
-   if (!db_open_batch_connexion(jcr, jcr->db)) {
-      Jmsg0(jcr, M_FATAL, 0, "Can't get batch sql connexion");
+   if (!db_open_batch_connection(jcr, jcr->db)) {
+      Jmsg0(jcr, M_FATAL, 0, "Can't get batch sql connection");
       return false;  /* Fail */
    }
 
@@ -342,8 +342,10 @@ bool send_accurate_current_files(JCR *jcr)
       }
    }
 
-   /* TODO: close the batch connection ? (can be used very soon) */
    jcr->file_bsock->signal(BNET_EOD);
+
+   /* The connection can be used very soon, but it's taking a lot of resources */
+   dir_close_batch_connection(jcr);
    return true;
 }
 
index 5c8bdddeee4f57eddf4a7b9933def0b42e8a0691..4227b7cc2df4f3ad3347bfcbfdc772868972bb0e 100644 (file)
@@ -1545,6 +1545,16 @@ void dird_free_jcr_pointers(JCR *jcr)
    free_and_null_pool_memory(jcr->media_type);
 }
 
+/* Close an existing batch connection */
+void dir_close_batch_connection(JCR *jcr)
+{
+   if (jcr->db_batch) {
+      db_close_database(jcr, jcr->db_batch);
+      jcr->db_batch = NULL;
+      jcr->batch_started = false;
+   }
+}
+
 /*
  * Free the Job Control Record if no one is still using it.
  *  Called from main free_jcr() routine in src/lib/jcr.c so
@@ -1571,16 +1581,11 @@ void dird_free_jcr(JCR *jcr)
       pthread_cond_destroy(&jcr->term_wait);
       jcr->term_wait_inited = false;
    }
-   if (jcr->db_batch) {
-      db_close_database(jcr, jcr->db_batch);
-      jcr->db_batch = NULL;
-      jcr->batch_started = false;
-   }
+   dir_close_batch_connection(jcr);
    if (jcr->db) {
       db_close_database(jcr, jcr->db);
       jcr->db = NULL;
    }
-
    free_and_null_pool_memory(jcr->stime);
    free_and_null_pool_memory(jcr->fname);
    free_and_null_pool_memory(jcr->pool_source);
index 50266b65b63371d85a326a59f26d38f030e626a4..fec32974fdd423faa2999fa3c15bb745a447eb43 100644 (file)
@@ -149,6 +149,7 @@ extern bool run_console_command(JCR *jcr, const char *cmd);
 extern void sd_msg_thread_send_signal(JCR *jcr, int sig);
 void terminate_sd_msg_chan_thread(JCR *jcr);
 bool flush_file_records(JCR *jcr);
+void dir_close_batch_connection(JCR *jcr);
 
 /* jobq.c */
 extern bool inc_read_store(JCR *jcr);
index aead6f7deba35c4950b7f2ec408487384de002a0..4ebe1b352571978e9c1f8ac013fe4e730a26bc7d 100644 (file)
@@ -597,8 +597,8 @@ static bool create_bootstrap_file(JCR *jcr, char *jobids)
 
 #define new_get_file_list
 #ifdef new_get_file_list
-   if (!db_open_batch_connexion(jcr, jcr->db)) {
-      Jmsg0(jcr, M_FATAL, 0, "Can't get batch sql connexion");
+   if (!db_open_batch_connection(jcr, jcr->db)) {
+      Jmsg0(jcr, M_FATAL, 0, "Can't get batch sql connection");
       return false;
    }
    /* If the new Job is a Full, we don't need to keep deleted records,
@@ -644,5 +644,6 @@ static bool create_bootstrap_file(JCR *jcr, char *jobids)
         jcr->ExpectedFiles);
    free_ua_context(ua);
    free_bsr(rx.bsr_list);
+   dir_close_batch_connection(jcr);
    return jcr->ExpectedFiles==0?false:true;
 }