- scheduler: FCGI: use mysql_ping() to check that DB connection

is still alive before handling a request.  If not, try to reconnect.
    This will hopefully make things work better if MySQL goes down and up
    when using FCGI.

svn path=/trunk/boinc/; revision=16112
This commit is contained in:
David Anderson 2008-10-02 19:03:52 +00:00
parent 466bb2a0e8
commit 59184caaa9
4 changed files with 33 additions and 8 deletions

View File

@ -7949,3 +7949,14 @@ Rom 2 Oct 2008
cURL/
<Various Files>
David 2 Oct 2008
- scheduler: FCGI: use mysql_ping() to check that DB connection
is still alive before handling a request. If not, try to reconnect.
This will hopefully make things work better if MySQL goes down and up
when using FCGI.
db/
db_base.cpp,h
sched/
main.cpp

View File

@ -125,6 +125,12 @@ int DB_CONN::rollback_transaction() {
return do_query("ROLLBACK");
}
int DB_CONN::ping() {
int retval = mysql_ping(mysql);
if (retval) return ERR_DB_CANT_CONNECT;
return 0;
}
DB_BASE::DB_BASE(const char *tn, DB_CONN* p) : db(p), table_name(tn) {
}

View File

@ -75,11 +75,12 @@ public:
int insert_id();
void print_error(const char*);
const char* error_string();
MYSQL* mysql;
int ping();
int start_transaction();
int rollback_transaction();
int commit_transaction();
MYSQL* mysql;
};
// Base for derived classes that can access the DB

View File

@ -167,15 +167,22 @@ static void send_message(const char* msg, int delay) {
int open_database() {
int retval;
if (db_opened) return 0;
if (db_opened) {
retval = boinc_db.ping();
if (retval) {
log_messages.printf(MSG_CRITICAL,
"lost connection to database - trying to reconnect\n"
);
} else {
return 0;
}
}
retval = boinc_db.open(
config.db_name, config.db_host, config.db_user, config.db_passwd
);
if (retval) {
log_messages.printf(MSG_CRITICAL,
"can't open database\n"
);
log_messages.printf(MSG_CRITICAL, "can't open database\n");
return retval;
}
db_opened = true;
@ -450,7 +457,7 @@ int main(int argc, char** argv) {
#ifndef _USING_FCGI_
fout = fopen(req_path, "w");
#else
fout = FCGI::fopen(req_path,"w");
fout = FCGI::fopen(req_path,"w");
#endif
if (!fout) {
log_messages.printf(MSG_CRITICAL,
@ -471,7 +478,7 @@ int main(int argc, char** argv) {
#ifndef _USING_FCGI_
fin = fopen(req_path, "r");
#else
fin = FCGI::fopen(req_path,"r");
fin = FCGI::fopen(req_path,"r");
#endif
if (!fin) {
log_messages.printf(MSG_CRITICAL,