Commit af1dfb61 authored by unknown's avatar unknown
Browse files

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
parent 6d29b23b
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -549,9 +549,8 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list)
  }
  
  {
    uint flags= 0;
    if (remove_table_from_cache(thd, db,
                                table_list->real_name, flags))
                                table_list->real_name, RTFC_NO_FLAG))
    {
      DBUG_RETURN(1);				// Table is in use
    }
+4 −3
Original line number Diff line number Diff line
@@ -606,9 +606,10 @@ bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db,
			    const char *table_name);
void remove_db_from_cache(const my_string db);
void flush_tables();
#define OWNED_BY_THD_FLAG 1
#define WAIT_OTHER_THREAD_FLAG 2
#define CHECK_KILLED_FLAG 4
#define RTFC_NO_FLAG                0x0000
#define RTFC_OWNED_BY_THD_FLAG      0x0001
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
#define RTFC_CHECK_KILLED_FLAG      0x0004
bool remove_table_from_cache(THD *thd, const char *db, const char *table,
                             uint flags);
bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables);
+7 −15
Original line number Diff line number Diff line
@@ -370,9 +370,8 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh,
    bool found=0;
    for (TABLE_LIST *table=tables ; table ; table=table->next)
    {
      uint flags= OWNED_BY_THD_FLAG;
      if (remove_table_from_cache(thd, table->db, table->real_name,
                                  flags))
                                  RTFC_OWNED_BY_THD_FLAG))
	found=1;
    }
    if (!found)
@@ -2415,13 +2414,10 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
  uint key_length;
  TABLE *table;
  bool result=0, signalled= 0;
  bool return_if_owned_by_thd= flags & OWNED_BY_THD_FLAG;
  bool wait_for_other_thread= flags & WAIT_OTHER_THREAD_FLAG;
  bool check_killed_flag= flags & CHECK_KILLED_FLAG;
  DBUG_ENTER("remove_table_from_cache");

  key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1;
  do
  for (;;)
  {
    result= signalled= 0;

@@ -2465,21 +2461,17 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
	     thd_table= thd_table->next)
        {
	  if (thd_table->db_stat)		// If table is open
          {
            bool found;
	    found= mysql_lock_abort_for_thread(thd, thd_table);
            signalled|= found;
          }
	    signalled|= mysql_lock_abort_for_thread(thd, thd_table);
        }
      }
      else
        result= result || return_if_owned_by_thd;
        result= result || (flags & RTFC_OWNED_BY_THD_FLAG);
    }
    while (unused_tables && !unused_tables->version)
      VOID(hash_delete(&open_cache,(byte*) unused_tables));
    if (result && wait_for_other_thread)
    if (result && (flags & RTFC_WAIT_OTHER_THREAD_FLAG))
    {
      if (!check_killed_flag || !thd->killed)
      if (!(flags & RTFC_CHECK_KILLED_FLAG) || !thd->killed)
      {
        if (likely(signalled))
        {
@@ -2508,7 +2500,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
      }
    }
    break;
  } while (1);
  }
  DBUG_RETURN(result);
}

+6 −9
Original line number Diff line number Diff line
@@ -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));