Skip to content

Commit 2bdd872

Browse files
author
andrey@lmy004.
committed
WL #3337 (Event scheduler new architecture)
Cut Nr. 8. All tests pass. Separated Event_scheduler into Event_queue and Event_scheduler. Added new Event_scheduler_ng which is the new scheduler and is used system-wide. Will be moved to the event_scheduler.cc in the future. Using Event_timed in Event_queue as well as cloned during execution. Next step is to have Event_worker_data which will be used during execution and will take ::compile()/::execute() out of Event_timed.
1 parent 6dd9a3b commit 2bdd872

24 files changed

Lines changed: 1198 additions & 531 deletions

mysql-test/r/events.result

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ root@localhost закачка events_test
323323
"Should be only 1 process"
324324
select /*1*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
325325
user host db command state info
326-
event_scheduler localhost NULL Connect Suspended NULL
327326
select release_lock("test_lock1");
328327
release_lock("test_lock1")
329328
1
@@ -343,7 +342,7 @@ create event закачка on schedule every 10 hour do select get_lock("test_l
343342
"Should have only 2 processes: the scheduler and the locked event"
344343
select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
345344
user host db command state info
346-
event_scheduler localhost NULL Connect Sleeping NULL
345+
event_scheduler localhost NULL Connect Waiting for next activation NULL
347346
root localhost events_test Connect User lock select get_lock("test_lock2", 20)
348347
"Release the mutex, the event worker should finish."
349348
"Release the mutex, the event worker should finish."
@@ -359,13 +358,12 @@ create event закачка21 on schedule every 10 hour do select get_lock("test
359358
"Should have only 3 processes: the scheduler, our conn and the locked event"
360359
select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
361360
user host db command state info
362-
event_scheduler localhost NULL Connect Sleeping NULL
361+
event_scheduler localhost NULL Connect Waiting for next activation NULL
363362
root localhost events_test Connect User lock select get_lock("test_lock2_1", 20)
364363
set global event_scheduler=2;
365364
"Should have only our process now:"
366365
select /*4*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
367366
user host db command state info
368-
event_scheduler localhost NULL Connect Suspended NULL
369367
root localhost events_test Connect User lock select get_lock("test_lock2_1", 20)
370368
drop event закачка21;
371369
create table t_16 (s1 int);

mysql-test/r/events_bugs.result

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ end|
4141
"Now if everything is fine the event has compiled and is locked
4242
select /*1*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
4343
user host db command state info
44-
event_scheduler localhost NULL Connect Sleeping NULL
44+
event_scheduler localhost NULL Connect Waiting for next activation NULL
4545
root localhost events_test Connect User lock select get_lock('test_bug16407', 60)
4646
select release_lock('test_bug16407');
4747
release_lock('test_bug16407')
@@ -94,7 +94,7 @@ get_lock('ee_16407_2', 60)
9494
set global event_scheduler= 1;
9595
select /*2*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
9696
user host db command state info
97-
event_scheduler localhost NULL Connect Sleeping NULL
97+
event_scheduler localhost NULL Connect Waiting for next activation NULL
9898
root localhost events_test Connect User lock select get_lock('ee_16407_2', 60) /*ee_16407_2*/
9999
root localhost events_test Connect User lock select get_lock('ee_16407_2', 60) /*ee_16407_3*/
100100
root localhost events_test Connect User lock select get_lock('ee_16407_2', 60) /*ee_16407_4*/
@@ -103,7 +103,7 @@ release_lock('ee_16407_2')
103103
1
104104
select /*3*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
105105
user host db command state info
106-
event_scheduler localhost NULL Connect Sleeping NULL
106+
event_scheduler localhost NULL Connect Waiting for next activation NULL
107107
set global event_scheduler= 2;
108108
select * from events_smode_test order by ev_name, a;
109109
ev_name a
@@ -142,7 +142,7 @@ set global event_scheduler= 1;
142142
"Should have 2 locked processes"
143143
select /*4*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
144144
user host db command state info
145-
event_scheduler localhost NULL Connect Sleeping NULL
145+
event_scheduler localhost NULL Connect Waiting for next activation NULL
146146
root localhost events_test Connect User lock select get_lock('ee_16407_5', 60) /*ee_16407_5*/
147147
root localhost events_test Connect User lock select get_lock('ee_16407_5', 60) /*ee_16407_6*/
148148
select release_lock('ee_16407_5');
@@ -151,7 +151,7 @@ release_lock('ee_16407_5')
151151
"Should have 0 processes locked"
152152
select /*5*/ user, host, db, command, state, info from information_schema.processlist where info is null or info not like '%processlist%' order by info;
153153
user host db command state info
154-
event_scheduler localhost NULL Connect Sleeping NULL
154+
event_scheduler localhost NULL Connect Waiting for next activation NULL
155155
select * from events_smode_test order by ev_name, a;
156156
ev_name a
157157
ee_16407_6 2004-02-29

