mirror of
https://github.com/MariaDB/server.git
synced 2025-09-11 05:52:26 +03:00
MDEV-17772 - 3 way lock : ALTER, MDL, BACKUP STAGE BLOCK_DDL While waiting for a (potentially long) RO transaction or SELECT, DDL and LOCK TABLES ... WRITE hold protection against FTWRL and BACKUP STAGE. This effectively makes FTWRL/BACKUP STAGE indirectly wait for this RO transaction or SELECT to finish. Which is not great, as otherwise we could do something useful meanwhile. With this patch BACKUP lock is attempted to be acquired after TABLE/SCHEMA locks. If this attempt fails, TABLE/SCHEMA locks gets released and we start waiting for BACKUP lock. When wait finishes, BACKUP lock is released (to avoid deadlocks) and we attempt to acquire all locks once again. Other changes: - Take MDL lock before testing if table exists as part of CREATE TABLE ... IF EXISTS. This change was an effect of changes in lock_table_name and removes an inconsistency where one could get different error messages from CREATE TABLE .. IF EXISTS depending on active mdl locks. One effect of this change is that we don't binary log CREATE TABLE IF EXISTS if the table exists. This was done because old code was sometimes behaving inconsistenly (it was logged some time and not other times) and sending the query to the slave could make the slave even more inconsistent as there is not guarantee that the new table will have the same definition as the old table on the master.
144 lines
3.9 KiB
Plaintext
144 lines
3.9 KiB
Plaintext
include/master-slave.inc
|
|
[connection master]
|
|
DROP DATABASE IF EXISTS mysqltest;
|
|
CREATE DATABASE IF NOT EXISTS mysqltest;
|
|
USE mysqltest;
|
|
CREATE TABLE IF NOT EXISTS t(c1 int);
|
|
CREATE TABLE IF NOT EXISTS t1 LIKE t;
|
|
CREATE TABLE IF NOT EXISTS t2 SELECT * FROM t;
|
|
CREATE EVENT IF NOT EXISTS e
|
|
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
|
|
DO SELECT now();
|
|
connection slave;
|
|
connection slave;
|
|
DROP DATABASE mysqltest;
|
|
connection master;
|
|
CREATE DATABASE IF NOT EXISTS mysqltest;
|
|
USE mysqltest;
|
|
CREATE TABLE IF NOT EXISTS t(c1 int);
|
|
CREATE TABLE IF NOT EXISTS t1 LIKE t;
|
|
CREATE TABLE IF NOT EXISTS t2 SELECT * FROM t;
|
|
CREATE EVENT IF NOT EXISTS e
|
|
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
|
|
DO SELECT now();
|
|
connection slave;
|
|
connection slave;
|
|
SHOW TABLES in mysqltest;
|
|
Tables_in_mysqltest
|
|
SHOW EVENTS in mysqltest;
|
|
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
|
|
mysqltest e root@localhost SYSTEM ONE TIME # NULL NULL NULL NULL SLAVESIDE_DISABLED 1 latin1 latin1_swedish_ci latin1_swedish_ci
|
|
connection master;
|
|
DROP DATABASE IF EXISTS mysqltest;
|
|
-------------BUG#47418-------------
|
|
connection master;
|
|
USE test;
|
|
DROP TABLE IF EXISTS t3;
|
|
CREATE TABLE t3(c1 INTEGER);
|
|
INSERT INTO t3 VALUES(33);
|
|
CREATE TEMPORARY TABLE t1(c1 INTEGER);
|
|
CREATE TEMPORARY TABLE t2(c1 INTEGER);
|
|
INSERT INTO t1 VALUES(1);
|
|
INSERT INTO t2 VALUES(1);
|
|
CREATE TABLE IF NOT EXISTS t1(c1 INTEGER) SELECT c1 FROM t3;
|
|
CREATE TABLE t2(c1 INTEGER) SELECT c1 FROM t3;
|
|
SELECT * FROM t1;
|
|
c1
|
|
1
|
|
SELECT * FROM t2;
|
|
c1
|
|
1
|
|
connection slave;
|
|
SELECT * FROM t1;
|
|
c1
|
|
33
|
|
SELECT * FROM t2;
|
|
c1
|
|
33
|
|
connection master;
|
|
DROP TEMPORARY TABLE t1;
|
|
DROP TEMPORARY TABLE t2;
|
|
SELECT * FROM t1;
|
|
c1
|
|
33
|
|
SELECT * FROM t2;
|
|
c1
|
|
33
|
|
DROP TABLE t1;
|
|
DROP TABLE t2;
|
|
DROP TABLE t3;
|
|
# WL#5370
|
|
# The behavior of statement 'CREATE TABLE SELECT IF NOT EXISTS' is changed.
|
|
# After the worklog, it will insert nothing and the statement will not be
|
|
# binlogged if the table already exists.
|
|
# After the worklog, some bugs will disappear automotically.
|
|
include/rpl_reset.inc
|
|
|
|
# Case 1: BUG#47132
|
|
connection master;
|
|
call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.*");
|
|
CREATE TABLE t1 (id int);
|
|
CREATE TABLE t2 (id int);
|
|
INSERT INTO t1 VALUES (1), (1);
|
|
INSERT INTO t2 VALUES (2), (2);
|
|
CREATE VIEW v1 AS SELECT id FROM t2;
|
|
CREATE TABLE IF NOT EXISTS v1(a int, b int) SELECT id, id as di FROM t1;
|
|
Warnings:
|
|
Note 1050 Table 'v1' already exists
|
|
include/show_binlog_events.inc
|
|
SHOW CREATE TABLE v1;
|
|
View Create View character_set_client collation_connection
|
|
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t2`.`id` AS `id` from `t2` latin1 latin1_swedish_ci
|
|
SELECT * FROM t2;
|
|
id
|
|
2
|
|
2
|
|
SELECT * FROM v1;
|
|
id
|
|
2
|
|
2
|
|
DROP VIEW v1;
|
|
CREATE TEMPORARY TABLE tt1 AS SELECT id FROM t2;
|
|
CREATE TEMPORARY TABLE IF NOT EXISTS tt1(a int, b int) SELECT id, id FROM t1;
|
|
Warnings:
|
|
Note 1050 Table 'tt1' already exists
|
|
include/show_binlog_events.inc
|
|
SELECT * FROM t2;
|
|
id
|
|
2
|
|
2
|
|
SELECT * FROM tt1;
|
|
id
|
|
2
|
|
2
|
|
DROP TEMPORARY TABLE tt1;
|
|
|
|
# Case 1: BUG#47132
|
|
# RBR breaks on CREATE TABLE IF EXISTS <existing VIEW> AS SELECT
|
|
CREATE VIEW v1 AS SELECT 1 as a;
|
|
CREATE TABLE IF NOT EXISTS v1 SELECT 2 as a;
|
|
Warnings:
|
|
Note 1050 Table 'v1' already exists
|
|
include/show_binlog_events.inc
|
|
connection slave;
|
|
connection master;
|
|
DROP VIEW v1;
|
|
DROP TABLE t1, t2;
|
|
#
|
|
# Test case which has failed on assertion after refactoring which was
|
|
# made as part of fix for bug #27480 "Extend CREATE TEMPORARY TABLES
|
|
# privilege to allow temp table operations".
|
|
#
|
|
CREATE TEMPORARY TABLE t1 (id int);
|
|
CREATE TABLE IF NOT EXISTS t2 LIKE t1;
|
|
# The below statement should succeed with warning and
|
|
# should not crash due to failing assertion.
|
|
CREATE TABLE IF NOT EXISTS t2 LIKE t1;
|
|
Warnings:
|
|
Note 1050 Table 't2' already exists
|
|
# Clean-up.
|
|
DROP TABLE t1, t2;
|
|
connection slave;
|
|
connection master;
|
|
include/rpl_end.inc
|