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 @@
*/
bool mysql_event_table_exists= 1;
QUEUE EVEX_EQ_NAME;
MEM_ROOT evex_mem_root;
void
evex_queue_init(EVEX_QUEUE_TYPE *queue)
{
......@@ -175,7 +171,6 @@ event_timed_compare(event_timed **a, event_timed **b)
else
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)
bool not_used;
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));
tables.db= (char*) "mysql";
tables.table_name= tables.alias= (char*) "event";
tables.lock_type= lock_type;
if (simple_open_n_lock_tables(thd, &tables))
{
mysql_event_table_exists= 0;
DBUG_RETURN(0);
}
DBUG_RETURN(tables.table);
}
......@@ -638,7 +623,7 @@ db_find_event(THD *thd, sp_name *name, event_timed **ett, TABLE *tbl)
et= 0;
}
// don't close the table if we haven't opened it ourselves
if (!tbl)
if (!tbl && table)
close_thread_tables(thd);
*ett= et;
DBUG_RETURN(ret);
......@@ -745,9 +730,7 @@ evex_remove_from_cache(LEX_STRING *db, LEX_STRING *name, bool use_lock)
}
/*
-= Exported functions follow =-
*/
/*
The function exported to the world for creating of events.
......
......@@ -41,7 +41,7 @@ bool evex_is_running= false;
ulonglong evex_main_thread_id= 0;
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 uint workers_count;
......@@ -65,13 +65,14 @@ static
void evex_init_mutexes()
{
if (evex_mutexes_initted)
{
evex_mutexes_initted= true;
return;
}
evex_mutexes_initted= true;
pthread_mutex_init(&LOCK_event_arrays, MY_MUTEX_INIT_FAST);
pthread_mutex_init(&LOCK_workers_count, 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()
VOID(pthread_mutex_lock(&LOCK_evex_running));
evex_is_running= false;
event_executor_running_global_var= false;
VOID(pthread_mutex_unlock(&LOCK_evex_running));
#ifndef DBUG_FAULTY_THR
......@@ -206,7 +206,6 @@ event_executor_main(void *arg)
evex_queue_init(&EVEX_EQ_NAME);
VOID(pthread_mutex_unlock(&LOCK_event_arrays));
evex_is_running= true;
event_executor_running_global_var= opt_event_executor;
VOID(pthread_mutex_unlock(&LOCK_evex_running));
if (evex_load_events_from_db(thd))
......@@ -224,7 +223,7 @@ event_executor_main(void *arg)
cnt++;
DBUG_PRINT("info", ("EVEX External Loop %d", cnt));
if (cnt > 1000) continue;
thd->proc_info = "Sleeping";
if (!evex_queue_num_elements(EVEX_EQ_NAME) ||
!event_executor_running_global_var)
......@@ -573,18 +572,17 @@ evex_load_events_from_db(THD *thd)
}
bool sys_var_event_executor::update(THD *thd, set_var *var)
{
// here start the thread if not 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));
init_events();
} else
VOID(pthread_mutex_unlock(&LOCK_evex_running));
return sys_var_bool_ptr::update(thd, var);
return 0;
}
......@@ -88,8 +88,6 @@ evex_queue_init(EVEX_QUEUE_TYPE *queue);
extern bool evex_is_running;
extern bool mysql_event_table_exists;
//extern DYNAMIC_ARRAY events_array;
extern MEM_ROOT evex_mem_root;
extern pthread_mutex_t LOCK_event_arrays,
LOCK_workers_count,
......
......@@ -725,6 +725,7 @@ bool
event_timed::update_fields(THD *thd)
{
TABLE *table;
Open_tables_state backup;
int ret= 0;
bool opened;
......@@ -736,8 +737,14 @@ event_timed::update_fields(THD *thd)
if (!(status_changed || last_executed_changed))
goto done;
thd->reset_n_backup_open_tables_state(&backup);
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)))
goto done;
......@@ -764,6 +771,7 @@ event_timed::update_fields(THD *thd)
done:
close_thread_tables(thd);
thd->restore_backup_open_tables_state(&backup);
DBUG_RETURN(ret);
}
......@@ -798,7 +806,7 @@ event_timed::get_show_create_event(THD *thd, uint *length)
*dst= '\0';
*length= len;
dst[len]= '\0';
sql_print_information("%d %d[%s]", len, dst-ret, 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