mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-25 05:44:59 +00:00
WIP Autodetect nodes & recurse to find new slaves
This commit is contained in:
@@ -25,6 +25,8 @@ require "$trunk/bin/pt-table-checksum";
|
||||
# Do this after requiring ptc, since it uses Mo
|
||||
require VersionParser;
|
||||
|
||||
my $ip = qr/\Q127.1\E|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $node1 = $sb->get_dbh_for('node1');
|
||||
@@ -74,40 +76,47 @@ $node1->do(qq/INSERT INTO dsns.dsns VALUES (1, 1, '$node1_dsn')/);
|
||||
# if no other cluster nodes are detected, in which case the user
|
||||
# probably didn't specifying --recursion-method dsn.
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args) },
|
||||
sub { pt_table_checksum::main(@args, qw(--no-autodetect-nodes)) },
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/h=127.1,P=12345 is a cluster node but no other nodes/,
|
||||
qr/h=127(?:\Q.0.0\E)?.1,P=12345 is a cluster node but no other nodes/,
|
||||
"Dies if no other nodes are found"
|
||||
);
|
||||
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
'--recursion-method', "dsn=$node1_dsn,D=dsns,t=dsns")
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
for my $args (
|
||||
["using recusion-method", '--recursion-method', "dsn=$node1_dsn,D=dsns,t=dsns"],
|
||||
["autodetecting everything"]
|
||||
)
|
||||
{
|
||||
my $test = shift @$args;
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
@$args)
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'errors'),
|
||||
0,
|
||||
"No diffs: no errors"
|
||||
);
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'errors'),
|
||||
0,
|
||||
"No diffs: no errors ($test)"
|
||||
);
|
||||
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'skipped'),
|
||||
0,
|
||||
"No diffs: no skips"
|
||||
);
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'skipped'),
|
||||
0,
|
||||
"No diffs: no skips ($test)"
|
||||
);
|
||||
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'diffs'),
|
||||
0,
|
||||
"No diffs: no diffs"
|
||||
);
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'diffs'),
|
||||
0,
|
||||
"No diffs: no diffs ($test)"
|
||||
);
|
||||
}
|
||||
|
||||
# Now really test checksumming a cluster. To create a diff we have to disable
|
||||
# the binlog. Although PXC doesn't need or use the binlog to communicate
|
||||
@@ -140,45 +149,53 @@ is(
|
||||
"Node3 not changed"
|
||||
);
|
||||
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
'--recursion-method', "dsn=$node1_dsn,D=dsns,t=dsns")
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
for my $args (
|
||||
["using recusion-method", '--recursion-method', "dsn=$node1_dsn,D=dsns,t=dsns"],
|
||||
["autodetecting everything"]
|
||||
)
|
||||
{
|
||||
my $test = shift @$args;
|
||||
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'errors'),
|
||||
0,
|
||||
"1 diff: no errors"
|
||||
);
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
@$args)
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'skipped'),
|
||||
0,
|
||||
"1 diff: no skips"
|
||||
);
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'errors'),
|
||||
0,
|
||||
"1 diff: no errors ($test)"
|
||||
);
|
||||
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'diffs'),
|
||||
1,
|
||||
"1 diff: 1 diff"
|
||||
) or diag($output);
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'skipped'),
|
||||
0,
|
||||
"1 diff: no skips ($test)"
|
||||
);
|
||||
|
||||
# 11-17T13:02:54 0 1 26 1 0 0.021 test.t
|
||||
like(
|
||||
$output,
|
||||
qr/^\S+\s+ # ts
|
||||
0\s+ # errors
|
||||
1\s+ # diffs
|
||||
26\s+ # rows
|
||||
\d+\s+ # chunks
|
||||
0\s+ # skipped
|
||||
\S+\s+ # time
|
||||
test.t$ # table
|
||||
/xm,
|
||||
"1 diff: it's in test.t"
|
||||
);
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'diffs'),
|
||||
1,
|
||||
"1 diff: 1 diff ($test)"
|
||||
) or diag($output);
|
||||
|
||||
# 11-17T13:02:54 0 1 26 1 0 0.021 test.t
|
||||
like(
|
||||
$output,
|
||||
qr/^\S+\s+ # ts
|
||||
0\s+ # errors
|
||||
1\s+ # diffs
|
||||
26\s+ # rows
|
||||
\d+\s+ # chunks
|
||||
0\s+ # skipped
|
||||
\S+\s+ # time
|
||||
test.t$ # table
|
||||
/xm,
|
||||
"1 diff: it's in test.t ($test)"
|
||||
);
|
||||
}
|
||||
|
||||
# #############################################################################
|
||||
# cluster, node1 -> slave, run on node1
|
||||
@@ -210,34 +227,42 @@ $slave_dbh->do("update test.t set c='zebra' where c='z'");
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1080385
|
||||
# Cluster nodes default to ROW format because that's what Galeara
|
||||
# works best with, even though it doesn't really use binlogs.
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
'--recursion-method', "dsn=$node1_dsn,D=dsns,t=dsns")
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
for my $args (
|
||||
["using recusion-method", '--recursion-method', "dsn=$node1_dsn,D=dsns,t=dsns"],
|
||||
["autodetecting everything"]
|
||||
)
|
||||
{
|
||||
my $test = shift @$args;
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
@$args)
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/replica h=127.1,P=12348 has binlog_format ROW/,
|
||||
"--check-binlog-format warns about slave's binlog format"
|
||||
);
|
||||
like(
|
||||
$output,
|
||||
qr/replica h=127(?:\Q.0.0\E)?\.1,P=12348 has binlog_format ROW/,
|
||||
"--check-binlog-format warns about slave's binlog format ($test)"
|
||||
);
|
||||
|
||||
# Now really test that diffs on the slave are detected.
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
@$args,
|
||||
qw(--no-check-binlog-format)),
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
# Now really test that diffs on the slave are detected.
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
'--recursion-method', "dsn=$node1_dsn,D=dsns,t=dsns",
|
||||
qw(--no-check-binlog-format)),
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'diffs'),
|
||||
1,
|
||||
"Detects diffs on slave of cluster node1"
|
||||
) or diag($output);
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'diffs'),
|
||||
1,
|
||||
"Detects diffs on slave of cluster node1 ($test)"
|
||||
) or diag($output);
|
||||
|
||||
}
|
||||
|
||||
$slave_dbh->disconnect;
|
||||
$sb->stop_sandbox('cslave1');
|
||||
|
||||
@@ -272,21 +297,28 @@ is(
|
||||
"Slave is changed"
|
||||
);
|
||||
|
||||
for my
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
'--recursion-method', "dsn=$node1_dsn,D=dsns,t=dsns",
|
||||
qw(--no-check-binlog-format -d test)),
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
for my $args (
|
||||
["using recusion-method", '--recursion-method', "dsn=$node1_dsn,D=dsns,t=dsns"],
|
||||
["autodetecting everything"]
|
||||
)
|
||||
{
|
||||
my $test = shift @$args;
|
||||
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'diffs'),
|
||||
0,
|
||||
"Limitation: does not detect diffs on slave of cluster node2"
|
||||
) or diag($output);
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
@$args,
|
||||
qw(--no-check-binlog-format -d test)),
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'diffs'),
|
||||
0,
|
||||
"Limitation: does not detect diffs on slave of cluster node2 ($test)"
|
||||
) or diag($output);
|
||||
}
|
||||
|
||||
$slave_dbh->disconnect;
|
||||
$sb->stop_sandbox('cslave1');
|
||||
|
||||
@@ -442,19 +474,27 @@ like(
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/the direct replica of h=127.1,P=12349 was not found or specified/,
|
||||
qr/the direct replica of h=$ip,P=12349 was not found or specified/,
|
||||
"Warns that direct replica of the master isn't found or specified",
|
||||
);
|
||||
|
||||
# Originally, these tested a dsn table with all nodes.
|
||||
# Use the other DSN table with all three nodes. Now the tool should
|
||||
# give a more specific warning than that ^.
|
||||
# Originally, these tested a dsn table with all nodes; now we hijack
|
||||
# those tests to also try the autodetection
|
||||
for my $args (
|
||||
["using recusion-method", '--recursion-method', "dsn=$node1_dsn,D=dsns,t=dsns"],
|
||||
["autodetecting everything"]
|
||||
)
|
||||
{
|
||||
my $test = shift @$args;
|
||||
|
||||
# Make a diff on node1. If ptc is really auto-detecting node1, then it
|
||||
# should report this diff.
|
||||
$node1->do("set sql_log_bin=0");
|
||||
$node1->do("update test.t set c='zebra' where c='z'");
|
||||
$node1->do("set sql_log_bin=1");
|
||||
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main($master_dsn,
|
||||
@$args,
|
||||
@@ -486,7 +526,7 @@ for my $args (
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Diffs will only be detected if the cluster is consistent with h=127.1,P=12345 because h=127.1,P=12349/,
|
||||
qr/Diffs will only be detected if the cluster is consistent with h=$ip,P=12345 because h=$ip,P=12349/,
|
||||
"Warns that diffs only detected if cluster consistent with direct replica ($test)",
|
||||
);
|
||||
|
||||
@@ -574,32 +614,40 @@ $sb->load_file('node4', "$sample/a-z.sql");
|
||||
# Add node4 in the cluster2 to the DSN table.
|
||||
$node1->do(qq/INSERT INTO dsns.dsns VALUES (5, null, '$c->{node4}->{dsn}')/);
|
||||
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
'--recursion-method', "dsn=$node1_dsn,D=dsns,t=dsns",
|
||||
qw(-d test))
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
for my $args (
|
||||
["using recusion-method", '--recursion-method', "dsn=$node1_dsn,D=dsns,t=dsns"],
|
||||
["autodetecting everything"]
|
||||
)
|
||||
{
|
||||
my $test = shift @$args;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/h=127.1,P=12345 is in cluster pt_sandbox_cluster/,
|
||||
"Detects that node1 is in pt_sandbox_cluster"
|
||||
);
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
@$args,
|
||||
qw(-d test))
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/h=127.1,P=2900 is in cluster cluster2/,
|
||||
"Detects that node4 is in cluster2"
|
||||
);
|
||||
like(
|
||||
$output,
|
||||
qr/h=127(?:\Q.0.0\E)?.1,P=12345 is in cluster pt_sandbox_cluster/,
|
||||
"Detects that node1 is in pt_sandbox_cluster ($test)"
|
||||
);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/test/,
|
||||
"Different clusters, no results"
|
||||
);
|
||||
like(
|
||||
$output,
|
||||
qr/h=127(?:\Q.0.0\E)?.1,P=2900 is in cluster cluster2/,
|
||||
"Detects that node4 is in cluster2 ($test)"
|
||||
);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/test/,
|
||||
"Different clusters, no results ($test)"
|
||||
);
|
||||
}
|
||||
|
||||
$sb->stop_sandbox(qw(node4 node5 node6));
|
||||
|
||||
# Restore the DSN table in case there are more tests.
|
||||
|
Reference in New Issue
Block a user