1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-34504 PURGE BINARY LOGS not working anymore

PURGE BINARY LOGS did not always purge binary logs. This commit fixes
some of the issues and adds notifications if a binary log cannot be
purged.

User visible changes:
- 'PURGE BINARY LOG TO log_name' and 'PURGE BINARY LOGS BEFORE date'
  worked differently. 'TO' ignored 'slave_connections_needed_for_purge'
  while 'BEFORE' did not. Now both versions ignores the
  'slave_connections_needed_for_purge variable'.
- 'PURGE BINARY LOG..' commands now returns 'note' if a binary log cannot
   be deleted like
   Note 1375 Binary log 'master-bin.000004' is not purged because it is
             the current active binlog
- Automatic binary log purges, based on date or size, will write a
  note to the error log if a binary log matching the size or date
  cannot yet be deleted.
- If 'slave_connections_needed_for_purge' is set from a config or
  command line, it is set to 0 if Galera is enabled and 1 otherwise
  (old default). This ensures that automatic binary log purge works
  with Galera as before the addition of
  'slave_connections_needed_for_purge'.
  If the variable is changed to 0, a warning will be printed to the error
  log.

Code changes:
- Added THD argument to several purge_logs related functions that needed
  THD.
- Added 'interactive' options to purge_logs functions. This allowed
  me to remove testing of sql_command == SQLCOM_PURGE.
- Changed purge_logs_before_date() to first check if log is applicable
  before calling can_purge_logs(). This ensures we do not get a
  notification for logs that does not match the remove criteria.
- MYSQL_BIN_LOG::can_purge_log() will write notifications to the user
  or error log if a log cannot yet be removed.
- log_in_use() will return reason why a binary log cannot be removed.

Changes to keep code consistent:
- Moved checking of binlog_format for Galera to be after Galera is
  initialized (The old check never worked). If Galera is enabled
  we now change the binlog_format to ROW, with a warning, instead of
  aborting the server. If this change happens a warning will be printed to
  the error log.
- Print a warning if Galera or FLASHBACK changes the binlog_format
  to ROW. Before it was done silently.

Reviewed by: Sergei Golubchik <serg@mariadb.com>,
             Kristian Nielsen <knielsen@knielsen-hq.org>
This commit is contained in:
Monty
2024-07-09 10:56:06 +03:00
parent 5fb07d942b
commit dd99780967
24 changed files with 269 additions and 54 deletions

View File

@@ -49,6 +49,9 @@ ERROR HY000: Could not delete gtid domain. Reason: binlog files may contain gtid
MDEV-31140: Missing error from DELETE_DOMAIN_ID when gtid_binlog_state partially matches GTID_LIST.
FLUSH BINARY LOGS;
PURGE BINARY LOGS TO 'master-bin.000005';
show binary logs;
Log_name File_size
master-bin.000005 #
SET @@SESSION.gtid_domain_id=8;
SET @@SESSION.server_id=10*8 + 1;
INSERT INTO t SELECT 1+MAX(a) FROM t;

View File

@@ -30,6 +30,7 @@ flush logs;
flush logs;
*** must be a warning master-bin.000001 was not found ***
Warnings:
Note 1375 Binary log 'master-bin.000004' is not purged because it is the current active binlog
Warning 1612 Being purged log master-bin.000001 was not found
*** must show one record, of the active binlog, left in the index file after PURGE ***
show binary logs;

View File

@@ -89,6 +89,8 @@ master-bin.000006 # Format_desc # # SERVER_VERSION, BINLOG_VERSION
master-bin.000006 # Gtid_list # # [#-#-#]
master-bin.000006 # Binlog_checkpoint # # master-bin.000004
PURGE BINARY LOGS TO "master-bin.000006";
Warnings:
Note 1375 Binary log 'master-bin.000004' is not purged because it may be needed for crash recovery (XID)
show binary logs;
Log_name File_size
master-bin.000004 #

View File

