1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00
Files
mariadb/mysql-test/suite/binlog/t/binlog_flush_binlogs_delete_domain.test
Monty dd99780967 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>
2024-07-10 18:50:08 +03:00

169 lines
5.5 KiB
Plaintext

# Prove basic properties of
#
# FLUSH BINARY LOGS DELETE_DOMAIN_ID = (...)
#
# The command removes the supplied list of domains from the current
# @@global.gtid_binlog_state provided the binlog files do not contain
# events from such domains.
# The test is not format specific. One format is chosen to run it.
--source include/have_binlog_format_mixed.inc
# Reset binlog state
RESET MASTER;
# Empty list is accepted
FLUSH BINARY LOGS DELETE_DOMAIN_ID = ();
--echo and the command execution is effective thence rotates binlog as usual
--source include/show_binary_logs.inc
--echo Non-existed domain is warned, the command completes without rotation
--echo but with a warning
--let $binlog_pre_flush=query_get_value(SHOW MASTER STATUS, Position, 1)
FLUSH BINARY LOGS DELETE_DOMAIN_ID = (99);
--source include/show_binary_logs.inc
# Log one event in a specified domain and try to delete the domain
SET @@SESSION.gtid_domain_id=1;
SET @@SESSION.server_id=1;
CREATE TABLE t (a int);
SELECT @@GLOBAL.gtid_binlog_state, @@GLOBAL.gtid_binlog_pos;
--let $binlog_start=
--source include/show_binlog_events.inc
--error ER_BINLOG_CANT_DELETE_GTID_DOMAIN
FLUSH BINARY LOGS DELETE_DOMAIN_ID = (1);
# the same error after log rotation
FLUSH BINARY LOGS;
--error ER_BINLOG_CANT_DELETE_GTID_DOMAIN
FLUSH BINARY LOGS DELETE_DOMAIN_ID = (1);
# the latest binlog does not really contain any events incl ones from 1-domain
--let $purge_to_binlog= query_get_value(SHOW MASTER STATUS, File, 1)
--eval PURGE BINARY LOGS TO '$purge_to_binlog';
# So now it's safe to delete
--error 0
FLUSH BINARY LOGS DELETE_DOMAIN_ID = (1);
--echo Gtid_list of the current binlog does not contain '1':
--let $binlog_file=query_get_value(SHOW MASTER STATUS, File, 1)
--source include/show_gtid_list.inc
--echo But the previous log's Gtid_list may have it which explains a warning from the following command
--let $binlog_file=$purge_to_binlog
--source include/show_gtid_list.inc
--echo Already deleted domain in Gtid_list of the earliest log is benign
--echo but may cause a warning
--error 0
FLUSH BINARY LOGS DELETE_DOMAIN_ID = (1);
# Few domains delete. The chosen number verifies among others how
# expected overrun of the static buffers of underlying dynamic arrays is doing.
--let $domain_cnt=17
--let $server_in_domain_cnt=3
--let $err_domain_id=`SELECT FLOOR($domain_cnt/2)`
--let $err_server_id=`SELECT FLOOR($server_in_domain_cnt/2)`
--let $domain_list=
--disable_query_log
while ($domain_cnt)
{
--let servers=$server_in_domain_cnt
--eval SET @@SESSION.gtid_domain_id=$domain_cnt
while ($servers)
{
--eval SET @@SESSION.server_id=10*$domain_cnt + $servers
--eval INSERT INTO t SET a=@@SESSION.server_id
--dec $servers
}
--let $domain_list= $domain_cnt, $domain_list
--dec $domain_cnt
}
--enable_query_log
--let $zero=0
--let $domain_list= $domain_list$zero
--error ER_BINLOG_CANT_DELETE_GTID_DOMAIN
--eval FLUSH BINARY LOGS DELETE_DOMAIN_ID = ($domain_list)
--echo MDEV-31140: Missing error from DELETE_DOMAIN_ID when gtid_binlog_state partially matches GTID_LIST.
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;
--error ER_BINLOG_CANT_DELETE_GTID_DOMAIN
--eval FLUSH BINARY LOGS DELETE_DOMAIN_ID = ($domain_list)
# Now satisfy the safety condtion to purge log files containing $domain list
FLUSH BINARY LOGS;
--let $purge_to_binlog= query_get_value(SHOW MASTER STATUS, File, 1)
--eval PURGE BINARY LOGS TO '$purge_to_binlog'
--error 0
--eval FLUSH BINARY LOGS DELETE_DOMAIN_ID = ($domain_list)
--echo Gtid_list of the current binlog does not contain $domain_list:
--let $binlog_file=query_get_value(SHOW MASTER STATUS, File, 1)
--source include/show_gtid_list.inc
# Show reaction on @@global.gtid_binlog_state not succeeding
# earlier state as described by the 1st binlog' Gtid_list.
# Now let it be out-order gtid logged to a domain unrelated to deletion.
--let $del_d_id=1
--eval SET @@SESSION.gtid_domain_id=$del_d_id;
SET @@SESSION.server_id=1;
SET @@SESSION.gtid_seq_no=1;
INSERT INTO t SET a=1;
SET @@SESSION.server_id=2;
SET @@SESSION.gtid_seq_no=2;
INSERT INTO t SET a=2;
SET @@SESSION.gtid_domain_id=11;
SET @@SESSION.server_id=11;
SET @@SESSION.gtid_seq_no=11;
INSERT INTO t SET a=11;
SET @gtid_binlog_state_saved=@@GLOBAL.gtid_binlog_state;
FLUSH BINARY LOGS;
# Inject out of order for domain '11' before
SET @@SESSION.gtid_domain_id=11;
SET @@SESSION.server_id=11;
SET @@SESSION.gtid_seq_no=1;
INSERT INTO t SET a=1;
SELECT @gtid_binlog_state_saved "as original state", @@GLOBAL.gtid_binlog_state as "out of order for 11 domain state";
# to delete '1', first to purge logs containing its events
--let $purge_to_binlog= query_get_value(SHOW MASTER STATUS, File, 1)
--eval PURGE BINARY LOGS TO '$purge_to_binlog'
--echo the following command succeeds with warnings
--eval FLUSH BINARY LOGS DELETE_DOMAIN_ID = ($del_d_id)
# cleanup: forget the out-of-order
RESET MASTER;
#
# MDEV-14431
# Check rejection to delete a domain with value exceeding its range's maximum
#
--let $d_max_plus_1=`SELECT 1 << 32`
--error ER_BINLOG_CANT_DELETE_GTID_DOMAIN
--eval FLUSH BINARY LOGS DELETE_DOMAIN_ID = ($d_max_plus_1)
# accepted maximum:
--let $d_max=`SELECT (1 << 32) - 1`
--error 0
--eval FLUSH BINARY LOGS DELETE_DOMAIN_ID = ($d_max)
#
# Cleanup
#
DROP TABLE t;
RESET MASTER;