summaryrefslogtreecommitdiff
path: root/sql/lock.cc
diff options
context:
space:
mode:
authorunknown <kostja@bodhi.(none)>2007-07-27 16:37:29 +0400
committerunknown <kostja@bodhi.(none)>2007-07-27 16:37:29 +0400
commit0c371eddee315fac4b7368b97e6853f60f7255eb (patch)
tree222b968f3296750c8756393cb2779dcfb1da2784 /sql/lock.cc
parenta086d6ec12c43aef951d7ae49a8af73d7478751a (diff)
downloadmariadb-git-0c371eddee315fac4b7368b97e6853f60f7255eb.tar.gz
A fix and a test case for Bug#24918 drop table and lock / inconsistent
between perm and temp tables. Review fixes. The original bug report complains that if we locked a temporary table with LOCK TABLES statement, we would not leave LOCK TABLES mode when this temporary table is dropped. Additionally, the bug was escalated when it was discovered than when a temporary transactional table that was previously locked with LOCK TABLES statement was dropped, futher actions with this table, such as UNLOCK TABLES, would lead to a crash. The problem originates from incomplete support of transactional temporary tables. When we added calls to handler::store_lock()/handler::external_lock() to operations that work with such tables, we only covered the normal server code flow and did not cover LOCK TABLES mode. In LOCK TABLES mode, ::external_lock(LOCK) would sometimes be called without matching ::external_lock(UNLOCK), e.g. when a transactional temporary table was dropped. Additionally, this table would be left in the list of LOCKed TABLES. The patch aims to address this inadequacy. Now, whenever an instance of 'handler' is destroyed, we assert that it was priorly external_lock(UNLOCK)-ed. All the places that violate this assert were fixed. This patch introduces no changes in behavior -- the discrepancy in behavior will be fixed when we start calling ::store_lock()/::external_lock() for all tables, regardless whether they are transactional or not, temporary or not. mysql-test/r/innodb_mysql.result: Update test results (Bug#24918) mysql-test/t/innodb_mysql.test: Add a test case for Bug#24918 sql/handler.h: Make handler::external_lock() a protected method. Backport from 5.1 its public wrapper handler::ha_external_lock(). Assert that the handler is not closed if it is still locked. sql/lock.cc: In mysql_lock_tables only call lock_external() for the list of tables that we called store_lock() for. E.g. get_lock_data() does not add non-transactional temporary tables to the lock list, so lock_external() should not be called for them. Use handler::ha_external_lock() instead of handler::external_lock(). Add comments for mysql_lock_remove(), parameterize one strange side effect that it has. At least in one place where mysql_lock_remove is used, this side effect is not desired (DROP TABLE). The parameter will be dropped in 5.1, along with the side effect. sql/mysql_priv.h: Update declaration of mysql_lock_remove(). sql/opt_range.cc: Deploy handler::ha_external_lock() instead of handler::external_lock() sql/sql_base.cc: When closing a temporary table, remove the table from the list of LOCKed TABLES of this thread, in case it's there. It's there if it is a transactional temporary table. Use a new declaration of mysql_lock_remove(). sql/sql_class.h: Extend the comment for THD::temporary_tables. sql/sql_table.cc: Deploy handler::ha_external_lock() instead of handler::external_lock()
Diffstat (limited to 'sql/lock.cc')
-rw-r--r--sql/lock.cc35
1 files changed, 29 insertions, 6 deletions
diff --git a/sql/lock.cc b/sql/lock.cc
index 93358e56701..f730ac56d35 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -151,7 +151,8 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count,
}
thd->proc_info="System lock";
- if (lock_external(thd, tables, count))
+ if (sql_lock->table_count && lock_external(thd, sql_lock->table,
+ sql_lock->table_count))
{
/* Clear the lock type of all lock data to avoid reusage. */
reset_lock_data(sql_lock);
@@ -246,12 +247,12 @@ static int lock_external(THD *thd, TABLE **tables, uint count)
(*tables)->reginfo.lock_type <= TL_READ_NO_INSERT))
lock_type=F_RDLCK;
- if ((error=(*tables)->file->external_lock(thd,lock_type)))
+ if ((error= (*tables)->file->ha_external_lock(thd,lock_type)))
{
print_lock_error(error, (*tables)->file->table_type());
for (; i-- ; tables--)
{
- (*tables)->file->external_lock(thd, F_UNLCK);
+ (*tables)->file->ha_external_lock(thd, F_UNLCK);
(*tables)->current_lock=F_UNLCK;
}
DBUG_RETURN(error);
@@ -353,10 +354,28 @@ void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock)
}
+/**
+ Try to find the table in the list of locked tables.
+ In case of success, unlock the table and remove it from this list.
-void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table)
+ @note This function has a legacy side effect: the table is
+ unlocked even if it is not found in the locked list.
+ It's not clear if this side effect is intentional or still
+ desirable. It might lead to unmatched calls to
+ unlock_external(). Moreover, a discrepancy can be left
+ unnoticed by the storage engine, because in
+ unlock_external() we call handler::external_lock(F_UNLCK) only
+ if table->current_lock is not F_UNLCK.
+
+ @param always_unlock specify explicitly if the legacy side
+ effect is desired.
+*/
+
+void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table,
+ bool always_unlock)
{
- mysql_unlock_some_tables(thd, &table,1);
+ if (always_unlock == TRUE)
+ mysql_unlock_some_tables(thd, &table, /* table count */ 1);
if (locked)
{
reg1 uint i;
@@ -370,6 +389,10 @@ void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table)
DBUG_ASSERT(table->lock_position == i);
+ /* Unlock if not yet unlocked */
+ if (always_unlock == FALSE)
+ mysql_unlock_some_tables(thd, &table, /* table count */ 1);
+
/* Decrement table_count in advance, making below expressions easier */
old_tables= --locked->table_count;
@@ -623,7 +646,7 @@ static int unlock_external(THD *thd, TABLE **table,uint count)
if ((*table)->current_lock != F_UNLCK)
{
(*table)->current_lock = F_UNLCK;
- if ((error=(*table)->file->external_lock(thd, F_UNLCK)))
+ if ((error= (*table)->file->ha_external_lock(thd, F_UNLCK)))
{
error_code=error;
print_lock_error(error_code, (*table)->file->table_type());