From 2e4dda4e9896641ba48d0a52be97fbc825795d39 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 26 Sep 2007 16:55:31 +0000 Subject: [PATCH] Add retry for opening batch db if it fails. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5657 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/sql_create.c | 22 +++++++++++++++++----- bacula/technotes-2.3 | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 2c8d52c4a2..928bc35796 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -688,10 +688,12 @@ bool db_create_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr) */ bool my_batch_start(JCR *jcr, B_DB *mdb) { - bool ok; + bool ok = false; + int retry = 0; - db_lock(mdb); - ok = db_sql_query(mdb, + while (!ok && retry++ < 10) { + db_lock(mdb); + ok = db_sql_query(mdb, "CREATE TEMPORARY TABLE batch (" "FileIndex integer," "JobId integer," @@ -699,7 +701,11 @@ bool my_batch_start(JCR *jcr, B_DB *mdb) "Name blob," "LStat tinyblob," "MD5 tinyblob)",NULL, NULL); - db_unlock(mdb); + db_unlock(mdb); + if (!ok) { + bmicrosleep(1, 0); + } + } return ok; } @@ -833,12 +839,14 @@ bool db_write_batch_file_records(JCR *jcr) */ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) { + int retry = 0; 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, + while (!jcr->db_batch && retry++ < 10) { + jcr->db_batch = db_init_database(jcr, mdb->db_name, mdb->db_user, mdb->db_password, @@ -846,6 +854,10 @@ bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) mdb->db_port, mdb->db_socket, 1 /* multi_db = true */); + if (!jcr->db_batch) { + bmicrosleep(1, 0); + } + } if (!jcr->db_batch) { Mmsg1(&mdb->errmsg, _("Could not init batch database: \"%s\".\n"), jcr->db->db_name); diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 2cf9febc6d..7d39cbe6ef 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,6 +2,7 @@ General: 26Sep07 +kes Add retry for opening batch db if it fails. kes Suppress extra error messages during batch insert failure. kes Add jcr to timer packets so if killed message can be sent to job. kes Add JobId to all Dmsg() output. -- 2.39.5