diff --git a/mysql-test/r/restart_fail_when_crash_on_create.result b/mysql-test/r/restart_fail_when_crash_on_create.result new file mode 100644 index 0000000..d959c72 --- /dev/null +++ b/mysql-test/r/restart_fail_when_crash_on_create.result @@ -0,0 +1,6 @@ +SET DEBUG_SYNC= 'wait_for_crash_server WAIT_FOR dummy_signal'; +create table crash_table(c int) engine=innodb; +1 + +In fact, we can just drop the .frm and .ibd here + diff --git a/mysql-test/t/restart_fail_when_crash_on_create.test b/mysql-test/t/restart_fail_when_crash_on_create.test new file mode 100644 index 0000000..6efbbae --- /dev/null +++ b/mysql-test/t/restart_fail_when_crash_on_create.test @@ -0,0 +1,38 @@ +--disable_query_log +call mtr.add_suppression("Try to move the frm and ibd away"); +--enable_query_log + +--connect (conn1, localhost, root, ,) +--connect (conn2, localhost, root, ,) + +--connection conn1 +SET DEBUG_SYNC= 'wait_for_crash_server WAIT_FOR dummy_signal'; +--send create table crash_table(c int) engine=innodb + +--connection conn2 +# make mtr expect the "crash" +--let $_server_id= `SELECT @@server_id` +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect +--exec echo "wait" > $_expect_file_name +--let $_mysqld_datadir= `SELECT @@datadir` + +# clean the error log +--exec > $_mysqld_datadir/../../log/mysqld.1.err + +# crashed, sending SIGSEGV +--let $pid_file_name = `select @@pid_file` +--exec kill -9 `cat $pid_file_name`; +--source include/wait_until_disconnected.inc + + +--enable_reconnect +--exec echo "restart" > $_expect_file_name +--source include/wait_until_connected_again.inc + +--exec grep "Try to move the frm and ibd away" $_mysqld_datadir/../../log/mysqld.1.err | wc -l + +--echo +--echo In fact, we can just drop the .frm and .ibd here +--echo +--remove_file $_mysqld_datadir/test/crash_table.frm +--remove_file $_mysqld_datadir/test/crash_table.ibd diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 16891c3..b6081d9 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -4343,6 +4343,33 @@ fil_load_single_table_tablespace( /* Read the first page of the remote tablespace */ if (def.success) { + /* do not exit when the sizeof .ibd is 0 */ + if (!remote.success) + { + size = os_file_get_size(def.file); + /* 64bit system can permit that, when def.file != -1, result of lseek will not be -1*/ + + /* Every .ibd file is created >= 4 pages in size. Smaller files + cannot be ok. */ + ulong minimum_size = FIL_IBD_FILE_INITIAL_SIZE * UNIV_PAGE_SIZE; + if (size < minimum_size) { +#ifndef UNIV_HOTBACKUP + ib_logf(IB_LOG_LEVEL_ERROR, + "The size of single-table tablespace file %s " + "is only " UINT64PF ", should be at least %lu! Try to move the frm and ibd away.", + def.filepath, size, minimum_size); + + os_file_close(def.file);//close def file but continue start-up + mem_free(tablename); + if (def.filepath) { + mem_free(def.filepath); + } + + return; +#endif /* !UNIV_HOTBACKUP */ + } + } + fil_validate_single_table_tablespace(tablename, &def); if (!def.success) { os_file_close(def.file); diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index ed82e4a..c9c8ce3 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -1753,6 +1753,7 @@ os_file_create_func( retry = false; } + DEBUG_SYNC_C("wait_for_crash_server"); } while (retry); /* We disable OS caching (O_DIRECT) only on data files */