Skip to content

Commit 33f70c4

Browse files
committed
MDEV-13869 MariaDB slow start
When code from MySQL 5.7.9 was merged to MariaDB 10.2.2 in commit 2e814d4 an assignment validate=true was inadvertently added to the function dict_check_sys_tables(). This causes InnoDB to open every single .ibd file on startup, even when no crash recovery was needed. Simply removing the assignment would make some tests fail. We do the best to retain almost the same level of inconsistency detection. In the test innodb.table_flags, access to one of the tables will not be blocked despite inconsistent flags. dict_check_sys_tables(): Remove the problematic assignment, and skip validation in normal startup. dict_load_table_one(): If the .ibd file cannot be opened, mark the table as corrupted and unreadable. fil_node_open_file(): Validate FSP_SPACE_FLAGS with the expected flags. If reading the tablespace fails, invalidate node->handle instead of letting it remain stale. This bug was caught by a fil_validate() assertion failure. fsp_flags_try_adjust(): If the tablespace file is invalid, do nothing.
1 parent 7a106d1 commit 33f70c4

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

mysql-test/suite/innodb/r/table_flags.result

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,21 @@ SHOW CREATE TABLE tr;
116116
ERROR 42S02: Table 'test.tr' doesn't exist in engine
117117
SHOW CREATE TABLE tc;
118118
ERROR 42S02: Table 'test.tc' doesn't exist in engine
119+
SELECT * FROM tc;
120+
ERROR 42S02: Table 'test.tc' doesn't exist in engine
119121
SHOW CREATE TABLE td;
120-
ERROR 42S02: Table 'test.td' doesn't exist in engine
122+
Table Create Table
123+
td CREATE TABLE `td` (
124+
`a` int(11) NOT NULL,
125+
PRIMARY KEY (`a`)
126+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC
127+
SELECT * FROM td;
128+
a
121129
SHOW CREATE TABLE tz;
122130
ERROR 42S02: Table 'test.tz' doesn't exist in engine
123131
SHOW CREATE TABLE tp;
124132
ERROR 42S02: Table 'test.tp' doesn't exist in engine
125-
FOUND 6 /InnoDB: Table `test`.`t[czp]` in InnoDB data dictionary contains invalid flags\. SYS_TABLES\.TYPE=(129|289|3873|1232[13]) SYS_TABLES\.N_COLS=2147483649/ in mysqld.1.err
126-
FOUND 2 /InnoDB: Refusing to load '\..test.td\.ibd' \(id=3, flags=0x1?[2ae]1\); dictionary contains id=3, flags=0x10[01][2ae]1\b/ in mysqld.1.err
133+
FOUND 7 /InnoDB: Table `test`.`t[czp]` in InnoDB data dictionary contains invalid flags\. SYS_TABLES\.TYPE=(129|289|3873|1232[13]) SYS_TABLES\.N_COLS=2147483649/ in mysqld.1.err
127134
FOUND 2 /InnoDB: Table `test`\.`tr` in InnoDB data dictionary contains invalid flags\. SYS_TABLES\.TYPE=65 SYS_TABLES\.MIX_LEN=4294967295\b/ in mysqld.1.err
128135
Restoring SYS_TABLES clustered index root page (8)
129136
SHOW CREATE TABLE tr;

mysql-test/suite/innodb/t/log_file_name.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ call mtr.add_suppression("InnoDB: Cannot rename.*because the target file exists"
163163
call mtr.add_suppression("InnoDB: Log scan aborted at LSN");
164164
# The following are for the --innodb-force-recovery=1 with broken u* tables:
165165
call mtr.add_suppression("InnoDB: Header page consists of zero bytes in datafile: .*u1.ibd");
166+
call mtr.add_suppression("InnoDB: The size of the file .*u1\\.ibd is only 16384 bytes, should be at least 65536");
166167
call mtr.add_suppression("InnoDB: The error means the system cannot find the path specified");
167168
call mtr.add_suppression("InnoDB: .*you must create directories");
168169
call mtr.add_suppression("InnoDB: Cannot open datafile for read-only: '.*u[1-5]\.ibd'");

mysql-test/suite/innodb/t/table_flags.test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ call mtr.add_suppression("InnoDB: Ignoring tablespace for `test`.`td` because it
1414
call mtr.add_suppression("InnoDB: Operating system error number .* in a file operation");
1515
call mtr.add_suppression("InnoDB: The error means the system cannot find the path specified");
1616
call mtr.add_suppression("InnoDB: If you are installing InnoDB, remember that you must create directories yourself");
17+
call mtr.add_suppression("InnoDB: adjusting FSP_SPACE_FLAGS of tablespace");
1718
FLUSH TABLES;
1819
--enable_query_log
1920

@@ -133,7 +134,9 @@ SHOW CREATE TABLE tr;
133134
--error ER_NO_SUCH_TABLE_IN_ENGINE
134135
SHOW CREATE TABLE tc;
135136
--error ER_NO_SUCH_TABLE_IN_ENGINE
137+
SELECT * FROM tc;
136138
SHOW CREATE TABLE td;
139+
SELECT * FROM td;
137140
--error ER_NO_SUCH_TABLE_IN_ENGINE
138141
SHOW CREATE TABLE tz;
139142
--error ER_NO_SUCH_TABLE_IN_ENGINE
@@ -144,8 +147,6 @@ SHOW CREATE TABLE tp;
144147
let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
145148
--let SEARCH_PATTERN= InnoDB: Table `test`.`t[czp]` in InnoDB data dictionary contains invalid flags\. SYS_TABLES\.TYPE=(129|289|3873|1232[13]) SYS_TABLES\.N_COLS=2147483649
146149
--source include/search_pattern_in_file.inc
147-
--let SEARCH_PATTERN= InnoDB: Refusing to load '\..test.td\.ibd' \(id=3, flags=0x1?[2ae]1\); dictionary contains id=3, flags=0x10[01][2ae]1\b
148-
--source include/search_pattern_in_file.inc
149150
--let SEARCH_PATTERN= InnoDB: Table `test`\.`tr` in InnoDB data dictionary contains invalid flags\. SYS_TABLES\.TYPE=65 SYS_TABLES\.MIX_LEN=4294967295\b
150151
--source include/search_pattern_in_file.inc
151152

storage/innobase/dict/dict0load.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2016, 2017, MariaDB Corporation.
4+
Copyright (c) 2016, 2018, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -1471,8 +1471,6 @@ dict_check_sys_tables(
14711471
char* filepath = dict_get_first_path(space_id);
14721472

14731473
/* Check that the .ibd file exists. */
1474-
validate = true; /* Encryption */
1475-
14761474
dberr_t err = fil_ibd_open(
14771475
validate,
14781476
!srv_read_only_mode && srv_log_file_size != 0,
@@ -3078,6 +3076,12 @@ dict_load_table_one(
30783076
} else {
30793077
dict_mem_table_fill_foreign_vcol_set(table);
30803078
table->fk_max_recusive_level = 0;
3079+
3080+
if (table->space
3081+
&& !fil_space_get_size(table->space)) {
3082+
table->corrupted = true;
3083+
table->file_unreadable = true;
3084+
}
30813085
}
30823086
} else {
30833087
dict_index_t* index;

storage/innobase/fil/fil0fil.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ fil_node_open_file(
624624
<< " is only " << size_bytes
625625
<< " bytes, should be at least " << min_size;
626626
os_file_close(node->handle);
627+
node->handle = OS_FILE_CLOSED;
627628
return(false);
628629
}
629630

@@ -661,10 +662,12 @@ fil_node_open_file(
661662

662663
ut_free(buf2);
663664
os_file_close(node->handle);
665+
node->handle = OS_FILE_CLOSED;
664666

665667
if (!fsp_flags_is_valid(flags, space->id)) {
666668
ulint cflags = fsp_flags_convert_from_101(flags);
667-
if (cflags == ULINT_UNDEFINED) {
669+
if (cflags == ULINT_UNDEFINED
670+
|| (cflags ^ space->flags) & ~FSP_FLAGS_MEM_MASK) {
668671
ib::error()
669672
<< "Expected tablespace flags "
670673
<< ib::hex(space->flags)
@@ -4626,7 +4629,9 @@ fsp_flags_try_adjust(ulint space_id, ulint flags)
46264629
{
46274630
ut_ad(!srv_read_only_mode);
46284631
ut_ad(fsp_flags_is_valid(flags, space_id));
4629-
4632+
if (!fil_space_get_size(space_id)) {
4633+
return;
4634+
}
46304635
mtr_t mtr;
46314636
mtr.start();
46324637
if (buf_block_t* b = buf_page_get(

0 commit comments

Comments
 (0)