mysql-test/r/ps_1general.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ t9 MyISAM 10 Dynamic 2 216 432 # 2048 0 NULL # # # latin1_swedish_ci NULL
299299
prepare stmt4 from ' show status like ''Threads_running'' ';
300300
execute stmt4;
301301
Variable_name Value
302-
Threads_running 2
302+
Threads_running 1
303303
prepare stmt4 from ' show variables like ''sql_mode'' ';
304304
execute stmt4;
305305
Variable_name Value

mysql-test/r/skip_name_resolve.result

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ user()
1010
#
1111
show processlist;
1212
Id User Host db Command Time State Info
13-
<id> event_scheduler <host> NULL <command> <time> <state> <info>
1413
<id> root <host> test <command> <time> <state> <info>
1514
<id> root <host> test <command> <time> <state> <info>

mysql-test/r/sp-threads.result

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ lock tables t2 write;
3434
call bug9486();
3535
show processlist;
3636
Id User Host db Command Time State Info
37-
# event_scheduler localhost NULL Connect # Suspended NULL
3837
# root localhost test Sleep # NULL
3938
# root localhost test Query # Locked update t1, t2 set val= 1 where id1=id2
4039
# root localhost test Query # NULL show processlist

mysql-test/r/sp_notembedded.result

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ show processlist;
1818
end|
1919
call bug4902_2()|
2020
Id User Host db Command Time State Info
21-
# event_scheduler localhost NULL Connect # Suspended NULL
2221
# root localhost test Query # NULL show processlist
2322
call bug4902_2()|
2423
Id User Host db Command Time State Info
25-
# event_scheduler localhost NULL Connect # Suspended NULL
2624
# root localhost test Query # NULL show processlist
2725
drop procedure bug4902_2|
2826
drop function if exists bug5278|

mysql-test/r/status.result

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ drop table t1;
5252
FLUSH STATUS;
5353
SHOW STATUS LIKE 'max_used_connections';
5454
Variable_name Value
55-
Max_used_connections 2
55+
Max_used_connections 1
5656
SET @save_thread_cache_size=@@thread_cache_size;
5757
SET GLOBAL thread_cache_size=3;
5858
SHOW STATUS LIKE 'max_used_connections';
5959
Variable_name Value
60-
Max_used_connections 4
60+
Max_used_connections 3
6161
FLUSH STATUS;
6262
SHOW STATUS LIKE 'max_used_connections';
6363
Variable_name Value
64-
Max_used_connections 3
64+
Max_used_connections 2
6565
SHOW STATUS LIKE 'max_used_connections';
6666
Variable_name Value
67-
Max_used_connections 4
67+
Max_used_connections 3
6868
SHOW STATUS LIKE 'max_used_connections';
6969
Variable_name Value
70-
Max_used_connections 5
70+
Max_used_connections 4
7171
SET GLOBAL thread_cache_size=@save_thread_cache_size;
7272
show status like 'com_show_status';
7373
Variable_name Value

mysql-test/t/events_stress.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ while ($1)
6161
--enable_query_log
6262
SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2';
6363
SET GLOBAL event_scheduler=1;
64-
--sleep 6
64+
--sleep 12
6565
DROP DATABASE events_conn1_test2;
6666

6767
SET GLOBAL event_scheduler=2;
@@ -100,7 +100,7 @@ while ($1)
100100
}
101101
--enable_query_log
102102
SELECT COUNT(*) FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_SCHEMA='events_conn1_test2';
103-
--sleep 6
103+
--sleep 12
104104
connection conn2;
105105
--send
106106
DROP DATABASE events_conn2_db;

