-Detect dead database handles and recover (mysql haandles expire in 8 hours by default, for example, see wait_timeout to test with mysql)

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4095 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2009-09-03 16:33:55 +00:00
parent a0c32e7136
commit 61ee396f44

View File

@ -185,6 +185,18 @@ sub handle_dbc_request {
my $tablename = $request->{tablename};
my @args = @{$request->{args}};
my $autocommit = $request->{autocommit};
my $dbindex;
foreach $dbindex (keys %{$::XCAT_DBHS}) {
unless ($::XCAT_DBHS->{$dbindex}->ping) {
my @afflictedobjs = @{$::XCAT_DBOBJSFORHANDLE->{$::XCAT_DBHS->{$dbindex}}};
my $oldhandle = $::XCAT_DBHS->{$dbindex};
$::XCAT_DBHS->{$dbindex} = $::XCAT_DBHS->{$dbindex}->clone();
foreach (@afflictedobjs) {
$$_->{dbh} = $::XCAT_DBHS->{$dbindex};
}
$oldhandle->disconnect();
}
}
if ($functionname eq 'new') {
unless ($opentables{$tablename}->{$autocommit}) {
shift @args; #Strip repeat class stuff
@ -510,6 +522,11 @@ sub new
umask $oldumask;
$self->{dbh} = $::XCAT_DBHS->{$self->{connstring},$self->{dbuser},$self->{dbpass},$self->{autocommit}};
#Store the Table object reference as afflicted by changes to the DBH
#This for now is ok, as either we aren't in DB worker mode, in which case this structure would be short lived...
#or we are in db worker mode, in which case Table objects live indefinitely
#TODO: be able to reap these objects sanely, just in case
push @{$::XCAT_DBOBJSFORHANDLE->{$::XCAT_DBHS->{$self->{connstring},$self->{dbuser},$self->{dbpass},$self->{autocommit}}}},\$self;
#DBI->connect($self->{connstring}, $self->{dbuser}, $self->{dbpass}, {AutoCommit => $autocommit});
if ($xcatcfg =~ /^SQLite:/)
{