Merge lp:~stewart/percona-server/max-binlog-files into lp:percona-server/5.5

Proposed by Stewart Smith
Status: Merged
Approved by: Laurynas Biveinis
Approved revision: no longer in the source branch.
Merged at revision: 306
Proposed branch: lp:~stewart/percona-server/max-binlog-files
Merge into: lp:percona-server/5.5
Diff against target: 641 lines (+477/-1)
14 files modified
Percona-Server/mysql-test/r/mysqld--help-notwin.result (+6/-0)
Percona-Server/mysql-test/r/mysqld--help-win.result (+6/-0)
Percona-Server/mysql-test/r/percona_server_variables_debug.result (+1/-0)
Percona-Server/mysql-test/r/percona_server_variables_release.result (+1/-0)
Percona-Server/mysql-test/suite/binlog/r/percona_binlog_max_nr.result (+30/-0)
Percona-Server/mysql-test/suite/binlog/t/percona_binlog_max_nr-master.opt (+2/-0)
Percona-Server/mysql-test/suite/binlog/t/percona_binlog_max_nr.test (+60/-0)
Percona-Server/mysql-test/suite/sys_vars/r/max_binlog_files_basic.result (+134/-0)
Percona-Server/mysql-test/suite/sys_vars/t/max_binlog_files_basic.test (+147/-0)
Percona-Server/sql/log.cc (+76/-1)
Percona-Server/sql/log.h (+1/-0)
Percona-Server/sql/mysqld.cc (+4/-0)
Percona-Server/sql/mysqld.h (+1/-0)
Percona-Server/sql/sys_vars.cc (+8/-0)
To merge this branch: bzr merge lp:~stewart/percona-server/max-binlog-files
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Approve
Alexey Kopytov Pending
Review via email: mp+119299@code.launchpad.net

This proposal supersedes a proposal from 2012-07-23.

Description of the change

introduces new server parameter to limit the number of binlog files. Used with setting max file size for binlog you can rather effectively set maximum disk space used by binlogs.

Original Jenkins run:
http://jenkins.percona.com/view/PS%205.5/job/percona-server-5.5-param/385/

This run:
http://jenkins.percona.com/job/percona-server-5.5-param/451/

In this resubmitted req it's just addressing review comments.

To post a comment you must log in.
Revision history for this message
Stewart Smith (stewart) wrote : Posted in a previous version of this proposal

This is for (internal) issue 23617

--
Stewart Smith

Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote : Posted in a previous version of this proposal

The testcase has commit but does not have matching begin transaction or disable autocommit.
Perhaps rename err label to exit, as it is used for non-error returns too.

review: Needs Fixing
Revision history for this message
Stewart Smith (stewart) wrote : Posted in a previous version of this proposal

On Fri, 01 Jun 2012 03:46:26 -0000, Laurynas Biveinis <email address hidden> wrote:
> The testcase has commit but does not have matching begin transaction
> or disable autocommit.

It does have a BEGIN;. It doesn't explicitly set engine to InnoDB,
although in this case it doesn't really matter what engine it executes
with, so I'm just running with default engine.

> Perhaps rename err label to exit, as it is used for non-error returns too.

I generally avoid exit as a label name due to exit(3) existing.
Using err as label is consistent with the rest of log.cc though.

--
Stewart Smith

Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote : Posted in a previous version of this proposal

OK, thanks for explaining.

review: Approve
Revision history for this message
Alexey Kopytov (akopytov) wrote : Posted in a previous version of this proposal

Stewart,

- There is a problem in MYSQL_BIN_LOG::purge_logs_maximum_number() when
  some files cannot be purged when in use, e.g. when there's a slave
  reading that log file. It looks like in this case we will be spinning
  in a tight loop *and* holding the LOCK_index mutex *and* incrementing
  current_number_of_logs, so it will also be an infinite loop.

- I wonder if we really need that "do while()" loop?

- Please fix formatting in purge_logs_maximum_number(). I know it's
  mostly copy-pasted code, but fixing it is just "C-M-h C-M-\"

- Please don't follow a bad example established previously with adding
  variables to all_vars.result. Let's have max_binlog_files_basic.test
  instead. The test case says there should no variable names in
  all_vars.result, and the upstream server has none.

review: Needs Fixing
Revision history for this message
Alexey Kopytov (akopytov) wrote : Posted in a previous version of this proposal

