mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-07 12:58:45 +00:00
PT-167 Still need to add tests
Description here
This commit is contained in:
30
bin/pt-kill
30
bin/pt-kill
@@ -3297,6 +3297,17 @@ sub new {
|
||||
foreach my $arg ( qw(MasterSlave) ) {
|
||||
die "I need a $arg argument" unless $args{$arg};
|
||||
}
|
||||
my $kill_busy_commands = {};
|
||||
if ($args{kill_busy_commands}) {
|
||||
for my $command (split /,/,$args{kill_busy_commands}) {
|
||||
$command =~ s/^\s+|\s+$//g;
|
||||
$kill_busy_commands->{$command} = 1;
|
||||
}
|
||||
} else {
|
||||
$kill_busy_commands->{Query} = 1;
|
||||
}
|
||||
$args{kill_busy_commands} = $kill_busy_commands;
|
||||
|
||||
my $self = {
|
||||
%args,
|
||||
polls => 0,
|
||||
@@ -3523,7 +3534,7 @@ sub find {
|
||||
next QUERY;
|
||||
}
|
||||
|
||||
if ( $find_spec{busy_time} && ($query->{Command} || '') eq 'Query' ) {
|
||||
if ( $find_spec{busy_time} && exists($self->{kill_busy_commands}->{$query->{Command} || ''}) ) {
|
||||
next QUERY unless defined($query->{Time});
|
||||
if ( $query->{Time} < $find_spec{busy_time} ) {
|
||||
PTDEBUG && _d("Query isn't running long enough");
|
||||
@@ -6788,7 +6799,7 @@ sub main {
|
||||
DSNParser => $dp,
|
||||
Quoter => "Quoter",
|
||||
);
|
||||
my $pl = new Processlist(MasterSlave => $ms);
|
||||
my $pl = new Processlist(MasterSlave => $ms, kill_busy_commands => $o->get('kill-busy-commands'));
|
||||
my $qr = new QueryRewriter();
|
||||
|
||||
my $cxn;
|
||||
@@ -8198,6 +8209,21 @@ that pt-kill matched and killed a query.
|
||||
|
||||
See also L<"--wait-before-kill"> and L<"--wait-after-kill">.
|
||||
|
||||
=item --kill-busy-commands
|
||||
|
||||
default: Query
|
||||
|
||||
group: Actions
|
||||
|
||||
Comma sepatated list of commands that will be watched/killed if they ran for
|
||||
more than L<"--busy-time"> seconds. Default: C<Query>
|
||||
|
||||
By default, L<"--busy-time"> kills only C<Query> commands but in some cases, it
|
||||
is needed to make L<"--busy-time"> to watch and kill other commands. For example,
|
||||
a prepared statement execution command is C<Execute> instead of C<Query>. In this
|
||||
case, specifying C<--kill-busy-commands=Query,Execute> will also kill the prepared
|
||||
stamente execution.
|
||||
|
||||
=item --kill-query
|
||||
|
||||
group: Actions
|
||||
|
@@ -3251,6 +3251,17 @@ sub new {
|
||||
foreach my $arg ( qw(MasterSlave) ) {
|
||||
die "I need a $arg argument" unless $args{$arg};
|
||||
}
|
||||
my $kill_busy_commands = {};
|
||||
if ($args{kill_busy_commands}) {
|
||||
for my $command (split /,/,$args{kill_busy_commands}) {
|
||||
$command =~ s/^\s+|\s+$//g;
|
||||
$kill_busy_commands->{$command} = 1;
|
||||
}
|
||||
} else {
|
||||
$kill_busy_commands->{Query} = 1;
|
||||
}
|
||||
$args{kill_busy_commands} = $kill_busy_commands;
|
||||
|
||||
my $self = {
|
||||
%args,
|
||||
polls => 0,
|
||||
@@ -3465,6 +3476,7 @@ sub find {
|
||||
my $ms = $self->{MasterSlave};
|
||||
|
||||
my @matches;
|
||||
$self->{_reasons_for_matching} = undef;
|
||||
QUERY:
|
||||
foreach my $query ( @$proclist ) {
|
||||
PTDEBUG && _d('Checking query', Dumper($query));
|
||||
@@ -3476,7 +3488,7 @@ sub find {
|
||||
next QUERY;
|
||||
}
|
||||
|
||||
if ( $find_spec{busy_time} && ($query->{Command} || '') eq 'Query' ) {
|
||||
if ( $find_spec{busy_time} && exists($self->{kill_busy_commands}->{$query->{Command} || ''}) ) {
|
||||
next QUERY unless defined($query->{Time});
|
||||
if ( $query->{Time} < $find_spec{busy_time} ) {
|
||||
PTDEBUG && _d("Query isn't running long enough");
|
||||
|
Reference in New Issue
Block a user