Commit 7634f7d6 authored by unknown's avatar unknown

WL #1034 update

- handle crashes where the table definition has been changed
  (different number of fields)


sql/event.cc:
  change the way table is opened
  check whether the number of fields is exact, otherwise report damaged table
sql/event_executor.cc:
  - move around some code
  - use the new way of table opening
sql/event_priv.h:
  - new declaration
sql/event_timed.cc:
  - now 0 is ok
parent 2d11a567
...@@ -188,12 +188,15 @@ event_timed_compare_q(void *vptr, byte* a, byte *b) ...@@ -188,12 +188,15 @@ event_timed_compare_q(void *vptr, byte* a, byte *b)
evex_open_event_table_for_read() evex_open_event_table_for_read()
thd Thread context thd Thread context
lock_type How to lock the table lock_type How to lock the table
table The table pointer
RETURN RETURN
0 Error 1 Cannot lock table
# Pointer to TABLE object 2 The table is corrupted - different number of fields
0 OK
*/ */
TABLE *evex_open_event_table(THD *thd, enum thr_lock_type lock_type) int
evex_open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table)
{ {
TABLE_LIST tables; TABLE_LIST tables;
bool not_used; bool not_used;
...@@ -205,9 +208,17 @@ TABLE *evex_open_event_table(THD *thd, enum thr_lock_type lock_type) ...@@ -205,9 +208,17 @@ TABLE *evex_open_event_table(THD *thd, enum thr_lock_type lock_type)
tables.lock_type= lock_type; tables.lock_type= lock_type;
if (simple_open_n_lock_tables(thd, &tables)) if (simple_open_n_lock_tables(thd, &tables))
DBUG_RETURN(0); DBUG_RETURN(1);
DBUG_RETURN(tables.table); if (tables.table->s->fields != EVEX_FIELD_COUNT)
{
my_error(ER_EVENT_COL_COUNT_DOESNT_MATCH, MYF(0), "mysql", "event");
close_thread_tables(thd);
DBUG_RETURN(2);
}
*table= tables.table;
DBUG_RETURN(0);
} }
...@@ -382,7 +393,7 @@ db_create_event(THD *thd, event_timed *et) ...@@ -382,7 +393,7 @@ db_create_event(THD *thd, event_timed *et)
DBUG_PRINT("info", ("open mysql.event for update")); DBUG_PRINT("info", ("open mysql.event for update"));
if (!(table= evex_open_event_table(thd, TL_WRITE))) if (evex_open_event_table(thd, TL_WRITE, &table))
{ {
my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0)); my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0));
goto err; goto err;
...@@ -491,7 +502,7 @@ db_update_event(THD *thd, event_timed *et, sp_name *new_name) ...@@ -491,7 +502,7 @@ db_update_event(THD *thd, event_timed *et, sp_name *new_name)
DBUG_PRINT("enter", ("rename to: %.*s", new_name->m_name.length, DBUG_PRINT("enter", ("rename to: %.*s", new_name->m_name.length,
new_name->m_name.str)); new_name->m_name.str));
if (!(table= evex_open_event_table(thd, TL_WRITE))) if (evex_open_event_table(thd, TL_WRITE, &table))
{ {
my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0)); my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0));
goto err; goto err;
...@@ -590,7 +601,7 @@ db_find_event(THD *thd, sp_name *name, event_timed **ett, TABLE *tbl) ...@@ -590,7 +601,7 @@ db_find_event(THD *thd, sp_name *name, event_timed **ett, TABLE *tbl)
if (tbl) if (tbl)
table= tbl; table= tbl;
else if (!(table= evex_open_event_table(thd, TL_READ))) else if (evex_open_event_table(thd, TL_READ, &table))
{ {
my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0)); my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0));
ret= EVEX_GENERAL_ERROR; ret= EVEX_GENERAL_ERROR;
...@@ -869,7 +880,7 @@ evex_drop_event(THD *thd, event_timed *et, bool drop_if_exists) ...@@ -869,7 +880,7 @@ evex_drop_event(THD *thd, event_timed *et, bool drop_if_exists)
bool opened; bool opened;
DBUG_ENTER("evex_drop_event"); DBUG_ENTER("evex_drop_event");
if (!(table= evex_open_event_table(thd, TL_WRITE))) if (evex_open_event_table(thd, TL_WRITE, &table))
{ {
my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0)); my_error(ER_EVENT_OPEN_TABLE_FAILED, MYF(0));
goto done; goto done;
......
...@@ -209,13 +209,13 @@ event_executor_main(void *arg) ...@@ -209,13 +209,13 @@ event_executor_main(void *arg)
evex_is_running= true; evex_is_running= true;
VOID(pthread_mutex_unlock(&LOCK_evex_running)); VOID(pthread_mutex_unlock(&LOCK_evex_running));
thd->security_ctx->user= my_strdup("event_scheduler", MYF(0));
if (evex_load_events_from_db(thd)) if (evex_load_events_from_db(thd))
goto err; goto err;
thd->security_ctx->user= my_strdup("event_scheduler", MYF(0));
THD_CHECK_SENTRY(thd);
/* Read queries from the IO/THREAD until this thread is killed */
evex_main_thread_id= thd->thread_id; evex_main_thread_id= thd->thread_id;
sql_print_information("Scheduler thread started"); sql_print_information("Scheduler thread started");
while (!thd->killed) while (!thd->killed)
{ {
...@@ -509,8 +509,11 @@ evex_load_events_from_db(THD *thd) ...@@ -509,8 +509,11 @@ evex_load_events_from_db(THD *thd)
DBUG_ENTER("evex_load_events_from_db"); DBUG_ENTER("evex_load_events_from_db");
if (!(table= evex_open_event_table(thd, TL_READ))) if ((ret= evex_open_event_table(thd, TL_READ, &table)))
{
sql_print_error("Table mysql.event is damaged.");
DBUG_RETURN(SP_OPEN_TABLE_FAILED); DBUG_RETURN(SP_OPEN_TABLE_FAILED);
}
VOID(pthread_mutex_lock(&LOCK_event_arrays)); VOID(pthread_mutex_lock(&LOCK_event_arrays));
......
...@@ -53,8 +53,8 @@ int ...@@ -53,8 +53,8 @@ int
evex_db_find_event_aux(THD *thd, const LEX_STRING dbname, evex_db_find_event_aux(THD *thd, const LEX_STRING dbname,
const LEX_STRING rname, TABLE *table); const LEX_STRING rname, TABLE *table);
TABLE * int
evex_open_event_table(THD *thd, enum thr_lock_type lock_type); evex_open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table);
int int
event_timed_compare_q(void *vptr, byte* a, byte *b); event_timed_compare_q(void *vptr, byte* a, byte *b);
......
...@@ -739,7 +739,7 @@ event_timed::update_fields(THD *thd) ...@@ -739,7 +739,7 @@ event_timed::update_fields(THD *thd)
thd->reset_n_backup_open_tables_state(&backup); thd->reset_n_backup_open_tables_state(&backup);
if (!(table= evex_open_event_table(thd, TL_WRITE))) if (evex_open_event_table(thd, TL_WRITE, &table))
{ {
ret= SP_OPEN_TABLE_FAILED; ret= SP_OPEN_TABLE_FAILED;
goto done; goto done;
......
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