Skip to content

Commit c06c735

Browse files
committed
Fix for bug#22740 Events: Decouple Event_queue from Event_db_repository
This patch implements the idea of the bug report by making Event_queue unaware of Event_db_repository by making a higher level class - Events, which is aware of most of all classes, responsible for passing all data needed for adding/updating/deleting an event to/from the queue. Introduces few new classes : - Event_worker_thread - Event_queue_element_for_exec
1 parent db5c164 commit c06c735

File tree

9 files changed

+404
-368
lines changed

9 files changed

+404
-368
lines changed

sql/event_data_objects.cc

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "event_db_repository.h"
2121
#include "sp_head.h"
2222

23+
/* That's a provisional solution */
24+
extern Event_db_repository events_event_db_repository;
2325

2426
#define EVEX_MAX_INTERVAL_VALUE 1000000000L
2527

@@ -30,6 +32,47 @@ event_change_security_context(THD *thd, LEX_STRING user, LEX_STRING host,
3032
static void
3133
event_restore_security_context(THD *thd, Security_context *backup);
3234

35+
36+
/*
37+
Initiliazes dbname and name of an Event_queue_element_for_exec
38+
object
39+
40+
SYNOPSIS
41+
Event_queue_element_for_exec::init()
42+
43+
RETURN VALUE
44+
FALSE OK
45+
TRUE Error (OOM)
46+
*/
47+
48+
bool
49+
Event_queue_element_for_exec::init(LEX_STRING db, LEX_STRING n)
50+
{
51+
if (!(dbname.str= my_strndup(db.str, dbname.length= db.length, MYF(MY_WME))))
52+
return TRUE;
53+
if (!(name.str= my_strndup(n.str, name.length= n.length, MYF(MY_WME))))
54+
{
55+
my_free((gptr) dbname.str, MYF(0));
56+
return TRUE;
57+
}
58+
return FALSE;
59+
}
60+
61+
62+
/*
63+
Destructor
64+
65+
SYNOPSIS
66+
Event_queue_element_for_exec::~Event_queue_element_for_exec()
67+
*/
68+
69+
Event_queue_element_for_exec::~Event_queue_element_for_exec()
70+
{
71+
my_free((gptr) dbname.str, MYF(0));
72+
my_free((gptr) name.str, MYF(0));
73+
}
74+
75+
3376
/*
3477
Returns a new instance
3578
@@ -743,7 +786,7 @@ Event_timed::~Event_timed()
743786
*/
744787

745788
Event_job_data::Event_job_data()
746-
:thd(NULL), sphead(NULL), sql_mode(0)
789+
:sphead(NULL), sql_mode(0)
747790
{
748791
}
749792

@@ -1239,6 +1282,7 @@ Event_queue_element::compute_next_execution_time()
12391282
DBUG_PRINT("info", ("Dropped: %d", dropped));
12401283
status= Event_queue_element::DISABLED;
12411284
status_changed= TRUE;
1285+
dropped= TRUE;
12421286

12431287
goto ret;
12441288
}
@@ -1446,32 +1490,6 @@ Event_queue_element::mark_last_executed(THD *thd)
14461490
}
14471491

14481492

1449-
/*
1450-
Drops the event
1451-
1452-
SYNOPSIS
1453-
Event_queue_element::drop()
1454-
thd thread context
1455-
1456-
RETURN VALUE
1457-
0 OK
1458-
-1 Cannot open mysql.event
1459-
-2 Cannot find the event in mysql.event (already deleted?)
1460-
1461-
others return code from SE in case deletion of the event row
1462-
failed.
1463-
*/
1464-
1465-
int
1466-
Event_queue_element::drop(THD *thd)
1467-
{
1468-
DBUG_ENTER("Event_queue_element::drop");
1469-
1470-
DBUG_RETURN(Events::get_instance()->
1471-
drop_event(thd, dbname, name, FALSE, TRUE));
1472-
}
1473-
1474-
14751493
/*
14761494
Saves status and last_executed_at to the disk if changed.
14771495
@@ -1503,13 +1521,13 @@ Event_queue_element::update_timing_fields(THD *thd)
15031521

15041522
thd->reset_n_backup_open_tables_state(&backup);
15051523

1506-
if (Events::get_instance()->open_event_table(thd, TL_WRITE, &table))
1524+
if (events_event_db_repository.open_event_table(thd, TL_WRITE, &table))
15071525
{
15081526
ret= TRUE;
15091527
goto done;
15101528
}
15111529
fields= table->field;
1512-
if ((ret= Events::get_instance()->db_repository->
1530+
if ((ret= events_event_db_repository.
15131531
find_named_event(thd, dbname, name, table)))
15141532
goto done;
15151533

sql/event_data_objects.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ class sp_head;
2727
class Sql_alloc;
2828

2929

30+
class Event_queue_element_for_exec
31+
{
32+
public:
33+
Event_queue_element_for_exec(){};
34+
~Event_queue_element_for_exec();
35+
36+
bool
37+
init(LEX_STRING dbname, LEX_STRING name);
38+
39+
LEX_STRING dbname;
40+
LEX_STRING name;
41+
bool dropped;
42+
THD *thd;
43+
44+
private:
45+
/* Prevent use of these */
46+
Event_queue_element_for_exec(const Event_queue_element_for_exec &);
47+
void operator=(Event_queue_element_for_exec &);
48+
};
49+
50+
3051
class Event_basic
3152
{
3253
protected:
@@ -96,9 +117,6 @@ class Event_queue_element : public Event_basic
96117
bool
97118
compute_next_execution_time();
98119

99-
int
100-
drop(THD *thd);
101-
102120
void
103121
mark_last_executed(THD *thd);
104122

@@ -160,7 +178,6 @@ class Event_timed : public Event_queue_element
160178
class Event_job_data : public Event_basic
161179
{
162180
public:
163-
THD *thd;
164181
sp_head *sphead;
165182

166183
LEX_STRING body;

0 commit comments

Comments
 (0)