Skip to content

Commit 94fa02f

Browse files
committed
Merge 10.1 into 10.2
2 parents a2f2f68 + fb252f7 commit 94fa02f

File tree

4 files changed

+112
-21
lines changed

4 files changed

+112
-21
lines changed

extra/mariabackup/fil_cur.cc

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
3030
#include <trx0sys.h>
3131

3232
#include "fil_cur.h"
33+
#include "fil0crypt.h"
3334
#include "common.h"
3435
#include "read_filt.h"
3536
#include "xtrabackup.h"
@@ -231,7 +232,7 @@ xb_fil_cur_open(
231232

232233
posix_fadvise(cursor->file, 0, 0, POSIX_FADV_SEQUENTIAL);
233234

234-
const page_size_t page_size(cursor->node->space->flags);
235+
const page_size_t page_size(node->space->flags);
235236
cursor->page_size = page_size;
236237

237238
/* Allocate read buffer */
@@ -247,6 +248,19 @@ xb_fil_cur_open(
247248
cursor->buf_page_no = 0;
248249
cursor->thread_n = thread_n;
249250

251+
if (!node->space->crypt_data
252+
&& os_file_read(IORequestRead,
253+
node->handle, cursor->buf, 0,
254+
page_size.physical())) {
255+
mutex_enter(&fil_system->mutex);
256+
if (!node->space->crypt_data) {
257+
node->space->crypt_data
258+
= fil_space_read_crypt_data(page_size,
259+
cursor->buf);
260+
}
261+
mutex_exit(&fil_system->mutex);
262+
}
263+
250264
cursor->space_size = (ulint)(cursor->statinfo.st_size
251265
/ page_size.physical());
252266

@@ -268,14 +282,15 @@ xb_fil_cur_read(
268282
/*============*/
269283
xb_fil_cur_t* cursor) /*!< in/out: source file cursor */
270284
{
271-
ibool success;
272285
byte* page;
273286
ulint i;
274287
ulint npages;
275288
ulint retry_count;
276289
xb_fil_cur_result_t ret;
277290
ib_int64_t offset;
278291
ib_int64_t to_read;
292+
byte tmp_frame[UNIV_PAGE_SIZE_MAX];
293+
byte tmp_page[UNIV_PAGE_SIZE_MAX];
279294
const ulint page_size = cursor->page_size.physical();
280295
xb_ad(!cursor->is_system() || page_size == UNIV_PAGE_SIZE);
281296

@@ -318,6 +333,12 @@ xb_fil_cur_read(
318333
retry_count = 10;
319334
ret = XB_FIL_CUR_SUCCESS;
320335

336+
fil_space_t *space = fil_space_acquire_for_io(cursor->space_id);
337+
338+
if (!space) {
339+
return XB_FIL_CUR_ERROR;
340+
}
341+
321342
read_retry:
322343
xtrabackup_io_throttling();
323344

@@ -326,19 +347,11 @@ xb_fil_cur_read(
326347
cursor->buf_offset = offset;
327348
cursor->buf_page_no = (ulint)(offset / cursor->page_size.physical());
328349

329-
FilSpace space(cursor->space_id);
330-
331-
if (!space()) {
332-
return(XB_FIL_CUR_ERROR);
333-
}
334-
335-
success = os_file_read(IORequestRead,
336-
cursor->file, cursor->buf, offset,
337-
(ulint) to_read);
338-
if (!success) {
339-
return(XB_FIL_CUR_ERROR);
350+
if (!os_file_read(IORequestRead, cursor->file, cursor->buf, offset,
351+
(ulint) to_read)) {
352+
ret = XB_FIL_CUR_ERROR;
353+
goto func_exit;
340354
}
341-
342355
/* check pages for corruption and re-read if necessary. i.e. in case of
343356
partially written pages */
344357
for (page = cursor->buf, i = 0; i < npages;
@@ -349,11 +362,26 @@ xb_fil_cur_read(
349362
page_no >= FSP_EXTENT_SIZE &&
350363
page_no < FSP_EXTENT_SIZE * 3) {
351364
/* We ignore the doublewrite buffer pages */
352-
} else if (!fil_space_verify_crypt_checksum(
353-
page, cursor->page_size, space->id, page_no)
354-
&& buf_page_is_corrupted(true, page,
355-
cursor->page_size,
356-
space)) {
365+
} else if (fil_space_verify_crypt_checksum(
366+
page, cursor->page_size,
367+
space->id, page_no)) {
368+
ut_ad(mach_read_from_4(page + FIL_PAGE_SPACE_ID)
369+
== space->id);
370+
371+
bool decrypted = false;
372+
373+
memcpy(tmp_page, page, page_size);
374+
375+
if (!fil_space_decrypt(space, tmp_frame,
376+
tmp_page, &decrypted)
377+
|| buf_page_is_corrupted(true, tmp_page,
378+
cursor->page_size,
379+
space)) {
380+
goto corrupted;
381+
}
382+
} else if (buf_page_is_corrupted(true, page, cursor->page_size,
383+
space)) {
384+
corrupted:
357385
retry_count--;
358386
if (retry_count == 0) {
359387
msg("[%02u] mariabackup: "
@@ -373,15 +401,15 @@ xb_fil_cur_read(
373401
}
374402

375403
os_thread_sleep(100000);
376-
377404
goto read_retry;
378405
}
379406
cursor->buf_read += page_size;
380407
cursor->buf_npages++;
381408
}
382409

383410
posix_fadvise(cursor->file, offset, to_read, POSIX_FADV_DONTNEED);
384-
411+
func_exit:
412+
fil_space_release_for_io(space);
385413
return(ret);
386414
}
387415

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--innodb-encrypt-log=ON
2+
--plugin-load-add=$FILE_KEY_MANAGEMENT_SO
3+
--loose-file-key-management
4+
--loose-file-key-management-filekey=FILE:$MTR_SUITE_DIR/filekeys-data.key
5+
--loose-file-key-management-filename=$MTR_SUITE_DIR/filekeys-data.enc
6+
--loose-file-key-management-encryption-algorithm=aes_cbc
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
call mtr.add_suppression("\\[ERROR\\] InnoDB: The page .* in file .* cannot be decrypted.");
2+
CREATE TABLE t1(c VARCHAR(128)) ENGINE INNODB, encrypted=yes;
3+
insert into t1 select repeat('a',100);
4+
# Corrupt the table
5+
# xtrabackup backup
6+
FOUND 1 /Database page corruption detected/ in backup.log
7+
drop table t1;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--source include/have_file_key_management.inc
2+
3+
call mtr.add_suppression("\\[ERROR\\] InnoDB: The page .* in file .* cannot be decrypted.");
4+
CREATE TABLE t1(c VARCHAR(128)) ENGINE INNODB, encrypted=yes;
5+
insert into t1 select repeat('a',100);
6+
7+
let $MYSQLD_DATADIR=`select @@datadir`;
8+
let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd;
9+
10+
--source include/shutdown_mysqld.inc
11+
12+
--echo # Corrupt the table
13+
14+
perl;
15+
use strict;
16+
use warnings;
17+
use Fcntl qw(:DEFAULT :seek);
18+
19+
my $ibd_file = $ENV{'t1_IBD'};
20+
21+
my $chunk;
22+
my $len;
23+
24+
sysopen IBD_FILE, $ibd_file, O_RDWR || die "Unable to open $ibd_file";
25+
sysseek IBD_FILE, 16384 * 3, SEEK_CUR;
26+
$chunk = '\xAA\xAA\xAA\xAA';
27+
syswrite IBD_FILE, $chunk, 4;
28+
29+
close IBD_FILE;
30+
EOF
31+
32+
--source include/start_mysqld.inc
33+
34+
echo # xtrabackup backup;
35+
let $targetdir=$MYSQLTEST_VARDIR/tmp/backup;
36+
let $backuplog=$MYSQLTEST_VARDIR/tmp/backup.log;
37+
38+
--disable_result_log
39+
--error 1
40+
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir > $backuplog;
41+
--enable_result_log
42+
43+
44+
--let SEARCH_PATTERN=Database page corruption detected
45+
--let SEARCH_FILE=$backuplog
46+
--source include/search_pattern_in_file.inc
47+
remove_file $backuplog;
48+
49+
drop table t1;
50+
rmdir $targetdir;

0 commit comments

Comments
 (0)