Commit 3f4e1f5c authored by andrey@lmy004's avatar andrey@lmy004

WL#3337 (Event scheduler new architecture)

event_scheduler_ng.cc/h is no more
parent 0d517461
prepare stmt1 from ' show full processlist '; prepare stmt1 from ' show full processlist ';
execute stmt1; execute stmt1;
Id User Host db Command Time State Info Id User Host db Command Time State Info
number event_scheduler localhost NULL Connect time Suspended NULL
number root localhost test Query time NULL show full processlist number root localhost test Query time NULL show full processlist
deallocate prepare stmt1; deallocate prepare stmt1;
...@@ -67,7 +67,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ ...@@ -67,7 +67,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
sql_array.h sql_cursor.h events.h \ sql_array.h sql_cursor.h events.h \
sql_plugin.h authors.h sql_partition.h event_data_objects.h \ sql_plugin.h authors.h sql_partition.h event_data_objects.h \
event_queue.h event_db_repository.h \ event_queue.h event_db_repository.h \
partition_info.h partition_element.h event_scheduler_ng.h \ partition_info.h partition_element.h event_scheduler.h \
contributors.h contributors.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \ item.cc item_sum.cc item_buff.cc item_func.cc \
...@@ -105,7 +105,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \ ...@@ -105,7 +105,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
tztime.cc my_time.c my_user.c my_decimal.cc\ tztime.cc my_time.c my_user.c my_decimal.cc\
sp_head.cc sp_pcontext.cc sp_rcontext.cc sp.cc \ sp_head.cc sp_pcontext.cc sp_rcontext.cc sp.cc \
sp_cache.cc parse_file.cc sql_trigger.cc event_scheduler.cc\ sp_cache.cc parse_file.cc sql_trigger.cc event_scheduler.cc\
event_scheduler_ng.cc events.cc event_data_objects.cc \ events.cc event_data_objects.cc \
event_queue.cc event_db_repository.cc \ event_queue.cc event_db_repository.cc \
sql_plugin.cc sql_binlog.cc \ sql_plugin.cc sql_binlog.cc \
sql_builtin.cc sql_tablespace.cc partition_info.cc sql_builtin.cc sql_tablespace.cc partition_info.cc
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "event_queue.h" #include "event_queue.h"
#include "event_data_objects.h" #include "event_data_objects.h"
#include "event_db_repository.h" #include "event_db_repository.h"
#include "event_scheduler_ng.h" #include "event_scheduler.h"
#define EVENT_QUEUE_INITIAL_SIZE 30 #define EVENT_QUEUE_INITIAL_SIZE 30
...@@ -123,7 +123,7 @@ Event_queue::deinit_mutexes() ...@@ -123,7 +123,7 @@ Event_queue::deinit_mutexes()
*/ */
bool bool
Event_queue::init_queue(Event_db_repository *db_repo, Event_scheduler_ng *sched) Event_queue::init_queue(Event_db_repository *db_repo, Event_scheduler *sched)
{ {
int i= 0; int i= 0;
bool ret= FALSE; bool ret= FALSE;
......
...@@ -22,7 +22,7 @@ class Event_job_data; ...@@ -22,7 +22,7 @@ class Event_job_data;
class Event_queue_element; class Event_queue_element;
class THD; class THD;
class Event_scheduler_ng; class Event_scheduler;
class Event_queue class Event_queue
{ {
...@@ -36,7 +36,7 @@ public: ...@@ -36,7 +36,7 @@ public:
deinit_mutexes(); deinit_mutexes();
bool bool
init_queue(Event_db_repository *db_repo, Event_scheduler_ng *sched); init_queue(Event_db_repository *db_repo, Event_scheduler *sched);
void void
deinit_queue(); deinit_queue();
...@@ -109,7 +109,7 @@ protected: ...@@ -109,7 +109,7 @@ protected:
void void
dbug_dump_queue(time_t now); dbug_dump_queue(time_t now);
Event_scheduler_ng *scheduler; Event_scheduler *scheduler;
/* The sorted queue with the Event_job_data objects */ /* The sorted queue with the Event_job_data objects */
QUEUE queue; QUEUE queue;
......
This diff is collapsed.
...@@ -16,4 +16,108 @@ ...@@ -16,4 +16,108 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
class Event_queue;
class Event_job_data;
class Event_scheduler
{
public:
Event_scheduler(){}
~Event_scheduler(){}
enum enum_state
{
INITIALIZED = 0,
RUNNING,
STOPPING
};
/* State changing methods follow */
bool
start();
bool
stop();
/*
Need to be public because has to be called from the function
passed to pthread_create.
*/
bool
run(THD *thd);
bool
init_scheduler(Event_queue *queue);
void
deinit_scheduler();
void
init_mutexes();
void
deinit_mutexes();
/* Information retrieving methods follow */
enum enum_state
get_state();
void
queue_changed();
bool
dump_internal_status(THD *thd);
private:
uint
workers_count();
/* helper functions */
bool
execute_top(THD *thd, Event_job_data *job_data);
/* helper functions for working with mutexes & conditionals */
void
lock_data(const char *func, uint line);
void
unlock_data(const char *func, uint line);
void
cond_wait(struct timespec *abstime, const char *func, uint line);
pthread_mutex_t LOCK_scheduler_state;
/* This is the current status of the life-cycle of the scheduler. */
enum enum_state state;
/*
Holds the thread id of the executor thread or 0 if the scheduler is not
running. It is used by ::shutdown() to know which thread to kill with
kill_one_thread(). The latter wake ups a thread if it is waiting on a
conditional variable and sets thd->killed to non-zero.
*/
ulong thread_id;
pthread_cond_t COND_state;
Event_queue *queue;
uint mutex_last_locked_at_line;
uint mutex_last_unlocked_at_line;
const char* mutex_last_locked_in_func;
const char* mutex_last_unlocked_in_func;
bool mutex_scheduler_data_locked;
bool waiting_on_cond;
ulonglong started_events;
private:
/* Prevent use of these */
Event_scheduler(const Event_scheduler &);
void operator=(Event_scheduler &);
};
#endif /* _EVENT_SCHEDULER_H_ */ #endif /* _EVENT_SCHEDULER_H_ */
This diff is collapsed.
#ifndef _EVENT_SCHEDULER_NG_H_
#define _EVENT_SCHEDULER_NG_H_
/* Copyright (C) 2004-2006 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
class Event_queue;
class Event_job_data;
class Event_scheduler_ng
{
public:
Event_scheduler_ng(){}
~Event_scheduler_ng(){}
enum enum_state
{
INITIALIZED = 0,
RUNNING,
STOPPING
};
/* State changing methods follow */
bool
start();
bool
stop();
/*
Need to be public because has to be called from the function
passed to pthread_create.
*/
bool
run(THD *thd);
bool
init_scheduler(Event_queue *queue);
void
deinit_scheduler();
void
init_mutexes();
void
deinit_mutexes();
/* Information retrieving methods follow */
enum enum_state
get_state();
void
queue_changed();
bool
dump_internal_status(THD *thd);
private:
uint
workers_count();
/* helper functions */
bool
execute_top(THD *thd, Event_job_data *job_data);
/* helper functions for working with mutexes & conditionals */
void
lock_data(const char *func, uint line);
void
unlock_data(const char *func, uint line);
void
cond_wait(struct timespec *abstime, const char *func, uint line);
pthread_mutex_t LOCK_scheduler_state;
/* This is the current status of the life-cycle of the scheduler. */
enum enum_state state;
/*
Holds the thread id of the executor thread or 0 if the scheduler is not
running. It is used by ::shutdown() to know which thread to kill with
kill_one_thread(). The latter wake ups a thread if it is waiting on a
conditional variable and sets thd->killed to non-zero.
*/
ulong thread_id;
pthread_cond_t COND_state;
Event_queue *queue;
uint mutex_last_locked_at_line;
uint mutex_last_unlocked_at_line;
const char* mutex_last_locked_in_func;
const char* mutex_last_unlocked_in_func;
bool mutex_scheduler_data_locked;
bool waiting_on_cond;
ulonglong started_events;
private:
/* Prevent use of these */
Event_scheduler_ng(const Event_scheduler_ng &);
void operator=(Event_scheduler_ng &);
};
#endif /* _EVENT_SCHEDULER_NG_H_ */
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "event_data_objects.h" #include "event_data_objects.h"
#include "event_db_repository.h" #include "event_db_repository.h"
#include "event_queue.h" #include "event_queue.h"
#include "event_scheduler_ng.h" #include "event_scheduler.h"
#include "sp_head.h" #include "sp_head.h"
/* /*
...@@ -560,15 +560,15 @@ int ...@@ -560,15 +560,15 @@ int
Events::init() Events::init()
{ {
DBUG_ENTER("Events::init"); DBUG_ENTER("Events::init");
event_queue->init_queue(db_repository, scheduler_ng); event_queue->init_queue(db_repository, scheduler);
scheduler_ng->init_scheduler(event_queue); scheduler->init_scheduler(event_queue);
/* it should be an assignment! */ /* it should be an assignment! */
if (opt_event_scheduler) if (opt_event_scheduler)
{ {
DBUG_ASSERT(opt_event_scheduler == 1 || opt_event_scheduler == 2); DBUG_ASSERT(opt_event_scheduler == 1 || opt_event_scheduler == 2);
if (opt_event_scheduler == 1) if (opt_event_scheduler == 1)
DBUG_RETURN(scheduler_ng->start()); DBUG_RETURN(scheduler->start());
} }
DBUG_RETURN(0); DBUG_RETURN(0);
...@@ -590,8 +590,8 @@ Events::deinit() ...@@ -590,8 +590,8 @@ Events::deinit()
{ {
DBUG_ENTER("Events::deinit"); DBUG_ENTER("Events::deinit");
scheduler_ng->stop(); scheduler->stop();
scheduler_ng->deinit_scheduler(); scheduler->deinit_scheduler();
event_queue->deinit_queue(); event_queue->deinit_queue();
...@@ -617,8 +617,8 @@ Events::init_mutexes() ...@@ -617,8 +617,8 @@ Events::init_mutexes()
event_queue= new Event_queue; event_queue= new Event_queue;
event_queue->init_mutexes(); event_queue->init_mutexes();
scheduler_ng= new Event_scheduler_ng(); scheduler= new Event_scheduler();
scheduler_ng->init_mutexes(); scheduler->init_mutexes();
} }
...@@ -633,9 +633,9 @@ void ...@@ -633,9 +633,9 @@ void
Events::destroy_mutexes() Events::destroy_mutexes()
{ {
event_queue->deinit_mutexes(); event_queue->deinit_mutexes();
scheduler_ng->deinit_mutexes(); scheduler->deinit_mutexes();
delete scheduler_ng; delete scheduler;
delete db_repository; delete db_repository;
pthread_mutex_destroy(&LOCK_event_metadata); pthread_mutex_destroy(&LOCK_event_metadata);
...@@ -670,7 +670,7 @@ Events::dump_internal_status(THD *thd) ...@@ -670,7 +670,7 @@ Events::dump_internal_status(THD *thd)
Protocol::SEND_EOF)) Protocol::SEND_EOF))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
if (scheduler_ng->dump_internal_status(thd) || if (scheduler->dump_internal_status(thd) ||
event_queue->dump_internal_status(thd)) event_queue->dump_internal_status(thd))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
...@@ -694,7 +694,7 @@ bool ...@@ -694,7 +694,7 @@ bool
Events::start_execution_of_events() Events::start_execution_of_events()
{ {
DBUG_ENTER("Events::start_execution_of_events"); DBUG_ENTER("Events::start_execution_of_events");
DBUG_RETURN(scheduler_ng->start()); DBUG_RETURN(scheduler->start());
} }
...@@ -715,7 +715,7 @@ bool ...@@ -715,7 +715,7 @@ bool
Events::stop_execution_of_events() Events::stop_execution_of_events()
{ {
DBUG_ENTER("Events::stop_execution_of_events"); DBUG_ENTER("Events::stop_execution_of_events");
DBUG_RETURN(scheduler_ng->stop()); DBUG_RETURN(scheduler->stop());
} }
...@@ -734,5 +734,5 @@ bool ...@@ -734,5 +734,5 @@ bool
Events::is_started() Events::is_started()
{ {
DBUG_ENTER("Events::is_started"); DBUG_ENTER("Events::is_started");
DBUG_RETURN(scheduler_ng->get_state() == Event_scheduler_ng::RUNNING); DBUG_RETURN(scheduler->get_state() == Event_scheduler::RUNNING);
} }
...@@ -21,7 +21,7 @@ class Event_parse_data; ...@@ -21,7 +21,7 @@ class Event_parse_data;
class Event_db_repository; class Event_db_repository;
class Event_queue; class Event_queue;
class Event_queue_element; class Event_queue_element;
class Event_scheduler_ng; class Event_scheduler;
/* Return codes */ /* Return codes */
enum enum_events_error_code enum enum_events_error_code
...@@ -117,7 +117,7 @@ private: ...@@ -117,7 +117,7 @@ private:
static Events singleton; static Events singleton;
Event_queue *event_queue; Event_queue *event_queue;
Event_scheduler_ng *scheduler_ng; Event_scheduler *scheduler;
Event_db_repository *db_repository; Event_db_repository *db_repository;
pthread_mutex_t LOCK_event_metadata; pthread_mutex_t LOCK_event_metadata;
......
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