2017-04-18 18:43:20 +00:00
|
|
|
/******************************************************
|
2017-10-25 09:06:45 +03:00
|
|
|
MariaBackup: hot backup tool for InnoDB
|
2017-04-18 18:43:20 +00:00
|
|
|
(c) 2009-2013 Percona LLC and/or its affiliates.
|
|
|
|
Originally Created 3/3/2009 Yasufumi Kinoshita
|
|
|
|
Written by Alexey Kopytov, Aleksandr Kuzminsky, Stewart Smith, Vadim Tkachenko,
|
|
|
|
Yasufumi Kinoshita, Ignacio Nin and Baron Schwartz.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
/* Page write filters implementation */
|
|
|
|
|
2017-08-21 16:57:08 +02:00
|
|
|
#include <my_global.h>
|
2017-04-18 18:43:20 +00:00
|
|
|
#include <my_base.h>
|
|
|
|
#include "common.h"
|
|
|
|
#include "write_filt.h"
|
|
|
|
#include "fil_cur.h"
|
|
|
|
#include "xtrabackup.h"
|
2017-11-09 18:59:08 +00:00
|
|
|
#include <os0proc.h>
|
2017-04-18 18:43:20 +00:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Write-through page write filter. */
|
|
|
|
static my_bool wf_wt_init(xb_write_filt_ctxt_t *ctxt, char *dst_name,
|
|
|
|
xb_fil_cur_t *cursor);
|
|
|
|
static my_bool wf_wt_process(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile);
|
|
|
|
|
|
|
|
xb_write_filt_t wf_write_through = {
|
|
|
|
&wf_wt_init,
|
|
|
|
&wf_wt_process,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Incremental page write filter. */
|
|
|
|
static my_bool wf_incremental_init(xb_write_filt_ctxt_t *ctxt, char *dst_name,
|
|
|
|
xb_fil_cur_t *cursor);
|
|
|
|
static my_bool wf_incremental_process(xb_write_filt_ctxt_t *ctxt,
|
|
|
|
ds_file_t *dstfile);
|
|
|
|
static my_bool wf_incremental_finalize(xb_write_filt_ctxt_t *ctxt,
|
|
|
|
ds_file_t *dstfile);
|
|
|
|
static void wf_incremental_deinit(xb_write_filt_ctxt_t *ctxt);
|
|
|
|
|
|
|
|
xb_write_filt_t wf_incremental = {
|
|
|
|
&wf_incremental_init,
|
|
|
|
&wf_incremental_process,
|
|
|
|
&wf_incremental_finalize,
|
|
|
|
&wf_incremental_deinit
|
|
|
|
};
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Initialize incremental page write filter.
|
|
|
|
|
|
|
|
@return TRUE on success, FALSE on error. */
|
|
|
|
static my_bool
|
|
|
|
wf_incremental_init(xb_write_filt_ctxt_t *ctxt, char *dst_name,
|
|
|
|
xb_fil_cur_t *cursor)
|
|
|
|
{
|
|
|
|
char meta_name[FN_REFLEN];
|
|
|
|
xb_wf_incremental_ctxt_t *cp =
|
|
|
|
&(ctxt->u.wf_incremental_ctxt);
|
|
|
|
|
|
|
|
ctxt->cursor = cursor;
|
|
|
|
|
|
|
|
/* allocate buffer for incremental backup (4096 pages) */
|
2017-11-21 19:47:46 +01:00
|
|
|
cp->delta_buf_size = (cursor->page_size.physical() / 4)
|
|
|
|
* cursor->page_size.physical();
|
2017-11-09 18:59:08 +00:00
|
|
|
cp->delta_buf = (unsigned char *)os_mem_alloc_large(&cp->delta_buf_size);
|
|
|
|
|
|
|
|
if (!cp->delta_buf) {
|
|
|
|
msg("[%02u] mariabackup: Error: "
|
|
|
|
"cannot allocate %zu bytes\n",
|
|
|
|
cursor->thread_n, (size_t) cp->delta_buf_size);
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2017-04-18 18:43:20 +00:00
|
|
|
|
|
|
|
/* write delta meta info */
|
|
|
|
snprintf(meta_name, sizeof(meta_name), "%s%s", dst_name,
|
|
|
|
XB_DELTA_INFO_SUFFIX);
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
const xb_delta_info_t info(cursor->page_size, cursor->space_id);
|
2017-04-18 18:43:20 +00:00
|
|
|
if (!xb_write_delta_metadata(meta_name, &info)) {
|
2017-10-25 09:06:45 +03:00
|
|
|
msg("[%02u] mariabackup: Error: "
|
2017-04-18 18:43:20 +00:00
|
|
|
"failed to write meta info for %s\n",
|
|
|
|
cursor->thread_n, cursor->rel_path);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* change the target file name, since we are only going to write
|
|
|
|
delta pages */
|
|
|
|
strcat(dst_name, ".delta");
|
|
|
|
|
|
|
|
mach_write_to_4(cp->delta_buf, 0x78747261UL); /*"xtra"*/
|
|
|
|
cp->npages = 1;
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Run the next batch of pages through incremental page write filter.
|
|
|
|
|
|
|
|
@return TRUE on success, FALSE on error. */
|
|
|
|
static my_bool
|
|
|
|
wf_incremental_process(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile)
|
|
|
|
{
|
|
|
|
ulint i;
|
|
|
|
xb_fil_cur_t *cursor = ctxt->cursor;
|
|
|
|
byte *page;
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
const ulint page_size
|
|
|
|
= cursor->page_size.physical();
|
2017-04-18 18:43:20 +00:00
|
|
|
xb_wf_incremental_ctxt_t *cp = &(ctxt->u.wf_incremental_ctxt);
|
|
|
|
|
|
|
|
for (i = 0, page = cursor->buf; i < cursor->buf_npages;
|
|
|
|
i++, page += page_size) {
|
|
|
|
|
|
|
|
if (incremental_lsn >= mach_read_from_8(page + FIL_PAGE_LSN)) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* updated page */
|
|
|
|
if (cp->npages == page_size / 4) {
|
|
|
|
/* flush buffer */
|
|
|
|
if (ds_write(dstfile, cp->delta_buf,
|
|
|
|
cp->npages * page_size)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear buffer */
|
|
|
|
memset(cp->delta_buf, 0, page_size / 4 * page_size);
|
|
|
|
/*"xtra"*/
|
|
|
|
mach_write_to_4(cp->delta_buf, 0x78747261UL);
|
|
|
|
cp->npages = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mach_write_to_4(cp->delta_buf + cp->npages * 4,
|
|
|
|
cursor->buf_page_no + i);
|
|
|
|
memcpy(cp->delta_buf + cp->npages * page_size, page,
|
|
|
|
page_size);
|
|
|
|
|
|
|
|
cp->npages++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Flush the incremental page write filter's buffer.
|
|
|
|
|
|
|
|
@return TRUE on success, FALSE on error. */
|
|
|
|
static my_bool
|
|
|
|
wf_incremental_finalize(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile)
|
|
|
|
{
|
|
|
|
xb_fil_cur_t *cursor = ctxt->cursor;
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
const ulint page_size
|
|
|
|
= cursor->page_size.physical();
|
2017-04-18 18:43:20 +00:00
|
|
|
xb_wf_incremental_ctxt_t *cp = &(ctxt->u.wf_incremental_ctxt);
|
|
|
|
|
|
|
|
if (cp->npages != page_size / 4) {
|
|
|
|
mach_write_to_4(cp->delta_buf + cp->npages * 4, 0xFFFFFFFFUL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark the final block */
|
|
|
|
mach_write_to_4(cp->delta_buf, 0x58545241UL); /*"XTRA"*/
|
|
|
|
|
|
|
|
/* flush buffer */
|
|
|
|
if (ds_write(dstfile, cp->delta_buf, cp->npages * page_size)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Free the incremental page write filter's buffer. */
|
|
|
|
static void
|
|
|
|
wf_incremental_deinit(xb_write_filt_ctxt_t *ctxt)
|
|
|
|
{
|
|
|
|
xb_wf_incremental_ctxt_t *cp = &(ctxt->u.wf_incremental_ctxt);
|
2017-11-09 18:59:08 +00:00
|
|
|
os_mem_free_large(cp->delta_buf, cp->delta_buf_size);
|
2017-04-18 18:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Initialize the write-through page write filter.
|
|
|
|
|
|
|
|
@return TRUE on success, FALSE on error. */
|
|
|
|
static my_bool
|
|
|
|
wf_wt_init(xb_write_filt_ctxt_t *ctxt, char *dst_name __attribute__((unused)),
|
|
|
|
xb_fil_cur_t *cursor)
|
|
|
|
{
|
|
|
|
ctxt->cursor = cursor;
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
Write the next batch of pages to the destination datasink.
|
|
|
|
|
|
|
|
@return TRUE on success, FALSE on error. */
|
|
|
|
static my_bool
|
|
|
|
wf_wt_process(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile)
|
|
|
|
{
|
|
|
|
xb_fil_cur_t *cursor = ctxt->cursor;
|
|
|
|
|
|
|
|
if (ds_write(dstfile, cursor->buf, cursor->buf_read)) {
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(TRUE);
|
|
|
|
}
|