pt-stalk deletes non-empty files
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Percona Toolkit moved to https://jira.percona.com/projects/PT |
Fix Released
|
Medium
|
Daniel Nichter |
Bug Description
Actually that's only half true. It's too aggressive about when it checks for empty files -- some important files that are slow to get their data are deleted, even though they would return data if the script waited longer:
$CMD_MYSQL $EXT_ARGV -e "$innostat" >> "$d/$p-
$CMD_MYSQL $EXT_ARGV -e "$mutex" >> "$d/$p-
open_tables >> "$d/$p-opentables2" &
kill $mysqladmin_pid
[ "$tail_
[ "$tcpdump_pid" ] && kill $tcpdump_pid
hostname > "$d/$p-hostname"
for file in "$d/$p-"*; do
if [ -z "$(grep -v '^TS ' --max-count 1 "$file")" ]; then
log "Removing empty file $file";
rm "$file"
fi
done
In particular I never get the mutex-status2 output, because it takes several seconds for the command to return any output. The for loop at the end happens before that, and deletes the file before it's written to, resulting in data loss.
I'm not sure the best solution to this; inserting a sleep before the file cleanup is pretty arbitrary. Maybe checking for no more child processes (with a timeout) would be a better approach. My bash-fu isn't quite good enough for this one I think. My work around is to simply comment out the file cleanup.
Related branches
- Daniel Nichter: Approve
-
Diff: 81 lines (+34/-3)4 files modifiedbin/pt-stalk (+10/-0)
lib/bash/collect.sh (+13/-1)
sandbox/jenkins-test (+9/-0)
t/pt-stalk/pt-stalk.t (+2/-2)
tags: | added: pt-stalk |
Changed in percona-toolkit: | |
importance: | Undecided → Medium |
Changed in percona-toolkit: | |
status: | Triaged → In Progress |
assignee: | nobody → Daniel Nichter (daniel-nichter) |
Changed in percona-toolkit: | |
status: | Fix Committed → Fix Released |
I don't think that's quite right; Even if the file is deleted, wouldn't it just be recreated if there was any output from the mutex command?
#!/bin/sh
rm yadda
touch yadda
(sleep 1; echo something >> yadda) &
rm yadda
if [ -f yadda ]; then
echo "file exists"
else
echo "file doesn't exist"
fi
sleep 1
cat yadda