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 8ae9c86 commit e555540
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 35 deletions.
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 @@ -7,7 +7,7 @@ CREATE TABLE tc(a INT)ENGINE=InnoDB ROW_FORMAT=COMPACT;
CREATE TABLE td(a INT)ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
CREATE TABLE tz(a INT)ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1;
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 @@ -28,7 +28,7 @@ CREATE TABLE tz(a INT)ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1;
--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 @@ -616,7 +616,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_logf(IB_LOG_LEVEL_WARN,
Expand Down
14 changes: 7 additions & 7 deletions storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,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_logf(IB_LOG_LEVEL_ERROR,
Expand Down Expand Up @@ -2366,7 +2366,7 @@ fil_read_first_page(
FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
}

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_logf(IB_LOG_LEVEL_ERROR,
Expand Down Expand Up @@ -2497,7 +2497,7 @@ fil_op_write_log(
ulint len;

log_ptr = mlog_open(mtr, 11 + 2 + 1);
ut_ad(fsp_flags_is_valid(flags));
ut_ad(fsp_flags_is_valid(flags, space_id));

if (!log_ptr) {
/* Logging in mtr is switched off during crash recovery:
Expand Down Expand Up @@ -3718,7 +3718,7 @@ fil_create_new_single_table_tablespace(
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));

if (is_temp) {
/* Temporary table filepath */
Expand Down Expand Up @@ -3979,7 +3979,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(&mtr);
Expand Down Expand Up @@ -4061,7 +4061,7 @@ fil_open_single_table_tablespace(
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));
atomic_writes = fsp_flags_get_atomic_writes(flags);

memset(&def, 0, sizeof(def));
Expand Down Expand Up @@ -4601,7 +4601,7 @@ fil_user_tablespace_restore_page(

flags = mach_read_from_4(FSP_HEADER_OFFSET + FSP_SPACE_FLAGS + page);

if (!fsp_flags_is_valid(flags)) {
if (!fsp_flags_is_valid(flags, fsp->id)) {
ulint cflags = fsp_flags_convert_from_101(flags);
if (cflags == ULINT_UNDEFINED) {
ib_logf(IB_LOG_LEVEL_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 @@ -661,7 +661,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 @@ -934,7 +934,7 @@ dict_tf_to_fsp_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
16 changes: 11 additions & 5 deletions storage/innobase/include/fsp0fsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -788,11 +788,12 @@ fseg_print(
/** 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 All @@ -816,7 +817,7 @@ fsp_flags_is_valid(ulint flags)
bits 10..14 would be nonzero 0bsssaa where sss is
nonzero PAGE_SSIZE (3, 4, 6, or 7)
and aa is ATOMIC_WRITES (not 0b11). */
if (FSP_FLAGS_GET_RESERVED(flags) & ~1) {
if (FSP_FLAGS_GET_RESERVED(flags) & ~1U) {
return(false);
}

Expand All @@ -839,7 +840,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);
}

/** Convert FSP_SPACE_FLAGS from the buggy MariaDB 10.1.0..10.1.20 format.
Expand Down Expand Up @@ -948,7 +954,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 @@ -962,7 +968,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/row/row0import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,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_logf(IB_LOG_LEVEL_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion storage/xtradb/buf/buf0dblwr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,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_logf(IB_LOG_LEVEL_WARN,
Expand Down
14 changes: 7 additions & 7 deletions storage/xtradb/fil/fil0fil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,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_logf(IB_LOG_LEVEL_ERROR,
Expand Down Expand Up @@ -2426,7 +2426,7 @@ fil_read_first_page(
FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
}

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_logf(IB_LOG_LEVEL_ERROR,
Expand Down Expand Up @@ -2541,7 +2541,7 @@ fil_op_write_log(
ulint len;

log_ptr = mlog_open(mtr, 11 + 2 + 1);
ut_ad(fsp_flags_is_valid(flags));
ut_ad(fsp_flags_is_valid(flags, space_id));

if (!log_ptr) {
/* Logging in mtr is switched off during crash recovery:
Expand Down Expand Up @@ -3778,7 +3778,7 @@ fil_create_new_single_table_tablespace(
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));

if (is_temp) {
/* Temporary table filepath */
Expand Down Expand Up @@ -4172,7 +4172,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(&mtr);
Expand Down Expand Up @@ -4254,7 +4254,7 @@ fil_open_single_table_tablespace(
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));
atomic_writes = fsp_flags_get_atomic_writes(flags);

memset(&def, 0, sizeof(def));
Expand Down Expand Up @@ -4795,7 +4795,7 @@ fil_user_tablespace_restore_page(

flags = mach_read_from_4(FSP_HEADER_OFFSET + FSP_SPACE_FLAGS + page);

if (!fsp_flags_is_valid(flags)) {
if (!fsp_flags_is_valid(flags, fsp->id)) {
ulint cflags = fsp_flags_convert_from_101(flags);
if (cflags == ULINT_UNDEFINED) {
ib_logf(IB_LOG_LEVEL_WARN,
Expand Down
2 changes: 1 addition & 1 deletion storage/xtradb/fsp/fsp0fsp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,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/xtradb/include/dict0dict.ic
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ dict_tf_to_fsp_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
16 changes: 11 additions & 5 deletions storage/xtradb/include/fsp0fsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,12 @@ fseg_print(
/** 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 All @@ -815,7 +816,7 @@ fsp_flags_is_valid(ulint flags)
bits 10..14 would be nonzero 0bsssaa where sss is
nonzero PAGE_SSIZE (3, 4, 6, or 7)
and aa is ATOMIC_WRITES (not 0b11). */
if (FSP_FLAGS_GET_RESERVED(flags) & ~1) {
if (FSP_FLAGS_GET_RESERVED(flags) & ~1U) {
return(false);
}

Expand All @@ -838,7 +839,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);
}

/** Convert FSP_SPACE_FLAGS from the buggy MariaDB 10.1.0..10.1.20 format.
Expand Down Expand Up @@ -947,7 +953,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 @@ -961,7 +967,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/xtradb/row/row0import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,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_logf(IB_LOG_LEVEL_ERROR,
Expand Down

0 comments on commit e555540

Please sign in to comment.