mirror of
https://github.com/MariaDB/server.git
synced 2025-01-23 07:14:17 +01:00
f32c08bd0c
If an EVENT is created without the DEFINER clause set explicitly or with it set to CURRENT_USER, the master and slaves become inconsistent. This issue stems from the fact that in both cases, the DEFINER is set to the CURRENT_USER of the current thread. On the master, the CURRENT_USER is the mysqld's user, while on the slave, the CURRENT_USER is empty for the SQL Thread which is responsible for executing the statement. To fix the problem, we do what follows. If the definer is not set explicitly, a DEFINER clause is added when writing the query into binlog; if 'CURRENT_USER' is used as the DEFINER, it is replaced with the value of the current user before writing to binlog. mysql-test/suite/rpl/r/rpl_create_if_not_exists.result: Updated the result file after fixing bug#44331 mysql-test/suite/rpl/r/rpl_drop_if_exists.result: Updated the result file after fixing bug#44331 mysql-test/suite/rpl/r/rpl_events.result: Test result of Bug#44331 mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result: Updated the result file after fixing bug#44331 mysql-test/suite/rpl/t/rpl_events.test: Added test to verify if the definer is consistent between master and slave when the event is created without the DEFINER clause set explicitly or the DEFINER is set to CURRENT_USER sql/events.cc: The "create_query_string" function is added to create a new query string for removing executable comments. sql/sql_yacc.yy: The remember_name token was added for recording the offset of EVENT_SYM.
237 lines
11 KiB
Text
237 lines
11 KiB
Text
stop slave;
|
|
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
|
|
reset master;
|
|
reset slave;
|
|
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
|
|
start slave;
|
|
SET @old_event_scheduler = @@global.event_scheduler;
|
|
set global event_scheduler=1;
|
|
set binlog_format=row;
|
|
DROP EVENT IF EXISTS test.justonce;
|
|
drop table if exists t1,t2;
|
|
CREATE TABLE `t1` (
|
|
`id` INT(10) UNSIGNED NOT NULL,
|
|
`c` VARCHAR(50) NOT NULL,
|
|
`ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
INSERT INTO t1 (id, c) VALUES (1, 'manually');
|
|
"Creating event test.justonce on the master"
|
|
CREATE EVENT test.justonce ON SCHEDULE EVERY 2 SECOND DO
|
|
INSERT IGNORE INTO t1 (id, c) VALUES (2, 'from justonce');
|
|
"Checking event is active on master"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'justonce';
|
|
db name status originator
|
|
test justonce ENABLED 1
|
|
"Checking event data on the master"
|
|
ONE
|
|
1
|
|
"Checking event data on the slave"
|
|
ZERO
|
|
0
|
|
"Checking event is inactive on slave"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'justonce';
|
|
db name status originator
|
|
test justonce SLAVESIDE_DISABLED 1
|
|
"Dropping event test.slave_once on the slave"
|
|
DROP EVENT IF EXISTS test.slave_once;
|
|
CREATE EVENT test.slave_once ON SCHEDULE EVERY 5 MINUTE STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO
|
|
INSERT IGNORE INTO t1(id, c) VALUES (3, 'from slave_once');
|
|
"Checking event status on the slave for originator value = slave's server_id"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_once';
|
|
db name status originator
|
|
test slave_once ENABLED 2
|
|
"Dropping event test.slave_once on the slave"
|
|
DROP EVENT IF EXISTS test.slave_once;
|
|
"Dropping event test.justonce on the master"
|
|
DROP EVENT IF EXISTS test.justonce;
|
|
"Creating event test.er on the master"
|
|
CREATE EVENT test.er ON SCHEDULE EVERY 3 SECOND STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO
|
|
INSERT IGNORE INTO t1(id, c) VALUES (4, 'from er');
|
|
"Checking event status on the master"
|
|
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
|
|
db name status originator body
|
|
test er ENABLED 1 INSERT IGNORE INTO t1(id, c) VALUES (4, 'from er')
|
|
"Checking event status on the slave"
|
|
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
|
|
db name status originator body
|
|
test er SLAVESIDE_DISABLED 1 INSERT IGNORE INTO t1(id, c) VALUES (4, 'from er')
|
|
"Altering event test.er on the master"
|
|
ALTER EVENT test.er ON SCHEDULE EVERY 5 SECOND STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO
|
|
INSERT IGNORE INTO t1(id, c) VALUES (5, 'from alter er');
|
|
"Checking event status on the master"
|
|
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
|
|
db name status originator body
|
|
test er ENABLED 1 INSERT IGNORE INTO t1(id, c) VALUES (5, 'from alter er')
|
|
"Checking event status on the slave"
|
|
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
|
|
db name status originator body
|
|
test er SLAVESIDE_DISABLED 1 INSERT IGNORE INTO t1(id, c) VALUES (5, 'from alter er')
|
|
"Dropping event test.er on the master"
|
|
DROP EVENT test.er;
|
|
"Checking event status on the master"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test';
|
|
db name status originator
|
|
"Checking event status on the slave"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test';
|
|
db name status originator
|
|
"Creating event test.slave_terminate on the slave"
|
|
CREATE EVENT test.slave_terminate ON SCHEDULE EVERY 3 SECOND STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO
|
|
INSERT IGNORE INTO t1(id, c) VALUES (6, 'from slave_terminate');
|
|
"Checking event status on the slave"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_terminate';
|
|
db name status originator
|
|
test slave_terminate ENABLED 2
|
|
"Dropping event test.slave_terminate on the slave"
|
|
DROP EVENT test.slave_terminate;
|
|
"Creating event test.slave_terminate with DISABLE ON SLAVE on the slave"
|
|
CREATE EVENT test.slave_terminate ON SCHEDULE EVERY 3 SECOND DISABLE ON SLAVE DO
|
|
INSERT IGNORE INTO t1(c) VALUES (7, 'from slave_terminate');
|
|
"Checking event status on the slave"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_terminate';
|
|
db name status originator
|
|
test slave_terminate SLAVESIDE_DISABLED 2
|
|
"Dropping event test.slave_terminate on the slave"
|
|
DROP EVENT test.slave_terminate;
|
|
"Cleanup"
|
|
DROP TABLE t1;
|
|
set binlog_format=statement;
|
|
DROP EVENT IF EXISTS test.justonce;
|
|
drop table if exists t1,t2;
|
|
CREATE TABLE `t1` (
|
|
`id` INT(10) UNSIGNED NOT NULL,
|
|
`c` VARCHAR(50) NOT NULL,
|
|
`ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
INSERT INTO t1 (id, c) VALUES (1, 'manually');
|
|
"Creating event test.justonce on the master"
|
|
CREATE EVENT test.justonce ON SCHEDULE EVERY 2 SECOND DO
|
|
INSERT IGNORE INTO t1 (id, c) VALUES (2, 'from justonce');
|
|
"Checking event is active on master"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'justonce';
|
|
db name status originator
|
|
test justonce ENABLED 1
|
|
"Checking event data on the master"
|
|
ONE
|
|
1
|
|
"Checking event data on the slave"
|
|
ZERO
|
|
0
|
|
"Checking event is inactive on slave"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'justonce';
|
|
db name status originator
|
|
test justonce SLAVESIDE_DISABLED 1
|
|
"Dropping event test.slave_once on the slave"
|
|
DROP EVENT IF EXISTS test.slave_once;
|
|
CREATE EVENT test.slave_once ON SCHEDULE EVERY 5 MINUTE STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO
|
|
INSERT IGNORE INTO t1(id, c) VALUES (3, 'from slave_once');
|
|
"Checking event status on the slave for originator value = slave's server_id"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_once';
|
|
db name status originator
|
|
test slave_once ENABLED 2
|
|
"Dropping event test.slave_once on the slave"
|
|
DROP EVENT IF EXISTS test.slave_once;
|
|
"Dropping event test.justonce on the master"
|
|
DROP EVENT IF EXISTS test.justonce;
|
|
"Creating event test.er on the master"
|
|
CREATE EVENT test.er ON SCHEDULE EVERY 3 SECOND STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO
|
|
INSERT IGNORE INTO t1(id, c) VALUES (4, 'from er');
|
|
"Checking event status on the master"
|
|
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
|
|
db name status originator body
|
|
test er ENABLED 1 INSERT IGNORE INTO t1(id, c) VALUES (4, 'from er')
|
|
"Checking event status on the slave"
|
|
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
|
|
db name status originator body
|
|
test er SLAVESIDE_DISABLED 1 INSERT IGNORE INTO t1(id, c) VALUES (4, 'from er')
|
|
"Altering event test.er on the master"
|
|
ALTER EVENT test.er ON SCHEDULE EVERY 5 SECOND STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO
|
|
INSERT IGNORE INTO t1(id, c) VALUES (5, 'from alter er');
|
|
"Checking event status on the master"
|
|
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
|
|
db name status originator body
|
|
test er ENABLED 1 INSERT IGNORE INTO t1(id, c) VALUES (5, 'from alter er')
|
|
"Checking event status on the slave"
|
|
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
|
|
db name status originator body
|
|
test er SLAVESIDE_DISABLED 1 INSERT IGNORE INTO t1(id, c) VALUES (5, 'from alter er')
|
|
"Dropping event test.er on the master"
|
|
DROP EVENT test.er;
|
|
"Checking event status on the master"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test';
|
|
db name status originator
|
|
"Checking event status on the slave"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test';
|
|
db name status originator
|
|
"Creating event test.slave_terminate on the slave"
|
|
CREATE EVENT test.slave_terminate ON SCHEDULE EVERY 3 SECOND STARTS CURRENT_TIMESTAMP + INTERVAL 1 HOUR DO
|
|
INSERT IGNORE INTO t1(id, c) VALUES (6, 'from slave_terminate');
|
|
"Checking event status on the slave"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_terminate';
|
|
db name status originator
|
|
test slave_terminate ENABLED 2
|
|
"Dropping event test.slave_terminate on the slave"
|
|
DROP EVENT test.slave_terminate;
|
|
"Creating event test.slave_terminate with DISABLE ON SLAVE on the slave"
|
|
CREATE EVENT test.slave_terminate ON SCHEDULE EVERY 3 SECOND DISABLE ON SLAVE DO
|
|
INSERT IGNORE INTO t1(c) VALUES (7, 'from slave_terminate');
|
|
"Checking event status on the slave"
|
|
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_terminate';
|
|
db name status originator
|
|
test slave_terminate SLAVESIDE_DISABLED 2
|
|
"Dropping event test.slave_terminate on the slave"
|
|
DROP EVENT test.slave_terminate;
|
|
"Cleanup"
|
|
DROP TABLE t1;
|
|
CREATE TABLE t28953 (a INT);
|
|
CREATE EVENT event1 ON SCHEDULE EVERY 1 YEAR
|
|
DO BEGIN
|
|
select * from t28953;
|
|
END;|
|
|
ALTER EVENT event1 RENAME TO event2;
|
|
DROP EVENT event2;
|
|
CREATE TABLE test.t1(details CHAR(30));
|
|
CREATE EVENT /*!50000 event44331_1 */
|
|
ON SCHEDULE AT CURRENT_TIMESTAMP
|
|
ON COMPLETION PRESERVE DISABLE
|
|
DO INSERT INTO test.t1 VALUES('event event44331_1 fired - no definer');
|
|
CREATE DEFINER=CURRENT_USER /*!50000 EVENT event44331_2 */
|
|
ON SCHEDULE AT CURRENT_TIMESTAMP
|
|
ON COMPLETION PRESERVE DISABLE
|
|
DO INSERT INTO test.t1 VALUES('event event44331_2 fired - DEFINER=CURRENT_USER');
|
|
CREATE DEFINER=CURRENT_USER() EVENT event44331_3
|
|
ON SCHEDULE AT CURRENT_TIMESTAMP
|
|
ON COMPLETION PRESERVE DISABLE
|
|
DO INSERT INTO test.t1 VALUES('event event44331_3 fired - DEFINER=CURRENT_USER() function');
|
|
CREATE /*!50000 DEFINER='user44331' */ EVENT event44331_4
|
|
ON SCHEDULE AT CURRENT_TIMESTAMP
|
|
ON COMPLETION PRESERVE DISABLE
|
|
DO INSERT INTO test.t1 VALUES('event event44331_4 fired - DEFINER=user1');
|
|
Warnings:
|
|
Note 1449 The user specified as a definer ('user44331'@'%') does not exist
|
|
#on master
|
|
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
|
|
where EVENT_NAME='event44331_1' || EVENT_NAME='event44331_2' ||
|
|
EVENT_NAME='event44331_3' || EVENT_NAME='event44331_4';
|
|
EVENT_SCHEMA EVENT_NAME DEFINER
|
|
test event44331_1 root@localhost
|
|
test event44331_2 root@localhost
|
|
test event44331_3 root@localhost
|
|
test event44331_4 user44331@%
|
|
#on slave
|
|
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
|
|
where EVENT_NAME='event44331_1' || EVENT_NAME='event44331_2' ||
|
|
EVENT_NAME='event44331_3' || EVENT_NAME='event44331_4';
|
|
EVENT_SCHEMA EVENT_NAME DEFINER
|
|
test event44331_1 root@localhost
|
|
test event44331_2 root@localhost
|
|
test event44331_3 root@localhost
|
|
test event44331_4 user44331@%
|
|
SET @@global.event_scheduler= @old_event_scheduler;
|
|
DROP TABLE t28953;
|
|
DROP TABLE t1;
|
|
DROP EVENT event44331_1;
|
|
DROP EVENT event44331_2;
|
|
DROP EVENT event44331_3;
|
|
DROP EVENT event44331_4;
|