Commit a3233427 authored by marko@hundin.mysql.fi's avatar marko@hundin.mysql.fi

InnoDB: LOCK TABLE clean-up

parent bea2f430
...@@ -418,7 +418,8 @@ lock_release_off_kernel( ...@@ -418,7 +418,8 @@ lock_release_off_kernel(
/*====================*/ /*====================*/
trx_t* trx); /* in: transaction */ trx_t* trx); /* in: transaction */
/************************************************************************* /*************************************************************************
Releases table locks, and releases possible other transactions waiting Releases table locks explicitly requested with LOCK TABLES (indicated by
lock type LOCK_TABLE_EXP), and releases possible other transactions waiting
because of these locks. */ because of these locks. */
void void
...@@ -548,7 +549,7 @@ extern lock_sys_t* lock_sys; ...@@ -548,7 +549,7 @@ extern lock_sys_t* lock_sys;
/* Lock types */ /* Lock types */
#define LOCK_TABLE 16 /* these type values should be so high that */ #define LOCK_TABLE 16 /* these type values should be so high that */
#define LOCK_REC 32 /* they can be ORed to the lock mode */ #define LOCK_REC 32 /* they can be ORed to the lock mode */
#define LOCK_TABLE_EXP 80 /* explicit table lock */ #define LOCK_TABLE_EXP 80 /* explicit table lock (80 = 16 + 64) */
#define LOCK_TYPE_MASK 0xF0UL /* mask used to extract lock type from the #define LOCK_TYPE_MASK 0xF0UL /* mask used to extract lock type from the
type_mode field in a lock */ type_mode field in a lock */
/* Waiting lock flag */ /* Waiting lock flag */
......
...@@ -153,11 +153,12 @@ row_lock_table_autoinc_for_mysql( ...@@ -153,11 +153,12 @@ row_lock_table_autoinc_for_mysql(
row_prebuilt_t* prebuilt); /* in: prebuilt struct in the MySQL row_prebuilt_t* prebuilt); /* in: prebuilt struct in the MySQL
table handle */ table handle */
/************************************************************************* /*************************************************************************
Unlocks a table lock possibly reserved by trx. */ Unlocks all table locks explicitly requested by trx (with LOCK TABLES,
lock type LOCK_TABLE_EXP). */
void void
row_unlock_table_for_mysql( row_unlock_tables_for_mysql(
/*=======================*/ /*========================*/
trx_t* trx); /* in: transaction */ trx_t* trx); /* in: transaction */
/************************************************************************* /*************************************************************************
Sets a table lock on the table mentioned in prebuilt. */ Sets a table lock on the table mentioned in prebuilt. */
......
...@@ -423,8 +423,9 @@ struct trx_struct{ ...@@ -423,8 +423,9 @@ struct trx_struct{
lock_t* auto_inc_lock; /* possible auto-inc lock reserved by lock_t* auto_inc_lock; /* possible auto-inc lock reserved by
the transaction; note that it is also the transaction; note that it is also
in the lock list trx_locks */ in the lock list trx_locks */
ulint n_tables_locked;/* number of table locks reserved by ulint n_lock_table_exp;/* number of explicit table locks
the transaction, stored in trx_locks */ (LOCK TABLES) reserved by the
transaction, stored in trx_locks */
UT_LIST_NODE_T(trx_t) UT_LIST_NODE_T(trx_t)
trx_list; /* list of transactions */ trx_list; /* list of transactions */
UT_LIST_NODE_T(trx_t) UT_LIST_NODE_T(trx_t)
......
...@@ -2023,9 +2023,8 @@ lock_grant( ...@@ -2023,9 +2023,8 @@ lock_grant(
lock->trx->auto_inc_lock = lock; lock->trx->auto_inc_lock = lock;
} else if (lock_get_type(lock) == LOCK_TABLE_EXP) { } else if (lock_get_type(lock) == LOCK_TABLE_EXP) {
ut_ad(lock_get_mode(lock) == LOCK_S ut_a(lock_get_mode(lock) == LOCK_S
|| lock_get_mode(lock) == LOCK_X); || lock_get_mode(lock) == LOCK_X);
lock->trx->n_tables_locked++;
} }
if (lock_print_waits) { if (lock_print_waits) {
...@@ -3203,6 +3202,10 @@ lock_table_create( ...@@ -3203,6 +3202,10 @@ lock_table_create(
lock->type_mode = type_mode | LOCK_TABLE; lock->type_mode = type_mode | LOCK_TABLE;
lock->trx = trx; lock->trx = trx;
if ((lock->type_mode & LOCK_TABLE_EXP) == LOCK_TABLE_EXP) {
lock->trx->n_lock_table_exp++;
}
lock->un_member.tab_lock.table = table; lock->un_member.tab_lock.table = table;
UT_LIST_ADD_LAST(un_member.tab_lock.locks, table->locks, lock); UT_LIST_ADD_LAST(un_member.tab_lock.locks, table->locks, lock);
...@@ -3386,7 +3389,7 @@ lock_table( ...@@ -3386,7 +3389,7 @@ lock_table(
return(DB_SUCCESS); return(DB_SUCCESS);
} }
ut_ad(flags == 0 || flags == LOCK_TABLE_EXP); ut_a(flags == 0 || flags == LOCK_TABLE_EXP);
trx = thr_get_trx(thr); trx = thr_get_trx(thr);
...@@ -3418,10 +3421,7 @@ lock_table( ...@@ -3418,10 +3421,7 @@ lock_table(
lock_table_create(table, mode | flags, trx); lock_table_create(table, mode | flags, trx);
if (flags) { ut_a(!flags || mode == LOCK_S || mode == LOCK_X);
ut_ad(mode == LOCK_S || mode == LOCK_X);
trx->n_tables_locked++;
}
lock_mutex_exit_kernel(); lock_mutex_exit_kernel();
...@@ -3502,7 +3502,7 @@ lock_table_dequeue( ...@@ -3502,7 +3502,7 @@ lock_table_dequeue(
#ifdef UNIV_SYNC_DEBUG #ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex)); ut_ad(mutex_own(&kernel_mutex));
#endif /* UNIV_SYNC_DEBUG */ #endif /* UNIV_SYNC_DEBUG */
ut_ad(lock_get_type(in_lock) == LOCK_TABLE || ut_a(lock_get_type(in_lock) == LOCK_TABLE ||
lock_get_type(in_lock) == LOCK_TABLE_EXP); lock_get_type(in_lock) == LOCK_TABLE_EXP);
lock = UT_LIST_GET_NEXT(un_member.tab_lock.locks, in_lock); lock = UT_LIST_GET_NEXT(un_member.tab_lock.locks, in_lock);
...@@ -3607,9 +3607,9 @@ lock_release_off_kernel( ...@@ -3607,9 +3607,9 @@ lock_release_off_kernel(
lock_table_dequeue(lock); lock_table_dequeue(lock);
if (lock_get_type(lock) == LOCK_TABLE_EXP) { if (lock_get_type(lock) == LOCK_TABLE_EXP) {
ut_ad(lock_get_mode(lock) == LOCK_S ut_a(lock_get_mode(lock) == LOCK_S
|| lock_get_mode(lock) == LOCK_X); || lock_get_mode(lock) == LOCK_X);
trx->n_tables_locked--; trx->n_lock_table_exp--;
} }
} }
...@@ -3630,11 +3630,12 @@ lock_release_off_kernel( ...@@ -3630,11 +3630,12 @@ lock_release_off_kernel(
mem_heap_empty(trx->lock_heap); mem_heap_empty(trx->lock_heap);
ut_a(trx->auto_inc_lock == NULL); ut_a(trx->auto_inc_lock == NULL);
ut_a(trx->n_tables_locked == 0); ut_a(trx->n_lock_table_exp == 0);
} }
/************************************************************************* /*************************************************************************
Releases table locks, and releases possible other transactions waiting Releases table locks explicitly requested with LOCK TABLES (indicated by
lock type LOCK_TABLE_EXP), and releases possible other transactions waiting
because of these locks. */ because of these locks. */
void void
...@@ -3659,7 +3660,7 @@ lock_release_tables_off_kernel( ...@@ -3659,7 +3660,7 @@ lock_release_tables_off_kernel(
count++; count++;
if (lock_get_type(lock) == LOCK_TABLE_EXP) { if (lock_get_type(lock) == LOCK_TABLE_EXP) {
ut_ad(lock_get_mode(lock) == LOCK_S ut_a(lock_get_mode(lock) == LOCK_S
|| lock_get_mode(lock) == LOCK_X); || lock_get_mode(lock) == LOCK_X);
if (trx->insert_undo || trx->update_undo) { if (trx->insert_undo || trx->update_undo) {
...@@ -3675,7 +3676,8 @@ lock_release_tables_off_kernel( ...@@ -3675,7 +3676,8 @@ lock_release_tables_off_kernel(
} }
lock_table_dequeue(lock); lock_table_dequeue(lock);
trx->n_tables_locked--; trx->n_lock_table_exp--;
lock = UT_LIST_GET_LAST(trx->trx_locks); lock = UT_LIST_GET_LAST(trx->trx_locks);
continue; continue;
} }
...@@ -3696,7 +3698,7 @@ lock_release_tables_off_kernel( ...@@ -3696,7 +3698,7 @@ lock_release_tables_off_kernel(
mem_heap_empty(trx->lock_heap); mem_heap_empty(trx->lock_heap);
ut_a(trx->n_tables_locked == 0); ut_a(trx->n_lock_table_exp == 0);
} }
/************************************************************************* /*************************************************************************
......
...@@ -723,14 +723,15 @@ row_lock_table_autoinc_for_mysql( ...@@ -723,14 +723,15 @@ row_lock_table_autoinc_for_mysql(
} }
/************************************************************************* /*************************************************************************
Unlocks a table lock possibly reserved by trx. */ Unlocks all table locks explicitly requested by trx (with LOCK TABLES,
lock type LOCK_TABLE_EXP). */
void void
row_unlock_table_for_mysql( row_unlock_tables_for_mysql(
/*=======================*/ /*========================*/
trx_t* trx) /* in: transaction */ trx_t* trx) /* in: transaction */
{ {
if (!trx->n_tables_locked) { if (!trx->n_lock_table_exp) {
return; return;
} }
......
...@@ -151,7 +151,7 @@ trx_create( ...@@ -151,7 +151,7 @@ trx_create(
trx->n_tickets_to_enter_innodb = 0; trx->n_tickets_to_enter_innodb = 0;
trx->auto_inc_lock = NULL; trx->auto_inc_lock = NULL;
trx->n_tables_locked = 0; trx->n_lock_table_exp = 0;
trx->read_view_heap = mem_heap_create(256); trx->read_view_heap = mem_heap_create(256);
trx->read_view = NULL; trx->read_view = NULL;
...@@ -279,7 +279,7 @@ trx_free( ...@@ -279,7 +279,7 @@ trx_free(
ut_a(!trx->has_search_latch); ut_a(!trx->has_search_latch);
ut_a(!trx->auto_inc_lock); ut_a(!trx->auto_inc_lock);
ut_a(!trx->n_tables_locked); ut_a(!trx->n_lock_table_exp);
ut_a(trx->dict_operation_lock_mode == 0); ut_a(trx->dict_operation_lock_mode == 0);
......
...@@ -4656,8 +4656,8 @@ ha_innobase::external_lock( ...@@ -4656,8 +4656,8 @@ ha_innobase::external_lock(
trx->n_mysql_tables_in_use--; trx->n_mysql_tables_in_use--;
prebuilt->mysql_has_locked = FALSE; prebuilt->mysql_has_locked = FALSE;
auto_inc_counter_for_this_stat = 0; auto_inc_counter_for_this_stat = 0;
if (trx->n_tables_locked) { if (trx->n_lock_table_exp) {
row_unlock_table_for_mysql(trx); row_unlock_tables_for_mysql(trx);
} }
/* If the MySQL lock count drops to zero we know that the current SQL /* If the MySQL lock count drops to zero we know that the current SQL
......
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