From: Kern Sibbald Date: Sat, 2 Jun 2007 07:57:46 +0000 (+0000) Subject: kes Do better checking for NULL results returned from PostgreSQL; X-Git-Tag: Release-7.0.0~6179 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6393f736f7b9580926595f88e909d879d4a21120;p=bacula%2Fbacula kes Do better checking for NULL results returned from PostgreSQL; implement retry for failed queries; clear results buffer after failed query. Hopefully this will correct the PostgreSQL failures. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4966 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index 9886faac0a..39b27a6aee 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -437,8 +437,14 @@ void my_postgresql_field_seek(B_DB *mdb, int field) /* * Note, if this routine returns 1 (failure), Bacula expects * that no result has been stored. + * This is where QUERY_DB comes with Postgresql. + * + * Returns: 0 on success + * 1 on failure + * */ -int my_postgresql_query(B_DB *mdb, const char *query) { +int my_postgresql_query(B_DB *mdb, const char *query) +{ Dmsg0(500, "my_postgresql_query started\n"); // We are starting a new query. reset everything. mdb->num_rows = -1; @@ -451,26 +457,42 @@ int my_postgresql_query(B_DB *mdb, const char *query) { } Dmsg1(500, "my_postgresql_query starts with '%s'\n", query); - mdb->result = PQexec(mdb->db, query); + + for (int i=0; i < 10; i++) { + mdb->result = PQexec(mdb->db, query); + if (mdb->result) { + break; + } + bmicrosleep(5, 0); + } + if (!mdb->result) { + goto bail_out; + } + mdb->status = PQresultStatus(mdb->result); if (mdb->status == PGRES_TUPLES_OK || mdb->status == PGRES_COMMAND_OK) { Dmsg1(500, "we have a result\n", query); // how many fields in the set? - mdb->num_fields = (int) PQnfields(mdb->result); + mdb->num_fields = (int)PQnfields(mdb->result); Dmsg1(500, "we have %d fields\n", mdb->num_fields); mdb->num_rows = PQntuples(mdb->result); Dmsg1(500, "we have %d rows\n", mdb->num_rows); - mdb->status = 0; + mdb->status = 0; /* succeed */ } else { - Dmsg1(500, "we failed\n", query); - mdb->status = 1; + goto bail_out; } Dmsg0(500, "my_postgresql_query finishing\n"); + return mdb->status; +bail_out: + Dmsg1(500, "we failed\n", query); + PQclear(mdb->result); + mdb->result = NULL; + mdb->status = 1; /* failed */ return mdb->status; } diff --git a/bacula/src/version.h b/bacula/src/version.h index 3e797e09b6..18a1c472af 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.1.11" -#define BDATE "01 June 2007" -#define LSMDATE "01Jun07" +#define BDATE "02 June 2007" +#define LSMDATE "02Jun07" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" #define BYEAR "2007" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index 6006afbbfa..b7ddb2e06b 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -1,6 +1,10 @@ Technical notes on version 2.1 General: +02Jun07 +kes Do better checking for NULL results returned from PostgreSQL; + implement retry for failed queries; clear results buffer after + failed query. Hopefully this will correct the PostgreSQL failures. 01Jun07 kes Implement algorithm to handle only one appendable volume with Prefer Mounted Volumes = no.