1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +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:
Monty
2023-12-03 21:42:44 +02:00
committed by Sergei Golubchik
parent 9933a8cc88
commit 18dfcfdecf
23 changed files with 906 additions and 46 deletions

View File

@ -150,6 +150,9 @@ The following specify which files/extra groups are read (specified before remain
MINIMAL means that only metadata actually required by
slave is logged; NO_LOG NO metadata will be
logged.Default: NO_LOG.
--binlog-space-limit=#
Alias for max_binlog_total_size. Compatibility with
Percona server.
--binlog-stmt-cache-size=#
The size of the statement cache for updates to
non-transactional engines for the binary log. If you
@ -619,6 +622,11 @@ The following specify which files/extra groups are read (specified before remain
exceeds this value.
--max-binlog-stmt-cache-size=#
Sets the total size of the statement cache
--max-binlog-total-size=#
Maximum space to use for all binary logs. Extra logs are
deleted on server start, log rotation, FLUSH LOGS or when
writing to binlog. Default is 0, which means no size
restrictions. See also slave_connections_needed_for_purge
--max-connect-errors=#
If there is more than this number of interrupted
connections from a host this host will be blocked from
@ -1294,6 +1302,10 @@ The following specify which files/extra groups are read (specified before remain
--skip-slave-start If set, slave is not autostarted.
--slave-compressed-protocol
Use compression on master/slave protocol
--slave-connections-needed-for-purge=#
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.
--slave-ddl-exec-mode=name
How replication events should be executed. Legal values
are STRICT and IDEMPOTENT (default). In IDEMPOTENT mode,
@ -1616,6 +1628,7 @@ binlog-optimize-thread-scheduling TRUE
binlog-row-event-max-size 8192
binlog-row-image FULL
binlog-row-metadata NO_LOG
binlog-space-limit 0
binlog-stmt-cache-size 32768
block-encryption-mode aes-128-ecb
bulk-insert-buffer-size 8388608
@ -1743,6 +1756,7 @@ max-allowed-packet 16777216
max-binlog-cache-size 18446744073709547520
max-binlog-size 1073741824
max-binlog-stmt-cache-size 18446744073709547520
max-binlog-total-size 0
max-connect-errors 100
max-delayed-threads 20
max-digest-length 1024
@ -1930,6 +1944,7 @@ skip-networking FALSE
skip-show-database FALSE
skip-slave-start FALSE
slave-compressed-protocol FALSE
slave-connections-needed-for-purge 1
slave-ddl-exec-mode IDEMPOTENT
slave-domain-parallel-threads 0
slave-exec-mode STRICT