Commit ca39997c authored by andrey@example.com's avatar andrey@example.com

WL#3337 (Event scheduler new architecture)

This is a post-review patch.

Fixes the typelib implementation, available only in 5.1.11.

--event-scheduler cmdline : DISABLED | ON | OFF | 0 | 1
DISABLED - makes the scheduler unavailable during the server run
(ON|1)-  When the server is started the scheduler will be started. It can
         be stopped and restarted by setting appropriate values to
         GLOBAL event_scheduler
(OFF|0)- When the server is started, the scheduler won't be started. It
         can be started and again stopped by setting appropriate values to
         GLOBAL event_scheduler. _DEFAULT_ value

The GLOBAL variable event_scheduler can have the following values:
OFF | ON | 0 | 1
DISABLED is not possible and every attempt will end with an error that
it's not a valid value for the variable.
OFF | 0 - This is the pre-5.1.11 behavior - The scheduler stops, if not
          already stopped, and can be started again  by setting
          the value of the variable to ON|1.
ON | 1  - This is the pre-5.1.11 behavior - The scheduler starts, if not
          already started, and can be stopped again by setting the value
          of the variable to OFF|0.
parent eedee130
......@@ -17,13 +17,13 @@ db_x
SHOW TABLES FROM db_x;
Tables_in_db_x
x_table
SET GLOBAL event_scheduler=2;
SET GLOBAL event_scheduler=off;
DROP EVENT e_x1;
DROP EVENT e_x2;
DROP DATABASE db_x;
DROP USER pauline@localhost;
USE events_test;
SET GLOBAL event_scheduler=2;
SET GLOBAL event_scheduler=off;
drop event if exists event1;
Warnings:
Note 1305 Event event1 does not exist
......@@ -94,7 +94,7 @@ begin
alter event e_43 on schedule every 5 minute;
insert into test_nested values(1);
end|
set global event_scheduler = 1;
set global event_scheduler = on;
select db, name, body, status, interval_field, interval_value from mysql.event;
db name body status interval_field interval_value
events_test e_43 begin
......@@ -113,7 +113,7 @@ drop event non_qualif_ev;
drop table non_qualif;
alter event non_existant rename to non_existant_too;
ERROR HY000: Unknown event 'non_existant'
set global event_scheduler = 2;
set global event_scheduler = off;
create event existant on schedule at now() + interval 1 year do select 12;
alter event non_existant rename to existant;
ERROR HY000: Event 'existant' already exists
......@@ -315,12 +315,14 @@ 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=2;
set event_scheduler=off;
ERROR HY000: Variable 'event_scheduler' is a GLOBAL variable and should be set with SET GLOBAL
set global event_scheduler=3;
ERROR 42000: Variable 'event_scheduler' can't be set to the value of '3'
set global event_scheduler=disabled;
ERROR 42000: Variable 'event_scheduler' can't be set to the value of 'disabled'
"DISABLE the scheduler. Testing that it does not work when the variable is 0"
set global event_scheduler=2;
set global event_scheduler=off;
select definer, name, db from mysql.event;
definer name db
select get_lock("test_lock1", 20);
......@@ -343,7 +345,7 @@ select count(*) from mysql.event;
count(*)
0
"ENABLE the scheduler and get a lock"
set global event_scheduler=1;
set global event_scheduler=on;
select get_lock("test_lock2", 20);
get_lock("test_lock2", 20)
1
......@@ -371,7 +373,7 @@ select /*3*/ user, host, db, command, state, info from information_schema.proces
user host db command state info
event_scheduler localhost NULL Daemon Waiting for next activation NULL
root localhost events_test Connect User lock select get_lock("test_lock2_1", 20)
set global event_scheduler=2;
set global event_scheduler=off;
"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;
user host db command state info
......
......@@ -36,9 +36,9 @@ create event e_55 on schedule at 20200101000000 starts 10000101000000 ends 10000
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=off;
delete from mysql.event;
set global event_scheduler= 1;
set global event_scheduler= on;
set @old_sql_mode:=@@sql_mode;
set sql_mode=ansi;
select get_lock('test_bug16407', 60);
......@@ -57,7 +57,7 @@ root localhost events_test select get_lock('test_bug16407', 60)
select release_lock('test_bug16407');
release_lock('test_bug16407')
1
set global event_scheduler= 2;
set global event_scheduler= off;
select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name;
event_schema event_name sql_mode
events_test e_16407 REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI
......@@ -118,7 +118,7 @@ release_lock('ee_16407_2')
select /*3*/ user, host, db, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
user host db info
event_scheduler localhost NULL NULL
set global event_scheduler= 2;
set global event_scheduler= off;
select * from events_smode_test order by ev_name, a;
ev_name a
ee_16407_3 1980-02-19
......@@ -139,7 +139,7 @@ set sql_mode='ansi';
select get_lock('ee_16407_5', 60);
get_lock('ee_16407_5', 60)
1
set global event_scheduler= 1;
set global event_scheduler= on;
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_6_pendant() begin insert into events_test.events_smode_test values('ee_16407_6','2004-02-29'); end|
......@@ -180,10 +180,10 @@ drop event ee_16407_5;
drop event ee_16407_6;
drop procedure ee_16407_5_pendant;
drop procedure ee_16407_6_pendant;
set global event_scheduler= 2;
set global event_scheduler= off;
drop table events_smode_test;
set sql_mode=@old_sql_mode;
set global event_scheduler=2;
set global event_scheduler=off;
delete from mysql.user where User like 'mysqltest_%';
delete from mysql.db where User like 'mysqltest_%';
flush privileges;
......
......@@ -14,7 +14,7 @@ USER_HOST CREATE procedure select_general_log()
BEGIN
SELECT user_host, argument FROM mysql.general_log WHERE argument LIKE '%alabala%';
END
SET GLOBAL event_scheduler=1;
SET GLOBAL event_scheduler=on;
TRUNCATE mysql.general_log;
CREATE EVENT log_general ON SCHEDULE EVERY 1 MINUTE DO SELECT 'alabala', SLEEP(1) FROM DUAL;
"Wait the scheduler to start"
......@@ -25,7 +25,7 @@ USER_HOST CREATE EVENT log_general ON SCHEDULE EVERY 1 MINUTE DO SELECT 'alabala
USER_HOST SELECT 'alabala', SLEEP(1) FROM DUAL
DROP PROCEDURE select_general_log;
DROP EVENT log_general;
SET GLOBAL event_scheduler=2;
SET GLOBAL event_scheduler=off;
"Check slow query log"
"Save the values"
SET @old_global_long_query_time:=(select get_value());
......@@ -58,12 +58,12 @@ SET SESSION long_query_time=1;
SELECT * FROM slow_event_test;
slo_val val
SET SESSION long_query_time=1;
SET GLOBAL event_scheduler=1;
SET GLOBAL event_scheduler=on;
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"
SHOW VARIABLES LIKE 'event_scheduler';
Variable_name Value
event_scheduler 1
event_scheduler ON
"Check our table. Should see 1 row"
SELECT * FROM slow_event_test;
slo_val val
......
create database if not exists mysqltest_events_test;
use mysqltest_events_test;
set global event_scheduler=2;
set global event_scheduler=off;
create table execution_log(name char(10));
create event abc1 on schedule every 1 second do insert into execution_log value('abc1');
create event abc2 on schedule every 1 second do insert into execution_log value('abc2');
create event abc3 on schedule every 1 second do insert into execution_log value('abc3');
select name from execution_log;
name
insert into mysql.event values ('db1','bad','select 42','root@localhost',NULL,1000,'MICROSECOND','2006-05-05 17:39:11','2006-05-05 17:39:20','2016-05-05 15:39:24','2016-05-05 15:39:11',NULL,'ENABLED','DROP','','comment1');
insert into mysql.event values ('db1','bad2','sect','root@localhost',NULL,1000,'SECOND','2006-05-05 17:39:11','2006-05-05 17:39:20','2016-05-05 15:39:24','2016-05-05 15:39:11',NULL,'ENABLED','DROP','','comment2');
"Now we restart the server"
......@@ -2,6 +2,9 @@ use mysqltest_events_test;
"Should get 3 rows : abc1, abc2, abc3
select distinct name from execution_log order by name;
name
abc1
abc2
abc3
drop event abc1;
drop event abc2;
drop event abc3;
......
CREATE DATABASE IF NOT EXISTS events_test;
USE events_test;
SET GLOBAL event_scheduler=OFF;
SHOW VARIABLES LIKE 'event_scheduler';
Variable_name Value
event_scheduler OFF
SET GLOBAL event_scheduler=1;
SHOW VARIABLES LIKE 'event_scheduler';
Variable_name Value
event_scheduler ON
SET GLOBAL event_scheduler=0;
SHOW VARIABLES LIKE 'event_scheduler';
Variable_name Value
event_scheduler OFF
SET GLOBAL event_scheduler=ON;
SHOW VARIABLES LIKE 'event_scheduler';
Variable_name Value
event_scheduler ON
SET GLOBAL event_scheduler=DISABLED;
ERROR 42000: Variable 'event_scheduler' can't be set to the value of 'DISABLED'
SHOW VARIABLES LIKE 'event_scheduler';
Variable_name Value
event_scheduler ON
SET GLOBAL event_scheduler=-1;
ERROR 42000: Variable 'event_scheduler' can't be set to the value of '-1'
SHOW VARIABLES LIKE 'event_scheduler';
Variable_name Value
event_scheduler ON
SET GLOBAL event_scheduler=2;
ERROR 42000: Variable 'event_scheduler' can't be set to the value of '2'
SHOW VARIABLES LIKE 'event_scheduler';
Variable_name Value
event_scheduler ON
SET GLOBAL event_scheduler=5;
ERROR 42000: Variable 'event_scheduler' can't be set to the value of '5'
SHOW VARIABLES LIKE 'event_scheduler';
Variable_name Value
event_scheduler ON
CREATE TABLE table_1(a int);
CREATE TABLE table_2(a int);
CREATE TABLE table_3(a int);
CREATE TABLE table_4(a int);
CREATE TABLE T19170(s1 TIMESTAMP);
SET GLOBAL event_scheduler=1;
SET GLOBAL event_scheduler=ON;
CREATE EVENT two_sec ON SCHEDULE EVERY 2 SECOND DO INSERT INTO table_1 VALUES(1);
CREATE EVENT start_n_end
ON SCHEDULE EVERY 1 SECOND
......
......@@ -32,15 +32,15 @@ USE events_conn1_test2;
SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2';
COUNT(*)
50
SET GLOBAL event_scheduler=1;
SET GLOBAL event_scheduler=on;
DROP DATABASE events_conn1_test2;
SET GLOBAL event_scheduler=2;
SET GLOBAL event_scheduler=off;
SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2';
COUNT(*)
0
CREATE DATABASE events_conn1_test3;
USE events_conn1_test3;
SET GLOBAL event_scheduler=1;
SET GLOBAL event_scheduler=on;
SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test3';
COUNT(*)
50
......@@ -55,9 +55,9 @@ DROP DATABASE events_conn2_db;
DROP DATABASE events_conn3_db;
DROP DATABASE events_conn1_test2;
DROP DATABASE events_conn1_test3;
SET GLOBAL event_scheduler=2;
SET GLOBAL event_scheduler=off;
DROP DATABASE events_conn1_test4;
SET GLOBAL event_scheduler=1;
SET GLOBAL event_scheduler=on;
USE events_test;
DROP TABLE fill_it1;
DROP TABLE fill_it2;
......
......@@ -21,7 +21,7 @@ SET GLOBAL event_scheduler=1;
--sleep 1.2
SHOW DATABASES LIKE 'db_x';
SHOW TABLES FROM db_x;
SET GLOBAL event_scheduler=2;
SET GLOBAL event_scheduler=off;
connection priv_conn;
DROP EVENT e_x1;
DROP EVENT e_x2;
......@@ -33,7 +33,7 @@ USE events_test;
#
# END: BUG #17289 Events: missing privilege check for drop database
#
SET GLOBAL event_scheduler=2;
SET GLOBAL event_scheduler=off;
drop event if exists event1;
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;
......@@ -92,7 +92,7 @@ begin
insert into test_nested values(1);
end|
delimiter ;|
set global event_scheduler = 1;
set global event_scheduler = on;
--sleep 3
select db, name, body, status, interval_field, interval_value from mysql.event;
drop event e_43;
......@@ -109,7 +109,7 @@ drop table non_qualif;
--error ER_EVENT_DOES_NOT_EXIST
alter event non_existant rename to non_existant_too;
set global event_scheduler = 2;
set global event_scheduler = off;
create event existant on schedule at now() + interval 1 year do select 12;
--error ER_EVENT_ALREADY_EXISTS
alter event non_existant rename to existant;
......@@ -279,13 +279,15 @@ drop event задачка;
# event_scheduler is a global var
--error ER_GLOBAL_VARIABLE
set event_scheduler=2;
set event_scheduler=off;
# event_scheduler could be only either 1 or 2
--error ER_WRONG_VALUE_FOR_VAR
set global event_scheduler=3;
--error ER_WRONG_VALUE_FOR_VAR
set global event_scheduler=disabled;
--echo "DISABLE the scheduler. Testing that it does not work when the variable is 0"
set global event_scheduler=2;
set global event_scheduler=off;
select definer, name, db from mysql.event;
select get_lock("test_lock1", 20);
create event закаÑка on schedule every 10 hour do select get_lock("test_lock1", 20);
......@@ -303,7 +305,7 @@ select count(*) from mysql.event;
#
#
--echo "ENABLE the scheduler and get a lock"
set global event_scheduler=1;
set global event_scheduler=on;
select get_lock("test_lock2", 20);
--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);
......@@ -329,7 +331,7 @@ create event закачка21 on schedule every 10 hour do select get_lock("test
--sleep 1
--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;
set global event_scheduler=2;
set global event_scheduler=off;
--sleep 0.8
--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;
......@@ -396,7 +398,7 @@ drop event e1;
##drop event закачка4;
##select release_lock("test_lock4");
##set global event_scheduler=2;
##set global event_scheduler=off;
##select sleep(2);
##--replace_column 1 # 6 #
##show processlist;
......
......@@ -65,9 +65,9 @@ create event e_55 on schedule every 10 hour starts 10000101000000 do drop table
#
# Start - 16407: Events: Changes in sql_mode won't be taken into account
#
set global event_scheduler=2;
set global event_scheduler=off;
delete from mysql.event;
set global event_scheduler= 1;
set global event_scheduler= on;
set @old_sql_mode:=@@sql_mode;
set sql_mode=ansi;
select get_lock('test_bug16407', 60);
......@@ -83,7 +83,7 @@ delimiter ;|
select /*1*/ user, host, db, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
select release_lock('test_bug16407');
set global event_scheduler= 2;
set global event_scheduler= off;
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"
......@@ -132,7 +132,7 @@ select /*2*/ user, host, db, info from information_schema.processlist where info
select release_lock('ee_16407_2');
--sleep 1.2
select /*3*/ user, host, db, 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= off;
select * from events_smode_test order by ev_name, a;
--echo "OK, last check before we drop them"
select event_schema, event_name, sql_mode from information_schema.events order by event_schema, event_name;
......@@ -146,7 +146,7 @@ delete from events_smode_test;
set sql_mode='ansi';
select get_lock('ee_16407_5', 60);
set global event_scheduler= 1;
set global event_scheduler= on;
set sql_mode='traditional';
delimiter |;
......@@ -179,7 +179,7 @@ drop event ee_16407_5;
drop event ee_16407_6;
drop procedure ee_16407_5_pendant;
drop procedure ee_16407_6_pendant;
set global event_scheduler= 2;
set global event_scheduler= off;
drop table events_smode_test;
set sql_mode=@old_sql_mode;
#
......@@ -189,7 +189,7 @@ set sql_mode=@old_sql_mode;
#
# START - 18897: Events: unauthorized action possible with alter event rename
#
set global event_scheduler=2;
set global event_scheduler=off;
--disable_warnings
delete from mysql.user where User like 'mysqltest_%';
delete from mysql.db where User like 'mysqltest_%';
......
......@@ -15,7 +15,7 @@ delimiter ;|
--echo "Check General Query Log"
--replace_column 1 USER_HOST
CALL select_general_log();
SET GLOBAL event_scheduler=1;
SET GLOBAL event_scheduler=on;
TRUNCATE mysql.general_log;
CREATE EVENT log_general ON SCHEDULE EVERY 1 MINUTE DO SELECT 'alabala', SLEEP(1) FROM DUAL;
--echo "Wait the scheduler to start"
......@@ -25,7 +25,7 @@ CREATE EVENT log_general ON SCHEDULE EVERY 1 MINUTE DO SELECT 'alabala', SLEEP(1
CALL select_general_log();
DROP PROCEDURE select_general_log;
DROP EVENT log_general;
SET GLOBAL event_scheduler=2;
SET GLOBAL event_scheduler=off;
--echo "Check slow query log"
--disable_query_log
......@@ -71,7 +71,7 @@ SET SESSION long_query_time=1;
--echo "This won't go to the slow log"
SELECT * FROM slow_event_test;
SET SESSION long_query_time=1;
SET GLOBAL event_scheduler=1;
SET GLOBAL event_scheduler=on;
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"
--sleep 2
......
......@@ -6,11 +6,13 @@ create database if not exists mysqltest_events_test;
--enable_warnings
use mysqltest_events_test;
set global event_scheduler=2;
set global event_scheduler=off;
create table execution_log(name char(10));
create event abc1 on schedule every 1 second do insert into execution_log value('abc1');
create event abc2 on schedule every 1 second do insert into execution_log value('abc2');
create event abc3 on schedule every 1 second do insert into execution_log value('abc3');
--sleep 1.5
select name from execution_log;
insert into mysql.event values ('db1','bad','select 42','root@localhost',NULL,1000,'MICROSECOND','2006-05-05 17:39:11','2006-05-05 17:39:20','2016-05-05 15:39:24','2016-05-05 15:39:11',NULL,'ENABLED','DROP','','comment1');
insert into mysql.event values ('db1','bad2','sect','root@localhost',NULL,1000,'SECOND','2006-05-05 17:39:11','2006-05-05 17:39:20','2016-05-05 15:39:24','2016-05-05 15:39:11',NULL,'ENABLED','DROP','','comment2');
......
......@@ -4,12 +4,34 @@
CREATE DATABASE IF NOT EXISTS events_test;
USE events_test;
SET GLOBAL event_scheduler=OFF;
SHOW VARIABLES LIKE 'event_scheduler';
SET GLOBAL event_scheduler=1;
SHOW VARIABLES LIKE 'event_scheduler';
SET GLOBAL event_scheduler=0;
SHOW VARIABLES LIKE 'event_scheduler';
SET GLOBAL event_scheduler=ON;
SHOW VARIABLES LIKE 'event_scheduler';
--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL event_scheduler=DISABLED;
SHOW VARIABLES LIKE 'event_scheduler';
--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL event_scheduler=-1;
SHOW VARIABLES LIKE 'event_scheduler';
--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL event_scheduler=2;
SHOW VARIABLES LIKE 'event_scheduler';
--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL event_scheduler=5;
SHOW VARIABLES LIKE 'event_scheduler';
CREATE TABLE table_1(a int);
CREATE TABLE table_2(a int);
CREATE TABLE table_3(a int);
CREATE TABLE table_4(a int);
CREATE TABLE T19170(s1 TIMESTAMP);
SET GLOBAL event_scheduler=1;
SET GLOBAL event_scheduler=ON;
# We need to have 2 to make it safe with valgrind. This is probably because
# of when we calculate the timestamp value
CREATE EVENT two_sec ON SCHEDULE EVERY 2 SECOND DO INSERT INTO table_1 VALUES(1);
......
......@@ -61,11 +61,11 @@ while ($1)
}
--enable_query_log
SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2';
SET GLOBAL event_scheduler=1;
SET GLOBAL event_scheduler=on;
--sleep 2.5
DROP DATABASE events_conn1_test2;
SET GLOBAL event_scheduler=2;
SET GLOBAL event_scheduler=off;
SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2';
CREATE DATABASE events_conn1_test3;
USE events_conn1_test3;
......@@ -77,7 +77,7 @@ while ($1)
dec $1;
}
--enable_query_log
SET GLOBAL event_scheduler=1;
SET GLOBAL event_scheduler=on;
SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test3';
CREATE DATABASE events_conn1_test4;
USE events_conn1_test4;
......@@ -112,9 +112,9 @@ connection default;
--send
DROP DATABASE events_conn1_test2;
DROP DATABASE events_conn1_test3;
SET GLOBAL event_scheduler=2;
SET GLOBAL event_scheduler=off;
DROP DATABASE events_conn1_test4;
SET GLOBAL event_scheduler=1;
SET GLOBAL event_scheduler=on;
connection conn2;
reap;
disconnect conn2;
......
......@@ -59,17 +59,39 @@
eligible for execution.
*/
const char *event_scheduler_state_names[]=
{ "OFF", "0", "ON", "1", "SUSPEND", "2", NullS };
/*
Keep the order of the first to as in var_typelib
sys_var_event_scheduler::value_ptr() references this array. Keep in
mind!
*/
static const char *opt_event_scheduler_state_names[]=
{ "OFF", "ON", "0", "1", "DISABLED", NullS };
TYPELIB Events::opt_typelib=
{
array_elements(event_scheduler_state_names)-1,
array_elements(opt_event_scheduler_state_names)-1,
"",
event_scheduler_state_names,
opt_event_scheduler_state_names,
NULL
};
/*
The order should not be changed. We consider OFF to be equivalent of INT 0
And ON of 1. If OFF & ON are interchanged the logic in
sys_var_event_scheduler::update() will be broken!
*/
static const char *var_event_scheduler_state_names[]= { "OFF", "ON", NullS };
TYPELIB Events::var_typelib=
{
array_elements(var_event_scheduler_state_names)-1,
"",
var_event_scheduler_state_names,
NULL
};
static
Event_queue events_event_queue;
......@@ -81,7 +103,8 @@ Event_db_repository events_event_db_repository;
Events Events::singleton;
ulong Events::opt_event_scheduler= 2;
enum Events::enum_opt_event_scheduler Events::opt_event_scheduler=
Events::EVENTS_OFF;
/*
......@@ -607,6 +630,9 @@ Events::init()
bool res= FALSE;
DBUG_ENTER("Events::init");
if (opt_event_scheduler == Events::EVENTS_DISABLED)
DBUG_RETURN(FALSE);
/* We need a temporary THD during boot */
if (!(thd= new THD()))
{
......@@ -637,12 +663,10 @@ Events::init()
}
scheduler->init_scheduler(event_queue);
if (opt_event_scheduler)
{
DBUG_ASSERT(opt_event_scheduler == 1 || opt_event_scheduler == 2);
if (opt_event_scheduler == 1)
res= scheduler->start();
}
DBUG_ASSERT(opt_event_scheduler == Events::EVENTS_ON ||
opt_event_scheduler == Events::EVENTS_OFF);
if (opt_event_scheduler == Events::EVENTS_ON)
res= scheduler->start();
end:
delete thd;
......@@ -667,10 +691,11 @@ void
Events::deinit()
{
DBUG_ENTER("Events::deinit");
if (likely(!check_system_tables_error))
if (likely(!check_system_tables_error) &&
scheduler->get_state() > Event_scheduler::UNINITIALIZED)
{
scheduler->stop();
DBUG_ASSERT(scheduler->get_state() == Event_scheduler::INITIALIZED);
scheduler->deinit_scheduler();
event_queue->deinit_queue();
......
......@@ -48,9 +48,18 @@ public:
or other scheme will be found.
*/
friend class Event_queue_element;
static ulong opt_event_scheduler;
/* The order should match the order in opt_typelib */
enum enum_opt_event_scheduler
{
EVENTS_OFF= 0,
EVENTS_ON= 1,
EVENTS_DISABLED= 5,
};
static enum_opt_event_scheduler opt_event_scheduler;
static TYPELIB opt_typelib;
static TYPELIB var_typelib;
bool
init();
......
......@@ -5072,9 +5072,9 @@ Disable with --skip-bdb (will save memory).",
(gptr*) &global_system_variables.engine_condition_pushdown,
(gptr*) &global_system_variables.engine_condition_pushdown,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
/* See how it's handled in get_one_option() */
{"event-scheduler", OPT_EVENT_SCHEDULER, "Enable/disable the event scheduler.",
(gptr*) &Events::opt_event_scheduler, (gptr*) &Events::opt_event_scheduler, 0, GET_ULONG,
REQUIRED_ARG, 2/*default*/, 0/*min-value*/, 2/*max-value*/, 0, 0, 0},
NULL, NULL, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"exit-info", 'T', "Used for debugging; Use at your own risk!", 0, 0, 0,
GET_LONG, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"external-locking", OPT_USE_LOCKING, "Use system (external) locking (disabled by default). With this option enabled you can run myisamchk to test (not repair) tables while the MySQL server is running. Disable with --skip-external-locking.",
......@@ -7423,20 +7423,33 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
#endif
case OPT_EVENT_SCHEDULER:
if (!argument)
Events::opt_event_scheduler= 2;
Events::opt_event_scheduler= Events::EVENTS_DISABLED;
else
{
int type;
if ((type=find_type(argument, &Events::opt_typelib, 1)) <= 0)
{
fprintf(stderr,"Unknown option to event-scheduler: %s\n",argument);
exit(1);
}
/*
type= 1 2 3 4 5 6
(OFF | 0) - (ON | 1) - (2 | SUSPEND)
type= 5 1 2 3 4
(DISABLE ) - (OFF | ON) - (0 | 1)
*/
Events::opt_event_scheduler= (type-1) / 2;
switch ((type=find_type(argument, &Events::opt_typelib, 1))) {
case 0:
fprintf(stderr, "Unknown option to event-scheduler: %s\n",argument);
exit(1);
case 5: /* OPT_DISABLED */
Events::opt_event_scheduler= Events::EVENTS_DISABLED;
break;
case 2: /* OPT_ON */
case 4: /* 1 */
Events::opt_event_scheduler= Events::EVENTS_ON;
break;
case 1: /* OPT_OFF */
case 3: /* 0 */
Events::opt_event_scheduler= Events::EVENTS_OFF;
break;
default:
DBUG_ASSERT(0);
unireg_abort(1);
}
}
break;
case (int) OPT_SKIP_NEW:
......
......@@ -3914,6 +3914,7 @@ bool sys_var_thd_dbug::update(THD *thd, set_var *var)
return 0;
}
byte *sys_var_thd_dbug::value_ptr(THD *thd, enum_var_type type, LEX_STRING *b)
{
char buf[256];
......@@ -3925,6 +3926,12 @@ byte *sys_var_thd_dbug::value_ptr(THD *thd, enum_var_type type, LEX_STRING *b)
}
bool sys_var_event_scheduler::check(THD *thd, set_var *var)
{
return check_enum(thd, var, &Events::var_typelib);
}
/*
The update method of the global variable event_scheduler.
If event_scheduler is switched from 0 to 1 then the scheduler main
......@@ -3946,29 +3953,27 @@ sys_var_event_scheduler::update(THD *thd, set_var *var)
int res;
/* here start the thread if not running. */
DBUG_ENTER("sys_var_event_scheduler::update");
if (Events::opt_event_scheduler == 0)
if (Events::opt_event_scheduler == Events::EVENTS_DISABLED)
{
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--event-scheduler=0");
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--event-scheduler=DISABLED");
DBUG_RETURN(TRUE);
}
DBUG_PRINT("new_value", ("%lu", (bool)var->save_result.ulong_value));
if (var->save_result.ulonglong_value < 1 ||
var->save_result.ulonglong_value > 2)
{
char buf[64];
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "event_scheduler",
llstr(var->save_result.ulonglong_value, buf));
DBUG_RETURN(TRUE);
}
if (var->save_result.ulonglong_value == 1)
Item_result var_type= var->value->result_type();
if (var->save_result.ulong_value == Events::EVENTS_ON)
res= Events::get_instance()->start_execution_of_events();
else
else if (var->save_result.ulong_value == Events::EVENTS_OFF)
res= Events::get_instance()->stop_execution_of_events();
else
{
DBUG_ASSERT(0);
}
if (res)
my_error(ER_EVENT_SET_VAR_ERROR, MYF(0));
DBUG_RETURN((bool) res);
}
......@@ -3976,14 +3981,15 @@ sys_var_event_scheduler::update(THD *thd, set_var *var)
byte *sys_var_event_scheduler::value_ptr(THD *thd, enum_var_type type,
LEX_STRING *base)
{
if (Events::opt_event_scheduler == 0)
thd->sys_var_tmp.long_value= 0;
int state;
if (Events::opt_event_scheduler == Events::EVENTS_DISABLED)
state= Events::EVENTS_DISABLED; // This should be DISABLED
else if (Events::get_instance()->is_execution_of_events_started())
thd->sys_var_tmp.long_value= 1;
state= Events::EVENTS_ON; // This should be ON
else
thd->sys_var_tmp.long_value= 2;
state= Events::EVENTS_OFF; // This should be OFF
return (byte*) &thd->sys_var_tmp;
return (byte*) Events::opt_typelib.type_names[state];
}
......
......@@ -932,6 +932,12 @@ public:
sys_var_long_ptr(name_arg, NULL, NULL) {};
bool update(THD *thd, set_var *var);
byte *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
SHOW_TYPE type() { return SHOW_CHAR; }
bool check(THD *thd, set_var *var);
bool check_update_type(Item_result type)
{
return type != STRING_RESULT && type != INT_RESULT;
}
};
#ifdef HAVE_ROW_BASED_REPLICATION
......
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