def commands performance enhancement: 1. fix performance issue in the getobjdefs; 2. def commands only get necessary attribute by getobjdefs; 3. lsdef without flags only displays node name; 4. rmobjdefs does not check the only_if condition; 5. Make Table::delEntries function can handle multiple records for a table
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4864 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
004904267e
commit
68de42c84b
File diff suppressed because it is too large
Load Diff
@ -2419,83 +2419,102 @@ sub delEntries
|
||||
return dbc_call($self,'delEntries',@_);
|
||||
}
|
||||
my $keyref = shift;
|
||||
my @all_keyparis;
|
||||
my %keypairs;
|
||||
if (not $self->{intransaction} and not $self->{autocommit} and $self->{realautocommit}) {
|
||||
$self->{intransaction}=1;
|
||||
$self->{dbh}->{AutoCommit}=0;
|
||||
}
|
||||
if ($keyref)
|
||||
if (ref($keyref) eq 'ARRAY')
|
||||
{
|
||||
%keypairs = %{$keyref};
|
||||
@all_keyparis = @{$keyref};
|
||||
}else {
|
||||
push @all_keyparis, $keyref;
|
||||
}
|
||||
|
||||
|
||||
my $notif = xCAT::NotifHandler->needToNotify($self->{tabname}, 'd');
|
||||
my @notif_data;
|
||||
if ($notif == 1)
|
||||
{
|
||||
my $qstring = "SELECT * FROM " . $self->{tabname};
|
||||
if ($keyref) { $qstring .= " WHERE "; }
|
||||
my @qargs = ();
|
||||
foreach (keys %keypairs)
|
||||
{
|
||||
#$qstring .= "\"$_\" = ? AND "; #mysql change
|
||||
#$qstring .= "$_ = ? AND ";
|
||||
if ($xcatcfg =~ /^mysql:/) { #for mysql
|
||||
$qstring .= q(`) . $_ . q(`) . " = ? AND "; # mysql change
|
||||
} else { # for other dbs
|
||||
$qstring .= "$_ = ? AND ";
|
||||
}
|
||||
|
||||
push @qargs, $keypairs{$_};
|
||||
}
|
||||
$qstring =~ s/ AND \z//;
|
||||
#print "this is qstring: $qstring";
|
||||
my $query = $self->{dbh}->prepare($qstring);
|
||||
$query->execute(@qargs);
|
||||
|
||||
#prepare the notification data
|
||||
#put the column names at the very front
|
||||
push(@notif_data, $query->{NAME});
|
||||
my $temp_data = $query->fetchall_arrayref();
|
||||
foreach (@$temp_data)
|
||||
my $record_num = 100;
|
||||
my @pieces = splice(@all_keyparis, 0, $record_num);
|
||||
while (@pieces) {
|
||||
my @notif_data;
|
||||
if ($notif == 1)
|
||||
{
|
||||
push(@notif_data, $_);
|
||||
}
|
||||
$query->finish();
|
||||
}
|
||||
my $qstring = "SELECT * FROM " . $self->{tabname};
|
||||
if ($keyref) { $qstring .= " WHERE "; }
|
||||
my @qargs = ();
|
||||
foreach my $keypairs (@pieces) {
|
||||
$qstring .= "(";
|
||||
foreach my $keypair (keys %{$keypairs})
|
||||
{
|
||||
if ($xcatcfg =~ /^mysql:/) {
|
||||
$qstring .= q(`) . $keypair . q(`) . " = ? AND "; # mysql change
|
||||
} else { # for other dbs
|
||||
$qstring .= "$keypair = ? AND ";
|
||||
}
|
||||
|
||||
my @stargs = ();
|
||||
my $delstring = 'DELETE FROM ' . $self->{tabname};
|
||||
if ($keyref) { $delstring .= ' WHERE '; }
|
||||
foreach (keys %keypairs)
|
||||
{
|
||||
#$delstring .= $_ . ' = ? AND ';
|
||||
#$delstring .= "\"$_\"" . ' = ? AND '; #mysql change
|
||||
if ($xcatcfg =~ /^mysql:/) { #for mysql
|
||||
$delstring .= q(`) . $_ . q(`) . ' = ? AND '; # mysql change
|
||||
} else { # for other dbs
|
||||
$delstring .= $_ . ' = ? AND ';
|
||||
push @qargs, $keypairs->{$keypair};
|
||||
}
|
||||
$qstring =~ s/ AND \z//;
|
||||
$qstring .= ") OR ";
|
||||
}
|
||||
$qstring =~ s/\(\)//;
|
||||
$qstring =~ s/ OR \z//;
|
||||
|
||||
|
||||
my $query = $self->{dbh}->prepare($qstring);
|
||||
$query->execute(@qargs);
|
||||
|
||||
#prepare the notification data
|
||||
#put the column names at the very front
|
||||
push(@notif_data, $query->{NAME});
|
||||
my $temp_data = $query->fetchall_arrayref();
|
||||
foreach (@$temp_data)
|
||||
{
|
||||
push(@notif_data, $_);
|
||||
}
|
||||
$query->finish();
|
||||
}
|
||||
if (ref($keypairs{$_}))
|
||||
{ #XML transformed data may come in mangled unreasonably into listrefs
|
||||
push @stargs, $keypairs{$_}->[0];
|
||||
|
||||
my @stargs = ();
|
||||
my $delstring = 'DELETE FROM ' . $self->{tabname};
|
||||
if ($keyref) { $delstring .= ' WHERE '; }
|
||||
foreach my $keypairs (@pieces) {
|
||||
$delstring .= "(";
|
||||
foreach my $keypair (keys %{$keypairs})
|
||||
{
|
||||
if ($xcatcfg =~ /^mysql:/) {
|
||||
$delstring .= q(`) . $keypair. q(`) . ' = ? AND '; # mysql change
|
||||
} else { # for other dbs
|
||||
$delstring .= $keypair . ' = ? AND ';
|
||||
}
|
||||
if (ref($keypairs->{$keypair}))
|
||||
{ #XML transformed data may come in mangled unreasonably into listrefs
|
||||
push @stargs, $keypairs->{$keypair}->[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
push @stargs, $keypairs->{$keypair};
|
||||
}
|
||||
}
|
||||
$delstring =~ s/ AND \z//;
|
||||
$delstring .= ") OR ";
|
||||
}
|
||||
else
|
||||
$delstring =~ s/\(\)//;
|
||||
$delstring =~ s/ OR \z//;
|
||||
my $stmt = $self->{dbh}->prepare($delstring);
|
||||
$stmt->execute(@stargs);
|
||||
$stmt->finish;
|
||||
|
||||
#notify the interested parties
|
||||
if ($notif == 1)
|
||||
{
|
||||
push @stargs, $keypairs{$_};
|
||||
xCAT::NotifHandler->notify("d", $self->{tabname}, \@notif_data, {});
|
||||
}
|
||||
@pieces = splice(@all_keyparis, 0, $record_num);
|
||||
}
|
||||
$delstring =~ s/ AND \z//;
|
||||
my $stmt = $self->{dbh}->prepare($delstring);
|
||||
$stmt->execute(@stargs);
|
||||
$stmt->finish;
|
||||
|
||||
#notify the interested parties
|
||||
if ($notif == 1)
|
||||
{
|
||||
xCAT::NotifHandler->notify("d", $self->{tabname}, \@notif_data,
|
||||
{});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
|
@ -1118,7 +1118,8 @@ sub defmk
|
||||
}
|
||||
|
||||
# get all the attrs for these nodes
|
||||
my %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash);
|
||||
my @whereattrs = keys %::WhereHash;
|
||||
my %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash, 0, \@whereattrs);
|
||||
|
||||
# see which ones match the where values
|
||||
foreach my $objname (keys %myhash)
|
||||
@ -1598,7 +1599,9 @@ sub defch
|
||||
if ($isDefined)
|
||||
{
|
||||
$objhash{$obj} = $type;
|
||||
%grphash = xCAT::DBobjUtils->getobjdefs(\%objhash);
|
||||
my @finalattrs = keys %{$::FINALATTRS{$obj}};
|
||||
push @finalattrs, 'grouptype';
|
||||
%grphash = xCAT::DBobjUtils->getobjdefs(\%objhash, 0, \@finalattrs);
|
||||
if (!defined(%grphash))
|
||||
{
|
||||
my $rsp;
|
||||
@ -1690,9 +1693,6 @@ sub defch
|
||||
$objhash{$n} = 'node';
|
||||
}
|
||||
|
||||
# get all the attrs for these nodes
|
||||
my %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash);
|
||||
|
||||
# get a list of attr=val pairs, is it really necessary??
|
||||
my @wherevals = split(/::/, $::FINALATTRS{$obj}{wherevals});
|
||||
my $rc = xCAT::Utils->parse_selection_string(\@wherevals, \%::WhereHash);
|
||||
@ -1704,6 +1704,10 @@ sub defch
|
||||
return 3;
|
||||
}
|
||||
|
||||
# get the attrs for these nodes
|
||||
my @whereattrs = keys %::WhereHash;
|
||||
my %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash, 0, \@whereattrs);
|
||||
|
||||
# see which ones match the where values
|
||||
foreach my $objname (keys %myhash)
|
||||
{
|
||||
@ -2240,7 +2244,7 @@ sub defls
|
||||
}
|
||||
|
||||
# do we want just the object names or all the attr=val
|
||||
if ($::opt_l || @::noderange || $::opt_i)
|
||||
if ($::opt_l || $::opt_i)
|
||||
{
|
||||
|
||||
# assume we want the the details - not just the names
|
||||
@ -2261,7 +2265,7 @@ sub defls
|
||||
} elsif ( @::noderange || $::opt_o) {
|
||||
# if they gave a list of objects then they must want more
|
||||
# than the object names!
|
||||
$::ATTRLIST="all";
|
||||
$::ATTRLIST="none";
|
||||
} else {
|
||||
# otherwise just get a list of object names
|
||||
$::ATTRLIST="none";
|
||||
@ -2286,7 +2290,7 @@ sub defls
|
||||
|
||||
}
|
||||
|
||||
%myhash = xCAT::DBobjUtils->getobjdefs(\%objhash, $::VERBOSE);
|
||||
%myhash = xCAT::DBobjUtils->getobjdefs(\%objhash, $::VERBOSE, \@::AttrList);
|
||||
if (!defined(%myhash))
|
||||
{
|
||||
my $rsp;
|
||||
@ -2303,7 +2307,7 @@ sub defls
|
||||
{
|
||||
%objhash = %::ObjTypeHash;
|
||||
|
||||
%myhash = xCAT::DBobjUtils->getobjdefs(\%objhash, $::VERBOSE);
|
||||
%myhash = xCAT::DBobjUtils->getobjdefs(\%objhash, $::VERBOSE, \@::AttrList);
|
||||
if (!defined(%myhash))
|
||||
{
|
||||
my $rsp;
|
||||
@ -2498,7 +2502,7 @@ sub defls
|
||||
return 0;
|
||||
}
|
||||
|
||||
# for each object
|
||||
# for each object
|
||||
foreach my $obj (sort keys %defhash)
|
||||
{
|
||||
|
||||
@ -2507,7 +2511,7 @@ sub defls
|
||||
next;
|
||||
}
|
||||
|
||||
# if anything but the site table do this
|
||||
# if anything but the site table do this
|
||||
if ($defhash{$obj}{'objtype'} ne 'site')
|
||||
{
|
||||
my @tmplist =
|
||||
@ -2563,7 +2567,6 @@ sub defls
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($::opt_x)
|
||||
{
|
||||
|
||||
@ -2973,7 +2976,8 @@ sub defrm
|
||||
# get the group object definition
|
||||
my %ghash;
|
||||
$ghash{$obj} = 'group';
|
||||
my %grphash = xCAT::DBobjUtils->getobjdefs(\%ghash);
|
||||
my @attrs = ('grouptype', 'wherevals');
|
||||
my %grphash = xCAT::DBobjUtils->getobjdefs(\%ghash, 0, \@attrs);
|
||||
if (!defined(%grphash))
|
||||
{
|
||||
my $rsp;
|
||||
@ -3010,7 +3014,8 @@ sub defrm
|
||||
$nhash{$m} = 'node';
|
||||
}
|
||||
# Performance: Only call getobjdefs once
|
||||
%nodehash = xCAT::DBobjUtils->getobjdefs(\%nhash);
|
||||
my @attrs = ('groups');
|
||||
%nodehash = xCAT::DBobjUtils->getobjdefs(\%nhash, 0, \@attrs);
|
||||
if (!defined(%nodehash))
|
||||
{
|
||||
my $rsp;
|
||||
|
Loading…
x
Reference in New Issue
Block a user