Skip to content

Commit

Permalink
MDEV-25919 preparation: Various cleanup
Browse files Browse the repository at this point in the history
que_eval_sql(): Remove the parameter lock_dict. The only caller
with lock_dict=true was dict_stats_exec_sql(), which will now
explicitly invoke dict_sys.lock() and dict_sys.unlock() by itself.

row_import_cleanup(): Do not unnecessarily lock the dictionary.
Concurrent access to the table during ALTER TABLE...IMPORT TABLESPACE
is prevented by MDL and the fact that there cannot exist any
undo log or change buffer records that would refer to the table
or tablespace.

row_import_for_mysql(): Do not unnecessarily lock the dictionary
while accessing fil_system. Thanks to MDL_EXCLUSIVE that was acquired
by the SQL layer, only one IMPORT may be in effect for the table name.

row_quiesce_set_state(): Do not unnecessarily lock the dictionary.
The dict_table_t::quiesce state is documented to be protected by
all index latches, which we are acquiring.

dict_table_close(): Introduce a simpler variant with fewer parameters.

dict_table_close(): Reduce the amount of calls.
We can simply invoke dict_table_t::release() on startup or
in DDL operations, or when the table is inaccessible.
In none of these cases, there is no need to invalidate the
InnoDB persistent statistics.

pars_info_t::graph_owns_us: Remove (unused).

pars_info_free(): Define inline.

fts_delete(), trx_t::evict_table(), row_prebuilt_free(),
row_rename_table_for_mysql(): Simplify.

row_mysql_lock_data_dictionary(): Remove some references;
use dict_sys.lock() and dict_sys.unlock() instead.

row_mysql_lock_table(): Remove. Use lock_table_for_trx() instead.

ha_innobase::check_if_supported_inplace_alter(),
row_create_table_for_mysql(): Simply assert dict_sys.sys_tables_exist().
In commit 49e2c8f and
commit 1bd681c srv_start()
actually guarantees that the system tables will exist,
or the server is in read-only mode, or startup will fail.

Reviewed by: Thirunarayanan Balathandayuthapani
  • Loading branch information
