Skip to content

Commit 19719d6

Browse files
committed
MDEV-38849 slave_connections_needed_for_purge prevents independent machine from purging binary logs
`@@slave_connections_needed_for_purge`’s default of `1` ensures binary log availability on replication masters, but is not a sensible default suitable for all scenarios, especially for long-term slave servers and standalone (not in a replication setup) servers. The outcome was that standalone server users were confused why automatic binlog purging does not work. This commit changes this default to `0`, which is suitable for both standalone and (when backed by prompt failure recovery) replication setups. `0` also more closely matches the behaviour before MDEV-31404, which added this variable, out of the box. This commit also adds a one-time replication warning when registering a slave, but `@@slave_connections_needed_for_purge` is left unchanged. Rather than enforcing a defence with an unsensible default, this reminder will bring awareness of the risk of automatic binlog purging. This commit also cleans up Galera and MTR workarounds to the introduction of the `@@slave_connections_needed_for_purge=1` default.
1 parent b51d2f1 commit 19719d6

16 files changed

Lines changed: 121 additions & 36 deletions

‎mysql-test/include/mtr_warnings.sql‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ INSERT INTO global_suppressions VALUES
148148
("Slave: .*Duplicate entry"),
149149

150150
("Statement may not be safe to log in statement format"),
151+
("slave_connections_needed_for_purge"),
151152

152153
/* innodb foreign key tests that fail in ALTER or RENAME produce this */
153154
("InnoDB: Error: in ALTER TABLE `test`.`t[123]`"),

