From 61ee396f4404e17a48cd00a3ec1ad36c9d45f2af Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Thu, 3 Sep 2009 16:33:55 +0000 Subject: [PATCH] -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 --- perl-xCAT/xCAT/Table.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index c884a3679..b4d1b8948 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -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:/) {