Move --log-dsn vars to outter scope to fix the rare Perl 5.8 scope-closure bug.

This commit is contained in:
Daniel Nichter
2013-08-12 09:11:53 -07:00
parent 8f78050570
commit c596331280
2 changed files with 40 additions and 9 deletions
+10 -7
View File
@@ -6772,7 +6772,7 @@ sub main {
} }
# Set up --log-dsn if specified. # Set up --log-dsn if specified.
my ($log, $log_sth); my ($log, $log_sql, $log_sth, $log_cxn);
my @processlist_columns = qw( my @processlist_columns = qw(
Id User Host db Command Id User Host db Command
Time State Info Time_ms Time State Info Time_ms
@@ -6783,7 +6783,7 @@ sub main {
die "--log-dsn does not specify a database (D) " die "--log-dsn does not specify a database (D) "
. "or a database-qualified table (t)" . "or a database-qualified table (t)"
unless defined $table && defined $db; unless defined $table && defined $db;
my $log_cxn = Cxn->new( $log_cxn = Cxn->new(
dsn_string => ($dp->get_cxn_params($log_dsn))[0], dsn_string => ($dp->get_cxn_params($log_dsn))[0],
NAME_lc => 0, NAME_lc => 0,
DSNParser => $dp, DSNParser => $dp,
@@ -6817,13 +6817,13 @@ sub main {
PTDEBUG && _d($sql); PTDEBUG && _d($sql);
my ($server_id) = $dbh->selectrow_array($sql); my ($server_id) = $dbh->selectrow_array($sql);
$sql = "INSERT INTO $log_table (" $log_sql = "INSERT INTO $log_table ("
. join(", ", @all_log_columns) . join(", ", @all_log_columns)
. ") VALUES(" . ") VALUES("
. join(", ", $server_id, ("?") x (@all_log_columns-1)) . join(", ", $server_id, ("?") x (@all_log_columns-1))
. ")"; . ")";
PTDEBUG && _d($sql); PTDEBUG && _d($sql);
$log_sth = $log_dbh->prepare($sql); $log_sth = $log_dbh->prepare($log_sql);
my $retry = Retry->new(); my $retry = Retry->new();
@@ -6831,7 +6831,7 @@ sub main {
my (@params) = @_; my (@params) = @_;
PTDEBUG && _d('Logging values:', @params); PTDEBUG && _d('Logging values:', @params);
return $retry->retry( return $retry->retry(
tries => 20, tries => 3,
wait => sub { sleep 3; }, wait => sub { sleep 3; },
try => sub { return $log_sth->execute(@params); }, try => sub { return $log_sth->execute(@params); },
fail => sub { fail => sub {
@@ -6843,10 +6843,13 @@ sub main {
|| $error =~ m/Lost connection to MySQL server/ ) { || $error =~ m/Lost connection to MySQL server/ ) {
eval { eval {
$log_dbh = $log_cxn->connect(); $log_dbh = $log_cxn->connect();
$log_sth = $log_dbh->prepare( $sql ); $log_sth = $log_dbh->prepare($log_sql);
msg('Reconnected to ' . $cxn->name()); 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 return 0; # call final_fail
}, },
+30 -2
View File
@@ -30,7 +30,8 @@ if ( !$dbh ) {
} }
my $output; 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 # TODO: These tests need something to match, so we background
# a SLEEP(4) query and match that, but this isn't ideal because # 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." "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"); $dbh->do("DROP DATABASE IF EXISTS kill_test");
PerconaTest::wait_until( PerconaTest::wait_until(
@@ -333,4 +362,3 @@ PerconaTest::wait_until(
$sb->wipe_clean($dbh); $sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing; done_testing;
exit;