Skip to content

Commit 652f33e

Browse files
committed
MDEV-30000: Force an InnoDB checkpoint in mariadb-backup
At the start of mariadb-backup --backup, trigger a flush of the InnoDB buffer pool, so that as little log as possible will have to be copied. The previously debug-build-only interface SET GLOBAL innodb_log_checkpoint_now=ON; will be made available on all builds, and mariadb-backup --backup will invoke it, unless the option --skip-innodb-log-checkpoint-now is specified. Reviewed by: Vladislav Vaintroub
1 parent 5b686cc commit 652f33e

File tree

9 files changed

+45
-13
lines changed

9 files changed

+45
-13
lines changed

extra/mariabackup/xtrabackup.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ enum options_xtrabackup
13811381
OPT_XTRA_MYSQLD_ARGS,
13821382
OPT_XB_IGNORE_INNODB_PAGE_CORRUPTION,
13831383
OPT_INNODB_FORCE_RECOVERY,
1384+
OPT_INNODB_CHECKPOINT,
13841385
OPT_ARIA_LOG_DIR_PATH
13851386
};
13861387

@@ -1790,6 +1791,8 @@ extern const char *io_uring_may_be_unsafe;
17901791
bool innodb_use_native_aio_default();
17911792
#endif
17921793

1794+
static my_bool innodb_log_checkpoint_now;
1795+
17931796
struct my_option xb_server_options[] =
17941797
{
17951798
{"datadir", 'h', "Path to the database root.", (G_PTR*) &mysql_data_home,
@@ -2017,6 +2020,12 @@ struct my_option xb_server_options[] =
20172020
(G_PTR*)&srv_force_recovery,
20182021
0, GET_ULONG, OPT_ARG, 0, 0, SRV_FORCE_IGNORE_CORRUPT, 0, 0, 0},
20192022

2023+
{"innodb_log_checkpoint_now", OPT_INNODB_CHECKPOINT,
2024+
"(for --backup): Force an InnoDB checkpoint",
2025+
(G_PTR*)&innodb_log_checkpoint_now,
2026+
(G_PTR*)&innodb_log_checkpoint_now,
2027+
0, GET_BOOL, OPT_ARG, 1, 0, 0, 0, 0, 0},
2028+
20202029
{"mysqld-args", OPT_XTRA_MYSQLD_ARGS,
20212030
"All arguments that follow this argument are considered as server "
20222031
"options, and if some of them are not supported by mariabackup, they "
@@ -5403,6 +5412,14 @@ static bool xtrabackup_backup_func()
54035412
}
54045413
msg("cd to %s", mysql_real_data_home);
54055414
encryption_plugin_backup_init(mysql_connection);
5415+
if (innodb_log_checkpoint_now != false && mysql_send_query(
5416+
mysql_connection,
5417+
C_STRING_WITH_LEN("SET GLOBAL "
5418+
"innodb_log_checkpoint_now=ON;"))) {
5419+
msg("initiating checkpoint failed");
5420+
return(false);
5421+
}
5422+
54065423
msg("open files limit requested %lu, set to %lu",
54075424
xb_open_files_limit,
54085425
xb_set_max_open_files(xb_open_files_limit));
@@ -5515,6 +5532,11 @@ static bool xtrabackup_backup_func()
55155532
goto fail;
55165533
}
55175534

5535+
/* try to wait for a log checkpoint, but do not fail if the
5536+
server does not support this */
5537+
if (innodb_log_checkpoint_now != false) {
5538+
mysql_read_query_result(mysql_connection);
5539+
}
55185540
/* label it */
55195541
recv_sys.file_checkpoint = log_sys.next_checkpoint_lsn;
55205542
log_hdr_init();

mysql-test/suite/encryption/t/doublewrite_debug.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ insert into t2 values (6, repeat('%', 400));
4141
# Copy the t1.ibd, t2.ibd file
4242
let $targetdir=$MYSQLTEST_VARDIR/tmp/backup_1;
4343
--disable_result_log
44-
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir;
44+
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --skip-innodb-log-checkpoint-now --target-dir=$targetdir;
4545
--enable_result_log
4646

4747
echo # xtrabackup prepare;

mysql-test/suite/mariabackup/full_backup.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
CREATE TABLE t(i INT) ENGINE INNODB;
22
INSERT INTO t VALUES(1);
3+
SET GLOBAL innodb_max_purge_lag_wait=0;
34
# xtrabackup backup
45
NOT FOUND /InnoDB: Allocated tablespace ID/ in backup.log
6+
SELECT variable_value FROM information_schema.global_status
7+
WHERE variable_name = 'INNODB_BUFFER_POOL_PAGES_DIRTY';
8+
variable_value
9+
0
510
INSERT INTO t VALUES(2);
611
# xtrabackup prepare
712
# shutdown server

mysql-test/suite/mariabackup/full_backup.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
CREATE TABLE t(i INT) ENGINE INNODB;
44
INSERT INTO t VALUES(1);
5+
SET GLOBAL innodb_max_purge_lag_wait=0;
56
echo # xtrabackup backup;
67
let $targetdir=$MYSQLTEST_VARDIR/tmp/backup;
78
--let $backup_log=$MYSQLTEST_VARDIR/tmp/backup.log
@@ -18,6 +19,8 @@ exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=
1819
--source include/search_pattern_in_file.inc
1920
--remove_file $backup_log
2021

22+
SELECT variable_value FROM information_schema.global_status
23+
WHERE variable_name = 'INNODB_BUFFER_POOL_PAGES_DIRTY';
2124
INSERT INTO t VALUES(2);
2225