@@ -91,6 +91,7 @@ while ($domain_cnt)
FLUSH BINARY LOGS;
--let $purge_to_binlog= query_get_value(SHOW MASTER STATUS, File, 1)
--eval PURGE BINARY LOGS TO '$purge_to_binlog'
--source include/show_binary_logs.inc
--eval SET @@SESSION.gtid_domain_id=$err_domain_id
--eval SET @@SESSION.server_id=10*$err_domain_id + $err_server_id
eval INSERT INTO t SELECT 1+MAX(a) FROM t;

View File

@@ -30,6 +30,7 @@ flush logs;
flush logs;
*** must be a warning master-bin.000001 was not found ***
Warnings:
Note 1375 Binary log 'master-bin.000004' is not purged because it is the current active binlog
Warning 1612 Being purged log master-bin.000001 was not found
*** must show one record, of the active binlog, left in the index file after PURGE ***
show binary logs;

View File

@@ -93,6 +93,8 @@ master-bin.000006 # Start_encryption # #
master-bin.000006 # Gtid_list # # [#-#-#]
master-bin.000006 # Binlog_checkpoint # # master-bin.000004
PURGE BINARY LOGS TO "master-bin.000006";
Warnings:
Note 1375 Binary log 'master-bin.000004' is not purged because it may be needed for crash recovery (XID)
show binary logs;
Log_name File_size
master-bin.000004 #

View File

@@ -1,3 +1,4 @@
call mtr.add_suppression("Binlog_format changed to.*flashback");
SET @@SQL_MODE = 'ORACLE';
##########################################################################
# Test verifies Gtid_log_event/Xid_log_event specific print #

View File

@@ -18,6 +18,8 @@
--source include/have_log_bin.inc
--source include/have_innodb.inc
call mtr.add_suppression("Binlog_format changed to.*flashback");
let $MYSQLD_DATADIR= `select @@datadir`;
SET @@SQL_MODE = 'ORACLE';

View File

@@ -1,5 +1,11 @@
connection node_2;
connection node_1;
select @@slave_connections_needed_for_purge;
@@slave_connections_needed_for_purge
0
select VARIABLE_NAME, GLOBAL_VALUE, GLOBAL_VALUE_ORIGIN from information_schema.system_variables where variable_name="slave_connections_needed_for_purge";
VARIABLE_NAME GLOBAL_VALUE GLOBAL_VALUE_ORIGIN
SLAVE_CONNECTIONS_NEEDED_FOR_PURGE 0 AUTO
USE test;
CREATE TABLE t1(c1 INT PRIMARY KEY) ENGINE=INNODB;
INSERT INTO t1 VALUES (1), (2), (3), (4), (5);

View File

@@ -1,6 +1,9 @@
--source include/galera_cluster.inc
--source include/have_innodb.inc
select @@slave_connections_needed_for_purge;
select VARIABLE_NAME, GLOBAL_VALUE, GLOBAL_VALUE_ORIGIN from information_schema.system_variables where variable_name="slave_connections_needed_for_purge";
USE test;
CREATE TABLE t1(c1 INT PRIMARY KEY) ENGINE=INNODB;
INSERT INTO t1 VALUES (1), (2), (3), (4), (5);

View File

@@ -0,0 +1,52 @@
include/master-slave.inc
[connection master]
#
# MDEV-34504 PURGE BINARY LOGS not working anymore
#
select @@slave_connections_needed_for_purge;
@@slave_connections_needed_for_purge
0
set @old_dbug= @@global.debug_dbug;
create table t1 (a int, b varchar(32768));
insert into t1 values(1,repeat("a",32768));
connection slave;
select a from t1;
a
1
set @@global.debug_dbug= "+d,pause_before_io_read_event";
connection master;
insert into t1 values(2,repeat("b",32768));
insert into t1 values(3,repeat("c",32768));
connection slave;
set debug_sync='now wait_for io_thread_at_read_event';
select a from t1;
a
1
connection master;
FLUSH BINARY LOGS;
show binary logs;
Log_name File_size
master-bin.000001 #
master-bin.000002 #
PURGE BINARY LOGS TO 'master-bin.000002';
Warnings:
Note 1375 Binary log XXX is not purged because it is in use by a slave thread
show binary logs;
Log_name File_size
master-bin.000001 #
master-bin.000002 #
connection slave;
set @@global.debug_dbug= @old_dbug;
set debug_sync='now signal io_thread_continue_read_event';
connection master;
connection slave;
select count(*) from t1;
count(*)
153
connection master;
PURGE BINARY LOGS TO 'master-bin.000002';
show binary logs;
Log_name File_size
master-bin.000002 #
drop table t1;
include/rpl_end.inc

