summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2018-12-14 16:11:05 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2018-12-14 16:11:05 +0200
commit94fa02f4d067285a57abb125829bfecd219df8fa (patch)
tree9e0a74af53f0d6e77151201e0b42142430ee17c5
parenta2f2f686cbcb239420724fe9b1520089933e36fb (diff)
parentfb252f70c17c0ade38082ca5db198dca68b810ed (diff)
downloadmariadb-git-94fa02f4d067285a57abb125829bfecd219df8fa.tar.gz
Merge 10.1 into 10.2
-rw-r--r--extra/mariabackup/fil_cur.cc70
-rw-r--r--mysql-test/suite/mariabackup/encrypted_page_corruption.opt6
-rw-r--r--mysql-test/suite/mariabackup/encrypted_page_corruption.result7
-rw-r--r--mysql-test/suite/mariabackup/encrypted_page_corruption.test50
4 files changed, 112 insertions, 21 deletions
diff --git a/extra/mariabackup/fil_cur.cc b/extra/mariabackup/fil_cur.cc
index 219ec8845d4..3c601db70a8 100644
--- a/extra/mariabackup/fil_cur.cc
+++ b/extra/mariabackup/fil_cur.cc
@@ -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"
@@ -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 */
@@ -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());
@@ -268,7 +282,6 @@ xb_fil_cur_read(
/*============*/
xb_fil_cur_t* cursor) /*!< in/out: source file cursor */
{
- ibool success;
byte* page;
ulint i;
ulint npages;
@@ -276,6 +289,8 @@ xb_fil_cur_read(
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);
@@ -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();
@@ -326,19 +347,11 @@ read_retry:
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;
@@ -349,11 +362,26 @@ read_retry:
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: "
@@ -373,7 +401,6 @@ read_retry:
}
os_thread_sleep(100000);
-
goto read_retry;
}
cursor->buf_read += page_size;
@@ -381,7 +408,8 @@ read_retry:
}
posix_fadvise(cursor->file, offset, to_read, POSIX_FADV_DONTNEED);
-
+func_exit:
+ fil_space_release_for_io(space);
return(ret);
}
diff --git a/mysql-test/suite/mariabackup/encrypted_page_corruption.opt b/mysql-test/suite/mariabackup/encrypted_page_corruption.opt
new file mode 100644
index 00000000000..74a6450a1ef
--- /dev/null
+++ b/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
diff --git a/mysql-test/suite/mariabackup/encrypted_page_corruption.result b/mysql-test/suite/mariabackup/encrypted_page_corruption.result
new file mode 100644
index 00000000000..bbcd3bba816
--- /dev/null
+++ b/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;
diff --git a/mysql-test/suite/mariabackup/encrypted_page_corruption.test b/mysql-test/suite/mariabackup/encrypted_page_corruption.test
new file mode 100644
index 00000000000..f8f7bdb6567
--- /dev/null
+++ b/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;