mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-20 01:16:14 +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" &
|
(echo $ts; transactions) >>"$d/$p-transactions" &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "$ps_instrumentation_enabled" > /tmp/k1
|
||||||
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"
|
ps_locks_transactions "$d/$p-ps-locks-transactions"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
slave_status "$d/$p-slave-status" "${mysql_version}"
|
||||||
|
|
||||||
curr_time=$(date +'%s')
|
curr_time=$(date +'%s')
|
||||||
done
|
done
|
||||||
log "Loop end: $(date +'TS %s.%N %F %T')"
|
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() {
|
collect_mysql_variables() {
|
||||||
local outfile=$1
|
local outfile=$1
|
||||||
|
|
||||||
|
@@ -64,12 +64,15 @@ my %port_for = (
|
|||||||
cslave1 => 12348, # cluster -> slave
|
cslave1 => 12348, # cluster -> slave
|
||||||
host1 => 12345, # pt-upgrade
|
host1 => 12345, # pt-upgrade
|
||||||
host2 => 12348, # pt-upgrade
|
host2 => 12348, # pt-upgrade
|
||||||
|
chan_master1 => 2900,
|
||||||
|
chan_master2 => 2901,
|
||||||
|
chan_slave1 => 2902,
|
||||||
);
|
);
|
||||||
|
|
||||||
my %server_type = (
|
my %server_type = (
|
||||||
master => 1,
|
master => 1,
|
||||||
slave => 1,
|
slave => 1,
|
||||||
node => 1,
|
node => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
my $test_dbs = qr/^(?:mysql|information_schema|sakila|performance_schema|percona_test|sys)$/;
|
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 $first_node = $args{first_node} ? $port_for{$args{first_node}} : '';
|
||||||
my $out = `$env $trunk/sandbox/start-sandbox cluster $port $first_node`;
|
my $out = `$env $trunk/sandbox/start-sandbox cluster $port $first_node`;
|
||||||
die $out if $CHILD_ERROR;
|
die $out if $CHILD_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $dbh = $self->get_dbh_for($server, $args{cxn_opts});
|
my $dbh = $self->get_dbh_for($server, $args{cxn_opts});
|
||||||
my $dsn = $self->dsn_for($server);
|
my $dsn = $self->dsn_for($server);
|
||||||
|
@@ -252,6 +252,8 @@ collect() {
|
|||||||
ps_locks_transactions "$d/$p-ps-locks-transactions"
|
ps_locks_transactions "$d/$p-ps-locks-transactions"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
slave_status "$d/$p-slave-status" "${mysql_version}"
|
||||||
|
|
||||||
curr_time=$(date +'%s')
|
curr_time=$(date +'%s')
|
||||||
done
|
done
|
||||||
log "Loop end: $(date +'TS %s.%N %F %T')"
|
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() {
|
collect_mysql_variables() {
|
||||||
local outfile=$1
|
local outfile=$1
|
||||||
|
|
||||||
@@ -446,6 +472,7 @@ collect_mysql_variables() {
|
|||||||
sql="select * from performance_schema.status_by_thread order by thread_id, variable_name; "
|
sql="select * from performance_schema.status_by_thread order by thread_id, variable_name; "
|
||||||
echo -e "\n$sql\n" >> $outfile
|
echo -e "\n$sql\n" >> $outfile
|
||||||
$CMD_MYSQL $EXT_ARGV -e "$sql" >> $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
|
port=$2 # sandbox port number, e.g. 12345
|
||||||
master_port=$3 # master port if slave or master-master
|
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."
|
die "Invalid sandbox type: $type. Valid types are master, slave, and master-master."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@@ -293,10 +293,23 @@ case $opt in
|
|||||||
exit_status=$((exit_status | $?))
|
exit_status=$((exit_status | $?))
|
||||||
set_mysql_version
|
set_mysql_version
|
||||||
if [ $exit_status -eq 0 ]; then
|
if [ $exit_status -eq 0 ]; then
|
||||||
./start-sandbox "${2:-"slave"}" 12346 12345
|
if [ "${2:-""}" = "channels" ] && [ "$MYSQL_VERSION" '>' "5.6" ]; then
|
||||||
exit_status=$((exit_status | $?))
|
./start-sandbox master 12346
|
||||||
./start-sandbox "${2:-"slave"}" 12347 12346
|
exit_status=$((exit_status | $?))
|
||||||
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
|
if [ "${2:-""}" = "cluster" ]; then
|
||||||
# Bit of magic here. 'start-sandbox cluster new_node old_node'
|
# Bit of magic here. 'start-sandbox cluster new_node old_node'
|
||||||
|
@@ -453,6 +453,7 @@ SKIP: {
|
|||||||
PerconaTest::kill_program(pid_file => $pid_file);
|
PerconaTest::kill_program(pid_file => $pid_file);
|
||||||
|
|
||||||
$output = `cat $dest/*-ps-locks-transactions 2>/dev/null`;
|
$output = `cat $dest/*-ps-locks-transactions 2>/dev/null`;
|
||||||
|
|
||||||
like(
|
like(
|
||||||
$output,
|
$output,
|
||||||
qr/ STATE: ACTIVE/,
|
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.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
Reference in New Issue
Block a user