Commit 0d517461 authored by andrey@lmy004's avatar andrey@lmy004

WL#3337 (Event scheduler new architecture)

More small fixes to the API : use LEX_STRING instead of LEX_STRING* and if error
then return bool(true) instead of error code.
Merged functions. Reduced usage of sp_name.
Fixed a lot of function documentation errors.
Added function documentation wherever needed.
Removed some unused defines and error codes.

Next to come is batch rename of Event_scheduler_ng to Event_scheduler.
parent 2f7555b3
...@@ -111,7 +111,15 @@ a ...@@ -111,7 +111,15 @@ a
800219 800219
drop event non_qualif_ev; drop event non_qualif_ev;
drop table non_qualif; 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 = 2;
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
alter event existant rename to events_test.existant;
ERROR HY000: Same old and new event name
drop event existant;
create table t_event3 (a int, b float); create table t_event3 (a int, b float);
drop event if exists event3; drop event if exists event3;
Warnings: Warnings:
......
create database if not exists events_test; CREATE DATABASE IF NOT EXISTS events_test;
use events_test; USE events_test;
"We use procedure here because its statements won't be logged into the general log" "We use procedure here because its statements won't be logged into the general log"
"If we had used normal select that are logged in different ways depending on whether" "If we had used normal select that are logged in different ways depending on whether"
"the test suite is run in normal mode or with --ps-protocol" "the test suite is run in normal mode or with --ps-protocol"
...@@ -8,18 +8,21 @@ BEGIN ...@@ -8,18 +8,21 @@ BEGIN
SELECT user_host, argument FROM mysql.general_log WHERE argument LIKE '%alabala%'; SELECT user_host, argument FROM mysql.general_log WHERE argument LIKE '%alabala%';
END| END|
"Check General Query Log" "Check General Query Log"
SET GLOBAL event_scheduler=2; CALL select_general_log();
create event log_general on schedule every 1 minute do SELect 'alabala', sleep(1) from dual;
TRUNCATE mysql.general_log;
"1 row, the current statement!"
call select_general_log();
user_host argument user_host argument
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=1;
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" "Wait the scheduler to start"
"Should see 3 rows - the 'SELect' is in the middle. The other two are selects from general_log" "Should see 2 rows - the 'SELECT' is in the middle. The other two are selects from general_log"
call select_general_log(); CALL select_general_log();
user_host argument user_host argument
USER_HOST SELect 'alabala', sleep(1) from dual USER_HOST CREATE EVENT log_general ON SCHEDULE EVERY 1 MINUTE DO SELECT 'alabala', SLEEP(1) FROM DUAL
USER_HOST SELECT 'alabala', SLEEP(1) FROM DUAL
DROP PROCEDURE select_general_log; DROP PROCEDURE select_general_log;
DROP EVENT log_general; DROP EVENT log_general;
SET GLOBAL event_scheduler=2; SET GLOBAL event_scheduler=2;
...@@ -90,4 +93,4 @@ TRUNCATE mysql.slow_log; ...@@ -90,4 +93,4 @@ TRUNCATE mysql.slow_log;
DROP TABLE slow_event_test; DROP TABLE slow_event_test;
SET GLOBAL long_query_time =@old_global_long_query_time; SET GLOBAL long_query_time =@old_global_long_query_time;
SET SESSION long_query_time =@old_session_long_query_time; SET SESSION long_query_time =@old_session_long_query_time;
drop database events_test; DROP DATABASE events_test;
...@@ -105,7 +105,18 @@ create event non_qualif_ev on schedule every 10 minute do insert into non_qualif ...@@ -105,7 +105,18 @@ create event non_qualif_ev on schedule every 10 minute do insert into non_qualif
select * from non_qualif; select * from non_qualif;
drop event non_qualif_ev; drop event non_qualif_ev;
drop table non_qualif; 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 = 2;
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;
--error ER_EVENT_SAME_NAME
alter event existant rename to events_test.existant;
drop event existant;
create table t_event3 (a int, b float); create table t_event3 (a int, b float);
drop event if exists event3; drop event if exists event3;
......
# Can't test with embedded server that doesn't support grants # Can't test with embedded server that doesn't support grants
-- source include/not_embedded.inc -- source include/not_embedded.inc
create database if not exists events_test; CREATE DATABASE IF NOT EXISTS events_test;
use events_test; USE events_test;
--echo "We use procedure here because its statements won't be logged into the general log" --echo "We use procedure here because its statements won't be logged into the general log"
--echo "If we had used normal select that are logged in different ways depending on whether" --echo "If we had used normal select that are logged in different ways depending on whether"
--echo "the test suite is run in normal mode or with --ps-protocol" --echo "the test suite is run in normal mode or with --ps-protocol"
...@@ -13,18 +13,16 @@ BEGIN ...@@ -13,18 +13,16 @@ BEGIN
END| END|
delimiter ;| delimiter ;|
--echo "Check General Query Log" --echo "Check General Query Log"
SET GLOBAL event_scheduler=2;
create event log_general on schedule every 1 minute do SELect 'alabala', sleep(1) from dual;
TRUNCATE mysql.general_log;
--echo "1 row, the current statement!"
--replace_column 1 USER_HOST --replace_column 1 USER_HOST
call select_general_log(); CALL select_general_log();
SET GLOBAL event_scheduler=1; SET GLOBAL event_scheduler=1;
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" --echo "Wait the scheduler to start"
--echo "Should see 3 rows - the 'SELect' is in the middle. The other two are selects from general_log" --sleep 1.5
--sleep 0.7 --echo "Should see 2 rows - the 'SELECT' is in the middle. The other two are selects from general_log"
--replace_column 1 USER_HOST --replace_column 1 USER_HOST
call select_general_log(); CALL select_general_log();
DROP PROCEDURE select_general_log; DROP PROCEDURE select_general_log;
DROP EVENT log_general; DROP EVENT log_general;
SET GLOBAL event_scheduler=2; SET GLOBAL event_scheduler=2;
...@@ -102,4 +100,4 @@ DROP TABLE slow_event_test; ...@@ -102,4 +100,4 @@ DROP TABLE slow_event_test;
SET GLOBAL long_query_time =@old_global_long_query_time; SET GLOBAL long_query_time =@old_global_long_query_time;
SET SESSION long_query_time =@old_session_long_query_time; SET SESSION long_query_time =@old_session_long_query_time;
drop database events_test; DROP DATABASE events_test;
This diff is collapsed.
...@@ -17,45 +17,16 @@ ...@@ -17,45 +17,16 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#define EVEX_OK 0 #define EVEX_GET_FIELD_FAILED -2
#define EVEX_KEY_NOT_FOUND -1 #define EVEX_COMPILE_ERROR -3
#define EVEX_OPEN_TABLE_FAILED -2 #define EVEX_GENERAL_ERROR -4
#define EVEX_WRITE_ROW_FAILED -3 #define EVEX_BAD_PARAMS -5
#define EVEX_DELETE_ROW_FAILED -4 #define EVEX_MICROSECOND_UNSUP -6
#define EVEX_GET_FIELD_FAILED -5
#define EVEX_PARSE_ERROR -6
#define EVEX_INTERNAL_ERROR -7
#define EVEX_NO_DB_ERROR -8
#define EVEX_COMPILE_ERROR -19
#define EVEX_GENERAL_ERROR -20
#define EVEX_BAD_IDENTIFIER -21
#define EVEX_BODY_TOO_LONG -22
#define EVEX_BAD_PARAMS -23
#define EVEX_NOT_RUNNING -24
#define EVEX_MICROSECOND_UNSUP -25
#define EVEX_CANT_KILL -26
#define EVENT_EXEC_NO_MORE (1L << 0)
#define EVENT_NOT_USED (1L << 1)
#define EVENT_FREE_WHEN_FINISHED (1L << 2)
#define EVENT_EXEC_STARTED 0
#define EVENT_EXEC_ALREADY_EXEC 1
#define EVENT_EXEC_CANT_FORK 2
class sp_head; class sp_head;
class Sql_alloc; class Sql_alloc;
class Event_basic;
/* Compares only the schema part of the identifier */
bool
event_basic_db_equal( LEX_STRING *db, Event_basic *et);
/* Compares the whole identifier*/
bool
event_basic_identifier_equal(LEX_STRING db, LEX_STRING name, Event_basic *b);
class Event_basic class Event_basic
{ {
...@@ -206,7 +177,7 @@ public: ...@@ -206,7 +177,7 @@ public:
load_from_row(TABLE *table); load_from_row(TABLE *table);
int int
execute(THD *thd, MEM_ROOT *mem_root); execute(THD *thd);
private: private:
int int
get_fake_create_event(THD *thd, String *buf); get_fake_create_event(THD *thd, String *buf);
...@@ -274,7 +245,7 @@ public: ...@@ -274,7 +245,7 @@ public:
private: private:
int void
init_definer(THD *thd); init_definer(THD *thd);
void void
...@@ -303,4 +274,13 @@ private: ...@@ -303,4 +274,13 @@ private:
}; };
/* Compares only the schema part of the identifier */
bool
event_basic_db_equal(LEX_STRING db, Event_basic *et);
/* Compares the whole identifier*/
bool
event_basic_identifier_equal(LEX_STRING db, LEX_STRING name, Event_basic *b);
#endif /* _EVENT_DATA_OBJECTS_H_ */ #endif /* _EVENT_DATA_OBJECTS_H_ */
This diff is collapsed.
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#define EVEX_OPEN_TABLE_FAILED -1
enum enum_events_table_field enum enum_events_table_field
{ {
ET_FIELD_DB = 0, ET_FIELD_DB = 0,
...@@ -60,24 +62,23 @@ public: ...@@ -60,24 +62,23 @@ public:
create_event(THD *thd, Event_parse_data *parse_data, my_bool create_if_not, create_event(THD *thd, Event_parse_data *parse_data, my_bool create_if_not,
uint *rows_affected); uint *rows_affected);
int bool
update_event(THD *thd, Event_parse_data *parse_data, sp_name *new_name); update_event(THD *thd, Event_parse_data *parse_data, LEX_STRING *new_dbname,
LEX_STRING *new_name);
int bool
drop_event(THD *thd, LEX_STRING db, LEX_STRING name, bool drop_if_exists, drop_event(THD *thd, LEX_STRING db, LEX_STRING name, bool drop_if_exists,
uint *rows_affected); uint *rows_affected);
int int
drop_schema_events(THD *thd, LEX_STRING schema); drop_schema_events(THD *thd, LEX_STRING schema);
int bool
find_event(THD *thd, LEX_STRING dbname, LEX_STRING name, Event_basic *et); find_named_event(THD *thd, LEX_STRING db, LEX_STRING name, TABLE *table);
int bool
load_named_event(THD *thd, LEX_STRING dbname, LEX_STRING name, Event_basic *et); load_named_event(THD *thd, LEX_STRING dbname, LEX_STRING name, Event_basic *et);
int
find_event_by_name(THD *thd, LEX_STRING db, LEX_STRING name, TABLE *table);
int int
open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table); open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table);
......
This diff is collapsed.
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
class sp_name;
class Event_basic; class Event_basic;
class Event_db_repository; class Event_db_repository;
class Event_job_data; class Event_job_data;
...@@ -57,31 +56,28 @@ public: ...@@ -57,31 +56,28 @@ public:
void void
drop_schema_events(THD *thd, LEX_STRING schema); drop_schema_events(THD *thd, LEX_STRING schema);
uint
events_count();
static bool static bool
check_system_tables(THD *thd); check_system_tables(THD *thd);
void void
recalculate_activation_times(THD *thd); recalculate_activation_times(THD *thd);
Event_job_data * bool
get_top_for_execution_if_time(THD *thd, time_t now, struct timespec *abstime); get_top_for_execution_if_time(THD *thd, time_t now, Event_job_data **job_data,
struct timespec *abstime);
bool bool
dump_internal_status(THD *thd); dump_internal_status(THD *thd);
protected: protected:
Event_queue_element * Event_queue_element *
find_event(LEX_STRING db, LEX_STRING name, bool remove_from_q); find_n_remove_event(LEX_STRING db, LEX_STRING name);
int int
load_events_from_db(THD *thd); load_events_from_db(THD *thd);
void void
drop_matching_events(THD *thd, LEX_STRING pattern, drop_matching_events(THD *thd, LEX_STRING pattern,
bool (*)(LEX_STRING *, Event_basic *)); bool (*)(LEX_STRING, Event_basic *));
void void
empty_queue(); empty_queue();
...@@ -93,9 +89,12 @@ protected: ...@@ -93,9 +89,12 @@ protected:
uint mutex_last_locked_at_line; uint mutex_last_locked_at_line;
uint mutex_last_unlocked_at_line; uint mutex_last_unlocked_at_line;
uint mutex_last_attempted_lock_at_line;
const char* mutex_last_locked_in_func; const char* mutex_last_locked_in_func;
const char* mutex_last_unlocked_in_func; const char* mutex_last_unlocked_in_func;
const char* mutex_last_attempted_lock_in_func;
bool mutex_queue_data_locked; bool mutex_queue_data_locked;
bool mutex_queue_data_attempting_lock;
/* helper functions for working with mutexes & conditionals */ /* helper functions for working with mutexes & conditionals */
void void
......
...@@ -176,6 +176,7 @@ deinit_event_thread(THD *thd) ...@@ -176,6 +176,7 @@ deinit_event_thread(THD *thd)
my_thread_end(); my_thread_end();
} }
/* /*
Function that executes the scheduler, Function that executes the scheduler,
...@@ -271,7 +272,7 @@ event_worker_ng_thread(void *arg) ...@@ -271,7 +272,7 @@ event_worker_ng_thread(void *arg)
thd->enable_slow_log= TRUE; thd->enable_slow_log= TRUE;
ret= event->execute(thd, thd->mem_root); ret= event->execute(thd);
evex_print_warnings(thd, event); evex_print_warnings(thd, event);
...@@ -506,8 +507,13 @@ Event_scheduler_ng::run(THD *thd) ...@@ -506,8 +507,13 @@ Event_scheduler_ng::run(THD *thd)
{ {
thd->end_time(); thd->end_time();
/* Gets a minimized version */ /* Gets a minimized version */
job_data= queue-> if (queue->get_top_for_execution_if_time(thd, thd->query_start(),
get_top_for_execution_if_time(thd, thd->query_start(), &abstime); &job_data, &abstime))
{
sql_print_information("SCHEDULER: Serious error during getting next"
" event to execute. Stopping.");
break;
}
DBUG_PRINT("info", ("get_top returned job_data=0x%lx now=%d " DBUG_PRINT("info", ("get_top returned job_data=0x%lx now=%d "
"abs_time.tv_sec=%d", "abs_time.tv_sec=%d",
......
...@@ -41,10 +41,6 @@ ...@@ -41,10 +41,6 @@
- Add logging to file - Add logging to file
Warning:
- For now parallel execution is not possible because the same sp_head cannot
be executed few times!!! There is still no lock attached to particular
event.
*/ */
...@@ -84,18 +80,14 @@ ulong Events::opt_event_scheduler= 2; ...@@ -84,18 +80,14 @@ ulong Events::opt_event_scheduler= 2;
SYNOPSIS SYNOPSIS
sortcmp_lex_string() sortcmp_lex_string()
s First LEX_STRING
s - first LEX_STRING t Second LEX_STRING
t - second LEX_STRING cs Charset
cs - charset
RETURN VALUE RETURN VALUE
-1 - s < t -1 s < t
0 - s == t 0 s == t
1 - s > t 1 s > t
Notes
TIME.second_part is not considered during comparison
*/ */
int sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs) int sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs)
...@@ -104,6 +96,7 @@ int sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs) ...@@ -104,6 +96,7 @@ int sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs)
(uchar *) t.str,t.length, 0); (uchar *) t.str,t.length, 0);
} }
/* /*
Accessor for the singleton instance. Accessor for the singleton instance.
...@@ -131,13 +124,13 @@ Events::get_instance() ...@@ -131,13 +124,13 @@ Events::get_instance()
SYNOPSIS SYNOPSIS
Events::reconstruct_interval_expression() Events::reconstruct_interval_expression()
buf - preallocated String buffer to add the value to buf Preallocated String buffer to add the value to
interval - the interval type (for instance YEAR_MONTH) interval The interval type (for instance YEAR_MONTH)
expression - the value in the lowest entity expression The value in the lowest entity
RETURN VALUE RETURN VALUE
0 - OK 0 OK
1 - Error 1 Error
*/ */
int int
...@@ -256,7 +249,7 @@ common_1_lev_code: ...@@ -256,7 +249,7 @@ common_1_lev_code:
/* /*
Open mysql.event table for read Opens mysql.event table with specified lock
SYNOPSIS SYNOPSIS
Events::open_event_table() Events::open_event_table()
...@@ -283,11 +276,10 @@ Events::open_event_table(THD *thd, enum thr_lock_type lock_type, ...@@ -283,11 +276,10 @@ Events::open_event_table(THD *thd, enum thr_lock_type lock_type,
SYNOPSIS SYNOPSIS
Events::create_event() Events::create_event()
thd THD thd [in] THD
et event's data et [in] Event's data from parsing stage
create_options Options specified when in the query. We are if_not_exists [in] Whether IF NOT EXISTS was specified in the DDL
interested whether there is IF NOT EXISTS rows_affected [out] How many rows were affected
rows_affected How many rows were affected
RETURN VALUE RETURN VALUE
0 OK 0 OK
...@@ -328,9 +320,10 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, bool if_not_exists, ...@@ -328,9 +320,10 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, bool if_not_exists,
SYNOPSIS SYNOPSIS
Events::update_event() Events::update_event()
thd THD thd [in] THD
et Event's data from parsing stage et [in] Event's data from parsing stage
new_name Set in case of RENAME TO. rename_to [in] Set in case of RENAME TO.
rows_affected [out] How many rows were affected.
RETURN VALUE RETURN VALUE
0 OK 0 OK
...@@ -338,26 +331,25 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, bool if_not_exists, ...@@ -338,26 +331,25 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, bool if_not_exists,
NOTES NOTES
et contains data about dbname and event name. et contains data about dbname and event name.
new_name is the new name of the event, if not null (this means new_name is the new name of the event, if not null this means
that RENAME TO was specified in the query) that RENAME TO was specified in the query
*/ */
int int
Events::update_event(THD *thd, Event_parse_data *parse_data, sp_name *new_name, Events::update_event(THD *thd, Event_parse_data *parse_data, sp_name *rename_to,
uint *rows_affected) uint *rows_affected)
{ {
int ret; int ret;
DBUG_ENTER("Events::update_event"); DBUG_ENTER("Events::update_event");
LEX_STRING *new_dbname= rename_to? &rename_to->m_db: NULL;
LEX_STRING *new_name= rename_to? &rename_to->m_name: NULL;
pthread_mutex_lock(&LOCK_event_metadata); pthread_mutex_lock(&LOCK_event_metadata);
/* On error conditions my_error() is called so no need to handle here */ /* On error conditions my_error() is called so no need to handle here */
if (!(ret= db_repository->update_event(thd, parse_data, new_name))) if (!(ret= db_repository->update_event(thd, parse_data, new_dbname, new_name)))
{ {
if ((ret= event_queue->update_event(thd, if ((ret= event_queue->update_event(thd, parse_data->dbname,
parse_data->dbname, parse_data->name, new_dbname, new_name)))
parse_data->name,
new_name? &new_name->m_db: NULL,
new_name? &new_name->m_name: NULL)))
{ {
DBUG_ASSERT(ret == OP_LOAD_ERROR); DBUG_ASSERT(ret == OP_LOAD_ERROR);
my_error(ER_EVENT_MODIFY_QUEUE_ERROR, MYF(0)); my_error(ER_EVENT_MODIFY_QUEUE_ERROR, MYF(0));
...@@ -374,16 +366,16 @@ Events::update_event(THD *thd, Event_parse_data *parse_data, sp_name *new_name, ...@@ -374,16 +366,16 @@ Events::update_event(THD *thd, Event_parse_data *parse_data, sp_name *new_name,
SYNOPSIS SYNOPSIS
Events::drop_event() Events::drop_event()
thd THD thd [in] THD
dbname Event's schema dbname [in] Event's schema
name Event's name name [in] Event's name
if_exists When set and the event does not exist => warning onto if_exists [in] When set and the event does not exist =>
the stack warning onto the stack
rows_affected Affected number of rows is returned heres rows_affected [out] Affected number of rows is returned here
only_from_disk Whether to remove the event from the queue too. In case only_from_disk [in] Whether to remove the event from the queue too.
of Event_job_data::drop() it's needed to do only disk In case of Event_job_data::drop() it's needed to
drop because Event_queue will handle removal from memory do only disk drop because Event_queue will handle
queue. removal from memory queue.
RETURN VALUE RETURN VALUE
0 OK 0 OK
...@@ -429,7 +421,7 @@ Events::drop_schema_events(THD *thd, char *db) ...@@ -429,7 +421,7 @@ Events::drop_schema_events(THD *thd, char *db)
int ret= 0; int ret= 0;
LEX_STRING db_lex= {db, strlen(db)}; LEX_STRING db_lex= {db, strlen(db)};
DBUG_ENTER("evex_drop_db_events"); DBUG_ENTER("Events::drop_schema_events");
DBUG_PRINT("enter", ("dropping events from %s", db)); DBUG_PRINT("enter", ("dropping events from %s", db));
pthread_mutex_lock(&LOCK_event_metadata); pthread_mutex_lock(&LOCK_event_metadata);
...@@ -455,24 +447,22 @@ Events::drop_schema_events(THD *thd, char *db) ...@@ -455,24 +447,22 @@ Events::drop_schema_events(THD *thd, char *db)
*/ */
int int
Events::show_create_event(THD *thd, sp_name *spn) Events::show_create_event(THD *thd, LEX_STRING dbname, LEX_STRING name)
{ {
CHARSET_INFO *scs= system_charset_info;
int ret; int ret;
Event_timed *et= new Event_timed(); Event_timed *et= new Event_timed();
Open_tables_state backup;
DBUG_ENTER("Events::show_create_event"); DBUG_ENTER("Events::show_create_event");
DBUG_PRINT("enter", ("name: %*s", spn->m_name.length, spn->m_name.str)); DBUG_PRINT("enter", ("name: %s@%s", dbname.str, name.str));
thd->reset_n_backup_open_tables_state(&backup); ret= db_repository->load_named_event(thd, dbname, name, et);
ret= db_repository->find_event(thd, spn->m_db, spn->m_name, et);
thd->restore_backup_open_tables_state(&backup);
if (!ret) if (!ret)
{ {
Protocol *protocol= thd->protocol; Protocol *protocol= thd->protocol;
char show_str_buf[768]; char show_str_buf[10 * STRING_BUFFER_USUAL_SIZE];
String show_str(show_str_buf, sizeof(show_str_buf), system_charset_info); String show_str(show_str_buf, sizeof(show_str_buf), scs);
List<Item> field_list; List<Item> field_list;
byte *sql_mode_str; byte *sql_mode_str;
ulong sql_mode_len=0; ulong sql_mode_len=0;
...@@ -491,18 +481,19 @@ Events::show_create_event(THD *thd, sp_name *spn) ...@@ -491,18 +481,19 @@ Events::show_create_event(THD *thd, sp_name *spn)
field_list.push_back(new Item_empty_string("sql_mode", sql_mode_len)); field_list.push_back(new Item_empty_string("sql_mode", sql_mode_len));
field_list.push_back(new Item_empty_string("Create Event", field_list.
show_str.length())); push_back(new Item_empty_string("Create Event", show_str.length()));
if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
Protocol::SEND_EOF)) Protocol::SEND_EOF))
goto err; goto err;
protocol->prepare_for_resend(); protocol->prepare_for_resend();
protocol->store(et->name.str, et->name.length, system_charset_info); protocol->store(et->name.str, et->name.length, scs);
protocol->store((char*) sql_mode_str, sql_mode_len, system_charset_info); protocol->store((char*) sql_mode_str, sql_mode_len, scs);
protocol->store(show_str.c_ptr(), show_str.length(), system_charset_info); protocol->store(show_str.c_ptr(), show_str.length(), scs);
ret= protocol->write(); ret= protocol->write();
send_eof(thd); send_eof(thd);
} }
...@@ -546,7 +537,8 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */) ...@@ -546,7 +537,8 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */)
DBUG_RETURN(1); DBUG_RETURN(1);
db= thd->lex->select_lex.db; db= thd->lex->select_lex.db;
} }
DBUG_RETURN(get_instance()->db_repository->fill_schema_events(thd, tables, db)); DBUG_RETURN(get_instance()->db_repository->
fill_schema_events(thd, tables, db));
} }
...@@ -561,14 +553,12 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */) ...@@ -561,14 +553,12 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */)
RETURN VALUE RETURN VALUE
0 OK 0 OK
1 Error 1 Error in case the scheduler can't start
*/ */
int int
Events::init() Events::init()
{ {
int ret= 0;
Event_db_repository *db_repo;
DBUG_ENTER("Events::init"); DBUG_ENTER("Events::init");
event_queue->init_queue(db_repository, scheduler_ng); event_queue->init_queue(db_repository, scheduler_ng);
scheduler_ng->init_scheduler(event_queue); scheduler_ng->init_scheduler(event_queue);
...@@ -653,7 +643,10 @@ Events::destroy_mutexes() ...@@ -653,7 +643,10 @@ Events::destroy_mutexes()
/* /*
Proxy for Event_scheduler::dump_internal_status Dumps the internal status of the scheduler and the memory cache
into a table with two columns - Name & Value. Different properties
which could be useful for debugging for instance deadlocks are
returned.
SYNOPSIS SYNOPSIS
Events::dump_internal_status() Events::dump_internal_status()
......
...@@ -81,7 +81,7 @@ public: ...@@ -81,7 +81,7 @@ public:
uint *rows_affected); uint *rows_affected);
int int
update_event(THD *thd, Event_parse_data *parse_data, sp_name *new_name, update_event(THD *thd, Event_parse_data *parse_data, sp_name *rename_to,
uint *rows_affected); uint *rows_affected);
int int
...@@ -95,7 +95,7 @@ public: ...@@ -95,7 +95,7 @@ public:
open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table); open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table);
int int
show_create_event(THD *thd, sp_name *spn); show_create_event(THD *thd, LEX_STRING dbname, LEX_STRING name);
/* Needed for both SHOW CREATE EVENT and INFORMATION_SCHEMA */ /* Needed for both SHOW CREATE EVENT and INFORMATION_SCHEMA */
static int static int
......
...@@ -3926,7 +3926,8 @@ end_with_restore_list: ...@@ -3926,7 +3926,8 @@ end_with_restore_list:
} }
if (lex->sql_command == SQLCOM_SHOW_CREATE_EVENT) if (lex->sql_command == SQLCOM_SHOW_CREATE_EVENT)
res= Events::get_instance()->show_create_event(thd, lex->spname); res= Events::get_instance()->show_create_event(thd, lex->spname->m_db,
lex->spname->m_name);
else else
{ {
uint affected= 1; uint affected= 1;
......
...@@ -1447,7 +1447,8 @@ ev_sql_stmt: ...@@ -1447,7 +1447,8 @@ ev_sql_stmt:
LEX *lex=Lex; LEX *lex=Lex;
// return back to the original memory root ASAP // return back to the original memory root ASAP
lex->sphead->init_strings(YYTHD, lex, NULL); lex->sphead->init_strings(YYTHD, lex,
Lex->event_parse_data->identifier);
lex->sphead->restore_thd_mem_root(YYTHD); lex->sphead->restore_thd_mem_root(YYTHD);
lex->sp_chistics.suid= SP_IS_SUID;//always the definer! lex->sp_chistics.suid= SP_IS_SUID;//always the definer!
......
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