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)
DBUG_ENTER("Event_timed::drop");
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,
const LEX_STRING ev_name,
TABLE *table)
{
return Events::get_instance()->db_repository.
return Events::get_instance()->db_repository->
find_event_by_name(thd, dbname, ev_name, table);
}
......
......@@ -258,7 +258,7 @@ int
Events::open_event_table(THD *thd, enum thr_lock_type lock_type,
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,
DBUG_PRINT("enter", ("name: %*s options:%d", et->name.length,
et->name.str, create_options));
if (!(ret= db_repository.
if (!(ret= db_repository->
create_event(thd, et,
create_options & HA_LEX_CREATE_IF_NOT_EXISTS,
rows_affected)))
......@@ -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.
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();
if (scheduler->initialized() &&
......@@ -376,7 +376,7 @@ Events::drop_event(THD *thd, sp_name *name, bool drop_if_exists,
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)))
{
Event_scheduler *scheduler= Event_scheduler::get_instance();
......@@ -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));
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);
if (!ret)
......@@ -484,7 +484,7 @@ Events::drop_schema_events(THD *thd, char *db)
Event_scheduler *scheduler= Event_scheduler::get_instance();
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);
}
......@@ -510,15 +510,14 @@ Events::init()
int ret= 0;
Event_db_repository *db_repo;
DBUG_ENTER("Events::init");
db_repo= &get_instance()->db_repository;
db_repo->init_repository();
db_repository->init_repository();
/* it should be an assignment! */
if (opt_event_scheduler)
{
Event_scheduler *scheduler= Event_scheduler::get_instance();
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():
scheduler->start_suspended()));
}
......@@ -540,18 +539,52 @@ void
Events::deinit()
{
DBUG_ENTER("Events::deinit");
Event_scheduler *scheduler= Event_scheduler::get_instance();
if (scheduler->initialized())
{
scheduler->stop();
scheduler->destroy();
}
get_instance()->db_repository.deinit_repository();
db_repository->deinit_repository();
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
......@@ -603,34 +636,5 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */)
DBUG_RETURN(1);
db= thd->lex->select_lex.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();
DBUG_RETURN(get_instance()->db_repository->fill_schema_events(thd, tables, db));
}
......@@ -19,8 +19,7 @@
class sp_name;
class Event_timed;
class Event_parse_data;
#include "event_db_repository.h"
class Event_db_repository;
/* Return codes */
enum enum_events_error_code
......@@ -51,16 +50,16 @@ public:
static ulong opt_event_scheduler;
static TYPELIB opt_typelib;
static int
int
init();
static void
void
deinit();
static void
void
init_mutexes();
static void
void
destroy_mutexes();
static Events*
......@@ -77,6 +76,9 @@ public:
int
drop_event(THD *thd, sp_name *name, bool drop_if_exists, uint *rows_affected);
int
drop_schema_events(THD *thd, char *db);
int
open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE **table);
......@@ -88,16 +90,13 @@ public:
reconstruct_interval_expression(String *buf, interval_type interval,
longlong expression);
int
drop_schema_events(THD *thd, char *db);
static int
fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */);
int
dump_internal_status(THD *thd);
Event_db_repository db_repository;
Event_db_repository *db_repository;
private:
/* Singleton DP is used */
......@@ -107,7 +106,6 @@ private:
/* Singleton instance */
static Events singleton;
/* Prevent use of these */
Events(const Events &);
void operator=(Events &);
......
......@@ -886,7 +886,7 @@ static void close_connections(void)
}
(void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list
Events::deinit();
Events::get_instance()->deinit();
end_slave();
if (thread_count)
......@@ -1321,7 +1321,7 @@ static void clean_up_mutexes()
(void) pthread_mutex_destroy(&LOCK_bytes_sent);
(void) pthread_mutex_destroy(&LOCK_bytes_received);
(void) pthread_mutex_destroy(&LOCK_user_conn);
Events::destroy_mutexes();
Events::get_instance()->destroy_mutexes();
#ifdef HAVE_OPENSSL
(void) pthread_mutex_destroy(&LOCK_des_key_file);
#ifndef HAVE_YASSL
......@@ -2884,7 +2884,7 @@ static int init_thread_environment()
(void) pthread_mutex_init(&LOCK_server_started, MY_MUTEX_INIT_FAST);
(void) pthread_cond_init(&COND_server_started,NULL);
sp_cache_init();
Events::init_mutexes();
Events::get_instance()->init_mutexes();
/* Parameter for threads created for connections */
(void) pthread_attr_init(&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.");
if (!opt_noacl)
{
Events::init();
Events::get_instance()->init();
}
#if defined(__NT__) || defined(HAVE_SMEM)
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