mirror of
https://github.com/MariaDB/server.git
synced 2025-01-20 14:02:32 +01:00
0b39c189ba
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.
129 lines
2.9 KiB
Text
129 lines
2.9 KiB
Text
drop table if exists t1;
|
|
set binlog_format=mixed;
|
|
set session transaction isolation level repeatable read;
|
|
create table t1(a int not null)
|
|
engine=innodb
|
|
DEFAULT CHARSET=latin1
|
|
PARTITION BY RANGE(a)
|
|
(PARTITION p0 VALUES LESS THAN (20),
|
|
PARTITION p1 VALUES LESS THAN MAXVALUE);
|
|
insert into t1 values (1),(2),(3),(4),(5),(6),(7);
|
|
set autocommit=0;
|
|
select * from t1 where a=3 lock in share mode;
|
|
a
|
|
3
|
|
set binlog_format=mixed;
|
|
set session transaction isolation level repeatable read;
|
|
set autocommit=0;
|
|
update t1 set a=10 where a=5;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
commit;
|
|
set session transaction isolation level read committed;
|
|
update t1 set a=10 where a=5;
|
|
select * from t1 where a=2 for update;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
select * from t1 where a=2 limit 1 for update;
|
|
a
|
|
2
|
|
update t1 set a=11 where a=6;
|
|
update t1 set a=12 where a=2;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
update t1 set a=13 where a=1;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
commit;
|
|
update t1 set a=14 where a=1;
|
|
commit;
|
|
select * from t1;
|
|
a
|
|
10
|
|
11
|
|
14
|
|
2
|
|
3
|
|
4
|
|
7
|
|
drop table t1;
|
|
SET SESSION AUTOCOMMIT = 0;
|
|
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
|
|
set binlog_format=mixed;
|
|
# Switch to connection con1
|
|
CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256))
|
|
ENGINE = InnoDB
|
|
PARTITION BY RANGE (a)
|
|
(PARTITION p0 VALUES LESS THAN (300),
|
|
PARTITION p1 VALUES LESS THAN MAXVALUE);
|
|
INSERT INTO t1 VALUES (1,2);
|
|
# 1. test for locking:
|
|
BEGIN;
|
|
UPDATE t1 SET b = 12 WHERE a = 1;
|
|
affected rows: 1
|
|
info: Rows matched: 1 Changed: 1 Warnings: 0
|
|
SELECT * FROM t1;
|
|
a b
|
|
1 12
|
|
# Switch to connection con2
|
|
UPDATE t1 SET b = 21 WHERE a = 1;
|
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
|
# Switch to connection con1
|
|
SELECT * FROM t1;
|
|
a b
|
|
1 12
|
|
ROLLBACK;
|
|
# 2. test for serialized update:
|
|
CREATE TABLE t2 (a INT);
|
|
TRUNCATE t1;
|
|
INSERT INTO t1 VALUES (1,'init');
|
|
CREATE PROCEDURE p1()
|
|
BEGIN
|
|
UPDATE t1 SET b = CONCAT(b, '+con2') WHERE a = 1;
|
|
INSERT INTO t2 VALUES ();
|
|
END|
|
|
BEGIN;
|
|
UPDATE t1 SET b = CONCAT(b, '+con1') WHERE a = 1;
|
|
affected rows: 1
|
|
info: Rows matched: 1 Changed: 1 Warnings: 0
|
|
SELECT * FROM t1;
|
|
a b
|
|
1 init+con1
|
|
# Switch to connection con2
|
|
CALL p1;;
|
|
# Switch to connection con1
|
|
SELECT * FROM t1;
|
|
a b
|
|
1 init+con1
|
|
COMMIT;
|
|
SELECT * FROM t1;
|
|
a b
|
|
1 init+con1
|
|
# Switch to connection con2
|
|
SELECT * FROM t1;
|
|
a b
|
|
1 init+con1+con2
|
|
# Switch to connection con1
|
|
# 3. test for updated key column:
|
|
TRUNCATE t1;
|
|
DELETE FROM t2;
|
|
INSERT INTO t1 VALUES (1,'init');
|
|
BEGIN;
|
|
UPDATE t1 SET a = 2, b = CONCAT(b, '+con1') WHERE a = 1;
|
|
affected rows: 1
|
|
info: Rows matched: 1 Changed: 1 Warnings: 0
|
|
SELECT * FROM t1;
|
|
a b
|
|
2 init+con1
|
|
# Switch to connection con2
|
|
CALL p1;;
|
|
# Switch to connection con1
|
|
SELECT * FROM t1;
|
|
a b
|
|
2 init+con1
|
|
COMMIT;
|
|
SELECT * FROM t1;
|
|
a b
|
|
2 init+con1
|
|
# Switch to connection con2
|
|
SELECT * FROM t1;
|
|
a b
|
|
2 init+con1
|
|
DROP PROCEDURE p1;
|
|
DROP TABLE t1, t2;
|