diff --git a/bin/pt-query-digest b/bin/pt-query-digest index d17d2ff7..fe23f713 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -12337,7 +12337,7 @@ sub main { # We need to figure out what interval we're in and what # interval is next. So first we need to parse the ts. if ( my($y, $m, $d, $h, $i, $s) - = $args->{event}->{ts} =~ m/^$mysql_ts$/ ) { + = $args->{event}->{ts} =~ m/^$Transformers::mysql_ts$/ ) { my $rt = $o->get('run-time'); if ( $run_time_interval == 60 ) { MKDEBUG && _d("Run-time interval in seconds"); diff --git a/bin/pt-show-grants b/bin/pt-show-grants index 5134e5d9..723a718a 100755 --- a/bin/pt-show-grants +++ b/bin/pt-show-grants @@ -1665,7 +1665,7 @@ sub main { my ( $version, $ts ) = $dbh->selectrow_array("SELECT VERSION(), NOW()"); print join("\n", - "-- Grants dumped by pt-show-grants $VERSION", + "-- Grants dumped by pt-show-grants", "-- Dumped from server " . ($dbh->{mysql_hostinfo} || '') . ($o->get('timestamp') ? ", MySQL $version at $ts" : ", MySQL $version"), ), "\n" if $o->get('header'); diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index b5b96582..88c6810a 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -9,26 +9,26 @@ use warnings FATAL => 'all'; use constant MKDEBUG => $ENV{MKDEBUG} || 0; # ########################################################################### -# TableParser package +# TableParser package 7156 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/TableParser.pm -# t/lib/TableParser.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/TableParser.pm +# trunk/common/t/TableParser.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ + package TableParser; use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use constant MKDEBUG => $ENV{MKDEBUG} || 0; - use Data::Dumper; $Data::Dumper::Indent = 1; $Data::Dumper::Sortkeys = 1; $Data::Dumper::Quotekeys = 0; +use constant MKDEBUG => $ENV{MKDEBUG} || 0; + sub new { my ( $class, %args ) = @_; my @required_args = qw(Quoter); @@ -319,7 +319,6 @@ sub get_keys { sub get_fks { my ( $self, $ddl, $opts ) = @_; - my $q = $self->{Quoter}; my $fks = {}; foreach my $fk ( @@ -329,22 +328,17 @@ sub get_fks { my ( $cols ) = $fk =~ m/FOREIGN KEY \(([^\)]+)\)/; my ( $parent, $parent_cols ) = $fk =~ m/REFERENCES (\S+) \(([^\)]+)\)/; - my ($db, $tbl) = $q->split_unquote($parent, $opts->{database}); - my %parent_tbl = (tbl => $tbl); - $parent_tbl{db} = $db if $db; - if ( $parent !~ m/\./ && $opts->{database} ) { - $parent = $q->quote($opts->{database}) . ".$parent"; + $parent = "`$opts->{database}`.$parent"; } $fks->{$name} = { name => $name, colnames => $cols, cols => [ map { s/[ `]+//g; $_; } split(',', $cols) ], - parent_tbl => \%parent_tbl, - parent_tblname => $parent, - parent_cols => [ map { s/[ `]+//g; $_; } split(',', $parent_cols) ], + parent_tbl => $parent, parent_colnames=> $parent_cols, + parent_cols => [ map { s/[ `]+//g; $_; } split(',', $parent_cols) ], ddl => $fk, }; } @@ -404,29 +398,28 @@ sub _d { } 1; -} + # ########################################################################### # End TableParser package # ########################################################################### # ########################################################################### -# TableChecksum package +# TableChecksum package 7080 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/TableChecksum.pm -# t/lib/TableChecksum.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/TableChecksum.pm +# trunk/common/t/TableChecksum.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ package TableChecksum; use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use constant MKDEBUG => $ENV{MKDEBUG} || 0; - use List::Util qw(max); +use constant MKDEBUG => $ENV{MKDEBUG} || 0; + our %ALGOS = ( CHECKSUM => { pref => 0, hash => 0 }, BIT_XOR => { pref => 2, hash => 1 }, @@ -787,28 +780,28 @@ sub _d { } 1; -} + # ########################################################################### # End TableChecksum package # ########################################################################### # ########################################################################### -# OptionParser package +# OptionParser package 7102 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/OptionParser.pm -# t/lib/OptionParser.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/OptionParser.pm +# trunk/common/t/OptionParser.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ + package OptionParser; use strict; use warnings FATAL => 'all'; +use List::Util qw(max); use English qw(-no_match_vars); use constant MKDEBUG => $ENV{MKDEBUG} || 0; -use List::Util qw(max); use Getopt::Long; my $POD_link_re = '[LC]<"?([^">]+)"?>'; @@ -858,9 +851,9 @@ sub new { defaults_to => {}, # rule: opt defaults to value of other opt DSNParser => undef, default_files => [ - "/etc/percona-toolkit/percona-toolkit.conf", - "/etc/percona-toolkit/$program_name.conf", - "$home/.percona-toolkit.conf", + "/etc/maatkit/maatkit.conf", + "/etc/maatkit/$program_name.conf", + "$home/.maatkit.conf", "$home/.$program_name.conf", ], types => { @@ -1808,20 +1801,20 @@ sub _d { } 1; -} + # ########################################################################### # End OptionParser package # ########################################################################### # ########################################################################### -# DSNParser package +# DSNParser package 7388 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/DSNParser.pm -# t/lib/DSNParser.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/DSNParser.pm +# trunk/common/t/DSNParser.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ + package DSNParser; use strict; @@ -1838,6 +1831,7 @@ eval { }; my $have_dbi = $EVAL_ERROR ? 0 : 1; + sub new { my ( $class, %args ) = @_; foreach my $arg ( qw(opts) ) { @@ -2034,8 +2028,8 @@ sub get_dbh { my $dbh; my $tries = 2; while ( !$dbh && $tries-- ) { - MKDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, - join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); + MKDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, ' {', + join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults ), '}'); eval { $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); @@ -2164,25 +2158,26 @@ sub _d { } 1; -} + # ########################################################################### # End DSNParser package # ########################################################################### # ########################################################################### -# VersionParser package +# VersionParser package 6667 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/VersionParser.pm -# t/lib/VersionParser.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/VersionParser.pm +# trunk/common/t/VersionParser.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ package VersionParser; use strict; use warnings FATAL => 'all'; + use English qw(-no_match_vars); + use constant MKDEBUG => $ENV{MKDEBUG} || 0; sub new { @@ -2247,25 +2242,26 @@ sub _d { } 1; -} + # ########################################################################### # End VersionParser package # ########################################################################### # ########################################################################### -# MySQLDump package +# MySQLDump package 6345 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/MySQLDump.pm -# t/lib/MySQLDump.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/MySQLDump.pm +# trunk/common/t/MySQLDump.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ package MySQLDump; use strict; use warnings FATAL => 'all'; + use English qw(-no_match_vars); + use constant MKDEBUG => $ENV{MKDEBUG} || 0; ( our $before = <<'EOF') =~ s/^ //gm; @@ -2552,20 +2548,20 @@ sub _d { } 1; -} + # ########################################################################### # End MySQLDump package # ########################################################################### # ########################################################################### -# TableChunker package +# TableChunker package 7169 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/TableChunker.pm -# t/lib/TableChunker.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/TableChunker.pm +# trunk/common/t/TableChunker.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ + package TableChunker; use strict; @@ -3485,25 +3481,26 @@ sub _d { } 1; -} + # ########################################################################### # End TableChunker package # ########################################################################### # ########################################################################### -# Quoter package +# Quoter package 6850 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/Quoter.pm -# t/lib/Quoter.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/Quoter.pm +# trunk/common/t/Quoter.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ + package Quoter; use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); + use constant MKDEBUG => $ENV{MKDEBUG} || 0; sub new { @@ -3562,20 +3559,20 @@ sub join_quote { } 1; -} + # ########################################################################### # End Quoter package # ########################################################################### # ########################################################################### -# MasterSlave package +# MasterSlave package 7525 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/MasterSlave.pm -# t/lib/MasterSlave.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/MasterSlave.pm +# trunk/common/t/MasterSlave.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ + package MasterSlave; use strict; @@ -3583,6 +3580,11 @@ use warnings FATAL => 'all'; use English qw(-no_match_vars); use constant MKDEBUG => $ENV{MKDEBUG} || 0; +use List::Util qw(min max); +use Data::Dumper; +$Data::Dumper::Quotekeys = 0; +$Data::Dumper::Indent = 0; + sub new { my ( $class, %args ) = @_; my $self = { @@ -3848,7 +3850,7 @@ sub get_master_status { MKDEBUG && _d($dbh, 'SHOW MASTER STATUS'); $sth->execute(); my ($ms) = @{$sth->fetchall_arrayref({})}; - MKDEBUG && _d(@$ms); + MKDEBUG && _d(Dumper($ms)); if ( !$ms || scalar keys %$ms < 2 ) { MKDEBUG && _d('Server on dbh', $dbh, 'does not seem to be a master'); @@ -3991,6 +3993,168 @@ sub catchup_to_same_pos { } +sub change_master_to { + my ( $self, $dbh, $master_dsn, $master_pos ) = @_; + $self->stop_slave($dbh); + MKDEBUG && _d(Dumper($master_dsn), Dumper($master_pos)); + my $sql = "CHANGE MASTER TO MASTER_HOST='$master_dsn->{h}', " + . "MASTER_PORT= $master_dsn->{P}, MASTER_LOG_FILE='$master_pos->{file}', " + . "MASTER_LOG_POS=$master_pos->{position}"; + MKDEBUG && _d($dbh, $sql); + $dbh->do($sql); +} + +sub make_sibling_of_master { + my ( $self, $slave_dbh, $slave_dsn, $dsn_parser, $timeout) = @_; + + my $master_dsn = $self->get_master_dsn($slave_dbh, $slave_dsn, $dsn_parser) + or die "This server is not a slave"; + my $master_dbh = $dsn_parser->get_dbh( + $dsn_parser->get_cxn_params($master_dsn), { AutoCommit => 1 }); + my $gmaster_dsn + = $self->get_master_dsn($master_dbh, $master_dsn, $dsn_parser) + or die "This server's master is not a slave"; + my $gmaster_dbh = $dsn_parser->get_dbh( + $dsn_parser->get_cxn_params($gmaster_dsn), { AutoCommit => 1 }); + if ( $self->short_host($slave_dsn) eq $self->short_host($gmaster_dsn) ) { + die "The slave's master's master is the slave: master-master replication"; + } + + $self->stop_slave($master_dbh); + $self->catchup_to_master($slave_dbh, $master_dbh, $timeout); + $self->stop_slave($slave_dbh); + + my $master_status = $self->get_master_status($master_dbh); + my $mslave_status = $self->get_slave_status($master_dbh); + my $slave_status = $self->get_slave_status($slave_dbh); + my $master_pos = $self->repl_posn($master_status); + my $slave_pos = $self->repl_posn($slave_status); + + if ( !$self->slave_is_running($mslave_status) + && !$self->slave_is_running($slave_status) + && $self->pos_cmp($master_pos, $slave_pos) == 0) + { + $self->change_master_to($slave_dbh, $gmaster_dsn, + $self->repl_posn($mslave_status)); # Note it's not $master_pos! + } + else { + die "The servers aren't both stopped at the same position"; + } + + $mslave_status = $self->get_slave_status($master_dbh); + $slave_status = $self->get_slave_status($slave_dbh); + my $mslave_pos = $self->repl_posn($mslave_status); + $slave_pos = $self->repl_posn($slave_status); + if ( $self->short_host($mslave_status) ne $self->short_host($slave_status) + || $self->pos_cmp($mslave_pos, $slave_pos) != 0) + { + die "The servers don't have the same master/position after the change"; + } +} + +sub make_slave_of_sibling { + my ( $self, $slave_dbh, $slave_dsn, $sib_dbh, $sib_dsn, + $dsn_parser, $timeout) = @_; + + if ( $self->short_host($slave_dsn) eq $self->short_host($sib_dsn) ) { + die "You are trying to make the slave a slave of itself"; + } + + my $master_dsn1 = $self->get_master_dsn($slave_dbh, $slave_dsn, $dsn_parser) + or die "This server is not a slave"; + my $master_dbh1 = $dsn_parser->get_dbh( + $dsn_parser->get_cxn_params($master_dsn1), { AutoCommit => 1 }); + my $master_dsn2 = $self->get_master_dsn($slave_dbh, $slave_dsn, $dsn_parser) + or die "The sibling is not a slave"; + if ( $self->short_host($master_dsn1) ne $self->short_host($master_dsn2) ) { + die "This server isn't a sibling of the slave"; + } + my $sib_master_stat = $self->get_master_status($sib_dbh) + or die "Binary logging is not enabled on the sibling"; + die "The log_slave_updates option is not enabled on the sibling" + unless $self->has_slave_updates($sib_dbh); + + $self->catchup_to_same_pos($slave_dbh, $sib_dbh); + + $sib_master_stat = $self->get_master_status($sib_dbh); + $self->change_master_to($slave_dbh, $sib_dsn, + $self->repl_posn($sib_master_stat)); + + my $slave_status = $self->get_slave_status($slave_dbh); + my $slave_pos = $self->repl_posn($slave_status); + $sib_master_stat = $self->get_master_status($sib_dbh); + if ( $self->short_host($slave_status) ne $self->short_host($sib_dsn) + || $self->pos_cmp($self->repl_posn($sib_master_stat), $slave_pos) != 0) + { + die "After changing the slave's master, it isn't a slave of the sibling, " + . "or it has a different replication position than the sibling"; + } +} + +sub make_slave_of_uncle { + my ( $self, $slave_dbh, $slave_dsn, $unc_dbh, $unc_dsn, + $dsn_parser, $timeout) = @_; + + if ( $self->short_host($slave_dsn) eq $self->short_host($unc_dsn) ) { + die "You are trying to make the slave a slave of itself"; + } + + my $master_dsn = $self->get_master_dsn($slave_dbh, $slave_dsn, $dsn_parser) + or die "This server is not a slave"; + my $master_dbh = $dsn_parser->get_dbh( + $dsn_parser->get_cxn_params($master_dsn), { AutoCommit => 1 }); + my $gmaster_dsn + = $self->get_master_dsn($master_dbh, $master_dsn, $dsn_parser) + or die "The master is not a slave"; + my $unc_master_dsn + = $self->get_master_dsn($unc_dbh, $unc_dsn, $dsn_parser) + or die "The uncle is not a slave"; + if ($self->short_host($gmaster_dsn) ne $self->short_host($unc_master_dsn)) { + die "The uncle isn't really the slave's uncle"; + } + + my $unc_master_stat = $self->get_master_status($unc_dbh) + or die "Binary logging is not enabled on the uncle"; + die "The log_slave_updates option is not enabled on the uncle" + unless $self->has_slave_updates($unc_dbh); + + $self->catchup_to_same_pos($master_dbh, $unc_dbh); + $self->catchup_to_master($slave_dbh, $master_dbh, $timeout); + + my $slave_status = $self->get_slave_status($slave_dbh); + my $master_status = $self->get_master_status($master_dbh); + if ( $self->pos_cmp( + $self->repl_posn($slave_status), + $self->repl_posn($master_status)) != 0 ) + { + die "The slave is not caught up to its master"; + } + + $unc_master_stat = $self->get_master_status($unc_dbh); + $self->change_master_to($slave_dbh, $unc_dsn, + $self->repl_posn($unc_master_stat)); + + + $slave_status = $self->get_slave_status($slave_dbh); + my $slave_pos = $self->repl_posn($slave_status); + if ( $self->short_host($slave_status) ne $self->short_host($unc_dsn) + || $self->pos_cmp($self->repl_posn($unc_master_stat), $slave_pos) != 0) + { + die "After changing the slave's master, it isn't a slave of the uncle, " + . "or it has a different replication position than the uncle"; + } +} + +sub detach_slave { + my ( $self, $dbh ) = @_; + $self->stop_slave($dbh); + my $stat = $self->get_slave_status($dbh) + or die "This server is not a slave"; + $dbh->do('CHANGE MASTER TO MASTER_HOST=""'); + $dbh->do('RESET SLAVE'); # Wipes out master.info, etc etc + return $stat; +} + sub slave_is_running { my ( $self, $slave_status ) = @_; return ($slave_status->{slave_sql_running} || 'No') eq 'Yes'; @@ -4174,28 +4338,29 @@ sub _d { } 1; -} + # ########################################################################### # End MasterSlave package # ########################################################################### # ########################################################################### -# Daemon package +# Daemon package 6255 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/Daemon.pm -# t/lib/Daemon.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/Daemon.pm +# trunk/common/t/Daemon.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ + package Daemon; use strict; use warnings FATAL => 'all'; -use English qw(-no_match_vars); -use constant MKDEBUG => $ENV{MKDEBUG} || 0; use POSIX qw(setsid); +use English qw(-no_match_vars); + +use constant MKDEBUG => $ENV{MKDEBUG} || 0; sub new { my ( $class, %args ) = @_; @@ -4360,22 +4525,22 @@ sub _d { } 1; -} + # ########################################################################### # End Daemon package # ########################################################################### # ########################################################################### -# SchemaIterator package +# SchemaIterator package 7512 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/SchemaIterator.pm -# t/lib/SchemaIterator.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/SchemaIterator.pm +# trunk/common/t/SchemaIterator.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ package SchemaIterator; +{ # package scope use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); @@ -4472,29 +4637,16 @@ sub _make_filters { sub next_schema_object { my ( $self ) = @_; - my $schema_obj; + my %schema_object; if ( $self->{file_itr} ) { - $schema_obj= $self->_iterate_files(); + %schema_object = $self->_iterate_files(); } else { # dbh - $schema_obj= $self->_iterate_dbh(); + %schema_object = $self->_iterate_dbh(); } - if ( $schema_obj ) { - if ( $schema_obj->{ddl} && $self->{TableParser} ) { - $schema_obj->{tbl_struct} - = $self->{TableParser}->parse($schema_obj->{ddl}); - } - - delete $schema_obj->{ddl} unless $self->{keep_ddl}; - - if ( my $schema = $self->{Schema} ) { - $schema->add_schema_object($schema_obj); - } - } - - MKDEBUG && _d('Next schema object:', $schema_obj->{db}, $schema_obj->{tbl}); - return $schema_obj; + MKDEBUG && _d('Next schema object:', Dumper(\%schema_object)); + return %schema_object; } sub _iterate_files { @@ -4543,11 +4695,11 @@ sub _iterate_files { my ($engine) = $ddl =~ m/\).*?(?:ENGINE|TYPE)=(\w+)/; if ( !$engine || $self->engine_is_allowed($engine) ) { - return { + return ( db => $self->{db}, tbl => $tbl, ddl => $ddl, - }; + ); } } } @@ -4615,11 +4767,11 @@ sub _iterate_dbh { $ddl = $du->get_create_table($dbh, $q, $self->{db}, $tbl)->[1]; } - return { + return ( db => $self->{db}, tbl => $tbl, ddl => $ddl, - }; + ); } } @@ -4746,21 +4898,21 @@ sub _d { print STDERR "# $package:$line $PID ", join(' ', @_), "\n"; } +} # package scope 1; -} + # ########################################################################### # End SchemaIterator package # ########################################################################### # ########################################################################### -# Retry package +# Retry package 7473 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/Retry.pm -# t/lib/Retry.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/Retry.pm +# trunk/common/t/Retry.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ package Retry; use strict; @@ -4831,25 +4983,30 @@ sub _d { } 1; -} + # ########################################################################### # End Retry package # ########################################################################### # ########################################################################### -# Progress package +# Progress package 7096 # This package is a copy without comments from the original. The original -# with comments and its test file can be found in the Bazaar repository at, -# lib/Progress.pm -# t/lib/Progress.t -# See https://launchpad.net/percona-toolkit for more information. +# with comments and its test file can be found in the SVN repository at, +# trunk/common/Progress.pm +# trunk/common/t/Progress.t +# See http://code.google.com/p/maatkit/wiki/Developers for more information. # ########################################################################### -{ package Progress; use strict; use warnings FATAL => 'all'; + use English qw(-no_match_vars); +use Data::Dumper; +$Data::Dumper::Indent = 1; +$Data::Dumper::Sortkeys = 1; +$Data::Dumper::Quotekeys = 0; + use constant MKDEBUG => $ENV{MKDEBUG} || 0; sub new { @@ -4972,7 +5129,7 @@ sub _d { } 1; -} + # ########################################################################### # End Progress package # ########################################################################### @@ -6593,7 +6750,7 @@ sub do_tbl_replicate { foreach my $warning ( @$warnings ) { if ( $warning->{message} =~ m/Data truncated for column 'boundaries'/ ) { _d("Warning: WHERE clause too large for boundaries column; ", - "pt-table-sync may fail; value:", $where); + "mk-table-sync may fail; value:", $where); } elsif ( ($warning->{code} || 0) == 1592 ) { # Error: 1592 SQLSTATE: HY000 (ER_BINLOG_UNSAFE_STATEMENT) @@ -7133,7 +7290,7 @@ Or, Or, - pt-table-checksum host1 host2 ... hostN | pt-checksum-filter + pt-table-checksum host1 host2 ... hostN | mk-checksum-filter See L<"SPECIFYING HOSTS"> for more on the syntax of the host arguments. @@ -7182,7 +7339,7 @@ on the same server, just checksum both databases: pt-table-checksum --databases db1,db2 -You can then use L to compare the results in both databases +You can then use L to compare the results in both databases easily. pt-table-checksum examines table structure only on the first host specified, @@ -7412,7 +7569,7 @@ Output is unsorted, though all lines for one table should be output together. For speed, all checksums are done in parallel (as much as possible) and may complete out of the order in which they were started. You might want to run them through another script or command-line utility to make sure they are in the -order you want. If you pipe the output through L, you +order you want. If you pipe the output through L, you can sort the output and/or avoid seeing output about tables that have no differences. @@ -8176,8 +8333,8 @@ L<"--replicate-check"> option, pt-table-checksum can run the query for you to make it even easier. See L<"CONSISTENT CHECKSUMS"> for details. If you find tables that have differences, you can use the chunk boundaries in a -WHERE clause with L to help repair them more efficiently. See -L for details. +WHERE clause with L to help repair them more efficiently. See +L for details. The table must have at least these columns: db, tbl, chunk, boundaries, this_crc, master_crc, this_cnt, master_cnt. The table may be named anything you @@ -8606,7 +8763,7 @@ These DSN options are used to create a DSN. Each option is given like C. The options are case-sensitive, so P and p are not the same option. There cannot be whitespace before or after the C<=> and if the value contains whitespace it must be quoted. DSN options are -comma-separated. See the L manpage for full details. +comma-separated. See the L manpage for full details. =over @@ -8661,7 +8818,7 @@ User for login if not current user. =back =head1 DOWNLOADING - + Visit L to download the latest release of Percona Toolkit. Or, to get the latest release from the command line: diff --git a/lib/MasterSlave.pm b/lib/MasterSlave.pm index 83522fbb..caf527d4 100644 --- a/lib/MasterSlave.pm +++ b/lib/MasterSlave.pm @@ -585,6 +585,7 @@ sub repl_posn { sub get_slave_lag { my ( $self, $dbh ) = @_; my $stat = $self->get_slave_status($dbh); + return unless $stat; # server is not a slave return $stat->{seconds_behind_master}; } diff --git a/t/lib/MasterSlave.t b/t/lib/MasterSlave.t index 8944cccd..d3755305 100644 --- a/t/lib/MasterSlave.t +++ b/t/lib/MasterSlave.t @@ -9,7 +9,7 @@ BEGIN { use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use Test::More tests => 37; +use Test::More tests => 39; use MasterSlave; use DSNParser; @@ -398,6 +398,17 @@ SKIP: { diag(`/tmp/12346/start >/dev/null`); }; +is( + $ms->get_slave_lag($dbh), + undef, + "get_slave_lag() for master" +); + +ok( + defined $ms->get_slave_lag($slaves[1]), + "get_slave_lag() for slave" +); + # ############################################################################# # Done. # ############################################################################# diff --git a/t/pt-table-usage/basics.t b/t/pt-table-usage/basics.t deleted file mode 100644 index 4a3b197d..00000000 --- a/t/pt-table-usage/basics.t +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env perl - -BEGIN { - die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" - unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; - unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; -}; - -use strict; -use warnings FATAL => 'all'; -use English qw(-no_match_vars); -use Test::More tests => 6; - -use PerconaTest; -shift @INC; # our unshift (above) -shift @INC; # PerconaTest's unshift - -require "$trunk/bin/pt-table-usage"; - -my @args = qw(); -my $in = "$trunk/t/pt-table-usage/samples/in/"; -my $out = "t/pt-table-usage/samples/out/"; -my $output = ''; - -# ############################################################################ -# Basic queries that parse without problems. -# ############################################################################ -ok( - no_diff( - sub { pt_table_usage::main(@args, "$in/slow001.txt") }, - "$out/slow001.txt", - ), - 'Analysis for slow001.txt' -); - -ok( - no_diff( - sub { pt_table_usage::main(@args, "$in/slow002.txt") }, - "$out/slow002.txt", - ), - 'Analysis for slow002.txt (issue 1237)' -); - -ok( - no_diff( - sub { pt_table_usage::main(@args, '--query', - 'DROP TABLE IF EXISTS t') }, - "$out/drop-table-if-exists.txt", - ), - 'DROP TABLE IF EXISTS' -); - -# ############################################################################ -# --id-attribute -# ############################################################################ -ok( - no_diff( - sub { pt_table_usage::main(@args, "$in/slow003.txt", - qw(--id-attribute ts)) }, - "$out/slow003-003.txt", - ), - 'Analysis for slow003.txt with --id-attribute' -); - -# ############################################################################ -# --constant-data-value -# ############################################################################ -$output = output( - sub { pt_table_usage::main('--query', 'INSERT INTO t VALUES (42)', - qw(--constant-data-value )) }, -); -like( - $output, - qr/SELECT /, - "--constant-data-value" -); - -# ############################################################################ -# Queries with tables that can't be resolved. -# ############################################################################ - -# The tables in the WHERE can't be resolved so there's no WHERE access listed. -ok( - no_diff( - sub { pt_table_usage::main(@args, "$in/slow003.txt") }, - "$out/slow003-001.txt", - ), - 'Analysis for slow003.txt' -); - - -# ############################################################################# -# Done. -# ############################################################################# -exit; diff --git a/t/pt-table-usage/create_table_definitions.t b/t/pt-table-usage/create_table_definitions.t deleted file mode 100644 index 9751aeb9..00000000 --- a/t/pt-table-usage/create_table_definitions.t +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env perl - -BEGIN { - die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" - unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; - unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; -}; - -use strict; -use warnings FATAL => 'all'; -use English qw(-no_match_vars); -use Test::More tests => 1; - -use PerconaTest; -shift @INC; # our unshift (above) -shift @INC; # PerconaTest's unshift - -require "$trunk/bin/pt-table-usage"; - -my @args = qw(); -my $in = "$trunk/t/pt-table-usage/samples/in/"; -my $out = "t/pt-table-usage/samples/out/"; -my $output = ''; - -# ############################################################################ -# Test --create-table-definitions -# ############################################################################ - -# Without --create-table-definitions, the tables wouldn't be db-qualified. -ok( - no_diff( - sub { pt_table_usage::main(@args, - '--query', 'select city from city where city="New York"', - '--create-table-definitions', - "$trunk/t/lib/samples/mysqldump-no-data/all-dbs.txt") }, - "$out/create-table-defs-001.txt", - ), - '--create-table-definitions' -); - -# ############################################################################# -# Done. -# ############################################################################# -exit; diff --git a/t/pt-table-usage/explain_extended.t b/t/pt-table-usage/explain_extended.t deleted file mode 100644 index 4c718660..00000000 --- a/t/pt-table-usage/explain_extended.t +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env perl - -BEGIN { - die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" - unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; - unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; -}; - -use strict; -use warnings FATAL => 'all'; -use English qw(-no_match_vars); -use Test::More; - -use PerconaTest; -use Sandbox; -require "$trunk/bin/pt-table-usage"; - -my $dp = new DSNParser(opts=>$dsn_opts); -my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $dbh = $sb->get_dbh_for('master'); - -if ( !$dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; -} -else { - plan tests => 2; -} - -my $output; -my $cnf = '/tmp/12345/my.sandbox.cnf'; -my @args = ('--explain-extended', "F=$cnf"); - -my $in = "$trunk/t/pt-table-usage/samples/in/"; -my $out = "t/pt-table-usage/samples/out/"; - -$output = output( - sub { pt_table_usage::main(@args, "$in/slow003.txt") }, - stderr => 1, -); - -like( - $output, - qr/No database/, - "--explain-extended doesn't work without a database" -); - -ok( - no_diff( - sub { pt_table_usage::main(@args, qw(-D sakila), "$in/slow003.txt") }, - "$out/slow003-002.txt", - ), - 'EXPLAIN EXTENDED slow003.txt' -); - -# ############################################################################# -# Done. -# ############################################################################# -exit; diff --git a/t/pt-table-usage/samples/in/slow001.txt b/t/pt-table-usage/samples/in/slow001.txt deleted file mode 100644 index ef0d5d63..00000000 --- a/t/pt-table-usage/samples/in/slow001.txt +++ /dev/null @@ -1,24 +0,0 @@ -# Time: 071218 11:48:27 -# Thread_id: 10 Query_id: 1 -# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 -select * from t; -# Time: 071218 11:48:27 -# Thread_id: 10 Query_id: 2 -# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 -select * from t1, t2 as x, t3 y, z; -# Time: 071218 11:48:27 -# Thread_id: 10 Query_id: 3 -# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 -insert into t values (1, 2, 3); -# Time: 071218 11:48:27 -# Thread_id: 10 Query_id: 4 -# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 -delete from t where id < 1000; -# Time: 071218 11:48:27 -# Thread_id: 10 Query_id: 5 -# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 -select * from a as t1, b as t2 where t1.id=t2.id; -# Time: 071218 11:48:27 -# Thread_id: 10 Query_id: 6 -# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 -replace into t set foo='bar'; diff --git a/t/pt-table-usage/samples/in/slow002.txt b/t/pt-table-usage/samples/in/slow002.txt deleted file mode 100644 index efe5fba5..00000000 --- a/t/pt-table-usage/samples/in/slow002.txt +++ /dev/null @@ -1,20 +0,0 @@ -# Time: 071218 11:48:27 -# Thread_id: 10 Query_id: 1 -# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 -UPDATE t1 AS a JOIN t2 AS b USING (id) SET a.foo="bar" WHERE b.foo IS NOT NULL; -# Time: 071218 11:48:27 -# Thread_id: 10 Query_id: 2 -# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 -UPDATE t1 AS a JOIN t2 AS b USING (id) SET a.foo="bar", b.foo="bat" WHERE a.id=1; -# Time: 071218 11:48:27 -# Thread_id: 10 Query_id: 3 -# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 -UPDATE t1 INNER JOIN t2 USING (id) SET t1.foo="bar" WHERE t2.id=1; -# Time: 071218 11:48:27 -# Thread_id: 10 Query_id: 4 -# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 -insert into t1 (a, b, c) select x, y, z from t2 where x is not null; -# Time: 071218 11:48:27 -# Thread_id: 10 Query_id: 5 -# Query_time: 0.000012 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 -insert into t (a, b, c) select a.x, a.y, b.z from a, b where a.id=b.id; diff --git a/t/pt-table-usage/samples/in/slow003.txt b/t/pt-table-usage/samples/in/slow003.txt deleted file mode 100644 index a9fc3087..00000000 --- a/t/pt-table-usage/samples/in/slow003.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Time: 110422 11:28:00 -# Query_time: 0.000300 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 1 -select country.country, city.city from city join country using (country_id) where country = 'Brazil' and city like 'A%' limit 1; diff --git a/t/pt-table-usage/samples/out/create-table-defs-001.txt b/t/pt-table-usage/samples/out/create-table-defs-001.txt deleted file mode 100644 index 49761617..00000000 --- a/t/pt-table-usage/samples/out/create-table-defs-001.txt +++ /dev/null @@ -1,4 +0,0 @@ -Query_id: 0x1E0BF7001F0D58BB.1 -SELECT sakila.city -WHERE sakila.city - diff --git a/t/pt-table-usage/samples/out/drop-table-if-exists.txt b/t/pt-table-usage/samples/out/drop-table-if-exists.txt deleted file mode 100644 index 4f668ecb..00000000 --- a/t/pt-table-usage/samples/out/drop-table-if-exists.txt +++ /dev/null @@ -1,3 +0,0 @@ -Query_id: 0xAED187CD505CBD92.1 -DROP_TABLE t - diff --git a/t/pt-table-usage/samples/out/slow001.txt b/t/pt-table-usage/samples/out/slow001.txt deleted file mode 100644 index d0d2f0ef..00000000 --- a/t/pt-table-usage/samples/out/slow001.txt +++ /dev/null @@ -1,31 +0,0 @@ -Query_id: 0xF28708D8F2920792.1 -SELECT t - -Query_id: 0x09CB59D3450EF6E8.1 -SELECT t1 -SELECT t2 -SELECT t3 -SELECT z -TLIST t1 -TLIST t2 -TLIST t3 -TLIST z - -Query_id: 0xCF687AF9F2D5E248.1 -INSERT t -SELECT DUAL - -Query_id: 0xF1FBC364588DC469.1 -DELETE t -WHERE t - -Query_id: 0x8745D03011B0E1CE.1 -SELECT a -SELECT b -JOIN a -JOIN b - -Query_id: 0xEB871CD2B5729EA1.1 -REPLACE t -SELECT DUAL - diff --git a/t/pt-table-usage/samples/out/slow002.txt b/t/pt-table-usage/samples/out/slow002.txt deleted file mode 100644 index 744b8fd4..00000000 --- a/t/pt-table-usage/samples/out/slow002.txt +++ /dev/null @@ -1,40 +0,0 @@ -Query_id: 0x6B1671EA6890F103.1 -UPDATE t1 -SELECT DUAL -JOIN t1 -JOIN t2 -WHERE t2 - -Query_id: 0x1CD27577D202A339.1 -UPDATE t1 -SELECT DUAL -JOIN t1 -JOIN t2 -WHERE t1 - -Query_id: 0x1CD27577D202A339.2 -UPDATE t2 -SELECT DUAL -JOIN t1 -JOIN t2 -WHERE t1 - -Query_id: 0xF4BEDD52BF14F91B.1 -UPDATE t1 -SELECT DUAL -JOIN t1 -JOIN t2 -WHERE t2 - -Query_id: 0x1E62B5AB0DD828BF.1 -INSERT t1 -SELECT t2 -WHERE t2 - -Query_id: 0xE25F88EDB02EA4A3.1 -INSERT t -SELECT a -SELECT b -JOIN a -JOIN b - diff --git a/t/pt-table-usage/samples/out/slow003-001.txt b/t/pt-table-usage/samples/out/slow003-001.txt deleted file mode 100644 index e6cb0719..00000000 --- a/t/pt-table-usage/samples/out/slow003-001.txt +++ /dev/null @@ -1,6 +0,0 @@ -Query_id: 0x7C6C08E1FA6D7E73.1 -SELECT country -SELECT city -JOIN city -JOIN country - diff --git a/t/pt-table-usage/samples/out/slow003-002.txt b/t/pt-table-usage/samples/out/slow003-002.txt deleted file mode 100644 index 535196c8..00000000 --- a/t/pt-table-usage/samples/out/slow003-002.txt +++ /dev/null @@ -1,8 +0,0 @@ -Query_id: 0x7C6C08E1FA6D7E73.1 -SELECT sakila.country -SELECT sakila.city -JOIN sakila.city -JOIN sakila.country -WHERE sakila.city -WHERE sakila.country - diff --git a/t/pt-table-usage/samples/out/slow003-003.txt b/t/pt-table-usage/samples/out/slow003-003.txt deleted file mode 100644 index d8e79c80..00000000 --- a/t/pt-table-usage/samples/out/slow003-003.txt +++ /dev/null @@ -1,6 +0,0 @@ -Query_id: 110422 11:28:00.1 -SELECT country -SELECT city -JOIN city -JOIN country - diff --git a/t/pt-variable-advisor/samples/vars001-verbose-verbose.txt b/t/pt-variable-advisor/samples/vars001-verbose-verbose.txt index c0f6ed5c..d8e9e933 100644 --- a/t/pt-variable-advisor/samples/vars001-verbose-verbose.txt +++ b/t/pt-variable-advisor/samples/vars001-verbose-verbose.txt @@ -8,7 +8,7 @@ # NOTE port: The server is listening on a non-default port. -# WARN slave_net_timeout: This variable is set too high. This is too long to wait before noticing that the connection to the master has failed and retrying. This should probably be set to 60 seconds or less. It is also a good idea to use mk-heartbeat to ensure that the connection does not appear to time out when the master is simply idle. +# WARN slave_net_timeout: This variable is set too high. This is too long to wait before noticing that the connection to the master has failed and retrying. This should probably be set to 60 seconds or less. It is also a good idea to use pt-heartbeat to ensure that the connection does not appear to time out when the master is simply idle. # NOTE innodb_data_file_path: Auto-extending InnoDB files can consume a lot of disk space that is very difficult to reclaim later. Some people prefer to set innodb_file_per_table and allocate a fixed-size file for ibdata1.