This handles some error cases that were not cleanly handled before.
Cc: Roberto Nibali <ratz@xxxxxxxxxxxx>
Signed-off-by: Simon Horman <horms@xxxxxxxxxxxx>
Index: heartbeat/ldirectord/ldirectord.in
===================================================================
--- heartbeat.orig/ldirectord/ldirectord.in 2007-04-24 17:48:43.000000000
+0900
+++ heartbeat/ldirectord/ldirectord.in 2007-04-24 18:11:35.000000000 +0900
@@ -2513,30 +2513,32 @@ sub check_sql
}
$result--;
$sth = $dbh->prepare($query);
+ unless ($sth) {
+ service_set($v, $r, "down");
+ &ld_log("Error preparing statement:" . $dbh->errstr() . "\n");
+ $dbh->disconnect();
+ service_set($v, $r, "down");
+ return 1;
+ }
$rows = $sth->execute;
ld_debug(4, "Database search returned $rows rows");
+ # If the query returns with a number of rows, then it is ok.
+ # * Disallows query of an empty table.
+ # * Only works with select and update statements, however most
+ # people will want to use select statements for health checks.
if ($rows gt 0) {
- # If it returns with a number, it is ok.
- # Disallows query of an empty table.
$result--;
- }
- # If user defined a receive string (number of rows returned), only do
- # the check if the previous fetchall_arrayref succeeded.
- #if (defined $$r{receive} && $result eq 0) {
- # # Receive string specifies an exact number of rows
- # if ($rows ne $$r{receive}) {
- # ld_debug(2,"Service down, receive=$$r{receive}");
- # $result=1;
- # }
- #}
- if ($result == 1) {
- # Should never get here
+ } else {
+ &ld_log("Prior executing statement returned $rows rows: " .
+ "not adding $$r{server}.\n");
service_set($v, $r, "down");
+ $sth->finish();
+ $dbh->disconnect();
return 1;
}
service_set($v, $r, "up");
- $sth->finish;
- $dbh->disconnect;
+ $sth->finish();
+ $dbh->disconnect();
return 0;
}
--
--
Horms
H: http://www.vergenet.net/~horms/
W: http://www.valinux.co.jp/en/
|