From f082fecb84b2fc645c2fa1b6967dd383c5d2d2b3 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Sun, 7 Mar 2010 11:56:49 +0100 Subject: [PATCH] Uses a dedicated connection when running bvfs_update command --- bacula/src/dird/protos.h | 1 + bacula/src/dird/ua.h | 1 + bacula/src/dird/ua_cmds.c | 26 +++++++++++++++++++++++++- bacula/src/dird/ua_dotcmds.c | 5 +++-- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 9f84950337..2055b8cb72 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -191,6 +191,7 @@ bool acl_access_ok(UAContext *ua, int acl, const char *item, int len); bool do_a_command(UAContext *ua); bool do_a_dot_command(UAContext *ua); int qmessagescmd(UAContext *ua, const char *cmd); +bool open_new_client_db(UAContext *ua); bool open_client_db(UAContext *ua); bool open_db(UAContext *ua); void close_db(UAContext *ua); diff --git a/bacula/src/dird/ua.h b/bacula/src/dird/ua.h index 522ac87a7b..bdd67addce 100644 --- a/bacula/src/dird/ua.h +++ b/bacula/src/dird/ua.h @@ -53,6 +53,7 @@ public: int max_prompts; /* max size of list */ int num_prompts; /* current number in list */ int api; /* For programs want an API */ + bool force_mult_db_connections; /* overwrite cat.mult_db_connections */ bool auto_display_messages; /* if set, display messages */ bool user_notified_msg_pending; /* set when user notified */ bool automount; /* if set, mount after label */ diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 829382f54d..37d0d9e439 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -1955,6 +1955,22 @@ static int version_cmd(UAContext *ua, const char *cmd) } #endif +/* + * This call uses open_client_db() and force a + * new dedicated connection to the catalog + */ +bool open_new_client_db(UAContext *ua) +{ + bool ret; + + /* Force a new dedicated connection */ + close_db(ua); + ua->force_mult_db_connections = true; + ret = open_client_db(ua); + ua->force_mult_db_connections = false; + return ret; +} + /* * This call explicitly checks for a catalog=xxx and * if given, opens that catalog. It also checks for @@ -2040,6 +2056,8 @@ bool open_client_db(UAContext *ua) */ bool open_db(UAContext *ua) { + bool mult_db_conn; + if (ua->db) { return true; } @@ -2051,6 +2069,12 @@ bool open_db(UAContext *ua) } } + /* Some modules like bvfs need their own catalog connection */ + mult_db_conn = ua->catalog->mult_db_connections; + if (ua->force_mult_db_connections) { + mult_db_conn = true; + } + ua->jcr->catalog = ua->catalog; Dmsg0(100, "UA Open database\n"); @@ -2058,7 +2082,7 @@ bool open_db(UAContext *ua) ua->catalog->db_user, ua->catalog->db_password, ua->catalog->db_address, ua->catalog->db_port, ua->catalog->db_socket, - ua->catalog->mult_db_connections); + mult_db_conn); if (!ua->db || !db_open_database(ua->jcr, ua->db)) { ua->error_msg(_("Could not open catalog database \"%s\".\n"), ua->catalog->db_name); diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index 4bc9c5c73b..1c42caf0cf 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -165,8 +165,7 @@ bool do_a_dot_command(UAContext *ua) static bool dot_bvfs_update(UAContext *ua, const char *cmd) { - - if (!open_client_db(ua)) { + if (!open_new_client_db(ua)) { return 1; } @@ -179,6 +178,8 @@ static bool dot_bvfs_update(UAContext *ua, const char *cmd) /* update cache for all jobids */ bvfs_update_cache(ua->jcr, ua->db); } + + close_db(ua); return true; } -- 2.39.5