mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 21:19:59 +00:00
Move --log-dsn vars to outter scope to fix the rare Perl 5.8 scope-closure bug.
This commit is contained in:
17
bin/pt-kill
17
bin/pt-kill
@@ -6772,7 +6772,7 @@ sub main {
|
||||
}
|
||||
|
||||
# Set up --log-dsn if specified.
|
||||
my ($log, $log_sth);
|
||||
my ($log, $log_sql, $log_sth, $log_cxn);
|
||||
my @processlist_columns = qw(
|
||||
Id User Host db Command
|
||||
Time State Info Time_ms
|
||||
@@ -6783,7 +6783,7 @@ sub main {
|
||||
die "--log-dsn does not specify a database (D) "
|
||||
. "or a database-qualified table (t)"
|
||||
unless defined $table && defined $db;
|
||||
my $log_cxn = Cxn->new(
|
||||
$log_cxn = Cxn->new(
|
||||
dsn_string => ($dp->get_cxn_params($log_dsn))[0],
|
||||
NAME_lc => 0,
|
||||
DSNParser => $dp,
|
||||
@@ -6817,13 +6817,13 @@ sub main {
|
||||
PTDEBUG && _d($sql);
|
||||
my ($server_id) = $dbh->selectrow_array($sql);
|
||||
|
||||
$sql = "INSERT INTO $log_table ("
|
||||
$log_sql = "INSERT INTO $log_table ("
|
||||
. join(", ", @all_log_columns)
|
||||
. ") VALUES("
|
||||
. join(", ", $server_id, ("?") x (@all_log_columns-1))
|
||||
. ")";
|
||||
PTDEBUG && _d($sql);
|
||||
$log_sth = $log_dbh->prepare($sql);
|
||||
$log_sth = $log_dbh->prepare($log_sql);
|
||||
|
||||
my $retry = Retry->new();
|
||||
|
||||
@@ -6831,7 +6831,7 @@ sub main {
|
||||
my (@params) = @_;
|
||||
PTDEBUG && _d('Logging values:', @params);
|
||||
return $retry->retry(
|
||||
tries => 20,
|
||||
tries => 3,
|
||||
wait => sub { sleep 3; },
|
||||
try => sub { return $log_sth->execute(@params); },
|
||||
fail => sub {
|
||||
@@ -6843,10 +6843,13 @@ sub main {
|
||||
|| $error =~ m/Lost connection to MySQL server/ ) {
|
||||
eval {
|
||||
$log_dbh = $log_cxn->connect();
|
||||
$log_sth = $log_dbh->prepare( $sql );
|
||||
$log_sth = $log_dbh->prepare($log_sql);
|
||||
msg('Reconnected to ' . $cxn->name());
|
||||
};
|
||||
return 1 unless $EVAL_ERROR; # try again
|
||||
if ( $EVAL_ERROR ) {
|
||||
warn "Fail code failed: $EVAL_ERROR";
|
||||
}
|
||||
return 1; # retry
|
||||
}
|
||||
return 0; # call final_fail
|
||||
},
|
||||
|
@@ -30,7 +30,8 @@ if ( !$dbh ) {
|
||||
}
|
||||
|
||||
my $output;
|
||||
my $cnf='/tmp/12345/my.sandbox.cnf';
|
||||
my $dsn = $sb->dsn_for('master');
|
||||
my $cnf = '/tmp/12345/my.sandbox.cnf';
|
||||
|
||||
# TODO: These tests need something to match, so we background
|
||||
# a SLEEP(4) query and match that, but this isn't ideal because
|
||||
@@ -318,6 +319,34 @@ is(
|
||||
"Different --log-dsn runs reuse the same table."
|
||||
);
|
||||
|
||||
|
||||
# --log-dsn and --daemonize
|
||||
|
||||
$dbh->do("DELETE FROM kill_test.log_table");
|
||||
$sb->wait_for_slaves();
|
||||
|
||||
my $pid_file = "/tmp/pt-kill-test.$PID";
|
||||
my $log_file = "/tmp/pt-kill-test-log.$PID";
|
||||
diag(`rm -f $pid_file $log_file >/dev/null 2>&1`);
|
||||
|
||||
my $slave2_dbh = $sb->get_dbh_for('slave2');
|
||||
my $slave2_dsn = $sb->dsn_for('slave2');
|
||||
|
||||
system($sys_cmd);
|
||||
sleep 0.5;
|
||||
|
||||
system("$trunk/bin/pt-kill $dsn --daemonize --run-time 1 --kill-query --interval 1 --match-info 'select sleep' --log-dsn $slave2_dsn,D=kill_test,t=log_table --pid $pid_file --log $log_file");
|
||||
PerconaTest::wait_for_files($pid_file); # start
|
||||
# ... # run
|
||||
PerconaTest::wait_until(sub { !-f $pid_file}); # stop
|
||||
|
||||
$results = $slave2_dbh->selectall_arrayref("SELECT * FROM kill_test.log_table");
|
||||
|
||||
ok(
|
||||
scalar @$results,
|
||||
"--log-dsn --daemonize (bug 1209436)"
|
||||
) or diag(Dumper($results));
|
||||
|
||||
$dbh->do("DROP DATABASE IF EXISTS kill_test");
|
||||
|
||||
PerconaTest::wait_until(
|
||||
@@ -333,4 +362,3 @@ PerconaTest::wait_until(
|
||||
$sb->wipe_clean($dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
||||
exit;
|
||||
|
Reference in New Issue
Block a user