mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 05:29:30 +00:00
Fixes per Daniel's review
This commit is contained in:
@@ -411,76 +411,75 @@ test_so(
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1047335
|
||||
# #############################################################################
|
||||
|
||||
use File::Spec;
|
||||
|
||||
my $master3_port = 2900;
|
||||
my $master3_port = 2900;
|
||||
my $master_basedir = "/tmp/$master3_port";
|
||||
diag(`$trunk/sandbox/stop-sandbox $master3_port >/dev/null`);
|
||||
diag(`$trunk/sandbox/start-sandbox master $master3_port >/dev/null`);
|
||||
my $dbh3 = $sb->get_dbh_for("master3");
|
||||
|
||||
$sb->load_file('master3', File::Spec->catfile(qw(t lib samples bug_1047335_crashed_table.sql)));
|
||||
my $sth = $dbh3->prepare("INSERT INTO bug_1047335.crashed_table (trx_id, etc) VALUES(?, ?)");
|
||||
$sth->execute($_, $_ x 100) for 1..1000;
|
||||
$sth->finish();
|
||||
SKIP: {
|
||||
skip "No /dev/urandom, can't corrupt the database", 1
|
||||
unless -e q{/dev/urandom};
|
||||
|
||||
# Create the SI object before crashing the table
|
||||
my $tmp_si = new SchemaIterator(
|
||||
dbh => $dbh3,
|
||||
OptionParser => $o,
|
||||
Quoter => $q,
|
||||
TableParser => $tp,
|
||||
# This is needed because the way we corrupt tables
|
||||
# accidentally removes the database from SHOW DATABASES
|
||||
db => 'bug_1047335',
|
||||
);
|
||||
$sb->load_file('master3', "t/lib/samples/bug_1047335_crashed_table.sql");
|
||||
|
||||
my $master_basedir = File::Spec->catdir(File::Spec->tmpdir(), $master3_port);
|
||||
my $db_dir = File::Spec->catdir($master_basedir, "data", "bug_1047335");
|
||||
my $myi = glob(File::Spec->catfile($db_dir, "crashed_table.[Mm][Yy][Iy]"));
|
||||
my $frm = glob(File::Spec->catfile($db_dir, "crashed_table.[Ff][Rr][Mm]"));
|
||||
# Create the SI object before crashing the table
|
||||
my $tmp_si = new SchemaIterator(
|
||||
dbh => $dbh3,
|
||||
OptionParser => $o,
|
||||
Quoter => $q,
|
||||
TableParser => $tp,
|
||||
# This is needed because the way we corrupt tables
|
||||
# accidentally removes the database from SHOW DATABASES
|
||||
db => 'bug_1047335',
|
||||
);
|
||||
|
||||
die "Cannot find .myi file for crashed_table" unless $myi && -f $myi;
|
||||
my $db_dir = "$master_basedir/data/bug_1047335";
|
||||
my $myi = glob("$db_dir/crashed_table.[Mm][Yy][Iy]");
|
||||
my $frm = glob("$db_dir/crashed_table.[Ff][Rr][Mm]");
|
||||
|
||||
# Truncate the .myi file to corrupt it
|
||||
truncate($myi, 4096);
|
||||
die "Cannot find .myi file for crashed_table" unless $myi && -f $myi;
|
||||
|
||||
use File::Slurp qw( prepend_file append_file write_file );
|
||||
# Truncate the .myi file to corrupt it
|
||||
truncate($myi, 4096);
|
||||
|
||||
# Corrupt the .frm file
|
||||
open my $urand_fh, q{<}, "/dev/urandom"
|
||||
or die "Cannot open /dev/urandom";
|
||||
prepend_file($frm, scalar(<$urand_fh>));
|
||||
append_file($frm, scalar(<$urand_fh>));
|
||||
close $urand_fh;
|
||||
use File::Slurp qw( prepend_file append_file write_file );
|
||||
|
||||
$dbh3->do("FLUSH TABLES");
|
||||
eval { $dbh3->do("SELECT etc FROM bug_1047335.crashed_table WHERE etc LIKE '10001' ORDER BY id ASC LIMIT 1") };
|
||||
# Corrupt the .frm file
|
||||
open my $urand_fh, q{<}, "/dev/urandom"
|
||||
or die "Cannot open /dev/urandom";
|
||||
prepend_file($frm, scalar(<$urand_fh>));
|
||||
append_file($frm, scalar(<$urand_fh>));
|
||||
close $urand_fh;
|
||||
|
||||
$dbh3->do("FLUSH TABLES");
|
||||
eval { $dbh3->do("SELECT etc FROM bug_1047335.crashed_table WHERE etc LIKE '10001' ORDER BY id ASC LIMIT 1") };
|
||||
|
||||
my $w = '';
|
||||
{
|
||||
local $SIG{__WARN__} = sub { $w .= shift };
|
||||
1 while $tmp_si->next();
|
||||
}
|
||||
|
||||
like(
|
||||
$w,
|
||||
qr/bug_1047335.crashed_table because SHOW CREATE TABLE failed:/,
|
||||
"->next() gives a warning if ->get_create_table dies from a strange error",
|
||||
);
|
||||
|
||||
my $w = '';
|
||||
{
|
||||
local $SIG{__WARN__} = sub { $w .= shift };
|
||||
1 while $tmp_si->next();
|
||||
}
|
||||
|
||||
like(
|
||||
$w,
|
||||
qr/bug_1047335.crashed_table because SHOW CREATE TABLE failed:/,
|
||||
"->next() gives a warning if ->get_create_table dies from a strange error",
|
||||
);
|
||||
|
||||
$dbh3->do(q{DROP DATABASE IF EXISTS bug_1047335_2});
|
||||
$dbh3->do(q{CREATE DATABASE bug_1047335_2});
|
||||
|
||||
my $broken_frm = File::Spec->catfile($trunk, qw(t lib samples broken_tbl.frm));
|
||||
my $db_dir_2 = File::Spec->catdir($master_basedir, "data", "bug_1047335_2");
|
||||
my $broken_frm = "$trunk/t/lib/samples/broken_tbl.frm";
|
||||
my $db_dir_2 = "$master_basedir/data/bug_1047335_2";
|
||||
|
||||
use File::Copy qw(copy);
|
||||
|
||||
copy($broken_frm, $db_dir_2);
|
||||
diag(`cp $broken_frm $db_dir_2 2>&1`);
|
||||
|
||||
$dbh3->do("FLUSH TABLES");
|
||||
|
||||
$tmp_si = new SchemaIterator(
|
||||
my $tmp_si2 = new SchemaIterator(
|
||||
dbh => $dbh3,
|
||||
OptionParser => $o,
|
||||
Quoter => $q,
|
||||
@@ -490,10 +489,10 @@ $tmp_si = new SchemaIterator(
|
||||
db => 'bug_1047335_2',
|
||||
);
|
||||
|
||||
$w = '';
|
||||
my $w = '';
|
||||
{
|
||||
local $SIG{__WARN__} = sub { $w .= shift };
|
||||
1 while $tmp_si->next();
|
||||
1 while $tmp_si2->next();
|
||||
}
|
||||
|
||||
like(
|
||||
|
Reference in New Issue
Block a user