Merge lp:~sergei.glushchenko/percona-server/5.6-BT31625-ps-blueprint-max-slowlog-files-and-max-slow-log-size into lp:percona-server/5.6
Proposed by
Sergei Glushchenko
Status: | Merged |
---|---|
Approved by: | Stewart Smith |
Approved revision: | no longer in the source branch. |
Merged at revision: | 535 |
Proposed branch: | lp:~sergei.glushchenko/percona-server/5.6-BT31625-ps-blueprint-max-slowlog-files-and-max-slow-log-size |
Merge into: | lp:percona-server/5.6 |
Diff against target: |
679 lines (+368/-25) 13 files modified
Percona-Server/mysql-test/r/mysqld--help-notwin.result (+11/-0) Percona-Server/mysql-test/r/mysqld--help-win.result (+11/-0) Percona-Server/mysql-test/r/percona_slowlog_size_limits.result (+21/-0) Percona-Server/mysql-test/suite/sys_vars/r/max_slowlog_files_basic.result (+30/-0) Percona-Server/mysql-test/suite/sys_vars/r/max_slowlog_size_basic.result (+32/-0) Percona-Server/mysql-test/suite/sys_vars/t/max_slowlog_files_basic.test (+18/-0) Percona-Server/mysql-test/suite/sys_vars/t/max_slowlog_size_basic.test (+18/-0) Percona-Server/mysql-test/t/percona_slowlog_size_limits.test (+60/-0) Percona-Server/sql/binlog.cc (+3/-3) Percona-Server/sql/log.cc (+133/-17) Percona-Server/sql/log.h (+11/-5) Percona-Server/sql/mysqld.h (+2/-0) Percona-Server/sql/sys_vars.cc (+18/-0) |
To merge this branch: | bzr merge lp:~sergei.glushchenko/percona-server/5.6-BT31625-ps-blueprint-max-slowlog-files-and-max-slow-log-size |
Related bugs: | |
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Stewart Smith (community) | Approve | ||
George Ormond Lorch III (community) | g2 | Approve | |
Review via email: mp+184600@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
George Ormond Lorch III (gl-az) wrote : | # |
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote : | # |
George, this MP refers to separate BP for 5.6. BP has same name as 5.5, but is different. Also I've updated this branch with changes from 5.5.
Revision history for this message
George Ormond Lorch III (gl-az) : | # |
review:
Approve
(g2)
Revision history for this message
Stewart Smith (stewart) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Percona-Server/mysql-test/r/mysqld--help-notwin.result' |
2 | --- Percona-Server/mysql-test/r/mysqld--help-notwin.result 2013-09-09 07:01:33 +0000 |
3 | +++ Percona-Server/mysql-test/r/mysqld--help-notwin.result 2013-09-20 19:27:42 +0000 |
4 | @@ -443,6 +443,15 @@ |
5 | --max-seeks-for-key=# |
6 | Limit assumed max number of seeks when looking up rows |
7 | based on a key |
8 | + --max-slowlog-files=# |
9 | + Maximum number of slow query log files. Used with |
10 | + --max-slowlog-size this can be used to limit the total |
11 | + amount of disk space used for the slow query log. Default |
12 | + is 0, don't limit. |
13 | + --max-slowlog-size=# |
14 | + Slow query log will be rotated automatically when the |
15 | + size exceeds this value. The default is 0, don't limit |
16 | + the size. |
17 | --max-sort-length=# The number of bytes to use when sorting BLOB or TEXT |
18 | values (only the first max_sort_length bytes of each |
19 | value are used; the rest are ignored) |
20 | @@ -1207,6 +1216,8 @@ |
21 | max-prepared-stmt-count 16382 |
22 | max-relay-log-size 0 |
23 | max-seeks-for-key 18446744073709551615 |
24 | +max-slowlog-files 0 |
25 | +max-slowlog-size 0 |
26 | max-sort-length 1024 |
27 | max-sp-recursion-depth 0 |
28 | max-tmp-tables 32 |
29 | |
30 | === modified file 'Percona-Server/mysql-test/r/mysqld--help-win.result' |
31 | --- Percona-Server/mysql-test/r/mysqld--help-win.result 2013-09-09 07:01:33 +0000 |
32 | +++ Percona-Server/mysql-test/r/mysqld--help-win.result 2013-09-20 19:27:42 +0000 |
33 | @@ -419,6 +419,15 @@ |
34 | --max-seeks-for-key=# |
35 | Limit assumed max number of seeks when looking up rows |
36 | based on a key |
37 | + --max-slowlog-files=# |
38 | + Maximum number of slow query log files. Used with |
39 | + --max-slowlog-size this can be used to limit the total |
40 | + amount of disk space used for the slow query log. Default |
41 | + is 0, don't limit. |
42 | + --max-slowlog-size=# |
43 | + Slow query log will be rotated automatically when the |
44 | + size exceeds this value. The default is 0, don't limit |
45 | + the size. |
46 | --max-sort-length=# The number of bytes to use when sorting BLOB or TEXT |
47 | values (only the first max_sort_length bytes of each |
48 | value are used; the rest are ignored) |
49 | @@ -1153,6 +1162,8 @@ |
50 | max-prepared-stmt-count 16382 |
51 | max-relay-log-size 0 |
52 | max-seeks-for-key 18446744073709551615 |
53 | +max-slowlog-files 0 |
54 | +max-slowlog-size 0 |
55 | max-sort-length 1024 |
56 | max-sp-recursion-depth 0 |
57 | max-tmp-tables 32 |
58 | |
59 | === added file 'Percona-Server/mysql-test/r/percona_slowlog_size_limits.result' |
60 | --- Percona-Server/mysql-test/r/percona_slowlog_size_limits.result 1970-01-01 00:00:00 +0000 |
61 | +++ Percona-Server/mysql-test/r/percona_slowlog_size_limits.result 2013-09-20 19:27:42 +0000 |
62 | @@ -0,0 +1,21 @@ |
63 | +SET @old_slow_query_log = @@global.slow_query_log; |
64 | +SET @old_log_output = @@global.log_output; |
65 | +SET @old_slow_query_log_file = @@global.slow_query_log_file; |
66 | +SET @old_max_slowlog_size = @@global.max_slowlog_size; |
67 | +SET @old_max_slowlog_files = @@global.max_slowlog_files; |
68 | +SET @old_long_query_time = @@long_query_time; |
69 | +SET GLOBAL slow_query_log=1; |
70 | +SET GLOBAL log_output=FILE; |
71 | +SET GLOBAL max_slowlog_size=4096; |
72 | +SET GLOBAL max_slowlog_files=5; |
73 | +SET long_query_time=0; |
74 | +SET GLOBAL slow_query_log_file='MYSQLTEST_VARDIR/abcd'; |
75 | +5 |
76 | +SET GLOBAL slow_query_log_file='MYSQLTEST_VARDIR/zxcv'; |
77 | +5 |
78 | +SET @@global.slow_query_log = @old_slow_query_log; |
79 | +SET @@global.log_output = @old_log_output; |
80 | +SET @@global.slow_query_log_file = @old_slow_query_log_file; |
81 | +SET @@global.max_slowlog_size = @old_max_slowlog_size; |
82 | +SET @@global.max_slowlog_files = @old_max_slowlog_files; |
83 | +SET @@long_query_time = @old_long_query_time; |
84 | |
85 | === added file 'Percona-Server/mysql-test/suite/sys_vars/r/max_slowlog_files_basic.result' |
86 | --- Percona-Server/mysql-test/suite/sys_vars/r/max_slowlog_files_basic.result 1970-01-01 00:00:00 +0000 |
87 | +++ Percona-Server/mysql-test/suite/sys_vars/r/max_slowlog_files_basic.result 2013-09-20 19:27:42 +0000 |
88 | @@ -0,0 +1,30 @@ |
89 | +SET @old = @@global.max_slowlog_files; |
90 | +SET GLOBAL max_slowlog_files = 0; |
91 | +SELECT @@global.max_slowlog_files; |
92 | +@@global.max_slowlog_files |
93 | +0 |
94 | +SET GLOBAL max_slowlog_files = 4096; |
95 | +SELECT @@global.max_slowlog_files; |
96 | +@@global.max_slowlog_files |
97 | +4096 |
98 | +SET GLOBAL max_slowlog_files = 1000; |
99 | +SELECT @@global.max_slowlog_files; |
100 | +@@global.max_slowlog_files |
101 | +1000 |
102 | +SET GLOBAL max_slowlog_files = -1; |
103 | +Warnings: |
104 | +Warning 1292 Truncated incorrect max_slowlog_files value: '-1' |
105 | +SELECT @@global.max_slowlog_files; |
106 | +@@global.max_slowlog_files |
107 | +0 |
108 | +SET GLOBAL max_slowlog_files = 102400; |
109 | +SELECT @@global.max_slowlog_files; |
110 | +@@global.max_slowlog_files |
111 | +102400 |
112 | +SET GLOBAL max_slowlog_files = 102401; |
113 | +Warnings: |
114 | +Warning 1292 Truncated incorrect max_slowlog_files value: '102401' |
115 | +SELECT @@global.max_slowlog_files; |
116 | +@@global.max_slowlog_files |
117 | +102400 |
118 | +SET @@global.max_slowlog_files = @old; |
119 | |
120 | === added file 'Percona-Server/mysql-test/suite/sys_vars/r/max_slowlog_size_basic.result' |
121 | --- Percona-Server/mysql-test/suite/sys_vars/r/max_slowlog_size_basic.result 1970-01-01 00:00:00 +0000 |
122 | +++ Percona-Server/mysql-test/suite/sys_vars/r/max_slowlog_size_basic.result 2013-09-20 19:27:42 +0000 |
123 | @@ -0,0 +1,32 @@ |
124 | +SET @old = @@global.max_slowlog_size; |
125 | +SET GLOBAL max_slowlog_size = 0; |
126 | +SELECT @@global.max_slowlog_size; |
127 | +@@global.max_slowlog_size |
128 | +0 |
129 | +SET GLOBAL max_slowlog_size = 4096; |
130 | +SELECT @@global.max_slowlog_size; |
131 | +@@global.max_slowlog_size |
132 | +4096 |
133 | +SET GLOBAL max_slowlog_size = 1000; |
134 | +Warnings: |
135 | +Warning 1292 Truncated incorrect max_slowlog_size value: '1000' |
136 | +SELECT @@global.max_slowlog_size; |
137 | +@@global.max_slowlog_size |
138 | +0 |
139 | +SET GLOBAL max_slowlog_size = -1; |
140 | +Warnings: |
141 | +Warning 1292 Truncated incorrect max_slowlog_size value: '-1' |
142 | +SELECT @@global.max_slowlog_size; |
143 | +@@global.max_slowlog_size |
144 | +0 |
145 | +SET GLOBAL max_slowlog_size = 1024*1024*1024; |
146 | +SELECT @@global.max_slowlog_size; |
147 | +@@global.max_slowlog_size |
148 | +1073741824 |
149 | +SET GLOBAL max_slowlog_size = 1024*1024*1024+1; |
150 | +Warnings: |
151 | +Warning 1292 Truncated incorrect max_slowlog_size value: '1073741825' |
152 | +SELECT @@global.max_slowlog_size; |
153 | +@@global.max_slowlog_size |
154 | +1073741824 |
155 | +SET @@global.max_slowlog_size = @old; |
156 | |
157 | === added file 'Percona-Server/mysql-test/suite/sys_vars/t/max_slowlog_files_basic.test' |
158 | --- Percona-Server/mysql-test/suite/sys_vars/t/max_slowlog_files_basic.test 1970-01-01 00:00:00 +0000 |
159 | +++ Percona-Server/mysql-test/suite/sys_vars/t/max_slowlog_files_basic.test 2013-09-20 19:27:42 +0000 |
160 | @@ -0,0 +1,18 @@ |
161 | +# |
162 | +# Test max_slowlog_files |
163 | +# |
164 | + |
165 | +SET @old = @@global.max_slowlog_files; |
166 | +SET GLOBAL max_slowlog_files = 0; |
167 | +SELECT @@global.max_slowlog_files; |
168 | +SET GLOBAL max_slowlog_files = 4096; |
169 | +SELECT @@global.max_slowlog_files; |
170 | +SET GLOBAL max_slowlog_files = 1000; |
171 | +SELECT @@global.max_slowlog_files; |
172 | +SET GLOBAL max_slowlog_files = -1; |
173 | +SELECT @@global.max_slowlog_files; |
174 | +SET GLOBAL max_slowlog_files = 102400; |
175 | +SELECT @@global.max_slowlog_files; |
176 | +SET GLOBAL max_slowlog_files = 102401; |
177 | +SELECT @@global.max_slowlog_files; |
178 | +SET @@global.max_slowlog_files = @old; |
179 | |
180 | === added file 'Percona-Server/mysql-test/suite/sys_vars/t/max_slowlog_size_basic.test' |
181 | --- Percona-Server/mysql-test/suite/sys_vars/t/max_slowlog_size_basic.test 1970-01-01 00:00:00 +0000 |
182 | +++ Percona-Server/mysql-test/suite/sys_vars/t/max_slowlog_size_basic.test 2013-09-20 19:27:42 +0000 |
183 | @@ -0,0 +1,18 @@ |
184 | +# |
185 | +# Test max_slowlog_size |
186 | +# |
187 | + |
188 | +SET @old = @@global.max_slowlog_size; |
189 | +SET GLOBAL max_slowlog_size = 0; |
190 | +SELECT @@global.max_slowlog_size; |
191 | +SET GLOBAL max_slowlog_size = 4096; |
192 | +SELECT @@global.max_slowlog_size; |
193 | +SET GLOBAL max_slowlog_size = 1000; |
194 | +SELECT @@global.max_slowlog_size; |
195 | +SET GLOBAL max_slowlog_size = -1; |
196 | +SELECT @@global.max_slowlog_size; |
197 | +SET GLOBAL max_slowlog_size = 1024*1024*1024; |
198 | +SELECT @@global.max_slowlog_size; |
199 | +SET GLOBAL max_slowlog_size = 1024*1024*1024+1; |
200 | +SELECT @@global.max_slowlog_size; |
201 | +SET @@global.max_slowlog_size = @old; |
202 | |
203 | === added file 'Percona-Server/mysql-test/t/percona_slowlog_size_limits.test' |
204 | --- Percona-Server/mysql-test/t/percona_slowlog_size_limits.test 1970-01-01 00:00:00 +0000 |
205 | +++ Percona-Server/mysql-test/t/percona_slowlog_size_limits.test 2013-09-20 19:27:42 +0000 |
206 | @@ -0,0 +1,60 @@ |
207 | +# |
208 | +# Test slowlog size limiting and rotation |
209 | +# |
210 | + |
211 | +SET @old_slow_query_log = @@global.slow_query_log; |
212 | +SET @old_log_output = @@global.log_output; |
213 | +SET @old_slow_query_log_file = @@global.slow_query_log_file; |
214 | +SET @old_max_slowlog_size = @@global.max_slowlog_size; |
215 | +SET @old_max_slowlog_files = @@global.max_slowlog_files; |
216 | +SET @old_long_query_time = @@long_query_time; |
217 | + |
218 | +SET GLOBAL slow_query_log=1; |
219 | +SET GLOBAL log_output=FILE; |
220 | +SET GLOBAL max_slowlog_size=4096; |
221 | +SET GLOBAL max_slowlog_files=5; |
222 | +SET long_query_time=0; |
223 | + |
224 | +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR |
225 | +eval SET GLOBAL slow_query_log_file='$MYSQLTEST_VARDIR/abcd'; |
226 | + |
227 | +# avoid 1000 selects 1 in .result |
228 | +let $i=1000; |
229 | +disable_query_log; |
230 | +disable_result_log; |
231 | +while($i) { |
232 | + eval select $i; |
233 | + dec $i; |
234 | +} |
235 | +enable_query_log; |
236 | +enable_result_log; |
237 | + |
238 | +perl; |
239 | +my @files = <$ENV{'MYSQLTEST_VARDIR'}/abcd*>; |
240 | +printf "%d\n", scalar(@files); |
241 | +EOF |
242 | + |
243 | + |
244 | +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR |
245 | +eval SET GLOBAL slow_query_log_file='$MYSQLTEST_VARDIR/zxcv'; |
246 | + |
247 | +let $i=1000; |
248 | +disable_query_log; |
249 | +disable_result_log; |
250 | +while($i) { |
251 | + eval select $i; |
252 | + dec $i; |
253 | +} |
254 | +enable_query_log; |
255 | +enable_result_log; |
256 | +perl; |
257 | +my @files = <$ENV{'MYSQLTEST_VARDIR'}/zxcv*>; |
258 | +printf "%d\n", scalar(@files); |
259 | +EOF |
260 | + |
261 | +SET @@global.slow_query_log = @old_slow_query_log; |
262 | +SET @@global.log_output = @old_log_output; |
263 | +SET @@global.slow_query_log_file = @old_slow_query_log_file; |
264 | +SET @@global.max_slowlog_size = @old_max_slowlog_size; |
265 | +SET @@global.max_slowlog_files = @old_max_slowlog_files; |
266 | +SET @@long_query_time = @old_long_query_time; |
267 | |
268 | === modified file 'Percona-Server/sql/binlog.cc' |
269 | --- Percona-Server/sql/binlog.cc 2013-08-06 15:16:34 +0000 |
270 | +++ Percona-Server/sql/binlog.cc 2013-09-20 19:27:42 +0000 |
271 | @@ -2909,7 +2909,7 @@ |
272 | DBUG_PRINT("enter",("name: %s", log_name)); |
273 | |
274 | if (init_and_set_log_file_name(log_name, new_name, LOG_BIN, |
275 | - io_cache_type_arg)) |
276 | + io_cache_type_arg, true)) |
277 | { |
278 | sql_print_error("MYSQL_BIN_LOG::open failed to generate new file name."); |
279 | DBUG_RETURN(1); |
280 | @@ -2951,7 +2951,7 @@ |
281 | #ifdef HAVE_PSI_INTERFACE |
282 | m_key_file_log, |
283 | #endif |
284 | - log_name, LOG_BIN, new_name, io_cache_type_arg)) |
285 | + log_name, LOG_BIN, new_name, io_cache_type_arg, true)) |
286 | { |
287 | #ifdef HAVE_REPLICATION |
288 | close_purge_index_file(); |
289 | @@ -4697,7 +4697,7 @@ |
290 | We have to do this here and not in open as we want to store the |
291 | new file name in the current binary log file. |
292 | */ |
293 | - if ((error= generate_new_name(new_name, name))) |
294 | + if ((error= generate_new_name(new_name, name, log_type == LOG_BIN))) |
295 | goto end; |
296 | else |
297 | { |
298 | |
299 | === modified file 'Percona-Server/sql/log.cc' |
300 | --- Percona-Server/sql/log.cc 2013-09-09 07:01:33 +0000 |
301 | +++ Percona-Server/sql/log.cc 2013-09-20 19:27:42 +0000 |
302 | @@ -196,6 +196,8 @@ |
303 | LOGGER logger; |
304 | |
305 | ulong max_binlog_files; |
306 | +ulong max_slowlog_size; |
307 | +ulong max_slowlog_files; |
308 | |
309 | static bool test_if_number(const char *str, |
310 | ulong *res, bool allow_wildcards); |
311 | @@ -1414,18 +1416,19 @@ |
312 | nonzero if not possible to get unique filename. |
313 | */ |
314 | |
315 | -static int find_uniq_filename(char *name) |
316 | +static int find_uniq_filename(char *name, ulong *next) |
317 | { |
318 | uint i; |
319 | char buff[FN_REFLEN], ext_buf[FN_REFLEN]; |
320 | struct st_my_dir *dir_info; |
321 | reg1 struct fileinfo *file_info; |
322 | - ulong max_found= 0, next= 0, number= 0; |
323 | + ulong max_found= 0, number= 0; |
324 | size_t buf_length, length; |
325 | char *start, *end; |
326 | int error= 0; |
327 | DBUG_ENTER("find_uniq_filename"); |
328 | |
329 | + *next= 0; |
330 | length= dirname_part(buff, name, &buf_length); |
331 | start= name + length; |
332 | end= strend(start); |
333 | @@ -1460,8 +1463,8 @@ |
334 | goto end; |
335 | } |
336 | |
337 | - next= max_found + 1; |
338 | - if (sprintf(ext_buf, "%06lu", next)<0) |
339 | + *next= max_found + 1; |
340 | + if (sprintf(ext_buf, "%06lu", *next) < 0) |
341 | { |
342 | error= 1; |
343 | goto end; |
344 | @@ -1482,17 +1485,17 @@ |
345 | goto end; |
346 | } |
347 | |
348 | - if (sprintf(end, "%06lu", next)<0) |
349 | + if (sprintf(end, "%06lu", *next)<0) |
350 | { |
351 | error= 1; |
352 | goto end; |
353 | } |
354 | |
355 | /* print warning if reaching the end of available extensions. */ |
356 | - if ((next > (MAX_LOG_UNIQUE_FN_EXT - LOG_WARN_UNIQUE_FN_EXT_LEFT))) |
357 | + if ((*next > (MAX_LOG_UNIQUE_FN_EXT - LOG_WARN_UNIQUE_FN_EXT_LEFT))) |
358 | sql_print_warning("Next log extension: %lu. \ |
359 | Remaining log filename extensions: %lu. \ |
360 | -Please consider archiving some logs.", next, (MAX_LOG_UNIQUE_FN_EXT - next)); |
361 | +Please consider archiving some logs.", *next, (MAX_LOG_UNIQUE_FN_EXT - *next)); |
362 | |
363 | end: |
364 | DBUG_RETURN(error); |
365 | @@ -1513,13 +1516,14 @@ |
366 | bool MYSQL_LOG::init_and_set_log_file_name(const char *log_name, |
367 | const char *new_name, |
368 | enum_log_type log_type_arg, |
369 | - enum cache_type io_cache_type_arg) |
370 | + enum cache_type io_cache_type_arg, |
371 | + bool unique) |
372 | { |
373 | init(log_type_arg, io_cache_type_arg); |
374 | |
375 | if (new_name && !strmov(log_file_name, new_name)) |
376 | return TRUE; |
377 | - else if (!new_name && generate_new_name(log_file_name, log_name)) |
378 | + else if (!new_name && generate_new_name(log_file_name, log_name, unique)) |
379 | return TRUE; |
380 | |
381 | return FALSE; |
382 | @@ -1552,7 +1556,8 @@ |
383 | PSI_file_key log_file_key, |
384 | #endif |
385 | const char *log_name, enum_log_type log_type_arg, |
386 | - const char *new_name, enum cache_type io_cache_type_arg) |
387 | + const char *new_name, enum cache_type io_cache_type_arg, |
388 | + bool unique) |
389 | { |
390 | char buff[FN_REFLEN]; |
391 | File file= -1; |
392 | @@ -1570,7 +1575,7 @@ |
393 | } |
394 | |
395 | if (init_and_set_log_file_name(name, new_name, |
396 | - log_type_arg, io_cache_type_arg)) |
397 | + log_type_arg, io_cache_type_arg, unique)) |
398 | goto err; |
399 | |
400 | if (io_cache_type == SEQ_READ_APPEND) |
401 | @@ -1646,9 +1651,10 @@ |
402 | |
403 | MYSQL_LOG::MYSQL_LOG() |
404 | : name(0), write_error(FALSE), inited(FALSE), log_type(LOG_UNKNOWN), |
405 | - log_state(LOG_CLOSED) |
406 | + log_state(LOG_CLOSED), |
407 | + cur_log_ext(-1) |
408 | #ifdef HAVE_PSI_INTERFACE |
409 | - , m_key_LOCK_log(key_LOG_LOCK_log) |
410 | + , m_key_LOCK_log(key_LOG_LOCK_log) |
411 | #endif |
412 | { |
413 | /* |
414 | @@ -1727,14 +1733,15 @@ |
415 | } |
416 | |
417 | |
418 | -int MYSQL_LOG::generate_new_name(char *new_name, const char *log_name) |
419 | +int MYSQL_LOG::generate_new_name(char *new_name, const char *log_name, |
420 | + bool unique) |
421 | { |
422 | fn_format(new_name, log_name, mysql_data_home, "", 4); |
423 | - if (log_type == LOG_BIN) |
424 | + if (unique) |
425 | { |
426 | if (!fn_ext(log_name)[0]) |
427 | { |
428 | - if (find_uniq_filename(new_name)) |
429 | + if (find_uniq_filename(new_name, &cur_log_ext)) |
430 | { |
431 | my_printf_error(ER_NO_UNIQUE_LOGFILE, ER(ER_NO_UNIQUE_LOGFILE), |
432 | MYF(ME_FATALERROR), log_name); |
433 | @@ -1747,6 +1754,27 @@ |
434 | } |
435 | |
436 | |
437 | +int MYSQL_LOG::purge_up_to(ulong to_ext, const char *log_name) |
438 | +{ |
439 | + char buff[FN_REFLEN]; |
440 | + int error= 0; |
441 | + |
442 | + DBUG_ENTER("MYSQL_LOG::purge_up_to"); |
443 | + |
444 | + do { |
445 | + snprintf(buff, sizeof(buff), "%s.%06lu", name, to_ext); |
446 | + if ((error= unlink(buff))) |
447 | + { |
448 | + if (my_errno == ENOENT) |
449 | + error= 0; |
450 | + break; |
451 | + } |
452 | + --to_ext; |
453 | + } while (to_ext > 0); |
454 | + |
455 | + DBUG_RETURN(error); |
456 | +} |
457 | + |
458 | /* |
459 | Reopen the log file |
460 | |
461 | @@ -1784,7 +1812,7 @@ |
462 | #ifdef HAVE_PSI_INTERFACE |
463 | m_log_file_key, |
464 | #endif |
465 | - save_name, log_type, 0, io_cache_type); |
466 | + save_name, log_type, 0, io_cache_type, false); |
467 | my_free(save_name); |
468 | |
469 | mysql_mutex_unlock(&LOCK_log); |
470 | @@ -1930,6 +1958,7 @@ |
471 | { |
472 | time_t current_time= my_time_possible_from_micro(current_utime); |
473 | bool error= 0; |
474 | + bool need_purge= false; |
475 | DBUG_ENTER("MYSQL_QUERY_LOG::write"); |
476 | |
477 | mysql_mutex_lock(&LOCK_log); |
478 | @@ -2149,8 +2178,95 @@ |
479 | my_strerror(errbuf, sizeof(errbuf), errno)); |
480 | } |
481 | } |
482 | + if (max_slowlog_size > 0) |
483 | + error= rotate(max_slowlog_size, &need_purge); |
484 | } |
485 | + ulong save_cur_ext = cur_log_ext; |
486 | mysql_mutex_unlock(&LOCK_log); |
487 | + if (max_slowlog_files && need_purge && !error) |
488 | + error= purge_up_to(save_cur_ext > max_slowlog_files ? |
489 | + save_cur_ext - max_slowlog_files : 0, |
490 | + log_file_name); |
491 | + DBUG_RETURN(error); |
492 | +} |
493 | + |
494 | + |
495 | +int MYSQL_QUERY_LOG::rotate(ulong max_size, bool *need_purge) |
496 | +{ |
497 | + int error; |
498 | + DBUG_ENTER("MYSQL_QUERY_LOG::rotate"); |
499 | + |
500 | + *need_purge= false; |
501 | + if (my_b_tell(&log_file) > max_size) |
502 | + { |
503 | + if ((error= new_file())) |
504 | + DBUG_RETURN(error); |
505 | + |
506 | + *need_purge= true; |
507 | + } |
508 | + |
509 | + DBUG_RETURN(0); |
510 | +} |
511 | + |
512 | +int MYSQL_QUERY_LOG::new_file() |
513 | +{ |
514 | + int error= 0, close_on_error= FALSE; |
515 | + char new_name[FN_REFLEN], *old_name; |
516 | + |
517 | + DBUG_ENTER("MYSQL_QUERY_LOG::new_file"); |
518 | + if (!is_open()) |
519 | + { |
520 | + DBUG_PRINT("info",("log is closed")); |
521 | + DBUG_RETURN(error); |
522 | + } |
523 | + |
524 | + mysql_mutex_assert_owner(&LOCK_log); |
525 | + |
526 | + if (cur_log_ext == (ulong)-1) |
527 | + { |
528 | + strcpy(new_name, name); |
529 | + if ((error= generate_new_name(new_name, name, true))) |
530 | + goto end; |
531 | + } |
532 | + else |
533 | + { |
534 | + if (cur_log_ext == MAX_LOG_UNIQUE_FN_EXT) |
535 | + { |
536 | + error= 1; |
537 | + goto end; |
538 | + } |
539 | + snprintf(new_name, sizeof(new_name), "%s.%06lu", name, ++cur_log_ext); |
540 | + } |
541 | + |
542 | + /* |
543 | + close will try to free name and zero name pointer, |
544 | + We saving current name value and zeroing the pointer to |
545 | + prvent it. |
546 | + */ |
547 | + old_name= name; |
548 | + name= NULL; |
549 | + close(LOG_CLOSE_TO_BE_OPENED); |
550 | + name= old_name; |
551 | + |
552 | + error= open( |
553 | +#ifdef HAVE_PSI_INTERFACE |
554 | + key_file_query_log, |
555 | +#endif |
556 | + name, |
557 | + LOG_NORMAL, new_name, WRITE_CACHE, false); |
558 | + |
559 | +end: |
560 | + |
561 | + if (error && close_on_error /* rotate or reopen failed */) |
562 | + { |
563 | + sql_print_error("Could not open %s for logging (error %d). " |
564 | + "Turning logging off for the whole duration " |
565 | + "of the MySQL server process. To turn it on " |
566 | + "again: fix the cause, shutdown the MySQL " |
567 | + "server and restart it.", |
568 | + new_name, errno); |
569 | + } |
570 | + |
571 | DBUG_RETURN(error); |
572 | } |
573 | |
574 | |
575 | === modified file 'Percona-Server/sql/log.h' |
576 | --- Percona-Server/sql/log.h 2013-06-20 15:16:00 +0000 |
577 | +++ Percona-Server/sql/log.h 2013-09-20 19:27:42 +0000 |
578 | @@ -271,18 +271,20 @@ |
579 | const char *log_name, |
580 | enum_log_type log_type, |
581 | const char *new_name, |
582 | - enum cache_type io_cache_type_arg); |
583 | + enum cache_type io_cache_type_arg, |
584 | + bool unique); |
585 | bool init_and_set_log_file_name(const char *log_name, |
586 | const char *new_name, |
587 | enum_log_type log_type_arg, |
588 | - enum cache_type io_cache_type_arg); |
589 | + enum cache_type io_cache_type_arg, |
590 | + bool unique); |
591 | void init(enum_log_type log_type_arg, |
592 | enum cache_type io_cache_type_arg); |
593 | void close(uint exiting); |
594 | inline bool is_open() { return log_state != LOG_CLOSED; } |
595 | const char *generate_name(const char *log_name, const char *suffix, |
596 | bool strip_ext, char *buff); |
597 | - int generate_new_name(char *new_name, const char *log_name); |
598 | + int generate_new_name(char *new_name, const char *log_name, bool unique); |
599 | protected: |
600 | /* LOCK_log is inited by init_pthread_objects() */ |
601 | mysql_mutex_t LOCK_log; |
602 | @@ -295,12 +297,14 @@ |
603 | volatile enum_log_state log_state; |
604 | enum cache_type io_cache_type; |
605 | friend class Log_event; |
606 | + ulong cur_log_ext; |
607 | #ifdef HAVE_PSI_INTERFACE |
608 | /** Instrumentation key to use for file io in @c log_file */ |
609 | PSI_file_key m_log_file_key; |
610 | /** The instrumentation key to use for @ LOCK_log. */ |
611 | PSI_mutex_key m_key_LOCK_log; |
612 | #endif |
613 | + int purge_up_to(ulong to_ext, const char *log_name); |
614 | }; |
615 | |
616 | |
617 | @@ -355,7 +359,7 @@ |
618 | key_file_slow_log, |
619 | #endif |
620 | generate_name(log_name, "-slow.log", 0, buf), |
621 | - LOG_NORMAL, 0, WRITE_CACHE); |
622 | + LOG_NORMAL, 0, WRITE_CACHE, max_slowlog_size > 0); |
623 | } |
624 | bool open_query_log(const char *log_name) |
625 | { |
626 | @@ -365,8 +369,10 @@ |
627 | key_file_query_log, |
628 | #endif |
629 | generate_name(log_name, ".log", 0, buf), |
630 | - LOG_NORMAL, 0, WRITE_CACHE); |
631 | + LOG_NORMAL, 0, WRITE_CACHE, false); |
632 | } |
633 | + int rotate(ulong max_size, bool *need_purge); |
634 | + int new_file(); |
635 | |
636 | private: |
637 | time_t last_time; |
638 | |
639 | === modified file 'Percona-Server/sql/mysqld.h' |
640 | --- Percona-Server/sql/mysqld.h 2013-09-09 07:01:33 +0000 |
641 | +++ Percona-Server/sql/mysqld.h 2013-09-20 19:27:42 +0000 |
642 | @@ -157,6 +157,8 @@ |
643 | extern ulong current_pid; |
644 | extern ulong expire_logs_days; |
645 | extern ulong max_binlog_files; |
646 | +extern ulong max_slowlog_size; |
647 | +extern ulong max_slowlog_files; |
648 | extern my_bool relay_log_recovery; |
649 | extern uint sync_binlog_period, sync_relaylog_period, |
650 | sync_relayloginfo_period, sync_masterinfo_period, |
651 | |
652 | === modified file 'Percona-Server/sql/sys_vars.cc' |
653 | --- Percona-Server/sql/sys_vars.cc 2013-09-09 07:01:33 +0000 |
654 | +++ Percona-Server/sql/sys_vars.cc 2013-09-20 19:27:42 +0000 |
655 | @@ -1307,6 +1307,24 @@ |
656 | GLOBAL_VAR(max_binlog_files), |
657 | CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 102400), DEFAULT(0), BLOCK_SIZE(1)); |
658 | |
659 | +static Sys_var_ulong Sys_max_slowlog_size( |
660 | + "max_slowlog_size", |
661 | + "Slow query log will be rotated automatically when the size exceeds " |
662 | + "this value. The default is 0, don't limit the size.", |
663 | + GLOBAL_VAR(max_slowlog_size), CMD_LINE(REQUIRED_ARG), |
664 | + VALID_RANGE(0, 1024*1024L*1024L), DEFAULT(0L), |
665 | + BLOCK_SIZE(IO_SIZE)); |
666 | + |
667 | +static Sys_var_ulong Sys_max_slowlog_files( |
668 | + "max_slowlog_files", |
669 | + "Maximum number of slow query log files. Used with --max-slowlog-size " |
670 | + "this can be used to limit the total amount of disk space used for the " |
671 | + "slow query log. " |
672 | + "Default is 0, don't limit.", |
673 | + GLOBAL_VAR(max_slowlog_files), |
674 | + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 102400), |
675 | + DEFAULT(0), BLOCK_SIZE(1)); |
676 | + |
677 | static Sys_var_mybool Sys_flush( |
678 | "flush", "Flush MyISAM tables to disk between SQL commands", |
679 | GLOBAL_VAR(myisam_flush), |
Same comments as 5.5. Can you create a 5.6 specific blueprint that just points back to the 5.5 and associate it with this branch and MP for docs.