Merge lp:~percona-toolkit-dev/percona-toolkit/pt-slave-restart-gtid-support-tweaks into lp:~gryp/percona-toolkit/pt-slave-restart-gtid-support
- pt-slave-restart-gtid-support-tweaks
- Merge into pt-slave-restart-gtid-support
Proposed by
Daniel Nichter
Status: | Merged |
---|---|
Approved by: | Kenny Gryp |
Approved revision: | 604 |
Merged at revision: | 604 |
Proposed branch: | lp:~percona-toolkit-dev/percona-toolkit/pt-slave-restart-gtid-support-tweaks |
Merge into: | lp:~gryp/percona-toolkit/pt-slave-restart-gtid-support |
Diff against target: |
535 lines (+187/-156) 5 files modified
bin/pt-slave-restart (+60/-71) lib/Sandbox.pm (+1/-0) sandbox/test-env (+10/-7) t/pt-slave-restart/gtid.t (+115/-78) util/checksum-test-dataset (+1/-0) |
To merge this branch: | bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-slave-restart-gtid-support-tweaks |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Kenny Gryp | Approve | ||
Review via email: mp+221293@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/pt-slave-restart' |
2 | --- bin/pt-slave-restart 2014-04-30 14:53:04 +0000 |
3 | +++ bin/pt-slave-restart 2014-05-28 20:34:17 +0000 |
4 | @@ -4982,8 +4982,8 @@ |
5 | $start_sql .= " UNTIL RELAY_LOG_FILE = '$file', RELAY_LOG_POS = $pos"; |
6 | } |
7 | |
8 | - my $start = $dbh->prepare($start_sql); |
9 | - my $stop = $dbh->prepare('STOP SLAVE'); |
10 | + my $start = $dbh->prepare($start_sql); |
11 | + my $stop = $dbh->prepare('STOP SLAVE'); |
12 | |
13 | # ######################################################################## |
14 | # Detect if GTID is enabled. Skipping an event is done differently. |
15 | @@ -4991,27 +4991,25 @@ |
16 | # When MySQL 5.6.5 or higher is used and gtid is enabled, skipping a |
17 | # transaction is not possible with SQL_SLAVE_SKIP_COUNTER |
18 | my $skip_event; |
19 | - my $gtid_mode; |
20 | - |
21 | + my $have_gtid = 0; |
22 | if ( VersionParser->new($dbh) >= '5.6.5' ) { |
23 | - my $row = $dbh->selectrow_arrayref('SELECT @@GLOBAL.gtid_mode'); |
24 | - $gtid_mode = $row->[0]; |
25 | - } else { |
26 | - $gtid_mode="N/A"; |
27 | + my $row = $dbh->selectrow_arrayref('SELECT @@GLOBAL.gtid_mode'); |
28 | + PTDEBUG && _d('@@GLOBAL.gtid_mode:', $row->[0]); |
29 | + if ( $row && $row->[0] eq 'ON' ) { |
30 | + $have_gtid = 1; |
31 | + } |
32 | } |
33 | - PTDEBUG && _d('GTID is ' . ($gtid_mode eq 'ON' |
34 | - ? 'enabled' |
35 | - : 'disabled')); |
36 | + PTDEBUG && _d('Have GTID:', $have_gtid); |
37 | |
38 | # If GTID is enabled, slave_parallel_workers should be == 0. |
39 | - # it's currently not possible to know what GTID event the failed trx is |
40 | - if ( $gtid_mode eq 'ON') { |
41 | - my $threads = $dbh->selectrow_hashref('SELECT |
42 | - @@GLOBAL.slave_parallel_workers AS threads'); |
43 | + # It's currently not possible to know what GTID event the failed trx is. |
44 | + if ( $have_gtid ) { |
45 | + my $threads = $dbh->selectrow_hashref( |
46 | + 'SELECT @@GLOBAL.slave_parallel_workers AS threads'); |
47 | if ( $threads->{threads} > 0 ) { |
48 | - die("Error: GTID is enabled, and slave_parallel_workers=" |
49 | - . $threads->{threads} |
50 | - . ". It is impossible to skip transactions properly.\n"); |
51 | + die "Cannot skip transactions properly because GTID is enabled " |
52 | + . "and slave_parallel_workers > 0. See 'GLOBAL TRANSACTION IDS' " |
53 | + . "in the tool's documentation.\n"; |
54 | } |
55 | } |
56 | |
57 | @@ -5023,9 +5021,7 @@ |
58 | [ qr/Could not parse relay log event entry/ => 'refetch_relay_log' ], |
59 | [ qr/Incorrect key file for table/ => 'repair_table' ], |
60 | # This must be the last one. It's a catch-all rule: skip and restart. |
61 | - [ qr/./ => ($gtid_mode eq 'ON' |
62 | - ? 'skip_gtid' |
63 | - : 'skip') ], |
64 | + [ qr/./ => ($have_gtid ? 'skip_gtid' : 'skip') ], |
65 | ); |
66 | |
67 | # ######################################################################## |
68 | @@ -5054,6 +5050,14 @@ |
69 | }, |
70 | skip_gtid => sub { |
71 | my ( $stat, $dbh ) = @_; |
72 | + |
73 | + # Get master_uuid from SHOW SLAVE STATUS if a UUID is not specified |
74 | + # with --master-uuid. |
75 | + my $gtid_uuid = $o->get('master-uuid'); |
76 | + if ( !$gtid_uuid ) { |
77 | + $gtid_uuid = $stat->{master_uuid}; |
78 | + die "No master_uuid" unless $gtid_uuid; # shouldn't happen |
79 | + } |
80 | |
81 | # We need the highest transaction in the executed_gtid_set. |
82 | # and then we need to increase it by 1 (the one we want to skip) |
83 | @@ -5062,54 +5066,38 @@ |
84 | # - it skips the next transaction from the master_uuid |
85 | # (when a slaveB is replicating from slaveA, |
86 | # the master_uuid is it's own master, slaveA) |
87 | - my $gtid_exec = $stat->{executed_gtid_set}; |
88 | - |
89 | - # default behavior is to take the master_uuid from SHOW SLAVE STATUS |
90 | - # or use --skip-gtid-uuid specified uuid. |
91 | - my $gtid_uuid; |
92 | - if ( $o->get('skip-gtid-uuid') eq 'master' ) { |
93 | - $gtid_uuid = $stat->{master_uuid}; |
94 | - } else { |
95 | - $gtid_uuid = $o->get('skip-gtid-uuid'); |
96 | - } |
97 | - |
98 | - $gtid_exec =~ /$gtid_uuid([0-9-:]*)/; |
99 | - my $gtid_exec_ids = $1; |
100 | - $gtid_exec_ids =~ s/:[0-9]-/:/g; |
101 | + my ($gtid_exec_ids) = ($stat->{executed_gtid_set} || '') =~ m/$gtid_uuid([0-9-:]*)/; |
102 | + $gtid_exec_ids =~ s/:[0-9]-/:/g; |
103 | + die "No executed GTIDs" unless $gtid_exec_ids; |
104 | |
105 | my @gtid_exec_ranges = split(/:/, $gtid_exec_ids); |
106 | - delete $gtid_exec_ranges[0]; # undef the first value,it's always empty |
107 | + delete $gtid_exec_ranges[0]; # undef the first value, it's always empty |
108 | |
109 | - # get the highest id by sorting the array, removing the undef value |
110 | + # Get the highest id by sorting the array, removing the undef value. |
111 | my @gtid_exec_sorted = sort { $a <=> $b } |
112 | grep { defined($_) } @gtid_exec_ranges; |
113 | my $gtid_exec_last = $gtid_exec_sorted[-1]; |
114 | |
115 | - PTDEBUG && _d("GTID: master_uuid:$gtid_uuid,\n" |
116 | - . "GTID: executed_gtid_set:$gtid_exec,\n" |
117 | - . "GTID: gtid max for master_uuid:" . $gtid_exec_sorted[-1] . "\n" |
118 | - . "GTID: last executed gtid:'$gtid_uuid:$gtid_exec_last'"); |
119 | + PTDEBUG && _d("\n", |
120 | + "GTID: master_uuid:", $gtid_uuid, "\n", |
121 | + "GTID: executed_gtid_set:", $gtid_exec_ids, "\n", |
122 | + "GTID: max for master_uuid:", $gtid_exec_sorted[-1], "\n", |
123 | + "GTID: last executed gtid:", $gtid_uuid, ":", $gtid_exec_last); |
124 | |
125 | # Set the sessions next gtid, write an empty transaction |
126 | - my $skipped=0; |
127 | - until ( $skipped == $o->get('skip-count') ) { |
128 | - $skipped++; |
129 | - |
130 | - my $gtid_next=$gtid_exec_last + $skipped; |
131 | - |
132 | - PTDEBUG && _d("GTID: Skipping " . $gtid_uuid . ":" . $gtid_next); |
133 | - |
134 | - my $gtid_set_next = $dbh->prepare("SET GTID_NEXT='" |
135 | - . $gtid_uuid . ":" . $gtid_next . "'"); |
136 | - $gtid_set_next->execute(); |
137 | + my $skipped = 0; |
138 | + while ( $skipped++ < $o->get('skip-count') ) { |
139 | + my $gtid_next = $gtid_exec_last + $skipped; |
140 | + my $sql = "SET GTID_NEXT='$gtid_uuid:$gtid_next'"; |
141 | + PTDEBUG && _d($sql); |
142 | + my $sth = $dbh->prepare($sql); |
143 | + $sth->execute(); |
144 | $dbh->begin_work(); |
145 | $dbh->commit(); |
146 | - |
147 | } |
148 | |
149 | # Set the session back to the automatically generated GTID_NEXT. |
150 | - my $gtid_automatic = $dbh->prepare("SET GTID_NEXT='AUTOMATIC'"); |
151 | - $gtid_automatic->execute(); |
152 | + $dbh->do("SET GTID_NEXT='AUTOMATIC'"); |
153 | }, |
154 | repair_table => sub { |
155 | my ( $stat, $dbh ) = @_; |
156 | @@ -5399,25 +5387,23 @@ |
157 | |
158 | =head1 GLOBAL TRANSACTION IDS |
159 | |
160 | -pt-slave-restart supports Global Transaction IDs, which has been introduced in |
161 | -MySQL in 5.6.5. |
162 | - |
163 | -It's important to keep in mind that: |
164 | +As of Percona Toolkit 2.2.8, pt-slave-restart supports Global Transaction IDs |
165 | +introduced in MySQL 5.6.5. It's important to keep in mind that: |
166 | |
167 | =over |
168 | |
169 | =item * |
170 | |
171 | pt-slave-restart will not skip transactions when multiple replication threads |
172 | -are being used (slave_parallel_workers>0). pt-slave-restart does not know what |
173 | -the GTID event is of the failed transaction of a specific slave thread. |
174 | +are being used (slave_parallel_workers > 0). pt-slave-restart does not know |
175 | +what the GTID event is of the failed transaction of a specific slave thread. |
176 | |
177 | =item * |
178 | |
179 | The default behavior is to skip the next transaction from the slave's master. |
180 | -Writes can originate on different servers, each with their own unique UUID. |
181 | +Writes can originate on different servers, each with their own UUID. |
182 | |
183 | -See L<"--skip-gtid-uuid">. |
184 | +See L<"--master-uuid">. |
185 | |
186 | =back |
187 | |
188 | @@ -5675,20 +5661,23 @@ |
189 | |
190 | Number of statements to skip when restarting the slave. |
191 | |
192 | -=item --skip-gtid-uuid |
193 | +=item --master-uuid |
194 | |
195 | -type: string; default: master |
196 | +type: string |
197 | |
198 | When using GTID, an empty transaction should be created in order to skip it. |
199 | If writes are coming from different nodes in the replication tree above, it is |
200 | not possible to know which event from which UUID to skip. |
201 | |
202 | -By default, the UUID from the slave's master is being used to skip. |
203 | -(C<SHOW GLOBAL STATUS Master_UUID> column). |
204 | - |
205 | -Example: Master -> Slave1 -> Slave2. When skipping events from 'Slave2', and |
206 | -writes originated from 'Master', --skip-gtid-uuid should be specified with the |
207 | -'Master' it's UUID. |
208 | +By default, transactions from the slave's master (C<'Master_UUID'> from |
209 | +C<SHOW SLAVE STATUS>) are skipped. |
210 | + |
211 | +For example, with |
212 | + |
213 | + master1 -> slave1 -> slave2 |
214 | + |
215 | +When skipping events on slave2 that were written to master1, you must specify |
216 | +the UUID of master1, else the tool will use the UUID of slave1 by default. |
217 | |
218 | See L<"GLOBAL TRANSACTION IDS">. |
219 | |
220 | |
221 | === modified file 'lib/Sandbox.pm' |
222 | --- lib/Sandbox.pm 2013-08-12 21:19:57 +0000 |
223 | +++ lib/Sandbox.pm 2014-05-28 20:34:17 +0000 |
224 | @@ -379,6 +379,7 @@ |
225 | # Diff the two sets of checksums: host to master (ref). |
226 | my @diffs; |
227 | foreach my $c ( @checksums ) { |
228 | + next unless $c->{checksum}; |
229 | if ( $c->{checksum} ne $ref->{$c->{table}}->{checksum} ) { |
230 | push @diffs, $c->{table}; |
231 | } |
232 | |
233 | === modified file 'sandbox/test-env' |
234 | --- sandbox/test-env 2013-03-07 21:17:01 +0000 |
235 | +++ sandbox/test-env 2014-05-28 20:34:17 +0000 |
236 | @@ -315,13 +315,16 @@ |
237 | fi |
238 | |
239 | if [ $? -eq 0 -a "$MYSQL_VERSION" '>' "4.1" ]; then |
240 | - echo -n "Loading sakila database... " |
241 | - ./load-sakila-db 12345 "${2:-""}" |
242 | - exit_status=$((exit_status | $?)) |
243 | - if [ $exit_status -ne 0 ]; then |
244 | - echo "FAILED" |
245 | - else |
246 | - echo "OK" |
247 | + SAKILA=${SAKILA:-1} |
248 | + if [ $SAKILA -eq 1 ]; then |
249 | + echo -n "Loading sakila database... " |
250 | + ./load-sakila-db 12345 "${2:-""}" |
251 | + exit_status=$((exit_status | $?)) |
252 | + if [ $exit_status -ne 0 ]; then |
253 | + echo "FAILED" |
254 | + else |
255 | + echo "OK" |
256 | + fi |
257 | fi |
258 | |
259 | # Create percona_test db and checksum all the tables. |
260 | |
261 | === modified file 't/pt-slave-restart/gtid.t' |
262 | --- t/pt-slave-restart/gtid.t 2014-04-30 14:53:04 +0000 |
263 | +++ t/pt-slave-restart/gtid.t 2014-05-28 20:34:17 +0000 |
264 | @@ -16,69 +16,119 @@ |
265 | require "$trunk/bin/pt-slave-restart"; |
266 | |
267 | if ( $sandbox_version lt '5.6' ) { |
268 | - plan skip_all => 'MySQL Version ' . $sandbox_version |
269 | - . ' < 5.6, GTID is not available, skipping tests'; |
270 | + plan skip_all => "Requires MySQL 5.6"; |
271 | } |
272 | |
273 | -diag("Stopping/reconfiguring/restarting sandboxes 12345, 12346 and 12347"); |
274 | - |
275 | -diag(`$trunk/sandbox/test-env stop >/dev/null`); |
276 | -diag(`GTID=1 $trunk/sandbox/test-env start >/dev/null`); |
277 | +diag(`SAKILA=0 GTID=1 $trunk/sandbox/test-env restart`); |
278 | |
279 | my $dp = new DSNParser(opts=>$dsn_opts); |
280 | my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); |
281 | -my $master_dbh = $sb->get_dbh_for('master'); |
282 | -my $slave_dbh = $sb->get_dbh_for('slave1'); |
283 | -my $slave2_dbh = $sb->get_dbh_for('slave2'); |
284 | +my $master_dbh = $sb->get_dbh_for('master'); |
285 | +my $slave1_dbh = $sb->get_dbh_for('slave1'); |
286 | +my $slave2_dbh = $sb->get_dbh_for('slave2'); |
287 | |
288 | if ( !$master_dbh ) { |
289 | plan skip_all => 'Cannot connect to sandbox master'; |
290 | } |
291 | -elsif ( !$slave_dbh ) { |
292 | +elsif ( !$slave1_dbh ) { |
293 | plan skip_all => 'Cannot connect to sandbox slave1'; |
294 | } |
295 | elsif ( !$slave2_dbh ) { |
296 | plan skip_all => 'Cannot connect to sandbox slave2'; |
297 | } |
298 | |
299 | -# ############################################################################# |
300 | -# basic test to see if restart works |
301 | -# ############################################################################# |
302 | +my $slave1_dsn = $sb->dsn_for("slave1"); |
303 | +my $slave2_dsn = $sb->dsn_for("slave2"); |
304 | + |
305 | +my $pid_file = "/tmp/pt-slave-restart-test-$PID.pid"; |
306 | +my $log_file = "/tmp/pt-slave-restart-test-$PID.log"; |
307 | +my $cmd = "$trunk/bin/pt-slave-restart --daemonize --run-time 5 --max-sleep .25 --pid $pid_file --log $log_file"; |
308 | + |
309 | +sub start { |
310 | + my ( $extra ) = @_; |
311 | + stop() or return; |
312 | + system "$cmd $extra"; |
313 | + PerconaTest::wait_for_files($pid_file); |
314 | +} |
315 | + |
316 | +sub stop() { |
317 | + return 1 if !is_running(); |
318 | + diag(`$trunk/bin/pt-slave-restart --stop -q >/dev/null 2>&1 &`); |
319 | + wait_until(sub { !-f $pid_file }, 0.3, 2); |
320 | + diag(`rm -f /tmp/pt-slave-restart-sentinel`); |
321 | + return is_running() ? 0 : 1; |
322 | +} |
323 | + |
324 | +sub is_running { |
325 | + chomp(my $running = `ps -eaf | grep -v grep | grep '$cmd'`); |
326 | + if (!-f $pid_file && !$running) { |
327 | + return 0; |
328 | + } elsif (-f $pid_file && !$running) { |
329 | + diag(`rm -f $pid_file`); |
330 | + return 0; |
331 | + } |
332 | + return 1; |
333 | +} |
334 | + |
335 | +sub wait_repl_broke { |
336 | + my $dbh = shift; |
337 | + return wait_until( |
338 | + sub { |
339 | + my $row = $dbh->selectrow_hashref('show slave status'); |
340 | + return $row->{last_sql_errno}; |
341 | + } |
342 | + ); |
343 | +} |
344 | + |
345 | +sub wait_repl_ok { |
346 | + my $dbh = shift; |
347 | + wait_until( |
348 | + sub { |
349 | + my $row = $dbh->selectrow_hashref('show slave status'); |
350 | + return $row->{last_sql_errno} == 0; |
351 | + }, |
352 | + 0.30, |
353 | + 5, |
354 | + ); |
355 | +} |
356 | + |
357 | +# ############################################################################# |
358 | +# Basic test to see if restart works with GTID. |
359 | +# ############################################################################# |
360 | + |
361 | $master_dbh->do('DROP DATABASE IF EXISTS test'); |
362 | $master_dbh->do('CREATE DATABASE test'); |
363 | $master_dbh->do('CREATE TABLE test.t (a INT)'); |
364 | $sb->wait_for_slaves; |
365 | |
366 | # Bust replication |
367 | -$slave_dbh->do('DROP TABLE test.t'); |
368 | +$slave1_dbh->do('DROP TABLE test.t'); |
369 | $master_dbh->do('INSERT INTO test.t SELECT 1'); |
370 | -wait_until( |
371 | - sub { |
372 | - my $row = $slave_dbh->selectrow_hashref('show slave status'); |
373 | - return $row->{last_sql_errno}; |
374 | - } |
375 | -); |
376 | +wait_repl_broke($slave1_dbh) or die "Failed to break replication"; |
377 | |
378 | -my $r = $slave_dbh->selectrow_hashref('show slave status'); |
379 | +my $r = $slave1_dbh->selectrow_hashref('show slave status'); |
380 | like($r->{last_error}, qr/Table 'test.t' doesn't exist'/, 'slave: Replication broke'); |
381 | |
382 | -# Start an instance |
383 | -diag(`$trunk/bin/pt-slave-restart --max-sleep .25 -h 127.0.0.1 -P 12346 -u msandbox -p msandbox --daemonize --pid /tmp/pt-slave-restart.pid --log /tmp/pt-slave-restart.log`); |
384 | -sleep 1; |
385 | - |
386 | -$r = $slave_dbh->selectrow_hashref('show slave status'); |
387 | -like($r->{last_errno}, qr/^0$/, 'slave: event is not skipped successfully'); |
388 | - |
389 | - |
390 | -diag(`$trunk/bin/pt-slave-restart --stop -q`); |
391 | -sleep 1; |
392 | -my $output = `ps -eaf | grep pt-slave-restart | grep -v grep`; |
393 | -unlike($output, qr/pt-slave-restart --max/, 'slave: stopped pt-slave-restart successfully'); |
394 | -diag(`rm -f /tmp/pt-slave-re*`); |
395 | - |
396 | -# ############################################################################# |
397 | -# test the slave of the master |
398 | -# ############################################################################# |
399 | +# Start pt-slave-restart and wait up to 5s for it to fix replication |
400 | +# (it should take < 1s but tests can be really slow sometimes). |
401 | +start("$slave1_dsn") or die "Failed to start pt-slave-restart"; |
402 | +wait_repl_ok($slave1_dbh); |
403 | + |
404 | +# Check if replication is fixed. |
405 | +$r = $slave1_dbh->selectrow_hashref('show slave status'); |
406 | +like( |
407 | + $r->{last_errno}, |
408 | + qr/^0$/, |
409 | + 'Event is skipped', |
410 | +) or BAIL_OUT("Replication is broken"); |
411 | + |
412 | +# Stop pt-slave-restart. |
413 | +stop() or die "Failed to stop pt-slave-restart"; |
414 | + |
415 | +# ############################################################################# |
416 | +# Test the slave of the master. |
417 | +# ############################################################################# |
418 | + |
419 | $master_dbh->do('DROP DATABASE IF EXISTS test'); |
420 | $master_dbh->do('CREATE DATABASE test'); |
421 | $master_dbh->do('CREATE TABLE test.t (a INT)'); |
422 | @@ -87,12 +137,7 @@ |
423 | # Bust replication |
424 | $slave2_dbh->do('DROP TABLE test.t'); |
425 | $master_dbh->do('INSERT INTO test.t SELECT 1'); |
426 | -wait_until( |
427 | - sub { |
428 | - my $row = $slave2_dbh->selectrow_hashref('show slave status'); |
429 | - return $row->{last_sql_errno}; |
430 | - } |
431 | -); |
432 | +wait_repl_broke($slave2_dbh) or die "Failed to break replication"; |
433 | |
434 | # fetch the master uuid, which is the machine we need to skip an event from |
435 | $r = $master_dbh->selectrow_hashref('select @@GLOBAL.server_uuid as uuid'); |
436 | @@ -102,22 +147,22 @@ |
437 | like($r->{last_error}, qr/Table 'test.t' doesn't exist'/, 'slaveofslave: Replication broke'); |
438 | |
439 | # Start an instance |
440 | -diag(`$trunk/bin/pt-slave-restart --skip-gtid-uuid=$uuid --max-sleep .25 -h 127.0.0.1 -P 12347 -u msandbox -p msandbox --daemonize --pid /tmp/pt-slave-restart.pid --log /tmp/pt-slave-restart.log`); |
441 | -sleep 1; |
442 | +start("--master-uuid=$uuid $slave2_dsn") or die; |
443 | +wait_repl_ok($slave2_dbh); |
444 | |
445 | $r = $slave2_dbh->selectrow_hashref('show slave status'); |
446 | -like($r->{last_errno}, qr/^0$/, 'slaveofslave: event is not skipped successfully'); |
447 | - |
448 | - |
449 | -diag(`$trunk/bin/pt-slave-restart --stop -q`); |
450 | -sleep 1; |
451 | -$output = `ps -eaf | grep pt-slave-restart | grep -v grep`; |
452 | -unlike($output, qr/pt-slave-restart --max/, 'slaveofslave: stopped pt-slave-restart successfully'); |
453 | -diag(`rm -f /tmp/pt-slave-re*`); |
454 | - |
455 | -# ############################################################################# |
456 | -# test skipping 2 events in a row. |
457 | -# ############################################################################# |
458 | +like( |
459 | + $r->{last_errno}, |
460 | + qr/^0$/, |
461 | + 'Skips event from master on slave2' |
462 | +) or BAIL_OUT("Replication is broken"); |
463 | + |
464 | +stop() or die "Failed to stop pt-slave-restart"; |
465 | + |
466 | +# ############################################################################# |
467 | +# Test skipping 2 events in a row. |
468 | +# ############################################################################# |
469 | + |
470 | $master_dbh->do('DROP DATABASE IF EXISTS test'); |
471 | $master_dbh->do('CREATE DATABASE test'); |
472 | $master_dbh->do('CREATE TABLE test.t (a INT)'); |
473 | @@ -127,12 +172,7 @@ |
474 | $slave2_dbh->do('DROP TABLE test.t'); |
475 | $master_dbh->do('INSERT INTO test.t SELECT 1'); |
476 | $master_dbh->do('INSERT INTO test.t SELECT 1'); |
477 | -wait_until( |
478 | - sub { |
479 | - my $row = $slave2_dbh->selectrow_hashref('show slave status'); |
480 | - return $row->{last_sql_errno}; |
481 | - } |
482 | -); |
483 | +wait_repl_broke($slave2_dbh) or die "Failed to break replication"; |
484 | |
485 | # fetch the master uuid, which is the machine we need to skip an event from |
486 | $r = $master_dbh->selectrow_hashref('select @@GLOBAL.server_uuid as uuid'); |
487 | @@ -142,25 +182,22 @@ |
488 | like($r->{last_error}, qr/Table 'test.t' doesn't exist'/, 'slaveofslaveskip2: Replication broke'); |
489 | |
490 | # Start an instance |
491 | -diag(`$trunk/bin/pt-slave-restart --skip-count=2 --skip-gtid-uuid=$uuid --max-sleep .25 -h 127.0.0.1 -P 12347 -u msandbox -p msandbox --daemonize --pid /tmp/pt-slave-restart.pid --log /tmp/pt-slave-restart.log`); |
492 | -sleep 1; |
493 | +start("--skip-count=2 --master-uuid=$uuid $slave2_dsn") or die; |
494 | +wait_repl_ok($slave2_dbh); |
495 | |
496 | $r = $slave2_dbh->selectrow_hashref('show slave status'); |
497 | -like($r->{last_errno}, qr/^0$/, 'slaveofslaveskip2: event is not skipped successfully'); |
498 | - |
499 | - |
500 | -diag(`$trunk/bin/pt-slave-restart --stop -q`); |
501 | -sleep 1; |
502 | -$output = `ps -eaf | grep pt-slave-restart | grep -v grep`; |
503 | -unlike($output, qr/pt-slave-restart --max/, 'slaveofslaveskip2: stopped pt-slave-restart successfully'); |
504 | -diag(`rm -f /tmp/pt-slave-re*`); |
505 | +like( |
506 | + $r->{last_errno}, |
507 | + qr/^0$/, |
508 | + 'Skips multiple events' |
509 | +) or BAIL_OUT("Replication is broken"); |
510 | + |
511 | +stop() or die "Failed to stop pt-slave-restart"; |
512 | |
513 | # ############################################################################# |
514 | # Done. |
515 | # ############################################################################# |
516 | -diag(`rm -f /tmp/pt-slave-re*`); |
517 | -diag(`$trunk/sandbox/test-env stop >/dev/null`); |
518 | -diag(`$trunk/sandbox/test-env start >/dev/null`); |
519 | - |
520 | +diag(`rm -f $pid_file $log_file >/dev/null`); |
521 | +diag(`$trunk/sandbox/test-env restart`); |
522 | ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); |
523 | done_testing; |
524 | |
525 | === modified file 'util/checksum-test-dataset' |
526 | --- util/checksum-test-dataset 2013-02-19 00:28:12 +0000 |
527 | +++ util/checksum-test-dataset 2014-05-28 20:34:17 +0000 |
528 | @@ -61,6 +61,7 @@ |
529 | . join(", ", map { "sakila.$_" } @tables_in_sakila); |
530 | my @checksums = @{$dbh->selectall_arrayref($sql, {Slice => {} })}; |
531 | foreach my $c ( @checksums ) { |
532 | + next unless $c->{Checksum}; |
533 | $dbh->do("INSERT INTO percona_test.checksums(db_tbl, checksum) |
534 | VALUES('$c->{Table}', $c->{Checksum})"); |
535 | } |
Looks great! Sorry you had to rewrite so much.