]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #4433 about 'UPDATE File SET MD5='...' WHERE FileId=0' error when using SpoolAttr...
authorEric Bollengier <eric@baculasystems.com>
Thu, 13 Dec 2018 10:56:31 +0000 (11:56 +0100)
committerKern Sibbald <kern@sibbald.com>
Mon, 8 Apr 2019 16:44:16 +0000 (18:44 +0200)
bacula/src/cats/mysql.c
bacula/src/cats/postgresql.c
bacula/src/cats/sqlite.c
bacula/src/dird/backup.c
bacula/src/dird/job.c
bacula/src/dird/mac.c
bacula/src/dird/protos.h
bacula/src/dird/vbackup.c
bacula/src/dird/verify.c

index d3a0c46f40f4c56b22383a68f8365cfcd75d89d5..ca9c60952b32b98f1c9762c06c90433904cce05e 100644 (file)
@@ -458,13 +458,6 @@ void BDB_MYSQL::bdb_start_transaction(JCR *jcr)
  
 void BDB_MYSQL::bdb_end_transaction(JCR *jcr) 
 { 
-   if (jcr && jcr->cached_attribute) { 
-      Dmsg0(400, "Flush last cached attribute.\n"); 
-      if (!bdb_create_attributes_record(jcr, jcr->ar)) { 
-         Jmsg1(jcr, M_FATAL, 0, _("Attribute create error. %s"), jcr->db->bdb_strerror()); 
-      } 
-      jcr->cached_attribute = false; 
-   } 
 } 
  
 /* 
index a611ffa3d269812b03bcc1d7c1192013aee6c908..46d29617615fe72a5626be168bc3cd2344cb8609 100644 (file)
@@ -546,14 +546,6 @@ void BDB_POSTGRESQL::bdb_end_transaction(JCR *jcr)
 {
    BDB_POSTGRESQL *mdb = this;
 
-   if (jcr && jcr->cached_attribute) { 
-      Dmsg0(dbglvl_info, "Flush last cached attribute.\n");
-      if (!bdb_create_attributes_record(jcr, jcr->ar)) {
-         Jmsg1(jcr, M_FATAL, 0, _("Attribute create error. %s"), jcr->db->bdb_strerror());
-      }
-      jcr->cached_attribute = false; 
-   }
-
    if (!mdb->m_allow_transactions) {
       return; 
    }
index 3ed39be5b4a4d2cdd3234ef248da383f8f43ae20..6339155cfd34a90ab60a87328dffadaa7c92ebc9 100644 (file)
@@ -395,7 +395,7 @@ void BDB_SQLITE::bdb_start_transaction(JCR *jcr)
    if (!mdb->m_transaction) { 
       sql_query("BEGIN");                  /* begin transaction */ 
       Dmsg0(400, "Start SQLite transaction\n"); 
-      mdb->m_transaction = true; 
+      mdb->m_transaction = true;
    } 
    bdb_unlock(); 
 }  
@@ -403,15 +403,6 @@ void BDB_SQLITE::bdb_start_transaction(JCR *jcr)
 void BDB_SQLITE::bdb_end_transaction(JCR *jcr) 
 {  
    BDB_SQLITE *mdb = this; 
-   if (jcr && jcr->cached_attribute) { 
-      Dmsg0(400, "Flush last cached attribute.\n"); 
-      if (!bdb_create_attributes_record(jcr, jcr->ar)) { 
-         Jmsg1(jcr, M_FATAL, 0, _("Attribute create error. %s"), jcr->db->bdb_strerror()); 
-      } 
-      jcr->cached_attribute = false; 
-   } 
    if (!mdb->m_allow_transactions) { 
       return; 
    } 
index 5c7dbfb5c149cb0bf7fada11ccd850e14a253020..f80ea78d4a053232884b1d4bf820773e60f23c2a 100644 (file)
@@ -631,7 +631,8 @@ bool do_backup(JCR *jcr)
 
    /* Pickup Job termination data */
    stat = wait_for_job_termination(jcr);
-   db_write_batch_file_records(jcr);    /* used by bulk batch file insert */
+
+   flush_file_records(jcr);     /* cached attribute + batch insert */
 
    if (jcr->HasBase) {
       db_commit_base_file_attributes_record(jcr, jcr->db);
index 4278f4b09bee9d171ce479babb80b8ce78347eb0..fbe35ef009a2034dfab073615d60bfe397cf0b06 100644 (file)
@@ -1919,3 +1919,16 @@ bool run_console_command(JCR *jcr, const char *cmd)
    free_jcr(ljcr);
    return ok;
 }
+
+bool flush_file_records(JCR *jcr)
+{
+   if (jcr->cached_attribute) {
+      Dmsg0(400, "Flush last cached attribute.\n");
+      if (!db_create_attributes_record(jcr, jcr->db, jcr->ar)) {
+         Jmsg1(jcr, M_FATAL, 0, _("Attribute create error. %s"), jcr->db->bdb_strerror());
+      }
+      jcr->cached_attribute = false;
+   }
+
+   return db_write_batch_file_records(jcr);    /* used by bulk batch file insert */
+}
index b54dcab65eb11fed10418f951e5c39ba08721455..371ab1bf9d00785574415e5b3f48529801956ef2 100644 (file)
@@ -568,7 +568,8 @@ bool do_mac(JCR *jcr)
    wjcr->setJobStatus(wjcr->SDJobStatus);
    wait_for_storage_daemon_termination(jcr);
    jcr->setJobStatus(jcr->SDJobStatus);
-   db_write_batch_file_records(wjcr);    /* used by bulk batch file insert */
+
+   flush_file_records(wjcr);     /* cached attribute + batch insert */
 
    ok = jcr->is_JobStatus(JS_Terminated) && wjcr->is_JobStatus(JS_Terminated);
 
index 4140046154854fd04b4794ea750a6c0de39df82b..79640c2698346d60cd3ec720b98b0e9bfe1ed23b 100644 (file)
@@ -152,6 +152,7 @@ extern void cancel_storage_daemon_job(JCR *jcr);
 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);
 
 /* jobq.c */
 extern bool inc_read_store(JCR *jcr);
index 7ee31733547cfcf5fce6d21fd3779f20d3fb0307..7c46222d66a74d1e1c65ca4291f0c03613b05cd3 100644 (file)
@@ -337,7 +337,8 @@ _("This Job is not an Accurate backup so is not equivalent to a Full backup.\n")
    /* Note, the SD stores in jcr->JobFiles/ReadBytes/JobBytes/JobErrors */
    wait_for_storage_daemon_termination(jcr);
    jcr->setJobStatus(jcr->SDJobStatus);
-   db_write_batch_file_records(jcr);    /* used by bulk batch file insert */
+   flush_file_records(jcr);     /* cached attribute + batch insert */
+
    if (jcr->JobStatus != JS_Terminated) {
       return false;
    }
index c0486ee931c5905c2fa27bc9759dbc3b0a5ca95c..1173388f7dab9caf8434f175e53f22c701e52a4b 100644 (file)
@@ -407,7 +407,7 @@ bool do_verify(JCR *jcr)
       jcr->SDJobStatus = JS_Terminated;
       get_attributes_and_put_in_catalog(jcr);
       db_end_transaction(jcr, jcr->db);   /* terminate any open transaction */
-      db_write_batch_file_records(jcr);
+      flush_file_records(jcr);     /* cached attribute + batch insert */
       break;
 
    case L_VERIFY_DATA: