Commit graph

25102 commits

Author SHA1 Message Date
Konstantin Osipov
391b5246fe Merge next-mr -> next-4284. 2009-12-15 22:59:07 +03:00
Konstantin Osipov
92b1c2f3ca Merge next-mr -> next-4284. 2009-12-15 22:03:56 +03:00
Jon Olav Hauglid
6331ef3efd Bug #48940 MDL deadlocks against mysql_rm_db
This deadlock would occur between two connections A and B if statements
where executed in the following way:
1) Connection A executes a DML statement against table s1.t1 with
autocommit off. This causes a shared metadata lock on s1.t1 to be 
acquired. (With autocommit on, the metadata lock will be dropped once
the statment completes and the deadlock will not occour.)
2) Connection B tries to DROP DATABASE s1. This will block against the
metadata lock connection A holds on s1.t1. While blocking, connection B
will hold the LOCK_mysql_create_db mutex.
3) Connection A tries to ALTER DATABASE s1. This will block when trying
to get LOCK_mysql_create_db mutex held by connection B.
4) Deadlock between DROP DATABASE and ALTER DATABASE (which has autocommit
off).

If Connection A used an explicitly started transaction rather than having
autocommit off, this deadlock did not happen as ALTER DATABASE is 
disallowed inside transactions.

This patch fixes the problem by changing ALTER DATABASE to cause an
implicit commit before executing. This will cause the metadata 
lock on s1.t1 to be dropped, allowing DROP DATABASE to proceed. 
This will in turn cause the LOCK_mysql_create_db mutex to be unlocked, 
allowing ALTER DATABASE to proceed.

Note that SQL commands other than ALTER DATABASE that also use 
LOCK_mysql_create_db, already cause an implicit commit. 

Incompatible change: ALTER DATABASE (and its synonym ALTER SCHEMA)
now cause an implicit commit. This must be reflected in the 
documentation.

Test case added to schema.test.


sql/sql_parse.cc:
  Added CF_AUTO_COMMIT_TRANS to SQLCOM_ALTER_DB.
  
  Removed thd->active_transaction() checks from SQLCOM_DROP_DB, 
  SQLCOM_ALTER_DB_UPGRADE and SQLCOM_ALTER_DB as these statements
  cause an implicit commit.
2009-12-15 14:18:10 +01:00
Konstantin Osipov
5a4f8e214c Backport of:
------------------------------------------------------------
 2599.161.3 Ingo Struewing      2009-07-21
 Bug#20667 - Truncate table fails for a write locked table

 TRUNCATE TABLE was not allowed under LOCK TABLES.

 The patch removes this restriction. mysql_truncate()
 does now handle that case.


mysql-test/r/merge.result:
  Bug#20667 - Truncate table fails for a write locked table
  Updated test result.
mysql-test/r/truncate.result:
  Bug#20667 - Truncate table fails for a write locked table
  Updated test result.
mysql-test/r/truncate_coverage.result:
  Bug#20667 - Truncate table fails for a write locked table
  New test result.
mysql-test/t/merge.test:
  Bug#20667 - Truncate table fails for a write locked table
  Updated test case due to now working TRUNCATE under LOCK TABLES.
  Added some SELECTs to show that child tables are truncated.
mysql-test/t/truncate.test:
  Bug#20667 - Truncate table fails for a write locked table
  Added test cases for TRUNCATE under LOCK TABLE.
mysql-test/t/truncate_coverage.test:
  Bug#20667 - Truncate table fails for a write locked table
  New test file. Coverage tests for TRUNCATE.
sql/sql_delete.cc:
  Bug#20667 - Truncate table fails for a write locked table
  Added branches for thd->locked_tables_mode.
sql/sql_parse.cc:
  Bug#20667 - Truncate table fails for a write locked table
  Deleted rejection of TRUNCATE in case of LOCK TABLES.
2009-12-11 15:24:23 +03:00
Magne Mahre
cc7239b2fc Bug#46374 crash, INSERT INTO t1 uses function, function modifies t1
An error occuring in the execution of a stored procedure, called
from do_select is masked, since the error condition is not
propagated back to the caller (join->conds->val_int() returns
a result value, and not an error code)
                  
An explicit check was added to see if the thd error code has been
set, and if so, the loop status is set to the error state.

Backport from 6.0-codebase (revid: 2617.68.31)
2009-12-10 16:22:41 +01:00
Jon Olav Hauglid
94154c9592 Backport of revno: 3690
Postfix for Bug#48210 FLUSH TABLES WITH READ LOCK deadlocks
                      against concurrent CREATE PROCEDURE

Rewrote the second test to use DROP PROCEDURE instead of 
CREATE USER as CREATE USER does not work with embedded server.
2009-12-10 15:09:56 +01:00
Jon Olav Hauglid
3d062adf25 Backport of revno: 3685
Bug #48210 FLUSH TABLES WITH READ LOCK deadlocks
           against concurrent CREATE PROCEDURE

This deadlock occured between
a) CREATE PROCEDURE (or other commands listed below)
b) FLUSH TABLES WITH READ LOCK

If the execution of them happened in the following order:
- a) opens a table (e.g. mysql.proc)
- b) locks the global read lock (or GRL)
- a) sleeps inside wait_if_global_read_lock()
- b) increases refresh_version and sleeps waiting 
     for old tables to go away

Note that a) must start waiting on the GRL before FLUSH increases
refresh_version. Otherwise a) won't wait on the GRL and instead
close its tables for reopen, allowing FLUSH to complete and thus
avoid the deadlock.

With this patch the deadlock is avoided by making CREATE PROCEDURE
acquire a protection against global read locks before it starts
executing. This means that FLUSH TABLES WITH READ LOCK will have
to wait until CREATE PROCEDURE completes before acquiring the global
read lock, thereby avoiding the deadlock.

This is implemented by introducing a new SQL command flag called
CF_PROTECT_AGAINST_GRL. Commands marked with this flag will
acquire a GRL protection in the beginning of mysql_execute_command().
This patch adds the flag to CREATE, ALTER and DROP for PROCEDURE
and FUNCTION, as well as CREATE USER, DROP USER, RENAME USER and 
REVOKE ALL. All these commands either call open_grant_tables() or
open_system_table_for_updated() which make them susceptible for
this deadlock.

The patch also adds the CF_PROTECT_AGAINST_GRL flag to a number
of commands that previously acquired GRL protection in their
respective SQLCOM case in mysql_execute_command().

Test case that checks for GRL protection for CREATE PROCEDURE
and CREATE USER added to mdl_sync.test.
2009-12-10 15:09:00 +01:00
Jon Olav Hauglid
6c13f657db Backport of revno: 2617.80.1
Also re-enables the test for Bug #43867

Followup to Bug#46654 False deadlock on concurrent DML/DDL with partitions, 
                      inconsistent behavior

Partition_sync.test uses features only available in debug builds.
Disabling the test for non-debug builds.
2009-12-10 14:41:41 +01:00
Jon Olav Hauglid
fb6b5ee462 Backport of revno: 2617.68.37
Bug #46654 False deadlock on concurrent DML/DDL with partitions, 
           inconsistent behavior

The problem was that if one connection is running a multi-statement 
transaction which involves a single partitioned table, and another 
connection attempts to alter the table, the first connection gets 
ER_LOCK_DEADLOCK and cannot proceed anymore, even when the ALTER TABLE 
statement in another connection has timed out or failed.

The reason for this was that the prepare phase for ALTER TABLE for 
partitioned tables removed all instances of the table from the table 
definition cache before it started waiting on the lock. The transaction 
running in the first connection would notice this and report ER_LOCK_DEADLOCK. 

This patch changes the prep_alter_part_table() ALTER TABLE code so that 
tdc_remove_table() is no longer called. Instead, only the TABLE instance
changed by prep_alter_part_table() is marked as needing reopen.

The patch also removes an unnecessary call to tdc_remove_table() from 
mysql_unpack_partition() as the changed TABLE object is destroyed by the 
caller at a later point.

Test case added in partition_sync.test.
2009-12-10 14:26:00 +01:00
Jon Olav Hauglid
7d71d71535 Backport of revno: 3514
Bug#40181 Made use of tdc_remove_table instead of just 
setting share->version to 0 to make sure all unused table
instances go away as part of CREATE/ALTER TABLE.
2009-12-10 14:15:50 +01:00
Jon Olav Hauglid
58a9857bc5 Backport of revno: 3673
Bug #47313 assert in check_key_in_view during CALL procedure

