diff --git a/t/pt-table-sync/bugs.t b/t/pt-table-sync/bugs.t new file mode 100644 index 00000000..dcf43d60 --- /dev/null +++ b/t/pt-table-sync/bugs.t @@ -0,0 +1,106 @@ +#!/usr/bin/env perl + +BEGIN { + die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" + unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; + unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; +}; + +use strict; +use warnings FATAL => 'all'; +use English qw(-no_match_vars); +use Test::More; +use Data::Dumper; + +use PerconaTest; +use Sandbox; +require "$trunk/bin/pt-table-sync"; + +my $output; +my $dp = new DSNParser(opts=>$dsn_opts); +my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); +my $master_dbh = $sb->get_dbh_for('master'); +my $slave_dbh = $sb->get_dbh_for('slave1'); + +if ( !$master_dbh ) { + plan skip_all => 'Cannot connect to sandbox master'; +} +elsif ( !$slave_dbh ) { + plan skip_all => 'Cannot connect to sandbox slave'; +} +else { + plan tests => 4; +} + +my $sample = "t/pt-table-sync/samples"; +my $master_dsn = "h=127.1,P=12345,u=msandbox,p=msandbox"; +my $slave_dsn = "h=127.1,P=12346,u=msandbox,p=msandbox"; + +# ############################################################################# +# +# ############################################################################# + +$sb->load_file('master', "$sample/wrong-tbl-struct-bug-1003014.sql"); +PerconaTest::wait_for_table($slave_dbh, "test.zzz", "id=111"); + +# Make a diff in each table. +$slave_dbh->do("DELETE FROM test.aaa WHERE STOP_ARCHIVE IN (5,6,7)"); +$slave_dbh->do("UPDATE test.zzz SET c='x' WHERE id IN (44,45,46)"); + +$output = `$trunk/bin/pt-table-checksum $master_dsn --lock-wait-timeout 3 --max-load '' -d test --chunk-size 10 2>&1`; + +is( + PerconaTest::count_checksum_results($output, 'diffs'), + 2, + "Bug 1003014 (wrong tbl_struct): 2 diffs" +) or print STDERR $output; + +my $rows = $master_dbh->selectall_arrayref("SELECT db, tbl, chunk FROM percona.checksums ORDER BY db, tbl, chunk"); +is_deeply( + $rows, + [ + [qw( test aaa 1 )], + [qw( test zzz 1 )], + [qw( test zzz 2 )], + [qw( test zzz 3 )], + [qw( test zzz 4 )], + [qw( test zzz 5 )], + [qw( test zzz 6 )], + [qw( test zzz 7 )], + [qw( test zzz 8 )], + [qw( test zzz 9 )], + [qw( test zzz 10 )], + [qw( test zzz 11 )], + [qw( test zzz 12 )], + [qw( test zzz 13 )], + [qw( test zzz 14 )], + ], + "Bug 1003014 (wrong tbl_struct): checksums" +); + +my $exit_status; +$output = output( + sub { $exit_status = pt_table_sync::main($slave_dsn, + qw(--replicate percona.checksums --sync-to-master --print), + "--tables", "test.aaa,test.zzz") }, + stderr => 1, +); + +is( + $exit_status, + 2, # rows synced OK; 3=error (1) & rows synced (2) + "Bug 1003014 (wrong tbl_struct): 0 exit" +) or diag($output); + +$rows = $slave_dbh->selectall_arrayref("SELECT c FROM test.zzz WHERE id IN (44,45,46)"); +is_deeply( + $rows, + [ ['a'], ['a'], ['a'] ], + "Bug 1003014 (wrong tbl_struct): synced rows" +); + +# ############################################################################# +# Done. +# ############################################################################# +$sb->wipe_clean($master_dbh); +exit; diff --git a/t/pt-table-sync/samples/wrong-tbl-struct-bug-1003014.sql b/t/pt-table-sync/samples/wrong-tbl-struct-bug-1003014.sql new file mode 100644 index 00000000..8fe2f00f --- /dev/null +++ b/t/pt-table-sync/samples/wrong-tbl-struct-bug-1003014.sql @@ -0,0 +1,35 @@ +drop database if exists test; +create database test; +use test; + +-- +-- Checksum aaa in one chunk, make it differ, sync it first. +-- +create table aaa ( + `STOP_ARCHIVE` int(11) NOT NULL default '1', + UNIQUE KEY `STOP_ARCHIVE` (`STOP_ARCHIVE`) +) ENGINE=MyISAM; + +insert into aaa values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); + +-- +-- Checksum zzz in chunks, make a chunk differ, sync it 2nd. +-- +create table `zzz` ( + id int not null primary key, + c varchar(16) not null +); + +insert into zzz values + (1,'a'),(2,'a'),(3,'a'),(4,'a'),(5,'a'),(6,'a'),(7,'a'),(8,'a'),(9,'a'),(10,'a'), + (11,'a'),(12,'a'),(13,'a'),(14,'a'),(15,'a'),(16,'a'),(17,'a'),(18,'a'),(19,'a'),(20,'a'), + (21,'a'),(22,'a'),(23,'a'),(24,'a'),(25,'a'),(26,'a'),(27,'a'),(28,'a'),(29,'a'),(30,'a'), + (31,'a'),(32,'a'),(33,'a'),(34,'a'),(35,'a'),(36,'a'),(37,'a'),(38,'a'),(39,'a'),(40,'a'), + (41,'a'),(42,'a'),(43,'a'),(44,'a'),(45,'a'),(46,'a'),(47,'a'),(48,'a'),(49,'a'),(50,'a'), + (51,'a'),(52,'a'),(53,'a'),(54,'a'),(55,'a'),(56,'a'),(57,'a'),(58,'a'),(59,'a'),(60,'a'), + (61,'a'),(62,'a'),(63,'a'),(64,'a'),(65,'a'),(66,'a'),(67,'a'),(68,'a'),(69,'a'),(70,'a'), + (71,'a'),(72,'a'),(73,'a'),(74,'a'),(75,'a'),(76,'a'),(77,'a'),(78,'a'),(79,'a'),(80,'a'), + (81,'a'),(82,'a'),(83,'a'),(84,'a'),(85,'a'),(86,'a'),(87,'a'),(88,'a'),(89,'a'),(90,'a'), + (91,'a'),(92,'a'),(93,'a'),(94,'a'),(95,'a'),(96,'a'),(97,'a'),(98,'a'),(99,'a'),(100,'a'), + (101,'a'),(102,'a'),(103,'a'),(104,'a'),(105,'a'),(106,'a'),(107,'a'),(108,'a'),(109,'a'),(110,'a'), + (111, 'a');