Skip to content

Commit

Permalink
MDEV-19445/MDEV-16678 fixup: Acquire proper MDL on innodb_ft_aux_table
Browse files Browse the repository at this point in the history
In commit 2647fd1 (MDEV-19445)
we fixed a race condition around the INFORMATION_SCHEMA tables
that access the table identified by the global variable
innodb_ft_aux_table. Thanks to MDEV-16678 we could fix it
even better by using MDL instead of the InnoDB dict_sys latches.
  • Loading branch information
dr-m committed Jul 29, 2021
1 parent e305493 commit 0aa2bc7
Showing 1 changed file with 22 additions and 44 deletions.
66 changes: 22 additions & 44 deletions storage/innobase/handler/i_s.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2401,21 +2401,17 @@ i_s_fts_deleted_generic_fill(

RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name.str);

/* Prevent DROP of the internal tables for fulltext indexes.
FIXME: acquire DDL-blocking MDL on the user table name! */
dict_sys.freeze();

MDL_ticket* mdl_ticket = nullptr;
user_table = dict_table_open_on_id(
innodb_ft_aux_table_id, FALSE, DICT_TABLE_OP_NORMAL);
innodb_ft_aux_table_id, false, DICT_TABLE_OP_NORMAL,
thd, &mdl_ticket);

if (!user_table) {
func_exit:
dict_sys.unfreeze();
DBUG_RETURN(0);
} else if (!dict_table_has_fts_index(user_table)
|| !user_table->is_readable()) {
dict_table_close(user_table, FALSE, FALSE);
goto func_exit;
dict_table_close(user_table, false, false, thd, mdl_ticket);
DBUG_RETURN(0);
}

deleted = fts_doc_ids_create();
Expand All @@ -2429,9 +2425,7 @@ i_s_fts_deleted_generic_fill(

fts_table_fetch_doc_ids(trx, &fts_table, deleted);

dict_table_close(user_table, FALSE, FALSE);

dict_sys.unfreeze();
dict_table_close(user_table, false, false, thd, mdl_ticket);

trx->free();

Expand Down Expand Up @@ -2778,22 +2772,18 @@ i_s_fts_index_cache_fill(

RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name.str);

/* Prevent DROP of the internal tables for fulltext indexes.
FIXME: acquire DDL-blocking MDL on the user table name! */
dict_sys.freeze();

MDL_ticket* mdl_ticket = nullptr;
user_table = dict_table_open_on_id(
innodb_ft_aux_table_id, FALSE, DICT_TABLE_OP_NORMAL);
innodb_ft_aux_table_id, false, DICT_TABLE_OP_NORMAL,
thd, &mdl_ticket);

if (!user_table) {
no_fts:
dict_sys.unfreeze();
DBUG_RETURN(0);
}

if (!user_table->fts || !user_table->fts->cache) {
dict_table_close(user_table, FALSE, FALSE);
goto no_fts;
dict_table_close(user_table, false, false, thd, mdl_ticket);
DBUG_RETURN(0);
}

cache = user_table->fts->cache;
Expand All @@ -2817,8 +2807,7 @@ i_s_fts_index_cache_fill(
}

mysql_mutex_unlock(&cache->lock);
dict_table_close(user_table, FALSE, FALSE);
dict_sys.unfreeze();
dict_table_close(user_table, false, false, thd, mdl_ticket);

DBUG_RETURN(ret);
}
Expand Down Expand Up @@ -3226,15 +3215,12 @@ i_s_fts_index_table_fill(

RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name.str);

/* Prevent DROP of the internal tables for fulltext indexes.
FIXME: acquire DDL-blocking MDL on the user table name! */
dict_sys.freeze();

MDL_ticket* mdl_ticket = nullptr;
user_table = dict_table_open_on_id(
innodb_ft_aux_table_id, FALSE, DICT_TABLE_OP_NORMAL);
innodb_ft_aux_table_id, false, DICT_TABLE_OP_NORMAL,
thd, &mdl_ticket);

if (!user_table) {
dict_sys.unfreeze();
DBUG_RETURN(0);
}

Expand All @@ -3252,9 +3238,7 @@ i_s_fts_index_table_fill(
}
}

dict_table_close(user_table, FALSE, FALSE);

dict_sys.unfreeze();
dict_table_close(user_table, false, false, thd, mdl_ticket);

ut_free(conv_str.f_str);

Expand Down Expand Up @@ -3380,22 +3364,18 @@ i_s_fts_config_fill(

RETURN_IF_INNODB_NOT_STARTED(tables->schema_table_name.str);

/* Prevent DROP of the internal tables for fulltext indexes.
FIXME: acquire DDL-blocking MDL on the user table name! */
dict_sys.freeze();

MDL_ticket* mdl_ticket = nullptr;
user_table = dict_table_open_on_id(
innodb_ft_aux_table_id, FALSE, DICT_TABLE_OP_NORMAL);
innodb_ft_aux_table_id, false, DICT_TABLE_OP_NORMAL,
thd, &mdl_ticket);

if (!user_table) {
no_fts:
dict_sys.unfreeze();
DBUG_RETURN(0);
}

if (!dict_table_has_fts_index(user_table)) {
dict_table_close(user_table, FALSE, FALSE);
goto no_fts;
dict_table_close(user_table, false, false, thd, mdl_ticket);
DBUG_RETURN(0);
}

fields = table->field;
Expand Down Expand Up @@ -3451,9 +3431,7 @@ i_s_fts_config_fill(

fts_sql_commit(trx);

dict_table_close(user_table, FALSE, FALSE);

dict_sys.unfreeze();
dict_table_close(user_table, false, false, thd, mdl_ticket);

trx->free();

Expand Down

0 comments on commit 0aa2bc7

Please sign in to comment.