Skip to content
Permalink
Browse files

MDEV-12600: crash during install_db with innodb_page_size=32K and ibd…

…ata1=3M;

Problem was that all doublewrite buffer pages must fit to first
system datafile.

Ported commit 27a34df7882b1f8ed283f22bf83e8bfc523cbfde
Author: Shaohua Wang <shaohua.wang@oracle.com>
Date:   Wed Aug 12 15:55:19 2015 +0800

    BUG#21551464 - SEGFAULT WHILE INITIALIZING DATABASE WHEN
    INNODB_DATA_FILE SIZE IS SMALL

To 10.1 (with extended error printout).

btr_create(): If ibuf header page allocation fails report error and
return FIL_NULL. Similarly if root page allocation fails return a error.

dict_build_table_def_step: If fsp_header_init fails return
error code.

fsp_header_init: returns true if header initialization succeeds
and false if not.

fseg_create_general: report error if segment or page allocation fails.

innobase_init: If first datafile is smaller than 3M and could not
contain all doublewrite buffer pages report error and fail to
initialize InnoDB plugin.

row_truncate_table_for_mysql: report error if fsp header init
fails.

srv_init_abort: New function to report database initialization errors.

srv_undo_tablespaces_init, innobase_start_or_create_for_mysql: If
database initialization fails report error and abort.

trx_rseg_create: If segment header creation fails return.
  • Loading branch information...
janlindstrom committed May 30, 2017
1 parent 6b69871 commit 112b21da37dad0fbb28bc65f9ab5a3ba6c0c2186
@@ -1,2 +1,2 @@
--loose-innodb-sys-indexes
--innodb-data-file-path=ibdata1:1M:autoextend
--innodb-data-file-path=ibdata1:3M:autoextend
@@ -1701,6 +1701,12 @@ btr_create(
space, 0,
IBUF_HEADER + IBUF_TREE_SEG_HEADER, mtr);

if (ibuf_hdr_block == NULL) {
ib_logf(IB_LOG_LEVEL_ERROR,
"Allocation of the first ibuf header page failed.");
return (FIL_NULL);
}

buf_block_dbg_add_level(
ibuf_hdr_block, SYNC_IBUF_TREE_NODE_NEW);

@@ -1714,6 +1720,11 @@ btr_create(
+ IBUF_HEADER + IBUF_TREE_SEG_HEADER,
IBUF_TREE_ROOT_PAGE_NO,
FSP_UP, mtr);

if (!block) {
ib_logf(IB_LOG_LEVEL_ERROR,
"Allocation of the tree root page segment failed.");
}
ut_ad(buf_block_get_page_no(block) == IBUF_TREE_ROOT_PAGE_NO);
} else {
#ifdef UNIV_BLOB_DEBUG
@@ -1726,6 +1737,12 @@ btr_create(
#endif /* UNIV_BLOB_DEBUG */
block = fseg_create(space, 0,
PAGE_HEADER + PAGE_BTR_SEG_TOP, mtr);

if (!block) {
ib_logf(IB_LOG_LEVEL_ERROR,
"Allocation of the btree segment failed.");
}

}

if (block == NULL) {
@@ -1754,6 +1771,8 @@ btr_create(
segment before return. */
btr_free_root(space, zip_size, page_no, mtr);

ib_logf(IB_LOG_LEVEL_ERROR,
"Allocation of the non-ibuf tree segment for leaf pages failed.");
return(FIL_NULL);
}

@@ -321,9 +321,13 @@ dict_build_table_def_step(

mtr_start(&mtr);

fsp_header_init(table->space, FIL_IBD_FILE_INITIAL_SIZE, &mtr);
bool res = fsp_header_init(table->space, FIL_IBD_FILE_INITIAL_SIZE, &mtr);

mtr_commit(&mtr);

if (!res) {
return (DB_ERROR);
}
} else {
/* Create in the system tablespace: disallow Barracuda
features by keeping only the first bit which says whether
@@ -5812,19 +5812,21 @@ fil_report_invalid_page_access(
ulint len, /*!< in: I/O length */
ulint type) /*!< in: I/O type */
{
fprintf(stderr,
"InnoDB: Error: trying to access page number %lu"
" in space %lu,\n"
"InnoDB: space name %s,\n"
"InnoDB: which is outside the tablespace bounds.\n"
"InnoDB: Byte offset %lu, len %lu, i/o type %lu.\n"
"InnoDB: If you get this error at mysqld startup,"
" please check that\n"
"InnoDB: your my.cnf matches the ibdata files"
" that you have in the\n"
"InnoDB: MySQL server.\n",
(ulong) block_offset, (ulong) space_id, space_name,
(ulong) byte_offset, (ulong) len, (ulong) type);
ib_logf(IB_LOG_LEVEL_ERROR,
"Trying to access page number " ULINTPF
" in space " ULINTPF
" space name %s,"
" which is outside the tablespace bounds."
" Byte offset " ULINTPF ", len " ULINTPF " i/o type " ULINTPF ".",
block_offset, space_id, space_name,
byte_offset, len, type);

ib_logf(IB_LOG_LEVEL_FATAL,
"If you get this error at mysqld startup,"
" please check that"
" your my.cnf matches the ibdata files"
" that you have in the"
" MySQL server.");
}

/********************************************************************//**
@@ -6043,11 +6045,10 @@ fil_io(
mutex_exit(&fil_system->mutex);
return(DB_ERROR);
}

fil_report_invalid_page_access(
block_offset, space_id, space->name,
byte_offset, len, type);

ut_error;
}

/* Open file if closed */
@@ -6059,10 +6060,11 @@ fil_io(
ib_logf(IB_LOG_LEVEL_ERROR,
"Trying to do i/o to a tablespace which "
"exists without .ibd data file. "
"i/o type %lu, space id %lu, page no %lu, "
"i/o length %lu bytes",
(ulong) type, (ulong) space_id,
(ulong) block_offset, (ulong) len);
"i/o type " ULINTPF ", space id "
ULINTPF ", page no " ULINTPF ", "
"i/o length " ULINTPF " bytes",
type, space_id,
block_offset, len);

return(DB_TABLESPACE_DELETED);
}
@@ -6082,8 +6084,6 @@ fil_io(
fil_report_invalid_page_access(
block_offset, space_id, space->name, byte_offset,
len, type);

ut_error;
}

/* Now we have made the changes in the data structures of fil_system */
@@ -670,16 +670,18 @@ fsp_header_init_fields(
}

#ifndef UNIV_HOTBACKUP
/**********************************************************************//**
Initializes the space header of a new created space and creates also the
insert buffer tree root if space == 0. */
/** Initializes the space header of a new created space and creates also the
insert buffer tree root if space == 0.
@param[in] space_id space id
@param[in] size current size in blocks
@param[in,out] mtr min-transaction
@return true on success, otherwise false. */
UNIV_INTERN
void
bool
fsp_header_init(
/*============*/
ulint space_id, /*!< in: space id */
ulint size, /*!< in: current size in blocks */
mtr_t* mtr) /*!< in/out: mini-transaction */
ulint space_id,
ulint size,
mtr_t* mtr)
{
fsp_header_t* header;
buf_block_t* block;
@@ -722,11 +724,15 @@ fsp_header_init(
flst_init(header + FSP_SEG_INODES_FREE, mtr);

mlog_write_ull(header + FSP_SEG_ID, 1, mtr);

if (space_id == 0) {
fsp_fill_free_list(FALSE, space_id, header, mtr);
btr_create(DICT_CLUSTERED | DICT_UNIVERSAL | DICT_IBUF,

if (btr_create(DICT_CLUSTERED | DICT_UNIVERSAL | DICT_IBUF,
0, 0, DICT_IBUF_ID_MIN + space_id,
dict_ind_redundant, mtr);
dict_ind_redundant, mtr) == FIL_NULL) {
return (false);
}
} else {
fsp_fill_free_list(TRUE, space_id, header, mtr);
}
@@ -739,6 +745,8 @@ fsp_header_init(
}

fil_space_release(space);

return (true);
}

#endif /* !UNIV_HOTBACKUP */
@@ -2057,6 +2065,10 @@ fseg_create_general(
success = fsp_reserve_free_extents(&n_reserved, space, 2,
FSP_NORMAL, mtr);
if (!success) {
ib_logf(IB_LOG_LEVEL_ERROR,
"Reserving %d free extents failed"
" could reserve only " ULINTPF " extents.",
2, n_reserved);
return(NULL);
}
}
@@ -2066,6 +2078,8 @@ fseg_create_general(
inode = fsp_alloc_seg_inode(space_header, mtr);

if (inode == NULL) {
ib_logf(IB_LOG_LEVEL_ERROR,
"Allocation of a new file segment inode page failed.");

goto funct_exit;
}
@@ -2095,6 +2109,9 @@ fseg_create_general(
inode, 0, FSP_UP, mtr, mtr);

if (block == NULL) {
ib_logf(IB_LOG_LEVEL_ERROR,
"Allocation of a free page from space " ULINTPF " failed.",
space);

fsp_free_seg_inode(space, zip_size, inode, mtr);

@@ -3353,6 +3353,7 @@ innobase_init(
char *default_path;
uint format_id;
ulong num_pll_degree;
ulint min_size = 0;

DBUG_ENTER("innobase_init");
handlerton *innobase_hton= (handlerton*) p;
@@ -3563,6 +3564,19 @@ innobase_init(
goto error;
}

/* All doublewrite buffer pages must fit to first system
datafile and first datafile must be at least 3M. */
min_size = ut_max((3*1024*1024U), (192U*UNIV_PAGE_SIZE));

if ((srv_data_file_sizes[0]*1024*1024) < min_size) {
sql_print_error(
"InnoDB: first datafile is too small current=" ULINTPF
"M it should be at least " ULINTPF "M.",
srv_data_file_sizes[0],
min_size / (1024 * 1024));
goto mem_free_and_error;
}

/* -------------- All log files ---------------------------*/

/* The default dir for log files is the datadir of MySQL */
@@ -520,16 +520,20 @@ fsp_header_init_fields(
ulint space_id, /*!< in: space id */
ulint flags); /*!< in: tablespace flags (FSP_SPACE_FLAGS):
0, or table->flags if newer than COMPACT */
/**********************************************************************//**
Initializes the space header of a new created space and creates also the
insert buffer tree root if space == 0. */
/** Initializes the space header of a new created space and creates also the
insert buffer tree root if space == 0.
@param[in] space_id space id
@param[in] size current size in blocks
@param[in,out] mtr min-transaction
@return true on success, otherwise false. */
UNIV_INTERN
void
bool
fsp_header_init(
/*============*/
ulint space, /*!< in: space id */
ulint size, /*!< in: current size in blocks */
mtr_t* mtr); /*!< in/out: mini-transaction */
ulint space_id,
ulint size,
mtr_t* mtr)
MY_ATTRIBUTE((warn_unused_result));

/**********************************************************************//**
Increases the space size field of a space. */
UNIV_INTERN
@@ -3590,9 +3590,15 @@ row_truncate_table_for_mysql(
} while (index);

mtr_start_trx(&mtr, trx);
fsp_header_init(space_id,
bool ret = fsp_header_init(space_id,
FIL_IBD_FILE_INITIAL_SIZE, &mtr);
mtr_commit(&mtr);

if (!ret) {
table->file_unreadable = true;
err = DB_ERROR;
goto funct_exit;
}
}
} else {
/* Lock all index trees for this table, as we will
@@ -188,6 +188,39 @@ UNIV_INTERN mysql_pfs_key_t srv_master_thread_key;
UNIV_INTERN mysql_pfs_key_t srv_purge_thread_key;
#endif /* UNIV_PFS_THREAD */

/** Innobase start-up aborted. Perform cleanup actions.
@param[in] create_new_db TRUE if new db is being created
@param[in] file File name
@param[in] line Line number
@param[in] err Reason for aborting InnoDB startup
@return DB_SUCCESS or error code. */
static
dberr_t
srv_init_abort(
bool create_new_db,
const char* file,
ulint line,
dberr_t err)
{
if (create_new_db) {
ib_logf(IB_LOG_LEVEL_ERROR,
"Database creation was aborted"
" at %s [" ULINTPF "]"
" with error %s. You may need"
" to delete the ibdata1 file before trying to start"
" up again.",
file, line, ut_strerr(err));
} else {
ib_logf(IB_LOG_LEVEL_ERROR,
"Plugin initialization aborted"
" at %s [" ULINTPF "]"
" with error %s.",
file, line, ut_strerr(err));
}

return(err);
}

/*********************************************************************//**
Convert a numeric string that optionally ends in G or M or K, to a number
containing megabytes.
@@ -1528,18 +1561,26 @@ srv_undo_tablespaces_init(

if (create_new_db) {
mtr_t mtr;
bool ret=true;

mtr_start(&mtr);

/* The undo log tablespace */
for (i = 0; i < n_undo_tablespaces; ++i) {

fsp_header_init(
ret = fsp_header_init(
undo_tablespace_ids[i],
SRV_UNDO_TABLESPACE_SIZE_IN_PAGES, &mtr);
if (!ret) {
break;
}
}

mtr_commit(&mtr);

if (!ret) {
return (srv_init_abort(create_new_db, __FILE__, __LINE__, DB_ERROR));
}
}

return(DB_SUCCESS);
@@ -2378,10 +2419,14 @@ innobase_start_or_create_for_mysql(void)

mtr_start(&mtr);

fsp_header_init(0, sum_of_new_sizes, &mtr);
bool ret = fsp_header_init(0, sum_of_new_sizes, &mtr);

mtr_commit(&mtr);

if (!ret) {
return (srv_init_abort(create_new_db, __FILE__, __LINE__, DB_ERROR));
}

/* To maintain backward compatibility we create only
the first rollback segment before the double write buffer.
All the remaining rollback segments will be created later,
@@ -2809,6 +2854,9 @@ innobase_start_or_create_for_mysql(void)
/* Can only happen if server is read only. */
ut_a(srv_read_only_mode);
srv_undo_logs = ULONG_UNDEFINED;
} else if (srv_available_undo_logs < srv_undo_logs) {
/* Should due to out of file space. */
return (srv_init_abort(create_new_db, __FILE__, __LINE__, DB_ERROR));
}

if (!srv_read_only_mode) {

0 comments on commit 112b21d

Please sign in to comment.
You can’t perform that action at this time.