summaryrefslogtreecommitdiff
path: root/sql/sql_insert.cc
diff options
context:
space:
mode:
authorunknown <ingo@mysql.com>2005-05-31 19:37:24 +0200
committerunknown <ingo@mysql.com>2005-05-31 19:37:24 +0200
commit57d4adf60c7b4c0d341903a29d64f96359e78adb (patch)
tree3a0071aee0fc84c8565299dbf4136b73fbea5c29 /sql/sql_insert.cc
parent7b4385f4725f99ed5115b0f89174fc358498cfe0 (diff)
parentcf2188ca398e12d4a10c50b069c2243825f9dced (diff)
downloadmariadb-git-57d4adf60c7b4c0d341903a29d64f96359e78adb.tar.gz
Bug#10224 - ANALYZE TABLE crashing with simultaneous CREATE ... SELECT statement.
Hand merged from 4.0. sql/lock.cc: Auto merged sql/mysql_priv.h: Auto merged sql/sql_acl.cc: Auto merged sql/sql_handler.cc: Auto merged sql/sql_table.cc: Auto merged
Diffstat (limited to 'sql/sql_insert.cc')
-rw-r--r--sql/sql_insert.cc24
1 files changed, 18 insertions, 6 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 0258f2c3e07..de3575dd856 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -882,10 +882,13 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
Avoid that a global read lock steps in while we are creating the
new thread. It would block trying to open the table. Hence, the
DI thread and this thread would wait until after the global
- readlock is gone. If the read lock exists already, we leave with
- no table and then switch to non-delayed insert.
+ readlock is gone. Since the insert thread needs to wait for a
+ global read lock anyway, we do it right now. Note that
+ wait_if_global_read_lock() sets a protection against a new
+ global read lock when it succeeds. This needs to be released by
+ start_waiting_global_read_lock().
*/
- if (set_protect_against_global_read_lock())
+ if (wait_if_global_read_lock(thd, 0, 1))
goto err;
if (!(tmp=new delayed_insert()))
{
@@ -927,7 +930,11 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
pthread_cond_wait(&tmp->cond_client,&tmp->mutex);
}
pthread_mutex_unlock(&tmp->mutex);
- unset_protect_against_global_read_lock();
+ /*
+ Release the protection against the global read lock and wake
+ everyone, who might want to set a global read lock.
+ */
+ start_waiting_global_read_lock(thd);
thd->proc_info="got old table";
if (tmp->thd.killed)
{
@@ -963,7 +970,11 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
err1:
thd->fatal_error();
- unset_protect_against_global_read_lock();
+ /*
+ Release the protection against the global read lock and wake
+ everyone, who might want to set a global read lock.
+ */
+ start_waiting_global_read_lock(thd);
err:
pthread_mutex_unlock(&LOCK_delayed_create);
DBUG_RETURN(0); // Continue with normal insert
@@ -1319,7 +1330,8 @@ extern "C" pthread_handler_decl(handle_delayed_insert,arg)
handler will close the table and finish when the outstanding
inserts are done.
*/
- if (! (thd->lock= mysql_lock_tables(thd, &di->table, 1, TRUE)))
+ if (! (thd->lock= mysql_lock_tables(thd, &di->table, 1,
+ MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK)))
{
di->dead= 1; // Some fatal error
thd->killed= 1;