From: Eric Bollengier Date: Thu, 13 Dec 2018 10:56:31 +0000 (+0100) Subject: Fix #4433 about 'UPDATE File SET MD5='...' WHERE FileId=0' error when using SpoolAttr... X-Git-Tag: Release-9.4.3~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bac7d23adf91da55cb9122ff21c888910aaf483;p=thirdparty%2Fbacula.git Fix #4433 about 'UPDATE File SET MD5='...' WHERE FileId=0' error when using SpoolAttributes=no --- diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index d3a0c46f4..ca9c60952 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -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; - } } /* diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index a611ffa3d..46d296176 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -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; } diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index 3ed39be5b..6339155cf 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -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; } diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 5c7dbfb5c..f80ea78d4 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -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); diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 4278f4b09..fbe35ef00 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -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 */ +} diff --git a/bacula/src/dird/mac.c b/bacula/src/dird/mac.c index b54dcab65..371ab1bf9 100644 --- a/bacula/src/dird/mac.c +++ b/bacula/src/dird/mac.c @@ -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); diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 414004615..79640c269 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -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); diff --git a/bacula/src/dird/vbackup.c b/bacula/src/dird/vbackup.c index 7ee317335..7c46222d6 100644 --- a/bacula/src/dird/vbackup.c +++ b/bacula/src/dird/vbackup.c @@ -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; } diff --git a/bacula/src/dird/verify.c b/bacula/src/dird/verify.c index c0486ee93..1173388f7 100644 --- a/bacula/src/dird/verify.c +++ b/bacula/src/dird/verify.c @@ -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: