perf improvement to getnodetype, getcecchildren, getchildren
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/branches/2.6@11017 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
+106
-92
@@ -10,17 +10,16 @@
|
||||
#####################################################
|
||||
package xCAT::DBobjUtils;
|
||||
|
||||
use xCAT::NodeRange;
|
||||
use xCAT::Schema;
|
||||
use xCAT::Table;
|
||||
use xCAT::Utils;
|
||||
use xCAT::MsgUtils;
|
||||
use xCAT::NetworkUtils;
|
||||
require xCAT::NodeRange;
|
||||
require xCAT::Schema;
|
||||
require xCAT::Table;
|
||||
require xCAT::Utils;
|
||||
require xCAT::MsgUtils;
|
||||
require xCAT::NetworkUtils;
|
||||
use strict;
|
||||
|
||||
# IPv6 not yet implemented - need Socket6
|
||||
use Socket;
|
||||
my @tabletype = qw(ppc zvm);
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
@@ -1039,7 +1038,8 @@ sub setobjdefs
|
||||
#
|
||||
# get the actual attr name to use in the table
|
||||
# - may be different then the attr name used for the object.
|
||||
($::tab, $::tabattr) = split('\.', $this_attr->{tabentry});
|
||||
my $ntab;
|
||||
($ntab, $::tabattr) = split('\.', $this_attr->{tabentry});
|
||||
|
||||
my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname,
|
||||
$this_attr->{access_tabentry}, \%tabentry);
|
||||
@@ -2104,6 +2104,7 @@ sub getchildren
|
||||
}
|
||||
$::RUNCMD_RC = 0;
|
||||
my $port = shift;
|
||||
my @tabletype = qw(ppc zvm);
|
||||
my @children = ();
|
||||
my @children_port = ();
|
||||
if (!%PPCHASH) {
|
||||
@@ -2118,23 +2119,21 @@ sub getchildren
|
||||
my $p = $entry->{parent};
|
||||
my $c = $entry->{node};
|
||||
my $t = $entry->{nodetype};
|
||||
if ($t) { # the nodetype exists in the ppc table, use it
|
||||
if ( $p and $c) {
|
||||
if ( $p and $c) {
|
||||
if ($t) { # the nodetype exists in the ppc table, use it
|
||||
if ( $t eq 'fsp' or $t eq 'bpa') {
|
||||
# build hash of ppc.parent -> ppc.node
|
||||
push @{$PPCHASH{$p}}, $c;
|
||||
}
|
||||
}
|
||||
} else { # go look in the nodetype table to find nodetype
|
||||
if ( $p and $c) {
|
||||
my $type = getnodetype($c);
|
||||
if ( $type eq 'fsp' or $type eq 'bpa')
|
||||
{
|
||||
} else { # go look in the nodetype table to find nodetype
|
||||
my $type = getnodetype($c);
|
||||
if ( $type eq 'fsp' or $type eq 'bpa')
|
||||
{
|
||||
# build hash of ppc.parent -> ppc.node
|
||||
push @{$PPCHASH{$p}}, $c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} # not $p and $c
|
||||
}
|
||||
# Find parent in the hash and build return values
|
||||
foreach (@{$PPCHASH{$parent}}) {
|
||||
@@ -2164,7 +2163,7 @@ sub getchildren
|
||||
{
|
||||
return undef;
|
||||
}
|
||||
for my $n (@children)
|
||||
foreach my $n (@children)
|
||||
{
|
||||
my $nside = $sides->{$n}->[0];
|
||||
if ($nside->{side} =~ /$port/)
|
||||
@@ -2178,23 +2177,19 @@ sub getchildren
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 getnodetype
|
||||
returns nodetype,
|
||||
first requery ppc table, if not exist, requery nodetypetable
|
||||
if the input is a array it will return a refrence,
|
||||
if the input is a simple node,it will return its type value
|
||||
if the value in the talbe is null, it will be undef but not ''
|
||||
Query ppc table, if no type found query nodetype table
|
||||
Arguments:
|
||||
none
|
||||
An array of nodenames or 1 nodename
|
||||
Returns:
|
||||
type of node
|
||||
Globals:
|
||||
%::GLOBLE_NODE_TYPE
|
||||
%NODETYPEHASH
|
||||
Error:
|
||||
none
|
||||
$::RUNCMD_RC = 1;
|
||||
Errors written to syslog
|
||||
Example:
|
||||
$type = getnodetype($node);
|
||||
$typerefer = getnodetype(\@nodes);
|
||||
@@ -2203,6 +2198,7 @@ sub getchildren
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
my %NODETYPEHASH;
|
||||
sub getnodetype
|
||||
{
|
||||
my $nodes = shift;
|
||||
@@ -2211,60 +2207,64 @@ sub getnodetype
|
||||
$nodes = shift;
|
||||
}
|
||||
my $rsp;
|
||||
my @tabletype = qw(ppc zvm);
|
||||
$::RUNCMD_RC = 0;
|
||||
|
||||
my $nodetypetab = xCAT::Table->new( 'nodetype' );
|
||||
if ( !$nodetypetab )
|
||||
{
|
||||
$rsp->{data}->[0] = "Could not open the nodetype table.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
||||
|
||||
unless ($nodetypetab) { # cannot open the table return with error
|
||||
xCAT::MsgUtils->
|
||||
message('S', "getnodetype:Unable to open nodetype table.\n");
|
||||
$::RUNCMD_RC = 1;
|
||||
return undef;
|
||||
}
|
||||
|
||||
my @types = ();
|
||||
my $typep;
|
||||
my $type;
|
||||
my %typehash;
|
||||
if ( $nodes =~ /^ARRAY/) {
|
||||
my @nodetypes = $nodetypetab->getAllAttribs('node','nodetype');
|
||||
for my $tn( @nodetypes ) {
|
||||
$typehash{ $tn->{'node'} } = $tn->{'nodetype'};
|
||||
}
|
||||
for my $nn (@$nodes) {
|
||||
$type = $typehash{$nn};
|
||||
if ($type) {
|
||||
my $flag = 0;
|
||||
my @tablename;
|
||||
for my $tt ( split /,/, $type ) {
|
||||
if ( grep(/$tt/, @tabletype)) {
|
||||
@tablename = grep(/$tt/, @tabletype);
|
||||
$flag = 1;
|
||||
next;
|
||||
}
|
||||
if (!%NODETYPEHASH) {
|
||||
my @nodetypes = $nodetypetab->getAllAttribs('node','nodetype');
|
||||
foreach my $tn (@nodetypes) {
|
||||
$NODETYPEHASH{ $tn->{'node'} } = $tn->{'nodetype'};
|
||||
}
|
||||
}
|
||||
foreach my $nn (@$nodes) {
|
||||
$type = $NODETYPEHASH{$nn};
|
||||
if ($type) {
|
||||
my $flag = 0;
|
||||
my @tablename;
|
||||
foreach my $tt (split /,/, $type) {
|
||||
if (grep(/$tt/, @tabletype)) {
|
||||
@tablename = grep(/$tt/, @tabletype);
|
||||
$flag = 1;
|
||||
next;
|
||||
}
|
||||
}
|
||||
unless ($flag) { # find type in nodetype table
|
||||
push (@types, $type);
|
||||
} else { # use table (ppc or zvm) from attribute
|
||||
my $tablehandler = xCAT::Table->new( $tablename[0] );
|
||||
unless ($tablehandler) { # cannot open
|
||||
xCAT::MsgUtils->
|
||||
message('S', "getnodetype:Unable to open $tablename[0] table.\n");
|
||||
$::RUNCMD_RC = 1;
|
||||
return undef;
|
||||
}
|
||||
unless ($flag) { # find type in nodetype table
|
||||
push (@types, $type);
|
||||
# read the table
|
||||
$typep = $tablehandler->getNodeAttribs($nn, ["nodetype"]);
|
||||
if ($typep and $typep->{nodetype}) {
|
||||
$type = $typep->{nodetype};
|
||||
push (@types, $type);
|
||||
} else {
|
||||
my $tablehandler = xCAT::Table->new( $tablename[0] );
|
||||
if ( !$tablehandler ) {
|
||||
$rsp->{data}->[0] = "Could not open the $tablename[0] table.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
||||
push (@types, undef);
|
||||
next;
|
||||
}
|
||||
$typep = $tablehandler->getNodeAttribs($nn, ["nodetype"]); # find type in ppc table
|
||||
if ($typep and $typep->{nodetype}) {
|
||||
$type = $typep->{nodetype};
|
||||
push (@types, $type);
|
||||
} else {
|
||||
push (@types, undef);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
push (@types, undef);
|
||||
}
|
||||
push (@types, undef);
|
||||
}
|
||||
} # end of processing PPC
|
||||
} else {
|
||||
push (@types, undef);
|
||||
}
|
||||
}
|
||||
return \@types;
|
||||
} else {
|
||||
} else { # for one node
|
||||
$typep = $nodetypetab->getNodeAttribs($nodes, ["nodetype"]);
|
||||
if ( $typep and $typep->{nodetype} ) {
|
||||
$type = $typep->{nodetype};
|
||||
@@ -2282,9 +2282,9 @@ sub getnodetype
|
||||
} else { # find type in ppc table
|
||||
my $tablehandler = xCAT::Table->new( $tablename[0] );
|
||||
if ( !$tablehandler ) {
|
||||
$rsp->{data}->[0] = "Could not open the $tablename[0] table.";
|
||||
xCAT::MsgUtils->message("E", $rsp, $::callback);
|
||||
return undef;
|
||||
xCAT::MsgUtils->message('S', "getnodetype:Unable to open $tablename[0] table.\n");
|
||||
$::RUNCMD_RC = 1;
|
||||
return undef;
|
||||
}
|
||||
$typep = $tablehandler->getNodeAttribs($nodes, ["nodetype"]);
|
||||
if ( $typep and $typep->{nodetype} ) {
|
||||
@@ -2306,18 +2306,19 @@ sub getnodetype
|
||||
Arguments:
|
||||
frame name
|
||||
Returns:
|
||||
refrence of cec hostnames
|
||||
Array of cec hostnames
|
||||
Globals:
|
||||
$::PARENT_CHILDREN_CEC
|
||||
%PARENT_CHILDREN_CEC
|
||||
Error:
|
||||
none
|
||||
Example:
|
||||
$c1 = getcecchildren($nodetocheck);
|
||||
@frame_members = getcecchildren($frame);
|
||||
Comments:
|
||||
none
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
my %PARENT_CHILDREN_CEC;
|
||||
sub getcecchildren
|
||||
{
|
||||
my $parent = shift;
|
||||
@@ -2326,33 +2327,46 @@ sub getcecchildren
|
||||
$parent = shift;
|
||||
}
|
||||
my @children = ();
|
||||
if (!%::PARENT_CHILDREN_CEC) {
|
||||
if (!%PARENT_CHILDREN_CEC) {
|
||||
my $ppctab = xCAT::Table->new( 'ppc' );
|
||||
unless ($ppctab) { # cannot open the table return with error
|
||||
xCAT::MsgUtils->message('S', "getcecchildren:Unable to open ppc table.\n");
|
||||
$::RUNCMD_RC = 1;
|
||||
return undef;
|
||||
}
|
||||
if ($ppctab)
|
||||
{
|
||||
my @ps = $ppctab->getAllNodeAttribs(['node','parent']);
|
||||
for my $entry ( @ps ) {
|
||||
my @ps = $ppctab->getAllNodeAttribs(['node','parent','nodetype']);
|
||||
foreach my $entry ( @ps ) {
|
||||
my $p = $entry->{parent};
|
||||
my $c = $entry->{node};
|
||||
my $t = $entry->{nodetype};
|
||||
if ( $p and $c) {
|
||||
#my $type = $ppctab->getNodeAttribs($c, ["nodetype"]);
|
||||
my $type = getnodetype($c);
|
||||
if ( $type eq 'cec') {
|
||||
push @{$::PARENT_CHILDREN_CEC{$p}}, $c;
|
||||
}
|
||||
if ($t) { # the nodetype exists in the ppc table, use it
|
||||
if ( $t eq 'cec') {
|
||||
# build hash of ppc.parent -> ppc.node
|
||||
push @{$PARENT_CHILDREN_CEC{$p}}, $c;
|
||||
}
|
||||
} else { # go look in the nodetype table to find nodetype
|
||||
my $type = getnodetype($c);
|
||||
if ( $type eq 'cec') {
|
||||
push @{$PARENT_CHILDREN_CEC{$p}}, $c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (@{$::PARENT_CHILDREN_CEC{$parent}}) {
|
||||
}
|
||||
# find a match for the parent and build the return array
|
||||
foreach (@{$PARENT_CHILDREN_CEC{$parent}}) {
|
||||
push @children, $_;
|
||||
}
|
||||
return \@children;
|
||||
return \@children;
|
||||
}
|
||||
} else {
|
||||
if (exists($::PARENT_CHILDREN_CEC{$parent})) {
|
||||
foreach (@{$::PARENT_CHILDREN_CEC{$parent}}) {
|
||||
} else { # already built the HASH
|
||||
if (exists($PARENT_CHILDREN_CEC{$parent})) {
|
||||
foreach (@{$PARENT_CHILDREN_CEC{$parent}}) {
|
||||
push @children, $_;
|
||||
}
|
||||
return \@children;
|
||||
return \@children;
|
||||
}
|
||||
}
|
||||
return undef;
|
||||
|
||||
Reference in New Issue
Block a user