View definitions are inlined in a stored procedure when the procedure
is fist called. This means that if a temporary table is later added
with the same name as the view, the stored procedure will still
use the view. This happens even if temporary tables normally shadow
base tables/views.

The reason for the assert was that even if the stored procedure
referenced the view, open_table() still tried to open the
temporary table. This "half view/half temporary table" state
caused the assert.

The bug was not present in 5.1 as open_table() is not called
for the view there. This code was changed with the introduction 
of MDL in order to properly lock the view and any objects it 
refers to.

This patch fixes the problem by instructing open_table()
to open base tables/views (using OT_BASE_ONLY) when reopening
tables/views used by stored procedures. This also means that
a prepared statement is no longer invalidated if a temporary
table is created with the same name as a view used in the
prepared statement.

Test case added to sp.test. The test case also demonstrates
the effect of sp cache invalidation between CALLs.


mysql-test/t/ps_ddl.test:
  Extended the VIEW->TEMPORARY TABLE transition test to cover not only
  merged views, but now also materialized views and views containing
  a reference to an information schema table. 
  
  Test also updated to reflect the change to prepared statement
  invalidatation.
2009-12-10 13:37:18 +01:00
Jon Olav Hauglid
69f677b215 Backport of revno: 2617.68.45
Bug #47635 assert in start_waiting_global_read_lock during CREATE VIEW

The problem was that CREATE VIEW would trigger an assert if
a temporary table with the same name already existed.

This bug was fixed by the patch for Bug#47335. CREATE/ALTER VIEW
will now ignore temporary tables. See Bug#47335 for more information.

Test case added to view.test.
2009-12-10 13:15:20 +01:00
Jon Olav Hauglid
0b874e3e09 Backport of revno: 2617.68.43
Bug #47335 assert in get_table_share

The assert would happen if ALTER VIEW was used to alter a view (existing 
or non-existing) and a temporary table with the same name already existed.

The assert is triggered if the current statement does not have a MDL lock on 
the view to be altered. This would happen because open_table() would open 
the temporary table instead and MDL locks are not taken for temporary 
tables (since they are local to one connection).

The patch changes open_type for CREATE/ALTER VIEW to OT_BASE_ONLY. This prevents 
open_table() from trying to open a temporary table with the same name should
one exist. Now the view will be altered if it exists or ER_NO_SUCH_TABLE will
be reported if it does not.

Test case added to view.test
2009-12-10 13:02:37 +01:00
Jon Olav Hauglid
84e35f5e1c Backport of revno: 2617.68.3
Followup to Bug#42546 Backup: RESTORE fails, thinking it finds an existing table

This patch updates lowercase_table2.test with the changed error message
CREATE TABLE produces if it fails because it finds an matching TABLE_SHARE 
in the TDC even if the .FRM/.MYD has been removed from disk.

With the changes introduced in Bug#42546, CREATE TABLE uses open_tables()
which will find the TDC entry and fail in open_table_from_share() with
ER_FILE_NOT_FOUND. Before, CREATE TABLE would not use open_tables() and
fail with ER_TABLE_EXISTS_ERROR upon finding the TDC entry in
mysql_create_table_no_lock().
2009-12-10 12:46:16 +01:00
Jon Olav Hauglid
5e1dfa4c06 Backport of revno: 2617.71.1
Bug#42546 Backup: RESTORE fails, thinking it finds an existing table

The problem occured when a MDL locking conflict happened for a non-existent 
table between a CREATE and a INSERT statement. The code for CREATE 
interpreted this lock conflict to mean that the table existed, 
which meant that the statement failed when it should not have.
The problem could occur for CREATE TABLE, CREATE TABLE LIKE and
ALTER TABLE RENAME.

This patch fixes the problem for CREATE TABLE and CREATE TABLE LIKE.
It is based on code backported from the mysql-6.1-fk tree written
by Dmitry Lenev. CREATE now uses normal open_and_lock_tables() code 
to acquire exclusive locks. This means that for the test case in the bug 
description, CREATE will wait until INSERT completes so that it can 
get the exclusive lock. This resolves the reported bug.

The patch also prohibits CREATE TABLE and CREATE TABLE LIKE under 
LOCK TABLES. Note that this is an incompatible change and must 
be reflected in the documentation. Affected test cases have been
updated.

mdl_sync.test contains tests for CREATE TABLE and CREATE TABLE LIKE.

Fixing the issue for ALTER TABLE RENAME is beyond the scope of this
patch. ALTER TABLE cannot be prohibited from working under LOCK TABLES
as this could seriously impact customers and a proper fix would require
a significant rewrite.
2009-12-10 11:53:20 +01:00
Konstantin Osipov
f129367288 Merge with next-4284. 2009-12-10 11:41:03 +03:00
Konstantin Osipov
e001a9f0d0 Backport of:
------------------------------------------------------------
revno: 2617.68.10
committer: Dmitry Lenev <dlenev@mysql.com>
branch nick: mysql-next-bg46673
timestamp: Tue 2009-09-01 19:57:05 +0400
message:
  Fix for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK and DML".

  Deadlocks occured when one concurrently executed transactions with
  several statements modifying data and FLUSH TABLES WITH READ LOCK
  statement or SET READ_ONLY=1 statement.

  These deadlocks were introduced by the patch for WL 4284: "Transactional
  DDL locking"/Bug 989: "If DROP TABLE while there's an active transaction,
  wrong binlog order" which has changed FLUSH TABLES WITH READ LOCK/SET
  READ_ONLY=1 to wait for pending transactions.
  What happened was that FLUSH TABLES WITH READ LOCK blocked all further
  statements changing tables by setting global_read_lock global variable
  and has started waiting for all pending transactions to complete.
  Then one of those transactions tried to executed DML, detected that
  global_read_lock non-zero and tried to wait until global read lock will
  be released (i.e. global_read_lock becomes 0), indeed, this led to a
  deadlock.

  Proper solution for this problem should probably involve full integration
  of global read lock with metadata locking subsystem (which will allow to
  implement waiting for pending transactions without blocking DML in them).
  But since it requires significant changes another, short-term solution
  for the problem is implemented in this patch.

  Basically, this patch restores behavior of FLUSH TABLES WITH READ LOCK/
  SET READ_ONLY=1 before the patch for WL 4284/bug 989. By ensuring that
  extra references to TABLE_SHARE are not stored for active metadata locks
  it changes these statements not to wait for pending transactions.
  As result deadlock is eliminated.
  Note that this does not change the fact that active FLUSH TABLES WITH
  READ LOCK lock or SET READ_ONLY=1 prevent modifications to tables as
  they also block transaction commits.


mysql-test/r/flush_block_commit.result:
  Adjusted test case after change in FLUSH TABLES WITH READ LOCK behavior
  - it is no longer blocked by a pending transaction.
mysql-test/r/mdl_sync.result:
  Added test for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK
  and DML".
mysql-test/r/read_only_innodb.result:
  Adjusted test case after change in SET READ_ONLY behavior - it is no
  longer blocked by a pending transaction.
mysql-test/t/flush_block_commit.test:
  Adjusted test case after change in FLUSH TABLES WITH READ LOCK behavior
  - it is no longer blocked by a pending transaction.
mysql-test/t/mdl_sync.test:
  Added test for bug #46673 "Deadlock between FLUSH TABLES WITH READ LOCK
  and DML".
mysql-test/t/read_only_innodb.test:
  Adjusted test case after change in SET READ_ONLY behavior - it is no
  longer blocked by a pending transaction.
sql/sql_base.cc:
  Disable caching of pointers to TABLE_SHARE objects in MDL subsystem.
  This means that transactions holding metadata lock on the table will
  no longer have extra reference to the TABLE_SHARE (due to this lock)
  and will no longer block concurrent FLUSH TABLES/FLUSH TABLES WITH
  READ LOCK. Note that this does not change the fact that FLUSH TABLES
  WITH READ LOCK prevents concurrent transactions from modifying data
  as it also blocks all commits.
2009-12-09 18:56:34 +03:00
Konstantin Osipov
2f26574026 Backport of:
------------------------------------------------------------
revno: 2617.68.7
committer: Dmitry Lenev <dlenev@mysql.com>
branch nick: mysql-next-bg46044
timestamp: Thu 2009-08-27 10:22:17 +0400
message:
  Fix for bug #46044 "MDL deadlock on LOCK TABLE + CREATE TABLE HIGH_PRIORITY
  FOR UPDATE".

  Deadlock occured when during execution of query to I_S we tried to open
  a table or its .FRM in order to get information about it and had to wait
  because we have encountered exclusive metadata lock on this table held by
  a DDL operation from another connection which in its turn waited for some
  resource currently owned by connection executing this I_S query.
  For example, this might have happened if one under LOCK TABLES executed I_S
  query targeted to particular table (which was not among locked) and also
  concurrently tried to create this table using CREATE TABLE SELECT which
  had to wait for one of tables locked by the first connection.
  Another situation in which deadlock might have occured is when I_S query,
  which was executed as part of transaction, tried to get information about
  table which just has been dropped by concurrent DROP TABLES executed under
  LOCK TABLES and this DROP TABLES for its completion also had to wait
  transaction from the first connection.

  This problem stemmed from the fact that opening of tables/.FRMs for I_S
  filling is happening outside of connection's main MDL_context so code
  which tries to detect deadlocks due to conflicting metadata locks doesn't
  work in this case. Indeed, this led to deadlocks when during I_S filling
  we tried to wait for conflicting metadata lock to go away, while its owner
  was waiting for some resource held by connection executing I_S query.

  This patch solves this problem by avoiding waiting in such situation.
  Instead we skip this table and produce warning that information about
  it was omitted from I_S due to concurrent DDL operation. We still wait
  for conflicting metadata lock to go away when it is known that deadlock
  is not possible (i.e. when connection executing I_S query does not hold
  any metadata or table-level locks).
  Basically, we apply our standard deadlock avoidance technique for metadata
  locks to the process of filling of I_S tables but replace ER_LOCK_DEADLOCK
  error with a warning.
  Note that this change is supposed to be safe for 'mysqldump' since the
  only its mode which is affected by this change is --single-transaction mode
  is not safe in the presence of concurrent DDL anyway (and this fact is
  documented). Other modes are unaffected because they either use
  SHOW TABLES/SELECT * FROM I_S.TABLE_NAMES which do not take any metadata
  locks in the process of I_S table filling and thus cannot skip tables or
  execute I_S queries for tables which were previously locked by LOCK TABLES
  (or in the presence of global read lock) which excludes possibility of
  encountering conflicting metadata lock.


mysql-test/r/mdl_sync.result:
  Added test for bug #46044 "MDL deadlock on LOCK TABLE + CREATE TABLE
  HIGH_PRIORITY FOR UPDATE".
mysql-test/t/mdl_sync.test:
  Added test for bug #46044 "MDL deadlock on LOCK TABLE + CREATE TABLE
  HIGH_PRIORITY FOR UPDATE".
sql/mysql_priv.h:
  Added a new flag for open_table() call which allows it to fail
  with an error in cases when conflicting metadata lock is discovered
  instead of waiting until this lock goes away.
sql/share/errmsg-utf8.txt:
  Added error/warning message to be generated in cases when information
  about table is omitted from I_S since there is conflicting metadata lock
  on the table.
sql/share/errmsg.txt:
  Added error/warning message to be generated in cases when information
  about table is omitted from I_S since there is conflicting metadata lock
  on the table.
sql/sql_base.cc:
  Added a new flag for open_table() call which allows it to fail
  with an error in cases when conflicting metadata lock is discovered
  instead of waiting until this lock goes away.
sql/sql_show.cc:
  When we are opening a table (or just .FRM) in order to fill I_S with
  information about this table and encounter conflicting metadata lock
  waiting for this lock to go away can lead to a deadlock in some
  situations (under LOCK TABLES, within transaction, etc.). To avoid
  these deadlocks we detect such situations and don't do waiting.
  Instead, we skip table for which we have conflicting metadata lock,
  thus omitting information about it from I_S table, and produce an
  appropriate warning.
2009-12-09 18:48:42 +03:00
Jon Olav Hauglid
0bd5741022 Backport of revno: 2617.68.18
Bug #42147 Concurrent DML and LOCK TABLE ... READ for InnoDB 
           table cause warnings in errlog

Concurrent execution of LOCK TABLES ... READ statement and DML statements 
affecting the same InnoDB table on debug builds of MySQL server might lead 
to "Found lock of type 6 that is write and read locked" warnings appearing 
in error log.

The problem is that the table-level locking code allows a thread to acquire
TL_READ_NO_INSERT lock on a table even if there is another thread which holds 
TL_WRITE_ALLOW_WRITE lock on the same table. At the same time, the locking
code assumes that that such locks are incompatible (for example, see check_locks()).

This doesn't lead to any problems other than warnings in error log for
debug builds of server since for InnoDB tables TL_READ_NO_INSERT type of
lock is only used for LOCK TABLES and for this statement InnoDB also
performs its own table-level locking.

Unfortunately, the table lock compatibility matrix cannot be updated to disallow
TL_READ_NO_INSERT when another thread holds TL_WRITE_ALLOW_WRITE without 
causing starvation of LOCK TABLE READ in InnoDB under high write load. 
This patch therefore contains no code changes.

The issue will be fixed later when LOCK TABLE READ has been updated
to not use table locks. This bug will therefore be marked as 
"To be fixed later".

Code comment in thr_lock.c expanded to clarify the issue and a 
test case based on the bug description added to innodb_mysql_lock.test.
Note that a global suppression rule has been added to both MTR v1 and v2
for the "Found lock of type 6 that is write and read locked" warning.
These suppression rules must be removed once this bug is properly fixed.
2009-12-09 16:13:00 +01:00
unknown
832ad46641 Backport of revno: 2617.68.36
---------------------------------------------

This is a patch for bug#47098 assert in MDL_context::destroy on
HANDLER <damaged merge table> OPEN.
      
The assert occurs in MDL_context::destroy when the connection is terminated,
because all mdl_tickets have not been released.
MERGE tables do not support being opened using the HANDLER ... OPEN command,
and trying to do so will result in an error. In the event of an error, all
tables that are opened, should be closed again. The fix for bug#45781 made
sure that this also works for MERGE tables, which causes multiple tables to
be opened.
This fix extends the fix for bug#45781, by ensuring that also all locks are
released, when MERGE tables are involved.

mysql-test/r/merge.result:
  The result of the test.
mysql-test/t/merge.test:
  Added a test based on the bug report, as well as a test of the more general
  scenario.
sql/sql_handler.cc:
  Added code to release all the locks.
2009-12-09 14:41:56 +01:00
Jon Olav Hauglid
334eb7e0af Backport of revno: 3702
Bug #48248 assert in MDL_ticket::upgrade_shared_lock_to_exclusive

The assert would happen if REPAIR TABLE was used on a table already
locked by LOCK TABLES READ. REPAIR mistakenly tried to upgrade the
read-lock to exclusive, thereby triggering the assert.

The cause of the problem was that REPAIR TABLE ignored errors 
from opening and locking tables. This is by design, as REPAIR
can be used to broken tables that cannot be opened. However,
repair also ignored logical errors such as the inability to
exclusivly lock a table due to conflicting LOCK TABLES.

This patch fixes the problem by not ignoring errors from
opening and locking tables if inside LOCK TABLES mode.
In LOCK TABLES we already know that the table can be opened,
so that the failure to open must be a logical error.

Test added to repair.test.
2009-12-09 14:03:37 +01:00
Jon Olav Hauglid
dd848dfa91 Backport of revno: 2617.76.3
Bug#47107

Add missing line in previous change set.


mysql-test/r/create.result:
  Bug#47107
  
  Add missing line in previous change set.
2009-12-09 13:27:24 +01:00
Jon Olav Hauglid
05a126eda1 Backport of revno: 2617.76.2
Bug #47107 assert in notify_shared_lock on incorrect CREATE TABLE , HANDLER

Attempts to create a table (using CREATE TABLE, CREATE TABLE LIKE or
CREATE TABLE SELECT statements) which already existed and was opened
by the same connection through HANDLER statement, led to a stalled
connection (for production builds of the server) or to the server being
aborted due to an assertion failure (for debug builds of the server).

