mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-28 00:21:56 +00:00
Merge fix-bailouts. t/pt-table-sync/issue_22.t needs to be fixed (bug 1038276).
This commit is contained in:
@@ -5434,7 +5434,7 @@ sub __get_boundaries {
|
||||
if ( $row ) {
|
||||
my $i = 0;
|
||||
$ub = $s->{boundaries}->{'<='};
|
||||
$ub =~ s/\?/$q->quote_val($row->{$s->{scols}->[$i]}, $self->{tbl_struct}->{is_numeric}->{$s->{scols}->[$i++]} || 0)/eg;
|
||||
$ub =~ s/\?/$q->quote_val($row->{$s->{scols}->[$i++]})/eg;
|
||||
}
|
||||
else {
|
||||
PTDEBUG && _d('No upper boundary');
|
||||
@@ -5466,7 +5466,7 @@ sub __make_boundary_sql {
|
||||
my $tmp = $self->{cached_row};
|
||||
my $i = 0;
|
||||
$lb = $s->{boundaries}->{'>'};
|
||||
$lb =~ s/\?/$q->quote_val($tmp->{$s->{scols}->[$i]}, $self->{tbl_struct}->{is_numeric}->{$s->{scols}->[$i++]} || 0)/eg;
|
||||
$lb =~ s/\?/$q->quote_val($tmp->{$s->{scols}->[$i++]})/eg;
|
||||
$sql .= $args{where} ? " AND $lb" : " WHERE $lb";
|
||||
}
|
||||
$sql .= " ORDER BY " . join(',', map { $q->quote($_) } @{$self->{key_cols}})
|
||||
|
@@ -6,7 +6,32 @@
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||
|
||||
# This tool is "fat-packed": most of its dependent modules are embedded
|
||||
# in this file. Setting %INC to this file for each module makes Perl aware
|
||||
# of this so it will not try to load the module from @INC. See the tool's
|
||||
# documentation for a full list of dependencies.
|
||||
BEGIN {
|
||||
$INC{$_} = __FILE__ for map { (my $pkg = "$_.pm") =~ s!::!/!g; $pkg } (qw(
|
||||
DSNParser
|
||||
OptionParser
|
||||
SlowLogParser
|
||||
Transformers
|
||||
QueryRewriter
|
||||
QueryParser
|
||||
FileIterator
|
||||
SQLParser
|
||||
TableUsage
|
||||
Daemon
|
||||
Runtime
|
||||
Progress
|
||||
Pipeline
|
||||
Quoter
|
||||
TableParser
|
||||
MysqldumpParser
|
||||
SchemaQualifier
|
||||
));
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
# DSNParser package
|
||||
|
@@ -5413,6 +5413,12 @@ sub _chunk_char {
|
||||
}
|
||||
PTDEBUG && _d("Base", $base, "chars:", @chars);
|
||||
|
||||
die "Cannot chunk table $db_tbl using the character column "
|
||||
. "$chunk_col, most likely because all values start with the "
|
||||
. "same character. This table must be synced separately by "
|
||||
. "specifying a list of --algorithms without the Chunk algorithm"
|
||||
if $base == 1;
|
||||
|
||||
|
||||
$sql = "SELECT MAX(LENGTH($qchunk_col)) FROM $db_tbl "
|
||||
. ($args{where} ? "WHERE $args{where} " : "")
|
||||
@@ -6982,9 +6988,10 @@ sub lock_and_wait {
|
||||
my $ms = $self->{MasterSlave};
|
||||
my $tries = $args{wait_retry_args}->{tries} || 3;
|
||||
my $wait;
|
||||
my $sleep = $args{wait_retry_args}->{wait} || 10;
|
||||
$self->{Retry}->retry(
|
||||
tries => $tries,
|
||||
wait => sub { sleep $args{wait_retry_args}->{wait} || 10 },
|
||||
wait => sub { sleep($sleep) },
|
||||
try => sub {
|
||||
my ( %args ) = @_;
|
||||
|
||||
@@ -7015,7 +7022,7 @@ sub lock_and_wait {
|
||||
. "the slave is running.";
|
||||
}
|
||||
if ( $tries - $args{tryno} ) {
|
||||
$msg .= " Sleeping $wait seconds then retrying "
|
||||
$msg .= " Sleeping $sleep seconds then retrying "
|
||||
. ($tries - $args{tryno}) . " more times.";
|
||||
}
|
||||
warn "$msg\n";
|
||||
@@ -7067,30 +7074,6 @@ sub lock_and_wait {
|
||||
return $result;
|
||||
}
|
||||
|
||||
sub have_all_privs {
|
||||
my ( $self, $dbh, $db, $tbl ) = @_;
|
||||
my $db_tbl = $self->{Quoter}->quote($db, $tbl);
|
||||
my $sql = "SHOW FULL COLUMNS FROM $db_tbl";
|
||||
PTDEBUG && _d('Permissions check:', $sql);
|
||||
my $cols = $dbh->selectall_arrayref($sql, {Slice => {}});
|
||||
my ($hdr_name) = grep { m/privileges/i } keys %{$cols->[0]};
|
||||
my $privs = $cols->[0]->{$hdr_name};
|
||||
$sql = "DELETE FROM $db_tbl LIMIT 0"; # FULL COLUMNS doesn't show all privs
|
||||
PTDEBUG && _d('Permissions check:', $sql);
|
||||
eval { $dbh->do($sql); };
|
||||
my $can_delete = $EVAL_ERROR ? 0 : 1;
|
||||
|
||||
PTDEBUG && _d('User privs on', $db_tbl, ':', $privs,
|
||||
($can_delete ? 'delete' : ''));
|
||||
if ( $privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/
|
||||
&& $can_delete ) {
|
||||
PTDEBUG && _d('User has all privs');
|
||||
return 1;
|
||||
}
|
||||
PTDEBUG && _d('User does not have all privs');
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub _d {
|
||||
my ($package, undef, $line) = caller 0;
|
||||
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
||||
@@ -7625,7 +7608,7 @@ sub __get_boundaries {
|
||||
if ( $row ) {
|
||||
my $i = 0;
|
||||
$ub = $s->{boundaries}->{'<='};
|
||||
$ub =~ s/\?/$q->quote_val($row->{$s->{scols}->[$i]}, $self->{tbl_struct}->{is_numeric}->{$s->{scols}->[$i++]} || 0)/eg;
|
||||
$ub =~ s/\?/$q->quote_val($row->{$s->{scols}->[$i++]})/eg;
|
||||
}
|
||||
else {
|
||||
PTDEBUG && _d('No upper boundary');
|
||||
@@ -7657,7 +7640,7 @@ sub __make_boundary_sql {
|
||||
my $tmp = $self->{cached_row};
|
||||
my $i = 0;
|
||||
$lb = $s->{boundaries}->{'>'};
|
||||
$lb =~ s/\?/$q->quote_val($tmp->{$s->{scols}->[$i]}, $self->{tbl_struct}->{is_numeric}->{$s->{scols}->[$i++]} || 0)/eg;
|
||||
$lb =~ s/\?/$q->quote_val($tmp->{$s->{scols}->[$i++]})/eg;
|
||||
$sql .= $args{where} ? " AND $lb" : " WHERE $lb";
|
||||
}
|
||||
$sql .= " ORDER BY " . join(',', map { $q->quote($_) } @{$self->{key_cols}})
|
||||
|
@@ -286,7 +286,7 @@ sub __get_boundaries {
|
||||
# any lower boundary the table rows should be > the lower boundary.)
|
||||
my $i = 0;
|
||||
$ub = $s->{boundaries}->{'<='};
|
||||
$ub =~ s/\?/$q->quote_val($row->{$s->{scols}->[$i]}, $self->{tbl_struct}->{is_numeric}->{$s->{scols}->[$i++]} || 0)/eg;
|
||||
$ub =~ s/\?/$q->quote_val($row->{$s->{scols}->[$i++]})/eg;
|
||||
}
|
||||
else {
|
||||
# This usually happens at the end of the table, after we've nibbled
|
||||
@@ -331,7 +331,7 @@ sub __make_boundary_sql {
|
||||
my $tmp = $self->{cached_row};
|
||||
my $i = 0;
|
||||
$lb = $s->{boundaries}->{'>'};
|
||||
$lb =~ s/\?/$q->quote_val($tmp->{$s->{scols}->[$i]}, $self->{tbl_struct}->{is_numeric}->{$s->{scols}->[$i++]} || 0)/eg;
|
||||
$lb =~ s/\?/$q->quote_val($tmp->{$s->{scols}->[$i++]})/eg;
|
||||
$sql .= $args{where} ? " AND $lb" : " WHERE $lb";
|
||||
}
|
||||
$sql .= " ORDER BY " . join(',', map { $q->quote($_) } @{$self->{key_cols}})
|
||||
|
@@ -9,7 +9,8 @@ BEGIN {
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More tests => 5;
|
||||
use Test::More;
|
||||
use Data::Dumper;
|
||||
|
||||
use TableSyncGroupBy;
|
||||
use Quoter;
|
||||
@@ -19,7 +20,11 @@ use ChangeHandler;
|
||||
use PerconaTest;
|
||||
|
||||
my $q = new Quoter();
|
||||
my $tbl_struct = { is_col => {} }; # fake tbl_struct
|
||||
my $tbl_struct = {
|
||||
type_for => { a => 'int', b => 'int', c => 'int' },
|
||||
col_posn => { a => 1, b => 2, c => 3 },
|
||||
is_col => { a => 1, b => 2, c => 3 },
|
||||
};
|
||||
my @rows;
|
||||
|
||||
throws_ok(
|
||||
@@ -40,6 +45,7 @@ my $ch = new ChangeHandler(
|
||||
replace => 0,
|
||||
actions => [ sub { push @rows, $_[0] }, ],
|
||||
queue => 0,
|
||||
tbl_struct => $tbl_struct,
|
||||
);
|
||||
|
||||
$t->prepare_to_sync(
|
||||
@@ -93,7 +99,7 @@ $d->compare_sets(
|
||||
{ a => 4, b => 2, c => 3, __maatkit_count => 1 },
|
||||
),
|
||||
syncer => $t,
|
||||
tbl_struct => {},
|
||||
tbl_struct => $tbl_struct,
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
@@ -107,4 +113,10 @@ is_deeply(
|
||||
"DELETE FROM `test`.`foo` WHERE `a`='4' AND `b`='2' AND `c`='3' LIMIT 1",
|
||||
],
|
||||
'rows from handler',
|
||||
);
|
||||
) or diag(Dumper(\@rows));
|
||||
|
||||
# #############################################################################
|
||||
# Done
|
||||
# #############################################################################
|
||||
done_testing;
|
||||
exit;
|
||||
|
@@ -49,9 +49,6 @@ if ( !$src_dbh || !$dbh ) {
|
||||
elsif ( !$dst_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox slave';
|
||||
}
|
||||
else {
|
||||
plan tests => 61;
|
||||
}
|
||||
|
||||
$sb->create_dbs($dbh, ['test']);
|
||||
$sb->load_file('master', 't/lib/samples/before-TableSyncChunk.sql');
|
||||
@@ -636,52 +633,8 @@ is(
|
||||
# Test check_permissions().
|
||||
# #############################################################################
|
||||
|
||||
SKIP: {
|
||||
skip "Not tested on MySQL $sandbox_version", 5
|
||||
unless $sandbox_version gt '4.0';
|
||||
|
||||
# Re-using issue_96.t from above.
|
||||
is(
|
||||
$syncer->have_all_privs($src->{dbh}, 'issue_96', 't'),
|
||||
1,
|
||||
'Have all privs'
|
||||
);
|
||||
|
||||
diag(`/tmp/12345/use -u root -e "CREATE USER 'bob'\@'\%' IDENTIFIED BY 'bob'"`);
|
||||
diag(`/tmp/12345/use -u root -e "GRANT select ON issue_96.t TO 'bob'\@'\%'"`);
|
||||
my $bob_dbh = DBI->connect(
|
||||
"DBI:mysql:;host=127.0.0.1;port=12345", 'bob', 'bob',
|
||||
{ PrintError => 0, RaiseError => 1 });
|
||||
|
||||
is(
|
||||
$syncer->have_all_privs($bob_dbh, 'issue_96', 't'),
|
||||
0,
|
||||
"Don't have all privs, just select"
|
||||
);
|
||||
|
||||
diag(`/tmp/12345/use -u root -e "GRANT insert ON issue_96.t TO 'bob'\@'\%'"`);
|
||||
is(
|
||||
$syncer->have_all_privs($bob_dbh, 'issue_96', 't'),
|
||||
0,
|
||||
"Don't have all privs, just select and insert"
|
||||
);
|
||||
|
||||
diag(`/tmp/12345/use -u root -e "GRANT update ON issue_96.t TO 'bob'\@'\%'"`);
|
||||
is(
|
||||
$syncer->have_all_privs($bob_dbh, 'issue_96', 't'),
|
||||
0,
|
||||
"Don't have all privs, just select, insert and update"
|
||||
);
|
||||
|
||||
diag(`/tmp/12345/use -u root -e "GRANT delete ON issue_96.t TO 'bob'\@'\%'"`);
|
||||
is(
|
||||
$syncer->have_all_privs($bob_dbh, 'issue_96', 't'),
|
||||
1,
|
||||
"Bob got his privs"
|
||||
);
|
||||
|
||||
diag(`/tmp/12345/use -u root -e "DROP USER 'bob'"`);
|
||||
}
|
||||
# have_all_privs() removed due to
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1036747
|
||||
|
||||
# ###########################################################################
|
||||
# Test that the calback gives us the src and dst sql.
|
||||
@@ -930,6 +883,7 @@ SKIP: {
|
||||
);
|
||||
|
||||
diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null &`);
|
||||
$dbh3->disconnect();
|
||||
}
|
||||
|
||||
# #############################################################################
|
||||
@@ -1066,7 +1020,9 @@ like(
|
||||
qr/Complete test coverage/,
|
||||
'_d() works'
|
||||
);
|
||||
$sb->wipe_clean($src_dbh);
|
||||
$sb->wipe_clean($dst_dbh);
|
||||
$src_dbh->disconnect() if $src_dbh;
|
||||
$dst_dbh->disconnect() if $dst_dbh;
|
||||
$sb->wipe_clean($dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
||||
exit;
|
||||
|
Reference in New Issue
Block a user