From 8647dd3013c78226f7ac07b47eba58cdab42d297 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 5 Nov 2009 15:11:30 +0100 Subject: [PATCH] Display a message if catalog max_connections setting is too low --- bacula/src/cats/cats.h | 1 + bacula/src/cats/sql.c | 47 +++++++++++++++++++++++++++++++++++++- bacula/src/cats/sql_cmds.c | 23 +++++++++++++++++++ bacula/src/cats/sql_cmds.h | 2 ++ bacula/src/dird/dird.c | 6 +++++ 5 files changed, 78 insertions(+), 1 deletion(-) diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index 1879050875..2220e3647f 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -1080,6 +1080,7 @@ void list_result(JCR *jcr, B_DB *mdb, DB_LIST_HANDLER *send, void *ctx, e_list_t void list_dashes(B_DB *mdb, DB_LIST_HANDLER *send, void *ctx); int get_sql_record_max(JCR *jcr, B_DB *mdb); bool check_tables_version(JCR *jcr, B_DB *mdb); +bool db_check_max_connections(JCR *jcr, B_DB *mdb, uint32_t nb); void _db_unlock(const char *file, int line, B_DB *mdb); void _db_lock(const char *file, int line, B_DB *mdb); const char *db_get_type(void); diff --git a/bacula/src/cats/sql.c b/bacula/src/cats/sql.c index 72ab05b512..bcc8b519d0 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -108,7 +108,6 @@ dbid_list::~dbid_list() free(DBId); } - /* * Called here to retrieve an integer from the database */ @@ -160,6 +159,52 @@ int db_list_handler(void *ctx, int num_fields, char **row) return 0; } + +/* + * Called here to retrieve an integer from the database + */ +static int db_max_connections_handler(void *ctx, int num_fields, char **row) +{ + uint32_t *val = (uint32_t *)ctx; + uint32_t index = sql_get_max_connections_index[db_type]; + if (row[index]) { + *val = str_to_int64(row[index]); + } else { + Dmsg0(800, "int_handler finds zero\n"); + *val = 0; + } + return 0; +} + +/* + * Check catalog max_connections setting + */ +bool db_check_max_connections(JCR *jcr, B_DB *mdb, uint32_t max_concurrent_jobs) +{ + uint32_t max_conn=0; + int ret=true; + + /* Without Batch insert, no need to verify max_connections */ +#ifndef HAVE_BATCH_FILE_INSERT + return ret; +#endif + + /* Check max_connections setting */ + if (!db_sql_query(mdb, sql_get_max_connections[db_type], db_max_connections_handler, &max_conn)) { + Jmsg(jcr, M_ERROR, 0, "Can't verify max_connections settings %s", mdb->errmsg); + return ret; + } + if (max_conn && max_concurrent_jobs && max_concurrent_jobs > max_conn) { + Mmsg(mdb->errmsg, + _("On db_name=%s, %s max_connections=%d is lower than Director MaxConcurentJobs=%d\n"), + mdb->db_name, db_get_type(), max_conn, max_concurrent_jobs); + Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg); + ret = false; + } + + return ret; +} + /* NOTE!!! The following routines expect that the * calling subroutine sets and clears the mutex */ diff --git a/bacula/src/cats/sql_cmds.c b/bacula/src/cats/sql_cmds.c index 8b28422e0a..1ac1721fd2 100644 --- a/bacula/src/cats/sql_cmds.c +++ b/bacula/src/cats/sql_cmds.c @@ -637,3 +637,26 @@ const char *uar_jobid_fileindex_from_dir[4] = { "AND Path.PathId=File.Pathid " "AND Filename.FilenameId=File.FilenameId " "GROUP BY File.FileIndex "}; + +const char *sql_get_max_connections[4] = { + /* Mysql */ + "SHOW VARIABLES LIKE 'max_connections'", + /* Postgresql */ + "SHOW max_connections", + /* SQLite */ + "SELECT 0", + /* SQLite3 */ + "SELECT 0" +}; + +/* Row number of the max_connections setting */ +const uint32_t sql_get_max_connections_index[4] = { + /* Mysql */ + 1, + /* Postgresql */ + 0, + /* SQLite */ + 0, + /* SQLite3 */ + 0 +}; diff --git a/bacula/src/cats/sql_cmds.h b/bacula/src/cats/sql_cmds.h index 7b967572e8..396b6812e4 100644 --- a/bacula/src/cats/sql_cmds.h +++ b/bacula/src/cats/sql_cmds.h @@ -78,3 +78,5 @@ extern const char CATS_IMP_EXP *uar_file[4]; extern const char CATS_IMP_EXP *uar_create_temp[4]; extern const char CATS_IMP_EXP *uar_create_temp1[4]; extern const char CATS_IMP_EXP *uar_jobid_fileindex_from_dir[4]; +extern const char CATS_IMP_EXP *sql_get_max_connections[4]; +extern const uint32_t CATS_IMP_EXP sql_get_max_connections_index[4]; diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index a431721461..58b96f1b62 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -958,6 +958,12 @@ static bool check_catalog(cat_op mode) OK = false; continue; } + + /* Display a message if the db max_connections is too low */ + if (!db_check_max_connections(NULL, db, director->MaxConcurrentJobs+1)) { + Pmsg1(000, "Warning, settings problem for Catalog=%s\n", catalog->name()); + Pmsg1(000, "%s", db_strerror(db)); + } /* we are in testing mode, so don't touch anything in the catalog */ if (mode == CHECK_CONNECTION) { -- 2.39.5