Commit 17c0218a authored by Timothy Smith's avatar Timothy Smith

Applying InnoDB snashot 5.1-ss4007, part 2. Fixes

Bug #42152: Race condition in lock_is_table_exclusive()

Detailed revision comments:

r4005 | marko | 2009-01-20 16:22:36 +0200 (Tue, 20 Jan 2009) | 8 lines
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 d2e4204a
...@@ -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