Skip to content

Commit 1e6e199

Browse files
Allen Laibjornmu
authored andcommitted
Fixed bug#22538749 IMPORT OF ENCRYPTED DBSPACE FAILS WITH MASTER KEY ERROR
In importing, we need to skip getting key information from data file. The key information should be acheived from .cfp file. Reviewed-by: Jimmy Yang<[email protected]> RB: 11492 (cherry picked from commit 2091b92ff866f0109e8bd4801e827473d5dfa955)
1 parent 44696d6 commit 1e6e199

File tree

6 files changed

+35
-18
lines changed

6 files changed

+35
-18
lines changed

storage/innobase/fil/fil0fil.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,6 +3785,7 @@ fil_ibd_open(
37853785
RemoteDatafile df_remote; /* remote location */
37863786
ulint tablespaces_found = 0;
37873787
ulint valid_tablespaces_found = 0;
3788+
bool for_import = (purpose == FIL_TYPE_IMPORT);
37883789

37893790
ut_ad(!fix_dict || rw_lock_own(dict_operation_lock, RW_LOCK_X));
37903791

@@ -3910,13 +3911,16 @@ fil_ibd_open(
39103911
/* Read and validate the first page of these three tablespace
39113912
locations, if found. */
39123913
valid_tablespaces_found +=
3913-
(df_remote.validate_to_dd(id, flags) == DB_SUCCESS) ? 1 : 0;
3914+
(df_remote.validate_to_dd(id, flags, for_import)
3915+
== DB_SUCCESS) ? 1 : 0;
39143916

39153917
valid_tablespaces_found +=
3916-
(df_default.validate_to_dd(id, flags) == DB_SUCCESS) ? 1 : 0;
3918+
(df_default.validate_to_dd(id, flags, for_import)
3919+
== DB_SUCCESS) ? 1 : 0;
39173920

39183921
valid_tablespaces_found +=
3919-
(df_dict.validate_to_dd(id, flags) == DB_SUCCESS) ? 1 : 0;
3922+
(df_dict.validate_to_dd(id, flags, for_import)
3923+
== DB_SUCCESS) ? 1 : 0;
39203924

39213925
/* Make sense of these three possible locations.
39223926
First, bail out if no tablespace files were found. */
@@ -4103,7 +4107,7 @@ fil_ibd_open(
41034107

41044108
/* For encryption tablespace, initialize encryption
41054109
information.*/
4106-
if (err == DB_SUCCESS && is_encrypted) {
4110+
if (err == DB_SUCCESS && is_encrypted && !for_import) {
41074111
Datafile& df_current = df_remote.is_open() ?
41084112
df_remote: df_dict.is_open() ?
41094113
df_dict : df_default;

storage/innobase/fsp/fsp0file.cc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,14 @@ space ID and flags. The file should exist and be successfully opened
387387
in order for this function to validate it.
388388
@param[in] space_id The expected tablespace ID.
389389
@param[in] flags The expected tablespace flags.
390+
@param[in] for_import if it is for importing
390391
@retval DB_SUCCESS if tablespace is valid, DB_ERROR if not.
391392
m_is_valid is also set true on success, else false. */
392393
dberr_t
393394
Datafile::validate_to_dd(
394-
ulint space_id,
395-
ulint flags)
395+
ulint space_id,
396+
ulint flags,
397+
bool for_import)
396398
{
397399
dberr_t err;
398400

@@ -403,7 +405,7 @@ Datafile::validate_to_dd(
403405
/* Validate this single-table-tablespace with the data dictionary,
404406
but do not compare the DATA_DIR flag, in case the tablespace was
405407
remotely located. */
406-
err = validate_first_page();
408+
err = validate_first_page(0, for_import);
407409
if (err != DB_SUCCESS) {
408410
return(err);
409411
}
@@ -447,7 +449,7 @@ Datafile::validate_for_recovery()
447449
ut_ad(is_open());
448450
ut_ad(!srv_read_only_mode);
449451

450-
err = validate_first_page();
452+
err = validate_first_page(0, false);
451453

452454
switch (err) {
453455
case DB_SUCCESS:
@@ -459,7 +461,7 @@ Datafile::validate_for_recovery()
459461
}
460462
/* Free the previously read first page and then re-validate. */
461463
free_first_page();
462-
err = validate_first_page();
464+
err = validate_first_page(0, false);
463465
if (err == DB_SUCCESS) {
464466
std::string filepath = fil_space_get_first_path(
465467
m_space_id);
@@ -520,7 +522,7 @@ Datafile::validate_for_recovery()
520522

521523
/* Free the previously read first page and then re-validate. */
522524
free_first_page();
523-
err = validate_first_page();
525+
err = validate_first_page(0, false);
524526
}
525527

526528
if (err == DB_SUCCESS) {
@@ -535,12 +537,14 @@ tablespace is opened. This occurs before the fil_space_t is created
535537
so the Space ID found here must not already be open.
536538
m_is_valid is set true on success, else false.
537539
@param[out] flush_lsn contents of FIL_PAGE_FILE_FLUSH_LSN
540+
@param[in] for_import if it is for importing
538541
(only valid for the first file of the system tablespace)
539542
@retval DB_SUCCESS on if the datafile is valid
540543
@retval DB_CORRUPTION if the datafile is not readable
541544
@retval DB_TABLESPACE_EXISTS if there is a duplicate space_id */
542545
dberr_t
543-
Datafile::validate_first_page(lsn_t* flush_lsn)
546+
Datafile::validate_first_page(lsn_t* flush_lsn,
547+
bool for_import)
544548
{
545549
char* prev_name;
546550
char* prev_filepath;
@@ -631,8 +635,8 @@ Datafile::validate_first_page(lsn_t* flush_lsn)
631635

632636
/* For encrypted tablespace, check the encryption info in the
633637
first page can be decrypt by master key, otherwise, this table
634-
can't be open. */
635-
if (FSP_FLAGS_GET_ENCRYPTION(m_flags)) {
638+
can't be open. And for importing, we skip checking it. */
639+
if (FSP_FLAGS_GET_ENCRYPTION(m_flags) && !for_import) {
636640
m_encryption_key = static_cast<byte*>(
637641
ut_zalloc_nokey(ENCRYPTION_KEY_LEN));
638642
m_encryption_iv = static_cast<byte*>(

storage/innobase/fsp/fsp0sysspace.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 2013, 2015, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 2013, 2016, Oracle and/or its affiliates. All Rights Reserved.
44
55
This program is free software; you can redistribute it and/or modify it under
66
the terms of the GNU General Public License as published by the Free Software
@@ -577,7 +577,7 @@ SysTablespace::read_lsn_and_check_flags(lsn_t* flushed_lsn)
577577
first datafile. */
578578
for (int retry = 0; retry < 2; ++retry) {
579579

580-
err = it->validate_first_page(flushed_lsn);
580+
err = it->validate_first_page(flushed_lsn, false);
581581

582582
if (err != DB_SUCCESS
583583
&& (retry == 1

storage/innobase/include/fsp0file.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,13 @@ class Datafile {
239239
successfully opened in order for this function to validate it.
240240
@param[in] space_id The expected tablespace ID.
241241
@param[in] flags The expected tablespace flags.
242+
@param[in] for_import is it for importing
242243
@retval DB_SUCCESS if tablespace is valid, DB_ERROR if not.
243244
m_is_valid is also set true on success, else false. */
244245
dberr_t validate_to_dd(
245-
ulint space_id,
246-
ulint flags)
246+
ulint space_id,
247+
ulint flags,
248+
bool for_import)
247249
__attribute__((warn_unused_result));
248250

249251
/** Validates this datafile for the purpose of recovery.
@@ -262,11 +264,13 @@ class Datafile {
262264
so the Space ID found here must not already be open.
263265
m_is_valid is set true on success, else false.
264266
@param[out] flush_lsn contents of FIL_PAGE_FILE_FLUSH_LSN
267+
@param[in] for_import if it is for importing
265268
(only valid for the first file of the system tablespace)
266269
@retval DB_SUCCESS on if the datafile is valid
267270
@retval DB_CORRUPTION if the datafile is not readable
268271
@retval DB_TABLESPACE_EXISTS if there is a duplicate space_id */
269-
dberr_t validate_first_page(lsn_t* flush_lsn = 0)
272+
dberr_t validate_first_page(lsn_t* flush_lsn,
273+
bool for_import)
270274
__attribute__((warn_unused_result));
271275

272276
/** Get Datafile::m_name.

storage/innobase/log/log0recv.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,7 @@ fil_write_encryption_parse(
16511651
ut_ad(FSP_FLAGS_GET_ENCRYPTION(space->flags));
16521652

16531653
space->encryption_type = Encryption::AES;
1654+
space->encryption_klen = ENCRYPTION_KEY_LEN;
16541655
}
16551656

16561657
return(ptr);

storage/innobase/os/os0file.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8859,6 +8859,8 @@ Encryption::encrypt(
88598859
case Encryption::AES: {
88608860
lint elen;
88618861

8862+
ut_ad(m_klen == ENCRYPTION_KEY_LEN);
8863+
88628864
elen = my_aes_encrypt(
88638865
src + FIL_PAGE_DATA,
88648866
static_cast<uLong>(main_len),
@@ -9071,6 +9073,8 @@ Encryption::decrypt(
90719073
/* First decrypt the last 2 blocks data of data, since
90729074
data is no block aligned. */
90739075
if (remain_len != 0) {
9076+
ut_ad(m_klen == ENCRYPTION_KEY_LEN);
9077+
90749078
remain_len = MY_AES_BLOCK_SIZE * 2;
90759079

90769080
/* Copy the last 2 blocks. */

0 commit comments

Comments
 (0)