]> git.sur5r.net Git - bacula/bacula/commitdiff
ebl Use a dedicate DB link to compute and send the accurate list
authorEric Bollengier <eric@eb.homelinux.org>
Mon, 22 Sep 2008 12:54:57 +0000 (12:54 +0000)
committerEric Bollengier <eric@eb.homelinux.org>
Mon, 22 Sep 2008 12:54:57 +0000 (12:54 +0000)
     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
bacula/src/cats/sql.c
bacula/src/cats/sql_create.c
bacula/src/dird/backup.c
bacula/src/dird/job.c
bacula/src/jcr.h
bacula/technotes-2.5

index 0ff887981afd2f14c88b183a6232594c99be6450..f0ef589ef3f499c5517a22ee51c75ae95d3f4a13 100644 (file)
@@ -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);
index f208299d6034c7555018dbe646509ec05d4284e0..a0cc7899a6bdeefae14fb581c4eaad2381edb6d9 100644 (file)
@@ -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*/
index 3f1e53b39abc63e668eb650ebbac6d02e67a6ec2..d3ba6f89b4a59d3cfc55e690a5af29aa76c93b2e 100644 (file)
@@ -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);
 }
index 6fd3d96be11772275b4fbfa21a5d68479f063017..4f50f8b7916657af713717908bb3adcec86f9a0f 100644 (file)
@@ -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;
 }
index 2224bc9939a9902157f59f81a87e3302caf04745..106757514f216d1917b0828a9c5d72971cf87a5b 100644 (file)
@@ -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;
index 6e8ce94fafd0c87a8d48495ad71653fb84ed664f..0b9af2a4fd2f054ad523bfb30f23ad558afe8762 100644 (file)
@@ -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 */
index 2f99b5093e4509d1820314dabfbf95fbceb6a7a0..61e776d66d706c179e7224a56756f490a3d1967b 100644 (file)
@@ -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