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

Proposed by Daniel Nichter
Status: Merged
Approved by: Daniel Nichter
Approved revision: 198
Merged at revision: 199
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-lock-wait-timeout-bug-946776
Merge into: lp:percona-toolkit/2.0
Diff against target: 80 lines (+37/-26)
1 file modified
bin/pt-table-checksum (+37/-26)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-lock-wait-timeout-bug-946776
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+96220@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-table-checksum'
2--- bin/pt-table-checksum 2012-03-02 15:51:28 +0000
3+++ bin/pt-table-checksum 2012-03-06 18:57:20 +0000
4@@ -5940,29 +5940,37 @@
5 . "level to REPEATABLE-READ.\n";
6 }
7
8- # We set innodb_lock_wait_timeout=1 so that if this tool happens to cause
9- # some locking, it will be more likely to be the victim than other
10- # connections to the server, and thus disrupt the server less.
11- $sql = 'SHOW SESSION VARIABLES LIKE "innodb_lock_wait_timeout"';
12- PTDEBUG && _d($dbh, $sql);
13- my (undef, $lock_wait_timeout) = $dbh->selectrow_array($sql);
14- PTDEBUG && _d('innodb_lock_wait_timeout', $lock_wait_timeout);
15- if ( ($lock_wait_timeout || 0) > $o->get('lock-wait-timeout') ) {
16- $sql = 'SET SESSION innodb_lock_wait_timeout=1';
17- eval {
18- PTDEBUG && _d($dbh, $sql);
19- $dbh->do($sql);
20- };
21- if ( $EVAL_ERROR ) {
22- warn "Failed to $sql: $EVAL_ERROR\n"
23+ # We set innodb_lock_wait_timeout=1 (the option's default value)
24+ # so that if this tool happens to cause some locking, it will more
25+ # likely be the victim than other connections and thus avoid disrupting
26+ # the server. The var is only dynamic with the InnoDB plugin, so
27+ # if setting it fails we only warn if the server's value is greater
28+ # than the desired value. E.g. if user does --lock-wait-timeout 5
29+ # and the set fails but the server's value is 1, then that's ok, but
30+ # if the server's value is 10, then that's not ok.
31+ my $lock_wait_timeout = $o->get('lock-wait-timeout');
32+ my $set_lwt = "SET SESSION innodb_lock_wait_timeout=$lock_wait_timeout";
33+ PTDEBUG && _d($dbh, $set_lwt);
34+ eval {
35+ $dbh->do($set_lwt);
36+ };
37+ if ( $EVAL_ERROR ) {
38+ PTDEBUG && _d($EVAL_ERROR);
39+ # Get the server's current value.
40+ $sql = "SHOW SESSION VARIABLES LIKE 'innodb_lock_wait_timeout'";
41+ PTDEBUG && _d($dbh, $sql);
42+ my (undef, $curr_lwt) = $dbh->selectrow_array($sql);
43+ PTDEBUG && _d('innodb_lock_wait_timeout on server:', $curr_lwt);
44+ if ( $curr_lwt > $lock_wait_timeout ) {
45+ warn "Failed to $set_lwt: $EVAL_ERROR\n"
46 . "The current innodb_lock_wait_timeout value "
47- . "$lock_wait_timeout is higher than the --lock-wait-timeout "
48- . "value " . $o->get('lock-wait-timeout') . " and the variable "
49- . "cannot be changed. innodb_lock_wait_timeout is only dynamic "
50- . "when using the InnoDB plugin. To prevent this warning, either "
51- . "specify --lock-wait-time=$lock_wait_timeout, or manually "
52- . "set innodb_lock_wait_timeout to a value less than or equal "
53- . "to " . $o->get('lock-wait-timeout') . " and restart MySQL.\n";
54+ . "$curr_lwt is greater than the --lock-wait-timeout "
55+ . "value $lock_wait_timeout and the variable cannot be "
56+ . "changed. innodb_lock_wait_timeout is only dynamic when "
57+ . "using the InnoDB plugin. To prevent this warning, either "
58+ . "specify --lock-wait-time=$curr_lwt, or manually set "
59+ . "innodb_lock_wait_timeout to a value less than or equal "
60+ . "to $lock_wait_timeout and restart MySQL.\n";
61 }
62 }
63 };
64@@ -7989,10 +7997,13 @@
65
66 type: int; default: 1
67
68-Set the session value of the innodb_lock_wait_timeout variable on the master host.
69-Setting this option dynamically requires the InnoDB plugin, so this works only
70-on newer InnoDB and MySQL versions. This option helps guard against long lock
71-waits if the checksum queries become slow for some reason.
72+Set the session value of C<innodb_lock_wait_timeout> on the master host.
73+This option helps guard against long lock waits if the checksum queries
74+become slow for some reason. Setting this option dynamically requires the
75+InnoDB plugin, so this works only on newer InnoDB and MySQL versions. If
76+setting the value fails and the current server value is greater than the
77+specified value, then a warning is printed; else, if the current server
78+value is less than or equal to the specified value, no warning is printed.
79
80 =item --max-lag
81

Subscribers

People subscribed via source and target branches