mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-19 08:56:34 +00:00
Merge pull request #196 from percona/issue-1642754
Issue 1642754 Collect replication slave information
This commit is contained in:
26
bin/pt-stalk
26
bin/pt-stalk
@@ -956,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')"
|
||||
@@ -1124,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
|
||||
}
|
||||
|
||||
collect_mysql_variables() {
|
||||
local outfile=$1
|
||||
|
||||
|
@@ -64,6 +64,9 @@ 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 = (
|
||||
|
@@ -252,6 +252,8 @@ collect() {
|
||||
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,30 @@ 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
|
||||
|
||||
}
|
||||
|
||||
collect_mysql_variables() {
|
||||
local outfile=$1
|
||||
|
||||
@@ -446,6 +472,7 @@ collect_mysql_variables() {
|
||||
sql="select * from performance_schema.status_by_thread order by thread_id, variable_name; "
|
||||
echo -e "\n$sql\n" >> $outfile
|
||||
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $outfile
|
||||
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
|
7
sandbox/gtid_on.sql
Normal file
7
sandbox/gtid_on.sql
Normal 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;
|
||||
|
15
sandbox/slave_channels.sql
Normal file
15
sandbox/slave_channels.sql
Normal 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';
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -293,10 +293,23 @@ case $opt in
|
||||
exit_status=$((exit_status | $?))
|
||||
set_mysql_version
|
||||
if [ $exit_status -eq 0 ]; then
|
||||
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'
|
||||
|
@@ -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.
|
||||
# #############################################################################
|
||||
|
Reference in New Issue
Block a user