From 6d29b23b15cdb14e0f60804db4eaeb5718cec78a Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 19 Jul 2005 00:29:19 +0200 Subject: Bug #10600 remove_table_from_cache fails to signal other thread and gets blocked when other thread also gets blocked include/thr_lock.h: Report if any threads was signalled mysys/thr_lock.c: Report if any threads was signalled sql/lock.cc: Report if any threads was signalled Use new interface for remove_table_from_cache sql/mysql_priv.h: New interface for remove_table_from_cache + mysql_lock_abort_for_thread sql/sql_base.cc: Use new interface of remove_table_cache Rewrote remove_table_from_cache to fix bug sql/sql_table.cc: Use new interface of remove_table_from_cache --- sql/sql_table.cc | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index a9af8144df0..d0ef29cee50 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -178,6 +178,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, for (table=tables ; table ; table=table->next) { char *db=table->db; + uint flags; mysql_ha_flush(thd, table, MYSQL_HA_CLOSE_FINAL); if (!close_temporary_table(thd, db, table->real_name)) { @@ -186,12 +187,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, } abort_locked_tables(thd,db,table->real_name); - while (remove_table_from_cache(thd,db,table->real_name) && !thd->killed) - { - dropping_tables++; - (void) pthread_cond_wait(&COND_refresh,&LOCK_open); - dropping_tables--; - } + flags= WAIT_OTHER_THREAD_FLAG | CHECK_KILLED_FLAG; + remove_table_from_cache(thd,db,table->real_name,flags); drop_locked_tables(thd,db,table->real_name); if (thd->killed) DBUG_RETURN(-1); @@ -979,6 +976,7 @@ mysql_rename_table(enum db_type base, static void wait_while_table_is_used(THD *thd,TABLE *table, enum ha_extra_function function) { + uint flags; DBUG_PRINT("enter",("table: %s", table->real_name)); DBUG_ENTER("wait_while_table_is_used"); safe_mutex_assert_owner(&LOCK_open); @@ -988,13 +986,9 @@ static void wait_while_table_is_used(THD *thd,TABLE *table, mysql_lock_abort(thd, table); // end threads waiting on lock /* Wait until all there are no other threads that has this table open */ - while (remove_table_from_cache(thd,table->table_cache_key, - table->real_name)) - { - dropping_tables++; - (void) pthread_cond_wait(&COND_refresh,&LOCK_open); - dropping_tables--; - } + flags= WAIT_OTHER_THREAD_FLAG; + remove_table_from_cache(thd,table->table_cache_key, + table->real_name,flags); DBUG_VOID_RETURN; } @@ -1306,18 +1300,14 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, /* Close all instances of the table to allow repair to rename files */ if (lock_type == TL_WRITE && table->table->version) { + uint flags; pthread_mutex_lock(&LOCK_open); const char *old_message=thd->enter_cond(&COND_refresh, &LOCK_open, "Waiting to get writelock"); mysql_lock_abort(thd,table->table); - while (remove_table_from_cache(thd, table->table->table_cache_key, - table->table->real_name) && - ! thd->killed) - { - dropping_tables++; - (void) pthread_cond_wait(&COND_refresh,&LOCK_open); - dropping_tables--; - } + flags= WAIT_OTHER_THREAD_FLAG | CHECK_KILLED_FLAG; + remove_table_from_cache(thd, table->table->table_cache_key, + table->table->real_name, flags); thd->exit_cond(old_message); if (thd->killed) goto err; @@ -1382,9 +1372,10 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, table->table->version=0; // Force close of table else if (open_for_modify) { + uint flags= 0; pthread_mutex_lock(&LOCK_open); remove_table_from_cache(thd, table->table->table_cache_key, - table->table->real_name); + table->table->real_name, flags); pthread_mutex_unlock(&LOCK_open); /* May be something modified consequently we have to invalidate cache */ query_cache_invalidate3(thd, table->table, 0); @@ -2108,8 +2099,9 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, */ if (table) { + uint flags= 0; VOID(table->file->extra(HA_EXTRA_FORCE_REOPEN)); // Use new file - remove_table_from_cache(thd,db,table_name); // Mark all in-use copies old + remove_table_from_cache(thd,db,table_name,flags);// Mark in-use copies old mysql_lock_abort(thd,table); // end threads waiting on lock } VOID(quick_rm_table(old_db_type,db,old_name)); -- cgit v1.2.1 From af1dfb613b7ce6343f461d6f4c3def6af9354814 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 20 Jul 2005 21:19:01 +0200 Subject: Bug #10600 After review fixes sql/lock.cc: Used flags immediately in call sql/mysql_priv.h: Added RTFC (short for remove_table_from_cache) for constants and used hex syntax to clarify it is bits in the flags sql/sql_base.cc: Use flags parameter immediately and use flags immediately in call Change to other variant of eternal loop variant sql/sql_table.cc: Use flags immediately in call --- sql/sql_table.cc | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'sql/sql_table.cc') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index d0ef29cee50..4c269e6830f 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -187,7 +187,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, } abort_locked_tables(thd,db,table->real_name); - flags= WAIT_OTHER_THREAD_FLAG | CHECK_KILLED_FLAG; + flags= RTFC_WAIT_OTHER_THREAD_FLAG | RTFC_CHECK_KILLED_FLAG; remove_table_from_cache(thd,db,table->real_name,flags); drop_locked_tables(thd,db,table->real_name); if (thd->killed) @@ -976,7 +976,6 @@ mysql_rename_table(enum db_type base, static void wait_while_table_is_used(THD *thd,TABLE *table, enum ha_extra_function function) { - uint flags; DBUG_PRINT("enter",("table: %s", table->real_name)); DBUG_ENTER("wait_while_table_is_used"); safe_mutex_assert_owner(&LOCK_open); @@ -986,9 +985,8 @@ static void wait_while_table_is_used(THD *thd,TABLE *table, mysql_lock_abort(thd, table); // end threads waiting on lock /* Wait until all there are no other threads that has this table open */ - flags= WAIT_OTHER_THREAD_FLAG; remove_table_from_cache(thd,table->table_cache_key, - table->real_name,flags); + table->real_name, RTFC_WAIT_OTHER_THREAD_FLAG); DBUG_VOID_RETURN; } @@ -1305,7 +1303,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, const char *old_message=thd->enter_cond(&COND_refresh, &LOCK_open, "Waiting to get writelock"); mysql_lock_abort(thd,table->table); - flags= WAIT_OTHER_THREAD_FLAG | CHECK_KILLED_FLAG; + flags= RTFC_WAIT_OTHER_THREAD_FLAG | RTFC_CHECK_KILLED_FLAG; remove_table_from_cache(thd, table->table->table_cache_key, table->table->real_name, flags); thd->exit_cond(old_message); @@ -1372,10 +1370,9 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, table->table->version=0; // Force close of table else if (open_for_modify) { - uint flags= 0; pthread_mutex_lock(&LOCK_open); remove_table_from_cache(thd, table->table->table_cache_key, - table->table->real_name, flags); + table->table->real_name, RTFC_NO_FLAG); pthread_mutex_unlock(&LOCK_open); /* May be something modified consequently we have to invalidate cache */ query_cache_invalidate3(thd, table->table, 0); @@ -2099,9 +2096,9 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, */ if (table) { - uint flags= 0; VOID(table->file->extra(HA_EXTRA_FORCE_REOPEN)); // Use new file - remove_table_from_cache(thd,db,table_name,flags);// Mark in-use copies old + remove_table_from_cache(thd,db,table_name,RTFC_NO_FLAG); + // Mark in-use copies old mysql_lock_abort(thd,table); // end threads waiting on lock } VOID(quick_rm_table(old_db_type,db,old_name)); -- cgit v1.2.1