PT-80 Collect replication slave information

This commit is contained in:
Carlos Salguero
2017-03-27 17:30:06 -03:00
parent 61c5ba4faa
commit be971eeee5
8 changed files with 148 additions and 13 deletions

View File

@@ -907,9 +907,10 @@ collect() {
log "Loop start: $(date +'TS %s.%N %F %T')"
local start_time=$(date +'%s')
local curr_time=$start_time
local ps_instrumentation_enabled=$($CMD_MYSQL $EXT_ARGV -e "SELECT ENABLED FROM performance_schema.setup_instruments WHERE NAME = 'transaction';" | sed '2q;d' | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')
local ps_instrumentation_enabled=$($CMD_MYSQL $EXT_ARGV -e 'SELECT ENABLED FROM performance_schema.setup_instruments WHERE NAME = "transaction";' \
| sed "2q;d" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')
if [ $ps_instrumentation_enabled != "yes" ]; then
if [ $ps_instrumentation_enabled != "yes"]; then
log "Performance Schema instrumentation is disabled"
fi
@@ -955,10 +956,13 @@ collect() {
(echo $ts; transactions) >>"$d/$p-transactions" &
fi
echo "$ps_instrumentation_enabled" > /tmp/k1
if [ "${mysql_version}" '>' "5.6" ] && [ $ps_instrumentation_enabled == "yes" ]; then
ps_locks_transactions "$d/$p-ps-locks-transactions"
fi
slave_status "$d/$p-slave-status" "${mysql_version}"
curr_time=$(date +'%s')
done
log "Loop end: $(date +'TS %s.%N %F %T')"
@@ -1099,7 +1103,7 @@ innodb_status() {
ps_locks_transactions() {
local outfile=$1
mysql -e 'select @@performance_schema' | grep "1" &>/dev/null
$CMD_MYSQL $EXT_ARGV -e 'select @@performance_schema' | grep "1" &>/dev/null
if [ $? -eq 0 ]; then
local status="select t.processlist_id, ml.* from performance_schema.metadata_locks ml join performance_schema.threads t on (ml.owner_thread_id=t.thread_id)\G"
@@ -1123,6 +1127,29 @@ ps_locks_transactions() {
}
slave_status() {
local outfile=$1
local mysql_version=$2
if [ "${mysql_version}" '<' "5.7" ]; then
local sql="SHOW SLAVE STATUS\G"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
else
local sql="SELECT * FROM performance_schema.replication_connection_configuration JOIN performance_schema.replication_applier_configuration USING(channel_name)\G"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
sql="SELECT * FROM replication_connection_status\G"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
sql="SELECT * FROM replication_applier_status JOIN replication_applier_status_by_coordinator USING(channel_name)\G"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
fi
}
# ###########################################################################
# End collect package
# ###########################################################################

View File

@@ -64,12 +64,15 @@ my %port_for = (
cslave1 => 12348, # cluster -> slave
host1 => 12345, # pt-upgrade
host2 => 12348, # pt-upgrade
chan_master1 => 2900,
chan_master2 => 2901,
chan_slave1 => 2902,
);
my %server_type = (
master => 1,
slave => 1,
node => 1,
master => 1,
slave => 1,
node => 1,
);
my $test_dbs = qr/^(?:mysql|information_schema|sakila|performance_schema|percona_test|sys)$/;
@@ -494,7 +497,7 @@ sub start_sandbox {
my $first_node = $args{first_node} ? $port_for{$args{first_node}} : '';
my $out = `$env $trunk/sandbox/start-sandbox cluster $port $first_node`;
die $out if $CHILD_ERROR;
}
}
my $dbh = $self->get_dbh_for($server, $args{cxn_opts});
my $dsn = $self->dsn_for($server);

View File

@@ -248,10 +248,12 @@ collect() {
(echo $ts; transactions) >>"$d/$p-transactions" &
fi
if [ "${mysql_version}" '>' "5.6" ] && [ $ps_instrumentation_enabled == "yes"]; then
if [ "${mysql_version}" '>' "5.6" ] && [ $ps_instrumentation_enabled == "yes" ]; then
ps_locks_transactions "$d/$p-ps-locks-transactions"
fi
slave_status "$d/$p-slave-status" "${mysql_version}"
curr_time=$(date +'%s')
done
log "Loop end: $(date +'TS %s.%N %F %T')"
@@ -428,6 +430,29 @@ ps_locks_transactions() {
}
slave_status() {
local outfile=$1
local mysql_version=$2
if [ "${mysql_version}" '<' "5.7" ]; then
local sql="SHOW SLAVE STATUS\G"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
else
local sql="SELECT * FROM performance_schema.replication_connection_configuration JOIN performance_schema.replication_applier_configuration USING(channel_name)\G"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
sql="SELECT * FROM replication_connection_status\G"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
sql="SELECT * FROM replication_applier_status JOIN replication_applier_status_by_coordinator USING(channel_name)\G"
echo -e "\n$sql\n" >> $outfile
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
fi
}
# ###########################################################################
# End collect package
# ###########################################################################

7
sandbox/gtid_on.sql Normal file
View File

@@ -0,0 +1,7 @@
SET GLOBAL master_info_repository = 'TABLE';
SET @@GLOBAL.relay_log_info_repository = 'TABLE';
SET @@GLOBAL.ENFORCE_GTID_CONSISTENCY=ON;
SET @@GLOBAL.GTID_MODE = OFF_PERMISSIVE;
SET @@GLOBAL.GTID_MODE = ON_PERMISSIVE;
SET @@GLOBAL.GTID_MODE = ON;

View File

@@ -0,0 +1,15 @@
STOP SLAVE FOR CHANNEL '';
SET GLOBAL master_info_repository = 'TABLE';
SET @@GLOBAL.relay_log_info_repository = 'TABLE';
SET @@GLOBAL.ENFORCE_GTID_CONSISTENCY=ON;
SET @@GLOBAL.GTID_MODE = OFF_PERMISSIVE;
SET @@GLOBAL.GTID_MODE = ON_PERMISSIVE;
SET @@GLOBAL.GTID_MODE = ON;
CHANGE MASTER TO master_host='127.0.0.1', master_port=12345, master_user='msandbox', master_password='msandbox', master_auto_position=1 FOR CHANNEL 'masterchan1';
CHANGE MASTER TO master_host='127.0.0.1', master_port=12346, master_user='msandbox', master_password='msandbox', master_auto_position=1 FOR CHANNEL 'masterchan2';
START SLAVE for channel 'masterchan1';
START SLAVE for channel 'masterchan2';

View File

@@ -186,7 +186,7 @@ type=$1 # master, slave or master-master
port=$2 # sandbox port number, e.g. 12345
master_port=$3 # master port if slave or master-master
if [ "$type" != "master" ] && [ "$type" != "slave" ] && [ "$type" != "master-master" ] && [ "$type" != "cluster" ]; then
if [ "$type" != "master" ] && [ "$type" != "slave" ] && [ "$type" != "master-master" ] && [ "$type" != "cluster" ] && [ "$type" != "channels" ]; then
die "Invalid sandbox type: $type. Valid types are master, slave, and master-master."
fi

View File

@@ -293,10 +293,23 @@ case $opt in
exit_status=$((exit_status | $?))
set_mysql_version
if [ $exit_status -eq 0 ]; then
./start-sandbox "${2:-"slave"}" 12346 12345
exit_status=$((exit_status | $?))
./start-sandbox "${2:-"slave"}" 12347 12346
exit_status=$((exit_status | $?))
if [ "${2:-""}" = "channels" ] && [ "$MYSQL_VERSION" '>' "5.6" ]; then
./start-sandbox master 12346
exit_status=$((exit_status | $?))
./start-sandbox master 12347
exit_status=$((exit_status | $?))
/tmp/12345/use < $PERCONA_TOOLKIT_BRANCH/sandbox/gtid_on.sql
exit_status=$?
/tmp/12346/use < $PERCONA_TOOLKIT_BRANCH/sandbox/gtid_on.sql
exit_status=$?
/tmp/12347/use < $PERCONA_TOOLKIT_BRANCH/sandbox/slave_channels.sql
exit_status=$?
else
./start-sandbox "${2:-"slave"}" 12346 12345
exit_status=$((exit_status | $?))
./start-sandbox "${2:-"slave"}" 12347 12346
exit_status=$((exit_status | $?))
fi
if [ "${2:-""}" = "cluster" ]; then
# Bit of magic here. 'start-sandbox cluster new_node old_node'

View File

@@ -453,6 +453,7 @@ SKIP: {
PerconaTest::kill_program(pid_file => $pid_file);
$output = `cat $dest/*-ps-locks-transactions 2>/dev/null`;
like(
$output,
qr/ STATE: ACTIVE/,
@@ -466,6 +467,50 @@ SKIP: {
);
}
cleanup();
my ($master1_dbh, $master1_dsn) = $sb->start_sandbox(
server => 'chan_master1',
type => 'master',
);
my ($master2_dbh, $master2_dsn) = $sb->start_sandbox(
server => 'chan_master2',
type => 'master',
);
my ($slave1_dbh, $slave1_dsn) = $sb->start_sandbox(
server => 'chan_slave1',
type => 'master',
);
my $slave1_port = $sb->port_for('chan_slave1');
$sb->load_file('chan_master1', "sandbox/gtid_on.sql", undef, no_wait => 1);
$sb->load_file('chan_master2', "sandbox/gtid_on.sql", undef, no_wait => 1);
$sb->load_file('chan_slave1', "sandbox/slave_channels.sql", undef, no_wait => 1);
my $cmd = "$trunk/bin/pt-stalk --no-stalk --iterations=1 --host=127.0.0.1 --port=$slave1_port --user=msandbox "
. "--password=msandbox --sleep 0 --run-time=10 --dest $dest --log $log_file --iterations=1 "
. "--run-time=2 --pid $pid_file --defaults-file=$cnf >$log_file 2>&1";
system($cmd);
sleep 5;
PerconaTest::kill_program(pid_file => $pid_file);
$output = `cat $dest/*-slave-status 2>/dev/null`;
if ( $sandbox_version lt '5.7' ) {
like(
$output,
qr/SHOW SLAVE STATUS/,
"MySQL 5.6 SLAVE STATUS"
);
} else {
like(
$output,
qr/FROM performance_schema.replication_connection_configuration JOIN performance_schema.replication_applier_configuration USING/,
"MySQL 5.7 SLAVE STATUS"
);
}
$sb->stop_sandbox(qw(chan_master1 chan_master2 chan_slave1));
# #############################################################################
# Done.
# #############################################################################