-Speed up noderange expansion
-Have Table calls that utilize noderange extend noderange's optimizations lifetime -Rework conserver to use the at-scale Table access methods, overall about 3 times faster so far git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1847 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
4ed55e2508
commit
ce8ee250d1
@ -1,7 +1,6 @@
|
||||
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
package xCAT::NodeRange;
|
||||
require xCAT::Table;
|
||||
require Data::Dumper;
|
||||
require Exporter;
|
||||
use strict;
|
||||
|
||||
@ -12,6 +11,8 @@ our @EXPORT = qw(noderange nodesmissed);
|
||||
my $missingnodes=[];
|
||||
my $nodelist; #=xCAT::Table->new('nodelist',-create =>1);
|
||||
#my $nodeprefix = "node";
|
||||
my @allnodeset;
|
||||
my $retaincache=0;
|
||||
|
||||
|
||||
sub subnodes (\@@) {
|
||||
@ -42,7 +43,7 @@ sub expandatom {
|
||||
}
|
||||
|
||||
# Try to match groups?
|
||||
foreach($nodelist->getAllAttribsWhere("groups like '%".$atom."%'",'node','groups')) {
|
||||
foreach($nodelist->getAllAttribs('node','groups')) {
|
||||
my @groups=split(/,/,$_->{groups}); #The where clause doesn't guarantee the atom is a full group name, only that it could be
|
||||
if (grep { $_ eq "$atom" } @groups ) {
|
||||
push @nodes,$_->{node};
|
||||
@ -64,7 +65,10 @@ sub expandatom {
|
||||
}
|
||||
#TODO: check against all groups
|
||||
$atom = substr($atom,1);
|
||||
foreach ($nodelist->getAllAttribs('node')) {
|
||||
unless (scalar(@allnodeset)) {
|
||||
@allnodeset = $nodelist->getAllAttribs('node');
|
||||
}
|
||||
foreach (@allnodeset) { #$nodelist->getAllAttribs('node')) {
|
||||
if ($_->{node} =~ m/^${atom}$/) {
|
||||
push(@nodes,$_->{node});
|
||||
}
|
||||
@ -199,6 +203,10 @@ sub expandatom {
|
||||
}
|
||||
}
|
||||
|
||||
sub retain_cache { #A semi private operation to be used *ONLY* in the interesting Table<->NodeRange module interactions.
|
||||
$retaincache=shift;
|
||||
}
|
||||
|
||||
sub noderange {
|
||||
$missingnodes=[];
|
||||
#We for now just do left to right operations
|
||||
@ -206,7 +214,12 @@ sub noderange {
|
||||
#answer not work
|
||||
my $range=shift;
|
||||
my $verify = (scalar(@_) == 1 ? shift : 1);
|
||||
$nodelist =xCAT::Table->new('nodelist',-create =>1);
|
||||
unless ($nodelist) {
|
||||
$nodelist =xCAT::Table->new('nodelist',-create =>1);
|
||||
$nodelist->{_use_cache} = 0; #TODO: a more proper external solution
|
||||
$nodelist->_build_cache(['node','groups']);
|
||||
$nodelist->{_use_cache} = 1; #TODO: a more proper external solution
|
||||
}
|
||||
my %nodes = ();
|
||||
my %delnodes = ();
|
||||
my $op = ",";
|
||||
@ -264,7 +277,10 @@ sub noderange {
|
||||
delete $nodes{$_};
|
||||
}
|
||||
}
|
||||
undef $nodelist;
|
||||
unless ($retaincache) {
|
||||
undef $nodelist;
|
||||
@allnodeset=();
|
||||
}
|
||||
return sort (keys %nodes);
|
||||
|
||||
}
|
||||
|
@ -910,9 +910,11 @@ sub getNodesAttribs {
|
||||
@attribs = @_;
|
||||
}
|
||||
if (scalar($nodelist) > $cachethreshold) {
|
||||
$self->{_use_cache} = 0;
|
||||
$self->{nodelist}->{_use_cache}=0;
|
||||
$self->_build_cache(\@attribs);
|
||||
$self->{_use_cache} = 1;
|
||||
$self->{nodelist}->_build_cache(['node','groups']);
|
||||
$self->{_use_cache} = 1;
|
||||
$self->{nodelist}->{_use_cache}=1;
|
||||
}
|
||||
my $rethash;
|
||||
@ -1308,6 +1310,7 @@ sub getAllNodeAttribs
|
||||
. $self->{tabname}
|
||||
. " WHERE \"disable\" is NULL or \"disable\" in ('','0','no','NO','no')");
|
||||
$query->execute();
|
||||
xCAT::NodeRange::retain_cache(1);
|
||||
while (my $data = $query->fetchrow_hashref())
|
||||
{
|
||||
|
||||
@ -1316,6 +1319,7 @@ sub getAllNodeAttribs
|
||||
my @nodes =
|
||||
xCAT::NodeRange::noderange($data->{node})
|
||||
; #expand node entry, to make groups expand
|
||||
my $localhash = $self->getNodesAttribs(\@nodes,$attribq);
|
||||
foreach (@nodes)
|
||||
{
|
||||
if ($donenodes{$_}) { next; }
|
||||
@ -1329,7 +1333,7 @@ sub getAllNodeAttribs
|
||||
# }
|
||||
#} else {
|
||||
my @attrs =
|
||||
$self->getNodeAttribs($_, $attribq)
|
||||
@{$localhash->{$_}} #$self->getNodeAttribs($_, $attribq)
|
||||
; #Logic moves to getNodeAttribs
|
||||
#}
|
||||
#populate node attribute by default, this sort of expansion essentially requires it.
|
||||
@ -1342,6 +1346,7 @@ sub getAllNodeAttribs
|
||||
}
|
||||
}
|
||||
}
|
||||
xCAT::NodeRange::retain_cache(0);
|
||||
$query->finish();
|
||||
return @results;
|
||||
}
|
||||
@ -1379,6 +1384,30 @@ sub getAllAttribs
|
||||
my $self = shift;
|
||||
my @attribs = @_;
|
||||
my @results = ();
|
||||
if ($self->{_use_cache}) {
|
||||
my @results;
|
||||
my $cacheline;
|
||||
CACHELINE: foreach $cacheline (@{$self->{_tablecache}}) {
|
||||
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 @results; #return wantarray ? @results : $results[0];
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
my $query =
|
||||
$self->{dbh}->prepare('SELECT * FROM '
|
||||
. $self->{tabname}
|
||||
|
@ -88,8 +88,9 @@ sub preprocess_request {
|
||||
my $allnodes=1;
|
||||
if ($noderange && @$noderange>0) {
|
||||
$allnodes=0;
|
||||
my $hmcache=$hmtab->getNodesAttribs(@$noderange,['node', 'serialport','cons', 'conserver']);
|
||||
foreach my $node (@$noderange) {
|
||||
my $ent=$hmtab->getNodeAttribs($node,['node', 'serialport','cons', 'conserver']);
|
||||
my $ent=$hmcache->{$node}->[0]; #$hmtab->getNodeAttribs($node,['node', 'serialport','cons', 'conserver']);
|
||||
push @items,$ent;
|
||||
}
|
||||
} else {
|
||||
@ -214,7 +215,14 @@ sub makeconservercf {
|
||||
#print "process_request nodes=@$nodes\n";
|
||||
|
||||
my $hmtab = xCAT::Table->new('nodehm');
|
||||
my @cfgents1 = $hmtab->getAllNodeAttribs(['cons','serialport','mgt','conserver']);
|
||||
my @cfgents1;# = $hmtab->getAllNodeAttribs(['cons','serialport','mgt','conserver','termserver','termport']);
|
||||
if (($nodes and @$nodes > 0) or $req->{noderange}->[0]) {
|
||||
@cfgents1 = $hmtab->getNodesAttribs($nodes,['cons','serialport','mgt','conserver','termserver','termport']);
|
||||
} else {
|
||||
@cfgents1 = $hmtab->getAllNodeAttribs(['cons','serialport','mgt','conserver','termserver','termport']);
|
||||
}
|
||||
|
||||
|
||||
#cfgents should now have all the nodes, so we can fill in our hashes one at a time.
|
||||
|
||||
# skip the one that does not have 'cons' defined, unless a serialport setting suggests otherwise
|
||||
@ -226,14 +234,14 @@ sub makeconservercf {
|
||||
# get the teminal servers and terminal port when cons is mrv or cyclades
|
||||
foreach (@cfgents) {
|
||||
unless ($_->{cons}) {$_->{cons} = $_->{mgt};} #populate with fallback
|
||||
my $cmeth=$_->{cons};
|
||||
if (grep(/^$cmeth$/,@cservers)) { #terminal server, more attribs needed
|
||||
my $node = $_->{node};
|
||||
my $tent = $hmtab->getNodeAttribs($node,["termserver","termport"]);
|
||||
$_->{termserver} = $tent->{termserver};
|
||||
$termservers{$tent->{termserver}} = 1;
|
||||
$_->{termport}= $tent->{termport};
|
||||
}
|
||||
#my $cmeth=$_->{cons};
|
||||
#if (grep(/^$cmeth$/,@cservers)) { #terminal server, more attribs needed
|
||||
# my $node = $_->{node};
|
||||
# my $tent = $hmtab->getNodeAttribs($node,["termserver","termport"]);
|
||||
# $_->{termserver} = $tent->{termserver};
|
||||
# $termservers{$tent->{termserver}} = 1;
|
||||
# $_->{termport}= $tent->{termport};
|
||||
#}
|
||||
}
|
||||
|
||||
# nodes defined, it is either on the service node or mkconserver is call with noderange on mn
|
||||
|
Loading…
Reference in New Issue
Block a user