Merge cant-nibble-bug-918056.

This commit is contained in:
Daniel Nichter
2013-01-23 11:43:14 -07:00
10 changed files with 452 additions and 11 deletions

View File

@@ -10582,6 +10582,7 @@ sub sync_a_table {
trim => $o->get('trim'),
wait => $o->get('wait'),
function => $o->get('function'),
trace => !$ENV{PT_TEST_NO_TRACE},
);
if ( sum(@status{@ChangeHandler::ACTIONS}) ) {
@@ -11281,19 +11282,30 @@ sub diff_where {
PTDEBUG && _d('Ascend params:', Dumper($asc));
}
my $lb_sql = $asc->{boundaries}->{'>='};
foreach my $val ( $q->deserialize_list($diff->{lower_boundary}) ) {
my $quoted_val = $q->quote_val($val);
$lb_sql =~ s/\?/$quoted_val/;
my ($lb_sql, $ub_sql);
if ( defined $diff->{lower_boundary} ) {
$lb_sql = $asc->{boundaries}->{'>='};
foreach my $val ( $q->deserialize_list($diff->{lower_boundary}) ) {
my $quoted_val = $q->quote_val($val);
$lb_sql =~ s/\?/$quoted_val/;
}
}
my $ub_sql = $asc->{boundaries}->{'<='};
foreach my $val ( $q->deserialize_list($diff->{upper_boundary}) ) {
my $quoted_val = $q->quote_val($val);
$ub_sql =~ s/\?/$quoted_val/;
if ( defined $diff->{upper_boundary} ) {
$ub_sql = $asc->{boundaries}->{'<='};
foreach my $val ( $q->deserialize_list($diff->{upper_boundary}) ) {
my $quoted_val = $q->quote_val($val);
$ub_sql =~ s/\?/$quoted_val/;
}
}
return "$lb_sql AND $ub_sql";
die "Invalid checksum diff: " . Dumper($diff)
unless $lb_sql || $ub_sql;
return $lb_sql && $ub_sql ? "$lb_sql AND $ub_sql"
: $lb_sql ? $lb_sql
: $ub_sql;
}
}

View File

@@ -9,7 +9,7 @@ BEGIN {
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 1;
use Test::More;
use PerconaTest;
use Sandbox;
@@ -57,7 +57,28 @@ test_diff_where(
where => "((`id` >= '7')) AND ((`id` <= '9'))",
);
test_diff_where(
name => "Lower oob chunk (bug 918056)",
file => "$sample/bug-918056-ddl.sql",
diff => {
chunk => '3',
chunk_index => 'PRIMARY',
cnt_diff => '49',
crc_diff => '0',
db => 'test',
lower_boundary => undef,
master_cnt => '0',
master_crc => '0',
table => 'test.history',
tbl => 'history',
this_cnt => '49',
this_crc => '0',
upper_boundary => '21,21,1045'
},
where => "((`uid` < '21') OR (`uid` = '21' AND `nid` <= '1045'))",
);
# #############################################################################
# Done.
# #############################################################################
exit;
done_testing;

View File

@@ -0,0 +1,90 @@
#!/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";
# Don't add /* trace */ messages to --print queries becuase they
# contain non-determinstic info like user, etc.
$ENV{PT_TEST_NO_TRACE} = 1;
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More;
use PerconaTest;
use Sandbox;
require "$trunk/bin/pt-table-sync";
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $master_dbh = $sb->get_dbh_for('master');
my $slave1_dbh = $sb->get_dbh_for('slave1');
if ( !$master_dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
elsif ( !$slave1_dbh ) {
plan skip_all => 'Cannot connect to sandbox slave1';
}
my $master_dsn = $sb->dsn_for('master');
my $slave1_dsn = $sb->dsn_for('slave1');
my $output;
my $sample = "t/pt-table-sync/samples";
# #############################################################################
# --replicate tests
# #############################################################################
# #############################################################################
# Bug 918056: pt-table-sync false-positive error "Cannot nibble table because
# MySQL chose no index instead of the PRIMARY index"
# https://bugs.launchpad.net/percona-toolkit/+bug/918056
# #############################################################################
# The slave has 49 extra rows on the low end, e.g. master has rows 50+
# but slave has rows 1-49 and 50+. This tests syncing the lower oob chunk.
$sb->create_dbs($master_dbh, [qw(bug918056)]);
$sb->load_file('master', "$sample/bug-918056-master.sql", "bug918056");
$sb->load_file('slave1', "$sample/bug-918056-slave.sql", "bug918056");
ok(
no_diff(
sub {
pt_table_sync::main($master_dsn, qw(--replicate percona.checksums),
qw(--print))
},
"$sample/bug-918056-print.txt",
stderr => 1,
),
"Sync lower oob (bug 918056)"
);
# Test syncing the upper oob chunk.
$sb->load_file('master', "$sample/upper-oob-master.sql");
$sb->load_file('slave1', "$sample/upper-oob-slave.sql");
ok(
no_diff(
sub {
pt_table_sync::main($master_dsn, qw(--replicate percona.checksums),
qw(--print))
},
"$sample/upper-oob-print.txt",
stderr => 1,
),
"Sync upper oob (bug 918056)"
);
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($master_dbh);
$sb->wipe_clean($slave1_dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;

View File

@@ -0,0 +1,6 @@
CREATE TABLE `history` (
`uid` int(11) NOT NULL DEFAULT '0',
`nid` int(11) NOT NULL DEFAULT '0',
`timestamp` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`uid`,`nid`)
) ENGINE=InnoDB;

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,49 @@
DELETE FROM `bug918056`.`history` WHERE `uid`='1' AND `nid`='14' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='1' AND `nid`='1591' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='1' AND `nid`='11501' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='1' AND `nid`='12648' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='1' AND `nid`='12652' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='1045' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='1046' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='11556' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12166' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12598' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12599' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12601' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12602' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12603' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12606' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12607' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12609' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12616' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12617' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12618' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12621' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12623' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12624' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12626' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12627' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12628' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12632' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12651' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12652' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12672' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12674' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12675' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12677' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12678' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12680' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12682' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12694' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12733' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12734' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='20' AND `nid`='12738' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='21' AND `nid`='12' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='21' AND `nid`='14' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='21' AND `nid`='16' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='21' AND `nid`='191' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='21' AND `nid`='307' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='21' AND `nid`='339' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='21' AND `nid`='340' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='21' AND `nid`='901' LIMIT 1;
DELETE FROM `bug918056`.`history` WHERE `uid`='21' AND `nid`='1039' LIMIT 1;

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,148 @@
DROP DATABASE IF EXISTS upper_oob;
CREATE DATABASE upper_oob;
USE upper_oob;
CREATE TABLE t (
id int not null auto_increment primary key,
c varchar(64)
) engine=innodb;
insert into t values
(1, 'Afghanistan'),
(2, 'Algeria'),
(3, 'American Samoa'),
(4, 'Angola'),
(5, 'Anguilla'),
(6, 'Argentina'),
(7, 'Armenia'),
(8, 'Australia'),
(9, 'Austria'),
(10, 'Azerbaijan'),
(11, 'Bahrain'),
(12, 'Bangladesh'),
(13, 'Belarus'),
(14, 'Bolivia'),
(15, 'Brazil'),
(16, 'Brunei'),
(17, 'Bulgaria'),
(18, 'Cambodia'),
(19, 'Cameroon'),
(20, 'Canada'),
(21, 'Chad'),
(22, 'Chile'),
(23, 'China'),
(24, 'Colombia'),
(25, 'Congo, The Democratic Republic of the'),
(26, 'Czech Republic'),
(27, 'Dominican Republic'),
(28, 'Ecuador'),
(29, 'Egypt'),
(30, 'Estonia'),
(31, 'Ethiopia'),
(32, 'Faroe Islands'),
(33, 'Finland'),
(34, 'France'),
(35, 'French Guiana'),
(36, 'French Polynesia'),
(37, 'Gambia'),
(38, 'Germany'),
(39, 'Greece'),
(40, 'Greenland'),
(41, 'Holy See (Vatican City State)'),
(42, 'Hong Kong'),
(43, 'Hungary'),
(44, 'India'),
(45, 'Indonesia'),
(46, 'Iran'),
(47, 'Iraq'),
(48, 'Israel'),
(49, 'Italy'),
(50, 'Japan'),
(51, 'Kazakstan'),
(52, 'Kenya'),
(53, 'Kuwait'),
(54, 'Latvia'),
(55, 'Liechtenstein'),
(56, 'Lithuania'),
(57, 'Madagascar'),
(58, 'Malawi'),
(59, 'Malaysia'),
(60, 'Mexico'),
(61, 'Moldova'),
(62, 'Morocco'),
(63, 'Mozambique'),
(64, 'Myanmar'),
(65, 'Nauru'),
(66, 'Nepal'),
(67, 'Netherlands'),
(68, 'New Zealand'),
(69, 'Nigeria'),
(70, 'North Korea'),
(71, 'Oman'),
(72, 'Pakistan'),
(73, 'Paraguay'),
(74, 'Peru'),
(75, 'Philippines'),
(76, 'Poland'),
(77, 'Puerto Rico'),
(78, 'Romania'),
(79, 'Runion'),
(80, 'Russian Federation'),
(81, 'Saint Vincent and the Grenadines'),
(82, 'Saudi Arabia'),
(83, 'Senegal'),
(84, 'Slovakia'),
(85, 'South Africa'),
(86, 'South Korea'),
(87, 'Spain'),
(88, 'Sri Lanka'),
(89, 'Sudan'),
(90, 'Sweden'),
(91, 'Switzerland'),
(92, 'Taiwan'),
(93, 'Tanzania'),
(94, 'Thailand'),
(95, 'Tonga'),
(96, 'Tunisia'),
(97, 'Turkey'),
(98, 'Turkmenistan'),
(99, 'Tuvalu'),
(100, 'Ukraine'),
(101, 'United Arab Emirates'),
(102, 'United Kingdom'),
(103, 'United States'),
(104, 'Venezuela'),
(105, 'Vietnam'),
(106, 'Virgin Islands, U.S.'),
(107, 'Yemen'),
(108, 'Yugoslavia'),
(109, 'Zambia');
CREATE DATABASE IF NOT EXISTS percona;
USE percona;
DROP TABLE IF EXISTS checksums;
CREATE TABLE `checksums` (
`db` char(64) NOT NULL,
`tbl` char(64) NOT NULL,
`chunk` int(11) NOT NULL,
`chunk_time` float DEFAULT NULL,
`chunk_index` varchar(200) DEFAULT NULL,
`lower_boundary` text,
`upper_boundary` text,
`this_crc` char(40) NOT NULL,
`this_cnt` int(11) NOT NULL,
`master_crc` char(40) DEFAULT NULL,
`master_cnt` int(11) DEFAULT NULL,
`ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`db`,`tbl`,`chunk`),
KEY `ts_db_tbl` (`ts`,`db`,`tbl`)
) ENGINE=InnoDB;
SET SQL_LOG_BIN=0;
DELETE FROM upper_oob.t where id > 99;
INSERT INTO percona.checksums VALUES
('upper_oob','t',1,0.001144,'PRIMARY','1','50','398f3270',50,'398f3270',50,'2013-01-23 17:36:56'),
('upper_oob','t',2,0.000878,'PRIMARY','51','99','bd9a892d',49,'bd9a892d',49,'2013-01-23 17:36:56'),
('upper_oob','t',3,0.000763,'PRIMARY',NULL,'1','0',0,'0',0,'2013-01-23 17:36:56'),
('upper_oob','t',4,0.000877,'PRIMARY','99',NULL,'0',0,'0',0,'2013-01-23 17:36:56');
SET SQL_LOG_BIN=1;

View File

@@ -0,0 +1,10 @@
DELETE FROM `upper_oob`.`t` WHERE `id`='100' LIMIT 1;
DELETE FROM `upper_oob`.`t` WHERE `id`='101' LIMIT 1;
DELETE FROM `upper_oob`.`t` WHERE `id`='102' LIMIT 1;
DELETE FROM `upper_oob`.`t` WHERE `id`='103' LIMIT 1;
DELETE FROM `upper_oob`.`t` WHERE `id`='104' LIMIT 1;
DELETE FROM `upper_oob`.`t` WHERE `id`='105' LIMIT 1;
DELETE FROM `upper_oob`.`t` WHERE `id`='106' LIMIT 1;
DELETE FROM `upper_oob`.`t` WHERE `id`='107' LIMIT 1;
DELETE FROM `upper_oob`.`t` WHERE `id`='108' LIMIT 1;
DELETE FROM `upper_oob`.`t` WHERE `id`='109' LIMIT 1;

View File

@@ -0,0 +1,7 @@
USE percona;
TRUNCATE TABLE checksums;
INSERT INTO `checksums` VALUES
('upper_oob','t',1,0.001144,'PRIMARY','1','50','398f3270',50,'398f3270',50,'2013-01-23 17:36:56'),
('upper_oob','t',2,0.000878,'PRIMARY','51','99','bd9a892d',49,'bd9a892d',49,'2013-01-23 17:36:56'),
('upper_oob','t',3,0.000763,'PRIMARY',NULL,'1','0',0,'0',0,'2013-01-23 17:36:56'),
('upper_oob','t',4,0.000877,'PRIMARY','99',NULL,'0',10,'0',0,'2013-01-23 17:36:56');