mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-02-27 02:00:57 +08:00
PT-2340 - Support MySQL 8.4
- Added test for replica lag check for pt-archiver - Re-added deprecated slave- options - Added tests for deprecation warnings and for legacy options for pt-archiver - Removed practically not supported options --replica-user and --replica-password from pt-archiver, pt-kill, pt-query-digest - Added legacy source/replica options (master/slave) variants and tests for pt-heartbeat, pt-online-schema-change, pt-replica-find, pt-replica-restart, pt-table-checksum, pt-table-sync - Updated modules after lib/MasterSlave.pm change
This commit is contained in:
@@ -29,7 +29,7 @@ elsif ( !$replica_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox replica';
|
||||
}
|
||||
else {
|
||||
plan tests => 24;
|
||||
plan tests => 30;
|
||||
}
|
||||
|
||||
$sb->create_dbs($source_dbh, [qw(test)]);
|
||||
@@ -131,6 +131,45 @@ is_deeply(
|
||||
'Synced OK with --replica-user'
|
||||
);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Option --slave-user is deprecated and will be removed in future versions./,
|
||||
'Deprecation warning not printed when option --replica-user provided'
|
||||
) or diag($output);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Option --slave-password is deprecated and will be removed in future versions./,
|
||||
'Deprecation warning not printed when option --replica-password provided'
|
||||
) or diag($output);
|
||||
|
||||
$sb->load_file('source', 't/pt-table-sync/samples/before.sql');
|
||||
$output = run('test1', 'test2', '--algorithms Chunk,GroupBy --no-bin-log --slave-user replica_user --slave-password replica_password');
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/INSERT INTO `test`.`test2`\(`a`, `b`\) VALUES \('1', 'en'\);\nINSERT INTO `test`.`test2`\(`a`, `b`\) VALUES \('2', 'ca'\);/,
|
||||
'Basic Chunk sync with --slave-user/--slave-password'
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
query_replica('select * from test.test2'),
|
||||
[ { a => 1, b => 'en' }, { a => 2, b => 'ca' } ],
|
||||
'Synced OK with --slave-user'
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Option --slave-user is deprecated and will be removed in future versions./,
|
||||
'Deprecation warning printed when option --slave-user provided'
|
||||
) or diag($output);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Option --slave-password is deprecated and will be removed in future versions./,
|
||||
'Deprecation warning printed when option --slave-password provided'
|
||||
) or diag($output);
|
||||
|
||||
$sb->load_file('source', 't/pt-table-sync/samples/before.sql');
|
||||
$output = run('test1', 'test2', '--algorithms Nibble --no-bin-log');
|
||||
is($output, "INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('1', 'en');
|
||||
|
||||
@@ -18,7 +18,7 @@ require "$trunk/bin/pt-table-sync";
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
|
||||
plan tests => 4;
|
||||
plan tests => 11;
|
||||
|
||||
# #############################################################################
|
||||
# Ensure that syncing source-source works OK
|
||||
@@ -26,13 +26,11 @@ plan tests => 4;
|
||||
|
||||
# Start up 12348 <-> 12349
|
||||
diag('Starting source-source servers...');
|
||||
#diag(`$trunk/sandbox/start-sandbox source-source 12348 12349 >/dev/null`);
|
||||
diag(`$trunk/sandbox/start-sandbox source-source 12348 12349`);
|
||||
my $source1_dbh = $sb->get_dbh_for('source1');
|
||||
my $source2_dbh = $sb->get_dbh_for('source2');
|
||||
|
||||
# Load some tables and data (on both, since they're source-source).
|
||||
$source1_dbh->do("CREATE DATABASE test");
|
||||
$sb->load_file("source1", "t/pt-table-sync/samples/before.sql");
|
||||
$sb->wait_for_replicas();
|
||||
$sb->wait_for_replicas(
|
||||
@@ -57,6 +55,7 @@ my $output = output(
|
||||
qw(--no-check-replica --sync-to-source --print --execute),
|
||||
"h=127.0.0.1,P=12348,u=msandbox,p=msandbox,D=test,t=test1")
|
||||
},
|
||||
stderr => 1
|
||||
);
|
||||
|
||||
# 0 = ok no diffs
|
||||
@@ -74,6 +73,18 @@ like(
|
||||
"SQL to sync diff"
|
||||
);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Option --sync-to-master is deprecated and will be removed in future versions./,
|
||||
'Deprecation warning not printed when option --sync-to-source provided'
|
||||
) or diag($output);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Option --\[no\]check-slave is deprecated and will be removed in future versions./,
|
||||
'Deprecation warning not printed when option --no-check-replica provided'
|
||||
) or diag($output);
|
||||
|
||||
|
||||
PerconaTest::wait_for_table($source1_dbh, "test.test1", "a=1 and b='mm'");
|
||||
my $rows = $source1_dbh->selectall_arrayref("SELECT * FROM test.test1");
|
||||
@@ -83,6 +94,81 @@ is_deeply(
|
||||
"Diff row synced on source1"
|
||||
);
|
||||
|
||||
diag('Stopping source-source servers...');
|
||||
diag(`$trunk/sandbox/stop-sandbox 12348 12349 >/dev/null`);
|
||||
# #############################################################################
|
||||
# Repeat the test with deprecated options.
|
||||
# #############################################################################
|
||||
|
||||
# Start up 12348 <-> 12349
|
||||
diag('Starting source-source servers...');
|
||||
diag(`$trunk/sandbox/start-sandbox source-source 12348 12349`);
|
||||
$source1_dbh = $sb->get_dbh_for('source1');
|
||||
$source2_dbh = $sb->get_dbh_for('source2');
|
||||
|
||||
$sb->load_file("source1", "t/pt-table-sync/samples/before.sql");
|
||||
$sb->wait_for_replicas();
|
||||
$sb->wait_for_replicas(
|
||||
source => 'source1',
|
||||
replica => 'source2',
|
||||
);
|
||||
|
||||
# Make source2 different from source1. So source2 has the _correct_ data,
|
||||
# and the sync below will make source1 have that data too.
|
||||
$source2_dbh->do("set sql_log_bin=0");
|
||||
$source2_dbh->do("update test.test1 set b='mm' where a=1");
|
||||
$source2_dbh->do("set sql_log_bin=1");
|
||||
|
||||
# This will make source1's data match the changed, correcct data on source2
|
||||
# (that is _not_ a typo). The sync direction is therefore source2 -> source1
|
||||
# because, given the command below, the given host source1 and with
|
||||
# --sync-to-source that makes source2 "the" source with the correct data.
|
||||
$exit_status = 0;
|
||||
$output = output(
|
||||
sub {
|
||||
$exit_status = pt_table_sync::main(
|
||||
qw(--no-check-slave --sync-to-master --print --execute),
|
||||
"h=127.0.0.1,P=12348,u=msandbox,p=msandbox,D=test,t=test1")
|
||||
},
|
||||
stderr =>1
|
||||
);
|
||||
|
||||
# 0 = ok no diffs
|
||||
# 1 = error
|
||||
# >1 = sum(@status{@ChangeHandler::ACTIONS})
|
||||
is(
|
||||
$exit_status,
|
||||
2,
|
||||
"Exit status 2"
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/REPLACE INTO `test`\.`test1`\s*\(`a`, `b`\) VALUES\s*\('1', 'mm'\)/,
|
||||
"SQL to sync diff"
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Option --sync-to-master is deprecated and will be removed in future versions./,
|
||||
'Deprecation warning printed when option --sync-to-master provided'
|
||||
) or diag($output);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Option --\[no\]check-slave is deprecated and will be removed in future versions./,
|
||||
'Deprecation warning printed when option --no-check-slave provided'
|
||||
) or diag($output);
|
||||
|
||||
|
||||
PerconaTest::wait_for_table($source1_dbh, "test.test1", "a=1 and b='mm'");
|
||||
$rows = $source1_dbh->selectall_arrayref("SELECT * FROM test.test1");
|
||||
is_deeply(
|
||||
$rows,
|
||||
[ [1, 'mm'], [2, 'ca'] ],
|
||||
"Diff row synced on source1"
|
||||
);
|
||||
|
||||
diag('Stopping source-source servers...');
|
||||
diag(`$trunk/sandbox/stop-sandbox 12348 12349 >/dev/null`);
|
||||
|
||||
|
||||
@@ -20,12 +20,13 @@ my $output;
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $source_dbh = $sb->get_dbh_for('source');
|
||||
my $replica_dbh = $sb->get_dbh_for('replica1');
|
||||
my $replica1_dbh = $sb->get_dbh_for('replica1');
|
||||
my $replica2_dbh = $sb->get_dbh_for('replica2');
|
||||
|
||||
if ( !$source_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox source';
|
||||
}
|
||||
elsif ( !$replica_dbh ) {
|
||||
elsif ( !$replica1_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox replica';
|
||||
}
|
||||
|
||||
@@ -59,7 +60,7 @@ like(
|
||||
"check-child-tables: error message"
|
||||
);
|
||||
|
||||
my $rows = $replica_dbh->selectall_arrayref("select * from on_del_cas.child2");
|
||||
my $rows = $replica1_dbh->selectall_arrayref("select * from on_del_cas.child2");
|
||||
is_deeply(
|
||||
$rows,
|
||||
[ [1,1] ],
|
||||
@@ -80,6 +81,76 @@ unlike(
|
||||
"check-child-tables: no error message with --print"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# --[no]check-source
|
||||
# #############################################################################
|
||||
# Connecting replica with wrong user name
|
||||
$replica1_dbh->do("STOP ${replica_name}");
|
||||
$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_port=12347, ${source_name}_user='does_not_exist'");
|
||||
$replica1_dbh->do("START ${replica_name}");
|
||||
|
||||
$output = output(
|
||||
sub {
|
||||
pt_table_sync::main($replica1_dsn, qw(--sync-to-source),
|
||||
qw(--execute -d on_del_cas --wait 0))
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/The server specified as a source has no connected replicas/,
|
||||
"Error when --check-source is enabled (default)"
|
||||
) or diag($output);
|
||||
|
||||
$output = output(
|
||||
sub {
|
||||
pt_table_sync::main($replica1_dsn, qw(--sync-to-source),
|
||||
qw(--execute -d on_del_cas --wait 0 --no-check-source))
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/The server specified as a source has no connected replicas/,
|
||||
"No wrong source error when --check-source is disabled"
|
||||
) or diag($output);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Option --\[no\]check-master is deprecated and will be removed in future versions./,
|
||||
'Deprecation warning not printed when option --no-check-source provided'
|
||||
) or diag($output);
|
||||
|
||||
# Legacy option
|
||||
$output = output(
|
||||
sub {
|
||||
pt_table_sync::main($replica1_dsn, qw(--sync-to-source),
|
||||
qw(--execute -d on_del_cas --wait 0 --no-check-master))
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/The server specified as a source has no connected replicas/,
|
||||
"No wrong source error when --check-master is disabled"
|
||||
) or diag($output);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Option --\[no\]check-master is deprecated and will be removed in future versions./,
|
||||
'Deprecation warning printed when option --no-check-master provided'
|
||||
) or diag($output);
|
||||
|
||||
$replica1_dbh->do("STOP ${replica_name}");
|
||||
$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_port=12345, ${source_name}_user='msandbox'");
|
||||
$replica1_dbh->do("START ${replica_name}");
|
||||
$replica1_dbh->do("STOP ${replica_name}");
|
||||
$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_port=12345, ${source_name}_user='msandbox'");
|
||||
$replica1_dbh->do("START ${replica_name}");
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
|
||||
Reference in New Issue
Block a user