Merge lp:~percona-toolkit-dev/percona-toolkit/fix-lock-wait-timeout-bug-946776.

This commit is contained in:
Daniel Nichter
2012-03-06 12:30:58 -07:00

View File

@@ -5940,29 +5940,37 @@ sub main {
. "level to REPEATABLE-READ.\n"; . "level to REPEATABLE-READ.\n";
} }
# We set innodb_lock_wait_timeout=1 so that if this tool happens to cause # We set innodb_lock_wait_timeout=1 (the option's default value)
# some locking, it will be more likely to be the victim than other # so that if this tool happens to cause some locking, it will more
# connections to the server, and thus disrupt the server less. # likely be the victim than other connections and thus avoid disrupting
$sql = 'SHOW SESSION VARIABLES LIKE "innodb_lock_wait_timeout"'; # the server. The var is only dynamic with the InnoDB plugin, so
PTDEBUG && _d($dbh, $sql); # if setting it fails we only warn if the server's value is greater
my (undef, $lock_wait_timeout) = $dbh->selectrow_array($sql); # than the desired value. E.g. if user does --lock-wait-timeout 5
PTDEBUG && _d('innodb_lock_wait_timeout', $lock_wait_timeout); # and the set fails but the server's value is 1, then that's ok, but
if ( ($lock_wait_timeout || 0) > $o->get('lock-wait-timeout') ) { # if the server's value is 10, then that's not ok.
$sql = 'SET SESSION innodb_lock_wait_timeout=1'; my $lock_wait_timeout = $o->get('lock-wait-timeout');
eval { my $set_lwt = "SET SESSION innodb_lock_wait_timeout=$lock_wait_timeout";
PTDEBUG && _d($dbh, $sql); PTDEBUG && _d($dbh, $set_lwt);
$dbh->do($sql); eval {
}; $dbh->do($set_lwt);
if ( $EVAL_ERROR ) { };
warn "Failed to $sql: $EVAL_ERROR\n" if ( $EVAL_ERROR ) {
PTDEBUG && _d($EVAL_ERROR);
# Get the server's current value.
$sql = "SHOW SESSION VARIABLES LIKE 'innodb_lock_wait_timeout'";
PTDEBUG && _d($dbh, $sql);
my (undef, $curr_lwt) = $dbh->selectrow_array($sql);
PTDEBUG && _d('innodb_lock_wait_timeout on server:', $curr_lwt);
if ( $curr_lwt > $lock_wait_timeout ) {
warn "Failed to $set_lwt: $EVAL_ERROR\n"
. "The current innodb_lock_wait_timeout value " . "The current innodb_lock_wait_timeout value "
. "$lock_wait_timeout is higher than the --lock-wait-timeout " . "$curr_lwt is greater than the --lock-wait-timeout "
. "value " . $o->get('lock-wait-timeout') . " and the variable " . "value $lock_wait_timeout and the variable cannot be "
. "cannot be changed. innodb_lock_wait_timeout is only dynamic " . "changed. innodb_lock_wait_timeout is only dynamic when "
. "when using the InnoDB plugin. To prevent this warning, either " . "using the InnoDB plugin. To prevent this warning, either "
. "specify --lock-wait-time=$lock_wait_timeout, or manually " . "specify --lock-wait-time=$curr_lwt, or manually set "
. "set innodb_lock_wait_timeout to a value less than or equal " . "innodb_lock_wait_timeout to a value less than or equal "
. "to " . $o->get('lock-wait-timeout') . " and restart MySQL.\n"; . "to $lock_wait_timeout and restart MySQL.\n";
} }
} }
}; };
@@ -7989,10 +7997,13 @@ Ignore tables whose names match the Perl regex.
type: int; default: 1 type: int; default: 1
Set the session value of the innodb_lock_wait_timeout variable on the master host. Set the session value of C<innodb_lock_wait_timeout> on the master host.
Setting this option dynamically requires the InnoDB plugin, so this works only This option helps guard against long lock waits if the checksum queries
on newer InnoDB and MySQL versions. This option helps guard against long lock become slow for some reason. Setting this option dynamically requires the
waits if the checksum queries become slow for some reason. InnoDB plugin, so this works only on newer InnoDB and MySQL versions. If
setting the value fails and the current server value is greater than the
specified value, then a warning is printed; else, if the current server
value is less than or equal to the specified value, no warning is printed.
=item --max-lag =item --max-lag