Fix for 1016131: ptc should skip tables when all its columns are excluded

This commit is contained in:
Brian Fraser
2012-08-02 11:29:57 -03:00
parent cc3826f665
commit 94a5d85212
4 changed files with 85 additions and 10 deletions

View File

@@ -3762,6 +3762,9 @@ sub make_row_checksum {
my $func = $args{func} || uc($o->get('function')); my $func = $args{func} || uc($o->get('function'));
my $cols = $self->get_checksum_columns(%args); my $cols = $self->get_checksum_columns(%args);
die "all columns are excluded by --columns or --ignore-columns"
unless @{$cols->{select}};
my $query; my $query;
if ( !$args{no_cols} ) { if ( !$args{no_cols} ) {
$query = join(', ', $query = join(', ',
@@ -7762,11 +7765,18 @@ sub main {
# Make a nibble iterator for this table. This should only fail # Make a nibble iterator for this table. This should only fail
# if the table has no indexes and is too large to checksum in # if the table has no indexes and is too large to checksum in
# one chunk. # one chunk.
my $checksum_cols = $rc->make_chunk_checksum( local $EVAL_ERROR;
my $checksum_cols = eval {
$rc->make_chunk_checksum(
dbh => $master_cxn->dbh(), dbh => $master_cxn->dbh(),
tbl => $tbl, tbl => $tbl,
%crc_args %crc_args
); );
} or do {
warn ts("Skipping table $tbl->{db}.$tbl->{tbl} because "
. "$EVAL_ERROR\n");
return;
};
my $nibble_iter; my $nibble_iter;
eval { eval {
$nibble_iter = new OobNibbleIterator( $nibble_iter = new OobNibbleIterator(
@@ -9083,7 +9093,8 @@ of leaving it at the default.
short form: -c; type: array; group: Filter short form: -c; type: array; group: Filter
Checksum only this comma-separated list of columns. Checksum only this comma-separated list of columns. If a table doesn't have
any of the specified columns it will be skipped.
=item --config =item --config
@@ -9197,6 +9208,8 @@ Host to connect to.
type: Hash; group: Filter type: Hash; group: Filter
Ignore this comma-separated list of columns when calculating the checksum. Ignore this comma-separated list of columns when calculating the checksum.
If a table has all of its columns filtered by --ignore-columns, it will
be skipped.
=item --ignore-databases =item --ignore-databases

View File

@@ -67,6 +67,11 @@ sub make_row_checksum {
my $func = $args{func} || uc($o->get('function')); my $func = $args{func} || uc($o->get('function'));
my $cols = $self->get_checksum_columns(%args); my $cols = $self->get_checksum_columns(%args);
# Skip tables that have all their columns skipped; See
# https://bugs.launchpad.net/percona-toolkit/+bug/1016131
die "all columns are excluded by --columns or --ignore-columns"
unless @{$cols->{select}};
# Prepend columns to query, resulting in "col1, col2, FUNC(..col1, col2...)", # Prepend columns to query, resulting in "col1, col2, FUNC(..col1, col2...)",
# unless caller says not to. The only caller that says not to is # unless caller says not to. The only caller that says not to is
# make_chunk_checksum() which uses this row checksum as part of a larger # make_chunk_checksum() which uses this row checksum as part of a larger

View File

@@ -26,9 +26,6 @@ my $dbh = $sb->get_dbh_for('master');
if ( !$dbh ) { if ( !$dbh ) {
plan skip_all => "Cannot connect to sandbox master"; plan skip_all => "Cannot connect to sandbox master";
} }
else {
plan tests => 29;
}
$sb->create_dbs($dbh, ['test']); $sb->create_dbs($dbh, ['test']);
@@ -421,9 +418,53 @@ is(
'Ignores specified columns' 'Ignores specified columns'
); );
# #############################################################################
# crash with --columns if none match / --ignore-columns if everything is ignored
# https://bugs.launchpad.net/percona-toolkit/+bug/1016131
# #############################################################################
# Re-using the $tbl from the previous test!
local @ARGV = ('--ignore-columns', 'a,b,c');
$o->get_opts();
local $EVAL_ERROR;
eval {
$c->make_row_checksum(
tbl => $tbl,
func => 'CRC32',
);
};
like(
$EVAL_ERROR,
qr/all columns are excluded by --columns or --ignore-columns/,
"Dies if all columns are ignored by --ignore-columns"
);
$tbl = {
db => 'mysql',
tbl => 'user',
tbl_struct => $tp->parse($tp->get_create_table($dbh, 'mysql', 'user')),
};
local @ARGV = qw(--columns some_column_that_doesnt_exist);
$o->get_opts();
local $EVAL_ERROR;
eval {
$c->make_row_checksum(
tbl => $tbl,
func => 'SHA1',
);
};
like(
$EVAL_ERROR,
qr/all columns are excluded by --columns or --ignore-columns/,
'Dies if all columns are ignored by --columns'
);
# ############################################################################ # ############################################################################
# Done. # Done.
# ############################################################################ # ############################################################################
$sb->wipe_clean($dbh); $sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit;
done_testing;

View File

@@ -175,6 +175,22 @@ is(
"Bug 1030031 (wrong DIFFS): 3 diffs" "Bug 1030031 (wrong DIFFS): 3 diffs"
); );
# #############################################################################
# pt-table-checksum can crash with --columns if none match
# https://bugs.launchpad.net/percona-toolkit/+bug/1016131
# #############################################################################
($output) = full_output(
sub { pt_table_checksum::main(@args, '--tables', 'mysql.user,mysql.host',
'--columns', 'some_fale_column') },
);
like(
$output,
qr/\QSkipping table mysql.user because all columns are excluded by --columns or --ignore-columns/,
"Bug 1016131: ptc should skip tables where all columns are excluded"
);
# ############################################################################# # #############################################################################
# Done. # Done.
# ############################################################################# # #############################################################################