Merge lp:~percona-toolkit-dev/percona-toolkit/pt-table-checksum-fails-on-BINARY-field-in-PK-1381280 into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.14

Proposed by Frank Cizmich
Status: Merged
Approved by: Daniel Nichter
Approved revision: 615
Merged at revision: 615
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/pt-table-checksum-fails-on-BINARY-field-in-PK-1381280
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.14
Diff against target: 115 lines (+42/-13)
2 files modified
bin/pt-table-checksum (+41/-12)
t/pt-table-checksum/progress.t (+1/-1)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-table-checksum-fails-on-BINARY-field-in-PK-1381280
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+255002@code.launchpad.net

Description of the change

Problem:

pt-table-checksum fails on tables where a binary column is used as key. This is because the upper and lower boundary column of the checksum table is of type text and fails when storing these keys.

Solution/Workaround:

Good results have been obtained changing checksum datatype to binary (blob)
Since a foolproof testing of this approach in all cases is very difficult, a less risky compromise approach is used: the --binary-key option is provided and documented so as to permit users to create the checksum table with blob datatype.

To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

PT tries to use "index" instead of "key" because it's a little more proper (CREATE INDEX, not CREATE KEY; --chunk-index; etc.), so I'd suggest --binary-index as the option name.

MySQL columns types are usually written as uppercase...

Revision history for this message
Daniel Nichter (daniel-nichter) :
615. By Frank Cizmich

pt-t-c changed text of warnings and docs. Minor tweak of test for Ubuntu 14

Revision history for this message
Frank Cizmich (frank-cizmich) wrote :

Changed texts and option name as suggested.

Also, unrelated, tweaked progress.t test, which somehow failed on ubuntu 14.04 unless I added a second of delay in one of the tests (both on virtualbox and my own)

Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

s/datatype/data type/g :-) Otherwise fine by me.

review: Approve
616. By Frank Cizmich

minor typo

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 2015-01-23 10:19:56 +0000
3+++ bin/pt-table-checksum 2015-04-07 21:06:09 +0000
4@@ -10866,6 +10866,7 @@
5 }
6 }
7 }
8+
9
10 # USE the correct db (probably the repl db, but maybe --replicate-database).
11 use_repl_db(%args);
12@@ -10888,6 +10889,7 @@
13 . "You need to create the table.\n";
14 }
15
16+
17 # We used to check the table privs here, but:
18 # https://bugs.launchpad.net/percona-toolkit/+bug/916168
19
20@@ -10974,6 +10976,18 @@
21 }
22 }
23
24+ if ( $o->get('binary-index') ) {
25+ PTDEBUG && _d('--binary-index : checking if replicate table has binary type columns');
26+ my $create_table = $tp->get_create_table( $dbh, $db, $tbl );
27+ if ( $create_table !~ /lower_boundary`?\s+BLOB/si
28+ || $create_table !~ /upper_boundary`?\s+BLOB/si )
29+ {
30+ die "--binary-index was specified but the current checksum table ($db.$tbl) uses"
31+ ." TEXT columns. To use BLOB columns, drop the current checksum table, then recreate"
32+ ." it by specifying --create-replicate-table --binary-index.";
33+ }
34+ }
35+
36 return; # success, repl table is ready to go
37 }
38
39@@ -11132,6 +11146,10 @@
40 my $sql = $o->read_para_after(__FILE__, qr/MAGIC_create_replicate/);
41 $sql =~ s/CREATE TABLE checksums/CREATE TABLE IF NOT EXISTS $repl_table/;
42 $sql =~ s/;$//;
43+ if ( $o->get('binary-index') ) {
44+ $sql =~ s/`?lower_boundary`?\s+TEXT/`lower_boundary` BLOB/is;
45+ $sql =~ s/`?upper_boundary`?\s+TEXT/`upper_boundary` BLOB/is;
46+ }
47 PTDEBUG && _d($dbh, $sql);
48 eval {
49 $dbh->do($sql);
50@@ -11808,6 +11826,15 @@
51
52 See "Replicas using row-based replication" under L<"LIMITATIONS">.
53
54+=item --binary-index
55+
56+This option modifies the behavior of L<"--create-replicate-table"> such that the
57+replicate table's upper and lower boundary columns are created with the BLOB
58+data type.
59+This is useful in cases where you have trouble checksuming tables with keys that
60+include a binary data type or that have non-standard character sets.
61+See L<"--replicate">.
62+
63 =item --check-interval
64
65 type: time; default: 1; group: Throttle
66@@ -12342,22 +12369,24 @@
67 structure (MAGIC_create_replicate):
68
69 CREATE TABLE checksums (
70- db char(64) NOT NULL,
71- tbl char(64) NOT NULL,
72- chunk int NOT NULL,
73- chunk_time float NULL,
74- chunk_index varchar(200) NULL,
75- lower_boundary text NULL,
76- upper_boundary text NULL,
77- this_crc char(40) NOT NULL,
78- this_cnt int NOT NULL,
79- master_crc char(40) NULL,
80- master_cnt int NULL,
81- ts timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
82+ db CHAR(64) NOT NULL,
83+ tbl CHAR(64) NOT NULL,
84+ chunk INT NOT NULL,
85+ chunk_time FLOAT NULL,
86+ chunk_index VARCHAR(200) NULL,
87+ lower_boundary TEXT NULL,
88+ upper_boundary TEXT NULL,
89+ this_crc CHAR(40) NOT NULL,
90+ this_cnt INT NOT NULL,
91+ master_crc CHAR(40) NULL,
92+ master_cnt INT NULL,
93+ ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
94 PRIMARY KEY (db, tbl, chunk),
95 INDEX ts_db_tbl (ts, db, tbl)
96 ) ENGINE=InnoDB;
97
98+Note: lower_boundary and upper_boundary data type can be BLOB. See L<"--binary-index">.
99+
100 By default, L<"--[no]create-replicate-table"> is true, so the database and
101 the table specified by this option are created automatically if they do not
102 exist.
103
104=== modified file 't/pt-table-checksum/progress.t'
105--- t/pt-table-checksum/progress.t 2013-03-02 02:02:13 +0000
106+++ t/pt-table-checksum/progress.t 2015-04-07 21:06:09 +0000
107@@ -68,7 +68,7 @@
108 # then starts it again.
109 # TEST_WISHLIST PLUGIN_WISHLIST: do this with a plugin to the tool itself,
110 # not in this unreliable fashion.
111-system("$trunk/util/wait-to-exec '$scripts/wait-for-chunk.sh 12345 sakila city 1' '$scripts/exec-wait-exec.sh 12347 \"stop slave sql_thread\" 2 \"start slave sql_thread\"' 3 >/dev/null &");
112+system("$trunk/util/wait-to-exec '$scripts/wait-for-chunk.sh 12345 sakila city 1' '$scripts/exec-wait-exec.sh 12347 \"stop slave sql_thread\" 2 \"start slave sql_thread\"' 4 >/dev/null &");
113
114 $output = output(
115 sub { pt_table_checksum::main(@args, qw(-d sakila)); },

Subscribers

People subscribed via source and target branches

to all changes: