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";
10
use warnings FATAL => 'all';
11
use English qw(-no_match_vars);
16
require "$trunk/bin/pt-table-sync";
19
my $dp = new DSNParser(opts=>$dsn_opts);
20
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
21
my $master_dbh = $sb->get_dbh_for('master');
22
my $slave_dbh = $sb->get_dbh_for('slave1');
25
plan skip_all => 'Cannot connect to sandbox master';
27
elsif ( !$slave_dbh ) {
28
plan skip_all => 'Cannot connect to sandbox slave';
34
$sb->wipe_clean($master_dbh);
35
$sb->wipe_clean($slave_dbh);
36
$sb->create_dbs($master_dbh, [qw(test)]);
37
$sb->load_file('master', 't/pt-table-sync/samples/before.sql');
38
$sb->load_file('master', 't/pt-table-sync/samples/checksum_tbl.sql');
40
# #############################################################################
41
# Issue 79: mk-table-sync with --replicate doesn't honor --tables
42
# #############################################################################
44
$master_dbh->do('create table test.messages (i int)');
46
$slave_dbh->do('insert into test.messages values (1), (2), (3)');
48
# The previous test should have left test.messages on the slave (12346)
49
# out of sync. Now we also unsync test2 on the slave and then re-sync only
50
# it. If --tables is honored, only test2 on the slave will be synced.
51
$sb->use('master', "-D test -e \"SET SQL_LOG_BIN=0; INSERT INTO test2 VALUES (1,'a'),(2,'b')\"");
52
diag(`$trunk/bin/pt-table-checksum --replicate=test.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test > /dev/null`);
55
$master_dbh->selectall_arrayref('select * from test.messages'),
57
'test.messages on master empty'
60
$slave_dbh->selectall_arrayref('select * from test.messages'),
62
'test.messages on slave has values'
65
# Test that what the doc says about --tables is true:
66
# "Table names may be qualified with the database name."
67
# In the code, a qualified db.tbl name is used.
68
# So we'll test first an unqualified tbl name.
69
$output = `$trunk/bin/pt-table-sync h=127.1,P=12345,u=msandbox,p=msandbox --replicate test.checksum --execute -d test -t test2 -v`;
70
unlike($output, qr/messages/, '--replicate honors --tables (1/4)');
71
like($output, qr/test2/, '--replicate honors --tables (2/4)');
73
# Now we'll test with a qualified db.tbl name.
74
$sb->use('slave1', '-D test -e "TRUNCATE TABLE test2; TRUNCATE TABLE messages"');
75
diag(`$trunk/bin/pt-table-checksum --replicate=test.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test > /dev/null`);
77
$output = `$trunk/bin/pt-table-sync h=127.1,P=12345,u=msandbox,p=msandbox --replicate test.checksum --execute -d test -t test.test2 -v`;
78
unlike($output, qr/messages/, '--replicate honors --tables (3/4)');
79
like($output, qr/test2/, '--replicate honors --tables (4/4)');
81
# #############################################################################
83
# #############################################################################
84
$sb->wipe_clean($master_dbh);
85
$sb->wipe_clean($slave_dbh);