diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index 0ef103127..51a603671 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -18,7 +18,7 @@ my $cachethreshold=16; #How many nodes in 'getNodesAttribs' before switching to use DBI; #use strict; -require Data::Dumper; +#use Data::Dumper; use Scalar::Util qw/weaken/; require xCAT::Schema; require xCAT::NodeRange; @@ -909,13 +909,29 @@ sub getNodesAttribs { } else { @attribs = @_; } + if (scalar($nodelist) > $cachethreshold) { + $self->_build_cache(\@attribs); + $self->{_use_cache} = 1; + $self->{nodelist}->_build_cache(['node','groups']); + $self->{nodelist}->{_use_cache}=1; + } my $rethash; foreach (@$nodelist) { $rethash->{$_} = $self->getNodeAttribs($_,\@attribs); } + $self->{_use_cache} = 0; + $self->{nodelist}->{_use_cache} = 0; return $rethash; } +sub _build_cache { #PRIVATE FUNCTION, PLEASE DON'T CALL DIRECTLY + my $self = shift; + my $attriblist = shift; + push @$attriblist,'node'; + my @tabcache = $self->getAllAttribs(@$attriblist); + $self->{_tablecache} = \@tabcache; + $self->{_cachestamp} = time; +} #-------------------------------------------------------------------------- =head3 getNodeAttribs @@ -1522,6 +1538,39 @@ sub getAttribs @attribs = @_; } my @return; + if ($self->{_use_cache}) { + my @results; + my $cacheline; + CACHELINE: foreach $cacheline (@{$self->{_tablecache}}) { + foreach (keys %keypairs) { + if (not $keypairs{$_} and $keypairs{$_} ne 0 and $cacheline->{$_}) { + next CACHELINE; + } + unless ($keypairs{$_} eq $cacheline->{$_}) { + next CACHELINE; + } + } + my $attrib; + my %rethash; + foreach $attrib (@attribs) + { + unless ($cacheline->{$attrib} =~ /^$/ || !defined($cacheline->{$attrib})) + { #To undef fields in rows that may still be returned + $rethash{$attrib} = $cacheline->{$attrib}; + } + } + if (keys %rethash) + { + push @results, \%rethash; + } + } + if (@results) + { + return wantarray ? @results : $results[0]; + } + return undef; + } + #print "Uncached access to ".$self->{tabname}."\n"; my $statement = 'SELECT * FROM ' . $self->{tabname} . ' WHERE '; my @exeargs; foreach (keys %keypairs) diff --git a/xCAT-server/sbin/xcatd b/xCAT-server/sbin/xcatd index 638939e5a..4ffbb5ed8 100755 --- a/xCAT-server/sbin/xcatd +++ b/xCAT-server/sbin/xcatd @@ -631,8 +631,9 @@ sub plugin_command { unless (@nodes) { #register the plugin in the event of usage $handler_hash{$ownmod} = 1; } + my $hdlrcache = $hdlrtable->getNodesAttribs(\@nodes,\@columns); foreach $node (@nodes) { - my $attribs = $hdlrtable->getNodeAttribs($node,\@columns); + my $attribs = $hdlrcache->{$node}; #$hdlrtable->getNodeAttribs($node,\@columns); unless (defined($attribs)) { next; } #TODO: This really ought to craft an unsupported response for this request foreach (@columns) { my $col=$_;