#At file:///export/home/z/mysql-azalea-bugfixing-bug45949/ based on revid:alik@stripped
2856 Jon Olav Hauglid 2009-08-13
Bug #45949 Assertion `!tables->table' in open_tables() on
ALTER + INSERT DELAYED
The assertion was caused by improperly closing tables when
INSERT DELAYED needed to reopen tables. This patch replaces
the call to close_thread_tables with close_tables_for_reopen
which fixes the problem.
The only way I was able to trigger the reopen code path and
thus the assertion, was if ALTER TABLE killed the delayed
insert thread and the delayed insert thread was able to enter
the reopen code path before it noticed that thd->killed had
been set. Note that in these cases reopen will always fail
since open_table() will check thd->killed and return. This patch
therefore adds two more thd->killed checks to minimize the
chance of entering the reopen code path without hope for success.
The patch also changes the killed_state used when aborting INSERT
DELAYED. It used to be KILL_CONNECTION which is mapped to
ER_SERVER_SHUTDOWN. It has been changed to the more appropriate
KILL_QUERY (=ER_QUERY_INTERRUPTED).
No test case is supplied. This is for two reasons:
1) Unable to reproduce the error without having the delayed insert
thread in a killed state which means that reopen is futile and
was not supposed to be attempted.
2) Difficulty of using sync points in other threads than
the connection thread.
The patch has been successfully tested with the RQG and the grammar
supplied in the bug description.
modified:
sql/sql_base.cc
sql/sql_insert.cc
=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc 2009-08-04 19:50:51 +0000
+++ b/sql/sql_base.cc 2009-08-13 10:58:10 +0000
@@ -7734,7 +7734,7 @@ bool mysql_notify_thread_having_shared_l
if ((in_use->system_thread & SYSTEM_THREAD_DELAYED_INSERT) &&
!in_use->killed)
{
- in_use->killed= THD::KILL_CONNECTION;
+ in_use->killed= THD::KILL_QUERY;
pthread_mutex_lock(&in_use->mysys_var->mutex);
if (in_use->mysys_var->current_cond)
pthread_cond_broadcast(in_use->mysys_var->current_cond);
=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc 2009-07-31 19:46:24 +0000
+++ b/sql/sql_insert.cc 2009-08-13 10:58:10 +0000
@@ -2294,7 +2294,7 @@ void kill_delayed_threads(void)
Delayed_insert *di;
while ((di= it++))
{
- di->thd.killed= THD::KILL_CONNECTION;
+ di->thd.killed= THD::KILL_QUERY;
if (di->thd.mysys_var)
{
pthread_mutex_lock(&di->thd.mysys_var->mutex);
@@ -2369,7 +2369,7 @@ pthread_handler_t handle_delayed_insert(
thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
thd->set_current_time();
threads.append(thd);
- thd->killed=abort_loop ? THD::KILL_CONNECTION : THD::NOT_KILLED;
+ thd->killed=abort_loop ? THD::KILL_QUERY : THD::NOT_KILLED;
pthread_mutex_unlock(&LOCK_thread_count);
/*
@@ -2426,7 +2426,7 @@ pthread_handler_t handle_delayed_insert(
for (;;)
{
- if (thd->killed == THD::KILL_CONNECTION)
+ if (thd->killed)
{
uint lock_count;
/*
@@ -2475,7 +2475,7 @@ pthread_handler_t handle_delayed_insert(
break;
if (error == ETIMEDOUT || error == ETIME)
{
- thd->killed= THD::KILL_CONNECTION;
+ thd->killed= THD::KILL_QUERY;
break;
}
}
@@ -2489,7 +2489,7 @@ pthread_handler_t handle_delayed_insert(
}
thd_proc_info(&(di->thd), 0);
- if (di->tables_in_use && ! thd->lock)
+ if (di->tables_in_use && ! thd->lock && !thd->killed)
{
bool need_reopen;
/*
@@ -2506,26 +2506,27 @@ pthread_handler_t handle_delayed_insert(
MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK,
&need_reopen)))
{
- if (need_reopen)
+ if (need_reopen && !thd->killed)
{
/*
We were waiting to obtain TL_WRITE_DELAYED (probably due to
someone having or requesting TL_WRITE_ALLOW_READ) and got
aborted. Try to reopen table and if it fails die.
*/
- close_thread_tables(thd);
+ TABLE_LIST *tl_ptr = &di->table_list;
+ close_tables_for_reopen(thd, &tl_ptr, FALSE);
di->table= 0;
if (di->open_and_lock_table())
{
di->dead= 1;
- thd->killed= THD::KILL_CONNECTION;
+ thd->killed= THD::KILL_QUERY;
}
}
else
{
/* Fatal error */
di->dead= 1;
- thd->killed= THD::KILL_CONNECTION;
+ thd->killed= THD::KILL_QUERY;
}
}
pthread_cond_broadcast(&di->cond_client);
@@ -2534,9 +2535,9 @@ pthread_handler_t handle_delayed_insert(
{
if (di->handle_inserts())
{
- /* Some fatal error */
- di->dead= 1;
- thd->killed= THD::KILL_CONNECTION;
+ /* Some fatal error */
+ di->dead= 1;
+ thd->killed= THD::KILL_QUERY;
}
}
di->status=0;
@@ -2586,7 +2587,7 @@ end:
di->table=0;
di->dead= 1; // If error
- thd->killed= THD::KILL_CONNECTION; // If error
+ thd->killed= THD::KILL_QUERY; // If error
pthread_mutex_unlock(&di->mutex);
close_thread_tables(thd); // Free the table
@@ -2664,7 +2665,7 @@ bool Delayed_insert::handle_inserts(void
max_rows= delayed_insert_limit;
if (thd.killed || table->needs_reopen())
{
- thd.killed= THD::KILL_CONNECTION;
+ thd.killed= THD::KILL_QUERY;
max_rows= ULONG_MAX; // Do as much as possible
}
Attachment: [text/bzr-bundle] bzr/jon.hauglid@sun.com-20090813105810-c0clitf3306tr57t.bundle
Thread |
---|
• bzr commit into mysql branch (jon.hauglid:2856) Bug#45949 | Jon Olav Hauglid | 13 Aug |