sql/Makefile.am

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
6767
sql_array.h sql_cursor.h events.h \
6868
sql_plugin.h authors.h sql_partition.h event_data_objects.h \
6969
event_queue.h event_db_repository.h \
70-
partition_info.h partition_element.h event_scheduler.h \
70+
partition_info.h partition_element.h event_scheduler_ng.h \
7171
contributors.h
7272
mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
7373
item.cc item_sum.cc item_buff.cc item_func.cc \
@@ -104,8 +104,8 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
104104
gstream.cc spatial.cc sql_help.cc sql_cursor.cc \
105105
tztime.cc my_time.c my_user.c my_decimal.cc\
106106
sp_head.cc sp_pcontext.cc sp_rcontext.cc sp.cc \
107-
sp_cache.cc parse_file.cc sql_trigger.cc \
108-
event_scheduler.cc events.cc event_data_objects.cc \
107+
sp_cache.cc parse_file.cc sql_trigger.cc event_scheduler.cc\
108+
event_scheduler_ng.cc events.cc event_data_objects.cc \
109109
event_queue.cc event_db_repository.cc \
110110
sql_plugin.cc sql_binlog.cc \
111111
sql_builtin.cc sql_tablespace.cc partition_info.cc

sql/event_data_objects.cc

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ Event_timed::Event_timed():in_spawned_thread(0),locked_by_thread_id(0),
556556
Event_timed::~Event_timed()
557557
{
558558
deinit_mutexes();
559+
free_root(&mem_root, MYF(0));
559560

560561
if (free_sphead_on_delete)
561562
free_sp();
@@ -622,6 +623,8 @@ Event_timed::init()
622623
definer_user.length= definer_host.length= 0;
623624

624625
sql_mode= 0;
626+
/* init memory root */
627+
init_alloc_root(&mem_root, 256, 512);
625628

626629
DBUG_VOID_RETURN;
627630
}
@@ -644,7 +647,7 @@ Event_timed::init()
644647
*/
645648

646649
int
647-
Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table)
650+
Event_timed::load_from_row(TABLE *table)
648651
{
649652
char *ptr;
650653
Event_timed *et;
@@ -661,22 +664,22 @@ Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table)
661664
if (table->s->fields != ET_FIELD_COUNT)
662665
goto error;
663666

664-
if ((et->dbname.str= get_field(mem_root, table->field[ET_FIELD_DB])) == NULL)
667+
if ((et->dbname.str= get_field(&mem_root, table->field[ET_FIELD_DB])) == NULL)
665668
goto error;
666669

667670
et->dbname.length= strlen(et->dbname.str);
668671

669-
if ((et->name.str= get_field(mem_root, table->field[ET_FIELD_NAME])) == NULL)
672+
if ((et->name.str= get_field(&mem_root, table->field[ET_FIELD_NAME])) == NULL)
670673
goto error;
671674

672675
et->name.length= strlen(et->name.str);
673676

674-
if ((et->body.str= get_field(mem_root, table->field[ET_FIELD_BODY])) == NULL)
677+
if ((et->body.str= get_field(&mem_root, table->field[ET_FIELD_BODY])) == NULL)
675678
goto error;
676679

677680
et->body.length= strlen(et->body.str);
678681

