1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-31273: Precompute binlog checksums

Compute binlog checksums (when enabled) already when writing events
into the statement or transaction caches, where before it was done
when the caches are copied to the real binlog file. This moves the
checksum computation outside of holding LOCK_log, improving
scalabitily.

At stmt/trx cache write time, the final end_log_pos values are not
known, so with this patch these will be set to 0. Events that are
written directly to the binlog file (not through stmt/trx cache) keep
the correct end_log_pos value. The GTID and COMMIT/XID events at the
start and end of event groups are written directly, so the zero
end_log_pos is only for events in the middle of event groups, which
do not negatively affect replication.

An option --binlog-legacy-event-pos, off by default, is provided to
disable this behavior to provide backwards compatibility with any
external applications that might rely on end_log_pos in events in the
middle of event groups.

Checksums cannot be pre-computed when binlog encryption is enabled, as
encryption relies on correct end_log_pos to provide part of the
nonce/IV.

Checksum pre-computation is also disabled for WSREP/Galera, as it uses
events differently in its write-sets and so on. Extending pre-computation of
checksums to Galera where it makes sense could be added in a future patch.

The current --binlog-checksum configuration is saved in
binlog_cache_data at transaction start and used to pre-compute
checksums in cache, if applicable. When the cache is later copied to
the binlog, a check is made if the saved value still matches the
configured global value; if so, the events are block-copied directly
into the binlog file. If --binlog-checksum was changed during the
transaction, events are re-written to the binlog file one-by-one and
the checksums recomputed/discarded as appropriate.

Reviewed-by: Monty <monty@mariadb.org>
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
This commit is contained in:
Kristian Nielsen
2023-06-13 11:41:44 +02:00
parent 24c923d498
commit b8f9f796ff
24 changed files with 440 additions and 126 deletions

View File

@ -402,7 +402,7 @@ public:
bool is_transactional);
void set_write_error(THD *thd, bool is_transactional);
static bool check_write_error(THD *thd);
int write_cache(THD *thd, IO_CACHE *cache);
int write_cache(THD *thd, binlog_cache_data *cache_data);
int write_cache_raw(THD *thd, IO_CACHE *cache);
char* get_name() { return name; }
void cleanup()
@ -427,6 +427,7 @@ public:
bool encrypt, bool dont_set_created,
bool is_relay_log);
bool write_event(Log_event *ev, binlog_cache_data *data, IO_CACHE *file);
bool write_event(Log_event *ev, enum enum_binlog_checksum_alg checksum_alg,
binlog_cache_data *data, IO_CACHE *file);
};
@ -994,7 +995,6 @@ public:
using Event_log::write_event;
bool write_event(Log_event *ev, binlog_cache_data *data, IO_CACHE *file);
bool write_event(Log_event *ev, enum enum_binlog_checksum_alg checksum_alg)
{
return write_event(ev, checksum_alg, 0, &log_file);