Merge lp:~percona-toolkit-dev/percona-toolkit/fix-ptc-diffs-bug-1030031 into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 327
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-ptc-diffs-bug-1030031
Merge into: lp:percona-toolkit/2.1
Diff against target: 126 lines (+65/-6)
3 files modified
bin/pt-table-checksum (+9/-2)
t/pt-table-checksum/bugs.t (+46/-4)
t/pt-table-checksum/samples/a-z.sql (+10/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-ptc-diffs-bug-1030031
Reviewer Review Type Date Requested Status
Brian Fraser (community) Approve
Daniel Nichter Approve
Review via email: mp+117105@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve
330. By Daniel Nichter

Switch bugs.t to use done_testing.

331. By Daniel Nichter

Add code comment to new %diff_chunks code.

Revision history for this message
Brian Fraser (fraserbn) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/pt-table-checksum'
--- bin/pt-table-checksum 2012-07-21 16:13:58 +0000
+++ bin/pt-table-checksum 2012-07-27 17:56:19 +0000
@@ -7690,6 +7690,7 @@
7690 );7690 );
76917691
7692 # Check each slave for checksum diffs.7692 # Check each slave for checksum diffs.
7693 my %diff_chunks;
7693 foreach my $slave ( @$slaves ) {7694 foreach my $slave ( @$slaves ) {
7694 eval {7695 eval {
7695 my $diffs = $rc->find_replication_differences(7696 my $diffs = $rc->find_replication_differences(
@@ -7699,8 +7700,13 @@
7699 );7700 );
7700 PTDEBUG && _d(scalar @$diffs, 'checksum diffs on',7701 PTDEBUG && _d(scalar @$diffs, 'checksum diffs on',
7701 $slave->name());7702 $slave->name());
7702 if ( @$diffs ) {7703 # Save unique chunks that differ.
7703 $tbl->{checksum_results}->{diffs} = scalar @$diffs;7704 # https://bugs.launchpad.net/percona-toolkit/+bug/1030031
7705 if ( scalar @$diffs ) {
7706 # "chunk" is the chunk number. See the SELECT
7707 # statement in RowChecksum::find_replication_differences()
7708 # for the full list of columns.
7709 map { $diff_chunks{ $_->{chunk} }++ } @$diffs;
7704 }7710 }
7705 };7711 };
7706 if ($EVAL_ERROR) {7712 if ($EVAL_ERROR) {
@@ -7714,6 +7720,7 @@
7714 $tbl->{checksum_results}->{errors}++;7720 $tbl->{checksum_results}->{errors}++;
7715 }7721 }
7716 }7722 }
7723 $tbl->{checksum_results}->{diffs} = scalar keys %diff_chunks;
7717 }7724 }
77187725
7719 # Print table's checksum results if we're not being quiet,7726 # Print table's checksum results if we're not being quiet,
77207727
=== modified file 't/pt-table-checksum/bugs.t'
--- t/pt-table-checksum/bugs.t 2012-06-07 14:25:44 +0000
+++ t/pt-table-checksum/bugs.t 2012-07-27 17:56:19 +0000
@@ -29,16 +29,17 @@
29my $dp = new DSNParser(opts=>$dsn_opts);29my $dp = new DSNParser(opts=>$dsn_opts);
30my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);30my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
31my $master_dbh = $sb->get_dbh_for('master');31my $master_dbh = $sb->get_dbh_for('master');
32my $slave_dbh = $sb->get_dbh_for('slave1');32my $slave1_dbh = $sb->get_dbh_for('slave1');
33my $slave2_dbh = $sb->get_dbh_for('slave2');
3334
34if ( !$master_dbh ) {35if ( !$master_dbh ) {
35 plan skip_all => 'Cannot connect to sandbox master';36 plan skip_all => 'Cannot connect to sandbox master';
36}37}
37elsif ( !$slave_dbh ) {38elsif ( !$slave1_dbh ) {
38 plan skip_all => 'Cannot connect to sandbox slave1';39 plan skip_all => 'Cannot connect to sandbox slave1';
39}40}
40else {41elsif ( !$slave2_dbh ) {
41 plan tests => 8;42 plan skip_all => 'Cannot connect to sandbox slave2';
42}43}
4344
44# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic45# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
@@ -135,8 +136,49 @@
135);136);
136137
137# #############################################################################138# #############################################################################
139# https://bugs.launchpad.net/percona-toolkit/+bug/1030031
140# pt-table-checksum reports wrong number of DIFFS
141# #############################################################################
142$sb->load_file('master', "$sample/a-z.sql");
143$sb->wait_for_slaves();
144
145# Create 2 diffs on slave1 and 1 diff on slave2.
146$slave1_dbh->do("UPDATE test.t SET c='' WHERE id=5"); # diff on slave1 & 2
147$slave1_dbh->do("SET SQL_LOG_BIN=0");
148$slave1_dbh->do("UPDATE test.t SET c='' WHERE id=20"); # diff only on slave1
149
150# Restore sql_log_bin on slave1 in case later tests use it.
151$slave1_dbh->do("SET SQL_LOG_BIN=1");
152
153$output = output(
154 sub { pt_table_checksum::main(@args, qw(-t test.t --chunk-size 10)) },
155);
156
157is(
158 PerconaTest::count_checksum_results($output, 'diffs'),
159 2,
160 "Bug 1030031 (wrong DIFFS): 2 diffs"
161);
162
163# Restore slave2, but then give it 1 diff that's not the same chunk#
164# as slave1, so there's 3 unique chunk that differ.
165$slave2_dbh->do("UPDATE test.t SET c='e' WHERE id=5");
166$slave2_dbh->do("UPDATE test.t SET c='' WHERE id=26");
167
168$output = output(
169 sub { pt_table_checksum::main(@args, qw(-t test.t --chunk-size 10)) },
170);
171
172is(
173 PerconaTest::count_checksum_results($output, 'diffs'),
174 3,
175 "Bug 1030031 (wrong DIFFS): 3 diffs"
176);
177
178# #############################################################################
138# Done.179# Done.
139# #############################################################################180# #############################################################################
140$sb->wipe_clean($master_dbh);181$sb->wipe_clean($master_dbh);
141ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");182ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
183done_testing;
142exit;184exit;
143185
=== added file 't/pt-table-checksum/samples/a-z.sql'
--- t/pt-table-checksum/samples/a-z.sql 1970-01-01 00:00:00 +0000
+++ t/pt-table-checksum/samples/a-z.sql 2012-07-27 17:56:19 +0000
@@ -0,0 +1,10 @@
1drop database if exists test;
2create database test;
3use test;
4
5create table t (
6 id int auto_increment primary key,
7 c varchar(16) not null
8) engine=innodb;
9
10insert into t values (null, 'a'),(null, 'b'),(null, 'c'),(null, 'd'),(null, 'e'),(null, 'f'),(null, 'g'),(null, 'h'),(null, 'i'),(null, 'j'),(null, 'k'),(null, 'l'),(null, 'm'),(null, 'n'),(null, 'o'),(null, 'p'),(null, 'q'),(null, 'r'),(null, 's'),(null, 't'),(null, 'u'),(null, 'v'),(null, 'w'),(null, 'x'),(null, 'y'),(null, 'z');

Subscribers

People subscribed via source and target branches