679-
if ((et->definer.str= get_field(mem_root,
682+
if ((et->definer.str= get_field(&mem_root,
680683
table->field[ET_FIELD_DEFINER])) == NullS)
681684
goto error;
682685
et->definer.length= strlen(et->definer.str);
@@ -688,10 +691,10 @@ Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table)
688691

689692
len= ptr - et->definer.str;
690693

691-
et->definer_user.str= strmake_root(mem_root, et->definer.str, len);
694+
et->definer_user.str= strmake_root(&mem_root, et->definer.str, len);
692695
et->definer_user.length= len;
693696
len= et->definer.length - len - 1; //1 is because of @
694-
et->definer_host.str= strmake_root(mem_root, ptr + 1, len);/* 1:because of @*/
697+
et->definer_host.str= strmake_root(&mem_root, ptr + 1, len);/* 1:because of @*/
695698
et->definer_host.length= len;
696699

697700
et->starts_null= table->field[ET_FIELD_STARTS]->is_null();
@@ -737,21 +740,21 @@ Event_timed::load_from_row(MEM_ROOT *mem_root, TABLE *table)
737740
last_executed_changed= false;
738741

739742
/* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */
740-
if ((ptr= get_field(mem_root, table->field[ET_FIELD_STATUS])) == NullS)
743+
if ((ptr= get_field(&mem_root, table->field[ET_FIELD_STATUS])) == NullS)
741744
goto error;
742745

743746
DBUG_PRINT("load_from_row", ("Event [%s] is [%s]", et->name.str, ptr));
744747
et->status= (ptr[0]=='E'? Event_timed::ENABLED:Event_timed::DISABLED);
745748

746749
/* ToDo : Andrey . Find a way not to allocate ptr on event_mem_root */
747-
if ((ptr= get_field(mem_root,
750+
if ((ptr= get_field(&mem_root,
748751
table->field[ET_FIELD_ON_COMPLETION])) == NullS)
749752
goto error;
750753

751754
et->on_completion= (ptr[0]=='D'? Event_timed::ON_COMPLETION_DROP:
752755
Event_timed::ON_COMPLETION_PRESERVE);
753756

754-
et->comment.str= get_field(mem_root, table->field[ET_FIELD_COMMENT]);
757+
et->comment.str= get_field(&mem_root, table->field[ET_FIELD_COMMENT]);
755758
if (et->comment.str != NullS)
756759
et->comment.length= strlen(et->comment.str);
757760
else
@@ -953,10 +956,10 @@ Event_timed::compute_next_execution_time()
953956
int tmp;
954957

955958
DBUG_ENTER("Event_timed::compute_next_execution_time");
956-
DBUG_PRINT("enter", ("starts=%llu ends=%llu last_executed=%llu",
959+
DBUG_PRINT("enter", ("starts=%llu ends=%llu last_executed=%llu this=%p",
957960
TIME_to_ulonglong_datetime(&starts),
958961
TIME_to_ulonglong_datetime(&ends),
959-
TIME_to_ulonglong_datetime(&last_executed)));
962+
TIME_to_ulonglong_datetime(&last_executed), this));
960963

961964
if (status == Event_timed::DISABLED)
962965
{
@@ -1168,7 +1171,8 @@ Event_timed::compute_next_execution_time()
11681171
goto ret;
11691172
}
11701173
ret:
1171-
DBUG_PRINT("info", ("ret=0"));
1174+
DBUG_PRINT("info", ("ret=0 execute_at=%llu",
1175+
TIME_to_ulonglong_datetime(&execute_at)));
11721176
DBUG_RETURN(false);
11731177
err:
11741178
DBUG_PRINT("info", ("ret=1"));
@@ -1392,6 +1396,7 @@ Event_timed::get_create_event(THD *thd, String *buf)
13921396
int
13931397
Event_timed::execute(THD *thd, MEM_ROOT *mem_root)
13941398
{
1399+
Security_context *save_ctx;
13951400
/* this one is local and not needed after exec */
13961401
Security_context security_ctx;
13971402
int ret= 0;
@@ -1400,14 +1405,8 @@ Event_timed::execute(THD *thd, MEM_ROOT *mem_root)
14001405
DBUG_PRINT("info", (" EVEX EXECUTING event %s.%s [EXPR:%d]",
14011406
dbname.str, name.str, (int) expression));
14021407

1403-
VOID(pthread_mutex_lock(&this->LOCK_running));
1404-
if (running)
1405-
{
1406-
VOID(pthread_mutex_unlock(&this->LOCK_running));
1407-
DBUG_RETURN(-100);
1408-
}
1409-
running= true;
1410-
VOID(pthread_mutex_unlock(&this->LOCK_running));
1408+
thd->change_security_context(definer_user, definer_host, dbname,
1409+
&security_ctx, &save_ctx);
14111410

14121411
if (!sphead && (ret= compile(thd, mem_root)))
14131412
goto done;
@@ -1434,14 +1433,11 @@ Event_timed::execute(THD *thd, MEM_ROOT *mem_root)
14341433
definer_host.str, dbname.str));
14351434
ret= -99;
14361435
}
1437-
1438-
VOID(pthread_mutex_lock(&this->LOCK_running));
1439-
running= false;
14401436
/* Will compile every time a new sp_head on different root */
14411437
free_sp();
1442-
VOID(pthread_mutex_unlock(&this->LOCK_running));
14431438

14441439
done:
1440+
thd->restore_security_context(save_ctx);
14451441
/*
14461442
1. Don't cache sphead if allocated on another mem_root
14471443
2. Don't call security_ctx.destroy() because this will free our dbname.str
@@ -1807,3 +1803,4 @@ event_timed_identifier_equal(LEX_STRING db, LEX_STRING name, Event_timed *b)
18071803
return !sortcmp_lex_string(name, b->name, system_charset_info) &&
18081804
!sortcmp_lex_string(db, b->dbname, system_charset_info);
18091805
}
1806+

0 commit comments

Comments
 (0)