mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-31404 Implement binlog_space_limit
binlog_space_limit is a variable in Percona server used to limit the total size of all binary logs. This implementation is based on code from Percona server 5.7. In MariaDB we decided to call the variable max-binlog-total-size to be similar to max-binlog-size. This makes it easier to find in the output from 'mariadbd --help --verbose'). MariaDB will also support binlog_space_limit for compatibility with Percona. Some internal notes to explain implementation notes: - When running MariaDB does not delete binary logs that are either used by slaves or have active xid that are not yet committed. Some implementation notes: - max-binlog-total-size is by default 0 (no limit). - max-binlog-total-size can be changed without server restart. - Binlog file sizes are checked on startup, or if max-binlog-total-size is set to a value > 0, not for every log write. The total size of all binary logs is cached and dynamically updated when updating the binary log on binary log rotation. - max-binlog-total-size is checked against existing log files during serverstart, binlog rotation, FLUSH LOGS, when writing to binary log or when max-binlog-total-size changes value. - Option --slave-connections-needed-for-purge with 1 as default added. This allows one to ensure that we do not delete binary logs if there is less than 'slave-connections-needed-for-purge' connected. Without this option max-binlog-total-size would potentially delete binlogs needed by slaves on server startup or when a slave disconnects as there are then no connected slaves to protect active binlogs. - PURGE BINARY LOGS TO ... will be executed as if slave-connectitons-needed-for-purge would be zero. In other words it will do the purge even if there is no slaves connected. If there are connected slaves working on the logs, these will be protected. - If binary log is on and max-binlog-total_size <> 0 then the status variable 'Binlog_disk_use' shows the current size of all old binary logs + the state of the current one. - Removed test of strcmp(log_file_name, log_info.log_file_name) in purge_logs_before_date() as this is tested in can_purge_logs() - To avoid expensive calls of log_in_use() we cache the result for the last log that is in use by a slave. Future calls to can_purge_logs() for this binary log will be quickly detected and false will be returned until a slave starts working on a new log. - Note that after a binary log rotation caused by max_binlog_size, the last log will not be purged directly as it is still in use internally. The next binary log write will purge binlogs if needed. Reviewer:Kristian Nielsen <knielsen@knielsen-hq.org>
This commit is contained in:
@@ -6,3 +6,5 @@
|
||||
# E.g. after !include ../my.cnf, in your `test.cnf`, specify your configuration
|
||||
# in option group e.g [mysqld.x], so that number `x` corresponds to the number
|
||||
# in the rpl server topology.
|
||||
[mariadbd]
|
||||
slave_connections_needed_for_purge=0
|
||||
|
49
mysql-test/suite/rpl/r/max_binlog_total_size.result
Normal file
49
mysql-test/suite/rpl/r/max_binlog_total_size.result
Normal file
@@ -0,0 +1,49 @@
|
||||
include/master-slave.inc
|
||||
[connection master]
|
||||
#
|
||||
# MDEV-31404 Implement binlog_space_limit
|
||||
#
|
||||
# Test that master is not deleting binary logs before slave has a
|
||||
# chance to digest them
|
||||
select @@global.max_binlog_total_size;
|
||||
@@global.max_binlog_total_size
|
||||
1500
|
||||
select @@global.max_binlog_size;
|
||||
@@global.max_binlog_size
|
||||
4096
|
||||
connection slave;
|
||||
STOP SLAVE IO_THREAD;
|
||||
include/wait_for_slave_io_to_stop.inc
|
||||
connection master;
|
||||
kill DUMP_THREAD;
|
||||
CREATE TABLE `t1` (
|
||||
`v1` int(11) DEFAULT NULL,
|
||||
`v2` varchar(8000) DEFAULT NULL,
|
||||
KEY `v1` (`v1`)
|
||||
);
|
||||
FLUSH LOGS;
|
||||
FLUSH LOGS;
|
||||
FLUSH LOGS;
|
||||
show binary logs;
|
||||
Log_name File_size
|
||||
binary.000001 #
|
||||
binary.000002 #
|
||||
binary.000003 #
|
||||
binary.000004 #
|
||||
INSERT INTO t1 VALUES (0,repeat("a",3000));
|
||||
show binary logs;
|
||||
Log_name File_size
|
||||
binary.000001 #
|
||||
binary.000002 #
|
||||
binary.000003 #
|
||||
binary.000004 #
|
||||
connection slave;
|
||||
START SLAVE IO_THREAD;
|
||||
connection master;
|
||||
connection slave;
|
||||
connection master;
|
||||
DROP TABLE t1;
|
||||
show binary logs;
|
||||
Log_name File_size
|
||||
binary.000004 #
|
||||
include/rpl_end.inc
|
5
mysql-test/suite/rpl/t/max_binlog_total_size-master.opt
Normal file
5
mysql-test/suite/rpl/t/max_binlog_total_size-master.opt
Normal file
@@ -0,0 +1,5 @@
|
||||
--log-bin=binary
|
||||
--max-binlog-total-size=1500
|
||||
--max-binlog-size=4096
|
||||
--binlog-format=row
|
||||
--slave_connections_needed_for_purge=1
|
58
mysql-test/suite/rpl/t/max_binlog_total_size.test
Normal file
58
mysql-test/suite/rpl/t/max_binlog_total_size.test
Normal file
@@ -0,0 +1,58 @@
|
||||
--source include/have_log_bin.inc
|
||||
--source include/master-slave.inc
|
||||
--source include/have_binlog_format_row.inc
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-31404 Implement binlog_space_limit
|
||||
--echo #
|
||||
|
||||
--echo # Test that master is not deleting binary logs before slave has a
|
||||
--echo # chance to digest them
|
||||
|
||||
select @@global.max_binlog_total_size;
|
||||
select @@global.max_binlog_size;
|
||||
|
||||
--connection slave
|
||||
STOP SLAVE IO_THREAD;
|
||||
--source include/wait_for_slave_io_to_stop.inc
|
||||
--connection master
|
||||
|
||||
# Kill the dump thread
|
||||
let $id=`SELECT id from information_schema.processlist where command='Binlog Dump'`;
|
||||
|
||||
if ($id)
|
||||
{
|
||||
replace_result $id DUMP_THREAD;
|
||||
eval kill $id;
|
||||
let $wait_condition= SELECT count(*)=0 from information_schema.processlist where command='Killed';
|
||||
source include/wait_condition.inc;
|
||||
}
|
||||
|
||||
CREATE TABLE `t1` (
|
||||
`v1` int(11) DEFAULT NULL,
|
||||
`v2` varchar(8000) DEFAULT NULL,
|
||||
KEY `v1` (`v1`)
|
||||
);
|
||||
|
||||
FLUSH LOGS;
|
||||
FLUSH LOGS;
|
||||
FLUSH LOGS;
|
||||
--source include/show_binary_logs.inc
|
||||
|
||||
INSERT INTO t1 VALUES (0,repeat("a",3000));
|
||||
--source include/show_binary_logs.inc
|
||||
|
||||
--connection slave
|
||||
START SLAVE IO_THREAD;
|
||||
--connection master
|
||||
|
||||
--sync_slave_with_master
|
||||
--connection master
|
||||
|
||||
# Slave is now connected. Next query should remove old binary logs.
|
||||
|
||||
DROP TABLE t1;
|
||||
--source include/show_binary_logs.inc
|
||||
|
||||
# End of 11.4 tests
|
||||
--source include/rpl_end.inc
|
Reference in New Issue
Block a user