Skip to content

Commit dd31d45

Browse files
author
andrey@lmy004.
committed
WL #3337 (Events new architecture)
Final stroke, events should be loaded from disk on server startup. Also check the validity of their bodies if possible during loading.
1 parent 3f4e1f5 commit dd31d45

22 files changed

Lines changed: 315 additions & 161 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
create database if not exists mysqltest_events_test;
2+
use mysqltest_events_test;
3+
set global event_scheduler=2;
4+
create table execution_log(name char(10));
5+
create event abc1 on schedule every 1 second do insert into execution_log value('abc1');
6+
create event abc2 on schedule every 1 second do insert into execution_log value('abc2');
7+
create event abc3 on schedule every 1 second do insert into execution_log value('abc3');
8+
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');
9+
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');
10+
"Now we restart the server"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use mysqltest_events_test;
2+
"Should get 0 rows because the queue aborted run
3+
select distinct name from execution_log order by name;
4+
name
5+
delete from mysql.event where name like 'bad%';
6+
"Now restart the server again"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use mysqltest_events_test;
2+
"Should get 3 rows : abc1, abc2, abc3
3+
select distinct name from execution_log order by name;
4+
name
5+
drop event abc1;
6+
drop event abc2;
7+
drop event abc3;
8+
drop table execution_log;
9+
drop database mysqltest_events_test;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Can't test with embedded server that doesn't support grants
2+
-- source include/not_embedded.inc
3+
4+
--disable_warnings
5+
create database if not exists mysqltest_events_test;
6+
--enable_warnings
7+
8+
use mysqltest_events_test;
9+
set global event_scheduler=2;
10+
create table execution_log(name char(10));
11+
create event abc1 on schedule every 1 second do insert into execution_log value('abc1');
12+
create event abc2 on schedule every 1 second do insert into execution_log value('abc2');
13+
create event abc3 on schedule every 1 second do insert into execution_log value('abc3');
14+
15+
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');
16+
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');
17+
--echo "Now we restart the server"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--event-scheduler=1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Can't test with embedded server that doesn't support grants
2+
-- source include/not_embedded.inc
3+
4+
use mysqltest_events_test;
5+
--sleep 1.5
6+
--echo "Should get 0 rows because the queue aborted run
7+
select distinct name from execution_log order by name;
8+
delete from mysql.event where name like 'bad%';
9+
--echo "Now restart the server again"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--event-scheduler=1
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Can't test with embedded server that doesn't support grants
2+
-- source include/not_embedded.inc
3+
4+
use mysqltest_events_test;
5+
--sleep 2
6+
--echo "Should get 3 rows : abc1, abc2, abc3
7+
select distinct name from execution_log order by name;
8+
9+
drop event abc1;
10+
drop event abc2;
11+
drop event abc3;
12+
drop table execution_log;
13+
14+
drop database mysqltest_events_test;

sql/event_data_objects.cc

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ Event_timed::~Event_timed()
731731
*/
732732

733733
Event_job_data::Event_job_data():
734-
thd(NULL), sphead(0), sql_mode(0)
734+
thd(NULL), sphead(NULL), sql_mode(0)
735735
{
736736
}
737737

@@ -745,7 +745,10 @@ Event_job_data::Event_job_data():
745745

746746
Event_job_data::~Event_job_data()
747747
{
748-
free_sp();
748+
DBUG_ENTER("Event_job_data::~Event_job_data");
749+
delete sphead;
750+
sphead= NULL;
751+
DBUG_VOID_RETURN;
749752
}
750753

751754

@@ -1605,20 +1608,6 @@ Event_job_data::get_fake_create_event(THD *thd, String *buf)
16051608
}
16061609

16071610

1608-
/*
1609-
Frees the memory of the sp_head object we hold
1610-
SYNOPSIS
1611-
Event_job_data::free_sp()
1612-
*/
1613-
1614-
void
1615-
Event_job_data::free_sp()
1616-
{
1617-
delete sphead;
1618-
sphead= NULL;
1619-
}
1620-
1621-
16221611
/*
16231612
Compiles an event before it's execution. Compiles the anonymous
16241613
sp_head object held by the event
@@ -1651,9 +1640,7 @@ Event_job_data::compile(THD *thd, MEM_ROOT *mem_root)
16511640
CHARSET_INFO *old_character_set_client,
16521641
*old_collation_connection,
16531642
*old_character_set_results;
1654-
Security_context *save_ctx;
1655-
/* this one is local and not needed after exec */
1656-
Security_context security_ctx;
1643+
Security_context save_ctx;
16571644

