From: Kern Sibbald Date: Wed, 26 Sep 2007 17:25:03 +0000 (+0000) Subject: Add retry for SQLite opening db if it fails. X-Git-Tag: Release-3.0.0~2448 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c08d2a5a7232bc7ebf1f976a483bc2adcff0c0aa;p=bacula%2Fbacula Add retry for SQLite opening db if it fails. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5658 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index 0fd4d0d7e2..9b0ede7ac9 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -148,6 +148,7 @@ db_open_database(JCR *jcr, B_DB *mdb) int len; struct stat statbuf; int errstat; + int retry = 0; P(mutex); if (mdb->connected) { @@ -178,28 +179,28 @@ db_open_database(JCR *jcr, B_DB *mdb) return 0; } + for (mdb->db=NULL; !mdb->db && retry++ < 10; ) { #ifdef HAVE_SQLITE3 - int stat = sqlite3_open(db_name, &mdb->db); - if (stat != SQLITE_OK) { - mdb->sqlite_errmsg = (char *)sqlite3_errmsg(mdb->db); - sqlite3_close(mdb->db); - mdb->db = NULL; - } else { - mdb->sqlite_errmsg = NULL; - } -#ifdef SQLITE3_INIT_QUERY - db_sql_query(mdb, SQLITE3_INIT_QUERY, NULL, NULL); -#endif - + int stat = sqlite3_open(db_name, &mdb->db); + if (stat != SQLITE_OK) { + mdb->sqlite_errmsg = (char *)sqlite3_errmsg(mdb->db); + sqlite3_close(mdb->db); + mdb->db = NULL; + } else { + mdb->sqlite_errmsg = NULL; + } #else - mdb->db = sqlite_open( - db_name, /* database name */ - 644, /* mode */ - &mdb->sqlite_errmsg); /* error message */ + mdb->db = sqlite_open( + db_name, /* database name */ + 644, /* mode */ + &mdb->sqlite_errmsg); /* error message */ #endif - Dmsg0(300, "sqlite_open\n"); - + Dmsg0(300, "sqlite_open\n"); + if (!mdb->db) { + bmicrosleep(1, 0); + } + } if (mdb->db == NULL) { Mmsg2(&mdb->errmsg, _("Unable to open Database=%s. ERR=%s\n"), db_name, mdb->sqlite_errmsg ? mdb->sqlite_errmsg : _("unknown")); @@ -209,6 +210,11 @@ db_open_database(JCR *jcr, B_DB *mdb) } mdb->connected = true; free(db_name); + +#if defined(HAVE_SQLITE3) && defined(SQLITE3_INIT_QUERY) + db_sql_query(mdb, SQLITE3_INIT_QUERY, NULL, NULL); +#endif + if (!check_tables_version(jcr, mdb)) { V(mutex); return 0; diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 7d39cbe6ef..e10e081db1 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,7 +2,7 @@ General: 26Sep07 -kes Add retry for opening batch db if it fails. +kes Add retry for SQLite opening 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.