1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Bug#43587: Putting event_scheduler=1 in init SQL file crashes

mysqld

The problem was that enabling the event scheduler inside a init
file caused the server to crash upon start-up. The crash occurred
because the event scheduler wasn't being initialized before the
commands in the init-file are processed.

The solution is to initialize the event scheduler before the init
file is read. The patch also disables the event scheduler during
bootstrap and makes the bootstrap operation robust in the
presence of background threads.

mysql-test/std_data/init_file.dat:
  Add test case for Bug#43587
sql/event_scheduler.cc:
  Signal that the thread_count has been decremented.
sql/events.cc:
  Disable the event scheduler during bootstrap.
sql/mysql_priv.h:
  Export variable.
sql/mysqld.cc:
  Initialize the event scheduler before commands are executed.
sql/sql_parse.cc:
  Signal that the bootstrap thread is done.
This commit is contained in:
Davi Arnaut
2009-07-24 15:45:42 -03:00
6 changed files with 61 additions and 29 deletions

View File

@@ -852,22 +852,23 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */)
}
/*
Inits the scheduler's structures.
/**
Initializes the scheduler's structures.
SYNOPSIS
Events::init()
@param opt_noacl_or_bootstrap
TRUE if there is --skip-grant-tables or --bootstrap
option. In that case we disable the event scheduler.
NOTES
This function is not synchronized.
@note This function is not synchronized.
RETURN VALUE
FALSE OK
TRUE Error in case the scheduler can't start
@retval FALSE Perhaps there was an error, and the event scheduler
is disabled. But the error is not fatal and the
server start up can continue.
@retval TRUE Fatal error. Startup must terminate (call unireg_abort()).
*/
bool
Events::init(my_bool opt_noacl)
Events::init(my_bool opt_noacl_or_bootstrap)
{
THD *thd;
@@ -875,11 +876,6 @@ Events::init(my_bool opt_noacl)
DBUG_ENTER("Events::init");
/* Disable the scheduler if running with --skip-grant-tables */
if (opt_noacl)
opt_event_scheduler= EVENTS_DISABLED;
/* We need a temporary THD during boot */
if (!(thd= new THD()))
{
@@ -908,23 +904,30 @@ Events::init(my_bool opt_noacl)
/*
Since we allow event DDL even if the scheduler is disabled,
check the system tables, as we might need them.
If run with --skip-grant-tables or --bootstrap, don't try to do the
check of system tables and don't complain: in these modes the tables
are most likely not there and we're going to disable the event
scheduler anyway.
*/
if (Event_db_repository::check_system_tables(thd))
if (opt_noacl_or_bootstrap || Event_db_repository::check_system_tables(thd))
{
sql_print_error("Event Scheduler: An error occurred when initializing "
"system tables.%s",
opt_event_scheduler == EVENTS_DISABLED ?
"" : " Disabling the Event Scheduler.");
if (! opt_noacl_or_bootstrap)
{
sql_print_error("Event Scheduler: An error occurred when initializing "
"system tables. Disabling the Event Scheduler.");
check_system_tables_error= TRUE;
}
/* Disable the scheduler since the system tables are not up to date */
opt_event_scheduler= EVENTS_DISABLED;
check_system_tables_error= TRUE;
goto end;
}
/*
Was disabled explicitly from the command line, or because we're running
with --skip-grant-tables, or because we have no system tables.
with --skip-grant-tables, or --bootstrap, or because we have no system
tables.
*/
if (opt_event_scheduler == Events::EVENTS_DISABLED)
goto end;
@@ -941,7 +944,7 @@ Events::init(my_bool opt_noacl)
}
if (event_queue->init_queue(thd) || load_events_from_db(thd) ||
opt_event_scheduler == EVENTS_ON && scheduler->start())
(opt_event_scheduler == EVENTS_ON && scheduler->start()))
{
sql_print_error("Event Scheduler: Error while loading from disk.");
res= TRUE; /* fatal error: request unireg_abort */