Commit 831569cb authored by andrey@lmy004's avatar andrey@lmy004

WL#1034 (update)

- fixed silly bug, the main thread restarted but did not execute events,
  Quite currious why many calls to pthread_mutex_init() do not lead to abort()
parent ba79f499
...@@ -64,14 +64,10 @@ Warning: ...@@ -64,14 +64,10 @@ Warning:
*/ */
bool mysql_event_table_exists= 1;
QUEUE EVEX_EQ_NAME; QUEUE EVEX_EQ_NAME;
MEM_ROOT evex_mem_root; MEM_ROOT evex_mem_root;
void void
evex_queue_init(EVEX_QUEUE_TYPE *queue) evex_queue_init(EVEX_QUEUE_TYPE *queue)
{ {
...@@ -175,7 +171,6 @@ event_timed_compare(event_timed **a, event_timed **b) ...@@ -175,7 +171,6 @@ event_timed_compare(event_timed **a, event_timed **b)
else else
return 0; return 0;
// return my_time_compare(&(*a)->execute_at, &(*b)->execute_at);
} }
...@@ -204,23 +199,13 @@ TABLE *evex_open_event_table(THD *thd, enum thr_lock_type lock_type) ...@@ -204,23 +199,13 @@ TABLE *evex_open_event_table(THD *thd, enum thr_lock_type lock_type)
bool not_used; bool not_used;
DBUG_ENTER("open_proc_table"); DBUG_ENTER("open_proc_table");
/*
Speed up things if the table doesn't exists. *table_exists
is set when we create or read stored procedure or on flush privileges.
*/
if (!mysql_event_table_exists)
DBUG_RETURN(0);
bzero((char*) &tables, sizeof(tables)); bzero((char*) &tables, sizeof(tables));
tables.db= (char*) "mysql"; tables.db= (char*) "mysql";
tables.table_name= tables.alias= (char*) "event"; tables.table_name= tables.alias= (char*) "event";
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))
{
mysql_event_table_exists= 0;
DBUG_RETURN(0); DBUG_RETURN(0);
}
DBUG_RETURN(tables.table); DBUG_RETURN(tables.table);
} }
...@@ -638,7 +623,7 @@ done: ...@@ -638,7 +623,7 @@ done:
et= 0; et= 0;
} }
// don't close the table if we haven't opened it ourselves // don't close the table if we haven't opened it ourselves
if (!tbl) if (!tbl && table)
close_thread_tables(thd); close_thread_tables(thd);
*ett= et; *ett= et;
DBUG_RETURN(ret); DBUG_RETURN(ret);
...@@ -745,9 +730,7 @@ done: ...@@ -745,9 +730,7 @@ done:
} }
/*
-= Exported functions follow =-
*/
/* /*
The function exported to the world for creating of events. The function exported to the world for creating of events.
......
...@@ -41,7 +41,7 @@ bool evex_is_running= false; ...@@ -41,7 +41,7 @@ bool evex_is_running= false;
ulonglong evex_main_thread_id= 0; ulonglong evex_main_thread_id= 0;
ulong opt_event_executor; ulong opt_event_executor;
my_bool event_executor_running_global_var= false; volatile my_bool event_executor_running_global_var;
static my_bool evex_mutexes_initted= false; static my_bool evex_mutexes_initted= false;
static uint workers_count; static uint workers_count;
...@@ -65,13 +65,14 @@ static ...@@ -65,13 +65,14 @@ static
void evex_init_mutexes() void evex_init_mutexes()
{ {
if (evex_mutexes_initted) if (evex_mutexes_initted)
{
evex_mutexes_initted= true;
return; return;
}
evex_mutexes_initted= true;
pthread_mutex_init(&LOCK_event_arrays, MY_MUTEX_INIT_FAST); pthread_mutex_init(&LOCK_event_arrays, MY_MUTEX_INIT_FAST);
pthread_mutex_init(&LOCK_workers_count, MY_MUTEX_INIT_FAST); pthread_mutex_init(&LOCK_workers_count, MY_MUTEX_INIT_FAST);
pthread_mutex_init(&LOCK_evex_running, MY_MUTEX_INIT_FAST); pthread_mutex_init(&LOCK_evex_running, MY_MUTEX_INIT_FAST);
event_executor_running_global_var= opt_event_executor;
} }
...@@ -88,7 +89,6 @@ init_events() ...@@ -88,7 +89,6 @@ init_events()
VOID(pthread_mutex_lock(&LOCK_evex_running)); VOID(pthread_mutex_lock(&LOCK_evex_running));
evex_is_running= false; evex_is_running= false;
event_executor_running_global_var= false;
VOID(pthread_mutex_unlock(&LOCK_evex_running)); VOID(pthread_mutex_unlock(&LOCK_evex_running));
#ifndef DBUG_FAULTY_THR #ifndef DBUG_FAULTY_THR
...@@ -206,7 +206,6 @@ event_executor_main(void *arg) ...@@ -206,7 +206,6 @@ event_executor_main(void *arg)
evex_queue_init(&EVEX_EQ_NAME); evex_queue_init(&EVEX_EQ_NAME);
VOID(pthread_mutex_unlock(&LOCK_event_arrays)); VOID(pthread_mutex_unlock(&LOCK_event_arrays));
evex_is_running= true; evex_is_running= true;
event_executor_running_global_var= opt_event_executor;
VOID(pthread_mutex_unlock(&LOCK_evex_running)); VOID(pthread_mutex_unlock(&LOCK_evex_running));
if (evex_load_events_from_db(thd)) if (evex_load_events_from_db(thd))
...@@ -224,7 +223,7 @@ event_executor_main(void *arg) ...@@ -224,7 +223,7 @@ event_executor_main(void *arg)
cnt++; cnt++;
DBUG_PRINT("info", ("EVEX External Loop %d", cnt)); DBUG_PRINT("info", ("EVEX External Loop %d", cnt));
if (cnt > 1000) continue;
thd->proc_info = "Sleeping"; thd->proc_info = "Sleeping";
if (!evex_queue_num_elements(EVEX_EQ_NAME) || if (!evex_queue_num_elements(EVEX_EQ_NAME) ||
!event_executor_running_global_var) !event_executor_running_global_var)
...@@ -573,18 +572,17 @@ end: ...@@ -573,18 +572,17 @@ end:
} }
bool sys_var_event_executor::update(THD *thd, set_var *var) bool sys_var_event_executor::update(THD *thd, set_var *var)
{ {
// here start the thread if not running. // here start the thread if not running.
VOID(pthread_mutex_lock(&LOCK_evex_running)); VOID(pthread_mutex_lock(&LOCK_evex_running));
if ((my_bool) var->save_result.ulong_value && !evex_is_running) *value= var->save_result.ulong_value;
if ((my_bool) *value && !evex_is_running)
{ {
VOID(pthread_mutex_unlock(&LOCK_evex_running)); VOID(pthread_mutex_unlock(&LOCK_evex_running));
init_events(); init_events();
} else } else
VOID(pthread_mutex_unlock(&LOCK_evex_running)); VOID(pthread_mutex_unlock(&LOCK_evex_running));
return 0;
return sys_var_bool_ptr::update(thd, var);
} }
...@@ -88,8 +88,6 @@ evex_queue_init(EVEX_QUEUE_TYPE *queue); ...@@ -88,8 +88,6 @@ evex_queue_init(EVEX_QUEUE_TYPE *queue);
extern bool evex_is_running; extern bool evex_is_running;
extern bool mysql_event_table_exists;
//extern DYNAMIC_ARRAY events_array;
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,
......
...@@ -725,6 +725,7 @@ bool ...@@ -725,6 +725,7 @@ bool
event_timed::update_fields(THD *thd) event_timed::update_fields(THD *thd)
{ {
TABLE *table; TABLE *table;
Open_tables_state backup;
int ret= 0; int ret= 0;
bool opened; bool opened;
...@@ -736,8 +737,14 @@ event_timed::update_fields(THD *thd) ...@@ -736,8 +737,14 @@ event_timed::update_fields(THD *thd)
if (!(status_changed || last_executed_changed)) if (!(status_changed || last_executed_changed))
goto done; goto done;
thd->reset_n_backup_open_tables_state(&backup);
if (!(table= evex_open_event_table(thd, TL_WRITE))) if (!(table= evex_open_event_table(thd, TL_WRITE)))
DBUG_RETURN(SP_OPEN_TABLE_FAILED); {
ret= SP_OPEN_TABLE_FAILED;
goto done;
}
if ((ret= evex_db_find_event_aux(thd, dbname, name, table))) if ((ret= evex_db_find_event_aux(thd, dbname, name, table)))
goto done; goto done;
...@@ -764,6 +771,7 @@ event_timed::update_fields(THD *thd) ...@@ -764,6 +771,7 @@ event_timed::update_fields(THD *thd)
done: done:
close_thread_tables(thd); close_thread_tables(thd);
thd->restore_backup_open_tables_state(&backup);
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
...@@ -798,7 +806,7 @@ event_timed::get_show_create_event(THD *thd, uint *length) ...@@ -798,7 +806,7 @@ event_timed::get_show_create_event(THD *thd, uint *length)
*dst= '\0'; *dst= '\0';
*length= len; *length= len;
dst[len]= '\0';
sql_print_information("%d %d[%s]", len, dst-ret, ret); 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