mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-18 01:12:05 +08:00
Merge find_my_cnf_file-bug-1070916.
This commit is contained in:
@@ -793,22 +793,21 @@ find_my_cnf_file() {
|
||||
local port="${2:-""}"
|
||||
|
||||
local cnf_file=""
|
||||
if test -n "$port" && grep -- "/mysqld.*--port=$port" "${file}" >/dev/null 2>&1 ; then
|
||||
cnf_file="$(grep -- "/mysqld.*--port=$port" "${file}" \
|
||||
| awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \
|
||||
| head -n1)"
|
||||
|
||||
if [ "$port" ]; then
|
||||
cnf_file="$(grep --max-count 1 "/mysqld.*--port=$port" "$file" \
|
||||
| awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }')"
|
||||
else
|
||||
cnf_file="$(grep '/mysqld' "${file}" \
|
||||
| awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \
|
||||
| head -n1)"
|
||||
cnf_file="$(grep --max-count 1 '/mysqld' "$file" \
|
||||
| awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }')"
|
||||
fi
|
||||
|
||||
if [ ! -n "${cnf_file}" ]; then
|
||||
cnf_file="/etc/my.cnf";
|
||||
if [ ! -e "${cnf_file}" ]; then
|
||||
cnf_file="/etc/mysql/my.cnf";
|
||||
fi
|
||||
if [ ! -e "${cnf_file}" ]; then
|
||||
if [ -z "$cnf_file" ]; then
|
||||
if [ -e "/etc/my.cnf" ]; then
|
||||
cnf_file="/etc/my.cnf"
|
||||
elif [ -e "/etc/mysql/my.cnf" ]; then
|
||||
cnf_file="/etc/mysql/my.cnf"
|
||||
elif [ -e "/var/db/mysql/my.cnf" ]; then
|
||||
cnf_file="/var/db/mysql/my.cnf";
|
||||
fi
|
||||
fi
|
||||
@@ -954,7 +953,7 @@ collect_mysql_info () {
|
||||
local port="$(get_var port "$dir/mysql-variables")"
|
||||
local cnf_file="$(find_my_cnf_file "$dir/mysqld-instances" ${port})"
|
||||
|
||||
cat "$cnf_file" > "$dir/mysql-config-file"
|
||||
[ -e "$cnf_file" ] && cat "$cnf_file" > "$dir/mysql-config-file"
|
||||
|
||||
local pid_file="$(get_var "pid_file" "$dir/mysql-variables")"
|
||||
local pid_file_exists=""
|
||||
|
||||
@@ -60,23 +60,24 @@ find_my_cnf_file() {
|
||||
local port="${2:-""}"
|
||||
|
||||
local cnf_file=""
|
||||
if test -n "$port" && grep -- "/mysqld.*--port=$port" "${file}" >/dev/null 2>&1 ; then
|
||||
cnf_file="$(grep -- "/mysqld.*--port=$port" "${file}" \
|
||||
| awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \
|
||||
| head -n1)"
|
||||
|
||||
if [ "$port" ]; then
|
||||
# Find the cnf file for the specific port.
|
||||
cnf_file="$(grep --max-count 1 "/mysqld.*--port=$port" "$file" \
|
||||
| awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }')"
|
||||
else
|
||||
cnf_file="$(grep '/mysqld' "${file}" \
|
||||
| awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }' \
|
||||
| head -n1)"
|
||||
# Find the cnf file for the first mysqld instance.
|
||||
cnf_file="$(grep --max-count 1 '/mysqld' "$file" \
|
||||
| awk 'BEGIN{RS=" "; FS="=";} $1 ~ /--defaults-file/ { print $2; }')"
|
||||
fi
|
||||
|
||||
if [ ! -n "${cnf_file}" ]; then
|
||||
# "Cannot autodetect config file, trying common locations"
|
||||
cnf_file="/etc/my.cnf";
|
||||
if [ ! -e "${cnf_file}" ]; then
|
||||
cnf_file="/etc/mysql/my.cnf";
|
||||
fi
|
||||
if [ ! -e "${cnf_file}" ]; then
|
||||
if [ -z "$cnf_file" ]; then
|
||||
# Cannot autodetect config file, try common locations.
|
||||
if [ -e "/etc/my.cnf" ]; then
|
||||
cnf_file="/etc/my.cnf"
|
||||
elif [ -e "/etc/mysql/my.cnf" ]; then
|
||||
cnf_file="/etc/mysql/my.cnf"
|
||||
elif [ -e "/var/db/mysql/my.cnf" ]; then
|
||||
cnf_file="/var/db/mysql/my.cnf";
|
||||
fi
|
||||
fi
|
||||
@@ -233,7 +234,7 @@ collect_mysql_info () {
|
||||
local port="$(get_var port "$dir/mysql-variables")"
|
||||
local cnf_file="$(find_my_cnf_file "$dir/mysqld-instances" ${port})"
|
||||
|
||||
cat "$cnf_file" > "$dir/mysql-config-file"
|
||||
[ -e "$cnf_file" ] && cat "$cnf_file" > "$dir/mysql-config-file"
|
||||
|
||||
local pid_file="$(get_var "pid_file" "$dir/mysql-variables")"
|
||||
local pid_file_exists=""
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plan 20
|
||||
plan 24
|
||||
|
||||
PT_TMPDIR="$TEST_PT_TMPDIR"
|
||||
PATH="$PATH:$PERCONA_TOOLKIT_SANDBOX/bin"
|
||||
@@ -18,6 +18,19 @@ samples="$PERCONA_TOOLKIT_BRANCH/t/pt-mysql-summary/samples"
|
||||
|
||||
mkdir "$p"
|
||||
|
||||
# This is mostly for the find_my_cnf_file tests.
|
||||
# Test machines may have one of these, and find_my_cnf_file will use
|
||||
# the same if the specific port-based cnf file isn't found.
|
||||
if [ -e "/etc/my.cnf" ]; then
|
||||
sys_cnf_file="/etc/my.cnf"
|
||||
elif [ -e "/etc/mysql/my.cnf" ]; then
|
||||
sys_cnf_file="/etc/mysql/my.cnf"
|
||||
elif [ -e "/var/db/mysql/my.cnf" ]; then
|
||||
sys_cnf_file="/var/db/mysql/my.cnf";
|
||||
else
|
||||
sys_cnf_file=""
|
||||
fi
|
||||
|
||||
parse_options "$BIN_DIR/pt-mysql-summary" --sleep 1 -- --defaults-file=/tmp/12345/my.sandbox.cnf
|
||||
|
||||
CMD_MYSQL="$(_which mysql)"
|
||||
@@ -28,7 +41,13 @@ wait
|
||||
|
||||
file_count=$(ls "$p" | wc -l)
|
||||
|
||||
is $file_count 14 "Creates the correct number of files (without --databases)"
|
||||
if [ "$sys_cnf_file" ]; then
|
||||
n_files=14
|
||||
else
|
||||
n_files=13
|
||||
fi
|
||||
|
||||
is $file_count $n_files "Creates the correct number of files (without --databases)"
|
||||
|
||||
awk '{print $1}' "$p/mysqld-instances" > "$PT_TMPDIR/collect_mysqld_instances1.test"
|
||||
pids="$(_pidof mysqld)"
|
||||
@@ -79,26 +98,49 @@ is \
|
||||
"collect_internal_vars works"
|
||||
|
||||
# find_my_cnf_file
|
||||
|
||||
# We know the port is 12345 (2nd to last test), but the sandbox is started
|
||||
# with just --defaults-file, no --port, so find_my_cnf_file isn't going to
|
||||
# be able to get the specific cnf file.
|
||||
cnf_file=$(find_my_cnf_file "$p/mysqld-instances" ${port});
|
||||
|
||||
is \
|
||||
"$cnf_file" \
|
||||
"/tmp/12345/my.sandbox.cnf" \
|
||||
"find_my_cnf_file gets the correct file"
|
||||
is "$cnf_file" "$sys_cnf_file" "find_my_cnf_file gets the correct file"
|
||||
[ $? -ne 0 ] && diag "$p/mysqld-instances"
|
||||
|
||||
# ps-mysqld-001.txt has several instances:
|
||||
# port 3306 cnf -
|
||||
# port 12345 cnf /tmp/12345/my.sandbox.cnf
|
||||
# port 12346 cnf /tmp/12346/my.sandbox.cnf
|
||||
|
||||
res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt")
|
||||
is "$res" "/tmp/12345/my.sandbox.cnf" "ps-mysqld-001.txt"
|
||||
is "$res" "$sys_cnf_file" "ps-mysqld-001.txt no port"
|
||||
|
||||
res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 3306)
|
||||
is "$res" "$sys_cnf_file" "ps-mysqld-001.txt port but no cnf"
|
||||
|
||||
res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 999)
|
||||
is "$res" "$sys_cnf_file" "ps-mysqld-001.txt nonexistent port"
|
||||
|
||||
res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 12346)
|
||||
is "$res" "/tmp/12346/my.sandbox.cnf" "ps-mysqld-001.txt with port"
|
||||
is "$res" "/tmp/12346/my.sandbox.cnf" "ps-mysqld-001.txt port 12346"
|
||||
|
||||
res=$(find_my_cnf_file "$samples/ps-mysqld-001.txt" 12345)
|
||||
is "$res" "/tmp/12345/my.sandbox.cnf" "ps-mysqld-001.txt port 12345"
|
||||
|
||||
# ps-mysqld-004.txt has 1 instance without --port using
|
||||
# --defaults-file=/var/lib/mysql/my.cnf
|
||||
|
||||
res=$(find_my_cnf_file "$samples/ps-mysqld-004.txt")
|
||||
is "$res" "/var/lib/mysql/my.cnf" "ps-mysqld-004.txt"
|
||||
is "$res" "/var/lib/mysql/my.cnf" "ps-mysqld-004.txt no port"
|
||||
|
||||
res=$(find_my_cnf_file "$samples/ps-mysqld-004.txt" 12345)
|
||||
is "$res" "/var/lib/mysql/my.cnf" "ps-mysqld-004.txt with port"
|
||||
is "$res" "$sys_cnf_file" "ps-mysqld-004.txt port 12345"
|
||||
|
||||
# ps-mysqld-005.txt has the 3 sandbox instances, but 12347
|
||||
# is first, which was causing bug 1070916.
|
||||
|
||||
res=$(find_my_cnf_file "$samples/ps-mysqld-005.txt" 12345)
|
||||
is "$res" "$sys_cnf_file" "ps-mysqld-005.txt port 12345 (bug 1070916)"
|
||||
|
||||
# collect_mysql_databases
|
||||
$CMD_MYSQL $EXT_ARGV -ss -e 'SHOW DATABASES' > "$PT_TMPDIR/mysql_collect_databases" 2>/dev/null
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plan 32
|
||||
plan 33
|
||||
|
||||
. "$LIB_DIR/alt_cmds.sh"
|
||||
. "$LIB_DIR/log_warn_die.sh"
|
||||
|
||||
@@ -32,13 +32,14 @@ ok(
|
||||
"Using --save-samples doesn't mistakenly delete the target dir"
|
||||
);
|
||||
|
||||
# If the box has a default my.cnf (e.g. /etc/my.cnf) there
|
||||
# should be 15 files, else 14.
|
||||
my @files = glob("$dir/*");
|
||||
|
||||
is(
|
||||
scalar @files,
|
||||
15,
|
||||
my $n_files = scalar @files;
|
||||
ok(
|
||||
$n_files == 15 || $n_files == 14,
|
||||
"And leaves all files in there"
|
||||
);
|
||||
) or diag($n_files, `ls -l $dir`);
|
||||
|
||||
undef($dir);
|
||||
|
||||
|
||||
4
t/pt-mysql-summary/samples/ps-mysqld-005.txt
Normal file
4
t/pt-mysql-summary/samples/ps-mysqld-005.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
PID TTY STAT TIME COMMAND
|
||||
1427 ? Sl 0:13 /home/jenkins/mysql-bin/mysql-5.5.24-i386-barebones/bin/mysqld --defaults-file=/tmp/12347/my.sandbox.cnf
|
||||
20928 ? Sl 0:07 /home/jenkins/mysql-bin/mysql-5.5.24-i386-barebones/bin/mysqld --defaults-file=/tmp/12345/my.sandbox.cnf
|
||||
29930 ? Sl 0:00 /home/jenkins/mysql-bin/mysql-5.5.24-i386-barebones/bin/mysqld --defaults-file=/tmp/12346/my.sandbox.cnf
|
||||
Reference in New Issue
Block a user