Commit e3d0524b authored by andrey@lmy004's avatar andrey@lmy004

WL#3337 (Event scheduler new architecture)

This patch introduces specialized Event data objects
Event_basic as parent.
Event_queue_element used for queue storage
Event_timed used for SHOW EVENTS/ I_S.EVENTS / SHOW CREATE EVENT
Event_job_data using during execution.
Methods were moved out of Event_timed to other classes.

This patch also introduces Events::LOCK_event_metadata.
This patch gives new implementation of Events::dump_internal_status().
Now both the Event_scheduler and Event_queue return information during
their ::dump_internal_status().

Shortened a bit the runtime for executing events test cases.
parent 3b840ade
...@@ -87,7 +87,6 @@ events_test event_starts_test root@localhost RECURRING NULL 20 SECOND # # ENABLE ...@@ -87,7 +87,6 @@ events_test event_starts_test root@localhost RECURRING NULL 20 SECOND # # ENABLE
DROP EVENT event_starts_test; DROP EVENT event_starts_test;
create table test_nested(a int); create table test_nested(a int);
create event e_43 on schedule every 1 second do set @a = 5; create event e_43 on schedule every 1 second do set @a = 5;
set global event_scheduler = 1;
alter event e_43 do alter event e_43 do set @a = 4; alter event e_43 do alter event e_43 do set @a = 4;
ERROR HY000: Recursivity of EVENT DDL statements is forbidden when body is present ERROR HY000: Recursivity of EVENT DDL statements is forbidden when body is present
alter event e_43 do alter event e_43 do
...@@ -207,6 +206,10 @@ ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' ...@@ -207,6 +206,10 @@ ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND'
SHOW EVENTS; SHOW EVENTS;
ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND' ERROR 42000: This version of MySQL doesn't yet support 'MICROSECOND'
drop event root22; drop event root22;
create event root23 on schedule every -100 year do select 1;
ERROR HY000: INTERVAL is either not positive or too big
create event root23 on schedule every 222222222222222222222 year do select 1;
ERROR HY000: INTERVAL is either not positive or too big
drop event root6; drop event root6;
drop event root7; drop event root7;
drop event root8; drop event root8;
...@@ -342,7 +345,7 @@ create event закачка on schedule every 10 hour do select get_lock("test_l ...@@ -342,7 +345,7 @@ create event закачка on schedule every 10 hour do select get_lock("test_l
"Should have only 2 processes: the scheduler and the locked event" "Should have only 2 processes: the scheduler and the locked event"
select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
user host db command state info user host db command state info
event_scheduler localhost NULL Connect Waiting for next activation NULL event_scheduler localhost NULL Daemon Waiting for next activation NULL
root localhost events_test Connect User lock select get_lock("test_lock2", 20) root localhost events_test Connect User lock select get_lock("test_lock2", 20)
"Release the mutex, the event worker should finish." "Release the mutex, the event worker should finish."
"Release the mutex, the event worker should finish." "Release the mutex, the event worker should finish."
...@@ -358,7 +361,7 @@ create event закачка21 on schedule every 10 hour do select get_lock("test ...@@ -358,7 +361,7 @@ create event закачка21 on schedule every 10 hour do select get_lock("test
"Should have only 3 processes: the scheduler, our conn and the locked event" "Should have only 3 processes: the scheduler, our conn and the locked event"
select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
user host db command state info user host db command state info
event_scheduler localhost NULL Connect Waiting for next activation NULL event_scheduler localhost NULL Daemon Waiting for next activation NULL
root localhost events_test Connect User lock select get_lock("test_lock2_1", 20) root localhost events_test Connect User lock select get_lock("test_lock2_1", 20)
set global event_scheduler=2; set global event_scheduler=2;
"Should have only our process now:" "Should have only our process now:"
......
...@@ -24,8 +24,19 @@ create event e_55 on schedule every 10 hour starts 99990101000000 do drop table ...@@ -24,8 +24,19 @@ create event e_55 on schedule every 10 hour starts 99990101000000 do drop table
ERROR HY000: Incorrect STARTS value: '99990101000000' ERROR HY000: Incorrect STARTS value: '99990101000000'
create event e_55 on schedule every 10 minute ends 99990101000000 do drop table t; create event e_55 on schedule every 10 minute ends 99990101000000 do drop table t;
ERROR HY000: ENDS is either invalid or before STARTS ERROR HY000: ENDS is either invalid or before STARTS
create event e_55 on schedule at 10000101000000 do drop table t;
ERROR HY000: Activation (AT) time is in the past
create event e_55 on schedule at 20000101000000 do drop table t;
ERROR HY000: Activation (AT) time is in the past
create event e_55 on schedule at 20200101000000 starts 10000101000000 do drop table t;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'starts 10000101000000 do drop table t' at line 1
create event e_55 on schedule at 20200101000000 ends 10000101000000 do drop table t;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ends 10000101000000 do drop table t' at line 1
create event e_55 on schedule at 20200101000000 starts 10000101000000 ends 10000101000000 do drop table t;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'starts 10000101000000 ends 10000101000000 do drop table t' at line 1
create event e_55 on schedule every 10 hour starts 10000101000000 do drop table t;
ERROR HY000: Incorrect STARTS value: '10000101000000'
set global event_scheduler=2; set global event_scheduler=2;
"Wait a bit to settle down"
delete from mysql.event; delete from mysql.event;
set global event_scheduler= 1; set global event_scheduler= 1;
set @old_sql_mode:=@@sql_mode; set @old_sql_mode:=@@sql_mode;
...@@ -41,7 +52,7 @@ end| ...@@ -41,7 +52,7 @@ end|
"Now if everything is fine the event has compiled and is locked "Now if everything is fine the event has compiled and is locked
select /*1*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*1*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
user host db command state info user host db command state info
event_scheduler localhost NULL Connect Waiting for next activation NULL event_scheduler localhost NULL Daemon Waiting for next activation NULL
root localhost events_test Connect User lock select get_lock('test_bug16407', 60) root localhost events_test Connect User lock select get_lock('test_bug16407', 60)
select release_lock('test_bug16407'); select release_lock('test_bug16407');
release_lock('test_bug16407') release_lock('test_bug16407')
...@@ -57,6 +68,11 @@ select event_schema, event_name, sql_mode from information_schema.events order b ...@@ -57,6 +68,11 @@ select event_schema, event_name, sql_mode from information_schema.events order b
event_schema event_name sql_mode event_schema event_name sql_mode
events_test e_16407 STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER events_test e_16407 STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
drop event e_16407; drop event e_16407;
set sql_mode="ansi";
select get_lock('ee_16407_2', 60);
get_lock('ee_16407_2', 60)
1
set global event_scheduler= 1;
"Another sql_mode test" "Another sql_mode test"
set sql_mode="traditional"; set sql_mode="traditional";
create table events_smode_test(ev_name char(10), a date) engine=myisam; create table events_smode_test(ev_name char(10), a date) engine=myisam;
...@@ -64,6 +80,7 @@ create table events_smode_test(ev_name char(10), a date) engine=myisam; ...@@ -64,6 +80,7 @@ create table events_smode_test(ev_name char(10), a date) engine=myisam;
create event ee_16407_2 on schedule every 60 second do create event ee_16407_2 on schedule every 60 second do
begin begin
select get_lock('ee_16407_2', 60) /*ee_16407_2*/; select get_lock('ee_16407_2', 60) /*ee_16407_2*/;
select release_lock('ee_16407_2');
insert into events_test.events_smode_test values('ee_16407_2','1980-19-02'); insert into events_test.events_smode_test values('ee_16407_2','1980-19-02');
end| end|
insert into events_smode_test values ('test','1980-19-02')| insert into events_smode_test values ('test','1980-19-02')|
...@@ -72,6 +89,7 @@ ERROR 22007: Incorrect date value: '1980-19-02' for column 'a' at row 1 ...@@ -72,6 +89,7 @@ ERROR 22007: Incorrect date value: '1980-19-02' for column 'a' at row 1
create event ee_16407_3 on schedule every 60 second do create event ee_16407_3 on schedule every 60 second do
begin begin
select get_lock('ee_16407_2', 60) /*ee_16407_3*/; select get_lock('ee_16407_2', 60) /*ee_16407_3*/;
select release_lock('ee_16407_2');
insert into events_test.events_smode_test values ('ee_16407_3','1980-02-19'); insert into events_test.events_smode_test values ('ee_16407_3','1980-02-19');
insert into events_test.events_smode_test values ('ee_16407_3','1980-02-29'); insert into events_test.events_smode_test values ('ee_16407_3','1980-02-29');
end| end|
...@@ -80,6 +98,7 @@ set sql_mode=""| ...@@ -80,6 +98,7 @@ set sql_mode=""|
create event ee_16407_4 on schedule every 60 second do create event ee_16407_4 on schedule every 60 second do
begin begin
select get_lock('ee_16407_2', 60) /*ee_16407_4*/; select get_lock('ee_16407_2', 60) /*ee_16407_4*/;
select release_lock('ee_16407_2');
insert into events_test.events_smode_test values ('ee_16407_4','10-11-1956'); insert into events_test.events_smode_test values ('ee_16407_4','10-11-1956');
end| end|
select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name; select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name;
...@@ -87,14 +106,9 @@ event_schema event_name sql_mode ...@@ -87,14 +106,9 @@ event_schema event_name sql_mode
events_test ee_16407_2 STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER events_test ee_16407_2 STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
events_test ee_16407_3 STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER events_test ee_16407_3 STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
events_test ee_16407_4 events_test ee_16407_4
set sql_mode="ansi";
select get_lock('ee_16407_2', 60);
get_lock('ee_16407_2', 60)
1
set global event_scheduler= 1;
select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
user host db command state info user host db command state info
event_scheduler localhost NULL Connect Waiting for next activation NULL event_scheduler localhost NULL Daemon Waiting for next activation NULL
root localhost events_test Connect User lock select get_lock('ee_16407_2', 60) /*ee_16407_2*/ root localhost events_test Connect User lock select get_lock('ee_16407_2', 60) /*ee_16407_2*/
root localhost events_test Connect User lock select get_lock('ee_16407_2', 60) /*ee_16407_3*/ root localhost events_test Connect User lock select get_lock('ee_16407_2', 60) /*ee_16407_3*/
root localhost events_test Connect User lock select get_lock('ee_16407_2', 60) /*ee_16407_4*/ root localhost events_test Connect User lock select get_lock('ee_16407_2', 60) /*ee_16407_4*/
...@@ -103,7 +117,7 @@ release_lock('ee_16407_2') ...@@ -103,7 +117,7 @@ release_lock('ee_16407_2')
1 1
select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
user host db command state info user host db command state info
event_scheduler localhost NULL Connect Waiting for next activation NULL event_scheduler localhost NULL Daemon Waiting for next activation NULL
set global event_scheduler= 2; set global event_scheduler= 2;
select * from events_smode_test order by ev_name, a; select * from events_smode_test order by ev_name, a;
ev_name a ev_name a
...@@ -121,28 +135,30 @@ drop event ee_16407_3; ...@@ -121,28 +135,30 @@ drop event ee_16407_3;
drop event ee_16407_4; drop event ee_16407_4;
"And now one last test regarding sql_mode and call of SP from an event" "And now one last test regarding sql_mode and call of SP from an event"
delete from events_smode_test; delete from events_smode_test;
set sql_mode='ansi';
select get_lock('ee_16407_5', 60);
get_lock('ee_16407_5', 60)
1
set global event_scheduler= 1;
set sql_mode='traditional'; set sql_mode='traditional';
create procedure ee_16407_5_pendant() begin insert into events_test.events_smode_test values('ee_16407_5','2001-02-29'); end| create procedure ee_16407_5_pendant() begin insert into events_test.events_smode_test values('ee_16407_5','2001-02-29'); end|
create procedure ee_16407_6_pendant() begin insert into events_test.events_smode_test values('ee_16407_6','2004-02-29'); end| create procedure ee_16407_6_pendant() begin insert into events_test.events_smode_test values('ee_16407_6','2004-02-29'); end|
create event ee_16407_5 on schedule every 60 second do create event ee_16407_5 on schedule every 60 second do
begin begin
select get_lock('ee_16407_5', 60) /*ee_16407_5*/; select get_lock('ee_16407_5', 60) /*ee_16407_5*/;
select release_lock('ee_16407_5');
call events_test.ee_16407_5_pendant(); call events_test.ee_16407_5_pendant();
end| end|
create event ee_16407_6 on schedule every 60 second do create event ee_16407_6 on schedule every 60 second do
begin begin
select get_lock('ee_16407_5', 60) /*ee_16407_6*/; select get_lock('ee_16407_5', 60) /*ee_16407_6*/;
select release_lock('ee_16407_5');
call events_test.ee_16407_6_pendant(); call events_test.ee_16407_6_pendant();
end| end|
set sql_mode='ansi';
select get_lock('ee_16407_5', 60);
get_lock('ee_16407_5', 60)
1
set global event_scheduler= 1;
"Should have 2 locked processes" "Should have 2 locked processes"
select /*4*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*4*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
user host db command state info user host db command state info
event_scheduler localhost NULL Connect Waiting for next activation NULL event_scheduler localhost NULL Daemon Waiting for next activation NULL
root localhost events_test Connect User lock select get_lock('ee_16407_5', 60) /*ee_16407_5*/ root localhost events_test Connect User lock select get_lock('ee_16407_5', 60) /*ee_16407_5*/
root localhost events_test Connect User lock select get_lock('ee_16407_5', 60) /*ee_16407_6*/ root localhost events_test Connect User lock select get_lock('ee_16407_5', 60) /*ee_16407_6*/
select release_lock('ee_16407_5'); select release_lock('ee_16407_5');
...@@ -151,7 +167,7 @@ release_lock('ee_16407_5') ...@@ -151,7 +167,7 @@ release_lock('ee_16407_5')
"Should have 0 processes locked" "Should have 0 processes locked"
select /*5*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*5*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
user host db command state info user host db command state info
event_scheduler localhost NULL Connect Waiting for next activation NULL event_scheduler localhost NULL Daemon Waiting for next activation NULL
select * from events_smode_test order by ev_name, a; select * from events_smode_test order by ev_name, a;
ev_name a ev_name a
ee_16407_6 2004-02-29 ee_16407_6 2004-02-29
......
...@@ -9,7 +9,7 @@ SELECT user_host, argument FROM mysql.general_log WHERE argument LIKE '%alabala% ...@@ -9,7 +9,7 @@ SELECT user_host, argument FROM mysql.general_log WHERE argument LIKE '%alabala%
END| END|
"Check General Query Log" "Check General Query Log"
SET GLOBAL event_scheduler=2; SET GLOBAL event_scheduler=2;
create event log_general on schedule every 1 minute do SELect 'alabala', sleep(3) from dual; create event log_general on schedule every 1 minute do SELect 'alabala', sleep(1) from dual;
TRUNCATE mysql.general_log; TRUNCATE mysql.general_log;
"1 row, the current statement!" "1 row, the current statement!"
call select_general_log(); call select_general_log();
...@@ -19,7 +19,7 @@ SET GLOBAL event_scheduler=1; ...@@ -19,7 +19,7 @@ SET GLOBAL event_scheduler=1;
"Should see 3 rows - the 'SELect' is in the middle. The other two are selects from general_log" "Should see 3 rows - the 'SELect' is in the middle. The other two are selects from general_log"
call select_general_log(); call select_general_log();
user_host argument user_host argument
USER_HOST SELect 'alabala', sleep(3) from dual USER_HOST SELect 'alabala', sleep(1) from dual
DROP PROCEDURE select_general_log; DROP PROCEDURE select_general_log;
DROP EVENT log_general; DROP EVENT log_general;
SET GLOBAL event_scheduler=2; SET GLOBAL event_scheduler=2;
...@@ -49,13 +49,13 @@ USER_HOST SLEEPVAL events_test SELECT SLEEP(2) ...@@ -49,13 +49,13 @@ USER_HOST SLEEPVAL events_test SELECT SLEEP(2)
SET SESSION long_query_time=300; SET SESSION long_query_time=300;
"Make it quite long" "Make it quite long"
TRUNCATE mysql.slow_log; TRUNCATE mysql.slow_log;
SET SESSION long_query_time=1;
CREATE TABLE slow_event_test (slo_val tinyint, val tinyint); CREATE TABLE slow_event_test (slo_val tinyint, val tinyint);
"This won't go to the slow log" "This won't go to the slow log"
CREATE EVENT long_event ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(3);
SELECT * FROM slow_event_test; SELECT * FROM slow_event_test;
slo_val val slo_val val
SET SESSION long_query_time=1;
SET GLOBAL event_scheduler=1; SET GLOBAL event_scheduler=1;
CREATE EVENT long_event ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(1.5);
"Sleep some more time than the actual event run will take" "Sleep some more time than the actual event run will take"
SHOW VARIABLES LIKE 'event_scheduler'; SHOW VARIABLES LIKE 'event_scheduler';
Variable_name Value Variable_name Value
...@@ -64,7 +64,7 @@ event_scheduler 1 ...@@ -64,7 +64,7 @@ event_scheduler 1
SELECT * FROM slow_event_test; SELECT * FROM slow_event_test;
slo_val val slo_val val
4 0 4 0
"Check slow log. Should not see anything because 3 is under the threshold of 4 for GLOBAL, though over SESSION which is 2" "Check slow log. Should not see anything because 1.5 is under the threshold of 300 for GLOBAL, though over SESSION which is 2"
SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; SELECT user_host, query_time, db, sql_text FROM mysql.slow_log;
user_host query_time db sql_text user_host query_time db sql_text
"This should go to the slow log" "This should go to the slow log"
......
...@@ -39,7 +39,7 @@ DROP EVENT start_n_end; ...@@ -39,7 +39,7 @@ DROP EVENT start_n_end;
DROP EVENT only_one_time; DROP EVENT only_one_time;
ERROR HY000: Unknown event 'only_one_time' ERROR HY000: Unknown event 'only_one_time'
"Should be preserved" "Should be preserved"
SELECT EVENT_NAME, STATUS FROM INFORMATION_SCHEMA.EVENTS; SELECT EVENT_NAME, STATUS FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_NAME;
EVENT_NAME STATUS EVENT_NAME STATUS
E19170 ENABLED E19170 ENABLED
two_time DISABLED two_time DISABLED
......
...@@ -18,7 +18,7 @@ CREATE EVENT e_x2 ON SCHEDULE EVERY 1 SECOND DO DROP TABLE x_table; ...@@ -18,7 +18,7 @@ CREATE EVENT e_x2 ON SCHEDULE EVERY 1 SECOND DO DROP TABLE x_table;
connection default; connection default;
SHOW DATABASES LIKE 'db_x'; SHOW DATABASES LIKE 'db_x';
SET GLOBAL event_scheduler=1; SET GLOBAL event_scheduler=1;
--sleep 1.5 --sleep 0.8
SHOW DATABASES LIKE 'db_x'; SHOW DATABASES LIKE 'db_x';
SHOW TABLES FROM db_x; SHOW TABLES FROM db_x;
SET GLOBAL event_scheduler=2; SET GLOBAL event_scheduler=2;
...@@ -83,7 +83,6 @@ DROP EVENT event_starts_test; ...@@ -83,7 +83,6 @@ DROP EVENT event_starts_test;
# #
create table test_nested(a int); create table test_nested(a int);
create event e_43 on schedule every 1 second do set @a = 5; create event e_43 on schedule every 1 second do set @a = 5;
set global event_scheduler = 1;
--error 1562 --error 1562
alter event e_43 do alter event e_43 do set @a = 4; alter event e_43 do alter event e_43 do set @a = 4;
delimiter |; delimiter |;
...@@ -94,7 +93,7 @@ begin ...@@ -94,7 +93,7 @@ begin
end| end|
delimiter ;| delimiter ;|
set global event_scheduler = 1; set global event_scheduler = 1;
--sleep 1 --sleep 3
select db, name, body, status, interval_field, interval_value from mysql.event; select db, name, body, status, interval_field, interval_value from mysql.event;
drop event e_43; drop event e_43;
drop table test_nested; drop table test_nested;
...@@ -102,7 +101,7 @@ drop table test_nested; ...@@ -102,7 +101,7 @@ drop table test_nested;
--echo "Let's check whether we can use non-qualified names" --echo "Let's check whether we can use non-qualified names"
create table non_qualif(a int); create table non_qualif(a int);
create event non_qualif_ev on schedule every 10 minute do insert into non_qualif values (800219); create event non_qualif_ev on schedule every 10 minute do insert into non_qualif values (800219);
--sleep 1 --sleep 0.5
select * from non_qualif; select * from non_qualif;
drop event non_qualif_ev; drop event non_qualif_ev;
drop table non_qualif; drop table non_qualif;
...@@ -165,6 +164,10 @@ show create event root22; ...@@ -165,6 +164,10 @@ show create event root22;
--error ER_NOT_SUPPORTED_YET --error ER_NOT_SUPPORTED_YET
SHOW EVENTS; SHOW EVENTS;
drop event root22; drop event root22;
--error ER_EVENT_INTERVAL_NOT_POSITIVE_OR_TOO_BIG
create event root23 on schedule every -100 year do select 1;
--error ER_EVENT_INTERVAL_NOT_POSITIVE_OR_TOO_BIG
create event root23 on schedule every 222222222222222222222 year do select 1;
drop event root6; drop event root6;
drop event root7; drop event root7;
drop event root8; drop event root8;
...@@ -294,7 +297,7 @@ select get_lock("test_lock2", 20); ...@@ -294,7 +297,7 @@ select get_lock("test_lock2", 20);
--echo "Create an event which tries to acquire a mutex. The event locks on the mutex" --echo "Create an event which tries to acquire a mutex. The event locks on the mutex"
create event закаÑка on schedule every 10 hour do select get_lock("test_lock2", 20); create event закаÑка on schedule every 10 hour do select get_lock("test_lock2", 20);
--echo "Let some time pass to the event starts" --echo "Let some time pass to the event starts"
--sleep 1 --sleep 0.5
--echo "Should have only 2 processes: the scheduler and the locked event" --echo "Should have only 2 processes: the scheduler and the locked event"
select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;--echo "Release the mutex, the event worker should finish." select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;--echo "Release the mutex, the event worker should finish."
--echo "Release the mutex, the event worker should finish." --echo "Release the mutex, the event worker should finish."
...@@ -312,10 +315,11 @@ drop event закачка; ...@@ -312,10 +315,11 @@ drop event закачка;
set global event_scheduler=1; set global event_scheduler=1;
select get_lock("test_lock2_1", 20); select get_lock("test_lock2_1", 20);
create event закаÑка21 on schedule every 10 hour do select get_lock("test_lock2_1", 20); create event закаÑка21 on schedule every 10 hour do select get_lock("test_lock2_1", 20);
--sleep 1 --sleep 0.5
--echo "Should have only 3 processes: the scheduler, our conn and the locked event" --echo "Should have only 3 processes: the scheduler, our conn and the locked event"
select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
set global event_scheduler=2; set global event_scheduler=2;
--sleep 0.3
--echo "Should have only our process now:" --echo "Should have only our process now:"
select /*4*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*4*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
drop event закаÑка21; drop event закаÑка21;
......
...@@ -45,6 +45,19 @@ create event e_55 on schedule at 99990101000000 do drop table t; ...@@ -45,6 +45,19 @@ create event e_55 on schedule at 99990101000000 do drop table t;
create event e_55 on schedule every 10 hour starts 99990101000000 do drop table t; create event e_55 on schedule every 10 hour starts 99990101000000 do drop table t;
--error ER_EVENT_ENDS_BEFORE_STARTS --error ER_EVENT_ENDS_BEFORE_STARTS
create event e_55 on schedule every 10 minute ends 99990101000000 do drop table t; create event e_55 on schedule every 10 minute ends 99990101000000 do drop table t;
--error ER_EVENT_EXEC_TIME_IN_THE_PAST
create event e_55 on schedule at 10000101000000 do drop table t;
--error ER_EVENT_EXEC_TIME_IN_THE_PAST
create event e_55 on schedule at 20000101000000 do drop table t;
--error ER_PARSE_ERROR
create event e_55 on schedule at 20200101000000 starts 10000101000000 do drop table t;
--error ER_PARSE_ERROR
create event e_55 on schedule at 20200101000000 ends 10000101000000 do drop table t;
--error ER_PARSE_ERROR
create event e_55 on schedule at 20200101000000 starts 10000101000000 ends 10000101000000 do drop table t;
--error ER_WRONG_VALUE
create event e_55 on schedule every 10 hour starts 10000101000000 do drop table t;
# #
# End - 16396: Events: Distant-future dates become past dates # End - 16396: Events: Distant-future dates become past dates
# #
...@@ -53,8 +66,6 @@ create event e_55 on schedule every 10 minute ends 99990101000000 do drop table ...@@ -53,8 +66,6 @@ create event e_55 on schedule every 10 minute ends 99990101000000 do drop table
# Start - 16407: Events: Changes in sql_mode won't be taken into account # Start - 16407: Events: Changes in sql_mode won't be taken into account
# #
set global event_scheduler=2; set global event_scheduler=2;
--echo "Wait a bit to settle down"
--sleep 1
delete from mysql.event; delete from mysql.event;
set global event_scheduler= 1; set global event_scheduler= 1;
set @old_sql_mode:=@@sql_mode; set @old_sql_mode:=@@sql_mode;
...@@ -67,11 +78,13 @@ begin ...@@ -67,11 +78,13 @@ begin
drop table "hashed_num"; drop table "hashed_num";
end| end|
delimiter ;| delimiter ;|
--sleep 1 --sleep 0.5
--echo "Now if everything is fine the event has compiled and is locked --echo "Now if everything is fine the event has compiled and is locked
select /*1*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*1*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
select release_lock('test_bug16407'); select release_lock('test_bug16407');
set global event_scheduler= 2; set global event_scheduler= 2;
select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name; select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name;
--echo "Let's check whether we change the sql_mode on ALTER EVENT" --echo "Let's check whether we change the sql_mode on ALTER EVENT"
set sql_mode='traditional'; set sql_mode='traditional';
...@@ -79,6 +92,10 @@ alter event e_16407 do select 1; ...@@ -79,6 +92,10 @@ alter event e_16407 do select 1;
select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name; select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name;
drop event e_16407; drop event e_16407;
set sql_mode="ansi";
select get_lock('ee_16407_2', 60);
set global event_scheduler= 1;
--echo "Another sql_mode test" --echo "Another sql_mode test"
set sql_mode="traditional"; set sql_mode="traditional";
create table events_smode_test(ev_name char(10), a date) engine=myisam; create table events_smode_test(ev_name char(10), a date) engine=myisam;
...@@ -87,6 +104,7 @@ delimiter |; ...@@ -87,6 +104,7 @@ delimiter |;
create event ee_16407_2 on schedule every 60 second do create event ee_16407_2 on schedule every 60 second do
begin begin
select get_lock('ee_16407_2', 60) /*ee_16407_2*/; select get_lock('ee_16407_2', 60) /*ee_16407_2*/;
select release_lock('ee_16407_2');
insert into events_test.events_smode_test values('ee_16407_2','1980-19-02'); insert into events_test.events_smode_test values('ee_16407_2','1980-19-02');
end| end|
--error ER_TRUNCATED_WRONG_VALUE --error ER_TRUNCATED_WRONG_VALUE
...@@ -95,6 +113,7 @@ insert into events_smode_test values ('test','1980-19-02')| ...@@ -95,6 +113,7 @@ insert into events_smode_test values ('test','1980-19-02')|
create event ee_16407_3 on schedule every 60 second do create event ee_16407_3 on schedule every 60 second do
begin begin
select get_lock('ee_16407_2', 60) /*ee_16407_3*/; select get_lock('ee_16407_2', 60) /*ee_16407_3*/;
select release_lock('ee_16407_2');
insert into events_test.events_smode_test values ('ee_16407_3','1980-02-19'); insert into events_test.events_smode_test values ('ee_16407_3','1980-02-19');
insert into events_test.events_smode_test values ('ee_16407_3','1980-02-29'); insert into events_test.events_smode_test values ('ee_16407_3','1980-02-29');
end| end|
...@@ -103,17 +122,15 @@ set sql_mode=""| ...@@ -103,17 +122,15 @@ set sql_mode=""|
create event ee_16407_4 on schedule every 60 second do create event ee_16407_4 on schedule every 60 second do
begin begin
select get_lock('ee_16407_2', 60) /*ee_16407_4*/; select get_lock('ee_16407_2', 60) /*ee_16407_4*/;
select release_lock('ee_16407_2');
insert into events_test.events_smode_test values ('ee_16407_4','10-11-1956'); insert into events_test.events_smode_test values ('ee_16407_4','10-11-1956');
end| end|
delimiter ;| delimiter ;|
select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name; select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name;
set sql_mode="ansi"; --sleep 0.5
select get_lock('ee_16407_2', 60);
set global event_scheduler= 1;
--sleep 1
select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
select release_lock('ee_16407_2'); select release_lock('ee_16407_2');
--sleep 2 --sleep 0.8
select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
set global event_scheduler= 2; set global event_scheduler= 2;
select * from events_smode_test order by ev_name, a; select * from events_smode_test order by ev_name, a;
...@@ -126,6 +143,11 @@ drop event ee_16407_4; ...@@ -126,6 +143,11 @@ drop event ee_16407_4;
--echo "And now one last test regarding sql_mode and call of SP from an event" --echo "And now one last test regarding sql_mode and call of SP from an event"
delete from events_smode_test; delete from events_smode_test;
set sql_mode='ansi';
select get_lock('ee_16407_5', 60);
set global event_scheduler= 1;
set sql_mode='traditional'; set sql_mode='traditional';
delimiter |; delimiter |;
create procedure ee_16407_5_pendant() begin insert into events_test.events_smode_test values('ee_16407_5','2001-02-29'); end| create procedure ee_16407_5_pendant() begin insert into events_test.events_smode_test values('ee_16407_5','2001-02-29'); end|
...@@ -133,22 +155,21 @@ create procedure ee_16407_6_pendant() begin insert into events_test.events_smode ...@@ -133,22 +155,21 @@ create procedure ee_16407_6_pendant() begin insert into events_test.events_smode
create event ee_16407_5 on schedule every 60 second do create event ee_16407_5 on schedule every 60 second do
begin begin
select get_lock('ee_16407_5', 60) /*ee_16407_5*/; select get_lock('ee_16407_5', 60) /*ee_16407_5*/;
select release_lock('ee_16407_5');
call events_test.ee_16407_5_pendant(); call events_test.ee_16407_5_pendant();
end| end|
create event ee_16407_6 on schedule every 60 second do create event ee_16407_6 on schedule every 60 second do
begin begin
select get_lock('ee_16407_5', 60) /*ee_16407_6*/; select get_lock('ee_16407_5', 60) /*ee_16407_6*/;
select release_lock('ee_16407_5');
call events_test.ee_16407_6_pendant(); call events_test.ee_16407_6_pendant();
end| end|
delimiter ;| delimiter ;|
set sql_mode='ansi'; --sleep 0.5
select get_lock('ee_16407_5', 60);
set global event_scheduler= 1;
--sleep 1
--echo "Should have 2 locked processes" --echo "Should have 2 locked processes"
select /*4*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*4*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
select release_lock('ee_16407_5'); select release_lock('ee_16407_5');
--sleep 2 --sleep 0.8
--echo "Should have 0 processes locked" --echo "Should have 0 processes locked"
select /*5*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info; select /*5*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
select * from events_smode_test order by ev_name, a; select * from events_smode_test order by ev_name, a;
......
...@@ -14,7 +14,7 @@ END| ...@@ -14,7 +14,7 @@ END|
delimiter ;| delimiter ;|
--echo "Check General Query Log" --echo "Check General Query Log"
SET GLOBAL event_scheduler=2; SET GLOBAL event_scheduler=2;
create event log_general on schedule every 1 minute do SELect 'alabala', sleep(3) from dual; create event log_general on schedule every 1 minute do SELect 'alabala', sleep(1) from dual;
TRUNCATE mysql.general_log; TRUNCATE mysql.general_log;
--echo "1 row, the current statement!" --echo "1 row, the current statement!"
--replace_column 1 USER_HOST --replace_column 1 USER_HOST
...@@ -22,13 +22,12 @@ call select_general_log(); ...@@ -22,13 +22,12 @@ call select_general_log();
SET GLOBAL event_scheduler=1; SET GLOBAL event_scheduler=1;
--echo "Wait the scheduler to start" --echo "Wait the scheduler to start"
--echo "Should see 3 rows - the 'SELect' is in the middle. The other two are selects from general_log" --echo "Should see 3 rows - the 'SELect' is in the middle. The other two are selects from general_log"
--sleep 2 --sleep 0.7
--replace_column 1 USER_HOST --replace_column 1 USER_HOST
call select_general_log(); call select_general_log();
DROP PROCEDURE select_general_log; DROP PROCEDURE select_general_log;
DROP EVENT log_general; DROP EVENT log_general;
SET GLOBAL event_scheduler=2; SET GLOBAL event_scheduler=2;
--sleep 1
--echo "Check slow query log" --echo "Check slow query log"
--disable_query_log --disable_query_log
...@@ -69,18 +68,18 @@ SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; ...@@ -69,18 +68,18 @@ SELECT user_host, query_time, db, sql_text FROM mysql.slow_log;
SET SESSION long_query_time=300; SET SESSION long_query_time=300;
--echo "Make it quite long" --echo "Make it quite long"
TRUNCATE mysql.slow_log; TRUNCATE mysql.slow_log;
SET SESSION long_query_time=1;
CREATE TABLE slow_event_test (slo_val tinyint, val tinyint); CREATE TABLE slow_event_test (slo_val tinyint, val tinyint);
--echo "This won't go to the slow log" --echo "This won't go to the slow log"
CREATE EVENT long_event ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(3);
SELECT * FROM slow_event_test; SELECT * FROM slow_event_test;
SET SESSION long_query_time=1;
SET GLOBAL event_scheduler=1; SET GLOBAL event_scheduler=1;
CREATE EVENT long_event ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(1.5);
--echo "Sleep some more time than the actual event run will take" --echo "Sleep some more time than the actual event run will take"
--sleep 5 --sleep 2
SHOW VARIABLES LIKE 'event_scheduler'; SHOW VARIABLES LIKE 'event_scheduler';
--echo "Check our table. Should see 1 row" --echo "Check our table. Should see 1 row"
SELECT * FROM slow_event_test; SELECT * FROM slow_event_test;
--echo "Check slow log. Should not see anything because 3 is under the threshold of 4 for GLOBAL, though over SESSION which is 2" --echo "Check slow log. Should not see anything because 1.5 is under the threshold of 300 for GLOBAL, though over SESSION which is 2"
SELECT user_host, query_time, db, sql_text FROM mysql.slow_log; SELECT user_host, query_time, db, sql_text FROM mysql.slow_log;
--echo "This should go to the slow log" --echo "This should go to the slow log"
DROP EVENT long_event; DROP EVENT long_event;
...@@ -88,7 +87,7 @@ SET SESSION long_query_time=10; ...@@ -88,7 +87,7 @@ SET SESSION long_query_time=10;
SET GLOBAL long_query_time=1; SET GLOBAL long_query_time=1;
CREATE EVENT long_event2 ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(2); CREATE EVENT long_event2 ON SCHEDULE EVERY 1 MINUTE DO INSERT INTO slow_event_test SELECT @@long_query_time, SLEEP(2);
--echo "Sleep some more time than the actual event run will take" --echo "Sleep some more time than the actual event run will take"
--sleep 3 --sleep 2.5
--echo "Check our table. Should see 2 rows" --echo "Check our table. Should see 2 rows"
SELECT * FROM slow_event_test; SELECT * FROM slow_event_test;
--echo "Check slow log. Should see 1 row because 4 is over the threshold of 3 for GLOBAL, though under SESSION which is 10" --echo "Check slow log. Should see 1 row because 4 is over the threshold of 3 for GLOBAL, though under SESSION which is 10"
......
...@@ -34,7 +34,7 @@ DROP EVENT start_n_end; ...@@ -34,7 +34,7 @@ DROP EVENT start_n_end;
--error ER_EVENT_DOES_NOT_EXIST --error ER_EVENT_DOES_NOT_EXIST
DROP EVENT only_one_time; DROP EVENT only_one_time;
--echo "Should be preserved" --echo "Should be preserved"
SELECT EVENT_NAME, STATUS FROM INFORMATION_SCHEMA.EVENTS; SELECT EVENT_NAME, STATUS FROM INFORMATION_SCHEMA.EVENTS ORDER BY EVENT_NAME;
DROP EVENT two_time; DROP EVENT two_time;
DROP TABLE table_1; DROP TABLE table_1;
DROP TABLE table_2; DROP TABLE table_2;
......
...@@ -61,7 +61,7 @@ while ($1) ...@@ -61,7 +61,7 @@ while ($1)
--enable_query_log --enable_query_log
SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2'; SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2';
SET GLOBAL event_scheduler=1; SET GLOBAL event_scheduler=1;
--sleep 12 --sleep 2.5
DROP DATABASE events_conn1_test2; DROP DATABASE events_conn1_test2;
SET GLOBAL event_scheduler=2; SET GLOBAL event_scheduler=2;
...@@ -100,7 +100,7 @@ while ($1) ...@@ -100,7 +100,7 @@ while ($1)
} }
--enable_query_log --enable_query_log
SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2'; SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2';
--sleep 12 --sleep 2.5
connection conn2; connection conn2;
--send --send
DROP DATABASE events_conn2_db; DROP DATABASE events_conn2_db;
......
This diff is collapsed.
...@@ -47,30 +47,46 @@ ...@@ -47,30 +47,46 @@
class sp_head; class sp_head;
class Sql_alloc; class Sql_alloc;
class Event_basic;
class Event_timed;
/* Compares only the schema part of the identifier */ /* Compares only the schema part of the identifier */
bool bool
event_timed_db_equal(Event_timed *et, LEX_STRING *db); event_basic_db_equal( LEX_STRING *db, Event_basic *et);
/* Compares the whole identifier*/ /* Compares the whole identifier*/
bool bool
event_timed_identifier_equal(LEX_STRING db, LEX_STRING name, Event_timed *b); event_basic_identifier_equal(LEX_STRING db, LEX_STRING name, Event_basic *b);
class Event_timed class Event_basic
{ {
Event_timed(const Event_timed &); /* Prevent use of these */ protected:
void operator=(Event_timed &); MEM_ROOT mem_root;
public:
LEX_STRING dbname;
LEX_STRING name;
LEX_STRING definer;// combination of user and host
Event_basic();
virtual ~Event_basic();
virtual int
load_from_row(TABLE *table) = 0;
protected:
bool
load_string_fields(Field **fields, ...);
};
class Event_queue_element : public Event_basic
{
protected:
bool status_changed; bool status_changed;
bool last_executed_changed; bool last_executed_changed;
MEM_ROOT mem_root;
public: public:
THD *thd;
enum enum_status enum enum_status
{ {
ENABLED = 1, ENABLED = 1,
...@@ -83,17 +99,10 @@ class Event_timed ...@@ -83,17 +99,10 @@ class Event_timed
ON_COMPLETION_PRESERVE ON_COMPLETION_PRESERVE
}; };
enum enum_on_completion on_completion;
enum enum_status status;
TIME last_executed; TIME last_executed;
LEX_STRING dbname;
LEX_STRING name;
LEX_STRING body;
LEX_STRING definer_user;
LEX_STRING definer_host;
LEX_STRING definer;// combination of user and host
LEX_STRING comment;
TIME starts; TIME starts;
TIME ends; TIME ends;
TIME execute_at; TIME execute_at;
...@@ -104,20 +113,32 @@ class Event_timed ...@@ -104,20 +113,32 @@ class Event_timed
longlong expression; longlong expression;
interval_type interval; interval_type interval;
ulonglong created; uint flags;//all kind of purposes
ulonglong modified;
enum enum_on_completion on_completion;
enum enum_status status;
sp_head *sphead;
ulong sql_mode;
bool dropped; bool dropped;
uint flags;//all kind of purposes
Event_queue_element();
virtual ~Event_queue_element();
virtual int
load_from_row(TABLE *table);
bool
compute_next_execution_time();
int
drop(THD *thd);
void
mark_last_executed(THD *thd);
bool
update_timing_fields(THD *thd);
static void *operator new(size_t size) static void *operator new(size_t size)
{ {
void *p; void *p;
DBUG_ENTER("Event_timed::new(size)"); DBUG_ENTER("Event_queue_element::new(size)");
p= my_malloc(size, MYF(0)); p= my_malloc(size, MYF(0));
DBUG_PRINT("info", ("alloc_ptr=0x%lx", p)); DBUG_PRINT("info", ("alloc_ptr=0x%lx", p));
DBUG_RETURN(p); DBUG_RETURN(p);
...@@ -125,54 +146,84 @@ class Event_timed ...@@ -125,54 +146,84 @@ class Event_timed
static void operator delete(void *ptr, size_t size) static void operator delete(void *ptr, size_t size)
{ {
DBUG_ENTER("Event_timed::delete(ptr,size)"); DBUG_ENTER("Event_queue_element::delete(ptr,size)");
DBUG_PRINT("enter", ("free_ptr=0x%lx", ptr)); DBUG_PRINT("enter", ("free_ptr=0x%lx", ptr));
TRASH(ptr, size); TRASH(ptr, size);
my_free((gptr) ptr, MYF(0)); my_free((gptr) ptr, MYF(0));
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
};
Event_timed();
~Event_timed(); class Event_timed : public Event_queue_element
{
Event_timed(const Event_timed &); /* Prevent use of these */
void operator=(Event_timed &);
void public:
init(); LEX_STRING body;
int LEX_STRING definer_user;
load_from_row(TABLE *table); LEX_STRING definer_host;
bool LEX_STRING comment;
compute_next_execution_time();
int ulonglong created;
drop(THD *thd); ulonglong modified;
ulong sql_mode;
Event_timed();
virtual ~Event_timed();
void void
mark_last_executed(THD *thd); init();
bool virtual int
update_fields(THD *thd); load_from_row(TABLE *table);
int int
get_create_event(THD *thd, String *buf); get_create_event(THD *thd, String *buf);
};
class Event_job_data : public Event_basic
{
public:
THD *thd;
sp_head *sphead;
LEX_STRING body;
LEX_STRING definer_user;
LEX_STRING definer_host;
ulong sql_mode;
Event_job_data();
virtual ~Event_job_data();
virtual int
load_from_row(TABLE *table);
int int
execute(THD *thd, MEM_ROOT *mem_root); execute(THD *thd, MEM_ROOT *mem_root);
private:
int
get_fake_create_event(THD *thd, String *buf);
int int
compile(THD *thd, MEM_ROOT *mem_root); compile(THD *thd, MEM_ROOT *mem_root);
void void
free_sp(); free_sp();
Event_job_data(const Event_job_data &); /* Prevent use of these */
void operator=(Event_job_data &);
}; };
class Event_parse_data : public Sql_alloc class Event_parse_data : public Sql_alloc
{ {
Event_parse_data(const Event_parse_data &); /* Prevent use of these */
void operator=(Event_parse_data &);
public: public:
enum enum_status enum enum_status
{ {
...@@ -185,7 +236,6 @@ class Event_parse_data : public Sql_alloc ...@@ -185,7 +236,6 @@ class Event_parse_data : public Sql_alloc
ON_COMPLETION_DROP = 1, ON_COMPLETION_DROP = 1,
ON_COMPLETION_PRESERVE ON_COMPLETION_PRESERVE
}; };
enum enum_on_completion on_completion; enum enum_on_completion on_completion;
enum enum_status status; enum enum_status status;
...@@ -193,8 +243,8 @@ class Event_parse_data : public Sql_alloc ...@@ -193,8 +243,8 @@ class Event_parse_data : public Sql_alloc
LEX_STRING dbname; LEX_STRING dbname;
LEX_STRING name; LEX_STRING name;
LEX_STRING body;
LEX_STRING definer;// combination of user and host LEX_STRING definer;// combination of user and host
LEX_STRING body;
LEX_STRING comment; LEX_STRING comment;
Item* item_starts; Item* item_starts;
...@@ -216,59 +266,41 @@ class Event_parse_data : public Sql_alloc ...@@ -216,59 +266,41 @@ class Event_parse_data : public Sql_alloc
static Event_parse_data * static Event_parse_data *
new_instance(THD *thd); new_instance(THD *thd);
Event_parse_data(); bool
~Event_parse_data(); check_parse_data(THD *);
int void
init_definer(THD *thd); init_body(THD *thd);
int private:
init_execute_at(THD *thd, Item *expr);
int int
init_interval(THD *thd, Item *expr, interval_type new_interval); init_definer(THD *thd);
void void
init_name(THD *thd, sp_name *spn); init_name(THD *thd, sp_name *spn);
int int
init_starts(THD *thd, Item *starts); init_execute_at(THD *thd);
int int
init_ends(THD *thd, Item *ends); init_interval(THD *thd);
void
init_body(THD *thd);
};
class Event_job_data
{
public:
LEX_STRING dbname;
LEX_STRING name;
sp_head *sphead;
LEX_STRING definer;
LEX_STRING body;
ulong sql_mode;
THD *thd;
Event_job_data(){}
~Event_job_data(){}
int int
execute(); init_starts(THD *thd);
private:
int int
load_from_disk(); init_ends(THD *thd);
int Event_parse_data();
compile(); ~Event_parse_data();
void
report_bad_value(const char *item_name, Item *bad_item);
Event_job_data(const Event_job_data &); /* Prevent use of these */ Event_parse_data(const Event_parse_data &); /* Prevent use of these */
void operator=(Event_job_data &); void operator=(Event_parse_data &);
}; };
#endif /* _EVENT_DATA_OBJECTS_H_ */ #endif /* _EVENT_DATA_OBJECTS_H_ */
This diff is collapsed.
...@@ -38,11 +38,6 @@ enum enum_events_table_field ...@@ -38,11 +38,6 @@ enum enum_events_table_field
}; };
int
evex_db_find_event_by_name(THD *thd, const LEX_STRING dbname,
const LEX_STRING ev_name,
TABLE *table);
int int
events_table_index_read_for_db(THD *thd, TABLE *schema_table, events_table_index_read_for_db(THD *thd, TABLE *schema_table,
TABLE *event_table); TABLE *event_table);
...@@ -53,22 +48,13 @@ events_table_scan_all(THD *thd, TABLE *schema_table, TABLE *event_table); ...@@ -53,22 +48,13 @@ events_table_scan_all(THD *thd, TABLE *schema_table, TABLE *event_table);
int int
fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */); fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */);
class Event_timed; class Event_basic;
class Event_parse_data; class Event_parse_data;
class Event_queue_element;
class Event_job_data;
class Event_db_repository class Event_db_repository
{ {
public: public:
Event_db_repository(){} Event_db_repository(){}
~Event_db_repository(){}
int
init_repository();
void
deinit_repository();
int int
create_event(THD *thd, Event_parse_data *parse_data, my_bool create_if_not, create_event(THD *thd, Event_parse_data *parse_data, my_bool create_if_not,
...@@ -85,19 +71,10 @@ class Event_db_repository ...@@ -85,19 +71,10 @@ class Event_db_repository
drop_schema_events(THD *thd, LEX_STRING schema); drop_schema_events(THD *thd, LEX_STRING schema);
int int
drop_user_events(THD *thd, LEX_STRING definer); find_event(THD *thd, LEX_STRING dbname, LEX_STRING name, Event_basic *et);
int
find_event(THD *thd, LEX_STRING dbname, LEX_STRING name, Event_timed **ett,
TABLE *tbl);
int
load_named_event_timed(THD *thd, LEX_STRING dbname, LEX_STRING name,
Event_timed **etn_new);
int int
load_named_event_job(THD *thd, LEX_STRING dbname, LEX_STRING name, load_named_event(THD *thd, LEX_STRING dbname, LEX_STRING name, Event_basic *et);
Event_job_data **etn_new);
int int
find_event_by_name(THD *thd, LEX_STRING db, LEX_STRING name, TABLE *table); find_event_by_name(THD *thd, LEX_STRING db, LEX_STRING name, TABLE *table);
......
This diff is collapsed.
...@@ -17,13 +17,12 @@ ...@@ -17,13 +17,12 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
class sp_name; class sp_name;
class Event_timed; class Event_basic;
class Event_db_repository; class Event_db_repository;
class Event_job_data; class Event_job_data;
class Event_queue_element;
class THD; class THD;
typedef bool * (*event_timed_identifier_comparator)(Event_timed*, Event_timed*);
class Event_scheduler_ng; class Event_scheduler_ng;
class Event_queue class Event_queue
...@@ -46,14 +45,14 @@ class Event_queue ...@@ -46,14 +45,14 @@ class Event_queue
/* Methods for queue management follow */ /* Methods for queue management follow */
int int
create_event(THD *thd, Event_parse_data *et); create_event(THD *thd, LEX_STRING dbname, LEX_STRING name);
int int
update_event(THD *thd, Event_parse_data *et, LEX_STRING *new_schema, update_event(THD *thd, LEX_STRING dbname, LEX_STRING name,
LEX_STRING *new_name); LEX_STRING *new_schema, LEX_STRING *new_name);
bool void
drop_event(THD *thd, sp_name *name); drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name);
void void
drop_schema_events(THD *thd, LEX_STRING schema); drop_schema_events(THD *thd, LEX_STRING schema);
...@@ -61,32 +60,20 @@ class Event_queue ...@@ -61,32 +60,20 @@ class Event_queue
uint uint
events_count(); events_count();
uint
events_count_no_lock();
static bool static bool
check_system_tables(THD *thd); check_system_tables(THD *thd);
void void
recalculate_queue(THD *thd); recalculate_activation_times(THD *thd);
void Event_job_data *
empty_queue();
Event_timed *
get_top_for_execution_if_time(THD *thd, time_t now, struct timespec *abstime); get_top_for_execution_if_time(THD *thd, time_t now, struct timespec *abstime);
Event_timed* bool
get_top(); dump_internal_status(THD *thd);
void
remove_top();
void
top_changed();
protected: protected:
Event_timed * Event_queue_element *
find_event(LEX_STRING db, LEX_STRING name, bool remove_from_q); find_event(LEX_STRING db, LEX_STRING name, bool remove_from_q);
int int
...@@ -94,14 +81,16 @@ class Event_queue ...@@ -94,14 +81,16 @@ class Event_queue
void void
drop_matching_events(THD *thd, LEX_STRING pattern, drop_matching_events(THD *thd, LEX_STRING pattern,
bool (*)(Event_timed *,LEX_STRING *)); bool (*)(LEX_STRING *, Event_basic *));
void
empty_queue();
/* LOCK_event_queue is the mutex which protects the access to the queue. */ /* LOCK_event_queue is the mutex which protects the access to the queue. */
pthread_mutex_t LOCK_event_queue; pthread_mutex_t LOCK_event_queue;
Event_db_repository *db_repository; Event_db_repository *db_repository;
uint mutex_last_locked_at_line; uint mutex_last_locked_at_line;
uint mutex_last_unlocked_at_line; uint mutex_last_unlocked_at_line;
const char* mutex_last_locked_in_func; const char* mutex_last_locked_in_func;
...@@ -123,10 +112,8 @@ class Event_queue ...@@ -123,10 +112,8 @@ class Event_queue
Event_scheduler_ng *scheduler; Event_scheduler_ng *scheduler;
//public: /* The sorted queue with the Event_job_data objects */
/* The sorted queue with the Event_timed objects */
QUEUE queue; QUEUE queue;
}; };
#endif /* _EVENT_QUEUE_H_ */ #endif /* _EVENT_QUEUE_H_ */
This diff is collapsed.
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
class Event_timed;
class Event_queue; class Event_queue;
class Event_job_data;
class Event_scheduler_ng class Event_scheduler_ng
{ {
...@@ -67,7 +67,7 @@ class Event_scheduler_ng ...@@ -67,7 +67,7 @@ class Event_scheduler_ng
void void
queue_changed(); queue_changed();
static int bool
dump_internal_status(THD *thd); dump_internal_status(THD *thd);
private: private:
...@@ -76,7 +76,7 @@ class Event_scheduler_ng ...@@ -76,7 +76,7 @@ class Event_scheduler_ng
/* helper functions */ /* helper functions */
bool bool
execute_top(THD *thd, Event_timed *job_data); execute_top(THD *thd, Event_job_data *job_data);
/* helper functions for working with mutexes & conditionals */ /* helper functions for working with mutexes & conditionals */
void void
...@@ -85,6 +85,9 @@ class Event_scheduler_ng ...@@ -85,6 +85,9 @@ class Event_scheduler_ng
void void
unlock_data(const char *func, uint line); unlock_data(const char *func, uint line);
void
cond_wait(struct timespec *abstime, const char *func, uint line);
pthread_mutex_t LOCK_scheduler_state; pthread_mutex_t LOCK_scheduler_state;
/* This is the current status of the life-cycle of the scheduler. */ /* This is the current status of the life-cycle of the scheduler. */
...@@ -107,6 +110,9 @@ class Event_scheduler_ng ...@@ -107,6 +110,9 @@ class Event_scheduler_ng
const char* mutex_last_locked_in_func; const char* mutex_last_locked_in_func;
const char* mutex_last_unlocked_in_func; const char* mutex_last_unlocked_in_func;
bool mutex_scheduler_data_locked; bool mutex_scheduler_data_locked;
bool waiting_on_cond;
ulonglong started_events;
private: private:
/* Prevent use of these */ /* Prevent use of these */
......
This diff is collapsed.
...@@ -20,6 +20,7 @@ class sp_name; ...@@ -20,6 +20,7 @@ class sp_name;
class Event_parse_data; class Event_parse_data;
class Event_db_repository; class Event_db_repository;
class Event_queue; class Event_queue;
class Event_queue_element;
class Event_scheduler_ng; class Event_scheduler_ng;
/* Return codes */ /* Return codes */
...@@ -41,6 +42,7 @@ sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs); ...@@ -41,6 +42,7 @@ sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs);
class Events class Events
{ {
public: public:
friend class Event_queue_element;
/* /*
Quite NOT the best practice and will be removed once Quite NOT the best practice and will be removed once
Event_timed::drop() and Event_timed is fixed not do drop directly Event_timed::drop() and Event_timed is fixed not do drop directly
...@@ -83,7 +85,8 @@ class Events ...@@ -83,7 +85,8 @@ class Events
uint *rows_affected); uint *rows_affected);
int int
drop_event(THD *thd, sp_name *name, bool if_exists, uint *rows_affected); drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists,
uint *rows_affected, bool only_from_disk);
int int
drop_schema_events(THD *thd, char *db); drop_schema_events(THD *thd, char *db);
...@@ -102,13 +105,9 @@ class Events ...@@ -102,13 +105,9 @@ class Events
static int static int
fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */); fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */);
int bool
dump_internal_status(THD *thd); dump_internal_status(THD *thd);
Event_queue *event_queue;
Event_scheduler_ng *scheduler_ng;
Event_db_repository *db_repository;
private: private:
/* Singleton DP is used */ /* Singleton DP is used */
Events(){} Events(){}
...@@ -117,6 +116,12 @@ class Events ...@@ -117,6 +116,12 @@ class Events
/* Singleton instance */ /* Singleton instance */
static Events singleton; static Events singleton;
Event_queue *event_queue;
Event_scheduler_ng *scheduler_ng;
Event_db_repository *db_repository;
pthread_mutex_t LOCK_event_metadata;
/* Prevent use of these */ /* Prevent use of these */
Events(const Events &); Events(const Events &);
void operator=(Events &); void operator=(Events &);
......
...@@ -5829,7 +5829,7 @@ ER_CANT_CHANGE_TX_ISOLATION 25001 ...@@ -5829,7 +5829,7 @@ ER_CANT_CHANGE_TX_ISOLATION 25001
ER_DUP_ENTRY_AUTOINCREMENT_CASE ER_DUP_ENTRY_AUTOINCREMENT_CASE
eng "ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '%-.64s' for key '%-.64s'" eng "ALTER TABLE causes auto_increment resequencing, resulting in duplicate entry '%-.64s' for key '%-.64s'"
ER_EVENT_MODIFY_QUEUE_ERROR ER_EVENT_MODIFY_QUEUE_ERROR
eng "Internal scheduler error %d" eng "Error during loading event from disk. mysql.event damaged?"
ER_EVENT_SET_VAR_ERROR ER_EVENT_SET_VAR_ERROR
eng "Error during starting/stopping of the scheduler." eng "Error during starting/stopping of the scheduler."
ER_PARTITION_MERGE_ERROR ER_PARTITION_MERGE_ERROR
......
...@@ -3886,8 +3886,12 @@ mysql_execute_command(THD *thd) ...@@ -3886,8 +3886,12 @@ mysql_execute_command(THD *thd)
else else
{ {
uint affected= 1; uint affected= 1;
if (!(res= Events::get_instance()-> if (!(res= Events::get_instance()->drop_event(thd,
drop_event(thd, lex->spname, lex->drop_if_exists, &affected))) lex->spname->m_db,
lex->spname->m_name,
lex->drop_if_exists,
&affected,
FALSE)))
send_ok(thd, affected); send_ok(thd, affected);
} }
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment