From df89dee4c691a45a3590869988be1cb2efbe85e5 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Fri, 11 May 2012 19:33:00 +0000 Subject: [PATCH] When doing getAllNodeAttribs, institute a noderange result cache to avoid many noderange() calls git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.7@12644 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Table.pm | 14 +++++++++++--- perl-xCAT/xCAT/Utils.pm | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/perl-xCAT/xCAT/Table.pm b/perl-xCAT/xCAT/Table.pm index ded46ea88..a70b52c42 100644 --- a/perl-xCAT/xCAT/Table.pm +++ b/perl-xCAT/xCAT/Table.pm @@ -2938,6 +2938,7 @@ sub getAllNodeAttribs } my $attribq = shift; my $hashretstyle = shift; + my %options=@_; my $rethash; my @results = (); my %donenodes @@ -2956,10 +2957,12 @@ sub getAllNodeAttribs $query = $self->{dbh}->prepare($qstring); $query->execute(); xCAT::NodeRange::retain_cache(1); + unless (%options{prefetchcache}) { $self->{_use_cache} = 0; $self->{nodelist}->{_use_cache}=0; $self->_clear_cache(); $self->{nodelist}->_clear_cache(); + } $self->_build_cache($attribq); $self->{nodelist}->_build_cache(['node','groups']); $self->{_use_cache} = 1; @@ -2969,9 +2972,14 @@ sub getAllNodeAttribs unless ($data->{$nodekey} =~ /^$/ || !defined($data->{$nodekey})) { #ignore records without node attrib, not possible? - my @nodes = - xCAT::NodeRange::noderange($data->{$nodekey}) - ; #expand node entry, to make groups expand + + my @nodes; + unless ($self->{nrcache}->{$data->{$nodekey}} and (($self->{nrcache}->{$data->{$nodekey}}->{tstamp} + 5) > time())) { + my @cnodes = xCAT::NodeRange::noderange($data->{$nodekey}); + $self->{nrcache}->{$data->{$nodekey}}->{value} = \@cnodes; + $self->{nrcache}->{$data->{$nodekey}}->{tstamp} = time(); + } + @nodes = @{$self->{nrcache}->{$data->{$nodekey}}->{value}}; #expand node entry, to make groups expand unless (@nodes) { #in the event of an entry not in nodelist, use entry value verbatim @nodes = ($data->{$nodekey}); } diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 3fbf6d33d..524d97cbd 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -3896,7 +3896,7 @@ sub isSN return 0; } - my @nodes = $servicenodetab->getAllNodeAttribs(['tftpserver']); + my @nodes = $servicenodetab->getAllNodeAttribs(['tftpserver'],undef,prefetchcache=>1); $servicenodetab->close; foreach my $nodes (@nodes) {