Commit 112d408f authored by unknown's avatar unknown

WL#1034 update

cleanup before throwin away DYNAMIC_ARRAY for event storage,
once reallocated I get dangling pointers so that's not good.
solution will be found however ;)


sql/event.cc:
  - remove unneeded variables
  - remove commented out code
  - remove non-cs compliant comment
  - fix a bug when removing from memory cache
  - better close the tables than relying on sql_parse.cc::do_command()
    to do that
sql/event_executor.cc:
  - cleanup
sql/event_priv.h:
  -cleanup
sql/event_timed.cc:
  cleanup
parent 81eadfca
...@@ -73,17 +73,11 @@ Warning: ...@@ -73,17 +73,11 @@ Warning:
bool mysql_event_table_exists= 1; bool mysql_event_table_exists= 1;
DYNAMIC_ARRAY events_array; DYNAMIC_ARRAY events_array;
DYNAMIC_ARRAY EXEC_QUEUE_DARR_NAME; QUEUE EVEX_EQ_NAME;
QUEUE EXEC_QUEUE_QUEUE_NAME;
MEM_ROOT evex_mem_root; MEM_ROOT evex_mem_root;
//extern volatile uint thread_running;
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//////////////// Static functions follow ///////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
void void
evex_queue_init(EVEX_QUEUE_TYPE *queue) evex_queue_init(EVEX_QUEUE_TYPE *queue)
{ {
...@@ -202,6 +196,7 @@ my_time_compare(TIME *a, TIME *b) ...@@ -202,6 +196,7 @@ my_time_compare(TIME *a, TIME *b)
DBUG_RETURN(0); DBUG_RETURN(0);
} }
int int
evex_time_diff(TIME *a, TIME *b) evex_time_diff(TIME *a, TIME *b)
{ {
...@@ -519,14 +514,17 @@ db_create_event(THD *thd, event_timed *et) ...@@ -519,14 +514,17 @@ db_create_event(THD *thd, event_timed *et)
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
// No need to close the table, it will be closed in sql_parse::do_command
if (dbchanged) if (dbchanged)
(void) mysql_change_db(thd, olddb, 1); (void) mysql_change_db(thd, olddb, 1);
if (table)
close_thread_tables(thd);
DBUG_RETURN(EVEX_OK); DBUG_RETURN(EVEX_OK);
err: err:
if (dbchanged) if (dbchanged)
(void) mysql_change_db(thd, olddb, 1); (void) mysql_change_db(thd, olddb, 1);
if (table)
close_thread_tables(thd);
DBUG_RETURN(EVEX_GENERAL_ERROR); DBUG_RETURN(EVEX_GENERAL_ERROR);
} }
...@@ -742,9 +740,7 @@ evex_load_and_compile_event(THD * thd, sp_name *spn, bool use_lock) ...@@ -742,9 +740,7 @@ evex_load_and_compile_event(THD * thd, sp_name *spn, bool use_lock)
VOID(push_dynamic(&events_array,(gptr) ett)); VOID(push_dynamic(&events_array,(gptr) ett));
ett_copy= dynamic_element(&events_array, events_array.elements - 1, ett_copy= dynamic_element(&events_array, events_array.elements - 1,
event_timed*); event_timed*);
/**
VOID(push_dynamic(&evex_executing_queue, (gptr) &ett_copy));
**/
evex_queue_insert(&EVEX_EQ_NAME, (EVEX_PTOQEL) ett_copy); evex_queue_insert(&EVEX_EQ_NAME, (EVEX_PTOQEL) ett_copy);
/* /*
...@@ -754,19 +750,6 @@ evex_load_and_compile_event(THD * thd, sp_name *spn, bool use_lock) ...@@ -754,19 +750,6 @@ evex_load_and_compile_event(THD * thd, sp_name *spn, bool use_lock)
ett->free_sphead_on_delete= false; ett->free_sphead_on_delete= false;
delete ett; delete ett;
/*
We find where the first element resides in the array. And then do a
qsort of events_array.elements (the current number of elements).
We know that the elements are stored in a contiguous block w/o holes.
*/
/**
qsort((gptr) dynamic_element(&evex_executing_queue, 0, event_timed**),
evex_executing_queue.elements,
sizeof(event_timed **),
(qsort_cmp) event_timed_compare);
**/
evex_queue_sort(&EVEX_EQ_NAME);
if (use_lock) if (use_lock)
VOID(pthread_mutex_unlock(&LOCK_event_arrays)); VOID(pthread_mutex_unlock(&LOCK_event_arrays));
...@@ -791,40 +774,10 @@ evex_remove_from_cache(LEX_STRING *db, LEX_STRING *name, bool use_lock) ...@@ -791,40 +774,10 @@ evex_remove_from_cache(LEX_STRING *db, LEX_STRING *name, bool use_lock)
if (use_lock) if (use_lock)
VOID(pthread_mutex_lock(&LOCK_event_arrays)); VOID(pthread_mutex_lock(&LOCK_event_arrays));
/**
for (i= 0; i < evex_executing_queue.elements; ++i)
{
event_timed *et= *dynamic_element(&evex_executing_queue, i, event_timed**);
DBUG_PRINT("info", ("[%s.%s]==[%s.%s]?",db->str,name->str, et->dbname.str,
et->name.str));
if (!sortcmp_lex_string(*name, et->name, system_charset_info) &&
!sortcmp_lex_string(*db, et->dbname, system_charset_info))
{
int idx= get_index_dynamic(&events_array, (gptr) et);
//we are lucky the event is in the executing queue, no need of second pass
if (idx == -1)
{
//this should never happen
DBUG_PRINT("error", (" get_index_dynamic problem. %d."
"i=%d idx=%d evex_ex_queue.buf=%p evex_ex_queue.elements=%d et=%p\n"
"events_array=%p events_array.elements=%d events_array.buf=%p et=%p\n",
__LINE__, i, idx, &evex_executing_queue.buffer,
evex_executing_queue.elements, et, &events_array,
events_array.elements, events_array.buffer, et));
DBUG_ASSERT(0);
}
//destruct first and then remove. the destructor will delete sp_head
et->free_sp();
delete_dynamic_element(&events_array, idx);
delete_dynamic_element(&evex_executing_queue, i);
// ok, we have cleaned
goto done;
}
}
**/
for (i= 0; i < evex_queue_num_elements(EVEX_EQ_NAME); ++i) for (i= 0; i < evex_queue_num_elements(EVEX_EQ_NAME); ++i)
{ {
event_timed *et= *evex_queue_element(&EVEX_EQ_NAME, i, event_timed**); event_timed *et= evex_queue_element(&EVEX_EQ_NAME, i, event_timed*);
DBUG_PRINT("info", ("[%s.%s]==[%s.%s]?",db->str,name->str, et->dbname.str, DBUG_PRINT("info", ("[%s.%s]==[%s.%s]?",db->str,name->str, et->dbname.str,
et->name.str)); et->name.str));
if (!sortcmp_lex_string(*name, et->name, system_charset_info) && if (!sortcmp_lex_string(*name, et->name, system_charset_info) &&
...@@ -834,7 +787,7 @@ evex_remove_from_cache(LEX_STRING *db, LEX_STRING *name, bool use_lock) ...@@ -834,7 +787,7 @@ evex_remove_from_cache(LEX_STRING *db, LEX_STRING *name, bool use_lock)
//we are lucky the event is in the executing queue, no need of second pass //we are lucky the event is in the executing queue, no need of second pass
//destruct first and then remove. the destructor will delete sp_head //destruct first and then remove. the destructor will delete sp_head
et->free_sp(); et->free_sp();
evex_queue_delete_element(&EVEX_EQ_NAME, idx); delete_dynamic_element(&events_array, idx);
evex_queue_delete_element(&EVEX_EQ_NAME, i); evex_queue_delete_element(&EVEX_EQ_NAME, i);
// ok, we have cleaned // ok, we have cleaned
goto done; goto done;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
are not possible because the scheduler thread code is ran inside the are not possible because the scheduler thread code is ran inside the
main thread (no spawning takes place. If you want to debug client main thread (no spawning takes place. If you want to debug client
connection then start with --one-thread and make the define connection then start with --one-thread and make the define
DBUG_FAULTY_THR2 ! DBUG_FAULTY_THR !
*/ */
#define DBUG_FAULTY_THR2 #define DBUG_FAULTY_THR2
...@@ -202,9 +202,6 @@ event_executor_main(void *arg) ...@@ -202,9 +202,6 @@ event_executor_main(void *arg)
thus data should be freed at later stage. thus data should be freed at later stage.
*/ */
VOID(my_init_dynamic_array(&events_array, sizeof(event_timed), 50, 100)); VOID(my_init_dynamic_array(&events_array, sizeof(event_timed), 50, 100));
/**
VOID(my_init_dynamic_array(&evex_executing_queue, sizeof(event_timed *), 50, 100));
**/
evex_queue_init(&EVEX_EQ_NAME); evex_queue_init(&EVEX_EQ_NAME);
...@@ -533,7 +530,7 @@ evex_load_events_from_db(THD *thd) ...@@ -533,7 +530,7 @@ evex_load_events_from_db(THD *thd)
while (!(read_record_info.read_record(&read_record_info))) while (!(read_record_info.read_record(&read_record_info)))
{ {
event_timed *et, *et_copy; event_timed *et, *et_copy;
if (!(et= new event_timed())) if (!(et= new event_timed))
{ {
DBUG_PRINT("evex_load_events_from_db", ("Out of memory")); DBUG_PRINT("evex_load_events_from_db", ("Out of memory"));
ret= -1; ret= -1;
......
...@@ -113,13 +113,11 @@ evex_queue_sort(EVEX_QUEUE_TYPE *queue); ...@@ -113,13 +113,11 @@ evex_queue_sort(EVEX_QUEUE_TYPE *queue);
extern bool evex_is_running; extern bool evex_is_running;
extern bool mysql_event_table_exists; extern bool mysql_event_table_exists;
extern DYNAMIC_ARRAY events_array; extern DYNAMIC_ARRAY events_array;
extern DYNAMIC_ARRAY EXEC_QUEUE_DARR_NAME;
extern QUEUE EXEC_QUEUE_QUEUE_NAME;
extern MEM_ROOT evex_mem_root; extern MEM_ROOT evex_mem_root;
extern pthread_mutex_t LOCK_event_arrays, extern pthread_mutex_t LOCK_event_arrays,
LOCK_workers_count, LOCK_workers_count,
LOCK_evex_running; LOCK_evex_running;
extern ulonglong evex_main_thread_id; extern ulonglong evex_main_thread_id;
extern QUEUE EVEX_EQ_NAME;
#endif /* _EVENT_PRIV_H_ */ #endif /* _EVENT_PRIV_H_ */
...@@ -776,17 +776,7 @@ event_timed::get_show_create_event(THD *thd, uint *length) ...@@ -776,17 +776,7 @@ event_timed::get_show_create_event(THD *thd, uint *length)
uint len, tmp_len; uint len, tmp_len;
len = strlen("CREATE EVENT ") + dbname.length + strlen(".") + name.length + len = strlen("CREATE EVENT ") + dbname.length + strlen(".") + name.length +
strlen(" ON SCHEDULE ") + strlen("EVERY 5 MINUTE ") strlen(" ON SCHEDULE EVERY 5 MINUTE DO ") + body.length + strlen(";");
/*
+ strlen("ON COMPLETION ")
+ (on_completion==MYSQL_EVENT_ON_COMPLETION_DROP?
strlen("NOT PRESERVE "):strlen("PRESERVE "))
+ (status==MYSQL_EVENT_ENABLED?
strlen("ENABLE "):strlen("DISABLE "))
+ strlen("COMMENT \"") + comment.length + strlen("\" ")
*/
+ strlen("DO ") +
+ body.length + strlen(";");
ret= dst= (char*) alloc_root(thd->mem_root, len + 1); ret= dst= (char*) alloc_root(thd->mem_root, len + 1);
memcpy(dst, "CREATE EVENT ", tmp_len= strlen("CREATE EVENT ")); memcpy(dst, "CREATE EVENT ", tmp_len= strlen("CREATE EVENT "));
...@@ -797,31 +787,8 @@ event_timed::get_show_create_event(THD *thd, uint *length) ...@@ -797,31 +787,8 @@ event_timed::get_show_create_event(THD *thd, uint *length)
dst+= tmp_len; dst+= tmp_len;
memcpy(dst, name.str, tmp_len= name.length); memcpy(dst, name.str, tmp_len= name.length);
dst+= tmp_len; dst+= tmp_len;
memcpy(dst, " ON SCHEDULE ", tmp_len= strlen(" ON SCHEDULE ")); memcpy(dst, " ON SCHEDULE EVERY 5 MINUTE DO ",
dst+= tmp_len; tmp_len= strlen(" ON SCHEDULE EVERY 5 MINUTE DO "));
memcpy(dst, "EVERY 5 MINUTE ", tmp_len= strlen("EVERY 5 MINUTE "));
dst+= tmp_len;
/*
memcpy(dst, "ON COMPLETION ", tmp_len =strlen("ON COMPLETION "));
dst+= tmp_len;
memcpy(dst, (on_completion==MYSQL_EVENT_ON_COMPLETION_DROP?
"NOT PRESERVE ":"PRESERVE "),
tmp_len =(on_completion==MYSQL_EVENT_ON_COMPLETION_DROP? 13:9));
dst+= tmp_len;
memcpy(dst, (status==MYSQL_EVENT_ENABLED?
"ENABLE ":"DISABLE "),
tmp_len= (status==MYSQL_EVENT_ENABLED? 8:9));
dst+=tmp_len;
memcpy(dst, "COMMENT \"", tmp_len= strlen("COMMENT \""));
dst+= tmp_len;
memcpy(dst, comment.str, tmp_len= comment.length);
dst+= tmp_len;
memcpy(dst, "\" ", tmp_len=2);
dst+= tmp_len;
*/
memcpy(dst, "DO ", tmp_len=3);
dst+= tmp_len; dst+= tmp_len;
memcpy(dst, body.str, tmp_len= body.length); memcpy(dst, body.str, tmp_len= body.length);
...@@ -829,9 +796,10 @@ event_timed::get_show_create_event(THD *thd, uint *length) ...@@ -829,9 +796,10 @@ event_timed::get_show_create_event(THD *thd, uint *length)
memcpy(dst, ";", 1); memcpy(dst, ";", 1);
++dst; ++dst;
*dst= '\0'; *dst= '\0';
*length= len; *length= len;
dst[len]= '\0'; dst[len]= '\0';
sql_print_information("%d %d[%s]", len, dst-ret, ret);
return ret; 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