16581645
DBUG_ENTER("Event_job_data::compile");
16591646

@@ -1699,10 +1686,9 @@ Event_job_data::compile(THD *thd, MEM_ROOT *mem_root)
16991686
thd->query_length= show_create.length();
17001687
DBUG_PRINT("info", ("query:%s",thd->query));
17011688

1702-
thd->change_security_context(definer_user, definer_host, dbname,
1703-
&security_ctx, &save_ctx);
1689+
thd->change_security_context(definer_user, definer_host, dbname, &save_ctx);
17041690
thd->lex= &lex;
1705-
lex_start(thd, (uchar*)thd->query, thd->query_length);
1691+
mysql_init_query(thd, (uchar*) thd->query, thd->query_length);
17061692
if (MYSQLparse((void *)thd) || thd->is_fatal_error)
17071693
{
17081694
DBUG_PRINT("error", ("error during compile or thd->is_fatal_error=%d",
@@ -1713,13 +1699,10 @@ Event_job_data::compile(THD *thd, MEM_ROOT *mem_root)
17131699
*/
17141700
sql_print_error("error during compile of %s.%s or thd->is_fatal_error=%d",
17151701
dbname.str, name.str, thd->is_fatal_error);
1716-
if (lex.sphead)
1717-
{
1718-
if (&lex != thd->lex)
1719-
thd->lex->sphead->restore_lex(thd);
1720-
delete lex.sphead;
1721-
lex.sphead= 0;
1722-
}
1702+
1703+
lex.unit.cleanup();
1704+
delete lex.sphead;
1705+
sphead= lex.sphead= NULL;
17231706
ret= EVEX_COMPILE_ERROR;
17241707
goto done;
17251708
}
@@ -1734,7 +1717,7 @@ Event_job_data::compile(THD *thd, MEM_ROOT *mem_root)
17341717
done:
17351718

17361719
lex_end(&lex);
1737-
thd->restore_security_context(save_ctx);
1720+
thd->restore_security_context(&save_ctx);
17381721
DBUG_PRINT("note", ("return old data on its place. set back NAMES"));
17391722

17401723
thd->lex= old_lex;
@@ -1772,20 +1755,17 @@ Event_job_data::compile(THD *thd, MEM_ROOT *mem_root)
17721755
int
17731756
Event_job_data::execute(THD *thd)
17741757
{
1775-
Security_context *save_ctx;
1758+
Security_context save_ctx;
17761759
/* this one is local and not needed after exec */
1777-
Security_context security_ctx;
17781760
int ret= 0;
17791761

17801762
DBUG_ENTER("Event_job_data::execute");
17811763
DBUG_PRINT("info", ("EXECUTING %s.%s", dbname.str, name.str));
17821764

1783-
17841765
if ((ret= compile(thd, NULL)))
17851766
goto done;
17861767

1787-
thd->change_security_context(definer_user, definer_host, dbname,
1788-
&security_ctx, &save_ctx);
1768+
thd->change_security_context(definer_user, definer_host, dbname, &save_ctx);
17891769
/*
17901770
THD::~THD will clean this or if there is DROP DATABASE in the SP then
17911771
it will be free there. It should not point to our buffer which is allocated
@@ -1810,9 +1790,10 @@ Event_job_data::execute(THD *thd)
18101790
ret= -99;
18111791
}
18121792

1813-
thd->restore_security_context(save_ctx);
1793+
thd->restore_security_context(&save_ctx);
18141794
done:
1815-
free_sp();
1795+
thd->end_statement();
1796+
thd->cleanup_after_query();
18161797

18171798
DBUG_PRINT("info", ("EXECUTED %s.%s ret=%d", dbname.str, name.str, ret));
18181799

sql/event_data_objects.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,12 @@ class Event_job_data : public Event_basic
178178

179179
int
180180
execute(THD *thd);
181-
private:
182-
int
183-
get_fake_create_event(THD *thd, String *buf);
184181

185182
int
186183
compile(THD *thd, MEM_ROOT *mem_root);
187-
188-
void
189-
free_sp();
184+
private:
185+
int
186+
get_fake_create_event(THD *thd, String *buf);
190187

191188
Event_job_data(const Event_job_data &); /* Prevent use of these */
192189
void operator=(Event_job_data &);

0 commit comments

Comments
 (0)