PS-2033, proof of concept (#540)

This commit is contained in:
Sveta Smirnova
2022-07-11 15:51:29 +03:00
committed by GitHub
parent d881738e2f
commit 07ee5eb1bf
2 changed files with 102 additions and 70 deletions

View File

@@ -979,7 +979,7 @@ collect_mysql_data_loop() {
(echo $ts; $CMD_MYSQL $EXT_ARGV -e "SHOW FULL PROCESSLIST\G") \
>> "$d/$p-processlist" &
if [ "$have_lock_waits_table" ]; then
(echo $ts; lock_waits) >>"$d/$p-lock-waits" &
(echo $ts; lock_waits "$d/lock_waits.running") >>"$d/$p-lock-waits" &
(echo $ts; transactions) >>"$d/$p-transactions" &
fi
@@ -988,7 +988,7 @@ collect_mysql_data_loop() {
fi
if [ "${mysql_version}" '>' "5.6" ]; then
(echo $ts; ps_prepared_statements) >> "$d/$p-prepared-statements" &
(echo $ts; ps_prepared_statements "$d/prepared_statements.isrunnning") >> "$d/$p-prepared-statements" &
fi
slave_status "$d/$p-slave-status" "${mysql_version}"
@@ -1089,6 +1089,11 @@ open_tables() {
}
lock_waits() {
local flag_file=$1
if test -f "$flag_file"; then
echo "Lock collection already running, skipping this iteration"
else
touch "$flag_file"
local sql1="SELECT SQL_NO_CACHE
CONCAT('thread ', b.trx_mysql_thread_id, ' from ', p.host) AS who_blocks,
IF(p.command = \"Sleep\", p.time, 0) AS idle_in_trx,
@@ -1119,6 +1124,8 @@ lock_waits() {
LEFT JOIN INFORMATION_SCHEMA.PROCESSLIST AS p ON p.id = b.trx_mysql_thread_id
ORDER BY wait_time DESC\G"
$CMD_MYSQL $EXT_ARGV -e "$sql2"
rm "$flag_file"
fi
}
transactions() {
@@ -1200,10 +1207,17 @@ ps_locks_transactions() {
}
ps_prepared_statements() {
local flag_file=$1
if test -f "$flag_file"; then
echo "Prepared statements collection already running, skipping this iteration"
else
touch "$flag_file"
$CMD_MYSQL $EXT_ARGV -e "SELECT t.processlist_id, pse.* \
FROM performance_schema.prepared_statements_instances pse \
JOIN performance_schema.threads t \
ON (pse.OWNER_THREAD_ID=t.thread_id)\G"
rm "$flag_file"
fi
}
slave_status() {

View File

@@ -266,7 +266,7 @@ collect_mysql_data_loop() {
(echo $ts; $CMD_MYSQL $EXT_ARGV -e "SHOW FULL PROCESSLIST\G") \
>> "$d/$p-processlist" &
if [ "$have_lock_waits_table" ]; then
(echo $ts; lock_waits) >>"$d/$p-lock-waits" &
(echo $ts; lock_waits "$d/lock_waits.running") >>"$d/$p-lock-waits" &
(echo $ts; transactions) >>"$d/$p-transactions" &
fi
@@ -275,7 +275,7 @@ collect_mysql_data_loop() {
fi
if [ "${mysql_version}" '>' "5.6" ]; then
(echo $ts; ps_prepared_statements) >> "$d/$p-prepared-statements" &
(echo $ts; ps_prepared_statements "$d/prepared_statements.isrunnning") >> "$d/$p-prepared-statements" &
fi
slave_status "$d/$p-slave-status" "${mysql_version}"
@@ -387,6 +387,11 @@ open_tables() {
}
lock_waits() {
local flag_file=$1
if test -f "$flag_file"; then
echo "Lock collection already running, skipping this iteration"
else
touch "$flag_file"
local sql1="SELECT SQL_NO_CACHE
CONCAT('thread ', b.trx_mysql_thread_id, ' from ', p.host) AS who_blocks,
IF(p.command = \"Sleep\", p.time, 0) AS idle_in_trx,
@@ -417,6 +422,8 @@ lock_waits() {
LEFT JOIN INFORMATION_SCHEMA.PROCESSLIST AS p ON p.id = b.trx_mysql_thread_id
ORDER BY wait_time DESC\G"
$CMD_MYSQL $EXT_ARGV -e "$sql2"
rm "$flag_file"
fi
}
transactions() {
@@ -498,10 +505,21 @@ ps_locks_transactions() {
}
ps_prepared_statements() {
# PS-2033:
# If no flag file exists, create it, then collect data
# After data collected, remove the file
# If flag file exists, skip current iteration
local flag_file=$1
if test -f "$flag_file"; then
echo "Prepared statements collection already running, skipping this iteration"
else
touch "$flag_file"
$CMD_MYSQL $EXT_ARGV -e "SELECT t.processlist_id, pse.* \
FROM performance_schema.prepared_statements_instances pse \
JOIN performance_schema.threads t \
ON (pse.OWNER_THREAD_ID=t.thread_id)\G"
rm "$flag_file"
fi
}
slave_status() {