Forgot to mention that the comment header in the .test file should be fixed too (copy-paste from another test).

Revision history for this message
Stewart Smith (stewart) wrote : Posted in a previous version of this proposal

http://jenkins.percona.com/job/percona-server-5.5-param/452/

(just set a sensible limit on max number of binlog files)

Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote : Posted in a previous version of this proposal

    --force-restart in percona_binlog_max_nr-master.opt is an MTR
    option, not mysqld one, so it should be removed.

    Please add a newline to that file.

    What does "FN_DYNVARS_072_01" mean in max_binlog_files_basic.test?

    while(find_next_log(&log_info, 0) == false) missing space after
    while and am not sure "== false" is the way to write it: there is
    an "if (find_next_log(&log_info, 0))" below.

    Use MYSQL_BIN_LOG::lock_index and unlock_index instead of directly
    touching the LOCK_index.

    Rev 253 and diff lines 579--580, is that a separate bug fixed?
    Maybe it needs an LP bug for it?

review: Needs Fixing
Revision history for this message
Stewart Smith (stewart) wrote : Posted in a previous version of this proposal

> --force-restart in percona_binlog_max_nr-master.opt is an MTR
> option, not mysqld one, so it should be removed.

fixed

> Please add a newline to that file.

fixed

> What does "FN_DYNVARS_072_01" mean in max_binlog_files_basic.test?

This is just copied from max_binlog_size test

> while(find_next_log(&log_info, 0) == false) missing space after
> while and am not sure "== false" is the way to write it: there is
> an "if (find_next_log(&log_info, 0))" below.

fixed

> Use MYSQL_BIN_LOG::lock_index and unlock_index instead of directly
> touching the LOCK_index.

none of the existing code uses this

> Rev 253 and diff lines 579--580, is that a separate bug fixed?
> Maybe it needs an LP bug for it?

possibly should...

Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

> > Rev 253 and diff lines 579--580, is that a separate bug fixed?
> > Maybe it needs an LP bug for it?

> possibly should...

So this is presumably bug 1036040? Then I have to ask all the boring questions about it: 1) does it apply to 5.1; 2) is there a testcase? (it's OK if it's percona_binlog_max_nr).

review: Needs Information
Revision history for this message
Stewart Smith (stewart) wrote :

> > > Rev 253 and diff lines 579--580, is that a separate bug fixed?
> > > Maybe it needs an LP bug for it?
>
> > possibly should...
>
> So this is presumably bug 1036040? Then I have to ask all the boring questions
> about it: 1) does it apply to 5.1; 2) is there a testcase? (it's OK if it's
> percona_binlog_max_nr).

1) no.

2) IIRC this was by code inspection and comparison to equiv mariadb code. Actual test case was pretty tricky IIRC.

