Rewrite how MasterSlave handles --recursion-methods.

This commit is contained in:
Daniel Nichter
2012-08-02 10:57:36 -06:00
parent e29aa514e3
commit e6d31a666a
11 changed files with 961 additions and 801 deletions

View File

@@ -22,13 +22,11 @@ use PerconaTest;
use Data::Dumper;
my $ms = new MasterSlave();
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 $master_dsn = {
h => '127.1',
P => '12345',
@@ -36,28 +34,29 @@ my $master_dsn = {
p => 'msandbox',
};
# ############################################################################
# get_slaves() wrapper around recurse_to_slaves()
# ############################################################################
my $q = new Quoter;
my $o = new OptionParser(description => 'MasterSlave');
$o->get_specs("$trunk/bin/pt-table-checksum");
my $ms = new MasterSlave(
OptionParser => $o,
DSNParser => $dp,
Quoter => $q,
);
# ############################################################################
# get_slaves() wrapper around recurse_to_slaves()
# ############################################################################
SKIP: {
skip "Cannot connect to sandbox master", 2 unless $master_dbh;
local @ARGV = ();
$o->get_opts();
my $slaves = $ms->get_slaves(
dbh => $master_dbh,
dsn => $master_dsn,
recursion_method => $o->got('recursion-method')
? $o->get('recursion-method')
: [],
recurse => $o->get('recurse'),
DSNParser => $dp,
Quoter => $q,
make_cxn => sub {
dbh => $master_dbh,
dsn => $master_dsn,
make_cxn => sub {
my $cxn = new Cxn(
@_,
DSNParser => $dp,
@@ -83,7 +82,7 @@ SKIP: {
master_id => 12345,
source => 'hosts',
},
'get_slaves() from recurse_to_slaves() with a default --recursion-method works'
'get_slaves() from recurse_to_slaves() with a default --recursion-method'
);
my ($id) = $slaves->[0]->dbh()->selectrow_array('SELECT @@SERVER_ID');
@@ -102,15 +101,9 @@ SKIP: {
$o->get_opts();
$slaves = $ms->get_slaves(
recursion_method => $o->got('recursion-method')
? $o->get('recursion-method')
: [],
recurse => $o->get('recurse'),
DSNParser => $dp,
Quoter => $q,
dbh => $master_dbh,
dsn => $master_dsn,
make_cxn => sub {
dbh => $master_dbh,
dsn => $master_dsn,
make_cxn => sub {
my $cxn = new Cxn(
@_,
DSNParser => $dp,
@@ -154,15 +147,9 @@ SKIP: {
throws_ok(
sub {
$slaves = $ms->get_slaves(
recursion_method => $o->got('recursion-method')
? $o->get('recursion-method')
: [],
recurse => $o->get('recurse'),
DSNParser => $dp,
Quoter => $q,
dbh => $ro_dbh,
dsn => $ro_dsn,
make_cxn => sub {
dbh => $ro_dbh,
dsn => $ro_dsn,
make_cxn => sub {
my $cxn = new Cxn(
@_,
DSNParser => $dp,
@@ -180,15 +167,9 @@ SKIP: {
@ARGV = ('--recursion-method', 'none');
$o->get_opts();
$slaves = $ms->get_slaves(
recursion_method => $o->got('recursion-method')
? $o->get('recursion-method')
: [],
recurse => $o->get('recurse'),
DSNParser => $dp,
Quoter => $q,
dbh => $ro_dbh,
dsn => $ro_dsn,
make_cxn => sub {
dbh => $ro_dbh,
dsn => $ro_dsn,
make_cxn => sub {
my $cxn = new Cxn(
@_,
DSNParser => $dp,
@@ -204,14 +185,13 @@ SKIP: {
"No privs needed for --recursion-method=none (bug 987694)"
);
@ARGV = ('--recursion-method', 'none', '--recurse', '2');
$o->get_opts();
my $recursed = 0;
$ms->recurse_to_slaves(
{ dsn_parser => $dp,
dbh => $ro_dbh,
dsn => $ro_dsn,
recurse => 2,
callback => sub { $recursed++ },
method => [ 'none' ],
{ dbh => $ro_dbh,
dsn => $ro_dsn,
callback => sub { $recursed++ },
});
is(
$recursed,
@@ -245,10 +225,10 @@ foreach my $port ( values %port_for ) {
diag(`$trunk/sandbox/stop-sandbox $port >/dev/null 2>&1`);
}
}
diag(`$trunk/sandbox/start-sandbox master 2900 >/dev/null 2>&1`);
diag(`$trunk/sandbox/start-sandbox slave 2903 2900 >/dev/null 2>&1`);
diag(`$trunk/sandbox/start-sandbox slave 2901 2900 >/dev/null 2>&1`);
diag(`$trunk/sandbox/start-sandbox slave 2902 2901 >/dev/null 2>&1`);
diag(`$trunk/sandbox/start-sandbox master 2900`);
diag(`$trunk/sandbox/start-sandbox slave 2903 2900`);
diag(`$trunk/sandbox/start-sandbox slave 2901 2900`);
diag(`$trunk/sandbox/start-sandbox slave 2902 2901`);
# I discovered something weird while updating this test. Above, you see that
# slave2 is started first, then the others. Before, slave2 was started last,
@@ -293,11 +273,12 @@ my $skip_callback = sub {
. " from $dsn->{source}");
};
@ARGV = ('--recurse', '2');
$o->get_opts();
$ms->recurse_to_slaves(
{ dsn_parser => $dp,
dbh => $dbh,
{ dbh => $dbh,
dsn => $dsn,
recurse => 2,
callback => $callback,
skip_callback => $skip_callback,
});
@@ -685,10 +666,7 @@ $sb->load_file('master', "t/lib/samples/MasterSlave/dsn_table.sql");
$o->get_opts();
my $slaves = $ms->get_slaves(
recursion_method => $o->got('recursion-method')
? $o->get('recursion-method')
: [],
recurse => $o->get('recurse'),
OptionParser => $o,
DSNParser => $dp,
Quoter => $q,
make_cxn => sub {
@@ -735,7 +713,7 @@ eval {
like(
$EVAL_ERROR,
qr/Invalid recursion method: stuff/,
"Invalid recursion methods are caught",
"--recursion-method stuff causes error"
);
local $EVAL_ERROR;
@@ -746,17 +724,18 @@ eval {
like(
$EVAL_ERROR,
qr/Invalid combination of recursion methods: processlist, stuff/,
"Invalid recursion methods are caught",
"--recursion-method processlist,stuff causes error",
);
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($master_dbh);
diag(`$trunk/sandbox/stop-sandbox 2903 2902 2901 2900 >/dev/null 2>&1`);
diag(`$trunk/sandbox/stop-sandbox 2903 2902 2901 2900`);
diag(`/tmp/12346/use -e "set global read_only=1"`);
diag(`/tmp/12347/use -e "set global read_only=1"`);
diag(`$trunk/sandbox/test-env reset >/dev/null 2>&1`);
$sb->wait_for_slaves();
diag(`$trunk/sandbox/test-env reset`);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;
exit;