mirror of
https://github.com/MariaDB/server.git
synced 2025-01-21 22:34:18 +01:00
4ba2a3322b
WL#1034 (Internal CRON) (with post-review fix)
198 lines
10 KiB
Text
198 lines
10 KiB
Text
create database if not exists events_test;
|
||
use events_test;
|
||
drop event if exists event1;
|
||
Warnings:
|
||
Note 1305 Event event1 does not exist
|
||
create event event1 on schedule every 15 minute starts now() ends date_add(now(), interval 5 hour) DO begin end;
|
||
alter event event1 rename to event2 enable;
|
||
alter event event2 disable;
|
||
alter event event2 enable;
|
||
alter event event2 on completion not preserve;
|
||
alter event event2 on schedule every 1 year on completion preserve rename to event3 comment "new comment" do begin select 1; end__
|
||
alter event event3 rename to event2;
|
||
drop event event2;
|
||
create event event2 on schedule every 2 second starts now() ends date_add(now(), interval 5 hour) comment "some" DO begin end;
|
||
drop event event2;
|
||
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;
|
||
select db, name, body, status, interval_field, interval_value from mysql.event;
|
||
db name body status interval_field interval_value
|
||
events_test e_43 set @a = 4 ENABLED SECOND 1
|
||
drop event e_43;
|
||
set global event_scheduler = 0;
|
||
create table t_event3 (a int, b float);
|
||
drop event if exists event3;
|
||
Warnings:
|
||
Note 1305 Event event3 does not exist
|
||
create event event3 on schedule every 50 + 10 minute starts date_add("20100101", interval 5 minute) ends date_add("20151010", interval 5 day) comment "portokala_comment" DO insert into t_event3 values (unix_timestamp(), rand());
|
||
set max_allowed_packet=128000000;
|
||
select count(*) from t_event3;
|
||
count(*)
|
||
0
|
||
drop event event3;
|
||
drop table t_event3;
|
||
create event one_event on schedule every 10 second do select 123;
|
||
SHOW EVENTS;
|
||
Db Name Definer Type Execute at Interval value Interval field Starts Ends Status
|
||
events_test one_event root@localhost RECURRING NULL 10 INTERVAL_SECOND # # ENABLED
|
||
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT from information_schema.events;
|
||
EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT
|
||
NULL events_test one_event root@localhost select 123 RECURRING NULL 10 INTERVAL_SECOND ENABLED NOT PRESERVE
|
||
CREATE DATABASE events_test2;
|
||
CREATE USER ev_test@localhost;
|
||
GRANT ALL ON events_test.* to ev_test@localhost;
|
||
GRANT ALL on events_test2.* to ev_test@localhost;
|
||
REVOKE EVENT ON events_test2.* FROM ev_test@localhost;
|
||
REVOKE PROCESS on *.* from ev_test@localhost;
|
||
select "NEW CONNECTION";
|
||
NEW CONNECTION
|
||
NEW CONNECTION
|
||
SELECT USER(), DATABASE();
|
||
USER() DATABASE()
|
||
ev_test@localhost events_test2
|
||
SHOW GRANTS;
|
||
Grants for ev_test@localhost
|
||
GRANT USAGE ON *.* TO 'ev_test'@'localhost'
|
||
GRANT ALL PRIVILEGES ON `events_test`.* TO 'ev_test'@'localhost'
|
||
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE ON `events_test2`.* TO 'ev_test'@'localhost'
|
||
"Here comes an error:";
|
||
SHOW EVENTS;
|
||
ERROR 42000: Access denied for user 'ev_test'@'localhost' to database 'events_test2'
|
||
USE events_test;
|
||
"Now the list should be empty:";
|
||
SHOW EVENTS;
|
||
Db Name Definer Type Execute at Interval value Interval field Starts Ends Status
|
||
select concat("Let's create some new events from the name of ",user());
|
||
concat("Let's create some new events from the name of ",user())
|
||
Let's create some new events from the name of ev_test@localhost
|
||
create event one_event on schedule every 20 second do select 123;
|
||
create event two_event on schedule every 20 second on completion not preserve comment "two event" do select 123;
|
||
create event three_event on schedule every 20 second on completion preserve comment "three event" do select 123;
|
||
"Now we should see 3 events:";
|
||
SHOW EVENTS;
|
||
Db Name Definer Type Execute at Interval value Interval field Starts Ends Status
|
||
events_test one_event ev_test@localhost RECURRING NULL 20 INTERVAL_SECOND # # ENABLED
|
||
events_test three_event ev_test@localhost RECURRING NULL 20 INTERVAL_SECOND # # ENABLED
|
||
events_test two_event ev_test@localhost RECURRING NULL 20 INTERVAL_SECOND # # ENABLED
|
||
"This should show us only 3 events:";
|
||
SHOW FULL EVENTS;
|
||
Db Name Definer Type Execute at Interval value Interval field Starts Ends Status
|
||
events_test one_event ev_test@localhost RECURRING NULL 20 INTERVAL_SECOND # # ENABLED
|
||
events_test three_event ev_test@localhost RECURRING NULL 20 INTERVAL_SECOND # # ENABLED
|
||
events_test two_event ev_test@localhost RECURRING NULL 20 INTERVAL_SECOND # # ENABLED
|
||
"This should show us only 2 events:";
|
||
SHOW FULL EVENTS LIKE 't%event';
|
||
Db Name Definer Type Execute at Interval value Interval field Starts Ends Status
|
||
events_test three_event ev_test@localhost RECURRING NULL 20 INTERVAL_SECOND # # ENABLED
|
||
events_test two_event ev_test@localhost RECURRING NULL 20 INTERVAL_SECOND # # ENABLED
|
||
"This should show us no events:";
|
||
SHOW FULL EVENTS FROM test LIKE '%';
|
||
Db Name Definer Type Execute at Interval value Interval field Starts Ends Status
|
||
DROP DATABASE events_test2;
|
||
"should see 1 event:";
|
||
SHOW EVENTS;
|
||
Db Name Definer Type Execute at Interval value Interval field Starts Ends Status
|
||
events_test one_event root@localhost RECURRING NULL 10 INTERVAL_SECOND # # ENABLED
|
||
"we should see 4 events now:";
|
||
SHOW FULL EVENTS;
|
||
Db Name Definer Type Execute at Interval value Interval field Starts Ends Status
|
||
events_test one_event ev_test@localhost RECURRING NULL 20 INTERVAL_SECOND # # ENABLED
|
||
events_test three_event ev_test@localhost RECURRING NULL 20 INTERVAL_SECOND # # ENABLED
|
||
events_test two_event ev_test@localhost RECURRING NULL 20 INTERVAL_SECOND # # ENABLED
|
||
events_test one_event root@localhost RECURRING NULL 10 INTERVAL_SECOND # # ENABLED
|
||
SELECT EVENT_CATALOG, EVENT_SCHEMA, EVENT_NAME, DEFINER, EVENT_BODY, EVENT_TYPE, EXECUTE_AT, INTERVAL_VALUE, INTERVAL_FIELD, STATUS,ON_COMPLETION, EVENT_COMMENT from information_schema.events;
|
||
EVENT_CATALOG EVENT_SCHEMA EVENT_NAME DEFINER EVENT_BODY EVENT_TYPE EXECUTE_AT INTERVAL_VALUE INTERVAL_FIELD STATUS ON_COMPLETION EVENT_COMMENT
|
||
NULL events_test one_event ev_test@localhost select 123 RECURRING NULL 20 INTERVAL_SECOND ENABLED NOT PRESERVE
|
||
NULL events_test three_event ev_test@localhost select 123 RECURRING NULL 20 INTERVAL_SECOND ENABLED PRESERVE three event
|
||
NULL events_test two_event ev_test@localhost select 123 RECURRING NULL 20 INTERVAL_SECOND ENABLED NOT PRESERVE two event
|
||
NULL events_test one_event root@localhost select 123 RECURRING NULL 10 INTERVAL_SECOND ENABLED NOT PRESERVE
|
||
drop event one_event;
|
||
drop event two_event;
|
||
drop event three_event;
|
||
drop user ev_test@localhost;
|
||
drop event one_event;
|
||
"Sleep a bit so the server closes the second connection"
|
||
create event e_26 on schedule at '2017-01-01 00:00:00' disable do set @a = 5;
|
||
select db, name, body, definer, convert_tz(execute_at, 'UTC', 'SYSTEM'), on_completion from mysql.event;
|
||
db name body definer convert_tz(execute_at, 'UTC', 'SYSTEM') on_completion
|
||
events_test e_26 set @a = 5 root@localhost 2017-01-01 00:00:00 DROP
|
||
drop event e_26;
|
||
create event e_26 on schedule at NULL disabled do set @a = 5;
|
||
ERROR HY000: Incorrect AT value: 'NULL'
|
||
create event e_26 on schedule at 'definitely not a datetime' disabled do set @a = 5;
|
||
ERROR HY000: Incorrect AT value: 'definitely not a datetime'
|
||
set names utf8;
|
||
create event задачка on schedule every 123 minute starts now() ends now() + interval 1 month do select 1;
|
||
drop event задачка;
|
||
set event_scheduler=0;
|
||
ERROR HY000: Variable 'event_scheduler' is a GLOBAL variable and should be set with SET GLOBAL
|
||
set global event_scheduler=2;
|
||
ERROR 42000: Variable 'event_scheduler' can't be set to the value of '2'
|
||
"DISABLE the scheduler. Testing that it does not work when the variable is 0"
|
||
set global event_scheduler=0;
|
||
select definer, name, db from mysql.event;
|
||
definer name db
|
||
select get_lock("test_lock1", 20);
|
||
get_lock("test_lock1", 20)
|
||
1
|
||
create event закачка on schedule every 10 hour do select get_lock("test_lock1", 20);
|
||
"Should return 1 row"
|
||
select definer, name, db from mysql.event;
|
||
definer name db
|
||
root@localhost закачка events_test
|
||
"Should be only 1 process"
|
||
show processlist;
|
||
Id User Host db Command Time State Info
|
||
# root localhost events_test Query # NULL show processlist
|
||
select release_lock("test_lock1");
|
||
release_lock("test_lock1")
|
||
1
|
||
drop event закачка;
|
||
"Should have 0 events"
|
||
select count(*) from mysql.event;
|
||
count(*)
|
||
0
|
||
"ENABLE the scheduler and get a lock"
|
||
set global event_scheduler=1;
|
||
select get_lock("test_lock2", 20);
|
||
get_lock("test_lock2", 20)
|
||
1
|
||
"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);
|
||
"Let some time pass to the event starts"
|
||
"Should have only 3 processes: the scheduler, our conn and the locked event"
|
||
show processlist;
|
||
Id User Host db Command Time State Info
|
||
# root localhost events_test Query # NULL show processlist
|
||
# event_scheduler NULL Connect # Sleeping NULL
|
||
# root events_test Connect # User lock select get_lock("test_lock2", 20)
|
||
"Release the mutex, the event worker should finish."
|
||
select release_lock("test_lock2");
|
||
release_lock("test_lock2")
|
||
1
|
||
drop event закачка;
|
||
set global event_scheduler=1;
|
||
select get_lock("test_lock2_1", 20);
|
||
get_lock("test_lock2_1", 20)
|
||
1
|
||
create event закачка21 on schedule every 10 hour do select get_lock("test_lock2_1", 20);
|
||
"Should see 2 processes, one locked on get_lock("
|
||
"Shutting down the scheduler, it should wait for the running event"
|
||
set global event_scheduler=0;
|
||
"Should have only 3 processes: the scheduler, our conn and the locked event"
|
||
show processlist;
|
||
Id User Host db Command Time State Info
|
||
# root localhost events_test Query # NULL show processlist
|
||
# event_scheduler NULL Connect # Sleeping NULL
|
||
# root events_test Connect # User lock select get_lock("test_lock2_1", 20)
|
||
"Release the lock so the child process should finish. Hence the scheduler also"
|
||
select release_lock("test_lock2_1");
|
||
release_lock("test_lock2_1")
|
||
1
|
||
"Should have only our process now:"
|
||
show processlist;
|
||
Id User Host db Command Time State Info
|
||
# root localhost events_test Query # NULL show processlist
|
||
drop event закачка21;
|
||
drop database events_test;
|