Skip to content

Commit

Permalink
catalog: Lets pass on try_reconnect and exit_on_fatal
Browse files Browse the repository at this point in the history
When implementing the new try_reconnect and exit_on_fatal flags to
workaround the fact that we handle a database shutdown badly I seem to
have forgotten to pass the arguments in all needed calls. This patch
fixes that.

From now on also most of the flags to instantiate a new connection to
the database need an explicit setting so we catch these kind of problems
in the future much easier. There is only one default left as last
argument to the function to get a new pooled or unpooled connection
which says if it should return a private database connection or not.
  • Loading branch information
Marco van Wieringen committed May 14, 2016
1 parent dbddf5b commit cb3d0b3
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 48 deletions.
9 changes: 4 additions & 5 deletions src/cats/bdb_priv.h
Expand Up @@ -2,6 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2011-2011 Free Software Foundation Europe e.V.
Copyright (C) 2013-2016 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -51,10 +52,8 @@ class CATS_IMP_EXP B_DB_PRIV: public B_DB {
int m_field_number; /* Field number from sql_field_seek */
SQL_ROW m_rows; /* Defined rows */
SQL_FIELD *m_fields; /* Defined fields */
bool m_allow_transactions; /* Transactions allowed */
bool m_transaction; /* Transaction started */
bool m_try_reconnect; /* Try reconnecting DB connection */
bool m_exit_on_fatal; /* Exit on FATAL DB errors */
bool m_allow_transactions; /* Transactions allowed ? */
bool m_transaction; /* Transaction started ? */

public:
/* methods */
Expand All @@ -66,7 +65,7 @@ class CATS_IMP_EXP B_DB_PRIV: public B_DB {
int sql_num_fields(void) { return m_num_fields; };
virtual void sql_free_result(void) = 0;
virtual SQL_ROW sql_fetch_row(void) = 0;
virtual bool sql_query(const char *query, int flags=0) = 0;
virtual bool sql_query(const char *query, int flags = 0) = 0;
virtual const char *sql_strerror(void) = 0;
virtual void sql_data_seek(int row) = 0;
virtual int sql_affected_rows(void) = 0;
Expand Down
8 changes: 5 additions & 3 deletions src/cats/cats.c
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2011-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2013 Bareos GmbH & Co. KG
Copyright (C) 2013-2016 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -78,10 +78,12 @@ B_DB *B_DB::db_clone_database_connection(JCR *jcr,
*/
if (get_pooled_connection) {
return db_sql_get_pooled_connection(jcr, m_db_driver, m_db_name, m_db_user, m_db_password,
m_db_address, m_db_port, m_db_socket, true, m_disabled_batch_insert, need_private);
m_db_address, m_db_port, m_db_socket, mult_db_connections, m_disabled_batch_insert,
m_try_reconnect, m_exit_on_fatal, need_private);
} else {
return db_sql_get_non_pooled_connection(jcr, m_db_driver, m_db_name, m_db_user, m_db_password,
m_db_address, m_db_port, m_db_socket, true, m_disabled_batch_insert, need_private);
m_db_address, m_db_port, m_db_socket, mult_db_connections, m_disabled_batch_insert,
m_try_reconnect, m_exit_on_fatal, need_private);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/cats/cats.h
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2013 Bareos GmbH & Co. KG
Copyright (C) 2013-2016 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -512,6 +512,8 @@ class CATS_IMP_EXP B_DB: public SMARTALLOC {
int m_ref_count; /* reference count */
bool m_connected; /* connection made to db */
bool m_have_batch_insert; /* have batch insert support ? */
bool m_try_reconnect; /* Try reconnecting DB connection ? */
bool m_exit_on_fatal; /* Exit on FATAL DB errors ? */
char *m_db_driver; /* database driver */
char *m_db_driverdir; /* database driver dir */
char *m_db_name; /* database name */
Expand Down
2 changes: 1 addition & 1 deletion src/cats/cats_backends.c
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2014 Bareos GmbH & Co. KG
Copyright (C) 2013-2016 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down
2 changes: 1 addition & 1 deletion src/cats/cats_backends.h
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2013 Bareos GmbH & Co. KG
Copyright (C) 2013-2016 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down
24 changes: 12 additions & 12 deletions src/cats/protos.h
Expand Up @@ -144,7 +144,7 @@ bool db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query,
bool verbose);
bool db_list_sql_query(JCR *jcr, B_DB *mdb, const char *query,
OUTPUT_FORMATTER *sendit, e_list_type type,
const char *description, bool verbose=false);
const char *description, bool verbose = false);
void db_list_client_records(JCR *jcr, B_DB *mdb, char *clientname,
OUTPUT_FORMATTER *sendit, e_list_type type);
void db_list_copies_records(JCR *jcr, B_DB *mdb, const char *range, char *jobids,
Expand Down Expand Up @@ -178,11 +178,11 @@ B_DB *db_sql_get_non_pooled_connection(JCR *jcr,
const char *db_address,
int db_port,
const char *db_socket,
bool mult_db_connections = false,
bool disable_batch_insert = false,
bool need_private = false,
bool try_reconnect = false,
bool exit_on_fatal = false);
bool mult_db_connections,
bool disable_batch_insert,
bool try_reconnect,
bool exit_on_fatal,
bool need_private = false);
B_DB *db_sql_get_pooled_connection(JCR *jcr,
const char *db_drivername,
const char *db_name,
Expand All @@ -191,12 +191,12 @@ B_DB *db_sql_get_pooled_connection(JCR *jcr,
const char *db_address,
int db_port,
const char *db_socket,
bool mult_db_connections = false,
bool disable_batch_insert = false,
bool need_private = false,
bool try_reconnect = false,
bool exit_on_fatal = false);
void db_sql_close_pooled_connection(JCR *jcr, B_DB *mdb, bool abort=false);
bool mult_db_connections,
bool disable_batch_insert,
bool try_reconnect,
bool exit_on_fatal,
bool need_private = false);
void db_sql_close_pooled_connection(JCR *jcr, B_DB *mdb, bool abort = false);

/* sql_update.c */
bool db_update_job_start_record(JCR *jcr, B_DB *db, JOB_DBR *jr);
Expand Down
34 changes: 17 additions & 17 deletions src/cats/sql_pooling.c
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2010-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2013 Bareos GmbH & Co. KG
Copyright (C) 2013-2016 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -49,9 +49,9 @@ B_DB *db_sql_get_non_pooled_connection(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
{
B_DB *mdb;

Expand All @@ -72,9 +72,9 @@ B_DB *db_sql_get_non_pooled_connection(JCR *jcr,
db_socket,
mult_db_connections,
disable_batch_insert,
need_private,
try_reconnect,
exit_on_fatal);
exit_on_fatal,
need_private);
if (mdb == NULL) {
return NULL;
}
Expand Down Expand Up @@ -543,9 +543,9 @@ B_DB *db_sql_get_pooled_connection(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
{
int cnt = 0;
SQL_POOL_DESCRIPTOR *wanted_pool;
Expand Down Expand Up @@ -576,9 +576,9 @@ B_DB *db_sql_get_pooled_connection(JCR *jcr,
db_socket,
mult_db_connections,
disable_batch_insert,
need_private,
try_reconnect,
exit_on_fatal);
exit_on_fatal,
need_private);
}

P(mutex);
Expand Down Expand Up @@ -637,9 +637,9 @@ B_DB *db_sql_get_pooled_connection(JCR *jcr,
db_socket,
mult_db_connections,
disable_batch_insert,
need_private,
try_reconnect,
exit_on_fatal);
exit_on_fatal,
need_private);
goto bail_out;
}

