Skip to content

Commit 5d626c5

Browse files
WL#3337 (Event scheduler new architecture)
Post-review fixes. Mostly whitespace, int-to-bool return value, fixed comments
1 parent 5b2608d commit 5d626c5

17 files changed

Lines changed: 469 additions & 457 deletions

sql/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.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 \
107107
sp_cache.cc parse_file.cc sql_trigger.cc \
108-
event_scheduler.cc events.cc event_data_objects.cc \
109-
event_queue.cc event_db_repository.cc \
108+
event_scheduler.cc event_data_objects.cc \
109+
event_queue.cc event_db_repository.cc events.cc \
110110
sql_plugin.cc sql_binlog.cc \
111111
sql_builtin.cc sql_tablespace.cc partition_info.cc
112112

sql/event_data_objects.cc

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,17 @@ Event_parse_data::new_instance(THD *thd)
5959
*/
6060

6161
Event_parse_data::Event_parse_data()
62+
:on_completion(ON_COMPLETION_DROP), status(ENABLED),
63+
item_starts(NULL), item_ends(NULL), item_execute_at(NULL),
64+
starts_null(TRUE), ends_null(TRUE), execute_at_null(TRUE),
65+
item_expression(NULL), expression(0)
6266
{
6367
DBUG_ENTER("Event_parse_data::Event_parse_data");
6468

65-
item_execute_at= item_expression= item_starts= item_ends= NULL;
66-
status= ENABLED;
67-
on_completion= ON_COMPLETION_DROP;
68-
expression= 0;
69-
7069
/* Actually in the parser STARTS is always set */
7170
set_zero_time(&starts, MYSQL_TIMESTAMP_DATETIME);
7271
set_zero_time(&ends, MYSQL_TIMESTAMP_DATETIME);
7372
set_zero_time(&execute_at, MYSQL_TIMESTAMP_DATETIME);
74-
starts_null= ends_null= execute_at_null= TRUE;
7573

7674
body.str= comment.str= NULL;
7775
body.length= comment.length= 0;
@@ -161,7 +159,7 @@ Event_parse_data::init_body(THD *thd)
161159
*/
162160
if ((*(body_end - 1) == '*') && (*body_end == '/'))
163161
{
164-
DBUG_PRINT("info", ("consumend one '*" "/' comment in the query '%s'",
162+
DBUG_PRINT("info", ("consumend one '*" "/' comment in the query '%s'",
165163
body_begin));
166164
body.length-= 2;
167165
body_end-= 2;
@@ -217,7 +215,7 @@ Event_parse_data::init_execute_at(THD *thd)
217215
DBUG_ASSERT(starts_null && ends_null);
218216

219217
/* let's check whether time is in the past */
220-
thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp,
218+
thd->variables.time_zone->gmt_sec_to_TIME(&time_tmp,
221219
(my_time_t) thd->query_start());
222220

223221
if ((not_used= item_execute_at->get_date(&ltime, TIME_NO_ZERO_DATE)))
@@ -736,8 +734,8 @@ Event_timed::~Event_timed()
736734
Event_job_data::Event_job_data()
737735
*/
738736

739-
Event_job_data::Event_job_data():
740-
thd(NULL), sphead(NULL), sql_mode(0)
737+
Event_job_data::Event_job_data()
738+
:thd(NULL), sphead(NULL), sql_mode(0)
741739
{
742740
}
743741

@@ -1073,7 +1071,7 @@ bool get_next_time(TIME *next, TIME *start, TIME *time_now, TIME *last_exec,
10731071
{
10741072
longlong seconds_diff;
10751073
long microsec_diff;
1076-
1074+
10771075
if (calc_time_diff(time_now, start, 1, &seconds_diff, &microsec_diff))
10781076
{
10791077
DBUG_PRINT("error", ("negative difference"));
@@ -1115,14 +1113,16 @@ bool get_next_time(TIME *next, TIME *start, TIME *time_now, TIME *last_exec,
11151113
interval.month= (diff_months / months)*months;
11161114
/*
11171115
Check if the same month as last_exec (always set - prerequisite)
1118-
An event happens at most once per month so there is no way to schedule
1119-
it two times for the current month. This saves us from two calls to
1120-
date_add_interval() if the event was just executed. But if the scheduler
1121-
is started and there was at least 1 scheduled date skipped this one does
1122-
not help and two calls to date_add_interval() will be done, which is a
1123-
bit more expensive but compared to the rareness of the case is neglectable.
1116+
An event happens at most once per month so there is no way to
1117+
schedule it two times for the current month. This saves us from two
1118+
calls to date_add_interval() if the event was just executed. But if
1119+
the scheduler is started and there was at least 1 scheduled date
1120+
skipped this one does not help and two calls to date_add_interval()
1121+
will be done, which is a bit more expensive but compared to the
1122+
rareness of the case is neglectable.
11241123
*/
1125-
if (time_now->year==last_exec->year && time_now->month==last_exec->month)
1124+
if (time_now->year == last_exec->year &&
1125+
time_now->month == last_exec->month)
11261126
interval.month+= months;
11271127

11281128
tmp= *start;
@@ -1289,7 +1289,7 @@ Event_queue_element::compute_next_execution_time()
12891289
}
12901290
goto ret;
12911291
}
1292-
else if (starts_null && ends_null)
1292+
else if (starts_null && ends_null)
12931293
{
12941294
/* starts is always set, so this is a dead branch !! */
12951295
DBUG_PRINT("info", ("Neither STARTS nor ENDS are set"));
@@ -1333,7 +1333,7 @@ Event_queue_element::compute_next_execution_time()
13331333

13341334
{
13351335
TIME next_exec;
1336-
if (get_next_time(&next_exec, &starts, &time_now,
1336+
if (get_next_time(&next_exec, &starts, &time_now,
13371337
last_executed.year? &last_executed:&starts,
13381338
expression, interval))
13391339
goto err;
@@ -1454,7 +1454,8 @@ Event_queue_element::drop(THD *thd)
14541454
14551455
RETURN VALUE
14561456
FALSE OK
1457-
TRUE Error while opening mysql.event for writing or during write on disk
1457+
TRUE Error while opening mysql.event for writing or during
1458+
write on disk
14581459
*/
14591460

14601461
bool
@@ -1645,9 +1646,9 @@ Event_job_data::execute(THD *thd)
16451646
event_change_security_context(thd, definer_user, definer_host, dbname,
16461647
&save_ctx);
16471648
/*
1648-
THD::~THD will clean this or if there is DROP DATABASE in the SP then
1649-
it will be free there. It should not point to our buffer which is allocated
1650-
on a mem_root.
1649+
THD::~THD will clean this or if there is DROP DATABASE in the
1650+
SP then it will be free there. It should not point to our buffer
1651+
which is allocated on a mem_root.
16511652
*/
16521653
thd->db= my_strdup(dbname.str, MYF(0));
16531654
thd->db_length= dbname.length;
@@ -1719,7 +1720,6 @@ Event_job_data::compile(THD *thd, MEM_ROOT *mem_root)
17191720

17201721
switch (get_fake_create_event(thd, &show_create)) {
17211722
case EVEX_MICROSECOND_UNSUP:
1722-
sql_print_error("Scheduler");
17231723
DBUG_RETURN(EVEX_MICROSECOND_UNSUP);
17241724
case 0:
17251725
break;
@@ -1769,7 +1769,8 @@ Event_job_data::compile(THD *thd, MEM_ROOT *mem_root)
17691769
Free lex associated resources
17701770
QQ: Do we really need all this stuff here?
17711771
*/
1772-
sql_print_error("error during compile of %s.%s or thd->is_fatal_error=%d",
1772+
sql_print_error("SCHEDULER: Error during compilation of %s.%s or "
1773+
"thd->is_fatal_error=%d",
17731774
dbname.str, name.str, thd->is_fatal_error);
17741775

17751776
lex.unit.cleanup();
@@ -1832,10 +1833,13 @@ event_basic_db_equal(LEX_STRING db, Event_basic *et)
18321833

18331834

18341835
/*
1835-
Checks whether two events are equal by identifiers
1836+
Checks whether an event has equal `db` and `name`
18361837
18371838
SYNOPSIS
18381839
event_basic_identifier_equal()
1840+
db Schema
1841+
name Name
1842+
et The event object
18391843
18401844
RETURN VALUE
18411845
TRUE Equal
@@ -1851,15 +1855,16 @@ event_basic_identifier_equal(LEX_STRING db, LEX_STRING name, Event_basic *b)
18511855

18521856

18531857
/*
1854-
Switches the security context
1858+
Switches the security context.
1859+
18551860
SYNOPSIS
18561861
event_change_security_context()
18571862
thd Thread
18581863
user The user
18591864
host The host of the user
18601865
db The schema for which the security_ctx will be loaded
18611866
backup Where to store the old context
1862-
1867+
18631868
RETURN VALUE
18641869
FALSE OK
18651870
TRUE Error (generates error too)
@@ -1887,7 +1892,8 @@ event_change_security_context(THD *thd, LEX_STRING user, LEX_STRING host,
18871892

18881893

18891894
/*
1890-
Restores the security context
1895+
Restores the security context.
1896+
18911897
SYNOPSIS
18921898
event_restore_security_context()
18931899
thd Thread

sql/event_data_objects.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Event_basic
3737
LEX_STRING dbname;
3838
LEX_STRING name;
3939
LEX_STRING definer;// combination of user and host
40-
40+
4141
Event_basic();
4242
virtual ~Event_basic();
4343

@@ -90,7 +90,7 @@ class Event_queue_element : public Event_basic
9090

9191
Event_queue_element();
9292
virtual ~Event_queue_element();
93-
93+
9494
virtual int
9595
load_from_row(TABLE *table);
9696

@@ -187,7 +187,7 @@ class Event_job_data : public Event_basic
187187
int
188188
get_fake_create_event(THD *thd, String *buf);
189189

190-
Event_job_data(const Event_job_data &); /* Prevent use of these */
190+
Event_job_data(const Event_job_data &); /* Prevent use of these */
191191
void operator=(Event_job_data &);
192192
};
193193

@@ -237,7 +237,7 @@ class Event_parse_data : public Sql_alloc
237237
new_instance(THD *thd);
238238

239239
bool
240-
check_parse_data(THD *);
240+
check_parse_data(THD *thd);
241241

242242
void
243243
init_body(THD *thd);

0 commit comments

Comments
 (0)