Commit f133a923 authored by unknown's avatar unknown

WL 1034 update

(pre-push cleanups removing debugging code)


sql/event.cc:
  - comment
  - fix 80 cols
  - fix a crash when dropping a running event (after it has finished
    its work because the memory got freed in remove_from_cache but the event
    was still running)
sql/event.h:
  - add new method
sql/event_executor.cc:
  - remove printf-s
  - fix 80cols
  - fix message
parent f3aea476
......@@ -100,13 +100,17 @@ my_time_compare(TIME *a, TIME *b)
}
inline int
int
event_timed_compare(event_timed *a, event_timed *b)
{
return my_time_compare(&a->execute_at, &b->execute_at);
}
/*
Callback for the prio queue
*/
int
event_timed_compare_q(void *vptr, byte* a, byte *b)
{
......@@ -244,14 +248,11 @@ evex_fill_row(THD *thd, TABLE *table, event_timed *et, my_bool is_update)
store(et->name.str, et->name.length, system_charset_info))
goto trunc_err;
table->field[EVEX_FIELD_ON_COMPLETION]->set_notnull();
// both ON_COMPLETION and STATUS are NOT NULL thus not calling set_notnull()
table->field[EVEX_FIELD_ON_COMPLETION]->store((longlong)et->on_completion);
table->field[EVEX_FIELD_STATUS]->set_notnull();
table->field[EVEX_FIELD_STATUS]->store((longlong)et->status);
// et->status_changed= false;
// ToDo: Andrey. How to use users current charset?
if (et->body.str)
if (table->field[field_num= EVEX_FIELD_BODY]->
store(et->body.str, et->body.length, system_charset_info))
......@@ -260,13 +261,15 @@ evex_fill_row(THD *thd, TABLE *table, event_timed *et, my_bool is_update)
if (et->starts.year)
{
table->field[EVEX_FIELD_STARTS]->set_notnull();// set NULL flag to OFF
table->field[EVEX_FIELD_STARTS]->store_time(&et->starts, MYSQL_TIMESTAMP_DATETIME);
table->field[EVEX_FIELD_STARTS]->
store_time(&et->starts, MYSQL_TIMESTAMP_DATETIME);
}
if (et->ends.year)
{
table->field[EVEX_FIELD_ENDS]->set_notnull();
table->field[EVEX_FIELD_ENDS]->store_time(&et->ends, MYSQL_TIMESTAMP_DATETIME);
table->field[EVEX_FIELD_ENDS]->
store_time(&et->ends, MYSQL_TIMESTAMP_DATETIME);
}
if (et->expression)
......@@ -276,10 +279,10 @@ evex_fill_row(THD *thd, TABLE *table, event_timed *et, my_bool is_update)
table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->set_notnull();
/*
In the enum (C) intervals start from 0 but in mysql enum valid values start
from 1. Thus +1 offset is needed!
In the enum (C) intervals start from 0 but in mysql enum valid values start
from 1. Thus +1 offset is needed!
*/
table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->store((longlong)et->interval + 1);
table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->store((longlong)et->interval+1);
}
else if (et->execute_at.year)
{
......@@ -288,8 +291,7 @@ evex_fill_row(THD *thd, TABLE *table, event_timed *et, my_bool is_update)
table->field[EVEX_FIELD_EXECUTE_AT]->store_time(&et->execute_at,
MYSQL_TIMESTAMP_DATETIME);
//this will make it NULL because we don't call set_notnull
table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->store((longlong) 0);
table->field[EVEX_FIELD_TRANSIENT_INTERVAL]->set_null();
}
else
{
......@@ -693,8 +695,16 @@ evex_remove_from_cache(LEX_STRING *db, LEX_STRING *name, bool use_lock)
if (!sortcmp_lex_string(*name, et->name, system_charset_info) &&
!sortcmp_lex_string(*db, et->dbname, system_charset_info))
{
et->free_sp();
delete et;
if (!et->is_running())
{
et->free_sp();
delete et;
}
else
{
et->flags|= EVENT_EXEC_NO_MORE;
et->dropped= true;
}
evex_queue_delete_element(&EVEX_EQ_NAME, i);
// ok, we have cleaned
goto done;
......
......@@ -113,6 +113,7 @@ class event_timed
free_sp();
}
void
init();
......@@ -164,6 +165,18 @@ class event_timed
int
compile(THD *thd, MEM_ROOT *mem_root= NULL);
my_bool
is_running()
{
my_bool ret;
VOID(pthread_mutex_lock(&this->LOCK_running));
ret= running;
VOID(pthread_mutex_unlock(&this->LOCK_running));
return ret;
}
void free_sp()
{
delete sphead;
......
......@@ -313,10 +313,8 @@ event_executor_main(void *arg)
{
pthread_t th;
printf("[%10s] exec at [%llu]\n", et->name.str,TIME_to_ulonglong_datetime(&et->execute_at));
et->mark_last_executed();
et->compute_next_execution_time();
printf("[%10s] next at [%llu]\n\n\n", et->name.str,TIME_to_ulonglong_datetime(&et->execute_at));
et->update_fields(thd);
DBUG_PRINT("info", (" Spawning a thread %d", ++iter_num));
#ifndef DBUG_FAULTY_THR
......@@ -461,11 +459,19 @@ event_executor_worker(void *event_void)
is_schema_db(event->dbname.str)))
{
int ret;
DBUG_PRINT("info", (" EVEX EXECUTING event for event %s.%s [EXPR:%d]", event->dbname.str, event->name.str,(int) event->expression));
sql_print_information(" EVEX EXECUTING event for event %s.%s [EXPR:%d]", event->dbname.str, event->name.str,(int) event->expression);
DBUG_PRINT("info", (" EVEX EXECUTING event %s.%s [EXPR:%d]",
event->dbname.str, event->name.str,(int) event->expression));
sql_print_information(" EVEX EXECUTING event %s.%s [EXPR:%d]",
event->dbname.str, event->name.str,(int) event->expression);
ret= event->execute(thd, &worker_mem_root);
sql_print_information(" EVEX EXECUTED event for event %s.%s [EXPR:%d]. RetCode=%d", event->dbname.str, event->name.str,(int) event->expression, ret);
DBUG_PRINT("info", (" EVEX EXECUTED event for event %s.%s [EXPR:%d]. RetCode=%d", event->dbname.str, event->name.str,(int) event->expression, ret));
sql_print_information(" EVEX EXECUTED event %s.%s [EXPR:%d]. RetCode=%d",
event->dbname.str, event->name.str,
(int) event->expression, ret);
DBUG_PRINT("info", (" EVEX EXECUTED event %s.%s [EXPR:%d]. RetCode=%d",
event->dbname.str, event->name.str,
(int) event->expression, ret));
}
if ((event->flags & EVENT_EXEC_NO_MORE) || event->status==MYSQL_EVENT_DISABLED)
{
......@@ -554,7 +560,7 @@ evex_load_events_from_db(THD *thd)
}
if (et->status != MYSQL_EVENT_ENABLED)
{
DBUG_PRINT("evex_load_events_from_db",("Event %s is disabled", et->name.str));
DBUG_PRINT("evex_load_events_from_db",("%s is disabled",et->name.str));
delete et;
continue;
}
......@@ -589,8 +595,9 @@ evex_load_events_from_db(THD *thd)
thd->version--; // Force close to free memory
close_thread_tables(thd);
sql_print_information("Scheduler loaded %d events", count);
DBUG_PRINT("info", ("Finishing with status code %d. Loaded %d events", ret, count));
sql_print_information("Scheduler loaded %d event%s", count, (count == 1)?"":"s");
DBUG_PRINT("info", ("Status code %d. Loaded %d event(s)", ret, count));
DBUG_RETURN(ret);
}
......
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