diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index f9bfd522..9e6bb62f 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -5604,8 +5604,14 @@ sub get_master_status { return; } - my $sth = $self->{sths}->{$dbh}->{MASTER_STATUS} + my $sth; + if ( $self->{sths}->{$dbh} && $dbh && $self->{sths}->{$dbh} == $dbh ) { + $sth = $self->{sths}->{$dbh}->{MASTER_STATUS} ||= $dbh->prepare('SHOW MASTER STATUS'); + } + else { + $sth = $dbh->prepare('SHOW MASTER STATUS'); + } PTDEBUG && _d($dbh, 'SHOW MASTER STATUS'); $sth->execute(); my ($ms) = @{$sth->fetchall_arrayref({})}; diff --git a/lib/MasterSlave.pm b/lib/MasterSlave.pm index 9b856302..007c4d6d 100644 --- a/lib/MasterSlave.pm +++ b/lib/MasterSlave.pm @@ -538,8 +538,14 @@ sub get_master_status { return; } - my $sth = $self->{sths}->{$dbh}->{MASTER_STATUS} + my $sth; + if ( $self->{sths}->{$dbh} && $dbh && $self->{sths}->{$dbh} == $dbh ) { + $sth = $self->{sths}->{$dbh}->{MASTER_STATUS} ||= $dbh->prepare('SHOW MASTER STATUS'); + } + else { + $sth = $dbh->prepare('SHOW MASTER STATUS'); + } PTDEBUG && _d($dbh, 'SHOW MASTER STATUS'); $sth->execute(); my ($ms) = @{$sth->fetchall_arrayref({})}; diff --git a/lib/bash/collect.sh b/lib/bash/collect.sh index 44ce68ea..be28f6da 100644 --- a/lib/bash/collect.sh +++ b/lib/bash/collect.sh @@ -317,6 +317,8 @@ collect_system_data_loop() { # Sleep between collect cycles. # Synchronize ourselves onto the clock tick, so the sleeps are 1-second sleep $(date +'%s.%N' | awk "{print $OPT_SLEEP_COLLECT - (\$1 % $OPT_SLEEP_COLLECT)}") + log "In collect_system_data_loop" + log $(date +'%s.%N' | awk "{print $OPT_SLEEP_COLLECT - (\$1 % $OPT_SLEEP_COLLECT)}") ts="$(date +"TS %s.%N %F %T")" # ##################################################################### diff --git a/t/lib/bash/collect.sh b/t/lib/bash/collect.sh index 3592ebf2..d013a292 100644 --- a/t/lib/bash/collect.sh +++ b/t/lib/bash/collect.sh @@ -173,6 +173,25 @@ parse_options "$BIN_DIR/pt-stalk" --run-time 2 -- --defaults-file=/tmp/12345/my. rm $PT_TMPDIR/collect/* +collect "$PT_TMPDIR/collect" "2011_12_05" > $p-output 2>&1 + +cat $p-output + +iters=$(cat $p-df | grep -c '^TS ') +is "$iters" "2" "2 iteration/2s run time" + +if [ -f "$p-vmstat" ]; then + n=$(awk '/[ ]*[0-9]/ { n += 1 } END { print n }' "$p-vmstat") + is \ + "$n" \ + "2" \ + "vmstat runs for --run-time seconds (bug 955860)" +else + is "1" "1" "SKIP vmstat not installed" +fi + +rm $PT_TMPDIR/collect/* + fake_opcontrol="$PT_TMPDIR/collect/fake_opcontrol" fake_out="$PT_TMPDIR/collect/pt-faked-opcontrol-out" cat < "$fake_opcontrol" @@ -192,25 +211,13 @@ collect "$PT_TMPDIR/collect" "2011_12_05" > $p-output 2>&1 CMD_OPCONTROL="" OPT_COLLECT_OPROFILE="" -cat $p-df | grep -c '^TS ' -iters=$(cat $p-df | grep -c '^TS ') -is "$iters" "2" "2 iteration/2s run time" - is \ "$(cat "$fake_out")" \ "Faked opcontrol: --init" \ "Bug 986847: Can manually set which commands pt-stalk uses" -if [ -f "$p-vmstat" ]; then - n=$(awk '/[ ]*[0-9]/ { n += 1 } END { print n }' "$p-vmstat") - is \ - "$n" \ - "2" \ - "vmstat runs for --run-time seconds (bug 955860)" -else - is "1" "1" "SKIP vmstat not installed" -fi - # ############################################################################ # Done # ############################################################################ + +rm $PT_TMPDIR/collect/* diff --git a/t/pt-table-checksum/basics.t b/t/pt-table-checksum/basics.t index 2b268ccb..844da5d1 100644 --- a/t/pt-table-checksum/basics.t +++ b/t/pt-table-checksum/basics.t @@ -85,16 +85,18 @@ sub reset_repl_db { # So we will re-run failed code if test does not pass. my $cmd = sub { pt_table_checksum::main(@args) }; -diag(output($cmd)) if not ok( +#diag(output($cmd)) +ok( no_diff( $cmd, "$sample/default-results-$sandbox_version.txt", sed_out => '\'/mysql.plugin$/d; /percona_test.checksums$/d; /mysql.help_category$/d; /mysql.help_keyword$/d; /mysql.help_relation$/d; /mysql.help_topic$/d\'', post_pipe => 'sed \'/mysql.plugin$/d; /percona_test.checksums$/d; /mysql.help_category$/d; /mysql.help_keyword$/d; /mysql.help_relation$/d; /mysql.help_topic$/d; /mysql.ndb_binlog_index$/d; /mysql.global_grants$/d\' | ' . 'awk \'{print $2 " " $3 " " $4 " " $7 " " $9}\'', + keep_ouput => 1, ), "Default checksum" -); +) or diag($test_diff); # On fast machines, the chunk size will probably be be auto-adjusted so # large that all tables will be done in a single chunk without an index. diff --git a/t/pt-table-checksum/progress.t b/t/pt-table-checksum/progress.t index c1578660..253629b1 100644 --- a/t/pt-table-checksum/progress.t +++ b/t/pt-table-checksum/progress.t @@ -48,7 +48,7 @@ else { # worse. This is a random stab in the dark. There is a problem either way.) my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox'; my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), - '--chunk-size', '200'); + '--chunk-size', '50'); my $output; my $row; my $scripts = "$trunk/t/pt-table-checksum/scripts/"; @@ -83,7 +83,7 @@ like( $output, qr/Replica h=127.0.0.1,P=12347 is stopped/, "--progress for slave lag" -); +) or diag($output); like( $output,