This problem was introduced by the new implementation of a metadata
locking subsystem and didn't affect earlier versions of the server.

The cause of the problem was that the HANDLER was not closed by CREATE TABLE
before CREATE tried to open and lock the table. Acquiring an exclusive MDL
lock on the table to be created would therefore fail since HANDLER
already had a shared MDL lock. This triggered an assert as the 
HANDLER and CREATE statements came from the same thread (self-deadlock).

This patch resolves the issue by closing any open HANDLERs on tables
to be created by CREATE TABLE, similar to what is already done for 
DROP and ALTER TABLE.

Test case added to create.test.
2009-12-09 13:15:35 +01:00
Sergey Vojtovich
cda5ad508a Merge mysql-next-mr to mysql-next-mr-svoj. 2009-12-09 15:03:34 +04:00
Konstantin Osipov
d6aaa5fd51 Merge. 2009-12-09 12:46:13 +03:00
Konstantin Osipov
736db89a76 Backport of:
------------------------------------------------------------
revno: 2617.69.37
committer: Dmitry Lenev <dlenev@mysql.com>
branch nick: mysql-next-bg46748
timestamp: Fri 2009-08-21 18:17:02 +0400
message:
  Fix for bug #46748 "Assertion in MDL_context::wait_for_locks()
  on INSERT + CREATE TRIGGER".

  Concurrent execution of statements involving stored functions or triggers
  which were using several tables and DDL statements which affected those
  tables on debug build of server might have led to assertion failures in
  MDL_context::wait_for_locks(). Non-debug build was not affected.

  The problem was that during back-off which happens when open_tables()
  encounters conflicting metadata lock for one of the tables being open
  we didn't reset MDL_request::ticket value for requests which correspond
  to tables from extended prelocking set. Since these requests are part
  of of list of requests to be waited for in Open_table_context this broke
  assumption that ticket value for them is 0 in MDL_context::wait_for_locks()
  and caused assertion failure.

  This fix ensures that close_tables_for_reopen(), which performs this back-off
  resets MDL_request::ticket value not only for tables directly used by the
  statement but also for tables from extended prelocking set, thus satisfying
  assumption described above.



mysql-test/r/mdl_sync.result:
  Added test case for bug #46748 "Assertion in MDL_context::wait_for_locks()
  on INSERT + CREATE TRIGGER".
mysql-test/t/mdl_sync.test:
  Added test case for bug #46748 "Assertion in MDL_context::wait_for_locks()
  on INSERT + CREATE TRIGGER".
sql/sql_base.cc:
  Since metadata lock requests for tables from extended part of prelocking
  set are also part of list of requests to be waited for in Open_table_context
  in close_tables_for_reopen() we have to reset MDL_request::ticket 
  values for them to assumptions in MDL_context::wait_for_locks().
2009-12-09 12:44:05 +03:00
Jon Olav Hauglid
fcae99271a Backport of revno: 2617.68.39
Bug #47249 assert in MDL_global_lock::is_lock_type_compatible

This assert could be triggered if LOCK TABLES were used to lock
both a table and a view that used the same table. The table would have
to be first WRITE locked and then READ locked. So "LOCK TABLES v1
WRITE, t1 READ" would eventually trigger the assert, "LOCK TABLES
v1 READ, t1 WRITE" would not. The reason is that the ordering of locks
in the interal representation made a difference when executing 
FLUSH TABLE on the table.

During FLUSH TABLE, a lock was upgraded to exclusive. If this lock
was of type MDL_SHARED and not MDL_SHARED_UPGRADABLE, an internal
counter in the MDL subsystem would get out of sync. This would happen
if the *last* mention of the table in LOCK TABLES was a READ lock.

The counter in question is the number exclusive locks (active or intention). 
This is used to make sure a global metadata lock is only taken when the 
counter is zero (= no conflicts). The counter is increased when a
MDL_EXCLUSIVE or MDL_SHARED_UPGRADABLE lock is taken, but not when 
upgrade_shared_lock_to_exclusive() is used to upgrade directly
from MDL_SHARED to MDL_EXCLUSIVE. 

This patch fixes the problem by searching for a TABLE instance locked
with MDL_SHARED_UPGRADABLE or MDL_EXCLUSIVE before calling
upgrade_shared_lock_to_exclusive(). The patch also adds an assert checking
that only MDL_SHARED_UPGRADABLE locks are upgraded to exclusive.

Test case added to lock_multi.test.
2009-12-09 10:44:01 +01:00
Konstantin Osipov
59f82702a1 Backport of:
------------------------------------------------------------
revno: 2617.69.32
committer: Dmitry Lenev <dlenev@mysql.com>
branch nick: mysql-next-bg46747
timestamp: Wed 2009-08-19 18:12:27 +0400
message:
  Fix for bug #46747 "Crash in MDL_ticket::upgrade_shared_lock_to_exclusive
  on TRIGGER + TEMP table".

  Server crashed when one tried to drop trigger which had its subject
  table shadowed by a temporary table with the same name.

  This problem occured because in such situation DROP TRIGGER has opened
  temporary table instead of base table on which trigger was defined.
  Attempt to upgrade metadata lock on this temporary table led to crash
  (we don't acquire metadata locks for temporary tables).

  This fix ensures that DROP TRIGGER ignores temporary tables when
  trying to open table on which trigger to be dropped is defined.


mysql-test/r/trigger.result:
  Added test case for bug #46747 "Crash in
  MDL_ticket::upgrade_shared_lock_to_exclusive
  on TRIGGER + TEMP table".
mysql-test/t/trigger.test:
  Added test case for bug #46747 "Crash in
  MDL_ticket::upgrade_shared_lock_to_exclusive
  on TRIGGER + TEMP table".
sql/sql_trigger.cc:
  Prevent DROP TRIGGER from opening temporary table which might
  shadow base table on which trigger to be dropped is defined.
2009-12-09 12:37:54 +03:00
Konstantin Osipov
c03174458a ----------------------------------------------------------
revno: 2617.69.33
committer: Konstantin Osipov <kostja@sun.com>
branch nick: mysql-next-46452
timestamp: Wed 2009-08-19 18:39:31 +0400
message:
  Bug#46452 "Crash in MDL, HANDLER OPEN + TRUNCATE TABLE".
  Flush open HANDLER tables before TRUNCATE, which is a DDL.


mysql-test/r/truncate.result:
  Update results for Bug#46452.
mysql-test/t/truncate.test:
  Add a test case for Bug#46452 "Crash in MDL, HANDLER OPEN + TRUNCATE TABLE".
2009-12-09 12:29:36 +03:00
Jon Olav Hauglid
4235167fcf Backport of revno: 2599.169.2
Bug #42074 concurrent optimize table and 
           alter table = Assertion failed: thd->is_error()

This assertion could occur if OPTIMIZE TABLE was started on a InnoDB table
and the table was altered to different storage engine after OPTIMIZE
had started. This allowed OPTIMIZE to pass the initial checks for 
storage engine support, but fail once it reached "recreate+analyze"
if this operation was not supported by the new storage engine.
The bug had no consequences for non-debug builds of the server.

In detail, the assertion was triggered when ha_analyze() returned 
HA_ADMIN_NOT_IMPLEMENTED. This led to a code path which included an 
assert checking for diagnostics area contents. Since this area had 
not been filled, the assertion was triggered. The diagnostics area 
is in this case only used to provide more detailed information about 
why optimize failed. The triggered code path sends this information 
to the client and clears the diagnostic area.

This patch fixed the problem by adding an error message to the diagnostic 
area if ha_analyze() fails. This error message contains the error code
returned by ha_analyze().

Test case added to innodb_mysql_sync.test.
2009-12-09 09:32:29 +01:00
Sergey Vojtovich
6b8cd32eaa An addition to backport of
WL#3951 - MyISAM: Additional Error Logs for Data Corruption
Fixed partition_repair_myisam.test.

mysql-test/suite/parts/t/partition_repair_myisam.test:
  Suppress some extra warnings produced by MyISAM.
2009-12-09 11:33:28 +04:00
Jon Olav Hauglid
19ff2445b1 Backport of revno: 2617.68.9
Bug #43272 HANDLER SQL command does not work under LOCK TABLES

HANDLER commands are now explicitly disallowed in LOCK TABLES mode.

Before, HANDLER OPEN gave the misleading error message: "Table x was 
not locked with LOCK TABLES". This patch changes HANDLER OPEN/READ/CLOSE 
to give ER_LOCK_OR_ACTIVE_TRANSACTION "Can't execute the given command 
because you have active locked tables or an active transaction" in
LOCK TABLES mode.

Test case added to lock.test.
2009-12-08 15:56:06 +01:00
Konstantin Osipov
97d2a9233b Merge with next-4284. 2009-12-08 16:59:54 +03:00
Konstantin Osipov
463dcbb51c Backport of revid 2617.69.21, 2617.69.22, 2617.29.23:
----------------------------------------------------------
revno: 2617.69.21
committer: Konstantin Osipov <kostja@sun.com>
branch nick: 5.4-4284-1-assert
timestamp: Thu 2009-08-13 20:13:55 +0400
message:
  A fix and a test case for Bug#46610 "MySQL 5.4.4: MyISAM MRG engine crash
  on auto-repair of child".
  Also fixes Bug#42862 "Crash on failed attempt to open a children of a
  merge table".

  MERGE engine needs to extend the global table list
  with TABLE_LIST elements for child tables,
  so that they are opened and locked.
  Previously these table list elements were allocated
  in memory of ha_myisammrg object (MERGE engine handler).
  That would lead to access to freed memory in
  recover_from_failed_open_table_attempt(), which would
  try to recover a MERGE table child (MyISAM table)
  and use for that TABLE_LIST of that child.
  But by the time recover_from_failed_open_table_attempt()
  is invoked, ha_myisammrg object that owns this
  TABLE_LIST may be destroyed, and thus TABLE_LIST
  memory freed.

  The fix is to ensure that TABLE_LIST elements
  that are added to the global table list (lex->query_tables)
  are always allocated in thd->mem_root, which is not
  destroyed until end of execution.

  If previously TABLE_LIST elements were allocated
  at ha_myisammrg::open() (i.e. when the TABLE
  object was created and added to the table cache),
  now they are allocated in ha_myisammrg::add_chidlren_list()
  (i.e. right after "open" of the merge parent in
  open_tables()).
  We still create a list of children names
  at ha_myisammrg::open() to use as a basis
  for creation of TABLE_LISTs, that allows
  to avoid reading the merge handler data
  file on every execution.


mysql-test/r/merge_recover.result:
  Test results for Bug#46610.
mysql-test/t/merge_recover-master.opt:
  Option file for Bug#46610 test (need a new test because
  of that option, which is not tested anywhere else).
