Merge lp:~percona-toolkit-dev/percona-toolkit/fix-sync-index-bug-1003014 into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 261
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-sync-index-bug-1003014
Merge into: lp:percona-toolkit/2.1
Diff against target: 236 lines (+209/-0)
3 files modified
bin/pt-table-sync (+18/-0)
t/pt-table-sync/bugs.t (+156/-0)
t/pt-table-sync/samples/wrong-tbl-struct-bug-1003014.sql (+35/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-sync-index-bug-1003014
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+106866@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
=== modified file 'bin/pt-table-sync'
--- bin/pt-table-sync 2012-05-21 21:50:40 +0000
+++ bin/pt-table-sync 2012-05-22 17:50:26 +0000
@@ -8035,6 +8035,16 @@
8035 lock_server(src => $src, dst => $dst, %args);8035 lock_server(src => $src, dst => $dst, %args);
80368036
8037 foreach my $diff ( @$diffs ) {8037 foreach my $diff ( @$diffs ) {
8038 # Clear the tbl_struct if this is a new table. The tbl_struct
8039 # is fetched and parsed in ok_to_sync() if not set. We only
8040 # need to set it once per table to avoid doing this for every
8041 # diff in the same table.
8042 # https://bugs.launchpad.net/percona-toolkit/+bug/1003014
8043 if ( ($src->{db} || '') ne $diff->{db}
8044 || ($src->{tbl} || '') ne $diff->{tbl} ) {
8045 PTDEBUG && _d('New table:', $diff->{db}, $diff->{tbl});
8046 $src->{tbl_struct} = undef;
8047 }
8038 $src->{db} = $dst->{db} = $diff->{db};8048 $src->{db} = $dst->{db} = $diff->{db};
8039 $src->{tbl} = $dst->{tbl} = $diff->{tbl};8049 $src->{tbl} = $dst->{tbl} = $diff->{tbl};
80408050
@@ -8103,6 +8113,14 @@
8103 lock_server(src => $src, dst => $dst, %args);8113 lock_server(src => $src, dst => $dst, %args);
81048114
8105 foreach my $diff ( @$diffs ) {8115 foreach my $diff ( @$diffs ) {
8116 # Clear the tbl_struct if this is a new table.
8117 # See the same code block above.
8118 if ( ($src->{db} || '') ne $diff->{db}
8119 || ($src->{tbl} || '') ne $diff->{tbl} ) {
8120 PTDEBUG && _d('New table:',
8121 $diff->{db}, $diff->{tbl});
8122 $src->{tbl_struct} = undef;
8123 }
8106 $src->{db} = $dst->{db} = $diff->{db};8124 $src->{db} = $dst->{db} = $diff->{db};
8107 $src->{tbl} = $dst->{tbl} = $diff->{tbl};8125 $src->{tbl} = $dst->{tbl} = $diff->{tbl};
81088126
81098127
=== added file 't/pt-table-sync/bugs.t'
--- t/pt-table-sync/bugs.t 1970-01-01 00:00:00 +0000
+++ t/pt-table-sync/bugs.t 2012-05-22 17:50:26 +0000
@@ -0,0 +1,156 @@
1#!/usr/bin/env perl
2
3BEGIN {
4 die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5 unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
6 unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
7};
8
9use strict;
10use warnings FATAL => 'all';
11use English qw(-no_match_vars);
12use Test::More;
13use Data::Dumper;
14
15use PerconaTest;
16use Sandbox;
17require "$trunk/bin/pt-table-sync";
18
19my $output;
20my $dp = new DSNParser(opts=>$dsn_opts);
21my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
22my $master_dbh = $sb->get_dbh_for('master');
23my $slave_dbh = $sb->get_dbh_for('slave1');
24
25if ( !$master_dbh ) {
26 plan skip_all => 'Cannot connect to sandbox master';
27}
28elsif ( !$slave_dbh ) {
29 plan skip_all => 'Cannot connect to sandbox slave';
30}
31else {
32 plan tests => 8;
33}
34
35my $sample = "t/pt-table-sync/samples";
36my $master_dsn = "h=127.1,P=12345,u=msandbox,p=msandbox";
37my $slave_dsn = "h=127.1,P=12346,u=msandbox,p=msandbox";
38
39# #############################################################################
40#
41# #############################################################################
42
43$sb->load_file('master', "$sample/wrong-tbl-struct-bug-1003014.sql");
44PerconaTest::wait_for_table($slave_dbh, "test.zzz", "id=111");
45
46# Make a diff in each table.
47$slave_dbh->do("DELETE FROM test.aaa WHERE STOP_ARCHIVE IN (5,6,7)");
48$slave_dbh->do("UPDATE test.zzz SET c='x' WHERE id IN (44,45,46)");
49
50$output = `$trunk/bin/pt-table-checksum $master_dsn --lock-wait-timeout 3 --max-load '' -d test --chunk-size 10 2>&1`;
51
52is(
53 PerconaTest::count_checksum_results($output, 'diffs'),
54 2,
55 "Bug 1003014 (wrong tbl_struct): 2 diffs"
56) or print STDERR $output;
57
58my $checksums = [
59 [qw( test aaa 1 )],
60 [qw( test zzz 1 )],
61 [qw( test zzz 2 )],
62 [qw( test zzz 3 )],
63 [qw( test zzz 4 )],
64 [qw( test zzz 5 )],
65 [qw( test zzz 6 )],
66 [qw( test zzz 7 )],
67 [qw( test zzz 8 )],
68 [qw( test zzz 9 )],
69 [qw( test zzz 10 )],
70 [qw( test zzz 11 )],
71 [qw( test zzz 12 )],
72 [qw( test zzz 13 )],
73 [qw( test zzz 14 )],
74];
75
76my $rows = $master_dbh->selectall_arrayref("SELECT db, tbl, chunk FROM percona.checksums ORDER BY db, tbl, chunk");
77is_deeply(
78 $rows,
79 $checksums,
80 "Bug 1003014 (wrong tbl_struct): checksums"
81);
82
83my $exit_status;
84$output = output(
85 sub { $exit_status = pt_table_sync::main($slave_dsn,
86 qw(--replicate percona.checksums --sync-to-master --print --execute),
87 "--tables", "test.aaa,test.zzz") },
88 stderr => 1,
89);
90
91is(
92 $exit_status,
93 2, # rows synced OK; 3=error (1) & rows synced (2)
94 "Bug 1003014 (wrong tbl_struct): 0 exit"
95) or diag($output);
96
97$rows = $slave_dbh->selectall_arrayref("SELECT c FROM test.zzz WHERE id IN (44,45,46)");
98is_deeply(
99 $rows,
100 [ ['a'], ['a'], ['a'] ],
101 "Bug 1003014 (wrong tbl_struct): synced rows"
102);
103
104# #########################################################################
105# Repeat the whole process without --sync-to-master so the second code path
106# in sync_via_replication() is tested.
107# #########################################################################
108
109$sb->wipe_clean($master_dbh);
110
111$sb->load_file('master', "$sample/wrong-tbl-struct-bug-1003014.sql");
112PerconaTest::wait_for_table($slave_dbh, "test.zzz", "id=111");
113
114$slave_dbh->do("DELETE FROM test.aaa WHERE STOP_ARCHIVE IN (5,6,7)");
115$slave_dbh->do("UPDATE test.zzz SET c='x' WHERE id IN (44,45,46)");
116
117$output = `$trunk/bin/pt-table-checksum $master_dsn --lock-wait-timeout 3 --max-load '' -d test --chunk-size 10 2>&1`;
118
119is(
120 PerconaTest::count_checksum_results($output, 'diffs'),
121 2,
122 "Bug 1003014 (wrong tbl_struct): 2 diffs (just replicate)"
123) or print STDERR $output;
124
125$rows = $master_dbh->selectall_arrayref("SELECT db, tbl, chunk FROM percona.checksums ORDER BY db, tbl, chunk");
126is_deeply(
127 $rows,
128 $checksums,
129 "Bug 1003014 (wrong tbl_struct): checksums (just replicate)"
130);
131
132$output = output(
133 sub { $exit_status = pt_table_sync::main($master_dsn,
134 qw(--replicate percona.checksums --print --execute),
135 "--tables", "test.aaa,test.zzz") },
136 stderr => 1,
137);
138
139is(
140 $exit_status,
141 2, # rows synced OK; 3=error (1) & rows synced (2)
142 "Bug 1003014 (wrong tbl_struct): 0 exit (just replicate)"
143) or diag($output);
144
145$rows = $slave_dbh->selectall_arrayref("SELECT c FROM test.zzz WHERE id IN (44,45,46)");
146is_deeply(
147 $rows,
148 [ ['a'], ['a'], ['a'] ],
149 "Bug 1003014 (wrong tbl_struct): synced rows (just replicate)"
150);
151
152# #############################################################################
153# Done.
154# #############################################################################
155$sb->wipe_clean($master_dbh);
156exit;
0157
=== added file 't/pt-table-sync/samples/wrong-tbl-struct-bug-1003014.sql'
--- t/pt-table-sync/samples/wrong-tbl-struct-bug-1003014.sql 1970-01-01 00:00:00 +0000
+++ t/pt-table-sync/samples/wrong-tbl-struct-bug-1003014.sql 2012-05-22 17:50:26 +0000
@@ -0,0 +1,35 @@
1drop database if exists test;
2create database test;
3use test;
4
5--
6-- Checksum aaa in one chunk, make it differ, sync it first.
7--
8create table aaa (
9 `STOP_ARCHIVE` int(11) NOT NULL default '1',
10 UNIQUE KEY `STOP_ARCHIVE` (`STOP_ARCHIVE`)
11) ENGINE=MyISAM;
12
13insert into aaa values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
14
15--
16-- Checksum zzz in chunks, make a chunk differ, sync it 2nd.
17--
18create table `zzz` (
19 id int not null primary key,
20 c varchar(16) not null
21);
22
23insert into zzz values
24 (1,'a'),(2,'a'),(3,'a'),(4,'a'),(5,'a'),(6,'a'),(7,'a'),(8,'a'),(9,'a'),(10,'a'),
25 (11,'a'),(12,'a'),(13,'a'),(14,'a'),(15,'a'),(16,'a'),(17,'a'),(18,'a'),(19,'a'),(20,'a'),
26 (21,'a'),(22,'a'),(23,'a'),(24,'a'),(25,'a'),(26,'a'),(27,'a'),(28,'a'),(29,'a'),(30,'a'),
27 (31,'a'),(32,'a'),(33,'a'),(34,'a'),(35,'a'),(36,'a'),(37,'a'),(38,'a'),(39,'a'),(40,'a'),
28 (41,'a'),(42,'a'),(43,'a'),(44,'a'),(45,'a'),(46,'a'),(47,'a'),(48,'a'),(49,'a'),(50,'a'),
29 (51,'a'),(52,'a'),(53,'a'),(54,'a'),(55,'a'),(56,'a'),(57,'a'),(58,'a'),(59,'a'),(60,'a'),
30 (61,'a'),(62,'a'),(63,'a'),(64,'a'),(65,'a'),(66,'a'),(67,'a'),(68,'a'),(69,'a'),(70,'a'),
31 (71,'a'),(72,'a'),(73,'a'),(74,'a'),(75,'a'),(76,'a'),(77,'a'),(78,'a'),(79,'a'),(80,'a'),
32 (81,'a'),(82,'a'),(83,'a'),(84,'a'),(85,'a'),(86,'a'),(87,'a'),(88,'a'),(89,'a'),(90,'a'),
33 (91,'a'),(92,'a'),(93,'a'),(94,'a'),(95,'a'),(96,'a'),(97,'a'),(98,'a'),(99,'a'),(100,'a'),
34 (101,'a'),(102,'a'),(103,'a'),(104,'a'),(105,'a'),(106,'a'),(107,'a'),(108,'a'),(109,'a'),(110,'a'),
35 (111, 'a');

Subscribers

People subscribed via source and target branches