Skip to content

Commit a13fac9

Browse files
committed
Merge 10.5 into 10.6
2 parents e28d9c1 + f146969 commit a13fac9

File tree

129 files changed

+2667
-481
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+2667
-481
lines changed

extra/mariabackup/backup_copy.cc

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -868,21 +868,14 @@ datafile_rsync_backup(const char *filepath, bool save_to_list, FILE *f)
868868
return(true);
869869
}
870870

871-
872-
static
873-
bool
874-
backup_file_vprintf(const char *filename, const char *fmt, va_list ap)
871+
bool backup_file_print_buf(const char *filename, const char *buf, int buf_len)
875872
{
876873
ds_file_t *dstfile = NULL;
877874
MY_STAT stat; /* unused for now */
878-
char *buf = 0;
879-
int buf_len;
880875
const char *action;
881876

882877
memset(&stat, 0, sizeof(stat));
883878

884-
buf_len = vasprintf(&buf, fmt, ap);
885-
886879
stat.st_size = buf_len;
887880
stat.st_mtime = my_time(0);
888881

@@ -906,7 +899,6 @@ backup_file_vprintf(const char *filename, const char *fmt, va_list ap)
906899

907900
/* close */
908901
msg(" ...done");
909-
free(buf);
910902

911903
if (ds_close(dstfile)) {
912904
goto error_close;
@@ -915,16 +907,28 @@ backup_file_vprintf(const char *filename, const char *fmt, va_list ap)
915907
return(true);
916908

917909
error:
918-
free(buf);
919910
if (dstfile != NULL) {
920911
ds_close(dstfile);
921912
}
922913

923914
error_close:
924915
msg("Error: backup file failed.");
925916
return(false); /*ERROR*/
926-
}
927917

918+
return true;
919+
};
920+
921+
static
922+
bool
923+
backup_file_vprintf(const char *filename, const char *fmt, va_list ap)
924+
{
925+
char *buf = 0;
926+
int buf_len;
927+
buf_len = vasprintf(&buf, fmt, ap);
928+
bool result = backup_file_print_buf(filename, buf, buf_len);
929+
free(buf);
930+
return result;
931+
}
928932

929933
bool
930934
backup_file_printf(const char *filename, const char *fmt, ...)
@@ -1380,7 +1384,7 @@ backup_files(const char *from, bool prep_mode)
13801384
return(ret);
13811385
}
13821386

1383-
void backup_fix_ddl(void);
1387+
void backup_fix_ddl(CorruptedPages &);
13841388

