Files
percona-toolkit/t/pt-duplicate-key-checker/clustered_keys.t
Sveta Smirnova 5c999ca3e0 PT-2340 - Support MySQL 8.4
- Removed runtime.txt after discussion with Anastasia Alexandrova
- Added "use VersionParser" into tests in t/lib when needed
- Removed word master from tests for pt-archiver, pt-config-diff, pt-deadlock-logger, pt-duplicate-key-checker, pt-find, pt-fk-error-logger, pt-heartbeat, pt-index-usage, pt-ioprofile, pt-kill, pt-mysql-summary
- Removed word slave from tests for pt-archiver, pt-config-diff, pt-deadlock-logger, pt-duplicate-key-checker, pt-find, pt-fk-error-logger, pt-heartbeat, pt-index-usage, pt-ioprofile, pt-kill, pt-mysql-summary
- Updated modules for pt-archiver, pt-config-diff, pt-deadlock-logger, pt-duplicate-key-checker, pt-find, pt-fk-error-logger, pt-heartbeat, pt-index-usage, pt-ioprofile, pt-kill, pt-mysql-summary
- Changed mysql_ssl patch, so it is now short option s
- Added a check for existing zombies in t/pt-kill/execute_command.t
- Added bin/pt-galera-log-explainer to .gitignore
2024-07-27 01:59:52 +03:00

116 lines
3.8 KiB
Perl

#!/usr/bin/env perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More;
use PerconaTest;
use Sandbox;
require "$trunk/bin/pt-duplicate-key-checker";
require VersionParser;
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $dbh = $sb->get_dbh_for('source');
if ( !$dbh ) {
plan skip_all => 'Cannot connect to sandbox source';
}
my $cnf = "/tmp/12345/my.sandbox.cnf";
my $sample = "t/pt-duplicate-key-checker/samples/";
my @args = ('-F', $cnf, qw(-h 127.1));
$sb->wipe_clean($dbh);
$sb->create_dbs($dbh, ['test']);
my $transform_int = undef;
# In version 8.0 integer display width is deprecated and not shown in the outputs.
# So we need to transform our samples.
if ($sandbox_version ge '8.0') {
$transform_int = sub {
my $txt = slurp_file(shift);
$txt =~ s/int\(\d{1,2}\)/int/g;
print $txt;
};
}
# #############################################################################
# Issue 295: Enhance rules for clustered keys in mk-duplicate-key-checker
# #############################################################################
$sb->load_file('source', 't/pt-duplicate-key-checker/samples/issue_295.sql', 'test');
ok(
no_diff(
sub { pt_duplicate_key_checker::main(@args, qw(-d issue_295)) },
($sandbox_version ge '5.1' ? "$sample/issue_295-51.txt"
: "$sample/issue_295.txt"),
transform_sample => $transform_int
),
"Shorten, not remove, clustered dupes"
) or diag($test_diff);
# #############################################################################
# Error if InnoDB table has no PK or unique indexes
# https://bugs.launchpad.net/percona-toolkit/+bug/1036804
# #############################################################################
$sb->load_file('source', "t/pt-duplicate-key-checker/samples/idb-no-uniques-bug-894140.sql");
# PTDEBUG was auto-vivifying $clustered_key:
#
# PTDEBUG && _d('clustered key:', $clustered_key->{name},
# $clustered_key->{colnames});
#
# if ( $clustered_key
# && $args{clustered}
# && $args{tbl_info}->{engine}
# && $args{tbl_info}->{engine} =~ m/InnoDB/i )
# {
# push @dupes, $self->remove_clustered_duplicates($clustered_key...
#
# sub remove_clustered_duplicates {
# my ( $self, $ck, $keys, %args ) = @_;
# die "I need a ck argument" unless $ck;
# die "I need a keys argument" unless $keys;
# my $ck_cols = $ck->{colnames};
# my @dupes;
# KEY:
# for my $i ( 0 .. @$keys - 1 ) {
# my $key = $keys->[$i]->{colnames};
# if ( $key =~ m/$ck_cols$/ ) {
my $output = `PTDEBUG=1 $trunk/bin/pt-duplicate-key-checker F=$cnf -d bug_1036804 2>&1`;
unlike(
$output,
qr/Use of uninitialized value/,
'PTDEBUG doesn\'t auto-vivify cluster key hashref (bug 1036804)'
);
# #############################################################################
#
# https://bugs.launchpad.net/percona-toolkit/+bug/1201443
# #############################################################################
$sb->load_file('source', "t/pt-duplicate-key-checker/samples/fk_chosen_index_bug_1201443.sql");
$output = `$trunk/bin/pt-duplicate-key-checker F=$cnf -d fk_chosen_index_bug_1201443 2>&1`;
unlike(
$output,
qr/Use of uninitialized value/,
'fk_chosen_index_bug_1201443'
);
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;