summaryrefslogtreecommitdiff
path: root/sql/sql_handler.cc
diff options
context:
space:
mode:
authorunknown <ramil/ram@mysql.com/myoffice.izhnet.ru>2006-11-27 13:24:24 +0400
committerunknown <ramil/ram@mysql.com/myoffice.izhnet.ru>2006-11-27 13:24:24 +0400
commit838b5378cb1998b27b106273f5e9043838888d39 (patch)
tree971fa749151a84c6076f08303a977feaa2d22906 /sql/sql_handler.cc
parent3c47f57f81156f7ba9707cfe7e506579b649866d (diff)
downloadmariadb-git-838b5378cb1998b27b106273f5e9043838888d39.tar.gz
Fix for bug #21587: FLUSH TABLES causes server crash when used with HANDLER statements
Problems (appear 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: end open index scans and table scans and remove references to the tables from the handler tables hash. After this preparation it is safe to close the tables. The close can no longer fail on open index/table scans and the closed table will not be used again by handler functions. sql/mysql_priv.h: 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: Fix for bug #21587: FLUSH TABLES causes server crash when used with HANDLER statements - call mysql_ha_mark_tables_for_reopen() to prepare for the following close. sql/sql_handler.cc: Fix for bug #21587: FLUSH TABLES causes server crash when used with HANDLER statements - mysql_ha_mark_tables_for_reopen() function introduced.
Diffstat (limited to 'sql/sql_handler.cc')
-rw-r--r--sql/sql_handler.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index 0193d4d5355..77c7bf137fb 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -748,3 +748,41 @@ static int mysql_ha_flush_table(THD *thd, TABLE **table_ptr, uint mode_flags)
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
+ For each table found in the handler hash mark it as closed
+ (ready for reopen) and end all index/table scans.
+
+ 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");
+
+ safe_mutex_assert_owner(&LOCK_open);
+ 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;
+ /* End open index/table scans. */
+ table->file->ha_index_or_rnd_end();
+ }
+ }
+ DBUG_VOID_RETURN;
+}