Commit 6b2f6cb2 authored by marko's avatar marko

branches/5.1: lock_is_table_exclusive(): Acquire kernel_mutex before

accessing table->locks and release kernel_mutex before returning from
the function.  This fixes a portential race condition in the
"commit every 10,000 rows" in ALTER TABLE, CREATE INDEX, DROP INDEX,
and OPTIMIZE TABLE. (Bug #42152)

rb://80 approved by Heikki Tuuri
parent 7d5683b6
...@@ -681,7 +681,10 @@ lock_is_table_exclusive( ...@@ -681,7 +681,10 @@ lock_is_table_exclusive(
lock_t* lock; lock_t* lock;
ibool ok = FALSE; ibool ok = FALSE;
ut_ad(table && trx); ut_ad(table);
ut_ad(trx);
lock_mutex_enter_kernel();
for (lock = UT_LIST_GET_FIRST(table->locks); for (lock = UT_LIST_GET_FIRST(table->locks);
lock; lock;
...@@ -689,7 +692,7 @@ lock_is_table_exclusive( ...@@ -689,7 +692,7 @@ lock_is_table_exclusive(
if (lock->trx != trx) { if (lock->trx != trx) {
/* A lock on the table is held /* A lock on the table is held
by some other transaction. */ by some other transaction. */
return(FALSE); goto not_ok;
} }
if (!(lock_get_type(lock) & LOCK_TABLE)) { if (!(lock_get_type(lock) & LOCK_TABLE)) {
...@@ -706,11 +709,16 @@ lock_is_table_exclusive( ...@@ -706,11 +709,16 @@ lock_is_table_exclusive(
auto_increment lock. */ auto_increment lock. */
break; break;
default: default:
not_ok:
/* Other table locks than LOCK_IX are not allowed. */ /* Other table locks than LOCK_IX are not allowed. */
return(FALSE); ok = FALSE;
goto func_exit;
} }
} }
func_exit:
lock_mutex_exit_kernel();
return(ok); return(ok);
} }
...@@ -3664,6 +3672,7 @@ lock_table_has_to_wait_in_queue( ...@@ -3664,6 +3672,7 @@ lock_table_has_to_wait_in_queue(
dict_table_t* table; dict_table_t* table;
lock_t* lock; lock_t* lock;
ut_ad(mutex_own(&kernel_mutex));
ut_ad(lock_get_wait(wait_lock)); ut_ad(lock_get_wait(wait_lock));
table = wait_lock->un_member.tab_lock.table; table = wait_lock->un_member.tab_lock.table;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment