diff --git a/bin/pt-stalk b/bin/pt-stalk index b0a699c4..10f8f9d3 100755 --- a/bin/pt-stalk +++ b/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 diff --git a/lib/Sandbox.pm b/lib/Sandbox.pm index 8178a585..10beafc0 100644 --- a/lib/Sandbox.pm +++ b/lib/Sandbox.pm @@ -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); diff --git a/lib/bash/collect.sh b/lib/bash/collect.sh index 5d0666af..71127905 100644 --- a/lib/bash/collect.sh +++ b/lib/bash/collect.sh @@ -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 + } # ########################################################################### diff --git a/sandbox/gtid_on.sql b/sandbox/gtid_on.sql new file mode 100644 index 00000000..1de63bc2 --- /dev/null +++ b/sandbox/gtid_on.sql @@ -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; + diff --git a/sandbox/slave_channels.sql b/sandbox/slave_channels.sql new file mode 100644 index 00000000..e65494a9 --- /dev/null +++ b/sandbox/slave_channels.sql @@ -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'; + diff --git a/sandbox/start-sandbox b/sandbox/start-sandbox index 0a69b00c..393c4cc0 100755 --- a/sandbox/start-sandbox +++ b/sandbox/start-sandbox @@ -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 diff --git a/sandbox/test-env b/sandbox/test-env index 22e6f119..1ee1efff 100755 --- a/sandbox/test-env +++ b/sandbox/test-env @@ -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' diff --git a/t/pt-stalk/pt-stalk.t b/t/pt-stalk/pt-stalk.t index 32d6c203..846f5385 100644 --- a/t/pt-stalk/pt-stalk.t +++ b/t/pt-stalk/pt-stalk.t @@ -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. # #############################################################################