Commit 092834cd authored by Sergey Vojtovich's avatar Sergey Vojtovich

Removed kill_delayed_threads_for_table()

After 7fb9d649 it is used only by ALTER/DROP SERVER, which most probably
wasn't intentional as Federated never supported delayed inserts anyway.

If delayed inserts will ever become an issue with ALTER/DROP SERVER, we
should kill them by acquiring X-lock instead.

Part of MDEV-17882 - Cleanup refresh version
parent 0aa807d1
...@@ -425,7 +425,7 @@ rpl_slave_state::truncate_state_table(THD *thd) ...@@ -425,7 +425,7 @@ rpl_slave_state::truncate_state_table(THD *thd)
if (!(err= open_and_lock_tables(thd, &tlist, FALSE, 0))) if (!(err= open_and_lock_tables(thd, &tlist, FALSE, 0)))
{ {
tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED, "mysql", tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED, "mysql",
rpl_gtid_slave_state_table_name.str, false); rpl_gtid_slave_state_table_name.str);
err= tlist.table->file->ha_truncate(); err= tlist.table->file->ha_truncate();
if (err) if (err)
......
...@@ -1158,7 +1158,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -1158,7 +1158,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
else if (open_for_modify || fatal_error) else if (open_for_modify || fatal_error)
{ {
tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED, tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED,
table->db.str, table->table_name.str, FALSE); table->db.str, table->table_name.str);
/* /*
May be something modified. Consequently, we have to May be something modified. Consequently, we have to
invalidate the query cache. invalidate the query cache.
......
...@@ -450,7 +450,7 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, ...@@ -450,7 +450,7 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables,
for (TABLE_LIST *table= tables; table; table= table->next_local) for (TABLE_LIST *table= tables; table; table= table->next_local)
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table->db.str, tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table->db.str,
table->table_name.str, false); table->table_name.str);
} }
DBUG_RETURN(false); DBUG_RETURN(false);
} }
...@@ -717,7 +717,7 @@ bool close_cached_connection_tables(THD *thd, LEX_CSTRING *connection) ...@@ -717,7 +717,7 @@ bool close_cached_connection_tables(THD *thd, LEX_CSTRING *connection)
for (TABLE_LIST *table= argument.tables; table; table= table->next_local) for (TABLE_LIST *table= argument.tables; table; table= table->next_local)
res|= tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED, res|= tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED,
table->db.str, table->db.str,
table->table_name.str, TRUE); table->table_name.str);
/* Return true if we found any open connections */ /* Return true if we found any open connections */
DBUG_RETURN(res); DBUG_RETURN(res);
...@@ -846,12 +846,9 @@ close_all_tables_for_name(THD *thd, TABLE_SHARE *share, ...@@ -846,12 +846,9 @@ close_all_tables_for_name(THD *thd, TABLE_SHARE *share,
prev= &table->next; prev= &table->next;
} }
} }
/* Remove the table share from the cache. */
if (skip_table == NULL) if (skip_table == NULL)
{ tdc_remove_table(thd, TDC_RT_REMOVE_ALL, db, table_name);
/* Remove the table share from the cache. */
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, db, table_name,
FALSE);
}
} }
...@@ -1414,8 +1411,7 @@ bool wait_while_table_is_used(THD *thd, TABLE *table, ...@@ -1414,8 +1411,7 @@ bool wait_while_table_is_used(THD *thd, TABLE *table,
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
tdc_remove_table(thd, TDC_RT_REMOVE_NOT_OWN, tdc_remove_table(thd, TDC_RT_REMOVE_NOT_OWN,
table->s->db.str, table->s->table_name.str, table->s->db.str, table->s->table_name.str);
FALSE);
/* extra() call must come only after all instances above are closed */ /* extra() call must come only after all instances above are closed */
if (function != HA_EXTRA_NOT_USED) if (function != HA_EXTRA_NOT_USED)
(void) table->file->extra(function); (void) table->file->extra(function);
...@@ -1456,8 +1452,7 @@ void drop_open_table(THD *thd, TABLE *table, const LEX_CSTRING *db_name, ...@@ -1456,8 +1452,7 @@ void drop_open_table(THD *thd, TABLE *table, const LEX_CSTRING *db_name,
table->file->extra(HA_EXTRA_PREPARE_FOR_DROP); table->file->extra(HA_EXTRA_PREPARE_FOR_DROP);
close_thread_table(thd, &thd->open_tables); close_thread_table(thd, &thd->open_tables);
/* Remove the table share from the table cache. */ /* Remove the table share from the table cache. */
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, db_name->str, table_name->str, tdc_remove_table(thd, TDC_RT_REMOVE_ALL, db_name->str, table_name->str);
FALSE);
/* Remove the table from the storage engine and rm the .frm. */ /* Remove the table from the storage engine and rm the .frm. */
quick_rm_table(thd, table_type, db_name, table_name, 0); quick_rm_table(thd, table_type, db_name, table_name, 0);
} }
...@@ -3046,8 +3041,7 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list) ...@@ -3046,8 +3041,7 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list)
tdc_release_share(share); tdc_release_share(share);
/* Remove the repaired share from the table cache. */ /* Remove the repaired share from the table cache. */
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, tdc_remove_table(thd, TDC_RT_REMOVE_ALL,
table_list->db.str, table_list->table_name.str, table_list->db.str, table_list->table_name.str);
FALSE);
end_free: end_free:
my_free(entry); my_free(entry);
return result; return result;
...@@ -3219,7 +3213,7 @@ Open_table_context::recover_from_failed_open() ...@@ -3219,7 +3213,7 @@ Open_table_context::recover_from_failed_open()
break; break;
tdc_remove_table(m_thd, TDC_RT_REMOVE_ALL, m_failed_table->db.str, tdc_remove_table(m_thd, TDC_RT_REMOVE_ALL, m_failed_table->db.str,
m_failed_table->table_name.str, FALSE); m_failed_table->table_name.str);
m_thd->get_stmt_da()->clear_warning_info(m_thd->query_id); m_thd->get_stmt_da()->clear_warning_info(m_thd->query_id);
m_thd->clear_error(); // Clear error message m_thd->clear_error(); // Clear error message
...@@ -3255,7 +3249,7 @@ Open_table_context::recover_from_failed_open() ...@@ -3255,7 +3249,7 @@ Open_table_context::recover_from_failed_open()
break; break;
tdc_remove_table(m_thd, TDC_RT_REMOVE_ALL, m_failed_table->db.str, tdc_remove_table(m_thd, TDC_RT_REMOVE_ALL, m_failed_table->db.str,
m_failed_table->table_name.str, FALSE); m_failed_table->table_name.str);
result= auto_repair_table(m_thd, m_failed_table); result= auto_repair_table(m_thd, m_failed_table);
/* /*
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "sql_acl.h" // SELECT_ACL, DB_ACLS, #include "sql_acl.h" // SELECT_ACL, DB_ACLS,
// acl_get, check_grant_db // acl_get, check_grant_db
#include "log_event.h" // Query_log_event #include "log_event.h" // Query_log_event
#include "sql_base.h" // lock_table_names, tdc_remove_table #include "sql_base.h" // lock_table_names
#include "sql_handler.h" // mysql_ha_rm_tables #include "sql_handler.h" // mysql_ha_rm_tables
#include "sql_class.h" #include "sql_class.h"
#include <mysys_err.h> #include <mysys_err.h>
......
...@@ -826,7 +826,7 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd) ...@@ -826,7 +826,7 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd)
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
tdc_remove_table(thd, TDC_RT_REMOVE_NOT_OWN, first_table->db.str, tdc_remove_table(thd, TDC_RT_REMOVE_NOT_OWN, first_table->db.str,
first_table->table_name.str, FALSE); first_table->table_name.str);
partition= (ha_partition*) first_table->table->file; partition= (ha_partition*) first_table->table->file;
/* Invoke the handler method responsible for truncating the partition. */ /* Invoke the handler method responsible for truncating the partition. */
......
...@@ -545,7 +545,7 @@ bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables) ...@@ -545,7 +545,7 @@ bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables)
/* Request removal of table from cache. */ /* Request removal of table from cache. */
tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED, tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED,
table_list->db.str, table_list->db.str,
table_list->table_name.str, FALSE); table_list->table_name.str);
/* Reset ticket to satisfy asserts in open_tables(). */ /* Reset ticket to satisfy asserts in open_tables(). */
table_list->mdl_request.ticket= NULL; table_list->mdl_request.ticket= NULL;
} }
......
...@@ -287,7 +287,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, const LEX_CSTRING *new_db, ...@@ -287,7 +287,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, const LEX_CSTRING *new_db,
{ {
DBUG_ASSERT(!thd->locked_tables_mode); DBUG_ASSERT(!thd->locked_tables_mode);
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, tdc_remove_table(thd, TDC_RT_REMOVE_ALL,
ren_table->db.str, ren_table->table_name.str, false); ren_table->db.str, ren_table->table_name.str);
if (hton != view_pseudo_hton) if (hton != view_pseudo_hton)
{ {
......
...@@ -2470,8 +2470,8 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -2470,8 +2470,8 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
table->table= 0; table->table= 0;
} }
else else
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table->db.str, table->table_name.str, tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table->db.str,
false); table->table_name.str);
/* Check that we have an exclusive lock on the table to be dropped. */ /* Check that we have an exclusive lock on the table to be dropped. */
DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->db.str, DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->db.str,
...@@ -7626,8 +7626,7 @@ static bool mysql_inplace_alter_table(THD *thd, ...@@ -7626,8 +7626,7 @@ static bool mysql_inplace_alter_table(THD *thd,
goto cleanup; goto cleanup;
tdc_remove_table(thd, TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE, tdc_remove_table(thd, TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE,
table->s->db.str, table->s->table_name.str, table->s->db.str, table->s->table_name.str);
false);
} }
/* /*
...@@ -7821,7 +7820,7 @@ static bool mysql_inplace_alter_table(THD *thd, ...@@ -7821,7 +7820,7 @@ static bool mysql_inplace_alter_table(THD *thd,
{ {
// Remove TABLE and TABLE_SHARE for old name from TDC. // Remove TABLE and TABLE_SHARE for old name from TDC.
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, tdc_remove_table(thd, TDC_RT_REMOVE_ALL,
alter_ctx->db.str, alter_ctx->table_name.str, false); alter_ctx->db.str, alter_ctx->table_name.str);
if (mysql_rename_table(db_type, &alter_ctx->db, &alter_ctx->table_name, if (mysql_rename_table(db_type, &alter_ctx->db, &alter_ctx->table_name,
&alter_ctx->new_db, &alter_ctx->new_alias, 0)) &alter_ctx->new_db, &alter_ctx->new_alias, 0))
......
...@@ -361,7 +361,7 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref, ...@@ -361,7 +361,7 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref,
{ {
/* Table is already locked exclusively. Remove cached instances. */ /* Table is already locked exclusively. Remove cached instances. */
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table_ref->db.str, tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table_ref->db.str,
table_ref->table_name.str, FALSE); table_ref->table_name.str);
} }
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
......
...@@ -646,7 +646,8 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, ...@@ -646,7 +646,8 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
*/ */
if (!res) if (!res)
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, view->db.str, view->table_name.str, false); tdc_remove_table(thd, TDC_RT_REMOVE_ALL, view->db.str,
view->table_name.str);
if (!res && mysql_bin_log.is_open()) if (!res && mysql_bin_log.is_open())
{ {
...@@ -1866,8 +1867,8 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) ...@@ -1866,8 +1867,8 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
For a view, there is a TABLE_SHARE object. For a view, there is a TABLE_SHARE object.
Remove it from the table definition cache, in case the view was cached. Remove it from the table definition cache, in case the view was cached.
*/ */
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, view->db.str, view->table_name.str, tdc_remove_table(thd, TDC_RT_REMOVE_ALL, view->db.str,
FALSE); view->table_name.str);
query_cache_invalidate3(thd, view, 0); query_cache_invalidate3(thd, view, 0);
sp_cache_invalidate(); sp_cache_invalidate();
} }
......
...@@ -1003,47 +1003,6 @@ void tdc_release_share(TABLE_SHARE *share) ...@@ -1003,47 +1003,6 @@ void tdc_release_share(TABLE_SHARE *share)
} }
/**
Auxiliary function which allows to kill delayed threads for
particular table identified by its share.
@param share Table share.
@pre Caller should have TABLE_SHARE::tdc.LOCK_table_share mutex.
*/
static void kill_delayed_threads_for_table(TDC_element *element)
{
All_share_tables_list::Iterator it(element->all_tables);
TABLE *tab;
mysql_mutex_assert_owner(&element->LOCK_table_share);
if (!delayed_insert_threads)
return;
while ((tab= it++))
{
THD *in_use= tab->in_use;
DBUG_ASSERT(in_use && tab->s->tdc->flushed);
if ((in_use->system_thread & SYSTEM_THREAD_DELAYED_INSERT) &&
! in_use->killed)
{
in_use->killed= KILL_SYSTEM_THREAD;
mysql_mutex_lock(&in_use->mysys_var->mutex);
if (in_use->mysys_var->current_cond)
{
mysql_mutex_lock(in_use->mysys_var->current_mutex);
mysql_cond_broadcast(in_use->mysys_var->current_cond);
mysql_mutex_unlock(in_use->mysys_var->current_mutex);
}
mysql_mutex_unlock(&in_use->mysys_var->mutex);
}
}
}
/** /**
Remove all or some (depending on parameter) instances of TABLE and Remove all or some (depending on parameter) instances of TABLE and
TABLE_SHARE from the table definition cache. TABLE_SHARE from the table definition cache.
...@@ -1077,15 +1036,13 @@ static void kill_delayed_threads_for_table(TDC_element *element) ...@@ -1077,15 +1036,13 @@ static void kill_delayed_threads_for_table(TDC_element *element)
metadata lock on the table. metadata lock on the table.
@param db Name of database @param db Name of database
@param table_name Name of table @param table_name Name of table
@param kill_delayed_threads If TRUE, kill INSERT DELAYED threads
@note It assumes that table instances are already not used by any @note It assumes that table instances are already not used by any
(other) thread (this should be achieved by using meta-data locks). (other) thread (this should be achieved by using meta-data locks).
*/ */
bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type, bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
const char *db, const char *table_name, const char *db, const char *table_name)
bool kill_delayed_threads)
{ {
Share_free_tables::List purge_tables; Share_free_tables::List purge_tables;
TABLE *table; TABLE *table;
...@@ -1129,9 +1086,6 @@ bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type, ...@@ -1129,9 +1086,6 @@ bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
tc_remove_all_unused_tables(element, &purge_tables, tc_remove_all_unused_tables(element, &purge_tables,
remove_type != TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE); remove_type != TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE);
if (kill_delayed_threads)
kill_delayed_threads_for_table(element);
if (remove_type == TDC_RT_REMOVE_NOT_OWN || if (remove_type == TDC_RT_REMOVE_NOT_OWN ||
remove_type == TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE) remove_type == TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE)
{ {
......
...@@ -82,8 +82,7 @@ extern TABLE_SHARE *tdc_acquire_share(THD *thd, TABLE_LIST *tl, uint flags, ...@@ -82,8 +82,7 @@ extern TABLE_SHARE *tdc_acquire_share(THD *thd, TABLE_LIST *tl, uint flags,
TABLE **out_table= 0); TABLE **out_table= 0);
extern void tdc_release_share(TABLE_SHARE *share); extern void tdc_release_share(TABLE_SHARE *share);
extern bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type, extern bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
const char *db, const char *table_name, const char *db, const char *table_name);
bool kill_delayed_threads);
extern int tdc_wait_for_old_version(THD *thd, const char *db, extern int tdc_wait_for_old_version(THD *thd, const char *db,
const char *table_name, const char *table_name,
......
...@@ -67,7 +67,7 @@ static int MDL_and_TDC(THD *thd, ...@@ -67,7 +67,7 @@ static int MDL_and_TDC(THD *thd,
table); table);
return error; return error;
} }
tdc_remove_table(thd, TDC_RT_REMOVE_ALL, db, table, false); tdc_remove_table(thd, TDC_RT_REMOVE_ALL, db, table);
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment