Skip to content

Commit

Permalink
MDEV-13105 InnoDB fails to load a table with PAGE_COMPRESSION_LEVEL a…
Browse files Browse the repository at this point in the history
…fter upgrade from 10.1.20

When using innodb_page_size=16k, InnoDB tables
that were created in MariaDB 10.1.0 to 10.1.20 with
PAGE_COMPRESSED=1 and
PAGE_COMPRESSION_LEVEL=2 or PAGE_COMPRESSION_LEVEL=3
would fail to load.

fsp_flags_is_valid(): When using innodb_page_size=16k, use a
more strict check for .ibd files, with the assumption that
nobody would try to use different-page-size files.
  • Loading branch information
dr-m committed Jul 5, 2017
1 parent f2931b1 commit e3d3147
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion extra/mariabackup/fil_cur.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ xb_fil_cur_open(
return(XB_FIL_CUR_SKIP);
}

if (!fsp_flags_is_valid(flags)) {
if (!fsp_flags_is_valid(flags, cursor->space_id)) {
ulint cflags = fsp_flags_convert_from_101(flags);
if (cflags == ULINT_UNDEFINED) {
msg("[%02u] xtrabackup: Error: Invalid "
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/innodb/include/ibd_convert.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sub convert_to_mariadb_101
# FIL_PAGE_DATA + FSP_SPACE_FLAGS = 38 + 16 = 54 bytes from the start
my($flags) = unpack "x[54]N", $_;
my $badflags = ($flags & 0x3f);
my $compression_level=6;
my $compression_level=3;
$badflags |= 1<<6|$compression_level<<7 if ($flags & 1 << 16);
$badflags |= ($flags & 15 << 6) << 7; # PAGE_SSIZE

Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/innodb/r/101_compatibility.result
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SET INNODB_STRICT_MODE=OFF;
CREATE TABLE tz(a INT)ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1;
SET INNODB_STRICT_MODE=ON;
CREATE TABLE tdd(a INT) ENGINE=InnoDB, DATA DIRECTORY='MYSQL_TMP_DIR';
CREATE TABLE tp(a INT) ENGINE=InnoDB page_compressed=1;
CREATE TABLE tp(a INT) ENGINE=InnoDB ROW_FORMAT=DYNAMIC PAGE_COMPRESSED=1;
CREATE TABLE ti(a INT) ENGINE=InnoDB;
FLUSH TABLES ti FOR EXPORT;
backup: ti
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/innodb/t/101_compatibility.test
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SET INNODB_STRICT_MODE=ON;
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
EVAL CREATE TABLE tdd(a INT) ENGINE=InnoDB, DATA DIRECTORY='$MYSQL_TMP_DIR';

CREATE TABLE tp(a INT) ENGINE=InnoDB page_compressed=1;
CREATE TABLE tp(a INT) ENGINE=InnoDB ROW_FORMAT=DYNAMIC PAGE_COMPRESSED=1;
CREATE TABLE ti(a INT) ENGINE=InnoDB;
FLUSH TABLES ti FOR EXPORT;
perl;
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/buf/buf0dblwr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ buf_dblwr_process()
if (page_no == 0) {
/* Check the FSP_SPACE_FLAGS. */
ulint flags = fsp_header_get_flags(page);
if (!fsp_flags_is_valid(flags)
if (!fsp_flags_is_valid(flags, space_id)
&& fsp_flags_convert_from_101(flags)
== ULINT_UNDEFINED) {
ib::warn() << "Ignoring a doublewrite copy"
Expand Down
12 changes: 6 additions & 6 deletions storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ fil_node_open_file(
ut_free(buf2);
os_file_close(node->handle);

if (!fsp_flags_is_valid(flags)) {
if (!fsp_flags_is_valid(flags, space->id)) {
ulint cflags = fsp_flags_convert_from_101(flags);
if (cflags == ULINT_UNDEFINED) {
ib::error()
Expand Down Expand Up @@ -1601,7 +1601,7 @@ fil_space_create(
fil_space_t* space;

ut_ad(fil_system);
ut_ad(fsp_flags_is_valid(flags & ~FSP_FLAGS_MEM_MASK));
ut_ad(fsp_flags_is_valid(flags & ~FSP_FLAGS_MEM_MASK, id));
ut_ad(purpose == FIL_TYPE_LOG
|| srv_page_size == UNIV_PAGE_SIZE_ORIG || flags != 0);

Expand Down Expand Up @@ -2388,7 +2388,7 @@ fil_op_write_log(
ulint len;

ut_ad(first_page_no == 0);
ut_ad(fsp_flags_is_valid(flags));
ut_ad(fsp_flags_is_valid(flags, space_id));

/* fil_name_parse() requires that there be at least one path
separator and that the file path end with ".ibd". */
Expand Down Expand Up @@ -3794,7 +3794,7 @@ fil_ibd_create(
ut_ad(!srv_read_only_mode);
ut_a(space_id < SRV_LOG_SPACE_FIRST_ID);
ut_a(size >= FIL_IBD_FILE_INITIAL_SIZE);
ut_a(fsp_flags_is_valid(flags & ~FSP_FLAGS_MEM_MASK));
ut_a(fsp_flags_is_valid(flags & ~FSP_FLAGS_MEM_MASK, space_id));

/* Create the subdirectories in the path, if they are
not there already. */
Expand Down Expand Up @@ -4089,7 +4089,7 @@ fil_ibd_open(
return(DB_CORRUPTION);
}

ut_ad(fsp_flags_is_valid(flags & ~FSP_FLAGS_MEM_MASK));
ut_ad(fsp_flags_is_valid(flags & ~FSP_FLAGS_MEM_MASK, id));
df_default.init(space_name, flags);
df_dict.init(space_name, flags);
df_remote.init(space_name, flags);
Expand Down Expand Up @@ -4737,7 +4737,7 @@ void
fsp_flags_try_adjust(ulint space_id, ulint flags)
{
ut_ad(!srv_read_only_mode);
ut_ad(fsp_flags_is_valid(flags));
ut_ad(fsp_flags_is_valid(flags, space_id));

mtr_t mtr;
mtr.start();
Expand Down
10 changes: 4 additions & 6 deletions storage/innobase/fsp/fsp0file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ Datafile::read_first_page(bool read_only_mode)
if (m_order == 0) {
m_space_id = fsp_header_get_space_id(m_first_page);
m_flags = fsp_header_get_flags(m_first_page);
if (!fsp_flags_is_valid(m_flags)) {
if (!fsp_flags_is_valid(m_flags, m_space_id)) {
ulint cflags = fsp_flags_convert_from_101(m_flags);
if (cflags == ULINT_UNDEFINED) {
ib::error()
Expand Down Expand Up @@ -524,9 +524,7 @@ Datafile::validate_first_page(lsn_t* flush_lsn)
}

/* Check if the whole page is blank. */
if (error_txt == NULL
&& m_space_id == srv_sys_space.space_id()
&& !m_flags) {
if (error_txt == NULL && !m_space_id && !m_flags) {
const byte* b = m_first_page;
ulint nonzero_bytes = UNIV_PAGE_SIZE;

Expand Down Expand Up @@ -558,7 +556,7 @@ Datafile::validate_first_page(lsn_t* flush_lsn)
free_first_page();

return(DB_ERROR);
} else if (!fsp_flags_is_valid(m_flags)) {
} else if (!fsp_flags_is_valid(m_flags, m_space_id)) {
/* Tablespace flags must be valid. */
error_txt = "Tablespace flags are invalid";
} else if (page_get_page_no(m_first_page) != 0) {
Expand Down Expand Up @@ -799,7 +797,7 @@ Datafile::restore_from_doublewrite()
ulint flags = mach_read_from_4(
FSP_HEADER_OFFSET + FSP_SPACE_FLAGS + page);

if (!fsp_flags_is_valid(flags)) {
if (!fsp_flags_is_valid(flags, m_space_id)) {
ulint cflags = fsp_flags_convert_from_101(flags);
if (cflags == ULINT_UNDEFINED) {
ib::warn()
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/fsp/fsp0fsp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ fsp_header_init_fields(
ulint flags) /*!< in: tablespace flags (FSP_SPACE_FLAGS) */
{
flags &= ~FSP_FLAGS_MEM_MASK;
ut_a(fsp_flags_is_valid(flags));
ut_a(fsp_flags_is_valid(flags, space_id));

mach_write_to_4(FSP_HEADER_OFFSET + FSP_SPACE_ID + page,
space_id);
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/dict0dict.ic
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ dict_tf_to_fsp_flags(ulint table_flags)
fsp_flags |= FSP_FLAGS_MASK_PAGE_COMPRESSION;
}

ut_a(fsp_flags_is_valid(fsp_flags));
ut_a(fsp_flags_is_valid(fsp_flags, false));

if (DICT_TF_HAS_DATA_DIR(table_flags)) {
fsp_flags |= 1U << FSP_FLAGS_MEM_DATA_DIR;
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/include/fsp0fsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ fsp_flags_convert_from_101(ulint flags)
flags = ((flags & 0x3f) | ssize << FSP_FLAGS_POS_PAGE_SSIZE
| FSP_FLAGS_GET_PAGE_COMPRESSION_MARIADB101(flags)
<< FSP_FLAGS_POS_PAGE_COMPRESSION);
ut_ad(fsp_flags_is_valid(flags));
ut_ad(fsp_flags_is_valid(flags, false));
return(flags);
}

Expand All @@ -793,7 +793,7 @@ bool
fsp_flags_match(ulint expected, ulint actual)
{
expected &= ~FSP_FLAGS_MEM_MASK;
ut_ad(fsp_flags_is_valid(expected));
ut_ad(fsp_flags_is_valid(expected, false));

if (actual == expected) {
return(true);
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/include/fsp0space.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Tablespace {
@param[in] fsp_flags tablespace flags */
void set_flags(ulint fsp_flags)
{
ut_ad(fsp_flags_is_valid(fsp_flags));
ut_ad(fsp_flags_is_valid(fsp_flags, false));
m_flags = fsp_flags;
}

Expand Down
10 changes: 8 additions & 2 deletions storage/innobase/include/fsp0types.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,12 @@ these are only used in MySQL 5.7 and used for compatibility. */
/** Validate the tablespace flags, which are stored in the
tablespace header at offset FSP_SPACE_FLAGS.
@param[in] flags the contents of FSP_SPACE_FLAGS
@param[in] is_ibd whether this is an .ibd file (not system tablespace)
@return whether the flags are correct (not in the buggy 10.1) format */
MY_ATTRIBUTE((warn_unused_result, const))
UNIV_INLINE
bool
fsp_flags_is_valid(ulint flags)
fsp_flags_is_valid(ulint flags, bool is_ibd)
{
DBUG_EXECUTE_IF("fsp_flags_is_valid_failure",
return(false););
Expand Down Expand Up @@ -422,7 +423,12 @@ fsp_flags_is_valid(ulint flags)
return(false);
}

return(true);
/* The flags do look valid. But, avoid misinterpreting
buggy MariaDB 10.1 format flags for
PAGE_COMPRESSED=1 PAGE_COMPRESSION_LEVEL={0,2,3}
as valid-looking PAGE_SSIZE if this is known to be
an .ibd file and we are using the default innodb_page_size=16k. */
return(ssize == 0 || !is_ibd || srv_page_size != UNIV_PAGE_SIZE_ORIG);
}

#endif /* fsp0types_h */
2 changes: 1 addition & 1 deletion storage/innobase/row/row0import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ AbstractCallback::init(
const page_t* page = block->frame;

m_space_flags = fsp_header_get_flags(page);
if (!fsp_flags_is_valid(m_space_flags)) {
if (!fsp_flags_is_valid(m_space_flags, true)) {
ulint cflags = fsp_flags_convert_from_101(m_space_flags);
if (cflags == ULINT_UNDEFINED) {
ib::error() << "Invalid FSP_SPACE_FLAGS="
Expand Down

0 comments on commit e3d3147

Please sign in to comment.