dr-m committed Aug 31, 2021
1 parent 6a2cd6f commit 094de71
Show file tree
Hide file tree
Showing 22 changed files with 153 additions and 327 deletions.
8 changes: 4 additions & 4 deletions storage/innobase/dict/dict0crea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ dberr_t dict_sys_t::create_or_check_sys_tables()
" ON SYS_FOREIGN (FOR_NAME);\n"
"CREATE INDEX REF_IND"
" ON SYS_FOREIGN (REF_NAME);\n"
"END;\n", false, trx);
"END;\n", trx);
if (UNIV_UNLIKELY(error != DB_SUCCESS))
{
tablename= SYS_TABLE[SYS_FOREIGN].data();
Expand All @@ -1425,7 +1425,7 @@ dberr_t dict_sys_t::create_or_check_sys_tables()
" FOR_COL_NAME CHAR, REF_COL_NAME CHAR);\n"
"CREATE UNIQUE CLUSTERED INDEX ID_IND"
" ON SYS_FOREIGN_COLS (ID, POS);\n"
"END;\n", false, trx);
"END;\n", trx);
if (UNIV_UNLIKELY(error != DB_SUCCESS))
{
tablename= SYS_TABLE[SYS_FOREIGN_COLS].data();
Expand All @@ -1440,7 +1440,7 @@ dberr_t dict_sys_t::create_or_check_sys_tables()
"SYS_VIRTUAL(TABLE_ID BIGINT,POS INT,BASE_POS INT);\n"
"CREATE UNIQUE CLUSTERED INDEX BASE_IDX"
" ON SYS_VIRTUAL(TABLE_ID, POS, BASE_POS);\n"
"END;\n", false, trx);
"END;\n", trx);
if (UNIV_UNLIKELY(error != DB_SUCCESS))
{
tablename= SYS_TABLE[SYS_VIRTUAL].data();
Expand Down Expand Up @@ -1504,7 +1504,7 @@ dict_foreign_eval_sql(
dberr_t error;
FILE* ef = dict_foreign_err_file;

error = que_eval_sql(info, sql, FALSE, trx);
error = que_eval_sql(info, sql, trx);

if (error == DB_DUPLICATE_KEY) {
mysql_mutex_lock(&dict_foreign_err_mutex);
Expand Down
38 changes: 25 additions & 13 deletions storage/innobase/dict/dict0dict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,25 @@ dict_table_try_drop_aborted_and_unlock(
}
}

/** Decrement the count of open handles */
void dict_table_close(dict_table_t *table)
{
if (dict_stats_is_persistent_enabled(table) &&
strchr(table->name.m_name, '/'))
{
dict_sys.freeze(SRW_LOCK_CALL);
if (table->release())
{
table->stats_mutex_lock();
dict_stats_deinit(table);
table->stats_mutex_unlock();
}
dict_sys.unfreeze();
}
else
table->release();
}

/** Decrements the count of open handles of a table.
@param[in,out] table table
@param[in] dict_locked data dictionary locked
Expand Down Expand Up @@ -4223,12 +4242,7 @@ void dict_set_encrypted_by_space(const fil_space_t* space)
/**********************************************************************//**
Flags an index corrupted both in the data dictionary cache
and in the SYS_INDEXES */
void
dict_set_corrupted(
/*===============*/
dict_index_t* index, /*!< in/out: index */
trx_t* trx, /*!< in/out: transaction */
const char* ctx) /*!< in: context */
void dict_set_corrupted(dict_index_t *index, const char *ctx, bool dict_locked)
{
mem_heap_t* heap;
mtr_t mtr;
Expand All @@ -4238,10 +4252,9 @@ dict_set_corrupted(
byte* buf;
const char* status;
btr_cur_t cursor;
bool locked = RW_X_LATCH == trx->dict_operation_lock_mode;

if (!locked) {
row_mysql_lock_data_dictionary(trx);
if (!dict_locked) {
dict_sys.lock(SRW_LOCK_CALL);
}

ut_ad(dict_sys.locked());
Expand Down Expand Up @@ -4311,14 +4324,13 @@ dict_set_corrupted(
}

mtr_commit(&mtr);
mem_heap_empty(heap);
mem_heap_free(heap);
ib::error() << status << " corruption of " << index->name
<< " in table " << index->table->name << " in " << ctx;
mem_heap_free(heap);

func_exit:
if (!locked) {
row_mysql_unlock_data_dictionary(trx);
if (!dict_locked) {
dict_sys.unlock();
}
}

Expand Down
10 changes: 5 additions & 5 deletions storage/innobase/dict/dict0stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,13 +533,13 @@ dberr_t dict_stats_exec_sql(pars_info_t *pinfo, const char* sql, trx_t *trx)
}

if (trx)
return que_eval_sql(pinfo, sql, FALSE, trx);
return que_eval_sql(pinfo, sql, trx);

trx= trx_create();
trx_start_internal(trx);

trx->dict_operation_lock_mode= RW_X_LATCH;
dberr_t err= que_eval_sql(pinfo, sql, FALSE, trx);
dberr_t err= que_eval_sql(pinfo, sql, trx);

if (err == DB_SUCCESS)
trx->commit();
Expand Down Expand Up @@ -3255,7 +3255,7 @@ dict_stats_fetch_from_ps(
"fetch_index_stats_step",
dict_stats_fetch_index_stats_step,
&index_fetch_arg);

dict_sys.lock(SRW_LOCK_CALL); /* FIXME: remove this */
ret = que_eval_sql(pinfo,
"PROCEDURE FETCH_STATS () IS\n"
"found INT;\n"
Expand Down Expand Up @@ -3309,9 +3309,9 @@ dict_stats_fetch_from_ps(
"END LOOP;\n"
"CLOSE index_stats_cur;\n"

"END;",
TRUE, trx);
"END;", trx);
/* pinfo is freed by que_eval_sql() */
dict_sys.unlock();

trx_commit_for_mysql(trx);

Expand Down
6 changes: 2 additions & 4 deletions storage/innobase/dict/dict0stats_bg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static bool dict_stats_process_entry_from_recalc_pool()
ut_ad(!table->is_temporary());

if (!table->is_accessible()) {
dict_table_close(table, TRUE, FALSE);
table->release();
no_table:
dict_sys.unlock();
goto next_table_id;
Expand Down Expand Up @@ -382,12 +382,10 @@ static bool dict_stats_process_entry_from_recalc_pool()
}

dict_sys.lock(SRW_LOCK_CALL);

table->stats_bg_flag = BG_STAT_NONE;

dict_table_close(table, TRUE, FALSE);

dict_sys.unlock();

return ret;
}

Expand Down
6 changes: 3 additions & 3 deletions storage/innobase/dict/drop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ dberr_t trx_t::drop_table_foreign(const table_name_t &name)
" DELETE FROM SYS_FOREIGN WHERE ID=fid;\n"
"END LOOP;\n"
"CLOSE fk;\n"
"END;\n", FALSE, this);
"END;\n", this);
}

