Commit e9e051d2 authored by Marko Mäkelä's avatar Marko Mäkelä

Follow-up fix to MDEV-12988 backup fails if innodb_undo_tablespaces>0

The fix broke mariabackup --prepare --incremental.

The restore of an incremental backup starts up (parts of) InnoDB twice.
First, all data files are discovered for applying .delta files. Then,
after the .delta files have been applied, InnoDB will be restarted
more completely, so that the redo log records will be applied via the
buffer pool.

During the first startup, the buffer pool is not initialized, and thus
trx_rseg_get_n_undo_tablespaces() must not be invoked. The apply of
the .delta files will currently assume that the --innodb-undo-tablespaces
option correctly specifies the number of undo tablespace files, just
like --backup does.

The second InnoDB startup of --prepare for applying the redo log will
properly invoke trx_rseg_get_n_undo_tablespaces().

enum srv_operation_mode: Add SRV_OPERATION_RESTORE_DELTA for
distinguishing the apply of .delta files from SRV_OPERATION_RESTORE.

srv_undo_tablespaces_init(): In mariabackup --prepare --incremental,
in the initial SRV_OPERATION_RESTORE_DELTA phase, do not invoke
trx_rseg_get_n_undo_tablespaces() because the buffer pool or the
redo logs are not available. Instead, blindly rely on the parameter
--innodb-undo-tablespaces.
parent f2699153
......@@ -159,7 +159,7 @@ xb_fil_cur_open(
/* In the backup mode we should already have a tablespace handle created
by fil_ibd_load() unless it is a system
tablespace. Otherwise we open the file here. */
if (cursor->is_system() || srv_operation == SRV_OPERATION_RESTORE
if (cursor->is_system() || srv_operation == SRV_OPERATION_RESTORE_DELTA
|| xb_close_files) {
node->handle = os_file_create_simple_no_error_handling(
0, node->name,
......
......@@ -2517,9 +2517,11 @@ xb_load_single_table_tablespace(
const char *filname,
bool is_remote)
{
ut_ad(srv_operation == SRV_OPERATION_BACKUP
|| srv_operation == SRV_OPERATION_RESTORE_DELTA);
/* Ignore .isl files on XtraBackup recovery. All tablespaces must be
local. */
if (is_remote && srv_operation == SRV_OPERATION_RESTORE) {
if (is_remote && srv_operation == SRV_OPERATION_RESTORE_DELTA) {
return;
}
if (check_if_skip_table(filname)) {
......@@ -2578,7 +2580,8 @@ xb_load_single_table_tablespace(
in the cache to be populated with fields from space header */
fil_space_open(space->name);
if (srv_operation == SRV_OPERATION_RESTORE || xb_close_files) {
if (srv_operation == SRV_OPERATION_RESTORE_DELTA
|| xb_close_files) {
fil_space_close(space->name);
}
}
......@@ -2753,7 +2756,7 @@ xb_load_tablespaces()
lsn_t flush_lsn;
ut_ad(srv_operation == SRV_OPERATION_BACKUP
|| srv_operation == SRV_OPERATION_RESTORE);
|| srv_operation == SRV_OPERATION_RESTORE_DELTA);
err = srv_sys_space.check_file_spec(&create_new_db, 0);
......@@ -4925,6 +4928,8 @@ xtrabackup_prepare_func(char** argv)
srv_thread_concurrency = 1;
if (xtrabackup_incremental) {
srv_operation = SRV_OPERATION_RESTORE_DELTA;
if (innodb_init_param()) {
error_cleanup:
xb_filters_free();
......@@ -4943,7 +4948,6 @@ xtrabackup_prepare_func(char** argv)
srv_allow_writes_event = os_event_create(0);
os_event_set(srv_allow_writes_event);
#endif
dberr_t err = xb_data_files_init();
if (err != DB_SUCCESS) {
msg("xtrabackup: error: xb_data_files_init() failed "
......@@ -4976,6 +4980,8 @@ xtrabackup_prepare_func(char** argv)
if (!ok) goto error_cleanup;
}
srv_operation = SRV_OPERATION_RESTORE;
if (innodb_init_param()) {
goto error_cleanup;
}
......
......@@ -507,7 +507,9 @@ enum srv_operation_mode {
/** Mariabackup taking a backup */
SRV_OPERATION_BACKUP,
/** Mariabackup restoring a backup */
SRV_OPERATION_RESTORE
SRV_OPERATION_RESTORE,
/** Mariabackup restoring the incremental part of a backup */
SRV_OPERATION_RESTORE_DELTA
};
/** Current mode of operation */
......
......@@ -892,11 +892,13 @@ srv_undo_tablespaces_init(bool create_new_db)
already exist. */
n_undo_tablespaces = create_new_db
|| srv_operation == SRV_OPERATION_BACKUP
|| srv_operation == SRV_OPERATION_RESTORE_DELTA
? srv_undo_tablespaces
: trx_rseg_get_n_undo_tablespaces(undo_tablespace_ids);
srv_undo_tablespaces_active = srv_undo_tablespaces;
switch (srv_operation) {
case SRV_OPERATION_RESTORE_DELTA:
case SRV_OPERATION_BACKUP:
/* MDEV-13561 FIXME: Determine srv_undo_space_id_start
from the undo001 file. */
......@@ -1317,6 +1319,7 @@ srv_shutdown_all_bg_threads()
switch (srv_operation) {
case SRV_OPERATION_BACKUP:
case SRV_OPERATION_RESTORE_DELTA:
break;
case SRV_OPERATION_NORMAL:
case SRV_OPERATION_RESTORE:
......@@ -2818,6 +2821,7 @@ innodb_shutdown()
switch (srv_operation) {
case SRV_OPERATION_BACKUP:
case SRV_OPERATION_RESTORE:
case SRV_OPERATION_RESTORE_DELTA:
fil_close_all_files();
break;
case SRV_OPERATION_NORMAL:
......
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