diff options
author | heikki@donna.mysql.fi <> | 2001-10-10 22:47:08 +0300 |
---|---|---|
committer | heikki@donna.mysql.fi <> | 2001-10-10 22:47:08 +0300 |
commit | 1d7747aa25fba426b9acbd21fcc362bb461b2c4b (patch) | |
tree | fc361924d14a3d1727a8b88f61352ed039054720 /innobase/lock | |
parent | a88a9842aa61e31e07dda8bc506f7f43e0636292 (diff) | |
download | mariadb-git-1d7747aa25fba426b9acbd21fcc362bb461b2c4b.tar.gz |
ut0mem.c Merge changes in InnoDB-3.23.43b
ut0ut.c Merge changes in InnoDB-3.23.43b
trx0purge.c Merge changes in InnoDB-3.23.43b
trx0rec.c Merge changes in InnoDB-3.23.43b
trx0trx.c Merge changes in InnoDB-3.23.43b
trx0undo.c Merge changes in InnoDB-3.23.43b
thr0loc.c Merge changes in InnoDB-3.23.43b
sync0arr.c Merge changes in InnoDB-3.23.43b
sync0rw.c Merge changes in InnoDB-3.23.43b
sync0sync.c Merge changes in InnoDB-3.23.43b
srv0srv.c Merge changes in InnoDB-3.23.43b
srv0start.c Merge changes in InnoDB-3.23.43b
row0ins.c Merge changes in InnoDB-3.23.43b
row0mysql.c Merge changes in InnoDB-3.23.43b
row0purge.c Merge changes in InnoDB-3.23.43b
row0sel.c Merge changes in InnoDB-3.23.43b
row0umod.c Merge changes in InnoDB-3.23.43b
row0upd.c Merge changes in InnoDB-3.23.43b
row0vers.c Merge changes in InnoDB-3.23.43b
rem0cmp.c Merge changes in InnoDB-3.23.43b
que0que.c Merge changes in InnoDB-3.23.43b
pars0opt.c Merge changes in InnoDB-3.23.43b
pars0pars.c Merge changes in InnoDB-3.23.43b
lexyy.c Merge changes in InnoDB-3.23.43b
pars0grm.c Merge changes in InnoDB-3.23.43b
page0page.c Merge changes in InnoDB-3.23.43b
os0file.c Merge changes in InnoDB-3.23.43b
mtr0log.c Merge changes in InnoDB-3.23.43b
mem0pool.c Merge changes in InnoDB-3.23.43b
log0log.c Merge changes in InnoDB-3.23.43b
log0recv.c Merge changes in InnoDB-3.23.43b
lock0lock.c Merge changes in InnoDB-3.23.43b
ibuf0ibuf.c Merge changes in InnoDB-3.23.43b
fil0fil.c Merge changes in InnoDB-3.23.43b
dict0crea.c Merge changes in InnoDB-3.23.43b
dict0dict.c Merge changes in InnoDB-3.23.43b
dict0load.c Merge changes in InnoDB-3.23.43b
dict0mem.c Merge changes in InnoDB-3.23.43b
data0data.c Merge changes in InnoDB-3.23.43b
data0type.c Merge changes in InnoDB-3.23.43b
buf0buf.c Merge changes in InnoDB-3.23.43b
buf0lru.c Merge changes in InnoDB-3.23.43b
btr0btr.c Merge changes in InnoDB-3.23.43b
btr0cur.c Merge changes in InnoDB-3.23.43b
btr0pcur.c Merge changes in InnoDB-3.23.43b
btr0sea.c Merge changes in InnoDB-3.23.43b
data0type.ic Merge changes in InnoDB-3.23.43b
dict0dict.ic Merge changes in InnoDB-3.23.43b
mtr0mtr.ic Merge changes in InnoDB-3.23.43b
row0upd.ic Merge changes in InnoDB-3.23.43b
sync0ipm.ic Merge changes in InnoDB-3.23.43b
sync0rw.ic Merge changes in InnoDB-3.23.43b
sync0sync.ic Merge changes in InnoDB-3.23.43b
trx0rseg.ic Merge changes in InnoDB-3.23.43b
btr0pcur.ic Merge changes in InnoDB-3.23.43b
buf0buf.ic Merge changes in InnoDB-3.23.43b
data0data.ic Merge changes in InnoDB-3.23.43b
row0upd.h Merge changes in InnoDB-3.23.43b
srv0srv.h Merge changes in InnoDB-3.23.43b
sync0arr.h Merge changes in InnoDB-3.23.43b
sync0rw.h Merge changes in InnoDB-3.23.43b
sync0sync.h Merge changes in InnoDB-3.23.43b
trx0trx.h Merge changes in InnoDB-3.23.43b
ut0mem.h Merge changes in InnoDB-3.23.43b
data0data.h Merge changes in InnoDB-3.23.43b
data0type.h Merge changes in InnoDB-3.23.43b
db0err.h Merge changes in InnoDB-3.23.43b
dict0crea.h Merge changes in InnoDB-3.23.43b
dict0dict.h Merge changes in InnoDB-3.23.43b
dict0load.h Merge changes in InnoDB-3.23.43b
dict0mem.h Merge changes in InnoDB-3.23.43b
dict0types.h Merge changes in InnoDB-3.23.43b
fil0fil.h Merge changes in InnoDB-3.23.43b
ibuf0ibuf.h Merge changes in InnoDB-3.23.43b
lock0lock.h Merge changes in InnoDB-3.23.43b
log0log.h Merge changes in InnoDB-3.23.43b
mtr0mtr.h Merge changes in InnoDB-3.23.43b
rem0cmp.h Merge changes in InnoDB-3.23.43b
row0ins.h Merge changes in InnoDB-3.23.43b
row0mysql.h Merge changes in InnoDB-3.23.43b
btr0cur.h Merge changes in InnoDB-3.23.43b
btr0pcur.h Merge changes in InnoDB-3.23.43b
btr0sea.h Merge changes in InnoDB-3.23.43b
buf0buf.h Merge changes in InnoDB-3.23.43b
sql_table.cc Merge changes in InnoDB-3.23.43b
sql_db.cc Merge changes in InnoDB-3.23.43b
ha_innobase.cc Merge changes in InnoDB-3.23.43b
handler.cc Merge changes in InnoDB-3.23.43b
ha_innobase.h Merge changes in InnoDB-3.23.43b
handler.h Merge changes in InnoDB-3.23.43b
Diffstat (limited to 'innobase/lock')
-rw-r--r-- | innobase/lock/lock0lock.c | 116 |
1 files changed, 104 insertions, 12 deletions
diff --git a/innobase/lock/lock0lock.c b/innobase/lock/lock0lock.c index df35e22005f..fa0641bad73 100644 --- a/innobase/lock/lock0lock.c +++ b/innobase/lock/lock0lock.c @@ -578,6 +578,17 @@ lock_sys_create( } /************************************************************************* +Gets the size of a lock struct. */ + +ulint +lock_get_size(void) +/*===============*/ + /* out: size in bytes */ +{ + return((ulint)sizeof(lock_t)); +} + +/************************************************************************* Gets the mode of a lock. */ UNIV_INLINE ulint @@ -709,13 +720,17 @@ lock_mode_stronger_or_eq( ulint mode2) /* in: lock mode */ { ut_ad(mode1 == LOCK_X || mode1 == LOCK_S || mode1 == LOCK_IX - || mode1 == LOCK_IS); + || mode1 == LOCK_IS || mode1 == LOCK_AUTO_INC); ut_ad(mode2 == LOCK_X || mode2 == LOCK_S || mode2 == LOCK_IX - || mode2 == LOCK_IS); + || mode2 == LOCK_IS || mode2 == LOCK_AUTO_INC); if (mode1 == LOCK_X) { return(TRUE); + } else if (mode1 == LOCK_AUTO_INC && mode2 == LOCK_AUTO_INC) { + + return(TRUE); + } else if (mode1 == LOCK_S && (mode2 == LOCK_S || mode2 == LOCK_IS)) { return(TRUE); @@ -743,9 +758,9 @@ lock_mode_compatible( ulint mode2) /* in: lock mode */ { ut_ad(mode1 == LOCK_X || mode1 == LOCK_S || mode1 == LOCK_IX - || mode1 == LOCK_IS); + || mode1 == LOCK_IS || mode1 == LOCK_AUTO_INC); ut_ad(mode2 == LOCK_X || mode2 == LOCK_S || mode2 == LOCK_IX - || mode2 == LOCK_IS); + || mode2 == LOCK_IS || mode2 == LOCK_AUTO_INC); if (mode1 == LOCK_S && (mode2 == LOCK_IS || mode2 == LOCK_S)) { @@ -755,12 +770,18 @@ lock_mode_compatible( return(FALSE); + } else if (mode1 == LOCK_AUTO_INC && (mode2 == LOCK_IS + || mode2 == LOCK_IX)) { + return(TRUE); + } else if (mode1 == LOCK_IS && (mode2 == LOCK_IS || mode2 == LOCK_IX + || mode2 == LOCK_AUTO_INC || mode2 == LOCK_S)) { return(TRUE); } else if (mode1 == LOCK_IX && (mode2 == LOCK_IS + || mode2 == LOCK_AUTO_INC || mode2 == LOCK_IX)) { return(TRUE); } @@ -1836,7 +1857,7 @@ lock_grant( Cancels a waiting record lock request and releases the waiting transaction that requested it. NOTE: does NOT check if waiting lock requests behind this one can now be granted! */ - +static void lock_rec_cancel( /*============*/ @@ -2812,7 +2833,18 @@ lock_table_create( ut_ad(table && trx); ut_ad(mutex_own(&kernel_mutex)); - lock = mem_heap_alloc(trx->lock_heap, sizeof(lock_t)); + if (type_mode == LOCK_AUTO_INC) { + /* Only one trx can have the lock on the table + at a time: we may use the memory preallocated + to the table object */ + + lock = table->auto_inc_lock; + + ut_a(trx->auto_inc_lock == NULL); + trx->auto_inc_lock = lock; + } else { + lock = mem_heap_alloc(trx->lock_heap, sizeof(lock_t)); + } if (lock == NULL) { @@ -2854,6 +2886,10 @@ lock_table_remove_low( table = lock->un_member.tab_lock.table; trx = lock->trx; + if (lock == trx->auto_inc_lock) { + trx->auto_inc_lock = NULL; + } + UT_LIST_REMOVE(trx_locks, trx->trx_locks, lock); UT_LIST_REMOVE(un_member.tab_lock.locks, table->locks, lock); } @@ -2988,7 +3024,7 @@ lock_table( if (lock_table_other_has_incompatible(trx, LOCK_WAIT, table, mode)) { - /* Another trx has request on the table in an incompatible + /* Another trx has a request on the table in an incompatible mode: this trx must wait */ err = lock_table_enqueue_waiting(mode, table, thr); @@ -3102,6 +3138,24 @@ lock_table_dequeue( /*=========================== LOCK RELEASE ==============================*/ /************************************************************************* +Releases an auto-inc lock a transaction possibly has on a table. +Releases possible other transactions waiting for this lock. */ + +void +lock_table_unlock_auto_inc( +/*=======================*/ + trx_t* trx) /* in: transaction */ +{ + if (trx->auto_inc_lock) { + mutex_enter(&kernel_mutex); + + lock_table_dequeue(trx->auto_inc_lock); + + mutex_exit(&kernel_mutex); + } +} + +/************************************************************************* Releases transaction locks, and releases possible other transactions waiting because of these locks. */ @@ -3147,6 +3201,37 @@ lock_release_off_kernel( } mem_heap_empty(trx->lock_heap); + + ut_a(trx->auto_inc_lock == NULL); +} + +/************************************************************************* +Cancels a waiting lock request and releases possible other transactions +waiting behind it. */ + +void +lock_cancel_waiting_and_release( +/*============================*/ + lock_t* lock) /* in: waiting lock request */ +{ + ut_ad(mutex_own(&kernel_mutex)); + + if (lock_get_type(lock) == LOCK_REC) { + + lock_rec_dequeue_from_page(lock); + } else { + ut_ad(lock_get_type(lock) == LOCK_TABLE); + + lock_table_dequeue(lock); + } + + /* Reset the wait flag and the back pointer to lock in trx */ + + lock_reset_lock_and_trx_wait(lock); + + /* The following function releases the trx from lock wait */ + + trx_end_lock_wait(lock->trx); } /************************************************************************* @@ -3237,8 +3322,10 @@ lock_table_print( printf(" lock_mode IS"); } else if (lock_get_mode(lock) == LOCK_IX) { printf(" lock_mode IX"); + } else if (lock_get_mode(lock) == LOCK_AUTO_INC) { + printf(" lock_mode AUTO-INC"); } else { - ut_error; + printf(" unknown lock_mode %lu", lock_get_mode(lock)); } if (lock_get_wait(lock)) { @@ -3304,10 +3391,7 @@ lock_rec_print( page = buf_page_get_gen(space, page_no, RW_NO_LATCH, NULL, BUF_GET_IF_IN_POOL, -#ifdef UNIV_SYNC_DEBUG - IB__FILE__, __LINE__, -#endif - &mtr); + IB__FILE__, __LINE__, &mtr); if (page) { page = buf_page_get_nowait(space, page_no, RW_S_LATCH, &mtr); } @@ -3417,6 +3501,11 @@ loop: trx = UT_LIST_GET_FIRST(trx_sys->trx_list); i = 0; + + /* Since we temporarily release the kernel mutex when + reading a database page in below, variable trx may be + obsolete now and we must loop through the trx list to + get probably the same trx, or some other trx. */ while (trx && (i < nth_trx)) { trx = UT_LIST_GET_NEXT(trx_list, trx); @@ -3466,6 +3555,9 @@ loop: i = 0; + /* Look at the note about the trx loop above why we loop here: + lock may be an obsolete pointer now. */ + lock = UT_LIST_GET_FIRST(trx->trx_locks); while (lock && (i < nth_lock)) { |