From cda26d3b5d408f293ac449aa744c18206e72ca16 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Mon, 22 Sep 2008 12:54:57 +0000 Subject: [PATCH] ebl Use a dedicate DB link to compute and send the accurate list file to the client. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7618 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/protos.h | 1 + bacula/src/cats/sql.c | 38 +++++++++++++++++++++++++++++++ bacula/src/cats/sql_create.c | 43 ++++++++++-------------------------- bacula/src/dird/backup.c | 11 +++++++-- bacula/src/dird/job.c | 5 +++-- bacula/src/jcr.h | 3 ++- bacula/technotes-2.5 | 3 +++ 7 files changed, 68 insertions(+), 36 deletions(-) diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 0ff887981a..f0ef589ef3 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -49,6 +49,7 @@ B_DB *db_init_database(JCR *jcr, const char *db_name, const char *db_user, const int mult_db_connections); int db_open_database(JCR *jcr, B_DB *db); void db_close_database(JCR *jcr, B_DB *db); +bool db_open_batch_connexion(JCR *jcr, B_DB *mdb); void db_escape_string(JCR *jcr, B_DB *db, char *snew, char *old, int len); char *db_strerror(B_DB *mdb); int db_next_index(JCR *jcr, B_DB *mdb, char *table, char *index); diff --git a/bacula/src/cats/sql.c b/bacula/src/cats/sql.c index f208299d60..a0cc7899a6 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -635,5 +635,43 @@ vertical_list: return; } +/* + * Open a new connexion to mdb catalog. This function is used + * by batch and accurate mode. + */ +bool db_open_batch_connexion(JCR *jcr, B_DB *mdb) +{ + int multi_db=false; + +#ifdef HAVE_BATCH_FILE_INSERT + multi_db=true; /* we force a new connexion only if batch insert is enabled */ +#endif + + if (!jcr->db_batch) { + jcr->db_batch = db_init_database(jcr, + mdb->db_name, + mdb->db_user, + mdb->db_password, + mdb->db_address, + mdb->db_port, + mdb->db_socket, + multi_db /* multi_db = true when using batch mode */); + if (!jcr->db_batch) { + Jmsg0(jcr, M_FATAL, 0, "Could not init batch connexion"); + return false; + } + + if (!db_open_database(jcr, jcr->db_batch)) { + Mmsg2(&jcr->db_batch->errmsg, _("Could not open database \"%s\": ERR=%s\n"), + jcr->db_batch->db_name, db_strerror(jcr->db_batch)); + Jmsg1(jcr, M_FATAL, 0, "%s", jcr->db_batch->errmsg); + return false; + } + Dmsg3(100, "initdb ref=%d connected=%d db=%p\n", jcr->db_batch->ref_count, + jcr->db_batch->connected, jcr->db_batch->db); + + } + return true; +} #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL*/ diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 3f1e53b39a..d3ba6f89b4 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -758,7 +758,7 @@ bool db_write_batch_file_records(JCR *jcr) { int JobStatus = jcr->JobStatus; - if (!jcr->db_batch) { /* no files to backup ? */ + if (!jcr->batch_started) { /* no files to backup ? */ Dmsg0(50,"db_create_file_record : no files\n"); return true; } @@ -845,38 +845,19 @@ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) Dmsg1(dbglevel, "Fname=%s\n", ar->fname); Dmsg0(dbglevel, "put_file_into_catalog\n"); - if (!jcr->db_batch) { - Dmsg2(100, "Opendb attr. Stream=%d fname=%s\n", ar->Stream, ar->fname); - jcr->db_batch = db_init_database(jcr, - mdb->db_name, - mdb->db_user, - mdb->db_password, - mdb->db_address, - mdb->db_port, - mdb->db_socket, - 1 /* multi_db = true */); - if (!jcr->db_batch) { - Mmsg1(&mdb->errmsg, _("Could not init batch database: \"%s\".\n"), - jcr->db->db_name); - Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg); - return false; - } + /* Open the dedicated connexion */ + if (!jcr->batch_started) { - if (!db_open_database(jcr, jcr->db_batch)) { - Mmsg2(&mdb->errmsg, _("Could not open database \"%s\": ERR=%s\n"), - jcr->db->db_name, db_strerror(jcr->db_batch)); - Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg); + if (!db_open_batch_connexion(jcr, mdb)) { return false; - } - + } if (!sql_batch_start(jcr, jcr->db_batch)) { Mmsg1(&mdb->errmsg, "Can't start batch mode: ERR=%s", db_strerror(jcr->db_batch)); Jmsg1(jcr, M_FATAL, 0, "%s", mdb->errmsg); return false; } - Dmsg3(100, "initdb ref=%d connected=%d db=%p\n", jcr->db_batch->ref_count, - jcr->db_batch->connected, jcr->db_batch->db); + jcr->batch_started = true; } B_DB *bdb = jcr->db_batch; @@ -895,12 +876,12 @@ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) /* - if (bdb->changes > 100000) { - db_write_batch_file_records(jcr); - bdb->changes = 0; - sql_batch_start(jcr, bdb); - } -*/ + * if (bdb->changes > 100000) { + * db_write_batch_file_records(jcr); + * bdb->changes = 0; + * sql_batch_start(jcr, bdb); + * } + */ return sql_batch_insert(jcr, bdb, ar); } diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 6fd3d96be1..4f50f8b791 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -136,6 +136,7 @@ bool send_accurate_current_files(JCR *jcr) return true; } POOLMEM *jobids = get_pool_memory(PM_FNAME); + db_accurate_get_jobids(jcr, jcr->db, &jcr->jr, jobids); if (*jobids == 0) { @@ -153,13 +154,19 @@ bool send_accurate_current_files(JCR *jcr) Dmsg2(200, "jobids=%s nb=%s\n", jobids, nb); jcr->file_bsock->fsend("accurate files=%s\n", nb); - db_get_file_list(jcr, jcr->db, jobids, accurate_list_handler, (void *)jcr); + if (!db_open_batch_connexion(jcr, jcr->db)) { + Jmsg0(jcr, M_FATAL, 0, "Can't get dedicate sql connexion"); + return false; + } + + db_get_file_list(jcr, jcr->db_batch, jobids, accurate_list_handler, (void *)jcr); + + /* TODO: close the batch connexion ? (can be used very soon) */ free_pool_memory(jobids); free_pool_memory(nb); jcr->file_bsock->signal(BNET_EOD); - /* TODO: use response() ? */ return true; } diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 2224bc9939..106757514f 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -972,10 +972,11 @@ void dird_free_jcr(JCR *jcr) pthread_cond_destroy(&jcr->term_wait); jcr->term_wait_inited = false; } - if (jcr->db_batch && jcr->db_batch != jcr->db) { + if (jcr->db_batch) { db_close_database(jcr, jcr->db_batch); + jcr->db_batch = NULL; + jcr->batch_started = false; } - jcr->db_batch = NULL; if (jcr->db) { db_close_database(jcr, jcr->db); jcr->db = NULL; diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 6e8ce94faf..0b9af2a4fd 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -233,7 +233,8 @@ public: bool cached_attribute; /* set if attribute is cached */ POOLMEM *attr; /* Attribute string from SD */ B_DB *db; /* database pointer */ - B_DB *db_batch; /* database pointer for batch insert */ + B_DB *db_batch; /* database pointer for batch and accurate */ + bool batch_started; /* is batch mode already started ? */ ATTR_DBR *ar; /* DB attribute record */ guid_list *id_list; /* User/group id to name list */ bool accurate; /* true if job is accurate */ diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index 2f99b5093e..61e776d66d 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -18,6 +18,9 @@ dbdriver remove reader/writer in FOPTS???? General: +22Sep08 +ebl Use a dedicate DB link to compute and send the accurate list + file to the client. 21Sep08 kes Fix compile errors in filed/fd_plugin.c. 20Sep08 -- 2.39.5