diff options
Diffstat (limited to 'sql/lock.cc')
-rw-r--r-- | sql/lock.cc | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/sql/lock.cc b/sql/lock.cc index f3445e3b38a..aba22ebb73d 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -90,6 +90,7 @@ extern HASH open_cache; static int lock_external(THD *thd, TABLE **table,uint count); static int unlock_external(THD *thd, TABLE **table,uint count); + /* Map the return value of thr_lock to an error from errmsg.txt */ static int thr_lock_errno_to_mysql[]= { 0, ER_LOCK_ABORTED, ER_LOCK_WAIT_TIMEOUT, ER_LOCK_DEADLOCK }; @@ -163,18 +164,12 @@ lock_tables_check(THD *thd, TABLE **tables, uint count, uint flags) write we must own metadata lock of MDL_SHARED_WRITE or stronger type. For table to be locked for read we must own metadata lock of MDL_SHARED_READ or stronger type). - The only exception are HANDLER statements which are allowed to - lock table for read while having only MDL_SHARED lock on it. */ DBUG_ASSERT(t->s->tmp_table || thd->mdl_context.is_lock_owner(MDL_key::TABLE, t->s->db.str, t->s->table_name.str, t->reginfo.lock_type >= TL_WRITE_ALLOW_WRITE ? - MDL_SHARED_WRITE : MDL_SHARED_READ) || - (t->open_by_handler && - thd->mdl_context.is_lock_owner(MDL_key::TABLE, - t->s->db.str, t->s->table_name.str, - MDL_SHARED))); + MDL_SHARED_WRITE : MDL_SHARED_READ)); /* Prevent modifications to base tables if READ_ONLY is activated. @@ -244,6 +239,39 @@ void reset_lock_data(MYSQL_LOCK *sql_lock, bool unlock) /** + Scan array of tables for access types; update transaction tracker + accordingly. + + @param thd The current thread. + @param tables An array of pointers to the tables to lock. + @param count The number of tables to lock. +*/ + +#ifndef EMBEDDED_LIBRARY +static void track_table_access(THD *thd, TABLE **tables, size_t count) +{ + if (thd->variables.session_track_transaction_info > TX_TRACK_NONE) + { + Transaction_state_tracker *tst= (Transaction_state_tracker *) + thd->session_tracker.get_tracker(TRANSACTION_INFO_TRACKER); + + while (count--) + { + TABLE *t= tables[count]; + + if (t) + tst->add_trx_state(thd, t->reginfo.lock_type, + t->file->has_transactions()); + } + } +} +#else +#define track_table_access(A,B,C) +#endif //EMBEDDED_LIBRARY + + + +/** Lock tables. @param thd The current thread. @@ -280,6 +308,9 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, uint flags) my_free(sql_lock); sql_lock= 0; } + + track_table_access(thd, tables, count); + DBUG_RETURN(sql_lock); } @@ -347,7 +378,7 @@ end: static int lock_external(THD *thd, TABLE **tables, uint count) { - reg1 uint i; + uint i; int lock_type,error; DBUG_ENTER("lock_external"); @@ -374,7 +405,6 @@ static int lock_external(THD *thd, TABLE **tables, uint count) } else { - (*tables)->db_stat &= ~ HA_BLOCK_LOCK; (*tables)->current_lock= lock_type; } } @@ -500,7 +530,7 @@ void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table) { if (locked) { - reg1 uint i; + uint i; for (i=0; i < locked->table_count; i++) { if (locked->table[i] == table) @@ -778,7 +808,7 @@ MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, uint flags) we may allocate too much, but better safe than memory overrun. And in the FLUSH case, the memory is released quickly anyway. */ - sql_lock->lock_count= locks - locks_buf; + sql_lock->lock_count= (uint)(locks - locks_buf); DBUG_ASSERT(sql_lock->lock_count <= lock_count); DBUG_PRINT("info", ("sql_lock->table_count %d sql_lock->lock_count %d", sql_lock->table_count, sql_lock->lock_count)); |