From: Eric Bollengier Date: Thu, 7 Apr 2022 11:46:53 +0000 (+0200) Subject: Save memory by not keeping the SQL batch session open during the backup X-Git-Tag: Beta-15.0.0~604 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61ead033c057ebf7eb535738decbdf250a2a99b7;p=thirdparty%2Fbacula.git Save memory by not keeping the SQL batch session open during the backup --- diff --git a/bacula/src/cats/bdb.h b/bacula/src/cats/bdb.h index 12f9c6b58..ad1bf6eda 100644 --- a/bacula/src/cats/bdb.h +++ b/bacula/src/cats/bdb.h @@ -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); diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 006324799..08e69b9fe 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -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) \ diff --git a/bacula/src/cats/sql.c b/bacula/src/cats/sql.c index 21de0de06..0689d787a 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -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; diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 7001a616e..17fd4a871 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -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)) { diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index dc82c8847..fca7177d2 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -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; } diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 5c8bdddee..4227b7cc2 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -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); diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 50266b65b..fec32974f 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -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); diff --git a/bacula/src/dird/vbackup.c b/bacula/src/dird/vbackup.c index aead6f7de..4ebe1b352 100644 --- a/bacula/src/dird/vbackup.c +++ b/bacula/src/dird/vbackup.c @@ -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; }