/** Try to drop the statistics for a persistent table.
Expand Down Expand Up @@ -182,7 +182,7 @@ dberr_t trx_t::drop_table(const dict_table_t &table)
"BEGIN\n"
"DELETE FROM SYS_VIRTUAL"
" WHERE TABLE_ID=:id;\n"
"END;\n", FALSE, this))
"END;\n", this))
return err;
}

Expand Down Expand Up @@ -224,7 +224,7 @@ dberr_t trx_t::drop_table(const dict_table_t &table)
"END LOOP;\n"
"CLOSE idx;\n"

"END;\n", FALSE, this);
"END;\n", this);
}

/** Commit the transaction, possibly after drop_table().
Expand Down
42 changes: 14 additions & 28 deletions storage/innobase/fts/fts0fts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1593,8 +1593,7 @@ dberr_t fts_lock_tables(trx_t *trx, const dict_table_t &table)
}

/** Drops the common ancillary tables needed for supporting an FTS index
on the given table. row_mysql_lock_data_dictionary must have been called
before this.
on the given table.
@param trx transaction to drop fts common table
@param fts_table table with an FTS index
@param rename whether to rename before dropping
Expand Down Expand Up @@ -1653,8 +1652,7 @@ dberr_t fts_drop_index_tables(trx_t *trx, const dict_index_t &index)

/****************************************************************//**
Drops FTS ancillary tables needed for supporting an FTS index
on the given table. row_mysql_lock_data_dictionary must have been called
before this.
on the given table.
@return DB_SUCCESS or error code */
static MY_ATTRIBUTE((nonnull, warn_unused_result))
dberr_t
Expand Down Expand Up @@ -1795,8 +1793,7 @@ fts_create_one_common_table(
}

/** Creates the common auxiliary tables needed for supporting an FTS index
on the given table. row_mysql_lock_data_dictionary must have been called
before this.
on the given table.
The following tables are created.
CREATE TABLE $FTS_PREFIX_DELETED
(doc_id BIGINT UNSIGNED, UNIQUE CLUSTERED INDEX on doc_id)
Expand Down Expand Up @@ -1974,8 +1971,7 @@ fts_create_one_index_table(
}

/** Creates the column specific ancillary tables needed for supporting an
FTS index on the given table. row_mysql_lock_data_dictionary must have
been called before this.
FTS index on the given table.
All FTS AUX Index tables have the following schema.
CREAT TABLE $FTS_PREFIX_INDEX_[1-6](
Expand Down Expand Up @@ -2754,7 +2750,6 @@ fts_delete(
{
que_t* graph;
fts_table_t fts_table;
dberr_t error = DB_SUCCESS;
doc_id_t write_doc_id;
dict_table_t* table = ftt->table;
doc_id_t doc_id = row->doc_id;
Expand All @@ -2765,7 +2760,7 @@ fts_delete(
/* we do not index Documents whose Doc ID value is 0 */
if (doc_id == FTS_NULL_DOC_ID) {
ut_ad(!DICT_TF2_FLAG_IS_SET(table, DICT_TF2_FTS_HAS_DOC_ID));
return(error);
return DB_SUCCESS;
}

ut_a(row->state == FTS_DELETE || row->state == FTS_MODIFY);
Expand Down Expand Up @@ -2800,29 +2795,20 @@ fts_delete(
}

/* Note the deleted document for OPTIMIZE to purge. */
if (error == DB_SUCCESS) {
char table_name[MAX_FULL_NAME_LEN];
char table_name[MAX_FULL_NAME_LEN];

trx->op_info = "adding doc id to FTS DELETED";
trx->op_info = "adding doc id to FTS DELETED";

info->graph_owns_us = TRUE;
fts_table.suffix = "DELETED";

fts_table.suffix = "DELETED";

fts_get_table_name(&fts_table, table_name);
pars_info_bind_id(info, "deleted", table_name);

graph = fts_parse_sql(
&fts_table,
info,
"BEGIN INSERT INTO $deleted VALUES (:doc_id);");
fts_get_table_name(&fts_table, table_name);
pars_info_bind_id(info, "deleted", table_name);

error = fts_eval_sql(trx, graph);
graph = fts_parse_sql(&fts_table, info,
"BEGIN INSERT INTO $deleted VALUES (:doc_id);");

que_graph_free(graph);
} else {
pars_info_free(info);
}
dberr_t error = fts_eval_sql(trx, graph);
que_graph_free(graph);

/* Increment the total deleted count, this is used to calculate the
number of documents indexed. */
Expand Down
Loading

0 comments on commit 094de71

Please sign in to comment.