mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
Fix pt-heartbeat/pxc.t. Exit early in test-env if wget fails. Add APP=FORK|mysql to start-sandbox so it too works around the pxc mysqld -V bug; add FORK=pxc to start_sandbox() calls.
This commit is contained in:
@@ -5395,7 +5395,7 @@ pt-heartbeat - Monitor MySQL replication delay.
|
|||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
Usage: pt-heartbeat [OPTION...] [DSN] --update|--monitor|--check|--stop
|
Usage: pt-heartbeat [OPTIONS] [DSN] --update|--monitor|--check|--stop
|
||||||
|
|
||||||
pt-heartbeat measures replication lag on a MySQL or PostgreSQL server. You can
|
pt-heartbeat measures replication lag on a MySQL or PostgreSQL server. You can
|
||||||
use it to update a master or monitor a replica. If possible, MySQL connection
|
use it to update a master or monitor a replica. If possible, MySQL connection
|
||||||
|
@@ -341,7 +341,7 @@ sub wait_for_slaves {
|
|||||||
sub {
|
sub {
|
||||||
my ($pong) = $slave2_dbh->selectrow_array(
|
my ($pong) = $slave2_dbh->selectrow_array(
|
||||||
"SELECT ping FROM percona_test.sentinel WHERE id=1 /* wait_for_slaves */");
|
"SELECT ping FROM percona_test.sentinel WHERE id=1 /* wait_for_slaves */");
|
||||||
return $ping eq $pong;
|
return $ping eq ($pong || '');
|
||||||
}, undef, 300
|
}, undef, 300
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -61,7 +61,8 @@ fi
|
|||||||
if [ -z "$MYSQL_BASE_DIR" ]; then
|
if [ -z "$MYSQL_BASE_DIR" ]; then
|
||||||
(
|
(
|
||||||
cd $MYSQL_BIN_DIR
|
cd $MYSQL_BIN_DIR
|
||||||
wget -q -O mysql.tar.gz http://hackmysql.com/barebones/$APP/$MYSQL/$ARCH
|
wget -q -O mysql.tar.gz http://hackmysql.com/barebones/$APP/$MYSQL/$ARCH \
|
||||||
|
|| exit 1
|
||||||
tar xvfz mysql.tar.gz
|
tar xvfz mysql.tar.gz
|
||||||
rm mysql.tar.gz
|
rm mysql.tar.gz
|
||||||
)
|
)
|
||||||
|
@@ -223,12 +223,16 @@ elif [ -x "$PERCONA_TOOLKIT_SANDBOX/libexec/mysqld" ]; then
|
|||||||
else
|
else
|
||||||
die "Cannot find executable mysqld in $PERCONA_TOOLKIT_SANDBOX/bin, $PERCONA_TOOLKIT_SANDBOX/sbin or $PERCONA_TOOLKIT_SANDBOX/libexec."
|
die "Cannot find executable mysqld in $PERCONA_TOOLKIT_SANDBOX/bin, $PERCONA_TOOLKIT_SANDBOX/sbin or $PERCONA_TOOLKIT_SANDBOX/libexec."
|
||||||
fi
|
fi
|
||||||
if [ $type != "cluster" ]; then
|
|
||||||
version=`$PERCONA_TOOLKIT_SANDBOX/$mysqld -V 2>/dev/null | awk '{print $3}' | cut -d. -f 1,2`;
|
APP="${FORK:-"mysql"}"
|
||||||
else
|
|
||||||
|
if [ $type = "cluster" -o $APP = "pxc" ]; then
|
||||||
ip=$(perl -MNet::Address::IP::Local -le 'print Net::Address::IP::Local->public')
|
ip=$(perl -MNet::Address::IP::Local -le 'print Net::Address::IP::Local->public')
|
||||||
version=`$PERCONA_TOOLKIT_SANDBOX/$mysqld -V --bind-address $ip 2>/dev/null | awk '{print $3}' | cut -d. -f 1,2`;
|
version=`$PERCONA_TOOLKIT_SANDBOX/$mysqld -V --bind-address $ip 2>/dev/null | awk '{print $3}' | cut -d. -f 1,2`;
|
||||||
|
else
|
||||||
|
version=`$PERCONA_TOOLKIT_SANDBOX/$mysqld -V 2>/dev/null | awk '{print $3}' | cut -d. -f 1,2`;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d "$PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version" ]; then
|
if [ ! -d "$PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version" ]; then
|
||||||
die "$PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version does not exist."
|
die "$PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version does not exist."
|
||||||
fi
|
fi
|
||||||
|
@@ -235,11 +235,11 @@ my ($slave_dbh, $slave_dsn) = $sb->start_sandbox(
|
|||||||
server => 'cslave1',
|
server => 'cslave1',
|
||||||
type => 'slave',
|
type => 'slave',
|
||||||
master => 'node1',
|
master => 'node1',
|
||||||
env => q/BINLOG_FORMAT="ROW"/,
|
env => q/FORK="pxc" BINLOG_FORMAT="ROW"/,
|
||||||
);
|
);
|
||||||
|
|
||||||
$sb->create_dbs($slave_dbh, ['test']);
|
$sb->create_dbs($slave_dbh, ['test']);
|
||||||
|
$sb->wait_for_slaves(master => 'node1', slave => 'cslave1');
|
||||||
start_update_instance($sb->port_for('cslave1'));
|
start_update_instance($sb->port_for('cslave1'));
|
||||||
PerconaTest::wait_for_table($slave_dbh, "test.heartbeat", "1=1");
|
PerconaTest::wait_for_table($slave_dbh, "test.heartbeat", "1=1");
|
||||||
|
|
||||||
@@ -292,31 +292,37 @@ like(
|
|||||||
my ($master_dbh, $master_dsn) = $sb->start_sandbox(
|
my ($master_dbh, $master_dsn) = $sb->start_sandbox(
|
||||||
server => 'cmaster',
|
server => 'cmaster',
|
||||||
type => 'master',
|
type => 'master',
|
||||||
env => q/BINLOG_FORMAT="ROW"/,
|
env => q/FORK="pxc" BINLOG_FORMAT="ROW"/,
|
||||||
);
|
);
|
||||||
|
|
||||||
my $cmaster_port = $sb->port_for('cmaster');
|
my $cmaster_port = $sb->port_for('cmaster');
|
||||||
|
|
||||||
$sb->create_dbs($master_dbh, ['test']);
|
$sb->create_dbs($master_dbh, ['test']);
|
||||||
|
$master_dbh->do("INSERT INTO percona_test.sentinel (id, ping) VALUES (1, '')");
|
||||||
$master_dbh->do("FLUSH LOGS");
|
$master_dbh->do("FLUSH LOGS");
|
||||||
$master_dbh->do("RESET MASTER");
|
$master_dbh->do("RESET MASTER");
|
||||||
|
|
||||||
$sb->set_as_slave('node1', 'cmaster');
|
$sb->set_as_slave('node1', 'cmaster');
|
||||||
|
$sb->wait_for_slaves(master => 'cmaster', slave => 'node1');
|
||||||
|
|
||||||
start_update_instance($sb->port_for('cmaster'));
|
start_update_instance($sb->port_for('cmaster'));
|
||||||
PerconaTest::wait_for_table($node1, "test.heartbeat", "server_id=$cmaster_port");
|
PerconaTest::wait_for_table($node1, "test.heartbeat", "server_id=$cmaster_port");
|
||||||
|
|
||||||
$output = output(sub{
|
# Auto-detecting the master id only works when ran on node1, the direct
|
||||||
pt_heartbeat::main($node1_dsn, qw(-D test --check --print-master-server-id)),
|
# slave of the master, because other nodes aren't slaves, but this could
|
||||||
},
|
# be made to work; see the node autodiscovery branch.
|
||||||
|
$output = output(
|
||||||
|
sub {
|
||||||
|
pt_heartbeat::main($node1_dsn,
|
||||||
|
qw(-D test --check --print-master-server-id)
|
||||||
|
)},
|
||||||
stderr => 1,
|
stderr => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
like(
|
like(
|
||||||
$output,
|
$output,
|
||||||
qr/^\d.\d{2} $cmaster_port$/,
|
qr/^\d.\d{2} $cmaster_port$/,
|
||||||
"--print-master-id works for master -> $node1_port, when run from $node1_port"
|
"Auto-detect master ID from node1"
|
||||||
);
|
);
|
||||||
|
|
||||||
# Wait until node2 & node3 get cmaster in their heartbeat tables
|
# Wait until node2 & node3 get cmaster in their heartbeat tables
|
||||||
@@ -324,38 +330,39 @@ $sb->wait_for_slaves(master => 'node1', slave => 'node2');
|
|||||||
$sb->wait_for_slaves(master => 'node1', slave => 'node3');
|
$sb->wait_for_slaves(master => 'node1', slave => 'node3');
|
||||||
|
|
||||||
foreach my $test (
|
foreach my $test (
|
||||||
[ $node2_port, $node2_dsn, $node2 ],
|
[ $node2_port, $node2_dsn, $node2, 'node2' ],
|
||||||
[ $node3_port, $node3_dsn, $node3 ],
|
[ $node3_port, $node3_dsn, $node3, 'node3' ],
|
||||||
) {
|
) {
|
||||||
my ($port, $dsn, $dbh) = @$test;
|
my ($port, $dsn, $dbh, $name) = @$test;
|
||||||
|
|
||||||
$output = output(sub{
|
$output = output(
|
||||||
pt_heartbeat::main($dsn, qw(-D test --check --print-master-server-id)),
|
sub {
|
||||||
},
|
pt_heartbeat::main($dsn,
|
||||||
|
qw(-D test --check --print-master-server-id)
|
||||||
|
)},
|
||||||
stderr => 1,
|
stderr => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
# This could be made to work, see the node autodiscovery branch
|
|
||||||
TODO: {
|
|
||||||
local $::TODO = "cmaster -> node1, other nodes can't autodetect the master";
|
|
||||||
like(
|
like(
|
||||||
$output,
|
$output,
|
||||||
qr/$cmaster_port/,
|
qr/server's master could not be automatically determined/,
|
||||||
"--print-master-id works for master -> $node1_port, when run from $port"
|
"Limitation: cannot auto-detect master id from $name"
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
$output = output(sub{
|
$output = output(
|
||||||
pt_heartbeat::main($dsn, qw(-D test --check --master-server-id), $cmaster_port),
|
sub {
|
||||||
},
|
pt_heartbeat::main($dsn,
|
||||||
|
qw(-D test --check --master-server-id), $cmaster_port
|
||||||
|
)},
|
||||||
stderr => 1,
|
stderr => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
$output =~ s/\d\.\d{2}/0.00/g;
|
$output =~ s/\d\.\d{2}/0.00/g;
|
||||||
|
|
||||||
is(
|
is(
|
||||||
$output,
|
$output,
|
||||||
"0.00\n",
|
"0.00\n",
|
||||||
"--check + explicit --master-server-id work for master -> node1, run from $port"
|
"$name --check --master-server-id $cmaster_port"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -146,7 +146,7 @@ is_deeply(
|
|||||||
my ($master_dbh, $master_dsn) = $sb->start_sandbox(
|
my ($master_dbh, $master_dsn) = $sb->start_sandbox(
|
||||||
server => 'cmaster',
|
server => 'cmaster',
|
||||||
type => 'master',
|
type => 'master',
|
||||||
env => q/BINLOG_FORMAT="ROW"/,
|
env => q/FORK="pxc" BINLOG_FORMAT="ROW"/,
|
||||||
);
|
);
|
||||||
|
|
||||||
$sb->set_as_slave('node1', 'cmaster');
|
$sb->set_as_slave('node1', 'cmaster');
|
||||||
|
@@ -183,7 +183,7 @@ my ($slave_dbh, $slave_dsn) = $sb->start_sandbox(
|
|||||||
server => 'cslave1',
|
server => 'cslave1',
|
||||||
type => 'slave',
|
type => 'slave',
|
||||||
master => 'node1',
|
master => 'node1',
|
||||||
env => q/BINLOG_FORMAT="ROW"/,
|
env => q/FORK="pxc" BINLOG_FORMAT="ROW"/,
|
||||||
);
|
);
|
||||||
|
|
||||||
# Add the slave to the DSN table.
|
# Add the slave to the DSN table.
|
||||||
@@ -251,7 +251,7 @@ $sb->stop_sandbox('cslave1');
|
|||||||
server => 'cslave1',
|
server => 'cslave1',
|
||||||
type => 'slave',
|
type => 'slave',
|
||||||
master => 'node2',
|
master => 'node2',
|
||||||
env => q/BINLOG_FORMAT="ROW"/,
|
env => q/FORK="pxc" BINLOG_FORMAT="ROW"/,
|
||||||
);
|
);
|
||||||
|
|
||||||
# Wait for the slave to apply the binlogs from node2 (its master).
|
# Wait for the slave to apply the binlogs from node2 (its master).
|
||||||
@@ -300,7 +300,7 @@ $node1->do(qq/DELETE FROM dsns.dsns WHERE id=4/);
|
|||||||
my ($master_dbh, $master_dsn) = $sb->start_sandbox(
|
my ($master_dbh, $master_dsn) = $sb->start_sandbox(
|
||||||
server => 'cmaster',
|
server => 'cmaster',
|
||||||
type => 'master',
|
type => 'master',
|
||||||
env => q/BINLOG_FORMAT="ROW"/,
|
env => q/FORK="pxc" BINLOG_FORMAT="ROW"/,
|
||||||
);
|
);
|
||||||
|
|
||||||
# Since master is new, node1 shouldn't have binlog to replay.
|
# Since master is new, node1 shouldn't have binlog to replay.
|
||||||
|
Reference in New Issue
Block a user