PT-81 Collect information about locks and transactions using P_S

This commit is contained in:
Carlos Salguero
2017-03-21 13:45:59 -03:00
parent b6bcf888e6
commit 4a056cf3b0
5 changed files with 95 additions and 2 deletions

View File

@@ -832,7 +832,6 @@ collect() {
log "Could not find the MySQL error log"
fi
ps_locks_transactions "$d/$p-ps-locks-transactions"
if [ "${mysql_version}" '>' "5.1" ]; then
local mutex="SHOW ENGINE INNODB MUTEX"
@@ -906,6 +905,12 @@ 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/')
if [ $ps_instrumentation_enabled != "yes" ]; then
log "Performance Schema instrumentation is disabled"
fi
while [ $((curr_time - start_time)) -lt $OPT_RUN_TIME ]; do
disk_space $d > $d/$p-disk-space
@@ -948,6 +953,10 @@ collect() {
(echo $ts; transactions) >>"$d/$p-transactions" &
fi
if [ $ps_instrumentation_enabled == "yes" ]; then
ps_locks_transactions "$d/$p-ps-locks-transactions"
fi
curr_time=$(date +'%s')
done
log "Loop end: $(date +'TS %s.%N %F %T')"

View File

@@ -102,7 +102,6 @@ collect() {
log "Could not find the MySQL error log"
fi
ps_locks_transactions "$d/$p-ps-locks-transactions"
# Get a sample of these right away, so we can get these without interaction
# with the other commands we're about to run.
@@ -193,6 +192,12 @@ 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/')
if [ $ps_instrumentation_enabled != "yes" ]; then
log "Performance Schema instrumentation is disabled"
fi
while [ $((curr_time - start_time)) -lt $OPT_RUN_TIME ]; do
# We check the disk, but don't exit, because we need to stop jobs if we
@@ -242,6 +247,10 @@ collect() {
(echo $ts; transactions) >>"$d/$p-transactions" &
fi
if [ $ps_instrumentation_enabled == "yes" ]; then
ps_locks_transactions "$d/$p-ps-locks-transactions"
fi
curr_time=$(date +'%s')
done
log "Loop end: $(date +'TS %s.%N %F %T')"

View File

@@ -30,3 +30,6 @@ lower_case_table_names = 0
# fkc test
binlog_format = STATEMENT
performance_schema = ON
performance-schema-instrument='wait/lock/metadata/sql/mdl=ON'
performance-schema-instrument='transaction=ON'

View File

@@ -8,6 +8,7 @@ BEGIN {
use strict;
use warnings FATAL => 'all';
use threads;
use English qw(-no_match_vars);
use Test::More;
use Time::HiRes qw(sleep);
@@ -421,7 +422,49 @@ like(
qr/matched=yes/,
"Accepts floating point values as treshold variable"
);
# ###########################################################################
# Test report about performance schema transactions in MySQL 5.7+
# ###########################################################################
cleanup();
SKIP: {
skip "Only test on mysql 5.7" if ( $sandbox_version lt '5.7' );
sub start_thread {
# this must run in a thread because we need to have an uncommitted transaction
my ($dsn_opts) = @_;
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $dbh = $sb->get_dbh_for('master');
$sb->load_file('master', "t/pt-stalk/samples/issue-1642751.sql");
}
my $thr = threads->create('start_thread', $dsn_opts);
$thr->detach();
threads->yield();
my $cmd = "$trunk/bin/pt-stalk --no-stalk --iterations=1 --host=127.0.0.1 --port=12345 --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 15;
PerconaTest::kill_program(pid_file => $pid_file);
$output = `cat $dest/*-ps-locks-transactions 2>/dev/null`;
like(
$output,
qr/ STATE: ACTIVE/,
"MySQL 5.7 ACTIVE transactions"
);
like(
$output,
qr/ STATE: COMMITTED/,
"MySQL 5.7 COMMITTED transactions"
);
}
# #############################################################################
# Done.

View File

@@ -0,0 +1,29 @@
/* This enables perfomance schema without a server restart */
UPDATE performance_schema.setup_consumers SET enabled='YES' WHERE NAME = 'events_waits_current';
/* Enable instrumentation */
UPDATE performance_schema.setup_consumers SET ENABLED='YES' WHERE NAME LIKE '%events_transactions%';
UPDATE performance_schema.setup_consumers SET ENABLED='YES' WHERE NAME LIKE '%events_transactions%';
UPDATE performance_schema.setup_instruments SET ENABLED='YES' WHERE NAME = 'wait/lock/metadata/sql/mdl';
CREATE SCHEMA IF NOT EXISTS test;
USE test;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (id int) ENGINE=INNODB;
/* Successfuly finished transaction */
SET autocommit=0;
START TRANSACTION;
INSERT INTO t1 VALUES (CEIL(RAND()*10000));
COMMIT;
/* Ongoing transaction */
SET autocommit=0;
START TRANSACTION;
INSERT INTO t1 VALUES (CEIL(RAND()*10000));
/* Wait to let pt-stalk to collect the data and find an ACTIVE transaction */
SELECT SLEEP(11);
COMMIT;
DROP DATABASE IF EXISTS test;