From e4cb55b3f950ed45c013324bc891ca42b8a61845 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Sun, 25 Mar 2012 15:16:11 +0000 Subject: [PATCH] Avoid redundant calls to the same table to do plugin lookup during plugin_command git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@11986 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/sbin/xcatd | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/xCAT-server/sbin/xcatd b/xCAT-server/sbin/xcatd index 8ae54465c..c5893d2ab 100755 --- a/xCAT-server/sbin/xcatd +++ b/xCAT-server/sbin/xcatd @@ -1018,6 +1018,7 @@ sub plugin_command { my $hdlspec; my @globalhandlers=(); my $useglobals=1; #If it stays 1, then use globals normally, if 0, use only for 'unhandled_nodes, if -1, don't do at all + my %hdlrcaches; foreach (@{$cmd_handlers{$req->{command}->[0]}}) { $hdlspec =$_->[1]; my $ownmod = $_->[0]; @@ -1045,10 +1046,13 @@ sub plugin_command { ($table,$cols) = split(/:/,$hdlspec); my @colmns=split(/,/,$cols); my @columns; - my $hdlrtable=xCAT::Table->new($table); - unless ($hdlrtable) { - #TODO: proper error handling - } + my $hdlrtable=0; + unless ($hdlrcaches{$hdlspec}) { + $hdlrtable=xCAT::Table->new($table,-create=>0); + unless ($hdlrtable) { + next; + } + } my $node; my $colvals = {}; foreach my $colu (@colmns) { @@ -1067,13 +1071,12 @@ sub plugin_command { $handler_hash{$ownmod} = 1; $useglobals = 1; } - my $hdlrcache; if ($hdlrtable) { - $hdlrcache = $hdlrtable->getNodesAttribs(\@nodes,\@columns); + $hdlrcaches{$hdlspec} = $hdlrtable->getNodesAttribs(\@nodes,\@columns); } foreach $node (@nodes) { - unless ($hdlrcache) { next; } - my $attribs = $hdlrcache->{$node}->[0]; #$hdlrtable->getNodeAttribs($node,\@columns); + unless ($hdlrcaches{$hdlspec}) { next; } + my $attribs = $hdlrcaches{$hdlspec}->{$node}->[0]; #$hdlrtable->getNodeAttribs($node,\@columns); unless (defined($attribs)) { next; } foreach (@columns) { my $col=$_; @@ -1095,7 +1098,7 @@ sub plugin_command { } } } - $hdlrtable->close; + $hdlrtable->close if $hdlrtable; } # end if (@nodes) } else {