2326

mysql-test/suite/mariabackup/partial.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ CREATE TABLE t21(i INT) ENGINE INNODB;
44
INSERT INTO t21 VALUES(1);
55
CREATE TABLE t2(i int) ENGINE INNODB;
66
# xtrabackup backup
7-
t1.new
8-
t21.new
7+
t1.ibd
8+
t21.ibd
99
# xtrabackup prepare
1010
t1.cfg
1111
t21.cfg

mysql-test/suite/mariabackup/partial_exclude.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ INSERT INTO test.t1 VALUES(20);
1414
INSERT INTO test.t2 VALUES(20);
1515
# xtrabackup backup
1616
COMMIT;
17-
t1.new
17+
t1.ibd
1818
DROP TABLE t1;
1919
DROP TABLE t2;
2020
DROP DATABASE db2;

mysql-test/suite/mariabackup/unsupported_redo.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ CREATE TABLE t2(i int) ENGINE INNODB;
2222
ALTER TABLE t21 FORCE, ALGORITHM=INPLACE;
2323
# Create partial backup (excluding table t21), Ignore the
2424
# unsupported redo log for the table t21.
25-
t1.new
26-
t2.new
25+
t1.ibd
26+
t2.ibd
2727
# Prepare the full backup
2828
t1.ibd
2929
t2.ibd

mysql-test/suite/sys_vars/r/sysvars_innodb.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ SESSION_VALUE NULL
10201020
DEFAULT_VALUE OFF
10211021
VARIABLE_SCOPE GLOBAL
10221022
VARIABLE_TYPE BOOLEAN
1023-
VARIABLE_COMMENT Force checkpoint now
1023+
VARIABLE_COMMENT Write back dirty pages from the buffer pool and update the log checkpoint
10241024
NUMERIC_MIN_VALUE NULL
10251025
NUMERIC_MAX_VALUE NULL
10261026
NUMERIC_BLOCK_SIZE NULL

storage/innobase/handler/ha_innodb.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18520,13 +18520,13 @@ static void innodb_buf_pool_update(THD *thd, st_mysql_sys_var *,
1852018520
mysql_mutex_unlock(&buf_pool.mutex);
1852118521
}
1852218522

18523+
static my_bool innodb_log_checkpoint_now;
1852318524
#ifdef UNIV_DEBUG
18524-
static my_bool innodb_log_checkpoint_now = TRUE;
1852518525
static my_bool innodb_buf_flush_list_now = TRUE;
1852618526
static uint innodb_merge_threshold_set_all_debug
1852718527
= DICT_INDEX_MERGE_THRESHOLD_DEFAULT;
18528+
#endif
1852818529

18529-
/** Force an InnoDB log checkpoint. */
1853018530
/** Force an InnoDB log checkpoint. */
1853118531
static
1853218532
void
@@ -18552,13 +18552,15 @@ checkpoint_now_set(THD* thd, st_mysql_sys_var*, void*, const void *save)
1855218552
? SIZE_OF_FILE_CHECKPOINT + 8 : SIZE_OF_FILE_CHECKPOINT;
1855318553
mysql_mutex_unlock(&LOCK_global_system_variables);
1855418554
lsn_t lsn;
18555-
while (log_sys.last_checkpoint_lsn.load(std::memory_order_acquire) + size <
18555+
while (!thd_kill_level(thd) &&
18556+
log_sys.last_checkpoint_lsn.load(std::memory_order_acquire) + size <
1855618557
(lsn= log_sys.get_lsn(std::memory_order_acquire)))
1855718558
log_make_checkpoint();
1855818559

1855918560
mysql_mutex_lock(&LOCK_global_system_variables);
1856018561
}
1856118562

18563+
#ifdef UNIV_DEBUG
1856218564
/****************************************************************//**
1856318565
Force a dirty pages flush now. */
1856418566
static
@@ -19130,12 +19132,12 @@ static MYSQL_SYSVAR_ULONG(io_capacity_max, srv_max_io_capacity,
1913019132
SRV_MAX_IO_CAPACITY_DUMMY_DEFAULT, 100,
1913119133
SRV_MAX_IO_CAPACITY_LIMIT, 0);
1913219134

19133-
#ifdef UNIV_DEBUG
1913419135
static MYSQL_SYSVAR_BOOL(log_checkpoint_now, innodb_log_checkpoint_now,
1913519136
PLUGIN_VAR_OPCMDARG,
19136-
"Force checkpoint now",
19137+
"Write back dirty pages from the buffer pool and update the log checkpoint",
1913719138
NULL, checkpoint_now_set, FALSE);
1913819139

19140+
#ifdef UNIV_DEBUG
1913919141
static MYSQL_SYSVAR_BOOL(buf_flush_list_now, innodb_buf_flush_list_now,
1914019142
PLUGIN_VAR_OPCMDARG,
1914119143
"Force dirty page flush now",
@@ -20213,8 +20215,8 @@ static struct st_mysql_sys_var* innobase_system_variables[]= {
2021320215
MYSQL_SYSVAR(monitor_reset_all),
2021420216
MYSQL_SYSVAR(purge_threads),
2021520217
MYSQL_SYSVAR(purge_batch_size),
20216-
#ifdef UNIV_DEBUG
2021720218
MYSQL_SYSVAR(log_checkpoint_now),
20219+
#ifdef UNIV_DEBUG
2021820220
MYSQL_SYSVAR(buf_flush_list_now),
2021920221
MYSQL_SYSVAR(merge_threshold_set_all_debug),
2022020222
#endif /* UNIV_DEBUG */

0 commit comments

Comments
 (0)