From: Date: November 16 2006 12:04pm Subject: bk commit into 5.0 tree (ramil:1.2296) BUG#21587 List-Archive: http://lists.mysql.com/commits/15402 X-Bug: 21587 Message-Id: <200611161104.kAGB4ev3015146@myoffice.izhnet.ru> Below is the list of changes that have just been committed into a local 5.0 repository of ram. When ram does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet@stripped, 2006-11-16 15:04:31+04:00, ramil@stripped +3 -0 Fix for bug #21587: FLUSH TABLES causes server crash when used with HANDLER statements Problem (appears only under some circumstances): 1. we get a reference to a deleted table searching in the thd->handler_tables_hash in the mysql_ha_read(). 2. DBUG_ASSERT(table->file->inited == handler::NONE); assert fails in the close_thread_table(). Fix: mark tables in the thd->handler_tables_hash as ready for reopen before the close_thread_table() cyclic calls in the close_thread_tables(). sql/mysql_priv.h@stripped, 2006-11-16 15:04:26+04:00, ramil@stripped +1 -0 Fix for bug #21587: FLUSH TABLES causes server crash when used with HANDLER statements - mysql_ha_mark_tables_for_reopen() introduced. sql/sql_base.cc@stripped, 2006-11-16 15:04:27+04:00, ramil@stripped +4 -1 Fix for bug #21587: FLUSH TABLES causes server crash when used with HANDLER statements - call mysql_ha_mark_tables_for_reopen() to mark tables in the thd->handler_tables_hash as ready for reopen. sql/sql_handler.cc@stripped, 2006-11-16 15:04:27+04:00, ramil@stripped +37 -0 Fix for bug #21587: FLUSH TABLES causes server crash when used with HANDLER statements - mysql_ha_mark_tables_for_reopen() function introduced. # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: ramil # Host: myoffice.izhnet.ru # Root: /usr/home/ram/work/bug21587/my50-bug21587 --- 1.420/sql/mysql_priv.h 2006-11-16 15:04:39 +04:00 +++ 1.421/sql/mysql_priv.h 2006-11-16 15:04:39 +04:00 @@ -941,6 +941,7 @@ bool mysql_ha_read(THD *, TABLE_LIST *,e List *,enum ha_rkey_function,Item *,ha_rows,ha_rows); int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags, bool is_locked); +void mysql_ha_mark_tables_for_reopen(THD *thd, TABLE *table); /* mysql_ha_flush mode_flags bits */ #define MYSQL_HA_CLOSE_FINAL 0x00 #define MYSQL_HA_REOPEN_ON_USAGE 0x01 --- 1.355/sql/sql_base.cc 2006-11-16 15:04:39 +04:00 +++ 1.356/sql/sql_base.cc 2006-11-16 15:04:39 +04:00 @@ -519,7 +519,10 @@ void close_thread_tables(THD *thd, bool DBUG_PRINT("info", ("thd->open_tables: %p", thd->open_tables)); - found_old_table= 0; + /* Mark tables in the thd->handler_tables_hash as ready for reopen. */ + mysql_ha_mark_tables_for_reopen(thd, thd->open_tables); + + found_old_table= 0; while (thd->open_tables) found_old_table|=close_thread_table(thd, &thd->open_tables); thd->some_tables_deleted=0; --- 1.83/sql/sql_handler.cc 2006-11-16 15:04:39 +04:00 +++ 1.84/sql/sql_handler.cc 2006-11-16 15:04:39 +04:00 @@ -748,3 +748,40 @@ static int mysql_ha_flush_table(THD *thd DBUG_RETURN(0); } + + +/* + Mark tables for reopen. + + SYNOPSIS + mysql_ha_mark_tables_for_reopen() + thd Thread identifier. + table Table list to mark for reopen. + + DESCRIPTION + Mark all tables from the table list which are in the + thd->handler_tables_hash for reopen. + + NOTE + The caller must lock LOCK_open. +*/ + +void mysql_ha_mark_tables_for_reopen(THD *thd, TABLE *table) +{ + DBUG_ENTER("mysql_ha_mark_tables_for_reopen"); + + for (; table; table= table->next) + { + TABLE_LIST *hash_tables; + if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash, + (byte*) table->alias, + strlen(table->alias) + 1))) + { + /* Mark table as ready for reopen. */ + hash_tables->table= NULL; + safe_mutex_assert_owner(&LOCK_open); + table->file->ha_index_or_rnd_end(); + } + } + DBUG_VOID_RETURN; +}