Expand Down Expand Up @@ -669,9 +669,9 @@ B_DB *db_sql_get_pooled_connection(JCR *jcr,
db_socket,
mult_db_connections,
disable_batch_insert,
need_private,
try_reconnect,
exit_on_fatal);
exit_on_fatal,
need_private);
goto bail_out;
}

Expand Down Expand Up @@ -876,9 +876,9 @@ B_DB *db_sql_get_pooled_connection(JCR *jcr,
const char *db_socket,
bool mult_db_connections,
bool disable_batch_insert,
bool need_private,
bool try_reconnect,
bool exit_on_fatal)
bool exit_on_fatal,
bool need_private)
{
return db_sql_get_non_pooled_connection(jcr,
db_drivername,
Expand All @@ -890,9 +890,9 @@ B_DB *db_sql_get_pooled_connection(JCR *jcr,
db_socket,
mult_db_connections,
disable_batch_insert,
need_private,
try_reconnect,
exit_on_fatal);
exit_on_fatal,
need_private);
}

/*
Expand Down
6 changes: 4 additions & 2 deletions src/dird/dbcheck.c
Expand Up @@ -317,7 +317,7 @@ int main (int argc, char *argv[])
NULL);
if (!db_open_database(NULL, db)) {
Emsg1(M_FATAL, 0, "%s", db_strerror(db));
return 1;
return 1;
}

/*
Expand Down Expand Up @@ -372,7 +372,9 @@ static void print_catalog_details(CATRES *catalog, const char *working_dir)
catalog->db_port,
catalog->db_socket,
catalog->mult_db_connections,
catalog->disable_batch_insert);
catalog->disable_batch_insert,
catalog->try_reconnect,
catalog->exit_on_fatal);
if (db) {
printf("%sdb_type=%s\nworking_dir=%s\n", catalog->display(catalog_details),
db->db_get_type(), working_directory);
Expand Down
5 changes: 4 additions & 1 deletion src/dird/dird.c
Expand Up @@ -1080,7 +1080,10 @@ static bool check_catalog(cat_op mode)
catalog->db_port,
catalog->db_socket,
catalog->mult_db_connections,
catalog->disable_batch_insert);
catalog->disable_batch_insert,
catalog->try_reconnect,
catalog->exit_on_fatal);

if (!db || !db_open_database(NULL, db)) {
Pmsg2(000, _("Could not open Catalog \"%s\", database \"%s\".\n"),
catalog->name(), catalog->db_name);
Expand Down
4 changes: 3 additions & 1 deletion src/dird/job.c
Expand Up @@ -148,7 +148,9 @@ bool setup_job(JCR *jcr, bool suppress_output)
jcr->res.catalog->db_port,
jcr->res.catalog->db_socket,
jcr->res.catalog->mult_db_connections,
jcr->res.catalog->disable_batch_insert);
jcr->res.catalog->disable_batch_insert,
jcr->res.catalog->try_reconnect,
jcr->res.catalog->exit_on_fatal);
if (jcr->db == NULL) {
Jmsg(jcr, M_FATAL, 0, _("Could not open database \"%s\".\n"), jcr->res.catalog->db_name);
goto bail_out;
Expand Down
4 changes: 3 additions & 1 deletion src/dird/stats.c
Expand Up @@ -149,7 +149,9 @@ void *statistics_thread_runner(void *arg)
jcr->res.catalog->db_port,
jcr->res.catalog->db_socket,
jcr->res.catalog->mult_db_connections,
jcr->res.catalog->disable_batch_insert);
jcr->res.catalog->disable_batch_insert,
jcr->res.catalog->try_reconnect,
jcr->res.catalog->exit_on_fatal);
if (jcr->db == NULL) {
Jmsg(jcr, M_FATAL, 0, _("Could not open database \"%s\".\n"), jcr->res.catalog->db_name);
goto bail_out;
Expand Down
2 changes: 2 additions & 0 deletions src/dird/ua_cmds.c
Expand Up @@ -2704,6 +2704,8 @@ bool open_db(UAContext *ua, bool use_private)
ua->catalog->db_socket,
mult_db_conn,
ua->catalog->disable_batch_insert,
ua->catalog->try_reconnect,
ua->catalog->exit_on_fatal,
use_private);
if (ua->db == NULL) {
ua->error_msg(_("Could not open catalog database \"%s\".\n"), ua->catalog->db_name);
Expand Down
7 changes: 4 additions & 3 deletions src/dird/ua_output.c
Expand Up @@ -1157,8 +1157,7 @@ RUNRES *find_next_run(RUNRES *run, JOBRES *job, utime_t &runtime, int ndays)
}

/*
* Fill in the remaining fields of the jcr as if it
* is going to run the job.
* Fill in the remaining fields of the jcr as if it is going to run the job.
*/
bool complete_jcr_for_job(JCR *jcr, JOBRES *job, POOLRES *pool)
{
Expand All @@ -1185,7 +1184,9 @@ bool complete_jcr_for_job(JCR *jcr, JOBRES *job, POOLRES *pool)
jcr->res.catalog->db_port,
jcr->res.catalog->db_socket,
jcr->res.catalog->mult_db_connections,
jcr->res.catalog->disable_batch_insert);
jcr->res.catalog->disable_batch_insert,
jcr->res.catalog->try_reconnect,
jcr->res.catalog->exit_on_fatal);
if (jcr->db == NULL) {
Jmsg(jcr, M_FATAL, 0, _("Could not open database \"%s\".\n"),
jcr->res.catalog->db_name);
Expand Down

0 comments on commit cb3d0b3

Please sign in to comment.