Commit 98d10477 authored by andrey@lmy004's avatar andrey@lmy004

WL#3337 (Events new architecture)

Cut 7 (refactoring)

db_repository is no more embedded in the Events
singleton. Therefore a change to Events_db_repository
won't mean recompile of all files in the server which include events.h
parent 03e0a231
...@@ -1304,7 +1304,7 @@ Event_timed::drop(THD *thd) ...@@ -1304,7 +1304,7 @@ Event_timed::drop(THD *thd)
DBUG_ENTER("Event_timed::drop"); DBUG_ENTER("Event_timed::drop");
DBUG_RETURN(Events::get_instance()-> DBUG_RETURN(Events::get_instance()->
db_repository.drop_event(thd, dbname, name, false, &tmp)); db_repository->drop_event(thd, dbname, name, false, &tmp));
} }
......
...@@ -271,7 +271,7 @@ evex_db_find_event_by_name(THD *thd, const LEX_STRING dbname, ...@@ -271,7 +271,7 @@ evex_db_find_event_by_name(THD *thd, const LEX_STRING dbname,
const LEX_STRING ev_name, const LEX_STRING ev_name,
TABLE *table) TABLE *table)
{ {
return Events::get_instance()->db_repository. return Events::get_instance()->db_repository->
find_event_by_name(thd, dbname, ev_name, table); find_event_by_name(thd, dbname, ev_name, table);
} }
......
...@@ -258,7 +258,7 @@ int ...@@ -258,7 +258,7 @@ int
Events::open_event_table(THD *thd, enum thr_lock_type lock_type, Events::open_event_table(THD *thd, enum thr_lock_type lock_type,
TABLE **table) TABLE **table)
{ {
return db_repository.open_event_table(thd, lock_type, table); return db_repository->open_event_table(thd, lock_type, table);
} }
...@@ -292,7 +292,7 @@ Events::create_event(THD *thd, Event_timed *et, Event_parse_data *parse_data, ...@@ -292,7 +292,7 @@ Events::create_event(THD *thd, Event_timed *et, Event_parse_data *parse_data,
DBUG_PRINT("enter", ("name: %*s options:%d", et->name.length, DBUG_PRINT("enter", ("name: %*s options:%d", et->name.length,
et->name.str, create_options)); et->name.str, create_options));
if (!(ret= db_repository. if (!(ret= db_repository->
create_event(thd, et, create_event(thd, et,
create_options & HA_LEX_CREATE_IF_NOT_EXISTS, create_options & HA_LEX_CREATE_IF_NOT_EXISTS,
rows_affected))) rows_affected)))
...@@ -340,7 +340,7 @@ Events::update_event(THD *thd, Event_timed *et, Event_parse_data *parse_data, ...@@ -340,7 +340,7 @@ Events::update_event(THD *thd, Event_timed *et, Event_parse_data *parse_data,
crash later in the code when loading and compiling the new definition. crash later in the code when loading and compiling the new definition.
Also on error conditions my_error() is called so no need to handle here Also on error conditions my_error() is called so no need to handle here
*/ */
if (!(ret= db_repository.update_event(thd, et, new_name))) if (!(ret= db_repository->update_event(thd, et, new_name)))
{ {
Event_scheduler *scheduler= Event_scheduler::get_instance(); Event_scheduler *scheduler= Event_scheduler::get_instance();
if (scheduler->initialized() && if (scheduler->initialized() &&
...@@ -376,7 +376,7 @@ Events::drop_event(THD *thd, sp_name *name, bool drop_if_exists, ...@@ -376,7 +376,7 @@ Events::drop_event(THD *thd, sp_name *name, bool drop_if_exists,
DBUG_ENTER("Events::drop_event"); DBUG_ENTER("Events::drop_event");
if (!(ret= db_repository.drop_event(thd, name->m_db, name->m_name, if (!(ret= db_repository->drop_event(thd, name->m_db, name->m_name,
drop_if_exists, rows_affected))) drop_if_exists, rows_affected)))
{ {
Event_scheduler *scheduler= Event_scheduler::get_instance(); Event_scheduler *scheduler= Event_scheduler::get_instance();
...@@ -411,7 +411,7 @@ Events::show_create_event(THD *thd, sp_name *spn) ...@@ -411,7 +411,7 @@ Events::show_create_event(THD *thd, sp_name *spn)
DBUG_PRINT("enter", ("name: %*s", spn->m_name.length, spn->m_name.str)); DBUG_PRINT("enter", ("name: %*s", spn->m_name.length, spn->m_name.str));
thd->reset_n_backup_open_tables_state(&backup); thd->reset_n_backup_open_tables_state(&backup);
ret= db_repository.find_event(thd, spn, &et, NULL, thd->mem_root); ret= db_repository->find_event(thd, spn, &et, NULL, thd->mem_root);
thd->restore_backup_open_tables_state(&backup); thd->restore_backup_open_tables_state(&backup);
if (!ret) if (!ret)
...@@ -484,7 +484,7 @@ Events::drop_schema_events(THD *thd, char *db) ...@@ -484,7 +484,7 @@ Events::drop_schema_events(THD *thd, char *db)
Event_scheduler *scheduler= Event_scheduler::get_instance(); Event_scheduler *scheduler= Event_scheduler::get_instance();
ret= scheduler->drop_schema_events(thd, db_lex); ret= scheduler->drop_schema_events(thd, db_lex);
ret= db_repository.drop_schema_events(thd, db_lex); ret= db_repository->drop_schema_events(thd, db_lex);
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
...@@ -510,15 +510,14 @@ Events::init() ...@@ -510,15 +510,14 @@ Events::init()
int ret= 0; int ret= 0;
Event_db_repository *db_repo; Event_db_repository *db_repo;
DBUG_ENTER("Events::init"); DBUG_ENTER("Events::init");
db_repo= &get_instance()->db_repository; db_repository->init_repository();
db_repo->init_repository();
/* it should be an assignment! */ /* it should be an assignment! */
if (opt_event_scheduler) if (opt_event_scheduler)
{ {
Event_scheduler *scheduler= Event_scheduler::get_instance(); Event_scheduler *scheduler= Event_scheduler::get_instance();
DBUG_ASSERT(opt_event_scheduler == 1 || opt_event_scheduler == 2); DBUG_ASSERT(opt_event_scheduler == 1 || opt_event_scheduler == 2);
DBUG_RETURN(scheduler->init(db_repo) || DBUG_RETURN(scheduler->init(db_repository) ||
(opt_event_scheduler == 1? scheduler->start(): (opt_event_scheduler == 1? scheduler->start():
scheduler->start_suspended())); scheduler->start_suspended()));
} }
...@@ -540,18 +539,52 @@ void ...@@ -540,18 +539,52 @@ void
Events::deinit() Events::deinit()
{ {
DBUG_ENTER("Events::deinit"); DBUG_ENTER("Events::deinit");
Event_scheduler *scheduler= Event_scheduler::get_instance(); Event_scheduler *scheduler= Event_scheduler::get_instance();
if (scheduler->initialized()) if (scheduler->initialized())
{ {
scheduler->stop(); scheduler->stop();
scheduler->destroy(); scheduler->destroy();
} }
get_instance()->db_repository.deinit_repository();
db_repository->deinit_repository();
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
/*
Inits Events mutexes
SYNOPSIS
Events::init_mutexes()
thd Thread
*/
void
Events::init_mutexes()
{
db_repository= new Event_db_repository;
Event_scheduler::init_mutexes();
}
/*
Destroys Events mutexes
SYNOPSIS
Events::destroy_mutexes()
*/
void
Events::destroy_mutexes()
{
Event_scheduler::destroy_mutexes();
delete db_repository;
db_repository= NULL;
}
/* /*
Proxy for Event_scheduler::dump_internal_status Proxy for Event_scheduler::dump_internal_status
...@@ -603,34 +636,5 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */) ...@@ -603,34 +636,5 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */)
DBUG_RETURN(1); DBUG_RETURN(1);
db= thd->lex->select_lex.db; db= thd->lex->select_lex.db;
} }
DBUG_RETURN(get_instance()->db_repository.fill_schema_events(thd, tables, db)); DBUG_RETURN(get_instance()->db_repository->fill_schema_events(thd, tables, db));
}
/*
Inits Events mutexes
SYNOPSIS
Events::init_mutexes()
thd Thread
*/
void
Events::init_mutexes()
{
Event_scheduler::init_mutexes();
}
/*
Destroys Events mutexes
SYNOPSIS
Events::destroy_mutexes()
*/
void
Events::destroy_mutexes()
{
Event_scheduler::destroy_mutexes();
} }
...@@ -19,8 +19,7 @@ ...@@ -19,8 +19,7 @@
class sp_name; class sp_name;
class Event_timed; class Event_timed;
class Event_parse_data; class Event_parse_data;
class Event_db_repository;
#include "event_db_repository.h"
/* Return codes */ /* Return codes */
enum enum_events_error_code enum enum_events_error_code
...@@ -51,16 +50,16 @@ public: ...@@ -51,16 +50,16 @@ public:
static ulong opt_event_scheduler; static ulong opt_event_scheduler;
static TYPELIB opt_typelib; static TYPELIB opt_typelib;
static int int
init(); init();
static void void
deinit(); deinit();
static void void
init_mutexes(); init_mutexes();
static void void
destroy_mutexes(); destroy_mutexes();
static Events* static Events*
...@@ -77,6 +76,9 @@ public: ...@@ -77,6 +76,9 @@ public:
int int
drop_event(THD *thd, sp_name *name, bool drop_if_exists, uint *rows_affected); drop_event(THD *thd, sp_name *name, bool drop_if_exists, uint *rows_affected);
int
drop_schema_events(THD *thd, char *db);
int int
open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table); open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table);
...@@ -88,16 +90,13 @@ public: ...@@ -88,16 +90,13 @@ public:
reconstruct_interval_expression(String *buf, interval_type interval, reconstruct_interval_expression(String *buf, interval_type interval,
longlong expression); longlong expression);
int
drop_schema_events(THD *thd, char *db);
static int static int
fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */); fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */);
int int
dump_internal_status(THD *thd); dump_internal_status(THD *thd);
Event_db_repository db_repository; Event_db_repository *db_repository;
private: private:
/* Singleton DP is used */ /* Singleton DP is used */
...@@ -107,7 +106,6 @@ private: ...@@ -107,7 +106,6 @@ private:
/* Singleton instance */ /* Singleton instance */
static Events singleton; static Events singleton;
/* Prevent use of these */ /* Prevent use of these */
Events(const Events &); Events(const Events &);
void operator=(Events &); void operator=(Events &);
......
...@@ -886,7 +886,7 @@ static void close_connections(void) ...@@ -886,7 +886,7 @@ static void close_connections(void)
} }
(void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list (void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list
Events::deinit(); Events::get_instance()->deinit();
end_slave(); end_slave();
if (thread_count) if (thread_count)
...@@ -1321,7 +1321,7 @@ static void clean_up_mutexes() ...@@ -1321,7 +1321,7 @@ static void clean_up_mutexes()
(void) pthread_mutex_destroy(&LOCK_bytes_sent); (void) pthread_mutex_destroy(&LOCK_bytes_sent);
(void) pthread_mutex_destroy(&LOCK_bytes_received); (void) pthread_mutex_destroy(&LOCK_bytes_received);
(void) pthread_mutex_destroy(&LOCK_user_conn); (void) pthread_mutex_destroy(&LOCK_user_conn);
Events::destroy_mutexes(); Events::get_instance()->destroy_mutexes();
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
(void) pthread_mutex_destroy(&LOCK_des_key_file); (void) pthread_mutex_destroy(&LOCK_des_key_file);
#ifndef HAVE_YASSL #ifndef HAVE_YASSL
...@@ -2884,7 +2884,7 @@ static int init_thread_environment() ...@@ -2884,7 +2884,7 @@ static int init_thread_environment()
(void) pthread_mutex_init(&LOCK_server_started, MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_server_started, MY_MUTEX_INIT_FAST);
(void) pthread_cond_init(&COND_server_started,NULL); (void) pthread_cond_init(&COND_server_started,NULL);
sp_cache_init(); sp_cache_init();
Events::init_mutexes(); Events::get_instance()->init_mutexes();
/* Parameter for threads created for connections */ /* Parameter for threads created for connections */
(void) pthread_attr_init(&connection_attrib); (void) pthread_attr_init(&connection_attrib);
(void) pthread_attr_setdetachstate(&connection_attrib, (void) pthread_attr_setdetachstate(&connection_attrib,
...@@ -3673,7 +3673,7 @@ we force server id to 2, but this MySQL server will not act as a slave."); ...@@ -3673,7 +3673,7 @@ we force server id to 2, but this MySQL server will not act as a slave.");
if (!opt_noacl) if (!opt_noacl)
{ {
Events::init(); Events::get_instance()->init();
} }
#if defined(__NT__) || defined(HAVE_SMEM) #if defined(__NT__) || defined(HAVE_SMEM)
handle_connections_methods(); handle_connections_methods();
......
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