From c7868bf082cd1abc6850ca746af1645715017d7f Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 23 Jan 2008 15:52:27 +0000 Subject: [PATCH] -Remove error-inducing lines from templates (errors were in commented out template portions, so no functional impact). -Revamp Table.pm to share database handles and have handles persist across object instances, avoiding numerous calls to connect in certain programmer use cases. -Modify xfork to use the aforementioned structure rather than the generic structures which are warned as being read-only -Remove probably deprecated interface field as a key in mac table git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@317 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT-2.0/xCAT/Schema.pm | 2 +- perl-xCAT-2.0/xCAT/Table.pm | 26 ++++++++++++------- perl-xCAT-2.0/xCAT/Utils.pm | 14 ++++------ .../share/xcat/install/centos/compute.tmpl | 1 - .../share/xcat/install/fedora/compute.tmpl | 1 - .../share/xcat/install/rh/compute.tmpl | 1 - 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/perl-xCAT-2.0/xCAT/Schema.pm b/perl-xCAT-2.0/xCAT/Schema.pm index 5d957fe5a..fd7a70877 100644 --- a/perl-xCAT-2.0/xCAT/Schema.pm +++ b/perl-xCAT-2.0/xCAT/Schema.pm @@ -56,7 +56,7 @@ package xCAT::Schema; }, mac => { cols => [qw(node interface mac comments disable)], - keys => [qw(node interface)], + keys => [qw(node)], }, chain => { cols => [qw(node currstate currchain chain ondiscover comments disable)], diff --git a/perl-xCAT-2.0/xCAT/Table.pm b/perl-xCAT-2.0/xCAT/Table.pm index ca860c787..745c8ba63 100644 --- a/perl-xCAT-2.0/xCAT/Table.pm +++ b/perl-xCAT-2.0/xCAT/Table.pm @@ -159,16 +159,16 @@ sub new $self->{colnames} = \@{$self->{schema}->{cols}}; my %otherargs = @_; my $create = $otherargs{'-create'}; #(scalar(@_) == 1 ? shift : 0); - my $autocommit = $otherargs{'-autocommit'}; + $self->{autocommit} = $otherargs{'-autocommit'}; - unless (defined($autocommit)) + unless (defined($self->{autocommit})) { - $autocommit = 1; + $self->{autocommit} = 1; } my $class = ref($proto) || $proto; - my $dbuser=""; - my $dbpass=""; + $self->{dbuser}=""; + $self->{dbpass}=""; my $xcatcfg = (defined $ENV{'XCATCFG'} ? $ENV{'XCATCFG'} : ''); if ($xcatcfg =~ /^$/) @@ -210,13 +210,18 @@ sub new } else #Generic DBI { - ($self->{connstring},$dbuser,$dbpass) = split(/\|/,$xcatcfg); + ($self->{connstring},$self->{dbuser},$self->{dbpass}) = split(/\|/,$xcatcfg); $self->{connstring} =~ s/^dbi://; $self->{connstring} =~ s/^/dbi:/; #return undef; } - $self->{dbh} = - DBI->connect($self->{connstring}, $dbuser, $dbpass, {AutoCommit => $autocommit}); + unless ($::XCAT_DBHS->{$self->{connstring},$self->{dbuser},$self->{dbpass},$self->{autocommit}}) { #= $self->{tabname}; + $::XCAT_DBHS->{$self->{connstring},$self->{dbuser},$self->{dbpass},$self->{autocommit}} = + DBI->connect($self->{connstring}, $self->{dbuser}, $self->{dbpass}, {AutoCommit => $self->{autocommit}}); + } + + $self->{dbh} = $::XCAT_DBHS->{$self->{connstring},$self->{dbuser},$self->{dbpass},$self->{autocommit}}; + #DBI->connect($self->{connstring}, $self->{dbuser}, $self->{dbpass}, {AutoCommit => $autocommit}); if ($xcatcfg =~ /^SQLite:/) { my $dbexistq = @@ -1570,8 +1575,8 @@ sub getTable sub close { my $self = shift; - if ($self->{dbh}) { $self->{dbh}->disconnect(); } - undef $self->{dbh}; + #if ($self->{dbh}) { $self->{dbh}->disconnect(); } + #undef $self->{dbh}; if ($self->{tabname} eq 'nodelist') { undef $self->{nodelist}; } else { @@ -1632,6 +1637,7 @@ sub open sub DESTROY { my $self = shift; + $self->{dbh} = ''; undef $self->{dbh}; #if ($self->{dbh}) { $self->{dbh}->disconnect(); undef $self->{dbh};} undef $self->{nodelist}; #Could be circular diff --git a/perl-xCAT-2.0/xCAT/Utils.pm b/perl-xCAT-2.0/xCAT/Utils.pm index 3676f8cd9..3ae4324e6 100644 --- a/perl-xCAT-2.0/xCAT/Utils.pm +++ b/perl-xCAT-2.0/xCAT/Utils.pm @@ -110,15 +110,11 @@ sub xfork { return $rc; } unless ($rc) { - my %drivers = DBI->installed_drivers; - foreach my $drh (values %drivers) { - foreach (@{$drh->{ChildHandles}}) { - $_->{InactiveDestroy} = 1; - } - foreach (@{$drh->{ChildHandles}}) { - undef $_; - } - } + #my %drivers = DBI->installed_drivers; + foreach (values %{$::XCAT_DBHS}) { #@{$drh->{ChildHandles}}) { + $_->{InactiveDestroy} = 1; + undef $_; + } } return $rc; } diff --git a/xCAT-server-2.0/share/xcat/install/centos/compute.tmpl b/xCAT-server-2.0/share/xcat/install/centos/compute.tmpl index 17fc262c9..f0a39b8e2 100644 --- a/xCAT-server-2.0/share/xcat/install/centos/compute.tmpl +++ b/xCAT-server-2.0/share/xcat/install/centos/compute.tmpl @@ -124,7 +124,6 @@ skipx #rootpw --iscrypted XaLGAVe1C41x2 #rootpw XaLGAVe1C41x2 --iscrypted rootpw --iscrypted #CRYPT:passwd:key=system,username=root:password# -#rootpw --iscrypted #COMMAND:perl -e 'print crypt("#TABLE:passwd.tab:rootpw:1#","Xa") . "\n";'p# # # NIS setup: auth --enablenis --nisdomain sensenet diff --git a/xCAT-server-2.0/share/xcat/install/fedora/compute.tmpl b/xCAT-server-2.0/share/xcat/install/fedora/compute.tmpl index da3de7918..84a7ba73d 100644 --- a/xCAT-server-2.0/share/xcat/install/fedora/compute.tmpl +++ b/xCAT-server-2.0/share/xcat/install/fedora/compute.tmpl @@ -125,7 +125,6 @@ skipx #rootpw --iscrypted XaLGAVe1C41x2 #rootpw XaLGAVe1C41x2 --iscrypted rootpw --iscrypted #CRYPT:passwd:key=system,username=root:password# -#rootpw --iscrypted #COMMAND:perl -e 'print crypt("#TABLE:passwd.tab:rootpw:1#","Xa") . "\n";'p# # # NIS setup: auth --enablenis --nisdomain sensenet diff --git a/xCAT-server-2.0/share/xcat/install/rh/compute.tmpl b/xCAT-server-2.0/share/xcat/install/rh/compute.tmpl index e967eb2f6..a1bbd17ac 100644 --- a/xCAT-server-2.0/share/xcat/install/rh/compute.tmpl +++ b/xCAT-server-2.0/share/xcat/install/rh/compute.tmpl @@ -125,7 +125,6 @@ skipx #rootpw --iscrypted XaLGAVe1C41x2 #rootpw XaLGAVe1C41x2 --iscrypted rootpw --iscrypted #CRYPT:passwd:key=system,username=root:password# -#rootpw --iscrypted #COMMAND:perl -e 'print crypt("#TABLE:passwd.tab:rootpw:1#","Xa") . "\n";'p# # # NIS setup: auth --enablenis --nisdomain sensenet