mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-09 07:30:02 +00:00
Merge latest.
This commit is contained in:
@@ -5395,7 +5395,7 @@ pt-heartbeat - Monitor MySQL replication delay.
|
||||
|
||||
=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
|
||||
use it to update a master or monitor a replica. If possible, MySQL connection
|
||||
|
@@ -341,7 +341,7 @@ sub wait_for_slaves {
|
||||
sub {
|
||||
my ($pong) = $slave2_dbh->selectrow_array(
|
||||
"SELECT ping FROM percona_test.sentinel WHERE id=1 /* wait_for_slaves */");
|
||||
return $ping eq $pong;
|
||||
return $ping eq ($pong || '');
|
||||
}, undef, 300
|
||||
);
|
||||
}
|
||||
|
@@ -61,7 +61,8 @@ fi
|
||||
if [ -z "$MYSQL_BASE_DIR" ]; then
|
||||
(
|
||||
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
|
||||
rm mysql.tar.gz
|
||||
)
|
||||
|
@@ -223,12 +223,16 @@ elif [ -x "$PERCONA_TOOLKIT_SANDBOX/libexec/mysqld" ]; then
|
||||
else
|
||||
die "Cannot find executable mysqld in $PERCONA_TOOLKIT_SANDBOX/bin, $PERCONA_TOOLKIT_SANDBOX/sbin or $PERCONA_TOOLKIT_SANDBOX/libexec."
|
||||
fi
|
||||
if [ $type != "cluster" ]; then
|
||||
version=`$PERCONA_TOOLKIT_SANDBOX/$mysqld -V 2>/dev/null | awk '{print $3}' | cut -d. -f 1,2`;
|
||||
else
|
||||
|
||||
APP="${FORK:-"mysql"}"
|
||||
|
||||
if [ $type = "cluster" -o $APP = "pxc" ]; then
|
||||
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`;
|
||||
else
|
||||
version=`$PERCONA_TOOLKIT_SANDBOX/$mysqld -V 2>/dev/null | awk '{print $3}' | cut -d. -f 1,2`;
|
||||
fi
|
||||
|
||||
if [ ! -d "$PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version" ]; then
|
||||
die "$PERCONA_TOOLKIT_BRANCH/sandbox/servers/$version does not exist."
|
||||
fi
|
||||
|
@@ -81,7 +81,7 @@ sub start_update_instance {
|
||||
exit 1;
|
||||
}
|
||||
push @exec_pids, $pid;
|
||||
|
||||
|
||||
PerconaTest::wait_for_files($pidfile);
|
||||
ok(
|
||||
-f $pidfile,
|
||||
@@ -235,11 +235,11 @@ my ($slave_dbh, $slave_dsn) = $sb->start_sandbox(
|
||||
server => 'cslave1',
|
||||
type => 'slave',
|
||||
master => 'node1',
|
||||
env => q/BINLOG_FORMAT="ROW"/,
|
||||
env => q/FORK="pxc" BINLOG_FORMAT="ROW"/,
|
||||
);
|
||||
|
||||
$sb->create_dbs($slave_dbh, ['test']);
|
||||
|
||||
$sb->wait_for_slaves(master => 'node1', slave => 'cslave1');
|
||||
start_update_instance($sb->port_for('cslave1'));
|
||||
PerconaTest::wait_for_table($slave_dbh, "test.heartbeat", "1=1");
|
||||
|
||||
@@ -292,31 +292,37 @@ like(
|
||||
my ($master_dbh, $master_dsn) = $sb->start_sandbox(
|
||||
server => 'cmaster',
|
||||
type => 'master',
|
||||
env => q/BINLOG_FORMAT="ROW"/,
|
||||
env => q/FORK="pxc" BINLOG_FORMAT="ROW"/,
|
||||
);
|
||||
|
||||
my $cmaster_port = $sb->port_for('cmaster');
|
||||
|
||||
$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("RESET MASTER");
|
||||
|
||||
$sb->set_as_slave('node1', 'cmaster');
|
||||
$sb->wait_for_slaves(master => 'cmaster', slave => 'node1');
|
||||
|
||||
start_update_instance($sb->port_for('cmaster'));
|
||||
PerconaTest::wait_for_table($node1, "test.heartbeat", "server_id=$cmaster_port");
|
||||
|
||||
$output = output(sub{
|
||||
pt_heartbeat::main($node1_dsn, qw(-D test --check --print-master-server-id)),
|
||||
},
|
||||
# Auto-detecting the master id only works when ran on node1, the direct
|
||||
# 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,
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
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
|
||||
@@ -324,38 +330,39 @@ $sb->wait_for_slaves(master => 'node1', slave => 'node2');
|
||||
$sb->wait_for_slaves(master => 'node1', slave => 'node3');
|
||||
|
||||
foreach my $test (
|
||||
[ $node2_port, $node2_dsn, $node2 ],
|
||||
[ $node3_port, $node3_dsn, $node3 ],
|
||||
[ $node2_port, $node2_dsn, $node2, 'node2' ],
|
||||
[ $node3_port, $node3_dsn, $node3, 'node3' ],
|
||||
) {
|
||||
my ($port, $dsn, $dbh) = @$test;
|
||||
my ($port, $dsn, $dbh, $name) = @$test;
|
||||
|
||||
$output = output(sub{
|
||||
pt_heartbeat::main($dsn, qw(-D test --check --print-master-server-id)),
|
||||
},
|
||||
$output = output(
|
||||
sub {
|
||||
pt_heartbeat::main($dsn,
|
||||
qw(-D test --check --print-master-server-id)
|
||||
)},
|
||||
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(
|
||||
$output,
|
||||
qr/$cmaster_port/,
|
||||
"--print-master-id works for master -> $node1_port, when run from $port"
|
||||
);
|
||||
}
|
||||
like(
|
||||
$output,
|
||||
qr/server's master could not be automatically determined/,
|
||||
"Limitation: cannot auto-detect master id from $name"
|
||||
);
|
||||
|
||||
$output = output(sub{
|
||||
pt_heartbeat::main($dsn, qw(-D test --check --master-server-id), $cmaster_port),
|
||||
},
|
||||
$output = output(
|
||||
sub {
|
||||
pt_heartbeat::main($dsn,
|
||||
qw(-D test --check --master-server-id), $cmaster_port
|
||||
)},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
$output =~ s/\d\.\d{2}/0.00/g;
|
||||
|
||||
is(
|
||||
$output,
|
||||
"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(
|
||||
server => 'cmaster',
|
||||
type => 'master',
|
||||
env => q/BINLOG_FORMAT="ROW"/,
|
||||
env => q/FORK="pxc" BINLOG_FORMAT="ROW"/,
|
||||
);
|
||||
|
||||
$sb->set_as_slave('node1', 'cmaster');
|
||||
|
@@ -183,7 +183,7 @@ my ($slave_dbh, $slave_dsn) = $sb->start_sandbox(
|
||||
server => 'cslave1',
|
||||
type => 'slave',
|
||||
master => 'node1',
|
||||
env => q/BINLOG_FORMAT="ROW"/,
|
||||
env => q/FORK="pxc" BINLOG_FORMAT="ROW"/,
|
||||
);
|
||||
|
||||
# Add the slave to the DSN table.
|
||||
@@ -251,7 +251,7 @@ $sb->stop_sandbox('cslave1');
|
||||
server => 'cslave1',
|
||||
type => 'slave',
|
||||
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).
|
||||
@@ -300,7 +300,7 @@ $node1->do(qq/DELETE FROM dsns.dsns WHERE id=4/);
|
||||
my ($master_dbh, $master_dsn) = $sb->start_sandbox(
|
||||
server => 'cmaster',
|
||||
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.
|
||||
|
Reference in New Issue
Block a user