From: Eric Bollengier Date: Mon, 21 Dec 2009 10:15:47 +0000 (+0100) Subject: M_ABORT Bacula If batch insert is turned on when we try to open a connection and... X-Git-Tag: Release-7.0.0~2446 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e3e63b1c5fa4f097eb745a36e314a4b1e5d1ffd6;p=bacula%2Fbacula M_ABORT Bacula If batch insert is turned on when we try to open a connection and thread safe is not enabled --- diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index d5cd64d873..994e0e5485 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -98,6 +98,7 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char } } } + db_check_backend_thread_safe(); Dmsg0(100, "db_open first time\n"); mdb = (B_DB *)malloc(sizeof(B_DB)); memset(mdb, 0, sizeof(B_DB)); @@ -272,6 +273,16 @@ db_close_database(JCR *jcr, B_DB *mdb) V(mutex); } +void db_check_backend_thread_safe() +{ +#ifdef HAVE_BATCH_FILE_INSERT + if (!mysql_thread_safe()) { + Emsg0(M_ABORT, 0, _("MySQL client library must be thread-safe " + "when using BatchMode.\n")); + } +#endif +} + /* * This call is needed because the message channel thread * opens a database on behalf of a jcr that was created in diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index 08f5846f95..b5fd981531 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -300,6 +300,16 @@ db_close_database(JCR *jcr, B_DB *mdb) V(mutex); } +void db_check_backend_thread_safe() +{ +#ifdef HAVE_BATCH_FILE_INSERT + if (!PQisthreadsafe()) { + Emsg0(M_ABORT, 0, _("Pg client library must be thread-safe " + "when using BatchMode.\n")); + } +#endif +} + void db_thread_cleanup() { } diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index 4d24db65c3..75753db356 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -61,6 +61,7 @@ int db_list_handler(void *ctx, int num_fields, char **row); void db_thread_cleanup(); void db_debug_print(JCR *jcr, FILE *fp); int db_int_handler(void *ctx, int num_fields, char **row); +void db_check_backend_thread_safe(); /* sql_create.c */ int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index 946a87e8fa..f98539ed38 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -265,6 +265,16 @@ db_close_database(JCR *jcr, B_DB *mdb) V(mutex); } +void db_check_backend_thread_safe() +{ +#ifdef HAVE_BATCH_FILE_INSERT + if (!sqlite3_threadsafe()) { + Emsg0(M_ABORT, 0, _("SQLite3 client library must be thread-safe " + "when using BatchMode.\n")); + } +#endif +} + void db_thread_cleanup() { #ifdef HAVE_SQLITE3 diff --git a/bacula/src/tools/dbcheck.c b/bacula/src/tools/dbcheck.c index 948e9f57fd..b18016777f 100644 --- a/bacula/src/tools/dbcheck.c +++ b/bacula/src/tools/dbcheck.c @@ -120,6 +120,7 @@ static void usage() " -d set debug level to \n" " -dt print a timestamp in debug output\n" " -f fix inconsistencies\n" +" -t test if client library is thread-safe\n" " -v verbose\n" " -? print this message\n\n"); exit(1); @@ -130,6 +131,7 @@ int main (int argc, char *argv[]) int ch; const char *user, *password, *db_name, *dbhost; int dbport = 0; + bool test_thread=false; bool print_catalog=false; char *configfile = NULL; char *catalogname = NULL; @@ -146,7 +148,7 @@ int main (int argc, char *argv[]) memset(&id_list, 0, sizeof(id_list)); memset(&name_list, 0, sizeof(name_list)); - while ((ch = getopt(argc, argv, "bc:C:d:fvB?")) != -1) { + while ((ch = getopt(argc, argv, "bc:C:d:fvBt?")) != -1) { switch (ch) { case 'B': print_catalog = true; /* get catalog information from config */ @@ -182,6 +184,9 @@ int main (int argc, char *argv[]) case 'v': verbose++; break; + case 't': + test_thread=true; + break; case '?': default: @@ -193,6 +198,16 @@ int main (int argc, char *argv[]) OSDependentInit(); + if (test_thread) { + /* When we will load the SQL backend with ldopen, this check would be + * moved after the database initialization. It will need a valid config + * file. + */ + db_check_backend_thread_safe(); + Pmsg0(0, _("OK - DB backend seems to be thread-safe.\n")); + exit(0); + } + if (configfile) { CAT *catalog = NULL; int found = 0;