Revision history for this message
Laurynas Biveinis (laurynas-biveinis) :
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 2012-08-07 06:10:00 +0000
3+++ Percona-Server/mysql-test/r/mysqld--help-notwin.result 2012-08-13 05:37:06 +0000
4@@ -321,6 +321,11 @@
5 --max-binlog-dump-events=#
6 Option used by mysql-test for debugging and testing of
7 replication.
8+ --max-binlog-files=#
9+ Maximum number of binlog files. Used with
10+ --max-binlog-size this can be used to limit the total
11+ amount of disk space used for the binlog. Default is 0,
12+ don't limit.
13 --max-binlog-size=# Binary log will be rotated automatically when the size
14 exceeds this value. Will also apply to relay logs if
15 max_relay_log_size is 0
16@@ -913,6 +918,7 @@
17 max-allowed-packet 1048576
18 max-binlog-cache-size 18446744073709547520
19 max-binlog-dump-events 0
20+max-binlog-files 0
21 max-binlog-size 1073741824
22 max-binlog-stmt-cache-size 18446744073709547520
23 max-connect-errors 10
24
25=== modified file 'Percona-Server/mysql-test/r/mysqld--help-win.result'
26--- Percona-Server/mysql-test/r/mysqld--help-win.result 2012-08-07 06:10:00 +0000
27+++ Percona-Server/mysql-test/r/mysqld--help-win.result 2012-08-13 05:37:06 +0000
28@@ -294,6 +294,11 @@
29 --max-binlog-dump-events=#
30 Option used by mysql-test for debugging and testing of
31 replication.
32+ --max-binlog-files=#
33+ Maximum number of binlog files. Used with
34+ --max-binlog-size this can be used to limit the total
35+ amount of disk space used for the binlog. Default is 0,
36+ don't limit.
37 --max-binlog-size=# Binary log will be rotated automatically when the size
38 exceeds this value. Will also apply to relay logs if
39 max_relay_log_size is 0
40@@ -857,6 +862,7 @@
41 max-allowed-packet 1048576
42 max-binlog-cache-size 18446744073709547520
43 max-binlog-dump-events 0
44+max-binlog-files 0
45 max-binlog-size 1073741824
46 max-binlog-stmt-cache-size 18446744073709547520
47 max-connect-errors 10
48
49=== modified file 'Percona-Server/mysql-test/r/percona_server_variables_debug.result'
50--- Percona-Server/mysql-test/r/percona_server_variables_debug.result 2012-08-09 06:49:56 +0000
51+++ Percona-Server/mysql-test/r/percona_server_variables_debug.result 2012-08-13 05:37:06 +0000
52@@ -214,6 +214,7 @@
53 LOW_PRIORITY_UPDATES
54 MAX_ALLOWED_PACKET
55 MAX_BINLOG_CACHE_SIZE
56+MAX_BINLOG_FILES
57 MAX_BINLOG_SIZE
58 MAX_BINLOG_STMT_CACHE_SIZE
59 MAX_CONNECTIONS
60
61=== modified file 'Percona-Server/mysql-test/r/percona_server_variables_release.result'
62--- Percona-Server/mysql-test/r/percona_server_variables_release.result 2012-08-07 06:10:00 +0000
63+++ Percona-Server/mysql-test/r/percona_server_variables_release.result 2012-08-13 05:37:06 +0000
64@@ -209,6 +209,7 @@
65 LOW_PRIORITY_UPDATES
66 MAX_ALLOWED_PACKET
67 MAX_BINLOG_CACHE_SIZE
68+MAX_BINLOG_FILES
69 MAX_BINLOG_SIZE
70 MAX_BINLOG_STMT_CACHE_SIZE
71 MAX_CONNECTIONS
72
73=== added file 'Percona-Server/mysql-test/suite/binlog/r/percona_binlog_max_nr.result'
74--- Percona-Server/mysql-test/suite/binlog/r/percona_binlog_max_nr.result 1970-01-01 00:00:00 +0000
75+++ Percona-Server/mysql-test/suite/binlog/r/percona_binlog_max_nr.result 2012-08-13 05:37:06 +0000
76@@ -0,0 +1,30 @@
77+RESET MASTER;
78+##############################################################
79+testing purge binary logs to max number on explicit FLUSH LOGS
80+##############################################################
81+show binary logs;
82+Log_name File_size
83+master-bin.000001 #
84+CREATE TABLE t1 (a int primary key auto_increment, b blob);
85+flush logs;
86+show binary logs;
87+Log_name File_size
88+master-bin.000006 #
89+master-bin.000007 #
90+DROP TABLE t1;
91+reset master;
92+##############################################################
93+testing purge binary logs to max number on implicit flush
94+i.e. when starting new file
95+##############################################################
96+show binary logs;
97+Log_name File_size
98+master-bin.000001 #
99+CREATE TABLE t1 (a int primary key auto_increment, b blob);
100+show binary logs;
101+Log_name File_size
102+master-bin.000005 #
103+master-bin.000006 #
104+DROP TABLE t1;
105+reset master;
106+End of tests
107
108=== added file 'Percona-Server/mysql-test/suite/binlog/t/percona_binlog_max_nr-master.opt'
109--- Percona-Server/mysql-test/suite/binlog/t/percona_binlog_max_nr-master.opt 1970-01-01 00:00:00 +0000
110+++ Percona-Server/mysql-test/suite/binlog/t/percona_binlog_max_nr-master.opt 2012-08-13 05:37:06 +0000
111@@ -0,0 +1,2 @@
112+--max-binlog-size=4096 --max-binlog-files=2
113+
114
115=== added file 'Percona-Server/mysql-test/suite/binlog/t/percona_binlog_max_nr.test'
116--- Percona-Server/mysql-test/suite/binlog/t/percona_binlog_max_nr.test 1970-01-01 00:00:00 +0000
117+++ Percona-Server/mysql-test/suite/binlog/t/percona_binlog_max_nr.test 2012-08-13 05:37:06 +0000
118@@ -0,0 +1,60 @@
119+source include/have_log_bin.inc;
120+source include/not_embedded.inc;
121+
122+RESET MASTER;
123+
124+let $MYSQLD_DATADIR= `select @@datadir`;
125+let $INDEX=$MYSQLD_DATADIR/master-bin.index;
126+
127+--echo ##############################################################
128+--echo testing purge binary logs to max number on explicit FLUSH LOGS
129+--echo ##############################################################
130+
131+source include/show_binary_logs.inc;
132+file_exists $MYSQLD_DATADIR/master-bin.000001;
133+
134+CREATE TABLE t1 (a int primary key auto_increment, b blob);
135+--disable_query_log
136+let $c=20;
137+begin;
138+while ($c)
139+{
140+ eval INSERT INTO t1 (b) values ('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789');
141+ dec $c;
142+}
143+commit;
144+--enable_query_log
145+
146+flush logs;
147+source include/show_binary_logs.inc;
148+
149+DROP TABLE t1;
150+
151+reset master;
152+
153+--echo ##############################################################
154+--echo testing purge binary logs to max number on implicit flush
155+--echo i.e. when starting new file
156+--echo ##############################################################
157+
158+source include/show_binary_logs.inc;
159+file_exists $MYSQLD_DATADIR/master-bin.000001;
160+
161+CREATE TABLE t1 (a int primary key auto_increment, b blob);
162+--disable_query_log
163+let $c=20;
164+begin;
165+while ($c)
166+{
167+ eval INSERT INTO t1 (b) values ('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789'),('0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789');
168+ dec $c;
169+}
170+commit;
171+--enable_query_log
172+
173+source include/show_binary_logs.inc;
174+DROP TABLE t1;
175+
176+reset master;
177+
178+--echo End of tests
179
180=== added file 'Percona-Server/mysql-test/suite/sys_vars/r/max_binlog_files_basic.result'
181--- Percona-Server/mysql-test/suite/sys_vars/r/max_binlog_files_basic.result 1970-01-01 00:00:00 +0000
182+++ Percona-Server/mysql-test/suite/sys_vars/r/max_binlog_files_basic.result 2012-08-13 05:37:06 +0000
183@@ -0,0 +1,134 @@
184+SET @start_value = @@global.max_binlog_files;
185+SELECT @start_value;
186+@start_value
187+0
188+'#--------------------FN_DYNVARS_072_01------------------------#'
189+SET @@global.max_binlog_files = 5000;
190+SET @@global.max_binlog_files = DEFAULT;
191+SELECT @@global.max_binlog_files;
192+@@global.max_binlog_files
193+0
194+'#---------------------FN_DYNVARS_072_02-------------------------#'
195+SET @@global.max_binlog_files = @start_value;
196+SELECT @@global.max_binlog_files = 0;
197+@@global.max_binlog_files = 0
198+1
199+'#--------------------FN_DYNVARS_072_03------------------------#'
200+SET @@global.max_binlog_files = 4;
201+SELECT @@global.max_binlog_files;
202+@@global.max_binlog_files
203+4
204+SET @@global.max_binlog_files = 10;
205+SELECT @@global.max_binlog_files;
206+@@global.max_binlog_files
207+10
208+SET @@global.max_binlog_files = 10;
209+SELECT @@global.max_binlog_files;
210+@@global.max_binlog_files
211+10
212+SET @@global.max_binlog_files = 40;
213+SELECT @@global.max_binlog_files;
214+@@global.max_binlog_files
215+40
216+SET @@global.max_binlog_files = 65;
217+SELECT @@global.max_binlog_files;
218+@@global.max_binlog_files
219+65
220+'#--------------------FN_DYNVARS_072_04-------------------------#'
221+SET @@global.max_binlog_files = -1;
222+Warnings:
223+Warning 1292 Truncated incorrect max_binlog_files value: '-1'
224+SELECT @@global.max_binlog_files;
225+@@global.max_binlog_files
226+0
227+SET @@global.max_binlog_files = 100000000000;
228+Warnings:
229+Warning 1292 Truncated incorrect max_binlog_files value: '100000000000'
230+SELECT @@global.max_binlog_files;
231+@@global.max_binlog_files
232+102400
233+SET @@global.max_binlog_files = 10000.01;
234+ERROR 42000: Incorrect argument type to variable 'max_binlog_files'
235+SELECT @@global.max_binlog_files;
236+@@global.max_binlog_files
237+102400
238+SET @@global.max_binlog_files = -1024;
239+Warnings:
240+Warning 1292 Truncated incorrect max_binlog_files value: '-1024'
241+SELECT @@global.max_binlog_files;
242+@@global.max_binlog_files
243+0
244+SET @@global.max_binlog_files = 1024;
245+SELECT @@global.max_binlog_files;
246+@@global.max_binlog_files
247+1024
248+SET @@global.max_binlog_files = 4294967296;
249+Warnings:
250+Warning 1292 Truncated incorrect max_binlog_files value: '4294967296'
251+SELECT @@global.max_binlog_files;
252+@@global.max_binlog_files
253+102400
254+SET @@global.max_binlog_files = 4095;
255+SELECT @@global.max_binlog_files;
256+@@global.max_binlog_files
257+4095
258+SET @@global.max_binlog_files = ON;
259+ERROR 42000: Incorrect argument type to variable 'max_binlog_files'
260+SELECT @@global.max_binlog_files;
261+@@global.max_binlog_files
262+4095
263+SET @@global.max_binlog_files = 'test';
264+ERROR 42000: Incorrect argument type to variable 'max_binlog_files'
265+SELECT @@global.max_binlog_files;
266+@@global.max_binlog_files
267+4095
268+'#-------------------FN_DYNVARS_072_05----------------------------#'
269+SET @@session.max_binlog_files = 4096;
270+ERROR HY000: Variable 'max_binlog_files' is a GLOBAL variable and should be set with SET GLOBAL
271+SELECT @@session.max_binlog_files;
272+ERROR HY000: Variable 'max_binlog_files' is a GLOBAL variable
273+'#----------------------FN_DYNVARS_072_06------------------------#'
274+SELECT @@global.max_binlog_files = VARIABLE_VALUE
275+FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
276+WHERE VARIABLE_NAME='max_binlog_files';
277+@@global.max_binlog_files = VARIABLE_VALUE
278+1
279+SELECT @@max_binlog_files = VARIABLE_VALUE
280+FROM INFORMATION_SCHEMA.SESSION_VARIABLES
281+WHERE VARIABLE_NAME='max_binlog_files';
282+@@max_binlog_files = VARIABLE_VALUE
283+1
284+'#---------------------FN_DYNVARS_072_07----------------------#'
285+SET @@global.max_binlog_files = TRUE;
286+SELECT @@global.max_binlog_files;
287+@@global.max_binlog_files
288+1
289+SET @@global.max_binlog_files = FALSE;
290+SELECT @@global.max_binlog_files;
291+@@global.max_binlog_files
292+0
293+'#---------------------FN_DYNVARS_072_08----------------------#'
294+SET @@global.max_binlog_files = 5000;
295+SELECT @@max_binlog_files = @@global.max_binlog_files;
296+@@max_binlog_files = @@global.max_binlog_files
297+1
298+'#---------------------FN_DYNVARS_072_09----------------------#'
299+SET max_binlog_files = 6000;
300+ERROR HY000: Variable 'max_binlog_files' is a GLOBAL variable and should be set with SET GLOBAL
301+SELECT @@max_binlog_files;
302+@@max_binlog_files
303+5000
304+SET local.max_binlog_files = 7000;
305+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'max_binlog_files = 7000' at line 1
306+SELECT local.max_binlog_files;
307+ERROR 42S02: Unknown table 'local' in field list
308+SET global.max_binlog_files = 8000;
309+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'max_binlog_files = 8000' at line 1
310+SELECT global.max_binlog_files;
311+ERROR 42S02: Unknown table 'global' in field list
312+SELECT max_binlog_files = @@session.max_binlog_files;
313+ERROR 42S22: Unknown column 'max_binlog_files' in 'field list'
314+SET @@global.max_binlog_files = @start_value;
315+SELECT @@global.max_binlog_files;
316+@@global.max_binlog_files
317+0
318
319=== added file 'Percona-Server/mysql-test/suite/sys_vars/t/max_binlog_files_basic.test'
320--- Percona-Server/mysql-test/suite/sys_vars/t/max_binlog_files_basic.test 1970-01-01 00:00:00 +0000
321+++ Percona-Server/mysql-test/suite/sys_vars/t/max_binlog_files_basic.test 2012-08-13 05:37:06 +0000
322@@ -0,0 +1,147 @@
323+--source include/load_sysvars.inc
324+#test max-binlog-files, mostly copied from max_binlog_files test
325+
326+SET @start_value = @@global.max_binlog_files;
327+SELECT @start_value;
328+
329+
330+--echo '#--------------------FN_DYNVARS_072_01------------------------#'
331+##################################################################
332+# Display the DEFAULT value of max_binlog_files #
333+##################################################################
334+
335+SET @@global.max_binlog_files = 5000;
336+SET @@global.max_binlog_files = DEFAULT;
337+SELECT @@global.max_binlog_files;
338+
339+--echo '#---------------------FN_DYNVARS_072_02-------------------------#'
340+###############################################
341+# Verify default value of variable #
342+###############################################
343+
344+SET @@global.max_binlog_files = @start_value;
345+SELECT @@global.max_binlog_files = 0;
346+
347+--echo '#--------------------FN_DYNVARS_072_03------------------------#'
348+##################################################################
349+# Change the value of max_binlog_files to a valid value #
350+##################################################################
351+
352+SET @@global.max_binlog_files = 4;
353+SELECT @@global.max_binlog_files;
354+SET @@global.max_binlog_files = 10;
355+SELECT @@global.max_binlog_files;
356+SET @@global.max_binlog_files = 10;
357+SELECT @@global.max_binlog_files;
358+SET @@global.max_binlog_files = 40;
359+SELECT @@global.max_binlog_files;
360+SET @@global.max_binlog_files = 65;
361+SELECT @@global.max_binlog_files;
362+
363+
364+--echo '#--------------------FN_DYNVARS_072_04-------------------------#'
365+#####################################################################
366+# Change the value of max_binlog_files to invalid value #
367+#####################################################################
368+
369+SET @@global.max_binlog_files = -1;
370+SELECT @@global.max_binlog_files;
371+SET @@global.max_binlog_files = 100000000000;
372+SELECT @@global.max_binlog_files;
373+--Error ER_WRONG_TYPE_FOR_VAR
374+SET @@global.max_binlog_files = 10000.01;
375+SELECT @@global.max_binlog_files;
376+SET @@global.max_binlog_files = -1024;
377+SELECT @@global.max_binlog_files;
378+SET @@global.max_binlog_files = 1024;
379+SELECT @@global.max_binlog_files;
380+SET @@global.max_binlog_files = 4294967296;
381+SELECT @@global.max_binlog_files;
382+SET @@global.max_binlog_files = 4095;
383+SELECT @@global.max_binlog_files;
384+
385+--Error ER_WRONG_TYPE_FOR_VAR
386+SET @@global.max_binlog_files = ON;
387+SELECT @@global.max_binlog_files;
388+--Error ER_WRONG_TYPE_FOR_VAR
389+SET @@global.max_binlog_files = 'test';
390+SELECT @@global.max_binlog_files;
391+
392+
393+--echo '#-------------------FN_DYNVARS_072_05----------------------------#'
394+#####################################################################
395+# Test if accessing session max_binlog_files gives error #
396+#####################################################################
397+
398+--Error ER_GLOBAL_VARIABLE
399+SET @@session.max_binlog_files = 4096;
400+--Error ER_INCORRECT_GLOBAL_LOCAL_VAR
401+SELECT @@session.max_binlog_files;
402+
403+
404+--echo '#----------------------FN_DYNVARS_072_06------------------------#'
405+##############################################################################
406+# Check if the value in GLOBAL & SESSION Tables matches values in variable #
407+##############################################################################
408+
409+SELECT @@global.max_binlog_files = VARIABLE_VALUE
410+FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
411+WHERE VARIABLE_NAME='max_binlog_files';
412+
413+SELECT @@max_binlog_files = VARIABLE_VALUE
414+FROM INFORMATION_SCHEMA.SESSION_VARIABLES
415+WHERE VARIABLE_NAME='max_binlog_files';
416+
417+
418+--echo '#---------------------FN_DYNVARS_072_07----------------------#'
419+###################################################################
420+# Check if TRUE and FALSE values can be used on variable #
421+###################################################################
422+
423+SET @@global.max_binlog_files = TRUE;
424+SELECT @@global.max_binlog_files;
425+SET @@global.max_binlog_files = FALSE;
426+SELECT @@global.max_binlog_files;
427+
428+
429+--echo '#---------------------FN_DYNVARS_072_08----------------------#'
430+########################################################################################################
431+# Check if accessing variable with SESSION,LOCAL and without SCOPE points to same session variable #
432+########################################################################################################
433+
434+SET @@global.max_binlog_files = 5000;
435+SELECT @@max_binlog_files = @@global.max_binlog_files;
436+
437+
438+--echo '#---------------------FN_DYNVARS_072_09----------------------#'
439+##########################################################################
440+# Check if max_binlog_files can be accessed with and without @@ sign #
441+##########################################################################
442+
443+--Error ER_GLOBAL_VARIABLE
444+SET max_binlog_files = 6000;
445+SELECT @@max_binlog_files;
446+--Error ER_PARSE_ERROR
447+SET local.max_binlog_files = 7000;
448+--Error ER_UNKNOWN_TABLE
449+SELECT local.max_binlog_files;
450+--Error ER_PARSE_ERROR
451+SET global.max_binlog_files = 8000;
452+--Error ER_UNKNOWN_TABLE
453+SELECT global.max_binlog_files;
454+--Error ER_BAD_FIELD_ERROR
455+SELECT max_binlog_files = @@session.max_binlog_files;
456+
457+
458+##############################
459+# Restore initial value #
460+##############################
461+
462+SET @@global.max_binlog_files = @start_value;
463+SELECT @@global.max_binlog_files;
464+
465+
466+##################################################################
467+# END OF max_binlog_files TESTS #
468+##################################################################
469+
470
471=== modified file 'Percona-Server/sql/log.cc'
472--- Percona-Server/sql/log.cc 2012-08-07 06:10:00 +0000
473+++ Percona-Server/sql/log.cc 2012-08-13 05:37:06 +0000
474@@ -1,4 +1,5 @@
475 /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
476+ Copyright (C) 2012 Percona Inc.
477
478 This program is free software; you can redistribute it and/or modify
479 it under the terms of the GNU General Public License as published by
480@@ -59,6 +60,8 @@
481
482 LOGGER logger;
483
484+ulong max_binlog_files;
485+
486 MYSQL_BIN_LOG mysql_bin_log(&sync_binlog_period);
487
488 static bool test_if_number(const char *str,
489@@ -4139,6 +4142,74 @@
490 }
491
492 /**
493+ Purge old logs so that we have a maximum of max_nr_files logs.
494+
495+ @param max_nr_files Maximum number of logfiles to have
496+
497+ @note
498+ If any of the logs before the deleted one is in use,
499+ only purge logs up to this one.
500+
501+ @retval
502+ 0 ok
503+ @retval
504+ LOG_INFO_PURGE_NO_ROTATE Binary file that can't be rotated
505+ LOG_INFO_FATAL if any other than ENOENT error from
506+ mysql_file_stat() or mysql_file_delete()
507+*/
508+
509+int MYSQL_BIN_LOG::purge_logs_maximum_number(ulong max_nr_files)
510+{
511+ int error;
512+ char to_log[FN_REFLEN];
513+ LOG_INFO log_info;
514+ ulong current_number_of_logs= 1;
515+
516+ DBUG_ENTER("purge_logs_maximum_number");
517+
518+ mysql_mutex_lock(&LOCK_index);
519+ to_log[0]= 0;
520+
521+ if ((error=find_log_pos(&log_info, NullS, 0 /*no mutex*/)))
522+ goto err;
523+
524+ while (!find_next_log(&log_info, 0))
525+ current_number_of_logs++;
526+
527+ if (current_number_of_logs <= max_nr_files)
528+ {
529+ error= 0;
530+ goto err; /* No logs to expire */
531+ }
532+
533+ if ((error=find_log_pos(&log_info, NullS, 0 /*no mutex*/)))
534+ goto err;
535+
536+ while (strcmp(log_file_name, log_info.log_file_name) &&
537+ !is_active(log_info.log_file_name) &&
538+ !log_in_use(log_info.log_file_name) &&
539+ current_number_of_logs > max_nr_files)
540+ {
541+ current_number_of_logs--;
542+ strmake(to_log,
543+ log_info.log_file_name,
544+ sizeof(log_info.log_file_name) - 1);
545+
546+ if (find_next_log(&log_info, 0))
547+ {
548+ break;
549+ }
550+ }
551+
552+ error= (to_log[0] ? purge_logs(to_log, 1, 0, 1, (ulonglong *) 0) : 0);
553+
554+err:
555+ mysql_mutex_unlock(&LOCK_index);
556+ DBUG_RETURN(error);
557+}
558+
559+
560+/**
561 Remove all logs before the given file date from disk and from the
562 index file.
563
564@@ -5315,6 +5386,10 @@
565 purge_logs_before_date(purge_time);
566 }
567 }
568+ if (max_binlog_files)
569+ {
570+ purge_logs_maximum_number(max_binlog_files);
571+ }
572 #endif
573 }
574
575@@ -5833,7 +5908,7 @@
576
577 mysql_mutex_unlock(&LOCK_log);
578
579- if (xid_count > 0 && check_purge)
580+ if (xid_count == 0 && check_purge)
581 {
582 purge();
583 }
584
585=== modified file 'Percona-Server/sql/log.h'
586--- Percona-Server/sql/log.h 2012-08-07 06:10:00 +0000
587+++ Percona-Server/sql/log.h 2012-08-13 05:37:06 +0000
588@@ -569,6 +569,7 @@
589 int purge_logs(const char *to_log, bool included,
590 bool need_mutex, bool need_update_threads,
591 ulonglong *decrease_log_space);
592+ int purge_logs_maximum_number(ulong max_nr_files);
593 int purge_logs_before_date(time_t purge_time);
594 int purge_first_log(Relay_log_info* rli, bool included);
595 int set_purge_index_file_name(const char *base_file_name);
596
597=== modified file 'Percona-Server/sql/mysqld.cc'
598--- Percona-Server/sql/mysqld.cc 2012-08-07 06:10:00 +0000
599+++ Percona-Server/sql/mysqld.cc 2012-08-13 05:37:06 +0000
600@@ -4151,6 +4151,10 @@
601 if (purge_time >= 0)
602 mysql_bin_log.purge_logs_before_date(purge_time);
603 }
604+ if (opt_bin_log && max_binlog_files)
605+ {
606+ mysql_bin_log.purge_logs_maximum_number(max_binlog_files);
607+ }
608 #endif
609
610 if (opt_myisam_log)
611
612=== modified file 'Percona-Server/sql/mysqld.h'
613--- Percona-Server/sql/mysqld.h 2012-08-07 06:10:00 +0000
614+++ Percona-Server/sql/mysqld.h 2012-08-13 05:37:06 +0000
615@@ -142,6 +142,7 @@
616 extern ulong max_long_data_size;
617 extern ulong current_pid;
618 extern ulong expire_logs_days;
619+extern ulong max_binlog_files;
620 extern my_bool relay_log_recovery;
621 extern uint sync_binlog_period, sync_relaylog_period,
622 sync_relayloginfo_period, sync_masterinfo_period;
623
624=== modified file 'Percona-Server/sql/sys_vars.cc'
625--- Percona-Server/sql/sys_vars.cc 2012-08-07 06:10:00 +0000
626+++ Percona-Server/sql/sys_vars.cc 2012-08-13 05:37:06 +0000
627@@ -799,6 +799,14 @@
628 GLOBAL_VAR(expire_logs_days),
629 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 99), DEFAULT(0), BLOCK_SIZE(1));
630
631+static Sys_var_ulong Sys_max_binlog_files(
632+ "max_binlog_files",
633+ "Maximum number of binlog files. Used with --max-binlog-size this can "
634+ "be used to limit the total amount of disk space used for the binlog. "
635+ "Default is 0, don't limit.",
636+ GLOBAL_VAR(max_binlog_files),
637+ CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 102400), DEFAULT(0), BLOCK_SIZE(1));
638+
639 static Sys_var_mybool Sys_flush(
640 "flush", "Flush MyISAM tables to disk between SQL commands",
641 GLOBAL_VAR(myisam_flush),

Subscribers

People subscribed via source and target branches