3
# This test's purpose: determine whether the SQL that pt-table-sync executes has
4
# distinct marker comments in it to identify the DML statements for DBAs to
5
# recognize. This is important for diagnosing what's in your binary log.
4
8
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5
9
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
21
25
my $slave_dbh = $sb->get_dbh_for('slave1');
23
27
my $mysqlbinlog = `which mysqlbinlog`;
24
chomp $mysqlbinlog if $mysqlbinlog;
31
elsif ( -x "$ENV{PERCONA_TOOLKIT_SANDBOX}/bin/mysqlbinlog" ) {
32
$mysqlbinlog = "$ENV{PERCONA_TOOLKIT_SANDBOX}/bin/mysqlbinlog";
26
35
if ( !$master_dbh ) {
27
36
plan skip_all => 'Cannot connect to sandbox master';
33
42
plan skip_all => 'Cannot find mysqlbinlog';
40
my @args = ('h=127.0.0.1,P=12346,u=msandbox,p=msandbox', qw(--sync-to-master --execute -t onlythisdb.t));
42
diag(`$trunk/sandbox/test-env reset`);
48
# We execute the test by changing a table so pt-table-sync will find something
49
# to modify. Then we examine the binary log to find the SQL in it, and check
43
51
$sb->load_file('master', "t/pt-table-sync/samples/issue_533.sql");
46
$slave_dbh->do('insert into onlythisdb.t values (5)');
52
my $pos = $master_dbh->selectrow_hashref('show master status');
53
diag("Master position: $pos->{file} / $pos->{position}");
55
my @args = ('h=127.1,P=12345,u=msandbox,p=msandbox,D=test,t=t1', 't=t2', '--execute');
49
57
sub { pt_table_sync::main(@args) },
52
my $binlog = $master_dbh->selectrow_arrayref('show master logs');
54
$output = `$mysqlbinlog /tmp/12345/data/$binlog->[0] | grep 'percona-toolkit'`;
55
$output =~ s/pid:\d+/pid:0/ if $output;
56
$output =~ s/host:\S+?\*/host:-*/ if $output;
60
# The statement really ought to look like this:
61
# "DELETE FROM `test`.`t2` WHERE `i`='5' LIMIT 1 /*percona-toolkit
62
# src_db:test src_tbl:t1 src_dsn:P=12345,h=127.0.0.1,p=...,u=msandbox
63
# dst_db:test dst_tbl:t2 dst_dsn:P=12346,h=127.0.0.1,p=...,u=msandbox
64
# lock:1 transaction:0 changing_src:1 replicate:0 bidirectional:0 pid:0
65
# user:$ENV{USER} host:-*/
66
my $output = `$mysqlbinlog /tmp/12345/data/$pos->{file} --start-position=$pos->{position} | grep 'percona-toolkit'`;
59
"DELETE FROM `onlythisdb`.`t` WHERE `i`='5' LIMIT 1 /*percona-toolkit src_db:onlythisdb src_tbl:t src_dsn:P=12345,h=127.0.0.1,p=...,u=msandbox dst_db:onlythisdb dst_tbl:t dst_dsn:P=12346,h=127.0.0.1,p=...,u=msandbox lock:1 transaction:0 changing_src:1 replicate:0 bidirectional:0 pid:0 user:$ENV{USER} host:-*/
69
qr/DELETE FROM.*test`.`t2.*percona-toolkit src_db:test.*user:$ENV{USER}/,
61
70
"Trace message appended to change SQL"