mysql-test/t/merge_recover.test:
  Add a test case for Bug#46610.
sql/table.h:
  MERGE child child_def_version is now moved from TABLE_LIST
  to MERGE engine specific data structure.
storage/myisammrg/ha_myisammrg.cc:
  Introduce an auxiliary structure to keep MERGE child name
  and definition version. A list of Mrg_child_def is created
  in ha_myisammrg::open() and reused in ha_myisammrg::add_children_list().
2009-12-08 16:57:25 +03:00
Jon Olav Hauglid
5ce2421bb1 Backport of revno: 2617.65.1
Bug #22876 Four-way deadlock

This bug was fixed as a part of Bug#989 
"If DROP TABLE while there's an active transaction, wrong binlog order"
A statement which would have caused circular wait will now 
be aborted with ER_LOCK_DEADLOCK.

Test case based on bug description added to innodb_mysql_lock.test.
Note that innodb_lock_wait_timeout is set to 5 mins to 
prevent race conditions in the test.
2009-12-08 14:27:33 +01:00
Jon Olav Hauglid
8da6d448b4 Backport of revno: 2617.62.1
Bug #39675 rename tables on innodb tables with pending 
           transactions causes slave data issue

Bug was already fixed as part of patch for Bug#989 
(If DROP TABLE while there's an active transaction, 
wrong binlog order) 

Test case added to rpl_innodb.test.
2009-12-08 14:22:26 +01:00
Jon Olav Hauglid
a164203fea Backport of revno: 2617.56.21
Bug #45066 FLUSH TABLES WITH READ LOCK deadlocks against LOCK TABLE

Test coverage for combinations of LOCK TABLE READ / WRITE and 
FLUSH TABLES / FLUSH TABLES WITH READ LOCK added to lock.test.
LOCK and FLUSH are executed sequentially from one connection.
2009-12-08 14:14:05 +01:00
V Narayanan
acacdb9e07 merging with mysql-next-mr-svoj 2009-12-08 17:22:59 +05:30
Konstantin Osipov
478e09609c Backport of:
----------------------------------------------------------
revno: 2617.69.2
committer: Konstantin Osipov <kostja@sun.com>
branch nick: 5.4-azalea-bugfixing
timestamp: Mon 2009-08-03 19:26:04 +0400
message:
  A fix and a test case for Bug#45035 "Altering table under LOCK TABLES
  results in "Error 1213 Deadlock found...".

  If a user had a table locked with LOCK TABLES
  for READ and for WRITE in the same connection, ALTER TABLE
  could fail.

  Root cause analysis:

  If a connection issues

  LOCK TABLE t1 write, t1 a read, t1 b read;

  the new LOCK TABLES code in 6.0 (part of WL 3726) will create
  the following list of TABLE_LIST objects
  (thd->locked_tables_list->m_locked_tables):

  {"t1" "b" tl_read_no_insert}, {"t1" "a" tl_read_no_insert},
  {"t1" "t1" tl_write }

  Later on, when we try to ALTER table t1, mysql_alter_table()
  closes all TABLE instances and releases its thr_lock locks,
  keeping only an exclusive metadata lock on t1.

  But when ALTER is finished, Locked_table_list::reopen_tables()
  tries to restore the original list of open and locked tables.

  Before this patch, it used to do so one by one:
  Open t1 b, get TL_READ_NO_INSERT lock,
  Open t1 a, get TL_READ_NO_INSERT lock
  Open t1, try to get TL_WRITE lock, deadlock.

  The cause of the deadlock is that thr_lock.c doesn't
  resolve the situation when the read list only consists
  of locks taken by the same thread, followed by this very
  thread trying to take a WRITE lock. Indeed, since
  thr_lock_multi always gets a sorted list of locks,
  WRITE locks always precede READ locks in the list
  to lock.

  Don't try to fix thr_lock.c deficiency, keep this
  code simple.
  Instead, try to take all thr_lock locks at once
  in ::reopen_tables().


mysql-test/r/lock.result:
  Update results: test case for Bug#45035.
mysql-test/t/lock.test:
  Add a test case for Bug#45035.
sql/sql_base.cc:
  Take all thr_lock locks at once in Locked_tables_list::reopen_tables().
sql/sql_class.h:
  Add a helper array to store tables for mysql_lock_tables()
  in reopen_tables().
sql/sql_table.cc:
  Update unlink_all_closed_tables() to the new signature.
2009-12-08 11:38:45 +03:00
Konstantin Osipov
a26d3f9963 Backport of:
------------------------------------------------------------
revno: 2617.43.3
committer: Davi Arnaut <Davi.Arnaut@Sun.COM>
branch nick: 40188-6.0
timestamp: Thu 2009-05-07 13:15:54 +0200
message:
Sort results as the file list of the database directory is not
sorted (MY_DONT_SORT).

