Merge lp:~percona-toolkit-dev/percona-toolkit/pt-table-sync-binlog-format-only-if-not-statement into lp:percona-toolkit/2.1

Proposed by Baron Schwartz
Status: Merged
Merged at revision: 301
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/pt-table-sync-binlog-format-only-if-not-statement
Merge into: lp:percona-toolkit/2.1
Diff against target: 42 lines (+29/-3)
1 file modified
bin/pt-table-sync (+29/-3)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-table-sync-binlog-format-only-if-not-statement
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+109760@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-sync'
2--- bin/pt-table-sync 2012-06-11 19:48:00 +0000
3+++ bin/pt-table-sync 2012-06-12 01:33:20 +0000
4@@ -8884,9 +8884,35 @@
5
6 # Ensure statement-based replication.
7 # http://code.google.com/p/maatkit/issues/detail?id=95
8- $sql = q{/*!50105 SET @@binlog_format='STATEMENT'*/};
9- PTDEBUG && _d($dbh, $sql);
10- $dbh->do($sql);
11+ # https://bugs.launchpad.net/percona-toolkit/+bug/919352
12+ # The tool shouldn't blindly attempt to change binlog_format;
13+ # instead, it should check if it's already set to STATEMENT.
14+ # This is becase starting with MySQL 5.1.29, changing the format
15+ # requires a SUPER user.
16+ my $vp = new VersionParser();
17+ if ( $vp->version_ge($dbh, '5.1.5') ) {
18+ $sql = 'SELECT @@binlog_format';
19+ PTDEBUG && _d($dbh, $sql);
20+ my ($original_binlog_format) = $dbh->selectrow_array($sql);
21+ PTDEBUG && _d('Original binlog_format:', $original_binlog_format);
22+ if ( $original_binlog_format !~ /STATEMENT/i ) {
23+ $sql = q{/*!50108 SET @@binlog_format := 'STATEMENT'*/};
24+ eval {
25+ PTDEBUG && _d($dbh, $sql);
26+ $dbh->do($sql);
27+ };
28+ if ( $EVAL_ERROR ) {
29+ die "Failed to $sql: $EVAL_ERROR\n"
30+ . "This tool requires binlog_format=STATEMENT, "
31+ . "but the current binlog_format is set to "
32+ ."$original_binlog_format and an error occurred while "
33+ . "attempting to change it. If running MySQL 5.1.29 or newer, "
34+ . "setting binlog_format requires the SUPER privilege. "
35+ . "You will need to manually set binlog_format to 'STATEMENT' "
36+ . "before running this tool.\n";
37+ }
38+ }
39+ }
40
41 if ( $o->get('transaction') ) {
42 my $sql = "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ";

Subscribers

People subscribed via source and target branches