Commit 852d42e9 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-34483 Backup may copy unnecessarily much log

In mariadb-backup --backup there are multiple mechanisms for ensuring that
a sufficient amount of the InnoDB write-ahead log (ib_logfile0) is being
copied at the end of the backup. The backup needs to include the latest
committed transaction. While further transaction commits are blocked by
BACKUP STAGE BLOCK_COMMIT, ongoing transactions may modify the database
contents and write log records. We were unnecessarily copying such log,
which would also cause further effort of rolling back incomplete
transactions after the backup is restored.

backup_wait_for_lsn(): Declare as static, and refactor some code
to separate functions backup_wait_for_lsn_low() and
backup_wait_timeout().

backup_wait_for_commit_lsn(): A new function to determine the current
LSN (within BACKUP STAGE BLOCK_COMMIT) and to wait for the log to be
copied until that. Invoked by BackupStages::stage_block_commit().

xtrabackup_backup_func(): Remove a condition that had already been
checked by a caller of backup_wait_timeout().

server_lsn_after_lock: Declare as a local variable in
BackupStages::stage_block_ddl().

log_copying_thread(), io_watching_thread(): Use metadata_last_lsn
instead of metadata_to_lsn as the stop condition.

BackupStages::stage_block_commit(): Ensure that the log tables
(in particular, mysql.general_log) will have been copied before
the BACKUP STAGE BLOCK_COMMIT is being followed by any further
SQL statements.

Reviewed by: Debarun Banerjee
Tested by: Matthias Leich
parent d002b1f5
......@@ -1353,9 +1353,6 @@ backup_files(ds_ctxt *ds_data, const char *from)
return(ret);
}
lsn_t server_lsn_after_lock;
extern void backup_wait_for_lsn(lsn_t lsn);
/** Release resources after backup_files() */
void backup_release()
{
......
This diff is collapsed.
CREATE TABLE t(i INT)
ENGINE ARIA TRANSACTIONAL=1 ROW_FORMAT=PAGE PAGE_CHECKSUM=1;
SET GLOBAL general_log = 0;
TRUNCATE mysql.general_log;
SET GLOBAL general_log = 1;
SET GLOBAL log_output = 'TABLE';
INSERT INTO t VALUES (1);
......
......@@ -7,9 +7,9 @@
CREATE TABLE t(i INT)
ENGINE ARIA TRANSACTIONAL=1 ROW_FORMAT=PAGE PAGE_CHECKSUM=1;
--let $general_log_old = `SELECT @@global.general_log`
--let $log_output_old = `SELECT @@global.log_output`
# Truncate the log in order to make the test ./mtr --repeat proof
SET GLOBAL general_log = 0;
TRUNCATE mysql.general_log;
SET GLOBAL general_log = 1;
SET GLOBAL log_output = 'TABLE';
......@@ -43,7 +43,3 @@ SELECT * FROM mysql.general_log
--rmdir $targetdir
DROP TABLE t;
--disable_query_log
--eval SET GLOBAL general_log = $general_log_old
--eval SET GLOBAL log_output = $log_output_old
--enable_query_log
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment