Fixes per Daniel's review

This commit is contained in:
Brian Fraser
2012-11-09 12:07:14 -03:00
parent ad4d69b3e2
commit 173a5766be
3 changed files with 1094 additions and 79 deletions

View File

@@ -411,76 +411,75 @@ test_so(
# https://bugs.launchpad.net/percona-toolkit/+bug/1047335 # https://bugs.launchpad.net/percona-toolkit/+bug/1047335
# ############################################################################# # #############################################################################
use File::Spec; my $master3_port = 2900;
my $master_basedir = "/tmp/$master3_port";
my $master3_port = 2900;
diag(`$trunk/sandbox/stop-sandbox $master3_port >/dev/null`); diag(`$trunk/sandbox/stop-sandbox $master3_port >/dev/null`);
diag(`$trunk/sandbox/start-sandbox master $master3_port >/dev/null`); diag(`$trunk/sandbox/start-sandbox master $master3_port >/dev/null`);
my $dbh3 = $sb->get_dbh_for("master3"); my $dbh3 = $sb->get_dbh_for("master3");
$sb->load_file('master3', File::Spec->catfile(qw(t lib samples bug_1047335_crashed_table.sql))); SKIP: {
my $sth = $dbh3->prepare("INSERT INTO bug_1047335.crashed_table (trx_id, etc) VALUES(?, ?)"); skip "No /dev/urandom, can't corrupt the database", 1
$sth->execute($_, $_ x 100) for 1..1000; unless -e q{/dev/urandom};
$sth->finish();
# Create the SI object before crashing the table $sb->load_file('master3', "t/lib/samples/bug_1047335_crashed_table.sql");
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',
);
my $master_basedir = File::Spec->catdir(File::Spec->tmpdir(), $master3_port); # Create the SI object before crashing the table
my $db_dir = File::Spec->catdir($master_basedir, "data", "bug_1047335"); my $tmp_si = new SchemaIterator(
my $myi = glob(File::Spec->catfile($db_dir, "crashed_table.[Mm][Yy][Iy]")); dbh => $dbh3,
my $frm = glob(File::Spec->catfile($db_dir, "crashed_table.[Ff][Rr][Mm]")); 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 die "Cannot find .myi file for crashed_table" unless $myi && -f $myi;
truncate($myi, 4096);
use File::Slurp qw( prepend_file append_file write_file ); # Truncate the .myi file to corrupt it
truncate($myi, 4096);
# Corrupt the .frm file use File::Slurp qw( prepend_file append_file write_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"); # Corrupt the .frm file
eval { $dbh3->do("SELECT etc FROM bug_1047335.crashed_table WHERE etc LIKE '10001' ORDER BY id ASC LIMIT 1") }; 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{DROP DATABASE IF EXISTS bug_1047335_2});
$dbh3->do(q{CREATE DATABASE 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 $broken_frm = "$trunk/t/lib/samples/broken_tbl.frm";
my $db_dir_2 = File::Spec->catdir($master_basedir, "data", "bug_1047335_2"); my $db_dir_2 = "$master_basedir/data/bug_1047335_2";
use File::Copy qw(copy); diag(`cp $broken_frm $db_dir_2 2>&1`);
copy($broken_frm, $db_dir_2);
$dbh3->do("FLUSH TABLES"); $dbh3->do("FLUSH TABLES");
$tmp_si = new SchemaIterator( my $tmp_si2 = new SchemaIterator(
dbh => $dbh3, dbh => $dbh3,
OptionParser => $o, OptionParser => $o,
Quoter => $q, Quoter => $q,
@@ -490,10 +489,10 @@ $tmp_si = new SchemaIterator(
db => 'bug_1047335_2', db => 'bug_1047335_2',
); );
$w = ''; my $w = '';
{ {
local $SIG{__WARN__} = sub { $w .= shift }; local $SIG{__WARN__} = sub { $w .= shift };
1 while $tmp_si->next(); 1 while $tmp_si2->next();
} }
like( like(

View File

@@ -900,52 +900,68 @@ is_deeply(
# We need to create a new server here, otherwise the whole test suite might die # We need to create a new server here, otherwise the whole test suite might die
# if the crashed table can't be dropped. # if the crashed table can't be dropped.
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/stop-sandbox $master3_port >/dev/null`);
diag(`$trunk/sandbox/start-sandbox master $master3_port >/dev/null`); diag(`$trunk/sandbox/start-sandbox master $master3_port >/dev/null`);
my $dbh3 = $sb->get_dbh_for("master3"); my $dbh3 = $sb->get_dbh_for("master3");
$sb->load_file('master3', File::Spec->catfile(qw(t lib samples bug_1047335_crashed_table.sql))); $sb->load_file('master3', "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};
my $master_basedir = File::Spec->catdir(File::Spec->tmpdir(), $master3_port); my $db_dir = "$master_basedir/data/bug_1047335";
my $db_dir = File::Spec->catdir($master_basedir, "data", "bug_1047335"); my $myi = glob("$db_dir/crashed_table.[Mm][Yy][Iy]");
my $myi = glob(File::Spec->catfile($db_dir, "crashed_table.[Mm][Yy][Iy]")); my $frm = glob("$db_dir/crashed_table.[Ff][Rr][Mm]");
my $frm = glob(File::Spec->catfile($db_dir, "crashed_table.[Ff][Rr][Mm]"));
die "Cannot find .myi file for crashed_table" unless $myi && -f $myi; die "Cannot find .myi file for crashed_table" unless $myi && -f $myi;
# Truncate the .myi file to corrupt it # Truncate the .myi file to corrupt it
truncate($myi, 4096); truncate($myi, 4096);
# Corrupt the .frm file # Corrupt the .frm file
open my $urand_fh, q{<}, "/dev/urandom" open my $urand_fh, q{<}, "/dev/urandom"
or die "Cannot open /dev/urandom: $OS_ERROR"; or die "Cannot open /dev/urandom: $OS_ERROR";
open my $tmp_fh, q{>}, $frm open my $tmp_fh, q{>}, $frm
or die "Cannot open $frm: $OS_ERROR"; or die "Cannot open $frm: $OS_ERROR";
print { $tmp_fh } scalar(<$urand_fh>), slurp_file($frm), scalar(<$urand_fh>); print { $tmp_fh } scalar(<$urand_fh>), slurp_file($frm), scalar(<$urand_fh>);
close $tmp_fh; close $tmp_fh;
close $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") };
eval { $tp->get_create_table($dbh3, 'bug_1047335', 'crashed_table') };
ok(
$EVAL_ERROR,
"get_create_table dies if SHOW CREATE TABLE failed",
);
# This might fail. Doesn't matter -- stop_sandbox will just rm -rf the folder
eval { $dbh3->do("DROP DATABASE IF EXISTS bug_1047335") };
}
$dbh3->do(q{DROP DATABASE IF EXISTS bug_1047335_2});
$dbh3->do(q{CREATE DATABASE bug_1047335_2});
my $broken_frm = "$trunk/t/lib/samples/broken_tbl.frm";
my $db_dir_2 = "$master_basedir/data/bug_1047335_2";
diag(`cp $broken_frm $db_dir_2 2>&1`);
$dbh3->do("FLUSH TABLES"); $dbh3->do("FLUSH TABLES");
eval { $dbh3->do("SELECT etc FROM bug_1047335.crashed_table WHERE etc LIKE '10001' ORDER BY id ASC LIMIT 1") };
eval { $tp->get_create_table($dbh3, 'bug_1047335', 'crashed_table') }; eval { $tp->get_create_table($dbh3, 'bug_1047335_2', 'broken_tbl') };
ok( ok(
$EVAL_ERROR, $EVAL_ERROR,
"get_create_table dies if SHOW CREATE TABLE failed", "get_create_table dies if SHOW CREATE TABLE failed (using broken_tbl.frm)",
); );
# This might fail. Doesn't matter -- stop_sandbox will just rm -rf the folder
eval { $dbh3->do("DROP DATABASE IF EXISTS bug_1047335") };
diag(`$trunk/sandbox/stop-sandbox $master3_port >/dev/null`); diag(`$trunk/sandbox/stop-sandbox $master3_port >/dev/null`);
# ############################################################################# # #############################################################################

File diff suppressed because it is too large Load Diff