1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
##################################################################
# Author: Giuseppe #
# Date: 2006-12-20 #
# Purpose: To test that event effects are replicated. #
##################################################################
if (`SELECT $PS_PROTOCOL != 0`)
{
--skip Need regular protocol but ps-protocol was specified
}
--source include/master-slave.inc
SET @old_event_scheduler = @@global.event_scheduler;
set global event_scheduler=1;
# first, we need a table to record something from an event
eval 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`)
) DEFAULT CHARSET=utf8;
INSERT INTO t1 (id, c) VALUES (1, 'manually');
# We create the event so that it inserts exactly 1 row in the table
# A recuring event is used so that we can be sure the event will
# fire regardless of timing delays on the server. Otherwise, it is
# possible for the event to timeout before it has inserted a row.
--echo "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');
# Show the event is alive and present on master
--echo "Checking event is active on master"
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'justonce';
# Wait until event has fired. We know this because t1 will contain
# the row from the event.
let $wait_condition=
SELECT COUNT(*) = 1 FROM t1 WHERE c = 'from justonce';
--source include/wait_condition.inc
# check that table t1 contains something
--echo "Checking event data on the master"
let $events_done=`SELECT count(*) FROM t1 id`;
--disable_query_log
eval SELECT $events_done > 0 as ONE;
--enable_query_log
sync_slave_with_master;
--echo "Checking event data on the slave"
--disable_query_log
eval SELECT count(*) - $events_done as ZERO FROM t1 id;
--enable_query_log
--echo "Checking event is inactive on slave"
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'justonce';
# Create an event on the slave and check to see what the originator is.
--echo "Dropping event test.slave_once on the slave"
--disable_warnings
DROP EVENT IF EXISTS test.slave_once;
--enable_warnings
# Create an event on slave and check its state. An event shouldn't be executed
# so set start time in 1 hour.
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');
--echo "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';
--echo "Dropping event test.slave_once on the slave"
--disable_warnings
DROP EVENT IF EXISTS test.slave_once;
--enable_warnings
connection master;
# BUG#20384 - disable events on slave
--echo "Dropping event test.justonce on the master"
--disable_warnings
DROP EVENT IF EXISTS test.justonce;
--enable_warnings
# Create an event on master and check its state on slave. An event shouldn't be executed
# so set start time in 1 hour. Check that changes of event statement replicated to slave
--echo "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');
--echo "Checking event status on the master"
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
sync_slave_with_master;
--echo "Checking event status on the slave"
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
connection master;
--echo "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');
--echo "Checking event status on the master"
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
sync_slave_with_master;
--echo "Checking event status on the slave"
SELECT db, name, status, originator, body FROM mysql.event WHERE db = 'test' AND name = 'er';
connection master;
--echo "Dropping event test.er on the master"
DROP EVENT test.er;
--echo "Checking event status on the master"
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test';
--disable_info
sync_slave_with_master;
--echo "Checking event status on the slave"
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test';
# test the DISABLE ON SLAVE for setting event SLAVESIDE_DISABLED as status
# on CREATE EVENT
# Create an event on slave and check its status. An event shouldn't be executed
# so set start time in 1 hour.
--echo "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');
--echo "Checking event status on the slave"
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_terminate';
--echo "Dropping event test.slave_terminate on the slave"
DROP EVENT test.slave_terminate;
--echo "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');
--echo "Checking event status on the slave"
SELECT db, name, status, originator FROM mysql.event WHERE db = 'test' AND name = 'slave_terminate';
--echo "Dropping event test.slave_terminate on the slave"
DROP EVENT test.slave_terminate;
--echo "Cleanup"
connection master;
DROP TABLE t1;
sync_slave_with_master;
connection master;
#
# Bug #28953 Using events in a replication let the slave crash.
#
CREATE TABLE t28953 (a INT);
DELIMITER |;
CREATE EVENT event1 ON SCHEDULE EVERY 1 YEAR
DO BEGIN
select * from t28953;
END;|
DELIMITER ;|
ALTER EVENT event1 RENAME TO event2;
sync_slave_with_master;
connection master;
DROP EVENT event2;
#
# BUG#44331
# This test verifies 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
#
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');
DELIMITER |;
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');
# Test for bug#50095 Multi-statement including CREATE EVENT causes rotten
# binlog entry
SELECT 'ABC';
SELECT '123'|
DELIMITER ;|
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
where EVENT_NAME='event44331_1';
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
where EVENT_NAME='event44331_2';
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
where EVENT_NAME='event44331_3';
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
where EVENT_NAME='event44331_4';
sync_slave_with_master;
connection slave;
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
where EVENT_NAME='event44331_1';
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
where EVENT_NAME='event44331_2';
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
where EVENT_NAME='event44331_3';
select EVENT_SCHEMA, EVENT_NAME, DEFINER from information_schema.events
where EVENT_NAME='event44331_4';
connection master;
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;
sync_slave_with_master;
--source include/rpl_end.inc
|