mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-20 19:04:59 +00:00
Merged fix-1156901-skip-retry-check-for-repl-threads
This commit is contained in:
33
bin/pt-kill
33
bin/pt-kill
@@ -1129,6 +1129,7 @@ if ( PTDEBUG ) {
|
|||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
{
|
{
|
||||||
package Lmo::Utils;
|
package Lmo::Utils;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings qw( FATAL all );
|
use warnings qw( FATAL all );
|
||||||
require Exporter;
|
require Exporter;
|
||||||
@@ -1136,7 +1137,12 @@ our (@ISA, @EXPORT, @EXPORT_OK);
|
|||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
@ISA = qw(Exporter);
|
@ISA = qw(Exporter);
|
||||||
@EXPORT = @EXPORT_OK = qw(_install_coderef _unimport_coderefs _glob_for _stash_for);
|
@EXPORT = @EXPORT_OK = qw(
|
||||||
|
_install_coderef
|
||||||
|
_unimport_coderefs
|
||||||
|
_glob_for
|
||||||
|
_stash_for
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -1320,7 +1326,6 @@ sub meta {
|
|||||||
return Lmo::Meta->new(class => $class);
|
return Lmo::Meta->new(class => $class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
}
|
}
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
@@ -3264,10 +3269,24 @@ sub parse_event {
|
|||||||
$new_query = 1;
|
$new_query = 1;
|
||||||
}
|
}
|
||||||
elsif ( $curr->[INFO] && defined $curr->[TIME]
|
elsif ( $curr->[INFO] && defined $curr->[TIME]
|
||||||
&& $query_start - $etime - $prev->[START] > $fudge ) {
|
&& $query_start - $etime - $prev->[START] > $fudge)
|
||||||
PTDEBUG && _d('Query restarted; new query',
|
{
|
||||||
$query_start, $etime, $prev->[START], $fudge);
|
my $ms = $self->{MasterSlave};
|
||||||
$new_query = 1;
|
|
||||||
|
my $is_repl_thread = $ms->is_replication_thread({
|
||||||
|
Command => $curr->[COMMAND],
|
||||||
|
User => $curr->[USER],
|
||||||
|
State => $curr->[STATE],
|
||||||
|
Id => $curr->[ID]});
|
||||||
|
if ( $is_repl_thread ) {
|
||||||
|
PTDEBUG &&
|
||||||
|
_d(q{Query has restarted but it's a replication thread, ignoring});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PTDEBUG && _d('Query restarted; new query',
|
||||||
|
$query_start, $etime, $prev->[START], $fudge);
|
||||||
|
$new_query = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $new_query ) {
|
if ( $new_query ) {
|
||||||
@@ -4951,6 +4970,8 @@ use warnings FATAL => 'all';
|
|||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||||
|
|
||||||
|
use Time::HiRes qw(sleep);
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ( $class, %args ) = @_;
|
my ( $class, %args ) = @_;
|
||||||
my $self = {
|
my $self = {
|
||||||
|
@@ -3215,10 +3215,24 @@ sub parse_event {
|
|||||||
$new_query = 1;
|
$new_query = 1;
|
||||||
}
|
}
|
||||||
elsif ( $curr->[INFO] && defined $curr->[TIME]
|
elsif ( $curr->[INFO] && defined $curr->[TIME]
|
||||||
&& $query_start - $etime - $prev->[START] > $fudge ) {
|
&& $query_start - $etime - $prev->[START] > $fudge)
|
||||||
PTDEBUG && _d('Query restarted; new query',
|
{
|
||||||
$query_start, $etime, $prev->[START], $fudge);
|
my $ms = $self->{MasterSlave};
|
||||||
$new_query = 1;
|
|
||||||
|
my $is_repl_thread = $ms->is_replication_thread({
|
||||||
|
Command => $curr->[COMMAND],
|
||||||
|
User => $curr->[USER],
|
||||||
|
State => $curr->[STATE],
|
||||||
|
Id => $curr->[ID]});
|
||||||
|
if ( $is_repl_thread ) {
|
||||||
|
PTDEBUG &&
|
||||||
|
_d(q{Query has restarted but it's a replication thread, ignoring});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PTDEBUG && _d('Query restarted; new query',
|
||||||
|
$query_start, $etime, $prev->[START], $fudge);
|
||||||
|
$new_query = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $new_query ) {
|
if ( $new_query ) {
|
||||||
|
@@ -245,14 +245,28 @@ sub parse_event {
|
|||||||
$new_query = 1;
|
$new_query = 1;
|
||||||
}
|
}
|
||||||
elsif ( $curr->[INFO] && defined $curr->[TIME]
|
elsif ( $curr->[INFO] && defined $curr->[TIME]
|
||||||
&& $query_start - $etime - $prev->[START] > $fudge ) {
|
&& $query_start - $etime - $prev->[START] > $fudge)
|
||||||
|
{
|
||||||
# If the query's recalculated start time minus its previously
|
# If the query's recalculated start time minus its previously
|
||||||
# calculated start time is greater than the fudge factor, then
|
# calculated start time is greater than the fudge factor, then
|
||||||
# the query has restarted. I.e. the new start time is after
|
# the query has restarted. I.e. the new start time is after
|
||||||
# the previous start time.
|
# the previous start time.
|
||||||
PTDEBUG && _d('Query restarted; new query',
|
my $ms = $self->{MasterSlave};
|
||||||
$query_start, $etime, $prev->[START], $fudge);
|
|
||||||
$new_query = 1;
|
my $is_repl_thread = $ms->is_replication_thread({
|
||||||
|
Command => $curr->[COMMAND],
|
||||||
|
User => $curr->[USER],
|
||||||
|
State => $curr->[STATE],
|
||||||
|
Id => $curr->[ID]});
|
||||||
|
if ( $is_repl_thread ) {
|
||||||
|
PTDEBUG &&
|
||||||
|
_d(q{Query has restarted but it's a replication thread, ignoring});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PTDEBUG && _d('Query restarted; new query',
|
||||||
|
$query_start, $etime, $prev->[START], $fudge);
|
||||||
|
$new_query = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $new_query ) {
|
if ( $new_query ) {
|
||||||
|
@@ -335,9 +335,116 @@ is_deeply(
|
|||||||
"New query2_2 is active, starting at 05:08"
|
"New query2_2 is active, starting at 05:08"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
# ###########################################################################
|
||||||
|
# pt-query-digest --processlist: Duplicate entries for replication thread
|
||||||
|
# https://bugs.launchpad.net/percona-toolkit/+bug/1156901
|
||||||
|
# ###########################################################################
|
||||||
|
|
||||||
|
# This is basically the same thing as above, but we're pretending to
|
||||||
|
# be a repl thread, so it should behave differently.
|
||||||
|
|
||||||
|
$pl = Processlist->new(MasterSlave=>$ms);
|
||||||
|
|
||||||
|
parse_n_times(
|
||||||
|
1,
|
||||||
|
code => sub {
|
||||||
|
return [
|
||||||
|
[ 2, 'system user', 'localhost', 'test', 'Query', 0, 'executing', 'query2_2'],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
time => Transformers::unix_timestamp('2001-01-01 00:05:03'),
|
||||||
|
etime => 3.14159,
|
||||||
|
);
|
||||||
|
|
||||||
|
is_deeply(
|
||||||
|
$pl->_get_active_cxn(),
|
||||||
|
{
|
||||||
|
2 => [
|
||||||
|
2, 'system user', 'localhost', 'test', 'Query', 0, 'executing', 'query2_2',
|
||||||
|
Transformers::unix_timestamp('2001-01-01 00:05:03'), # START
|
||||||
|
3.14159, # ETIME
|
||||||
|
Transformers::unix_timestamp('2001-01-01 00:05:03'), # FSEEN
|
||||||
|
{ executing => 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
'query2_2 just started',
|
||||||
|
);
|
||||||
|
|
||||||
|
# And there is no event on cxn 2.
|
||||||
|
is(
|
||||||
|
scalar @events,
|
||||||
|
0,
|
||||||
|
'query2_2 has not fired yet',
|
||||||
|
);
|
||||||
|
|
||||||
|
parse_n_times(
|
||||||
|
1,
|
||||||
|
code => sub {
|
||||||
|
return [
|
||||||
|
[ 2, 'system user', 'localhost', 'test', 'Query', 0, 'executing', 'query2_2'],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
time => Transformers::unix_timestamp('2001-01-01 00:05:05'),
|
||||||
|
etime => 2.718,
|
||||||
|
);
|
||||||
|
|
||||||
|
is(
|
||||||
|
scalar @events,
|
||||||
|
0,
|
||||||
|
'query2_2 has not fired yet, same as with normal queries',
|
||||||
|
);
|
||||||
|
|
||||||
|
is_deeply(
|
||||||
|
$pl->_get_active_cxn(),
|
||||||
|
{
|
||||||
|
2 => [
|
||||||
|
2, 'system user', 'localhost', 'test', 'Query', 0, 'executing', 'query2_2',
|
||||||
|
Transformers::unix_timestamp('2001-01-01 00:05:03'),
|
||||||
|
3.14159,
|
||||||
|
Transformers::unix_timestamp('2001-01-01 00:05:03'),
|
||||||
|
{ executing => 2 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
'Cxn 2 still active with query starting at 05:03',
|
||||||
|
);
|
||||||
|
|
||||||
|
# Same as above but five seconds and a half later
|
||||||
|
parse_n_times(
|
||||||
|
1,
|
||||||
|
code => sub {
|
||||||
|
return [
|
||||||
|
[ 2, 'system user', 'localhost', 'test', 'Query', 0, 'executing', 'query2_2'],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
time => Transformers::unix_timestamp('2001-01-01 00:05:08.500'),
|
||||||
|
etime => 0.123,
|
||||||
|
);
|
||||||
|
|
||||||
|
is_deeply(
|
||||||
|
\@events,
|
||||||
|
[],
|
||||||
|
'Original query2_2 not fired because we are a repl thrad',
|
||||||
|
);
|
||||||
|
|
||||||
|
is_deeply(
|
||||||
|
$pl->_get_active_cxn(),
|
||||||
|
{
|
||||||
|
2 => [
|
||||||
|
2, 'system user', 'localhost', 'test', 'Query', 0, 'executing', 'query2_2',
|
||||||
|
Transformers::unix_timestamp('2001-01-01 00:05:03'), # START
|
||||||
|
3.14159, # ETIME
|
||||||
|
Transformers::unix_timestamp('2001-01-01 00:05:03'), # FSEEN
|
||||||
|
{ executing => 5.5 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"Old query2_2 is active because we're a repl thread, but executing has updated"
|
||||||
|
);
|
||||||
|
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
# Issue 867: Make mk-query-digest detect Lock_time from processlist
|
# Issue 867: Make mk-query-digest detect Lock_time from processlist
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
|
$ms = new MasterSlave(OptionParser=>1,DSNParser=>1,Quoter=>1);
|
||||||
$pl = Processlist->new(MasterSlave=>$ms);
|
$pl = Processlist->new(MasterSlave=>$ms);
|
||||||
|
|
||||||
# For 2/10ths of a second, the query is Locked. First time we see this
|
# For 2/10ths of a second, the query is Locked. First time we see this
|
||||||
|
Reference in New Issue
Block a user