mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-16 16:23:30 +00:00
PT-2340 - Support MySQL 8.4
- Updated modules and tests for pt-table-sync, pt-table-usage, pt-upgrade, pt-variable-advisor
This commit is contained in:
@@ -18,26 +18,26 @@ 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 $slave_dbh = $sb->get_dbh_for('slave1');
|
||||
my $source_dbh = $sb->get_dbh_for('source');
|
||||
my $replica_dbh = $sb->get_dbh_for('replica1');
|
||||
|
||||
if ( !$master_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
if ( !$source_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox source';
|
||||
}
|
||||
elsif ( !$slave_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox slave';
|
||||
elsif ( !$replica_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox replica';
|
||||
}
|
||||
else {
|
||||
plan tests => 18;
|
||||
}
|
||||
|
||||
my $master_dsn = $sb->dsn_for('master');
|
||||
my $slave1_dsn = $sb->dsn_for('slave1');
|
||||
my $source_dsn = $sb->dsn_for('source');
|
||||
my $replica1_dsn = $sb->dsn_for('replica1');
|
||||
my $output;
|
||||
|
||||
# See this SQL file because it has a number of simple dbs and tbls
|
||||
# that are used to checking schema object filters.
|
||||
$sb->load_file('master', "t/lib/samples/SchemaIterator.sql");
|
||||
$sb->load_file('source', "t/lib/samples/SchemaIterator.sql");
|
||||
|
||||
sub test_filters {
|
||||
my (%args) = @_;
|
||||
@@ -50,7 +50,7 @@ sub test_filters {
|
||||
},
|
||||
);
|
||||
|
||||
my $tables_used = PerconaTest::tables_used($sb->genlog('master'));
|
||||
my $tables_used = PerconaTest::tables_used($sb->genlog('source'));
|
||||
is_deeply(
|
||||
$tables_used,
|
||||
$args{res},
|
||||
@@ -65,16 +65,16 @@ sub test_filters {
|
||||
# Not really a filter, but only the specified tables should be used.
|
||||
test_filters(
|
||||
name => "Sync d1.t1 to d1.t2",
|
||||
cmds => ["$master_dsn,D=d1,t=t1", "t=t2"],
|
||||
cmds => ["$source_dsn,D=d1,t=t1", "t=t2"],
|
||||
res => [qw(d1.t1 d1.t2)],
|
||||
);
|
||||
|
||||
# Use slave1 like it's another master, ok becuase we're not actually
|
||||
# syncing anything, so --no-check-slave is required else pt-table-sync
|
||||
# won't run (because it doesn't like to sync directly to a slave).
|
||||
# Use replica1 like it's another source, ok becuase we're not actually
|
||||
# syncing anything, so --no-check-replica is required else pt-table-sync
|
||||
# won't run (because it doesn't like to sync directly to a replica).
|
||||
test_filters(
|
||||
name => "-t d1.t1",
|
||||
cmds => [$master_dsn, $slave1_dsn, qw(--no-check-slave),
|
||||
cmds => [$source_dsn, $replica1_dsn, qw(--no-check-replica),
|
||||
qw(-t d1.t1)],
|
||||
res => [qw(d1.t1)],
|
||||
);
|
||||
@@ -82,7 +82,7 @@ test_filters(
|
||||
# Like the previous test, but now any table called "t1".
|
||||
test_filters(
|
||||
name => "-t t1",
|
||||
cmds => [$master_dsn, $slave1_dsn, qw(--no-check-slave),
|
||||
cmds => [$source_dsn, $replica1_dsn, qw(--no-check-replica),
|
||||
qw(-t t1)],
|
||||
res => [qw(d1.t1 d2.t1)],
|
||||
);
|
||||
@@ -90,7 +90,7 @@ test_filters(
|
||||
# Only the given db, all its tables: there's only 1 tbl in d2.
|
||||
test_filters(
|
||||
name => "--databases d2",
|
||||
cmds => [$master_dsn, $slave1_dsn, qw(--no-check-slave),
|
||||
cmds => [$source_dsn, $replica1_dsn, qw(--no-check-replica),
|
||||
qw(--databases d2)],
|
||||
res => [qw(d2.t1)],
|
||||
);
|
||||
@@ -98,21 +98,21 @@ test_filters(
|
||||
# --database with --tables.
|
||||
test_filters(
|
||||
name => "--databases d1 --tables t2,t3",
|
||||
cmds => [$master_dsn, $slave1_dsn, qw(--no-check-slave),
|
||||
cmds => [$source_dsn, $replica1_dsn, qw(--no-check-replica),
|
||||
qw(--databases d1), "--tables", "t2,t3"],
|
||||
res => [qw(d1.t2 d1.t3)],
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Filters with --replicate and --sync-to-master.
|
||||
# Filters with --replicate and --sync-to-source.
|
||||
# #############################################################################
|
||||
|
||||
# Checksum the filter tables.
|
||||
$master_dbh->do("DROP DATABASE IF EXISTS percona");
|
||||
$sb->wait_for_slaves();
|
||||
diag(`$trunk/bin/pt-table-checksum $master_dsn -d d1,d2,d3 --chunk-size 100 --quiet --set-vars innodb_lock_wait_timeout=3 --max-load ''`);
|
||||
$source_dbh->do("DROP DATABASE IF EXISTS percona");
|
||||
$sb->wait_for_replicas();
|
||||
diag(`$trunk/bin/pt-table-checksum $source_dsn -d d1,d2,d3 --chunk-size 100 --quiet --set-vars innodb_lock_wait_timeout=3 --max-load ''`);
|
||||
|
||||
my $rows = $master_dbh->selectall_arrayref("SELECT CONCAT(db, '.', tbl) FROM percona.checksums ORDER BY db, tbl");
|
||||
my $rows = $source_dbh->selectall_arrayref("SELECT CONCAT(db, '.', tbl) FROM percona.checksums ORDER BY db, tbl");
|
||||
is_deeply(
|
||||
$rows,
|
||||
[
|
||||
@@ -124,27 +124,27 @@ is_deeply(
|
||||
"Checksummed all tables"
|
||||
) or diag(Dumper($rows));
|
||||
|
||||
# Make all checksums on the slave different than the master
|
||||
# Make all checksums on the replica different than the source
|
||||
# so that pt-table-sync would sync all the tables if there
|
||||
# were no filters.
|
||||
$slave_dbh->do("UPDATE percona.checksums SET this_cnt=999 WHERE 1=1");
|
||||
$replica_dbh->do("UPDATE percona.checksums SET this_cnt=999 WHERE 1=1");
|
||||
|
||||
# Verify that that ^ is true.
|
||||
test_filters(
|
||||
name => "All tables are different on the slave",
|
||||
cmds => [$master_dsn, qw(--replicate percona.checksums)],
|
||||
name => "All tables are different on the replica",
|
||||
cmds => [$source_dsn, qw(--replicate percona.checksums)],
|
||||
res => [qw(d1.t1 d1.t2 d1.t3 d2.t1 percona.checksums)],
|
||||
);
|
||||
|
||||
# Sync with --replicate, --sync-to-master, and some filters.
|
||||
# --replicate and --sync-to-master have different code paths,
|
||||
# Sync with --replicate, --sync-to-source, and some filters.
|
||||
# --replicate and --sync-to-source have different code paths,
|
||||
# but the filter results should be the same.
|
||||
foreach my $args (
|
||||
[$master_dsn, qw(--replicate percona.checksums)],
|
||||
[$slave1_dsn, qw(--replicate percona.checksums --sync-to-master)]
|
||||
[$source_dsn, qw(--replicate percona.checksums)],
|
||||
[$replica1_dsn, qw(--replicate percona.checksums --sync-to-source)]
|
||||
) {
|
||||
|
||||
my $stm = $args->[-1] eq '--sync-to-master' ? ' --sync-to-master' : '';
|
||||
my $stm = $args->[-1] eq '--sync-to-source' ? ' --sync-to-source' : '';
|
||||
|
||||
test_filters(
|
||||
name => $stm . "--replicate --tables t1",
|
||||
@@ -172,18 +172,18 @@ foreach my $args (
|
||||
# pt-table-sync --ignore-* options don't work with --replicate
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1002365
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($master_dbh);
|
||||
$sb->load_file("master", "t/pt-table-sync/samples/simple-tbls.sql");
|
||||
$sb->wipe_clean($source_dbh);
|
||||
$sb->load_file("source", "t/pt-table-sync/samples/simple-tbls.sql");
|
||||
|
||||
# Create a checksum diff in a table that we're going to ignore
|
||||
# when we sync.
|
||||
$slave_dbh->do("INSERT INTO test.empty_it VALUES (null,11,11,'eleven')");
|
||||
$replica_dbh->do("INSERT INTO test.empty_it VALUES (null,11,11,'eleven')");
|
||||
|
||||
# Create the checksums.
|
||||
diag(`$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test --quiet --quiet --set-vars innodb_lock_wait_timeout=3 --max-load ''`);
|
||||
|
||||
# Make sure all the tables were checksummed.
|
||||
$rows = $master_dbh->selectall_arrayref("SELECT DISTINCT db, tbl FROM percona.checksums ORDER BY db, tbl");
|
||||
$rows = $source_dbh->selectall_arrayref("SELECT DISTINCT db, tbl FROM percona.checksums ORDER BY db, tbl");
|
||||
is_deeply(
|
||||
$rows,
|
||||
[ [qw(test empty_it) ],
|
||||
@@ -199,7 +199,7 @@ is_deeply(
|
||||
# Sync the checksummed tables, but ignore the table with the diff we created.
|
||||
$output = output(
|
||||
sub { pt_table_sync::main("h=127.1,P=12346,u=msandbox,p=msandbox",
|
||||
qw(--print --sync-to-master --replicate percona.checksums),
|
||||
qw(--print --sync-to-source --replicate percona.checksums),
|
||||
"--ignore-tables", "test.empty_it") },
|
||||
stderr => 1,
|
||||
);
|
||||
@@ -213,7 +213,7 @@ is(
|
||||
# Sync the checksummed tables, but ignore the database.
|
||||
$output = output(
|
||||
sub { pt_table_sync::main("h=127.1,P=12346,u=msandbox,p=msandbox",
|
||||
qw(--print --sync-to-master --replicate percona.checksums),
|
||||
qw(--print --sync-to-source --replicate percona.checksums),
|
||||
"--ignore-databases", "test") },
|
||||
stderr => 1,
|
||||
);
|
||||
@@ -224,10 +224,10 @@ is(
|
||||
"Database ignored, nothing to sync (bug 1002365)"
|
||||
);
|
||||
|
||||
# The same should work for just --sync-to-master.
|
||||
# The same should work for just --sync-to-source.
|
||||
$output = output(
|
||||
sub { pt_table_sync::main("h=127.1,P=12346,u=msandbox,p=msandbox",
|
||||
qw(--print --sync-to-master),
|
||||
qw(--print --sync-to-source),
|
||||
"--ignore-tables", "test.empty_it",
|
||||
"--ignore-databases", "percona") },
|
||||
stderr => 1,
|
||||
@@ -236,12 +236,12 @@ $output = output(
|
||||
unlike(
|
||||
$output,
|
||||
qr/empty_it/,
|
||||
"Table ignored, nothing to sync-to-master (bug 1002365)"
|
||||
"Table ignored, nothing to sync-to-source (bug 1002365)"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($master_dbh);
|
||||
$sb->wipe_clean($source_dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
exit;
|
||||
|
Reference in New Issue
Block a user