Merge lp:~percona-toolkit-dev/percona-toolkit/disable-pt-mysql-summary-schema-dump-prompt-bug-1214685 into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.6

Proposed by Daniel Nichter
Status: Merged
Approved by: Daniel Nichter
Approved revision: 606
Merged at revision: 602
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/disable-pt-mysql-summary-schema-dump-prompt-bug-1214685
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.6
Diff against target: 275 lines (+47/-97)
7 files modified
bin/pt-mysql-summary (+24/-50)
lib/bash/collect_mysql_info.sh (+6/-5)
lib/bash/report_mysql_info.sh (+12/-38)
t/lib/bash/report_mysql_info.sh (+1/-0)
t/pt-mysql-summary/pt-mysql-summary.t (+2/-2)
t/pt-mysql-summary/samples/expected_output_temp003.txt (+1/-1)
t/pt-mysql-summary/samples/expected_output_temp004.txt (+1/-1)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/disable-pt-mysql-summary-schema-dump-prompt-bug-1214685
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+198661@code.launchpad.net
To post a comment you must log in.
603. By Daniel Nichter

Remove blank lines around Schema section contents.

604. By Daniel Nichter

Add back blank lines around Schema section contents. Use default vals for OPT_DATABASE, OPT_ALL_DATABASES, and OPT_READ_SAMPLE in report_mysql_info.sh to avoid errors in unit tests.

605. By Daniel Nichter

Merge

606. By Daniel Nichter