13851389
lsn_t get_current_lsn(MYSQL *connection)
13861390
{
@@ -1405,7 +1409,7 @@ lsn_t get_current_lsn(MYSQL *connection)
14051409
lsn_t server_lsn_after_lock;
14061410
extern void backup_wait_for_lsn(lsn_t lsn);
14071411
/** Start --backup */
1408-
bool backup_start()
1412+
bool backup_start(CorruptedPages &corrupted_pages)
14091413
{
14101414
if (!opt_no_lock) {
14111415
if (opt_safe_slave_backup) {
@@ -1440,7 +1444,7 @@ bool backup_start()
14401444

14411445
msg("Waiting for log copy thread to read lsn %llu", (ulonglong)server_lsn_after_lock);
14421446
backup_wait_for_lsn(server_lsn_after_lock);
1443-
backup_fix_ddl();
1447+
backup_fix_ddl(corrupted_pages);
14441448

14451449
// There is no need to stop slave thread before coping non-Innodb data when
14461450
// --no-lock option is used because --no-lock option requires that no DDL or

extra/mariabackup/backup_copy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ copy_file(ds_ctxt_t *datasink,
3333
uint thread_n);
3434

3535
/** Start --backup */
36-
bool backup_start();
36+
bool backup_start(CorruptedPages &corrupted_pages);
3737
/** Release resources after backup_start() */
3838
void backup_release();
3939
/** Finish after backup_start() and backup_release() */
@@ -51,5 +51,6 @@ directory_exists(const char *dir, bool create);
5151

5252
lsn_t
5353
get_current_lsn(MYSQL *connection);
54+
bool backup_file_print_buf(const char *filename, const char *buf, int buf_len);
5455

5556
#endif

extra/mariabackup/backup_debug.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
#include "my_dbug.h"
3+
#ifndef DBUG_OFF
4+
extern char *dbug_mariabackup_get_val(const char *event, const char *key);
5+
/*
6+
In debug mode, execute SQL statement that was passed via environment.
7+
To use this facility, you need to
8+
9+
1. Add code DBUG_EXECUTE_MARIABACKUP_EVENT("my_event_name", key););
10+
to the code. key is usually a table name
11+
2. Set environment variable my_event_name_$key SQL statement you want to execute
12+
when event occurs, in DBUG_EXECUTE_IF from above.
13+
In mtr , you can set environment via 'let' statement (do not use $ as the first char
14+
for the variable)
15+
3. start mariabackup with --dbug=+d,debug_mariabackup_events
16+
*/
17+
extern void dbug_mariabackup_event(
18+
const char *event,const char *key);
19+
#define DBUG_MARIABACKUP_EVENT(A, B) \
20+
DBUG_EXECUTE_IF("mariabackup_events", \
21+
dbug_mariabackup_event(A,B););
22+
#define DBUG_EXECUTE_FOR_KEY(EVENT, KEY, CODE) \
23+
DBUG_EXECUTE_IF("mariabackup_inject_code", {\
24+
char *dbug_val = dbug_mariabackup_get_val(EVENT, KEY); \
25+
if (dbug_val && *dbug_val) CODE \
26+
})
27+
#else
28+
#define DBUG_MARIABACKUP_EVENT(A,B)
29+
#define DBUG_MARIABACKUP_EVENT_LOCK(A,B)
30+
#define DBUG_EXECUTE_FOR_KEY(EVENT, KEY, CODE)
31+
#endif
32+

extra/mariabackup/encryption_plugin.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <mysql.h>
1919
#include <xtrabackup.h>
2020
#include <encryption_plugin.h>
21-
#include <backup_copy.h>
2221
#include <sql_plugin.h>
2322
#include <sstream>
2423
#include <vector>

extra/mariabackup/fil_cur.cc

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
3535
#include "common.h"
3636
#include "read_filt.h"
3737
#include "xtrabackup.h"
38+
#include "backup_debug.h"
3839

3940
/* Size of read buffer in pages (640 pages = 10M for 16K sized pages) */
4041
#define XB_FIL_CUR_PAGES 640
@@ -351,19 +352,18 @@ static bool page_is_corrupted(const byte *page, ulint page_no,
351352
return buf_page_is_corrupted(true, page, space->flags);
352353
}
353354

354-
/************************************************************************
355-
Reads and verifies the next block of pages from the source
355+
/** Reads and verifies the next block of pages from the source
356356
file. Positions the cursor after the last read non-corrupted page.
357-
357+
@param[in,out] cursor source file cursor
358+
@param[out] corrupted_pages adds corrupted pages if
359+
opt_log_innodb_page_corruption is set
358360
@return XB_FIL_CUR_SUCCESS if some have been read successfully, XB_FIL_CUR_EOF
359361
if there are no more pages to read and XB_FIL_CUR_ERROR on error. */
360-
xb_fil_cur_result_t
361-
xb_fil_cur_read(
362-
/*============*/
363-
xb_fil_cur_t* cursor) /*!< in/out: source file cursor */
362+
xb_fil_cur_result_t xb_fil_cur_read(xb_fil_cur_t* cursor,
363+
CorruptedPages &corrupted_pages)
364364
{
365365
byte* page;
366-
ulint i;
366+
unsigned i;
367367
ulint npages;
368368
ulint retry_count;
369369
xb_fil_cur_result_t ret;
@@ -417,7 +417,7 @@ xb_fil_cur_read(
417417
cursor->buf_read = 0;
418418
cursor->buf_npages = 0;
419419
cursor->buf_offset = offset;
420-
cursor->buf_page_no = (ulint)(offset / page_size);
420+
cursor->buf_page_no = static_cast<unsigned>(offset / page_size);
421421

422422
if (os_file_read(IORequestRead, cursor->file, cursor->buf, offset,
423423
(ulint) to_read) != DB_SUCCESS) {
@@ -428,26 +428,47 @@ xb_fil_cur_read(
428428
partially written pages */
429429
for (page = cursor->buf, i = 0; i < npages;
430430
page += page_size, i++) {
431-
ulint page_no = cursor->buf_page_no + i;
431+
unsigned page_no = cursor->buf_page_no + i;
432432

433433
if (page_is_corrupted(page, page_no, cursor, space)){
434434
retry_count--;
435435

436436
if (retry_count == 0) {
437+
const char *ignore_corruption_warn = opt_log_innodb_page_corruption ?
438+
" WARNING!!! The corruption is ignored due to"
439+
" log-innodb-page-corruption option, the backup can contain"
440+
" corrupted data." : "";
437441
msg(cursor->thread_n,
438442
"Error: failed to read page after "
439443
"10 retries. File %s seems to be "
440-
"corrupted.", cursor->abs_path);
441-
ret = XB_FIL_CUR_ERROR;
444+
"corrupted.%s", cursor->abs_path, ignore_corruption_warn);
442445
ut_print_buf(stderr, page, page_size);
443-
break;
446+
if (opt_log_innodb_page_corruption) {
447+
corrupted_pages.add_page(cursor->node->name, cursor->node->space->id,
448+
page_no);
449+
retry_count = 1;
450+
}
451+
else {
452+
ret = XB_FIL_CUR_ERROR;
453+
break;
454+
}
455+
}
456+
else {
457+
msg(cursor->thread_n, "Database page corruption detected at page "
458+
UINT32PF ", retrying...",
459+
page_no);
460+
os_thread_sleep(100000);
461+
goto read_retry;
444462
}
445-
msg(cursor->thread_n, "Database page corruption detected at page "
446-
ULINTPF ", retrying...",
447-
page_no);
448-
os_thread_sleep(100000);
449-
goto read_retry;
450463
}
464+
DBUG_EXECUTE_FOR_KEY("add_corrupted_page_for", cursor->node->space->name,
465+
{
466+
unsigned corrupted_page_no =
467+
static_cast<unsigned>(strtoul(dbug_val, NULL, 10));
468+
if (page_no == corrupted_page_no)
469+
corrupted_pages.add_page(cursor->node->name, cursor->node->space->id,
470+
corrupted_page_no);
471+
});
451472
cursor->buf_read += page_size;
452473
cursor->buf_npages++;
453474
}

extra/mariabackup/fil_cur.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
2929
#include "read_filt.h"
3030
#include "srv0start.h"
3131
#include "srv0srv.h"
32+
#include "xtrabackup.h"
3233

3334
struct xb_fil_cur_t {
3435
pfs_os_file_t file; /*!< source file handle */
@@ -52,7 +53,7 @@ struct xb_fil_cur_t {
5253
last cursor read */
5354
ib_int64_t buf_offset; /*!< file offset of the first page in
5455
buffer */
55-
ulint buf_page_no; /*!< number of the first page in
56+
unsigned buf_page_no; /*!< number of the first page in
5657
buffer */
5758
uint thread_n; /*!< thread number for diagnostics */
5859
ulint space_id; /*!< ID of tablespace */
@@ -88,17 +89,15 @@ xb_fil_cur_open(
8889
uint thread_n, /*!< thread number for diagnostics */
8990
ulonglong max_file_size = ULLONG_MAX);
9091

91-
/************************************************************************
92-
Reads and verifies the next block of pages from the source
92+
/** Reads and verifies the next block of pages from the source
9393
file. Positions the cursor after the last read non-corrupted page.
94-
94+
@param[in,out] cursor source file cursor
95+
@param[out] corrupted_pages adds corrupted pages if
96+
opt_log_innodb_page_corruption is set
9597
@return XB_FIL_CUR_SUCCESS if some have been read successfully, XB_FIL_CUR_EOF
9698
if there are no more pages to read and XB_FIL_CUR_ERROR on error. */
97-
xb_fil_cur_result_t
98-
xb_fil_cur_read(
99-
/*============*/
100-
xb_fil_cur_t* cursor); /*!< in/out: source file cursor */
101-
99+
xb_fil_cur_result_t xb_fil_cur_read(xb_fil_cur_t *cursor,
100+
CorruptedPages &corrupted_pages);
102101
/************************************************************************
103102
Close the source file cursor opened with xb_fil_cur_open() and its
104103
associated read filter. */

extra/mariabackup/write_filt.cc

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
3232
/************************************************************************
3333
Write-through page write filter. */
3434
static my_bool wf_wt_init(xb_write_filt_ctxt_t *ctxt, char *dst_name,
35-
xb_fil_cur_t *cursor);
35+
xb_fil_cur_t *cursor, CorruptedPages *corrupted_pages);
3636
static my_bool wf_wt_process(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile);
3737

3838
xb_write_filt_t wf_write_through = {
@@ -45,7 +45,7 @@ xb_write_filt_t wf_write_through = {
4545
/************************************************************************
4646
Incremental page write filter. */
4747
static my_bool wf_incremental_init(xb_write_filt_ctxt_t *ctxt, char *dst_name,
48-
xb_fil_cur_t *cursor);
48+
xb_fil_cur_t *cursor, CorruptedPages *corrupted_pages);
4949
static my_bool wf_incremental_process(xb_write_filt_ctxt_t *ctxt,
5050
ds_file_t *dstfile);
5151
static my_bool wf_incremental_finalize(xb_write_filt_ctxt_t *ctxt,
@@ -65,11 +65,11 @@ Initialize incremental page write filter.
6565
@return TRUE on success, FALSE on error. */
6666
static my_bool
6767
wf_incremental_init(xb_write_filt_ctxt_t *ctxt, char *dst_name,
68-
xb_fil_cur_t *cursor)
68+
xb_fil_cur_t *cursor, CorruptedPages *corrupted_pages)
6969
{
7070
char meta_name[FN_REFLEN];
7171
xb_wf_incremental_ctxt_t *cp =
72-
&(ctxt->u.wf_incremental_ctxt);
72+
&(ctxt->wf_incremental_ctxt);
7373

7474
ctxt->cursor = cursor;
7575

@@ -100,7 +100,9 @@ wf_incremental_init(xb_write_filt_ctxt_t *ctxt, char *dst_name,
100100
strcat(dst_name, ".delta");
101101

102102
mach_write_to_4(cp->delta_buf, 0x78747261UL); /*"xtra"*/
103+
103104
cp->npages = 1;
105+
cp->corrupted_pages = corrupted_pages;
104106

105107
return(TRUE);
106108
}
@@ -112,19 +114,20 @@ Run the next batch of pages through incremental page write filter.
112114
static my_bool
113115
wf_incremental_process(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile)
114116
{
115-
ulint i;
117+
unsigned i;
116118
xb_fil_cur_t *cursor = ctxt->cursor;
117119
byte *page;
118120
const ulint page_size = cursor->page_size;
119-
xb_wf_incremental_ctxt_t *cp = &(ctxt->u.wf_incremental_ctxt);
121+
xb_wf_incremental_ctxt_t *cp = &(ctxt->wf_incremental_ctxt);
120122

121123
for (i = 0, page = cursor->buf; i < cursor->buf_npages;
122124
i++, page += page_size) {
123125

124-
if (incremental_lsn >= mach_read_from_8(page + FIL_PAGE_LSN)) {
125-
126+
if ((!cp->corrupted_pages ||
127+
!cp->corrupted_pages->contains(cursor->node->space->id,
128+
cursor->buf_page_no + i)) &&
129+
incremental_lsn >= mach_read_from_8(page + FIL_PAGE_LSN))
126130
continue;
127-
}
128131

129132
/* updated page */
130133
if (cp->npages == page_size / 4) {
@@ -161,7 +164,7 @@ wf_incremental_finalize(xb_write_filt_ctxt_t *ctxt, ds_file_t *dstfile)
161164
{
162165
xb_fil_cur_t *cursor = ctxt->cursor;
163166
const ulint page_size = cursor->page_size;
164-
xb_wf_incremental_ctxt_t *cp = &(ctxt->u.wf_incremental_ctxt);
167+
xb_wf_incremental_ctxt_t *cp = &(ctxt->wf_incremental_ctxt);
165168

166169
if (cp->npages != page_size / 4) {
167170
mach_write_to_4(cp->delta_buf + cp->npages * 4, 0xFFFFFFFFUL);
@@ -183,7 +186,7 @@ Free the incremental page write filter's buffer. */
183186
static void
184187
wf_incremental_deinit(xb_write_filt_ctxt_t *ctxt)
185188
{
186-
xb_wf_incremental_ctxt_t *cp = &(ctxt->u.wf_incremental_ctxt);
189+
xb_wf_incremental_ctxt_t *cp = &(ctxt->wf_incremental_ctxt);
187190
my_large_free(cp->delta_buf, cp->delta_buf_size);
188191
}
189192

@@ -193,7 +196,7 @@ Initialize the write-through page write filter.
193196
@return TRUE on success, FALSE on error. */
194197
static my_bool
195198
wf_wt_init(xb_write_filt_ctxt_t *ctxt, char *dst_name __attribute__((unused)),
196-
xb_fil_cur_t *cursor)
199+
xb_fil_cur_t *cursor, CorruptedPages *)
197200
{
198201
ctxt->cursor = cursor;
199202

0 commit comments

Comments
 (0)