16
16
require "$trunk/bin/pt-table-checksum";
18
diag(`$trunk/sandbox/test-env reset`);
19
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
20
diag(`$trunk/sandbox/start-sandbox slave 12347 12346 >/dev/null`);
22
18
my $dp = new DSNParser(opts=>$dsn_opts);
23
19
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
24
20
my $master_dbh = $sb->get_dbh_for('master');
37
# Must have empty checksums table for these tests.
38
$master_dbh->do('drop table if exists percona.checksums');
40
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
41
# so we need to specify --lock-wait-timeout=3 else the tool will die.
42
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
43
my @args = ($master_dsn, qw(--lock-wait-timeout 3),
44
'--progress', 'time,1');
43
my $cnf ='/tmp/12345/my.sandbox.cnf';
44
my @args = (qw(--replicate test.checksum --empty-replicate-table -d test -t resume -q), '-F', $cnf, 'h=127.1', '--progress', 'time,1');
46
$sb->create_dbs($master_dbh, [qw(test)]);
47
$sb->load_file('master', 't/pt-table-checksum/samples/checksum_tbl.sql');
48
# We're not using resume table for anything specific, we just need
49
# any table to checksum.
50
$sb->load_file('master', 't/pt-table-checksum/samples/resume.sql');
47
my $scripts = "$trunk/t/pt-table-checksum/scripts/";
49
# ############################################################################
50
# Tool should check all slaves' lag, so slave2, not just slave1.
51
# ############################################################################
52
52
wait_until( # slaves aren't lagging
54
54
$row = $slave1_dbh->selectrow_hashref('show slave status');
56
56
$row = $slave2_dbh->selectrow_hashref('show slave status');
57
57
return 0 if $row->{Seconds_Behind_Master};
61
$slave1_dbh->do('stop slave sql_thread');
62
$row = $slave1_dbh->selectrow_hashref('show slave status');
64
$row->{slave_sql_running},
66
'Stopped slave SQL thread on slave1'
69
$slave2_dbh->do('stop slave sql_thread');
70
$row = $slave2_dbh->selectrow_hashref('show slave status');
72
$row->{slave_sql_running},
74
'Stopped slave SQL thread on slave2'
77
system("sleep 2 && /tmp/12346/use -e 'start slave sql_thread' >/dev/null 2>/dev/null &");
78
system("sleep 3 && /tmp/12347/use -e 'start slave sql_thread' >/dev/null 2>/dev/null &");
80
# This time we do not need to capture STDERR because mk-table-checksum
81
# should see slave2 come alive in 2 seconds then return before wait_for
60
) or die "Slaves are still lagging";
62
# This big fancy command waits until it sees the checksum for sakila.city
63
# in the repl table on the master, then it stops slave2 for 2 seconds,
64
# then starts it again.
65
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 &");
84
sub { pt_table_checksum::main(@args); },
68
sub { pt_table_checksum::main(@args, qw(-d sakila)); },
90
qr/Waiting for slave.+?Still waiting/s,
91
"Progress reports while waiting for slaves"
74
qr/Replica h=127.0.0.1,P=12347 is stopped/,
75
"--progress for slave lag"
81
"Checksumming continues after waiting for slave lag"
85
PerconaTest::count_checksum_results($output, 'errors'),
87
"No errors after waiting for slave lag"
94
90
# #############################################################################
96
92
# #############################################################################
97
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
98
diag(`/tmp/12346/stop >/dev/null`); # Start/stop clears SHOW SLAVE HOSTS.
99
diag(`/tmp/12346/start >/dev/null`);
100
93
$sb->wipe_clean($master_dbh);
101
94
diag(`$trunk/sandbox/test-env reset >/dev/null`);