Fix tests.

Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-mysql-summary'
2--- bin/pt-mysql-summary 2013-10-20 03:45:04 +0000
3+++ bin/pt-mysql-summary 2013-12-12 05:50:47 +0000
4@@ -963,7 +963,7 @@
5 $CMD_MYSQLDUMP $EXT_ARGV --no-data --skip-comments \
6 --skip-add-locks --skip-add-drop-table --compact \
7 --skip-lock-all-tables --skip-lock-tables --skip-set-charset \
8- ${args} --databases $( local IFS=,; echo ${dbtodump})
9+ ${args} --databases $(local IFS=,; echo ${dbtodump})
10 }
11
12 get_mysqldump_args () {
13@@ -1036,9 +1036,10 @@
14 echo "pt-summary-internal-Config_File_path $cnf_file" >> "$dir/mysql-variables"
15 collect_internal_vars "$dir/mysqld-executables" >> "$dir/mysql-variables"
16
17- if [ -n "${OPT_DATABASES}" ]; then
18- local trg_arg="$( get_mysqldump_args "$dir/mysql-variables" )"
19- get_mysqldump_for "${trg_arg}" "${OPT_DATABASES}" > "$dir/mysqldump"
20+ if [ "$OPT_DATABASES" -o "$OPT_ALL_DATABASES" ]; then
21+ local trg_arg="$(get_mysqldump_args "$dir/mysql-variables")"
22+ local dbs="${OPT_DATABASES:-""}"
23+ get_mysqldump_for "${trg_arg}" "$dbs" > "$dir/mysqldump"
24 fi
25
26 (
27@@ -2243,37 +2244,16 @@
28 fi
29
30 section "Schema"
31- local reply="n"
32- if [ "${OPT_DATABASES}" ] || [ "${OPT_READ_SAMPLES}" ] \
33- || [ -e "$dir/mysqldump" -a -s "$dir/mysqldump" ]; then
34- reply="y"
35- elif [ -t 0 -a -t 1 ]; then
36- echo -n "Would you like to mysqldump -d the schema and analyze it? y/n "
37- read reply
38- reply=${reply:-n}
39- fi
40- if echo "${reply:-n}" | grep -i '^y' > /dev/null ; then
41- if [ -z "${OPT_DATABASES}" ] && [ -z "$OPT_READ_SAMPLES" ] \
42- && [ ! -e "$dir/mysqldump" ]; then
43- echo "There are ${num_dbs} databases. Would you like to dump all, or just one?"
44- echo -n "Type the name of the database, or press Enter to dump all of them. "
45- local dbtodump=""
46- read dbtodump
47- local trg_arg="$( get_mysqldump_args "$dir/mysql-variables" )"
48- get_mysqldump_for "${trg_arg}" "${dbtodump}" > "$dir/mysqldump"
49- fi
50-
51- if [ -e "$dir/mysqldump" -a -s "$dir/mysqldump" ] \
52- && grep 'CREATE TABLE' "$dir/mysqldump" >/dev/null 2>&1; then
53- format_overall_db_stats "$dir/mysqldump"
54- elif [ ! -e "$dir/mysqldump" -a "$OPT_READ_SAMPLES" ]; then
55- echo "Skipping schema analysis as the directory passed in" \
56- "doesn't have a dump file"
57- else
58- echo "Skipping schema analysis due to apparent error in dump file"
59- fi
60+ if [ -s "$dir/mysqldump" ] \
61+ && grep 'CREATE TABLE' "$dir/mysqldump" >/dev/null 2>&1; then
62+ format_overall_db_stats "$dir/mysqldump"
63+ elif [ ! -e "$dir/mysqldump" -a "$OPT_READ_SAMPLES" ]; then
64+ echo "Skipping schema analysis because --read-samples $dir/mysqldump " \
65+ "does not exist"
66+ elif [ -z "$OPT_DATABASES" -a -z "$OPT_ALL_DATABASES" ]; then
67+ echo "Specify --databases or --all-databases to dump and summarize schemas"
68 else
69- echo "Skipping schema analysis"
70+ echo "Skipping schema analysis due to apparent error in dump file"
71 fi
72
73 section "Noteworthy Technologies"
74@@ -2731,9 +2711,6 @@
75 are fuzzy-rounded.
76
77 # Schema #####################################################
78- Would you like to mysqldump -d the schema and analyze it? y/n y
79- There are 4 databases. Would you like to dump all, or just one?
80- Type the name of the database, or press Enter to dump all of them.
81
82 Database Tables Views SPs Trigs Funcs FKs Partn
83 mysql 24
84@@ -2765,16 +2742,10 @@
85 performance_schema 5 16 33
86 sakila 1 15 1 3 4 3 19 42 26
87
88-If you select to dump the schema and analyze it, the tool will print the above
89-section. This summarizes the number and type of objects in the database. It is
90-generated by running C<mysqldump --no-data>, not by querying the
91-INFORMATION_SCHEMA, which can freeze a busy server. You can use the
92-L<"--databases"> option to specify which databases to examine. If you do not,
93-and you run the tool interactively, it will prompt you as shown.
94-
95-You can choose not to dump the schema, to dump all of the databases, or to dump
96-only a single named one, by specifying the appropriate options. In the example
97-above, we are dumping all databases.
98+If you specify L<"--databases"> or L<"--all-databases">, the tool will print
99+the above section. This summarizes the number and type of objects in the
100+databases. It is generated by running C<mysqldump --no-data>, not by querying
101+the INFORMATION_SCHEMA, which can freeze a busy server.
102
103 The first sub-report in the section is the count of objects by type in each
104 database: tables, views, and so on. The second one shows how many tables use
105@@ -2949,6 +2920,10 @@
106
107 =over
108
109+=item --all-databases
110+
111+mysqldump and summarize all databases. See L<"--databases">.
112+
113 =item --config
114
115 type: string
116@@ -2960,9 +2935,8 @@
117
118 type: string
119
120-Names of databases to summarize. If you want all of them, you can use the value
121-C<--all-databases>; you can also pass in a comma-separated list of database
122-names. If not provided, the program will ask you for manual input.
123+mysqldump and summarize this comma-separated list of databases. Specify
124+L<"--all-databases"> instead if you want to dump and summary all databases.
125
126 =item --defaults-file
127
128
129=== modified file 'lib/bash/collect_mysql_info.sh'
130--- lib/bash/collect_mysql_info.sh 2013-02-25 14:21:46 +0000
131+++ lib/bash/collect_mysql_info.sh 2013-12-12 05:50:47 +0000
132@@ -168,7 +168,7 @@
133 $CMD_MYSQLDUMP $EXT_ARGV --no-data --skip-comments \
134 --skip-add-locks --skip-add-drop-table --compact \
135 --skip-lock-all-tables --skip-lock-tables --skip-set-charset \
136- ${args} --databases $( local IFS=,; echo ${dbtodump})
137+ ${args} --databases $(local IFS=,; echo ${dbtodump})
138 }
139
140 # Returns a string with arguments to pass to mysqldump.
141@@ -250,10 +250,11 @@
142 echo "pt-summary-internal-Config_File_path $cnf_file" >> "$dir/mysql-variables"
143 collect_internal_vars "$dir/mysqld-executables" >> "$dir/mysql-variables"
144
145- if [ -n "${OPT_DATABASES}" ]; then
146- # "--dump-schemas passed in, dumping early"
147- local trg_arg="$( get_mysqldump_args "$dir/mysql-variables" )"
148- get_mysqldump_for "${trg_arg}" "${OPT_DATABASES}" > "$dir/mysqldump"
149+ # mysqldump schemas
150+ if [ "$OPT_DATABASES" -o "$OPT_ALL_DATABASES" ]; then
151+ local trg_arg="$(get_mysqldump_args "$dir/mysql-variables")"
152+ local dbs="${OPT_DATABASES:-""}"
153+ get_mysqldump_for "${trg_arg}" "$dbs" > "$dir/mysqldump"
154 fi
155
156 # TODO: gather this data in the same format as normal: TS line, stats
157
158=== modified file 'lib/bash/report_mysql_info.sh'
159--- lib/bash/report_mysql_info.sh 2013-02-25 14:21:46 +0000
160+++ lib/bash/report_mysql_info.sh 2013-12-12 05:50:47 +0000
161@@ -1318,45 +1318,19 @@
162 # Schema, databases, data type, other analysis.
163 # ########################################################################
164 section "Schema"
165- # Assume "no" if stdin or stdout is not a terminal, so this can be run and
166- # put into a file, or piped into a pager, or something else like that.
167- local reply="n"
168- # But dump no matter what if they passed in something through --databases,
169- # OR if --read-samples was set
170- if [ "${OPT_DATABASES}" ] || [ "${OPT_READ_SAMPLES}" ] \
171- || [ -e "$dir/mysqldump" -a -s "$dir/mysqldump" ]; then
172- reply="y"
173- elif [ -t 0 -a -t 1 ]; then
174- echo -n "Would you like to mysqldump -d the schema and analyze it? y/n "
175- read reply
176- reply=${reply:-n}
177- fi
178- if echo "${reply:-n}" | grep -i '^y' > /dev/null ; then
179- if [ -z "${OPT_DATABASES}" ] && [ -z "$OPT_READ_SAMPLES" ] \
180- && [ ! -e "$dir/mysqldump" ]; then
181- # If --dump-schemas wasn't used, ask what they want to dump
182- echo "There are ${num_dbs} databases. Would you like to dump all, or just one?"
183- echo -n "Type the name of the database, or press Enter to dump all of them. "
184- local dbtodump=""
185- read dbtodump
186- local trg_arg="$( get_mysqldump_args "$dir/mysql-variables" )"
187- get_mysqldump_for "${trg_arg}" "${dbtodump}" > "$dir/mysqldump"
188- fi
189-
190- # Test the result by checking the file, not by the exit status, because we
191- # might get partway through and then die, and the info is worth analyzing
192- # anyway.
193- if [ -e "$dir/mysqldump" -a -s "$dir/mysqldump" ] \
194- && grep 'CREATE TABLE' "$dir/mysqldump" >/dev/null 2>&1; then
195- format_overall_db_stats "$dir/mysqldump"
196- elif [ ! -e "$dir/mysqldump" -a "$OPT_READ_SAMPLES" ]; then
197- echo "Skipping schema analysis as the directory passed in" \
198- "doesn't have a dump file"
199- else
200- echo "Skipping schema analysis due to apparent error in dump file"
201- fi
202+ # Test the result by checking the file, not by the exit status, because we
203+ # might get partway through and then die, and the info is worth analyzing
204+ # anyway.
205+ if [ -s "$dir/mysqldump" ] \
206+ && grep 'CREATE TABLE' "$dir/mysqldump" >/dev/null 2>&1; then
207+ format_overall_db_stats "$dir/mysqldump"
208+ elif [ ! -e "$dir/mysqldump" -a "$OPT_READ_SAMPLES" ]; then
209+ echo "Skipping schema analysis because --read-samples $dir/mysqldump " \
210+ "does not exist"
211+ elif [ -z "$OPT_DATABASES" -a -z "$OPT_ALL_DATABASES" ]; then
212+ echo "Specify --databases or --all-databases to dump and summarize schemas"
213 else
214- echo "Skipping schema analysis"
215+ echo "Skipping schema analysis due to apparent error in dump file"
216 fi
217
218 # ########################################################################
219
220=== modified file 't/lib/bash/report_mysql_info.sh'
221--- t/lib/bash/report_mysql_info.sh 2012-12-06 00:10:22 +0000
222+++ t/lib/bash/report_mysql_info.sh 2013-12-12 05:50:47 +0000
223@@ -715,6 +715,7 @@
224 OPT_SLEEP=1
225 OPT_DATABASES=""
226 OPT_READ_SAMPLES=""
227+OPT_ALL_DATABASES=""
228 NAME_VAL_LEN=25
229 report_mysql_summary "$samples/tempdir" | tail -n+3 > "$PT_TMPDIR/got"
230 no_diff "$PT_TMPDIR/got" "$samples/expected_result_report_summary.txt"
231
232=== modified file 't/pt-mysql-summary/pt-mysql-summary.t'
233--- t/pt-mysql-summary/pt-mysql-summary.t 2012-12-07 18:52:33 +0000
234+++ t/pt-mysql-summary/pt-mysql-summary.t 2013-12-12 05:50:47 +0000
235@@ -66,12 +66,12 @@
236 no_diff(
237 sub {
238 local $ENV{_NO_FALSE_NEGATIVES} = 1;
239- print `$env $trunk/bin/$tool --read-samples $trunk/t/pt-mysql-summary/samples/temp00$i -- --defaults-file=/tmp/12345/my.sandbox.cnf | tail -n+3 | perl -wlnpe 's/Skipping schema analysis.*/Skipping schema analysis/'`
240+ print `$env $trunk/bin/$tool --read-samples $trunk/t/pt-mysql-summary/samples/temp00$i -- --defaults-file=/tmp/12345/my.sandbox.cnf | tail -n+3 | perl -wlnpe 's/Skipping schema analysis.*/Specify --databases or --all-databases to dump and summarize schemas/'`
241 },
242 "t/pt-mysql-summary/samples/expected_output_temp00$i.txt",
243 ),
244 "--read-samples works for t/pt-mysql-summary/temp00$i",
245- );
246+ ) or diag($test_diff);
247 }
248
249 # Test that --help works under sh
250
251=== modified file 't/pt-mysql-summary/samples/expected_output_temp003.txt'
252--- t/pt-mysql-summary/samples/expected_output_temp003.txt 2012-11-27 22:05:45 +0000
253+++ t/pt-mysql-summary/samples/expected_output_temp003.txt 2013-12-12 05:50:47 +0000
254@@ -108,7 +108,7 @@
255 Usage | 0%
256 HitToInsertRatio | 0%
257 # Schema #####################################################
258-Skipping schema analysis
259+Specify --databases or --all-databases to dump and summarize schemas
260 # Noteworthy Technologies ####################################
261 SSL | No
262 Explicit LOCK TABLES | No
263
264=== modified file 't/pt-mysql-summary/samples/expected_output_temp004.txt'
265--- t/pt-mysql-summary/samples/expected_output_temp004.txt 2012-11-27 22:05:45 +0000
266+++ t/pt-mysql-summary/samples/expected_output_temp004.txt 2013-12-12 05:50:47 +0000
267@@ -107,7 +107,7 @@
268 Usage | 0%
269 HitToInsertRatio | 0%
270 # Schema #####################################################
271-Skipping schema analysis
272+Specify --databases or --all-databases to dump and summarize schemas
273 # Noteworthy Technologies ####################################
274 SSL | No
275 Explicit LOCK TABLES | No

Subscribers

People subscribed via source and target branches

to all changes: