28
30
plan skip_all => 'Cannot connect to sandbox slave';
36
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
37
# so we need to specify --lock-wait-timeout=3 else the tool will die.
38
# And --max-load "" prevents waiting for status variables.
39
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
40
my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
35
my $cnf='/tmp/12345/my.sandbox.cnf';
36
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1";
38
45
$sb->wipe_clean($master_dbh);
39
$sb->create_dbs($master_dbh, [qw(test)]);
41
# #############################################################################
42
# Issue 77: mk-table-checksum should be able to create the --replicate table
43
# #############################################################################
46
$master_dbh->selectall_arrayref('show tables from test'),
48
"Checksum table does not exist on master"
52
$slave_dbh->selectall_arrayref('show tables from test'),
54
"Checksum table does not exist on slave"
57
# First check that, like a Klingon, it dies with honor.
58
$output = `$cmd --replicate test.checksum 2>&1`;
46
#$sb->create_dbs($master_dbh, [qw(test)]);
48
# Most other tests implicitly test that --create-replicate-table is on
49
# by default because they use that functionality. So here we need to
50
# test that we can turn it off, that it doesn't blow up if the repl table
51
# already exists, etc.
54
pt_table_checksum::main(@args, '--no-create-replicate-table');
58
qr/--replicate database percona does not exist/,
59
"--no-create-replicate-table dies if db doesn't exist"
62
$master_dbh->do('create database percona');
63
$master_dbh->do('use percona');
65
pt_table_checksum::main(@args, '--no-create-replicate-table');
69
qr/--replicate table `percona`.`checksums` does not exist/,
70
"--no-create-replicate-table dies if table doesn't exist"
73
my $create_repl_table =
74
"CREATE TABLE `checksums` (
76
tbl char(64) NOT NULL,
78
chunk_time float NULL,
79
chunk_index varchar(200) NULL,
80
lower_boundary text NULL,
81
upper_boundary text NULL,
82
this_crc char(40) NOT NULL,
83
this_cnt int NOT NULL,
84
master_crc char(40) NULL,
86
ts timestamp NOT NULL,
87
PRIMARY KEY (db, tbl, chunk)
90
$master_dbh->do($create_repl_table);
93
sub { pt_table_checksum::main(@args, '--no-create-replicate-table',
94
qw(-t sakila.country)) },
61
qr/replicate table .+ does not exist/,
62
'Dies with honor when replication table does not exist'
66
sub { pt_table_checksum::main('-F', $cnf,
67
qw(--create-replicate-table --replicate test.checksum 127.1)) },
71
# In 5.0 "on" in "on update" is lowercase, in 5.1 it's uppercase.
72
my $create_tbl = lc("CREATE TABLE `checksum` (
73
`db` char(64) NOT NULL,
74
`tbl` char(64) NOT NULL,
75
`chunk` int(11) NOT NULL,
76
`boundaries` char(100) NOT NULL,
77
`this_crc` char(40) NOT NULL,
78
`this_cnt` int(11) NOT NULL,
79
`master_crc` char(40) default NULL,
80
`master_cnt` int(11) default NULL,
81
`ts` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
82
PRIMARY KEY (`db`,`tbl`,`chunk`)
83
) ENGINE=MyISAM DEFAULT CHARSET=latin1");
85
# In 5.0 there's 2 spaces, in 5.1 there 1.
86
if ( $vp->version_ge($master_dbh, '5.1.0') ) {
87
$create_tbl =~ s/primary key /primary key /;
91
lc($master_dbh->selectrow_hashref('show create table test.checksum')->{'create table'}),
93
'Creates the replicate table'
98
qr/^\S+\s+0\s+0\s+109\s+1\s+0\s+\S+\s+sakila.country$/m,
99
"Uses pre-created replicate table"
96
102
# ############################################################################
97
103
# Issue 1318: mk-tabke-checksum --create-replicate-table doesn't replicate
98
104
# ############################################################################
100
lc($slave_dbh->selectrow_hashref('show create table test.checksum')->{'create table'}),
102
'Creates the replicate table replicates (issue 1318)'
106
$sb->wipe_clean($master_dbh);
108
# Wait until the slave no longer has the percona db.
109
PerconaTest::wait_until(
111
eval { $slave_dbh->do("use percona") };
112
return 1 if $EVAL_ERROR;
117
pt_table_checksum::main(@args, qw(-t sakila.country --quiet));
119
# Wait until the repl table replicates, or timeout.
120
PerconaTest::wait_for_table($slave_dbh, 'percona.checksums');
122
$row = $slave_dbh->selectrow_arrayref("show tables from percona");
126
'Auto-created replicate table replicates (issue 1318)'
105
129
# #############################################################################