Merge lp:~percona-toolkit-dev/percona-toolkit/fix-slowlog-ts-bug-1082599 into lp:percona-toolkit/2.1
- fix-slowlog-ts-bug-1082599
- Merge into 2.1
Proposed by
Daniel Nichter
Status: | Merged |
---|---|
Merged at revision: | 496 |
Proposed branch: | lp:~percona-toolkit-dev/percona-toolkit/fix-slowlog-ts-bug-1082599 |
Merge into: | lp:percona-toolkit/2.1 |
Diff against target: |
288 lines (+194/-19) 6 files modified
bin/pt-query-digest (+18/-7) lib/SlowLogParser.pm (+28/-7) t/lib/SlowLogParser.t (+55/-2) t/lib/samples/slowlogs/slow056.txt (+12/-0) t/pt-query-digest/samples/slow056.txt (+68/-0) t/pt-query-digest/slowlog_analyses.t (+13/-3) |
To merge this branch: | bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-slowlog-ts-bug-1082599 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Nichter | Approve | ||
Review via email: mp+139129@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
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-query-digest' | |||
2 | --- bin/pt-query-digest 2012-12-10 23:41:11 +0000 | |||
3 | +++ bin/pt-query-digest 2012-12-11 01:40:25 +0000 | |||
4 | @@ -4875,14 +4875,25 @@ | |||
5 | 4875 | 4875 | ||
6 | 4876 | if ( !$found_arg && $pos == $len ) { | 4876 | if ( !$found_arg && $pos == $len ) { |
7 | 4877 | PTDEBUG && _d("Did not find arg, looking for special cases"); | 4877 | PTDEBUG && _d("Did not find arg, looking for special cases"); |
9 | 4878 | local $INPUT_RECORD_SEPARATOR = ";\n"; | 4878 | local $INPUT_RECORD_SEPARATOR = ";\n"; # get next line |
10 | 4879 | if ( defined(my $l = $next_event->()) ) { | 4879 | if ( defined(my $l = $next_event->()) ) { |
17 | 4880 | chomp $l; | 4880 | if ( $l =~ /^\s*[A-Z][a-z_]+: / ) { |
18 | 4881 | $l =~ s/^\s+//; | 4881 | PTDEBUG && _d("Found NULL query before", $l); |
19 | 4882 | PTDEBUG && _d("Found admin statement", $l); | 4882 | local $INPUT_RECORD_SEPARATOR = ";\n#"; |
20 | 4883 | push @properties, 'cmd', 'Admin', 'arg', $l; | 4883 | my $rest_of_event = $next_event->(); |
21 | 4884 | push @properties, 'bytes', length($properties[-1]); | 4884 | push @{$self->{pending}}, $l . $rest_of_event; |
22 | 4885 | $found_arg++; | 4885 | push @properties, 'cmd', 'Query', 'arg', '/* No query */'; |
23 | 4886 | push @properties, 'bytes', 0; | ||
24 | 4887 | $found_arg++; | ||
25 | 4888 | } | ||
26 | 4889 | else { | ||
27 | 4890 | chomp $l; | ||
28 | 4891 | $l =~ s/^\s+//; | ||
29 | 4892 | PTDEBUG && _d("Found admin statement", $l); | ||
30 | 4893 | push @properties, 'cmd', 'Admin', 'arg', $l; | ||
31 | 4894 | push @properties, 'bytes', length($properties[-1]); | ||
32 | 4895 | $found_arg++; | ||
33 | 4896 | } | ||
34 | 4886 | } | 4897 | } |
35 | 4887 | else { | 4898 | else { |
36 | 4888 | PTDEBUG && _d("I can't figure out what to do with this line"); | 4899 | PTDEBUG && _d("I can't figure out what to do with this line"); |
37 | 4889 | 4900 | ||
38 | === modified file 'lib/SlowLogParser.pm' | |||
39 | --- lib/SlowLogParser.pm 2012-01-19 19:46:56 +0000 | |||
40 | +++ lib/SlowLogParser.pm 2012-12-11 01:40:25 +0000 | |||
41 | @@ -235,14 +235,35 @@ | |||
42 | 235 | # this only if we've seen the user/host line. | 235 | # this only if we've seen the user/host line. |
43 | 236 | if ( !$found_arg && $pos == $len ) { | 236 | if ( !$found_arg && $pos == $len ) { |
44 | 237 | PTDEBUG && _d("Did not find arg, looking for special cases"); | 237 | PTDEBUG && _d("Did not find arg, looking for special cases"); |
46 | 238 | local $INPUT_RECORD_SEPARATOR = ";\n"; | 238 | local $INPUT_RECORD_SEPARATOR = ";\n"; # get next line |
47 | 239 | if ( defined(my $l = $next_event->()) ) { | 239 | if ( defined(my $l = $next_event->()) ) { |
54 | 240 | chomp $l; | 240 | if ( $l =~ /^\s*[A-Z][a-z_]+: / ) { |
55 | 241 | $l =~ s/^\s+//; | 241 | PTDEBUG && _d("Found NULL query before", $l); |
56 | 242 | PTDEBUG && _d("Found admin statement", $l); | 242 | # https://bugs.launchpad.net/percona-toolkit/+bug/1082599 |
57 | 243 | push @properties, 'cmd', 'Admin', 'arg', $l; | 243 | # This is really pathological but it happens: |
58 | 244 | push @properties, 'bytes', length($properties[-1]); | 244 | # header_for_query_1 |
59 | 245 | $found_arg++; | 245 | # SET timestamp=123; |
60 | 246 | # use db; | ||
61 | 247 | # header_for_query_2 | ||
62 | 248 | # In this case, "get next line" ^ will actually fetch | ||
63 | 249 | # header_for_query_2 and the first line of any arg data, | ||
64 | 250 | # so to get the rest of the arg data, we switch back to | ||
65 | 251 | # the default input rec. sep. | ||
66 | 252 | local $INPUT_RECORD_SEPARATOR = ";\n#"; | ||
67 | 253 | my $rest_of_event = $next_event->(); | ||
68 | 254 | push @{$self->{pending}}, $l . $rest_of_event; | ||
69 | 255 | push @properties, 'cmd', 'Query', 'arg', '/* No query */'; | ||
70 | 256 | push @properties, 'bytes', 0; | ||
71 | 257 | $found_arg++; | ||
72 | 258 | } | ||
73 | 259 | else { | ||
74 | 260 | chomp $l; | ||
75 | 261 | $l =~ s/^\s+//; | ||
76 | 262 | PTDEBUG && _d("Found admin statement", $l); | ||
77 | 263 | push @properties, 'cmd', 'Admin', 'arg', $l; | ||
78 | 264 | push @properties, 'bytes', length($properties[-1]); | ||
79 | 265 | $found_arg++; | ||
80 | 266 | } | ||
81 | 246 | } | 267 | } |
82 | 247 | else { | 268 | else { |
83 | 248 | # Unrecoverable -- who knows what happened. This is possible, | 269 | # Unrecoverable -- who knows what happened. This is possible, |
84 | 249 | 270 | ||
85 | === modified file 't/lib/SlowLogParser.t' | |||
86 | --- t/lib/SlowLogParser.t 2012-03-30 02:16:53 +0000 | |||
87 | +++ t/lib/SlowLogParser.t 2012-12-11 01:40:25 +0000 | |||
88 | @@ -9,8 +9,8 @@ | |||
89 | 9 | use strict; | 9 | use strict; |
90 | 10 | use warnings FATAL => 'all'; | 10 | use warnings FATAL => 'all'; |
91 | 11 | use English qw(-no_match_vars); | 11 | use English qw(-no_match_vars); |
92 | 12 | use Test::More tests => 48; | ||
93 | 13 | 12 | ||
94 | 13 | use Test::More; | ||
95 | 14 | use SlowLogParser; | 14 | use SlowLogParser; |
96 | 15 | use PerconaTest; | 15 | use PerconaTest; |
97 | 16 | 16 | ||
98 | @@ -1297,6 +1297,59 @@ | |||
99 | 1297 | ); | 1297 | ); |
100 | 1298 | 1298 | ||
101 | 1299 | # ############################################################################# | 1299 | # ############################################################################# |
102 | 1300 | # pt-query-digest fails to parse timestamp with no query | ||
103 | 1301 | # https://bugs.launchpad.net/percona-toolkit/+bug/1082599 | ||
104 | 1302 | # ############################################################################# | ||
105 | 1303 | test_log_parser( | ||
106 | 1304 | parser => $p, | ||
107 | 1305 | file => "$sample/slow056.txt", | ||
108 | 1306 | result => [ | ||
109 | 1307 | { Lock_time => '0.000000', | ||
110 | 1308 | Query_time => '0.000102', | ||
111 | 1309 | Rows_read => '0', | ||
112 | 1310 | Rows_affected => '0', | ||
113 | 1311 | Rows_examined => '0', | ||
114 | 1312 | Rows_sent => '0', | ||
115 | 1313 | arg => '/* No query */', | ||
116 | 1314 | bytes => '0', | ||
117 | 1315 | cmd => 'Query', | ||
118 | 1316 | pos_in_log => '0', | ||
119 | 1317 | ts => '121123 19:56:06', | ||
120 | 1318 | Thread_id => '558038', | ||
121 | 1319 | Last_errno => 0, | ||
122 | 1320 | Killed => 0, | ||
123 | 1321 | db => 'test_db', | ||
124 | 1322 | host => '', | ||
125 | 1323 | Schema => 'test_db', | ||
126 | 1324 | ip => '127.0.0.1', | ||
127 | 1325 | timestamp => '1111111111', | ||
128 | 1326 | user => 'root', | ||
129 | 1327 | }, | ||
130 | 1328 | { | ||
131 | 1329 | ts => '121123 19:56:06', | ||
132 | 1330 | Killed => '0', | ||
133 | 1331 | Last_errno => '0', | ||
134 | 1332 | Lock_time => '0.000197', | ||
135 | 1333 | Query_time => '0.002515', | ||
136 | 1334 | Rows_affected => '1', | ||
137 | 1335 | Rows_examined => '1', | ||
138 | 1336 | Rows_read => '0', | ||
139 | 1337 | Rows_sent => '0', | ||
140 | 1338 | Schema => 'test_db', | ||
141 | 1339 | Thread_id => '558032', | ||
142 | 1340 | arg => 'update t set b = b + 30 where user_id=1', | ||
143 | 1341 | bytes => 39, | ||
144 | 1342 | cmd => 'Query', | ||
145 | 1343 | host => '', | ||
146 | 1344 | ip => '127.0.0.1', | ||
147 | 1345 | pos_in_log => 596, | ||
148 | 1346 | timestamp => '2222222222', | ||
149 | 1347 | user => 'root', | ||
150 | 1348 | }, | ||
151 | 1349 | ], | ||
152 | 1350 | ); | ||
153 | 1351 | |||
154 | 1352 | # ############################################################################# | ||
155 | 1300 | # Done. | 1353 | # Done. |
156 | 1301 | # ############################################################################# | 1354 | # ############################################################################# |
157 | 1302 | my $output = ''; | 1355 | my $output = ''; |
158 | @@ -1310,4 +1363,4 @@ | |||
159 | 1310 | qr/Complete test coverage/, | 1363 | qr/Complete test coverage/, |
160 | 1311 | '_d() works' | 1364 | '_d() works' |
161 | 1312 | ); | 1365 | ); |
163 | 1313 | exit; | 1366 | done_testing; |
164 | 1314 | 1367 | ||
165 | === added file 't/lib/samples/slowlogs/slow056.txt' | |||
166 | --- t/lib/samples/slowlogs/slow056.txt 1970-01-01 00:00:00 +0000 | |||
167 | +++ t/lib/samples/slowlogs/slow056.txt 2012-12-11 01:40:25 +0000 | |||
168 | @@ -0,0 +1,12 @@ | |||
169 | 1 | # Time: 121123 19:56:06.0000001967 | ||
170 | 2 | # User@Host: root[root] @ [127.0.0.1] | ||
171 | 3 | # Thread_id: 558038 Schema: test_db Last_errno: 0 Killed: 0 | ||
172 | 4 | # Query_time: 0.000102 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0 Rows_affected: 0 Rows_read: 0 | ||
173 | 5 | SET timestamp=1111111111; | ||
174 | 6 | use test_db; | ||
175 | 7 | # Time: 121123 19:56:06.0000002134 | ||
176 | 8 | # User@Host: root[root] @ [127.0.0.1] | ||
177 | 9 | # Thread_id: 558032 Schema: test_db Last_errno: 0 Killed: 0 | ||
178 | 10 | # Query_time: 0.002515 Lock_time: 0.000197 Rows_sent: 0 Rows_examined: 1 Rows_affected: 1 Rows_read: 0 | ||
179 | 11 | SET timestamp=2222222222; | ||
180 | 12 | update t set b = b + 30 where user_id=1; | ||
181 | 0 | 13 | ||
182 | === added file 't/pt-query-digest/samples/slow056.txt' | |||
183 | --- t/pt-query-digest/samples/slow056.txt 1970-01-01 00:00:00 +0000 | |||
184 | +++ t/pt-query-digest/samples/slow056.txt 2012-12-11 01:40:25 +0000 | |||
185 | @@ -0,0 +1,68 @@ | |||
186 | 1 | |||
187 | 2 | # Query 1: 0 QPS, 0x concurrency, ID 0x54E0BB9E70EAA792 at byte 596 ______ | ||
188 | 3 | # This item is included in the report because it matches --limit. | ||
189 | 4 | # Scores: Apdex = 1.00 [1.0]*, V/M = 0.00 | ||
190 | 5 | # Query_time sparkline: | ^ | | ||
191 | 6 | # Time range: all events occurred at 2012-11-23 19:56:06 | ||
192 | 7 | # Attribute pct total min max avg 95% stddev median | ||
193 | 8 | # ============ === ======= ======= ======= ======= ======= ======= ======= | ||
194 | 9 | # Count 50 1 | ||
195 | 10 | # Exec time 96 3ms 3ms 3ms 3ms 3ms 0 3ms | ||
196 | 11 | # Lock time 100 197us 197us 197us 197us 197us 0 197us | ||
197 | 12 | # Rows sent 0 0 0 0 0 0 0 0 | ||
198 | 13 | # Rows examine 100 1 1 1 1 1 0 1 | ||
199 | 14 | # Rows affecte 100 1 1 1 1 1 0 1 | ||
200 | 15 | # Rows read 0 0 0 0 0 0 0 0 | ||
201 | 16 | # Query size 100 39 39 39 39 39 0 39 | ||
202 | 17 | # String: | ||
203 | 18 | # Databases test_db | ||
204 | 19 | # Hosts | ||
205 | 20 | # Last errno 0 | ||
206 | 21 | # Users root | ||
207 | 22 | # Query_time distribution | ||
208 | 23 | # 1us | ||
209 | 24 | # 10us | ||
210 | 25 | # 100us | ||
211 | 26 | # 1ms ################################################################ | ||
212 | 27 | # 10ms | ||
213 | 28 | # 100ms | ||
214 | 29 | # 1s | ||
215 | 30 | # 10s+ | ||
216 | 31 | # Tables | ||
217 | 32 | # SHOW TABLE STATUS FROM `test_db` LIKE 't'\G | ||
218 | 33 | # SHOW CREATE TABLE `test_db`.`t`\G | ||
219 | 34 | update t set b = b + 30 where user_id=1\G | ||
220 | 35 | # Converted for EXPLAIN | ||
221 | 36 | # EXPLAIN /*!50100 PARTITIONS*/ | ||
222 | 37 | select b = b + 30 from t where user_id=1\G | ||
223 | 38 | |||
224 | 39 | # Query 2: 0 QPS, 0x concurrency, ID 0xE9800998ECF8427E at byte 0 ________ | ||
225 | 40 | # This item is included in the report because it matches --limit. | ||
226 | 41 | # Scores: Apdex = 1.00 [1.0]*, V/M = 0.00 | ||
227 | 42 | # Query_time sparkline: | ^ | | ||
228 | 43 | # Time range: all events occurred at 2012-11-23 19:56:06 | ||
229 | 44 | # Attribute pct total min max avg 95% stddev median | ||
230 | 45 | # ============ === ======= ======= ======= ======= ======= ======= ======= | ||
231 | 46 | # Count 50 1 | ||
232 | 47 | # Exec time 3 102us 102us 102us 102us 102us 0 102us | ||
233 | 48 | # Lock time 0 0 0 0 0 0 0 0 | ||
234 | 49 | # Rows sent 0 0 0 0 0 0 0 0 | ||
235 | 50 | # Rows examine 0 0 0 0 0 0 0 0 | ||
236 | 51 | # Rows affecte 0 0 0 0 0 0 0 0 | ||
237 | 52 | # Rows read 0 0 0 0 0 0 0 0 | ||
238 | 53 | # Query size 0 0 0 0 0 0 0 0 | ||
239 | 54 | # String: | ||
240 | 55 | # Databases test_db | ||
241 | 56 | # Hosts | ||
242 | 57 | # Last errno 0 | ||
243 | 58 | # Users root | ||
244 | 59 | # Query_time distribution | ||
245 | 60 | # 1us | ||
246 | 61 | # 10us | ||
247 | 62 | # 100us ################################################################ | ||
248 | 63 | # 1ms | ||
249 | 64 | # 10ms | ||
250 | 65 | # 100ms | ||
251 | 66 | # 1s | ||
252 | 67 | # 10s+ | ||
253 | 68 | /* No query */\G | ||
254 | 0 | 69 | ||
255 | === modified file 't/pt-query-digest/slowlog_analyses.t' | |||
256 | --- t/pt-query-digest/slowlog_analyses.t 2012-11-21 16:58:40 +0000 | |||
257 | +++ t/pt-query-digest/slowlog_analyses.t 2012-12-11 01:40:25 +0000 | |||
258 | @@ -9,10 +9,9 @@ | |||
259 | 9 | use strict; | 9 | use strict; |
260 | 10 | use warnings FATAL => 'all'; | 10 | use warnings FATAL => 'all'; |
261 | 11 | use English qw(-no_match_vars); | 11 | use English qw(-no_match_vars); |
263 | 12 | use Test::More tests => 44; | 12 | use Test::More; |
264 | 13 | 13 | ||
265 | 14 | use PerconaTest; | 14 | use PerconaTest; |
266 | 15 | |||
267 | 16 | require "$trunk/bin/pt-query-digest"; | 15 | require "$trunk/bin/pt-query-digest"; |
268 | 17 | 16 | ||
269 | 18 | # ############################################################################# | 17 | # ############################################################################# |
270 | @@ -435,6 +434,17 @@ | |||
271 | 435 | ); | 434 | ); |
272 | 436 | 435 | ||
273 | 437 | # ############################################################################# | 436 | # ############################################################################# |
274 | 437 | # Bug 1082599: pt-query-digest fails to parse timestamp with no query | ||
275 | 438 | # ############################################################################# | ||
276 | 439 | ok( | ||
277 | 440 | no_diff( | ||
278 | 441 | sub { pt_query_digest::main(@args, $sample.'slow056.txt') }, | ||
279 | 442 | "t/pt-query-digest/samples/slow056.txt", | ||
280 | 443 | ), | ||
281 | 444 | 'Analysis for slow056 (no query bug 1082599)' | ||
282 | 445 | ); | ||
283 | 446 | |||
284 | 447 | # ############################################################################# | ||
285 | 438 | # Done. | 448 | # Done. |
286 | 439 | # ############################################################################# | 449 | # ############################################################################# |
288 | 440 | exit; | 450 | done_testing; |