‎mysql-test/main/mysqld--help.result‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,6 @@ The following specify which files/extra groups are read (specified before remain
13211321
Minimum number of connected slaves required for automatic
13221322
binary log purge with max_binlog_total_size,
13231323
binlog_expire_logs_seconds or binlog_expire_logs_days.
1324-
Default is 0 when Galera is enabled and 1 otherwise.
13251324
--slave-ddl-exec-mode=name
13261325
How replication events should be executed. Legal values
13271326
are STRICT and IDEMPOTENT (default). In IDEMPOTENT mode,
@@ -1955,7 +1954,7 @@ skip-networking FALSE
19551954
skip-show-database FALSE
19561955
skip-slave-start FALSE
19571956
slave-compressed-protocol FALSE
1958-
slave-connections-needed-for-purge 1
1957+
slave-connections-needed-for-purge 0
19591958
slave-ddl-exec-mode IDEMPOTENT
19601959
slave-domain-parallel-threads 0
19611960
slave-exec-mode STRICT

‎mysql-test/suite/binlog/my.cnf‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎mysql-test/suite/binlog_encryption/binlog_index-master.opt‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎mysql-test/suite/galera/r/basic.result‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
connection node_2;
22
connection node_1;
3-
select @@slave_connections_needed_for_purge;
4-
@@slave_connections_needed_for_purge
5-
0
6-
select VARIABLE_NAME, GLOBAL_VALUE, GLOBAL_VALUE_ORIGIN from information_schema.system_variables where variable_name="slave_connections_needed_for_purge";
7-
VARIABLE_NAME GLOBAL_VALUE GLOBAL_VALUE_ORIGIN
8-
SLAVE_CONNECTIONS_NEEDED_FOR_PURGE 0 AUTO
93
USE test;
104
CREATE TABLE t1(c1 INT PRIMARY KEY) ENGINE=INNODB;
115
INSERT INTO t1 VALUES (1), (2), (3), (4), (5);

‎mysql-test/suite/galera/t/basic.test‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
--source include/galera_cluster.inc
22
--source include/have_innodb.inc
33

4-
select @@slave_connections_needed_for_purge;
5-
select VARIABLE_NAME, GLOBAL_VALUE, GLOBAL_VALUE_ORIGIN from information_schema.system_variables where variable_name="slave_connections_needed_for_purge";
6-
74
USE test;
85
CREATE TABLE t1(c1 INT PRIMARY KEY) ENGINE=INNODB;
96
INSERT INTO t1 VALUES (1), (2), (3), (4), (5);

‎mysql-test/suite/rpl/my.cnf‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@
66
# E.g. after !include ../my.cnf, in your `test.cnf`, specify your configuration
77
# in option group e.g [mysqld.x], so that number `x` corresponds to the number
88
# in the rpl server topology.
9-
[mariadbd]
10-
slave_connections_needed_for_purge=0
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
include/master-slave.inc
2+
[connection master]
3+
NOT FOUND /slave_connections_needed_for_purge/ in mysqld.1.err
4+
connection slave;
5+
START SLAVE IO_THREAD;
6+
include/wait_for_slave_io_to_start.inc
7+
FOUND 1 /slave_connections_needed_for_purge/ in mysqld.1.err
8+
include/stop_slave_io.inc
9+
START SLAVE IO_THREAD;
10+
include/wait_for_slave_io_to_start.inc
11+
include/stop_slave_io.inc
12+
include/rpl_restart_server.inc [server_number=1 parameters: --slave-connections-needed-for-purge 0]
13+
connection slave;
14+
START SLAVE IO_THREAD;
15+
include/wait_for_slave_io_to_start.inc
16+
include/stop_slave_io.inc
17+
include/rpl_restart_server.inc [server_number=1]
18+
connection master;
19+
SET @@GLOBAL.slave_connections_needed_for_purge= DEFAULT;
20+
connection slave;
21+
START SLAVE IO_THREAD;
22+
include/wait_for_slave_io_to_start.inc
23+
connection master;
24+
FOUND 1 /slave_connections_needed_for_purge/ in mysqld.1.err
25+
include/rpl_end.inc
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# MDEV-38849: Test the warning that the _default_ for
2+
# `@@slave_connections_needed_for_purge` does not match the replication setup.
3+
# (Do _not_ warn if `@@slave_connections_needed_for_purge` is manually set.)
4+
5+
--source include/have_binlog_format_mixed.inc # no actual binlog content
6+
--let $rpl_skip_start_slave= 1
7+
--source include/master-slave.inc
8+
9+
10+
--let SEARCH_FILE= `SELECT @@log_error`
11+
--let SEARCH_PATTERN= slave_connections_needed_for_purge
12+
# Not connected: should not warn
13+
--source include/search_pattern_in_file.inc
14+
15+
16+
--connection slave
17+
START SLAVE IO_THREAD;
18+
--source include/wait_for_slave_io_to_start.inc
19+
# Connected when left as default: should warn
20+
--source include/search_pattern_in_file.inc
21+
22+
23+
--source include/stop_slave_io.inc
24+
START SLAVE IO_THREAD;
25+
--source include/wait_for_slave_io_to_start.inc
26+
# Reconnected: should not warn a second time
27+
28+
--source include/stop_slave_io.inc
29+
--let $rpl_server_parameters= --slave-connections-needed-for-purge 0
30+
--let $rpl_server_number= 1
31+
--source include/rpl_restart_server.inc
32+
--connection slave
33+
START SLAVE IO_THREAD;
34+
--source include/wait_for_slave_io_to_start.inc
35+
# Explicitly set to 0 in server options: should not warn
36+
37+
--source include/stop_slave_io.inc
38+
--let $rpl_server_parameters=
39+
--source include/rpl_restart_server.inc
40+
--connection master
41+
SET @@GLOBAL.slave_connections_needed_for_purge= DEFAULT;
42+
--connection slave
43+
START SLAVE IO_THREAD;
44+
--source include/wait_for_slave_io_to_start.inc
45+
# Explicitly set to DEFAULT in system variables: should _not_ warn
46+
47+
--connection master
48+
--source include/search_pattern_in_file.inc
49+
50+
51+
--let $rpl_only_running_threads= 1
52+
--source include/rpl_end.inc

‎mysql-test/suite/sys_vars/r/sysvars_server_embedded.result‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3465,7 +3465,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL
34653465
VARIABLE_NAME SLAVE_CONNECTIONS_NEEDED_FOR_PURGE
34663466
VARIABLE_SCOPE GLOBAL
34673467
VARIABLE_TYPE INT UNSIGNED
3468-
VARIABLE_COMMENT Minimum number of connected slaves required for automatic binary log purge with max_binlog_total_size, binlog_expire_logs_seconds or binlog_expire_logs_days. Default is 0 when Galera is enabled and 1 otherwise.
3468+
VARIABLE_COMMENT Minimum number of connected slaves required for automatic binary log purge with max_binlog_total_size, binlog_expire_logs_seconds or binlog_expire_logs_days.
34693469
NUMERIC_MIN_VALUE 0
34703470
NUMERIC_MAX_VALUE 4294967295
34713471
NUMERIC_BLOCK_SIZE 1

0 commit comments

Comments
 (0)