Skip to content

Commit

Permalink
Merge 10.1 into 10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed Dec 14, 2018
2 parents a2f2f68 + fb252f7 commit 94fa02f
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 21 deletions.
70 changes: 49 additions & 21 deletions extra/mariabackup/fil_cur.cc
Expand Up @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#include <trx0sys.h>

#include "fil_cur.h"
#include "fil0crypt.h"
#include "common.h"
#include "read_filt.h"
#include "xtrabackup.h"
Expand Down Expand Up @@ -231,7 +232,7 @@ xb_fil_cur_open(

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

const page_size_t page_size(cursor->node->space->flags);
const page_size_t page_size(node->space->flags);
cursor->page_size = page_size;

/* Allocate read buffer */
Expand All @@ -247,6 +248,19 @@ xb_fil_cur_open(
cursor->buf_page_no = 0;
cursor->thread_n = thread_n;

if (!node->space->crypt_data
&& os_file_read(IORequestRead,
node->handle, cursor->buf, 0,
page_size.physical())) {
mutex_enter(&fil_system->mutex);
if (!node->space->crypt_data) {
node->space->crypt_data
= fil_space_read_crypt_data(page_size,
cursor->buf);
}
mutex_exit(&fil_system->mutex);
}

cursor->space_size = (ulint)(cursor->statinfo.st_size
/ page_size.physical());

Expand All @@ -268,14 +282,15 @@ xb_fil_cur_read(
/*============*/
xb_fil_cur_t* cursor) /*!< in/out: source file cursor */
{
ibool success;
byte* page;
ulint i;
ulint npages;
ulint retry_count;
xb_fil_cur_result_t ret;
ib_int64_t offset;
ib_int64_t to_read;
byte tmp_frame[UNIV_PAGE_SIZE_MAX];
byte tmp_page[UNIV_PAGE_SIZE_MAX];
const ulint page_size = cursor->page_size.physical();
xb_ad(!cursor->is_system() || page_size == UNIV_PAGE_SIZE);

Expand Down Expand Up @@ -318,6 +333,12 @@ xb_fil_cur_read(
retry_count = 10;
ret = XB_FIL_CUR_SUCCESS;

fil_space_t *space = fil_space_acquire_for_io(cursor->space_id);

if (!space) {
return XB_FIL_CUR_ERROR;
}

read_retry:
xtrabackup_io_throttling();

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

FilSpace space(cursor->space_id);

if (!space()) {
return(XB_FIL_CUR_ERROR);
}

success = os_file_read(IORequestRead,
cursor->file, cursor->buf, offset,
(ulint) to_read);
if (!success) {
return(XB_FIL_CUR_ERROR);
if (!os_file_read(IORequestRead, cursor->file, cursor->buf, offset,
(ulint) to_read)) {
ret = XB_FIL_CUR_ERROR;
goto func_exit;
}

/* check pages for corruption and re-read if necessary. i.e. in case of
partially written pages */
for (page = cursor->buf, i = 0; i < npages;
Expand All @@ -349,11 +362,26 @@ xb_fil_cur_read(
page_no >= FSP_EXTENT_SIZE &&
page_no < FSP_EXTENT_SIZE * 3) {
/* We ignore the doublewrite buffer pages */
} else if (!fil_space_verify_crypt_checksum(
page, cursor->page_size, space->id, page_no)
&& buf_page_is_corrupted(true, page,
cursor->page_size,
space)) {
} else if (fil_space_verify_crypt_checksum(
page, cursor->page_size,
space->id, page_no)) {
ut_ad(mach_read_from_4(page + FIL_PAGE_SPACE_ID)
== space->id);

bool decrypted = false;

memcpy(tmp_page, page, page_size);

if (!fil_space_decrypt(space, tmp_frame,
tmp_page, &decrypted)
|| buf_page_is_corrupted(true, tmp_page,
cursor->page_size,
space)) {
goto corrupted;
}
} else if (buf_page_is_corrupted(true, page, cursor->page_size,
space)) {
corrupted:
retry_count--;
if (retry_count == 0) {
msg("[%02u] mariabackup: "
Expand All @@ -373,15 +401,15 @@ xb_fil_cur_read(
}

os_thread_sleep(100000);

goto read_retry;
}
cursor->buf_read += page_size;
cursor->buf_npages++;
}

posix_fadvise(cursor->file, offset, to_read, POSIX_FADV_DONTNEED);

func_exit:
fil_space_release_for_io(space);
return(ret);
}

Expand Down
6 changes: 6 additions & 0 deletions mysql-test/suite/mariabackup/encrypted_page_corruption.opt
@@ -0,0 +1,6 @@
--innodb-encrypt-log=ON
--plugin-load-add=$FILE_KEY_MANAGEMENT_SO
--loose-file-key-management
--loose-file-key-management-filekey=FILE:$MTR_SUITE_DIR/filekeys-data.key
--loose-file-key-management-filename=$MTR_SUITE_DIR/filekeys-data.enc
--loose-file-key-management-encryption-algorithm=aes_cbc
7 changes: 7 additions & 0 deletions mysql-test/suite/mariabackup/encrypted_page_corruption.result
@@ -0,0 +1,7 @@
call mtr.add_suppression("\\[ERROR\\] InnoDB: The page .* in file .* cannot be decrypted.");
CREATE TABLE t1(c VARCHAR(128)) ENGINE INNODB, encrypted=yes;
insert into t1 select repeat('a',100);
# Corrupt the table
# xtrabackup backup
FOUND 1 /Database page corruption detected/ in backup.log
drop table t1;
50 changes: 50 additions & 0 deletions mysql-test/suite/mariabackup/encrypted_page_corruption.test
@@ -0,0 +1,50 @@
--source include/have_file_key_management.inc

call mtr.add_suppression("\\[ERROR\\] InnoDB: The page .* in file .* cannot be decrypted.");
CREATE TABLE t1(c VARCHAR(128)) ENGINE INNODB, encrypted=yes;
insert into t1 select repeat('a',100);

let $MYSQLD_DATADIR=`select @@datadir`;
let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd;

--source include/shutdown_mysqld.inc

--echo # Corrupt the table

perl;
use strict;
use warnings;
use Fcntl qw(:DEFAULT :seek);

my $ibd_file = $ENV{'t1_IBD'};

my $chunk;
my $len;

sysopen IBD_FILE, $ibd_file, O_RDWR || die "Unable to open $ibd_file";
sysseek IBD_FILE, 16384 * 3, SEEK_CUR;
$chunk = '\xAA\xAA\xAA\xAA';
syswrite IBD_FILE, $chunk, 4;

close IBD_FILE;
EOF

--source include/start_mysqld.inc

echo # xtrabackup backup;
let $targetdir=$MYSQLTEST_VARDIR/tmp/backup;
let $backuplog=$MYSQLTEST_VARDIR/tmp/backup.log;

--disable_result_log
--error 1
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir > $backuplog;
--enable_result_log


--let SEARCH_PATTERN=Database page corruption detected
--let SEARCH_FILE=$backuplog
--source include/search_pattern_in_file.inc
remove_file $backuplog;

drop table t1;
rmdir $targetdir;

0 comments on commit 94fa02f

Please sign in to comment.