(This is a follow-up fix for WL#4284).

mysql-test/r/drop_debug.result:
  Update test case result.
mysql-test/t/drop_debug.test:
  Sort warnings.
2009-12-08 10:53:40 +03:00
Konstantin Osipov
356597c0fa Backport of:
------------------------------------------------------------
revno: 2617.31.7
committer: Davi Arnaut <Davi.Arnaut@Sun.COM>
branch nick: mysql-6.0-runtime
timestamp: Wed 2009-03-25 19:22:00 -0300
message:
WL#4284: Transactional DDL locking

Post-merge fixes for test cases.

mysql-test/include/mix1.inc:
  Ignore deadlock errors due to the table being altered.
mysql-test/r/innodb_mysql.result:
  Update test case result (WL$4284).
mysql-test/suite/parts/r/partition_special_innodb.result:
  The INSERT and SELECT are not necessary to reproduce the
  problem as the assertion happens when the table is being
  altered.
         
  Furthermore, the INSERT and SELECT will yield a deadlock
  error as after the alter the table version is set to zero,
  which means that any metadata locks on the table must be
  relinquished, but this won't happen voluntarily in a
  multi-statement transaction (metadata locks are released
  on commit or rollback). Reported as Bug#43867.
mysql-test/suite/parts/t/partition_special_innodb.test:
  The INSERT and SELECT are not necessary to reproduce the
  problem as the assertion happens when the table is being
  altered.
         
  Furthermore, the INSERT and SELECT will yield a deadlock
  error as after the alter the table version is set to zero,
  which means that any metadata locks on the table must be
  relinquished, but this won't happen voluntarily in a
  multi-statement transaction (metadata locks are released
  on commit or rollback). Reported as Bug#43867.
2009-12-08 10:39:49 +03:00
Sergey Vojtovich
e8d0168475 WL#2511 - Add a new table to the Information Schema for TABLESPACE's
Implemented a new INFORMATION_SCHEMA table, which is intended to
provide information about tablespaces.

mysql-test/r/information_schema.result:
  Updated test result according to WL#2511. With this WL
  I_S has new TABLESPACES schema.
mysql-test/r/information_schema_db.result:
  Updated test result according to WL#2511. With this WL
  I_S has new TABLESPACES schema.
mysql-test/r/mysqlshow.result:
  Updated test result according to WL#2511. With this WL
  I_S has new TABLESPACES schema.
mysql-test/suite/funcs_1/r/is_columns_is.result:
  Updated test result according to WL#2511. With this WL
  I_S has new TABLESPACES schema.
mysql-test/suite/funcs_1/r/is_tables_is.result:
  Updated test result according to WL#2511. With this WL
  I_S has new TABLESPACES schema.
sql/handler.h:
  Added SCH_TABLESPACES to enum_schema_tables.
sql/mysql_priv.h:
  Added human readable definitions for I_S.TABLESPACES field
  identifiers.
sql/sql_show.cc:
  Added I_S.TABLESPACES schema. The code which handles I_S.FILES
  is capable to handle I_S.TABLESPACES as well. Thus we reuse
  this code and let functions/variables have more generic names.
2009-12-07 16:22:51 +04:00
Konstantin Osipov
a14bbee5ab Backport of revno ## 2617.31.1, 2617.31.3, 2617.31.4, 2617.31.5,
2617.31.12, 2617.31.15, 2617.31.15, 2617.31.16, 2617.43.1
- initial changeset that introduced the fix for 
Bug#989 and follow up fixes for all test suite failures
introduced in the initial changeset. 
------------------------------------------------------------
revno: 2617.31.1
committer: Davi Arnaut <Davi.Arnaut@Sun.COM>
branch nick: 4284-6.0
timestamp: Fri 2009-03-06 19:17:00 -0300
message:
Bug#989: If DROP TABLE while there's an active transaction, wrong binlog order
WL#4284: Transactional DDL locking

Currently the MySQL server does not keep metadata locks on
schema objects for the duration of a transaction, thus failing
to guarantee the integrity of the schema objects being used
during the transaction and to protect then from concurrent
DDL operations. This also poses a problem for replication as
a DDL operation might be replicated even thought there are
active transactions using the object being modified.

The solution is to defer the release of metadata locks until
a active transaction is either committed or rolled back. This
prevents other statements from modifying the table for the
entire duration of the transaction. This provides commitment
ordering for guaranteeing serializability across multiple
transactions.

- Incompatible change:

If MySQL's metadata locking system encounters a lock conflict,
the usual schema is to use the try and back-off technique to
avoid deadlocks -- this schema consists in releasing all locks
and trying to acquire them all in one go.

But in a transactional context this algorithm can't be utilized
as its not possible to release locks acquired during the course
of the transaction without breaking the transaction commitments.
To avoid deadlocks in this case, the ER_LOCK_DEADLOCK will be
returned if a lock conflict is encountered during a transaction.

Let's consider an example:

A transaction has two statements that modify table t1, then table
t2, and then commits. The first statement of the transaction will
acquire a shared metadata lock on table t1, and it will be kept
utill COMMIT to ensure serializability.

At the moment when the second statement attempts to acquire a
shared metadata lock on t2, a concurrent ALTER or DROP statement
might have locked t2 exclusively. The prescription of the current
locking protocol is that the acquirer of the shared lock backs off
-- gives up all his current locks and retries. This implies that
the entire multi-statement transaction has to be rolled back.

- Incompatible change:

FLUSH commands such as FLUSH PRIVILEGES and FLUSH TABLES WITH READ
LOCK won't cause locked tables to be implicitly unlocked anymore.


mysql-test/extra/binlog_tests/drop_table.test:
  Add test case for Bug#989.
mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test:
  Fix test case to reflect the fact that transactions now hold
  metadata locks for the duration of a transaction.
mysql-test/include/mix1.inc:
  Fix test case to reflect the fact that transactions now hold
  metadata locks for the duration of a transaction.
mysql-test/include/mix2.inc:
  Fix test case to reflect the fact that transactions now hold
  metadata locks for the duration of a transaction.
mysql-test/r/flush_block_commit.result:
  Update test case result (WL#4284).
mysql-test/r/flush_block_commit_notembedded.result:
  Update test case result (WL#4284).
mysql-test/r/innodb.result:
  Update test case result (WL#4284).
mysql-test/r/innodb_mysql.result:
  Update test case result (WL#4284).
mysql-test/r/lock.result:
  Add test case result for an effect of WL#4284/Bug#989
  (all locks should be released when a connection terminates).
mysql-test/r/mix2_myisam.result:
  Update test case result (effects of WL#4284/Bug#989).
mysql-test/r/not_embedded_server.result:
  Update test case result (effects of WL#4284/Bug#989).
  Add a test case for interaction of WL#4284 and FLUSH PRIVILEGES.
mysql-test/r/partition_innodb_semi_consistent.result:
  Update test case result (effects of WL#4284/Bug#989).
mysql-test/r/partition_sync.result:
  Temporarily disable the test case for Bug#43867,
  which will be fixed by a subsequent backport.
mysql-test/r/ps.result:
  Add a test case for effect of PREPARE on transactional
  locks: we take a savepoint at beginning of PREAPRE
  and release it at the end. Thus PREPARE does not 
  accumulate metadata locks (Bug#989/WL#4284).
mysql-test/r/read_only_innodb.result:
  Update test case result (effects of WL#4284/Bug#989).
mysql-test/suite/binlog/r/binlog_row_drop_tbl.result:
  Add a test case result (WL#4284/Bug#989).
mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
  Update test case result (effects of WL#4284/Bug#989).
mysql-test/suite/binlog/r/binlog_stm_drop_tbl.result:
  Add a test case result (WL#4284/Bug#989).
mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result:
  Update test case result (effects of WL#4284/Bug#989).
mysql-test/suite/binlog/r/binlog_unsafe.result:
  A side effect of Bug#989 -- slightly different table map ids.
mysql-test/suite/binlog/t/binlog_row_drop_tbl.test:
  Add a test case for WL#4284/Bug#989.
mysql-test/suite/binlog/t/binlog_stm_drop_tbl.test:
  Add a test case for WL#4284/Bug#989.
mysql-test/suite/binlog/t/binlog_stm_row.test:
  Update to the new state name. This
  is actually a follow up to another patch for WL#4284, 
  that changes Locked thread state to Table lock.
mysql-test/suite/ndb/r/ndb_index_ordered.result:
  Remove result for disabled part of the test case.
mysql-test/suite/ndb/t/disabled.def:
  Temporarily disable a test case (Bug#45621).
mysql-test/suite/ndb/t/ndb_index_ordered.test:
  Disable a part of a test case (needs update to
  reflect semantics of Bug#989).
mysql-test/suite/rpl/t/disabled.def:
  Disable tests made meaningless by transactional metadata
  locking.
mysql-test/suite/sys_vars/r/autocommit_func.result:
  Add a commit (Bug#989).
mysql-test/suite/sys_vars/t/autocommit_func.test:
  Add a commit (Bug#989).
mysql-test/t/flush_block_commit.test:
  Fix test case to reflect the fact that transactions now hold
  metadata locks for the duration of a transaction.
mysql-test/t/flush_block_commit_notembedded.test:
  Fix test case to reflect the fact that transactions now hold
  metadata locks for the duration of a transaction.
  Add a test case for transaction-scope locks and the global
  read lock (Bug#989/WL#4284).
mysql-test/t/innodb.test:
  Fix test case to reflect the fact that transactions now hold
  metadata locks for the duration of a transaction
  (effects of Bug#989/WL#4284).
mysql-test/t/lock.test:
  Add a test case for Bug#989/WL#4284.
mysql-test/t/not_embedded_server.test:
  Add a test case for Bug#989/WL#4284.
mysql-test/t/partition_innodb_semi_consistent.test:
  Replace TRUNCATE with DELETE, to not issue
  an implicit commit of a transaction, and not depend
  on metadata locks.
mysql-test/t/partition_sync.test:
  Temporarily disable the test case for Bug#43867,
  which needs a fix to be backported from 6.0.
mysql-test/t/ps.test:
  Add a test case for semantics of PREPARE and transaction-scope
  locks: metadata locks on tables used in PREPARE are enclosed into a
  temporary savepoint, taken at the beginning of PREPARE,
  and released at the end. Thus PREPARE does not effect
  what locks a transaction owns.
mysql-test/t/read_only_innodb.test:
  Fix test case to reflect the fact that transactions now hold
  metadata locks for the duration of a transaction 
  (Bug#989/WL#4284).
  
  Wait for the read_only statement to actually flush tables before
  sending other concurrent statements that depend on its state.
mysql-test/t/xa.test:
  Fix test case to reflect the fact that transactions now hold
  metadata locks for the duration of a transaction 
  (Bug#989/WL#4284).
sql/ha_ndbcluster_binlog.cc:
  Backport bits of changes of ha_ndbcluster_binlog.cc
  from 6.0, to fix the failing binlog test suite with
  WL#4284. WL#4284 implementation does not work
  with 5.1 implementation of ndbcluster binlog index.
sql/log_event.cc:
  Release metadata locks after issuing a commit.
sql/mdl.cc:
  Style changes (WL#4284).
sql/mysql_priv.h:
  Rename parameter to match the name used in the definition (WL#4284).
sql/rpl_injector.cc:
  Release metadata locks on commit (WL#4284).
sql/rpl_rli.cc:
  Remove assert made meaningless, metadata locks are released
  at the end of the transaction.
sql/set_var.cc:
  Close tables and release locks if autocommit mode is set.
sql/slave.cc:
  Release metadata locks after a rollback.
sql/sql_acl.cc:
  Don't implicitly unlock locked tables. Issue a implicit commit
  at the end and unlock tables.
sql/sql_base.cc:
  Defer the release of metadata locks when closing tables
  if not required to.
  Issue a deadlock error if the locking protocol requires
  that a transaction re-acquire its locks.
  
  Release metadata locks when closing tables for reopen.
sql/sql_class.cc:
  Release metadata locks if the thread is killed.
sql/sql_parse.cc:
  Release metadata locks after implicitly committing a active
  transaction, or after explicit commits or rollbacks.
sql/sql_plugin.cc:
  
  Allocate MDL request on the stack as the use of the table
  is contained within the function. It will be removed from
  the context once close_thread_tables is called at the end
  of the function.
sql/sql_prepare.cc:
  The problem is that the prepare phase of the CREATE TABLE
  statement takes a exclusive metadata lock lock and this can
  cause a self-deadlock the thread already holds a shared lock
  on the table being that should be created.
  
  The solution is to make the prepare phase take a shared
  metadata lock when preparing a CREATE TABLE statement. The
  execution of the statement will still acquire a exclusive
  lock, but won't cause any problem as it issues a implicit
  commit.
  
  After some discussions with stakeholders it has been decided that
  metadata locks acquired during a PREPARE statement must be released
  once the statement is prepared even if it is prepared within a multi
  statement transaction.
sql/sql_servers.cc:
  Don't implicitly unlock locked tables. Issue a implicit commit
  at the end and unlock tables.
sql/sql_table.cc:
  Close table and release metadata locks after a admin operation.
sql/table.h:
  The problem is that the prepare phase of the CREATE TABLE
  statement takes a exclusive metadata lock lock and this can
  cause a self-deadlock the thread already holds a shared lock
  on the table being that should be created.
  
  The solution is to make the prepare phase take a shared
  metadata lock when preparing a CREATE TABLE statement. The
  execution of the statement will still acquire a exclusive
  lock, but won't cause any problem as it issues a implicit
  commit.
sql/transaction.cc:
  Release metadata locks after the implicitly committed due
  to a new transaction being started. Also, release metadata
  locks acquired after a savepoint if the transaction is rolled
  back to the save point.
  
  The problem is that in some cases transaction-long metadata locks
  could be released before the transaction was committed. This could
  happen when a active transaction was ended by a "START TRANSACTION"
  or "BEGIN" statement, in which case the metadata locks would be
  released before the actual commit of the active transaction.
  
  The solution is to defer the release of metadata locks to after the
  transaction has been implicitly committed. No test case is provided
  as the effort to provide one is too disproportional to the size of
  the fix.
2009-12-05 02:02:48 +03:00
Konstantin Osipov
f477e66ec5 Backport of:
------------------------------------------------------------
revno: 2617.23.18
committer: Davi Arnaut <Davi.Arnaut@Sun.COM>
branch nick: 4284-6.0
timestamp: Mon 2009-03-02 18:18:26 -0300
message:
Bug#989: If DROP TABLE while there's an active transaction, wrong binlog order
WL#4284: Transactional DDL locking

This is a prerequisite patch:

These changes are intended to split lock requests from granted
locks and to allow the memory and lifetime of granted locks to
be managed within the MDL subsystem. Furthermore, tickets can
now be shared and therefore are used to satisfy multiple lock
requests, but only shared locks can be recursive.

The problem is that the MDL subsystem morphs lock requests into
granted locks locks but does not manage the memory and lifetime
of lock requests, and hence, does not manage the memory of
granted locks either. This can be problematic because it puts the
burden of tracking references on the users of the subsystem and
it can't be easily done in transactional contexts where the locks
have to be kept around for the duration of a transaction.

Another issue is that recursive locks (when the context trying to
acquire a lock already holds a lock on the same object) requires
that each time the lock is granted, a unique lock request/granted
lock structure structure must be kept around until the lock is
released. This can lead to memory leaks in transactional contexts
as locks taken during the transaction should only be released at
the end of the transaction. This also leads to unnecessary wake
ups (broadcasts) in the MDL subsystem if the context still holds
a equivalent of the lock being released.

These issues are exacerbated due to the fact that WL#4284 low-level
design says that the implementation should "2) Store metadata locks
in transaction memory root, rather than statement memory root" but
this is not possible because a memory root, as implemented in mysys,
requires all objects allocated from it to be freed all at once.

This patch combines review input and significant code contributions
from Konstantin Osipov (kostja) and Dmitri Lenev (dlenev).


mysql-test/r/mdl_sync.result:
  Add test case result.
mysql-test/t/mdl_sync.test:
  Add test case for shared lock upgrade case.
sql/event_db_repository.cc:
  Rename mdl_alloc_lock to mdl_request_alloc.
sql/ha_ndbcluster_binlog.cc:
  Use new function names to initialize MDL lock requests.
sql/lock.cc:
  Rename MDL functions.
sql/log_event.cc:
  The MDL request now holds the table and database name data (MDL_KEY).
sql/mdl.cc:
  Move the MDL key to the MDL_LOCK structure in order to make the
  object suitable for allocation from a fixed-size allocator. This
  allows the simplification of the lists in the MDL_LOCK object,
  which now are just two, one for granted tickets and other for
  waiting (upgraders) tickets.
  
  Recursive requests for a shared lock on the same object can now
  be granted using the same lock ticket. This schema is only used
  for shared locks because that the only case that matters. This
  is used to avoid waste of resources in case a context (connection)
  already holds a shared lock on a object.
sql/mdl.h:
  Introduce a metadata lock object key which is used  to uniquely
  identify lock objects.
  
  Separate the structure used to represent pending lock requests
  from the structure used to represent granted metadata locks.
  
  Rename functions used to manipulate locks requests in order to
  have a more consistent function naming schema.
sql/sp_head.cc:
  Rename mdl_alloc_lock to mdl_request_alloc.
sql/sql_acl.cc:
  Rename alloc_mdl_locks to alloc_mdl_requests.
sql/sql_base.cc:
  Various changes to accommodate that lock requests are separated
  from lock tickets (granted locks).
sql/sql_class.h:
  Last acquired lock before the savepoint was set.
sql/sql_delete.cc:
  Various changes to accommodate that lock requests are separated
  from lock tickets (granted locks).
sql/sql_handler.cc:
  Various changes to accommodate that lock requests are separated
  from lock tickets (granted locks).
sql/sql_insert.cc:
  Rename alloc_mdl_locks to alloc_mdl_requests.
sql/sql_parse.cc:
  Rename alloc_mdl_locks to alloc_mdl_requests.
sql/sql_plist.h:
  Typedef for iterator type.
sql/sql_plugin.cc:
  Rename alloc_mdl_locks to alloc_mdl_requests.
sql/sql_servers.cc:
  Rename alloc_mdl_locks to alloc_mdl_requests.
sql/sql_show.cc:
  Various changes to accommodate that lock requests are separated
  from lock tickets (granted locks).
sql/sql_table.cc:
  Various changes to accommodate that lock requests are separated
  from lock tickets (granted locks).
sql/sql_trigger.cc:
  Save reference to the lock ticket so it can be downgraded later.
sql/sql_udf.cc:
  Rename alloc_mdl_locks to alloc_mdl_requests.
sql/table.cc:
  Rename mdl_alloc_lock to mdl_request_alloc.
sql/table.h:
  Separate MDL lock requests from lock tickets (granted locks).
storage/myisammrg/ha_myisammrg.cc:
  Rename alloc_mdl_locks to alloc_mdl_requests.
2009-12-04 02:29:40 +03:00
Konstantin Osipov
cd155be564 Backport of:
------------------------------------------------------------
revno: 3035.4.1
committer: Davi Arnaut <Davi.Arnaut@Sun.COM>
branch nick: 39897-6.0
timestamp: Thu 2009-01-15 12:17:57 -0200
message:
Bug#39897: lock_multi fails in pushbuild: timeout waiting for processlist

The problem is that relying on the "Table lock" thread state in
its current position to detect that a thread is waiting on a lock
is race prone. The "Table lock" state change happens before the
thread actually tries to grab a lock on a table.

The solution is to move the "Table lock" state so that its set
only when a thread is actually going to wait for a lock. The state
change happens after the thread fails to grab the lock (because it
is owned by other thread) and proceeds to wait on a condition.

This is considered part of work related to WL#4284 "Transactional
DDL locking"
Warning: this patch contains an incompatible change. 
When waiting on a lock in thr_lock.c, the server used to display "Locked"
processlist state. After this patch, the state is "Table lock".
The new state was actually intended to be display since year 2002,
when Monty added it. But up until removal of thd->locked boolean
member, this state was ignored by SHOW PROCESSLIST code.  

mysql-test/r/lock_multi.result:
  A style fix.
mysql-test/r/sp-threads.result:
  Changed output of SHOW PROCESSLIST (new wait state).
mysql-test/t/lock_multi.test:
  Use a more accurate state description when waiting inside thr_lock.c.
mysql-test/t/lock_sync.test:
  Use a more accurate state description when waiting inside thr_lock.c.
mysql-test/t/multi_update.test:
  Use a more accurate state description when waiting inside thr_lock.c.
mysql-test/t/query_cache_28249.test:
  Use a more accurate state description when waiting inside thr_lock.c.
mysql-test/t/sp_notembedded.test:
  Use a more accurate state description when waiting inside thr_lock.c.
mysql-test/t/status.test:
  Use a more accurate state description when waiting inside thr_lock.c.
mysys/thr_lock.c:
  Update thread state while waiting for a table lock.
sql/lock.cc:
  State change was moved inside thr_lock.c.
2009-12-03 23:08:27 +03:00
Konstantin Osipov
6a5bbd4bdc Backport of:
------------------------------------------------------------
revno: 2630.13.17
committer: Davi Arnaut <Davi.Arnaut@Sun.COM>
branch nick: 4284-6.0
timestamp: Sun 2008-07-27 10:14:46 -0300
message:
Post-merge fixes:

Remove dependency on binlog, require not embedded as test uses
the event scheduler and disable abort on error for syntax only
available on servers built with debugging support.

This is a patch in scope of WL#4284 "Transactional DDL locking"

mysql-test/t/implicit_commit.test:
  Remove dependency on binlog, require not embedded as test uses
  the event scheduler and disable abort on error for syntax only
  available on servers built with debugging support.
2009-12-03 18:52:21 +03:00
Konstantin Osipov
3543d2556d Backport of:
------------------------------------------------------------
revno: 2630.13.16
committer: Davi Arnaut <Davi.Arnaut@Sun.COM>
branch nick: WL#4284
timestamp: Sat 2008-07-26 13:38:20 -0300
message:
WL#4284: Transactional DDL locking

SQL statements' effect on transactions.

Currently the MySQL server and its storage engines are not
capable of rolling back operations that define or modify data
structures (also known as DDL statements) or operations that
alter any of the system tables (the mysql database). Allowing
these group of statements to participate in transactions
is unfeasible at this time (since rollback has no effect
whatsoever on them) and goes against the design of our metadata
locking subsystem.

The solution is to issue implicit commits before and after
those statements execution. This effectively confines each of
those statements to its own special transaction and ensures
that metadata locks taken during this special transaction
are not leaked into posterior statements/transactions.


mysql-test/include/commit.inc:
  Alter table rename was not committing the normal transaction at the
  end of its execution, and as a consequence, the commit was being
  issued in the next DDL command (rename table) that happened to end
  the active transaction. Other changes are to take into account the
  implicit commits issued before and after the DDL command execution.
mysql-test/include/implicit_commit_helper.inc:
  Add auxiliary test that shows if a statement issued a 
  implicit commit.
mysql-test/r/commit_1innodb.result:
  
  Update test case result.
mysql-test/r/implicit_commit.result:
  Test implicit commit behavior of some SQL commands.
mysql-test/t/implicit_commit.test:
  Test implicit commit behavior of some SQL commands.
sql/events.cc:
  Transaction is now ended before the command execution.
sql/mysql_priv.h:
  Add flags array for server commands and remove historical 
  left over.
sql/sql_class.h:
  Add flags to control when to issue implicit commits before and
  after a command execution.
sql/sql_delete.cc:
  A implicit commit is issued at the end of truncate
  statements.
sql/sql_parse.cc:
  Mark commands that need implicit commits before and
  after their executions. The implicit commits of the
  statement and the normal transaction are now issued
  regardless of the user access privileges.
sql/sql_table.cc:
  A implicit commit is now issued before admin commands.
tests/mysql_client_test.c:
  Test that COM_REFRESH issues a implicit commit.
2009-12-03 18:47:20 +03:00
V Narayanan
a5aa3b3c91 Bug#40814 CSV engine does not parse \X characters when they occur in unquoted fields
When a .CSV file for table in the CSV engine contains
\X characters as part of unquoted fields, e.g.
    
2,naraya\nan
    
\n is not interpreted as a new line (it is however interpreted as a
newline in a quoted field).
    
The old algorithm copied the entire value for a unquoted field without
parsing the \X characters. 
    
The new algorithm adds the capability to handle \X characters in the 
unquoted fields of a .CSV file.

mysql-test/r/csv.result:
  Bug#40814 CSV engine does not parse \X characters when they occur in unquoted fields
  
  Contains additional test output corresponding to the new 
  tests added.
mysql-test/t/csv.test:
  Bug#40814 CSV engine does not parse \X characters when they occur in unquoted fields
  
  Contains additional tests for testing the behaviour of the CSV 
  storage engine when the fields are not enclosed in quotes and
  contain \X characters.
storage/csv/ha_tina.cc:
  Bug#40814 CSV engine does not parse \X characters when they occur in unquoted fields
  
  Changes the parsing logic of the rows in a CSV file, to parse
  \X characters that might be present in the unquoted fields.
2009-12-03 17:18:43 +05:30
Konstantin Osipov
c659143c1e Merge next-mr -> next-4284 2009-12-03 14:37:42 +03:00
Konstantin Osipov
94f25504a3 Merge next-mr -> next-mr-runtime 2009-12-03 14:01:04 +03:00