PT-2340 - Support MySQL 8.4

- Updated modules and tests for pt-online-schema-change
- Removed typo from lib/MasterSlave.pm
This commit is contained in:
Sveta Smirnova
2024-07-29 18:47:13 +03:00
parent 5c999ca3e0
commit 76c1202cb5
69 changed files with 1606 additions and 1380 deletions

View File

@@ -27,14 +27,14 @@ $Data::Dumper::Quotekeys = 0;
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';
}
my $q = new Quoter();
@@ -66,12 +66,12 @@ sub test_alter_table {
my $delete_triggers = $args{delete_triggers} || '';
if ( my $file = $args{file} ) {
$sb->load_file('master', "$sample/$file");
$master_dbh->do("USE `$db`");
$slave_dbh->do("USE `$db`");
$sb->load_file('source', "$sample/$file");
$source_dbh->do("USE `$db`");
$replica_dbh->do("USE `$db`");
}
my $ddl = $tp->get_create_table($master_dbh, $db, $tbl);
my $ddl = $tp->get_create_table($source_dbh, $db, $tbl);
my $tbl_struct = $tp->parse($ddl);
my $cols = '*';
@@ -81,13 +81,13 @@ sub test_alter_table {
die "I need a drop_col argument" unless $col;
$cols = join(', ', grep { $_ ne $col } @{$tbl_struct->{cols}});
}
my $orig_rows = $master_dbh->selectall_arrayref(
my $orig_rows = $source_dbh->selectall_arrayref(
"SELECT $cols FROM $table ORDER BY `$pk_col`");
my $orig_tbls = $master_dbh->selectall_arrayref(
my $orig_tbls = $source_dbh->selectall_arrayref(
"SHOW TABLES FROM `$db`");
my $orig_max_id = $master_dbh->selectall_arrayref(
my $orig_max_id = $source_dbh->selectall_arrayref(
"SELECT MAX(`$pk_col`) FROM `$db`.`$tbl`");
my $triggers_sql = "SELECT TRIGGER_SCHEMA, TRIGGER_NAME, DEFINER, ACTION_STATEMENT, SQL_MODE, "
@@ -95,7 +95,7 @@ sub test_alter_table {
. " FROM INFORMATION_SCHEMA.TRIGGERS "
. " WHERE TRIGGER_SCHEMA = '$db' "
. " AND EVENT_OBJECT_TABLE = '$tbl'";
my $orig_triggers = $master_dbh->selectall_arrayref($triggers_sql);
my $orig_triggers = $source_dbh->selectall_arrayref($triggers_sql);
my ($orig_auto_inc) = $ddl =~ m/\s+AUTO_INCREMENT=(\d+)\s+/;
@@ -104,7 +104,7 @@ sub test_alter_table {
if ( $fk_method ) {
foreach my $tbl ( @$orig_tbls ) {
my $fks = $tp->get_fks(
$tp->get_create_table($master_dbh, $db, $tbl->[0]));
$tp->get_create_table($source_dbh, $db, $tbl->[0]));
push @orig_fks, $fks;
}
}
@@ -128,7 +128,7 @@ sub test_alter_table {
stderr => 1,
);
my $new_ddl = $tp->get_create_table($master_dbh, $db, $tbl);
my $new_ddl = $tp->get_create_table($source_dbh, $db, $tbl);
my $new_tbl_struct = $tp->parse($new_ddl);
my $fail = 0;
@@ -139,7 +139,7 @@ sub test_alter_table {
) or $fail = 1;
# There should be no new or missing tables.
my $new_tbls = $master_dbh->selectall_arrayref("SHOW TABLES FROM `$db`");
my $new_tbls = $source_dbh->selectall_arrayref("SHOW TABLES FROM `$db`");
is_deeply(
$new_tbls,
$orig_tbls,
@@ -147,7 +147,7 @@ sub test_alter_table {
) or $fail = 1;
# Rows in the original and new table should be identical.
my $new_rows = $master_dbh->selectall_arrayref("SELECT $cols FROM $table ORDER BY `$pk_col`");
my $new_rows = $source_dbh->selectall_arrayref("SELECT $cols FROM $table ORDER BY `$pk_col`");
is_deeply(
$new_rows,
$orig_rows,
@@ -155,7 +155,7 @@ sub test_alter_table {
) or $fail = 1;
if ( grep { $_ eq '--preserve-triggers' } @$cmds && !$delete_triggers) {
my $new_triggers = $master_dbh->selectall_arrayref($triggers_sql);
my $new_triggers = $source_dbh->selectall_arrayref($triggers_sql);
is_deeply(
$new_triggers,
$orig_triggers,
@@ -164,7 +164,7 @@ sub test_alter_table {
}
if ( grep { $_ eq '--no-drop-new-table' } @$cmds ) {
$new_rows = $master_dbh->selectall_arrayref(
$new_rows = $source_dbh->selectall_arrayref(
"SELECT $cols FROM `$db`.`$new_tbl` ORDER BY `$pk_col`");
is_deeply(
$new_rows,
@@ -173,7 +173,7 @@ sub test_alter_table {
) or $fail = 1;
}
my $new_max_id = $master_dbh->selectall_arrayref(
my $new_max_id = $source_dbh->selectall_arrayref(
"SELECT MAX(`$pk_col`) FROM `$db`.`$tbl`");
is(
$orig_max_id->[0]->[0],
@@ -224,7 +224,7 @@ sub test_alter_table {
elsif ( $test_type eq 'new_engine' ) {
my $new_engine = lc($args{new_engine});
die "I need a new_engine argument" unless $new_engine;
my $rows = $master_dbh->selectall_hashref(
my $rows = $source_dbh->selectall_hashref(
"SHOW TABLE STATUS FROM `$db`", "name");
is(
lc($rows->{$tbl}->{engine}),
@@ -240,7 +240,7 @@ sub test_alter_table {
foreach my $tbl ( @$orig_tbls ) {
my $fks = $tp->get_fks(
$tp->get_create_table($master_dbh, $db, $tbl->[0]));
$tp->get_create_table($source_dbh, $db, $tbl->[0]));
# The tool does not use the same/original fk name,
# it appends a single _. So we need to strip this
@@ -286,7 +286,7 @@ sub test_alter_table {
# a parent row that's being referenced by a child.
my $sql = "DELETE FROM $table WHERE $pk_col=1 LIMIT 1";
eval {
$master_dbh->do($sql);
$source_dbh->do($sql);
};
like(
$EVAL_ERROR,
@@ -336,7 +336,7 @@ SKIP: {
);
$sb->load_file('master', "$sample/after_triggers.sql");
$sb->load_file('source', "$sample/after_triggers.sql");
($output, $exit) = full_output(
sub { pt_online_schema_change::main(@args,
@@ -372,7 +372,7 @@ SKIP: {
"--preserve-triggers --no-swap-tables exit status",
);
$sb->load_file('master', "$sample/after_triggers.sql");
$sb->load_file('source', "$sample/after_triggers.sql");
($output, $exit) = full_output(
sub { pt_online_schema_change::main(@args,
@@ -388,7 +388,7 @@ SKIP: {
"--preserve-triggers --no-drop-old-table exit status",
);
my $rows = $master_dbh->selectall_arrayref("SHOW TABLES LIKE '%t1%'");
my $rows = $source_dbh->selectall_arrayref("SHOW TABLES LIKE '%t1%'");
is_deeply(
$rows,
[ [ '_t1_old' ], [ 't1' ] ],
@@ -446,29 +446,29 @@ SKIP: {
}
diag("Reloading sakila");
my $master_port = $sb->port_for('master');
system "$trunk/sandbox/load-sakila-db $master_port";
my $source_port = $sb->port_for('source');
system "$trunk/sandbox/load-sakila-db $source_port";
if ($sandbox_version ge '8.0') {
$sb->do_as_root("master", q/CREATE USER 'slave_user'@'%' IDENTIFIED WITH mysql_native_password BY 'slave_password'/);
if ($sandbox_version eq '8.0') {
$sb->do_as_root("source", q/CREATE USER 'replica_user'@'%' IDENTIFIED WITH mysql_native_password BY 'replica_password'/);
} else {
$sb->do_as_root("master", q/CREATE USER 'slave_user'@'%' IDENTIFIED BY 'slave_password'/);
$sb->do_as_root("source", q/CREATE USER 'replica_user'@'%' IDENTIFIED BY 'replica_password'/);
}
$sb->do_as_root("master", q/GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%'/);
$sb->do_as_root("master", q/set sql_log_bin=0/);
$sb->do_as_root("master", q/DROP USER 'slave_user'/);
$sb->do_as_root("master", q/set sql_log_bin=1/);
$sb->do_as_root("source", q/GRANT REPLICATION SLAVE ON *.* TO 'replica_user'@'%'/);
$sb->do_as_root("source", q/set sql_log_bin=0/);
$sb->do_as_root("source", q/DROP USER 'replica_user'/);
$sb->do_as_root("source", q/set sql_log_bin=1/);
# Need to wait for both slaves here to avoid deadlock
$sb->wait_for_slaves(slave => 'slave1');
$sb->wait_for_slaves(slave => 'slave2');
# Need to wait for both replicas here to avoid deadlock
$sb->wait_for_replicas(replica => 'replica1');
$sb->wait_for_replicas(replica => 'replica2');
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($master_dbh);
# Need to wait for both slaves here to avoid deadlock
$sb->wait_for_slaves(slave => 'slave1');
$sb->wait_for_slaves(slave => 'slave2');
$sb->wipe_clean($source_dbh);
# Need to wait for both replicas here to avoid deadlock
$sb->wait_for_replicas(replica => 'replica1');
$sb->wait_for_replicas(replica => 'replica2');
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
#
done_testing;