View File

@@ -70,6 +70,8 @@ master-bin.000002 #
master-bin.000003 #
SELECT @time_for_purge:=DATE_ADD('tmpval', INTERVAL 1 SECOND);
purge master logs before (@time_for_purge);
Warnings:
Note 1375 Binary log 'master-bin.000003' is not purged because it is the current active binlog
show binary logs;
Log_name File_size
master-bin.000003 #

View File

@@ -0,0 +1,51 @@
--source include/have_debug.inc
--source include/have_debug_sync.inc
--source include/master-slave.inc
--source include/have_binlog_format_row.inc
--echo #
--echo # MDEV-34504 PURGE BINARY LOGS not working anymore
--echo #
select @@slave_connections_needed_for_purge;
set @old_dbug= @@global.debug_dbug;
create table t1 (a int, b varchar(32768));
insert into t1 values(1,repeat("a",32768));
--sync_slave_with_master
select a from t1;
set @@global.debug_dbug= "+d,pause_before_io_read_event";
--connection master
insert into t1 values(2,repeat("b",32768));
insert into t1 values(3,repeat("c",32768));
--connection slave
set debug_sync='now wait_for io_thread_at_read_event';
select a from t1;
--connection master
--disable_query_log
let $i=150;
while ($i)
{
--eval insert into t1 values($i+4,repeat(char(64+$i),32768));
--dec $i
}
--enable_query_log
FLUSH BINARY LOGS;
--source include/show_binary_logs.inc
--let $purge_to_binlog= query_get_value(SHOW MASTER STATUS, File, 1)
--replace_regex /Binary log.*is not/Binary log XXX is not/
--eval PURGE BINARY LOGS TO '$purge_to_binlog'
--source include/show_binary_logs.inc
--connection slave
set @@global.debug_dbug= @old_dbug;
set debug_sync='now signal io_thread_continue_read_event';
--connection master
--sync_slave_with_master
select count(*) from t1;
--connection master
--eval PURGE BINARY LOGS TO '$purge_to_binlog'
--source include/show_binary_logs.inc
drop table t1;
--source include/rpl_end.inc

View File

@@ -190,10 +190,12 @@ sync_slave_with_master;
#
--error 1220
show binlog events in 'non existing_binlog_file';
--disable_warnings
purge master logs before now();
--error 1220
show binlog events in '';
purge master logs before now();
--enable_warnings
--echo End of 5.0 tests
--echo #cleanup

View File

@@ -3435,7 +3435,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL
VARIABLE_NAME SLAVE_CONNECTIONS_NEEDED_FOR_PURGE
VARIABLE_SCOPE GLOBAL
VARIABLE_TYPE INT UNSIGNED
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.
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.
NUMERIC_MIN_VALUE 0
NUMERIC_MAX_VALUE 4294967295
NUMERIC_BLOCK_SIZE 1

View File

@@ -4005,7 +4005,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL
VARIABLE_NAME SLAVE_CONNECTIONS_NEEDED_FOR_PURGE
VARIABLE_SCOPE GLOBAL
VARIABLE_TYPE INT UNSIGNED
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.
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.
NUMERIC_MIN_VALUE 0
NUMERIC_MAX_VALUE 4294967295
NUMERIC_BLOCK_SIZE 1