MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Event Scheduler
Collaboration diagram for Event Scheduler:

Files

file  event_data_objects.h
file  event_db_repository.h
file  event_queue.h
file  event_scheduler.h
file  events.h

Classes

class  Event_creation_ctx
class  Event_queue_element_for_exec
class  Event_basic
class  Event_queue_element
class  Event_timed
class  Event_job_data
class  Event_db_intact
class  Event_db_repository
class  Event_queue
struct  scheduler_param
class  Event_worker_thread
class  Event_scheduler
class  Events
 A facade to the functionality of the Event Scheduler. More...

Macros

#define EVENT_QUEUE_INITIAL_SIZE   30
#define EVENT_QUEUE_EXTENT   30
#define SCHED_FUNC   "<unknown>"
#define LOCK_QUEUE_DATA()   lock_data(SCHED_FUNC, __LINE__)
#define UNLOCK_QUEUE_DATA()   unlock_data(SCHED_FUNC, __LINE__)
#define SCHED_FUNC   "<unknown>"
#define LOCK_DATA()   lock_data(SCHED_FUNC, __LINE__)
#define UNLOCK_DATA()   unlock_data(SCHED_FUNC, __LINE__)
#define COND_STATE_WAIT(mythd, abstime, stage)   cond_wait(mythd, abstime, stage, SCHED_FUNC, __FILE__, __LINE__)

Typedefs

typedef struct charset_info_st CHARSET_INFO

Enumerations

enum  enum_events_table_field {
  ET_FIELD_DB = 0, ET_FIELD_NAME, ET_FIELD_BODY, ET_FIELD_DEFINER,
  ET_FIELD_EXECUTE_AT, ET_FIELD_INTERVAL_EXPR, ET_FIELD_TRANSIENT_INTERVAL, ET_FIELD_CREATED,
  ET_FIELD_MODIFIED, ET_FIELD_LAST_EXECUTED, ET_FIELD_STARTS, ET_FIELD_ENDS,
  ET_FIELD_STATUS, ET_FIELD_ON_COMPLETION, ET_FIELD_SQL_MODE, ET_FIELD_COMMENT,
  ET_FIELD_ORIGINATOR, ET_FIELD_TIME_ZONE, ET_FIELD_CHARACTER_SET_CLIENT, ET_FIELD_COLLATION_CONNECTION,
  ET_FIELD_DB_COLLATION, ET_FIELD_BODY_UTF8, ET_FIELD_COUNT
}

Functions

bool event_basic_db_equal (LEX_STRING db, Event_basic *et)
bool event_basic_identifier_equal (LEX_STRING db, LEX_STRING name, Event_basic *b)
int events_table_index_read_for_db (THD *thd, TABLE *schema_table, TABLE *event_table)
int events_table_scan_all (THD *thd, TABLE *schema_table, TABLE *event_table)
int event_queue_element_compare_q (void *, uchar *, uchar *)
bool post_init_event_thread (THD *thd)
void deinit_event_thread (THD *thd)
void pre_init_event_thread (THD *thd)
pthread_handler_t event_scheduler_thread (void *arg)
pthread_handler_t event_worker_thread (void *arg)
int sortcmp_lex_string (LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs)
static bool Event_creation_ctx::load_from_db (THD *thd, MEM_ROOT *event_mem_root, const char *db_name, const char *event_name, TABLE *event_tbl, Stored_program_creation_ctx **ctx)
bool Event_queue_element_for_exec::init (LEX_STRING dbname, LEX_STRING name)
bool Event_basic::load_string_fields (Field **fields,...)
bool Event_basic::load_time_zone (THD *thd, const LEX_STRING tz_name)
void Event_timed::init ()
virtual bool Event_job_data::load_from_row (THD *thd, TABLE *table)
virtual bool Event_queue_element::load_from_row (THD *thd, TABLE *table)
virtual bool Event_timed::load_from_row (THD *thd, TABLE *table)
bool Event_queue_element::compute_next_execution_time ()
void Event_queue_element::mark_last_executed (THD *thd)
int Event_timed::get_create_event (THD *thd, String *buf)
bool Event_job_data::execute (THD *thd, bool drop)
bool Event_db_repository::fill_schema_events (THD *thd, TABLE_LIST *tables, const char *db)
static bool Event_db_repository::open_event_table (THD *thd, enum thr_lock_type lock_type, TABLE **table)
bool Event_db_repository::create_event (THD *thd, Event_parse_data *parse_data, bool create_if_not, bool *event_already_exists)
bool Event_db_repository::update_event (THD *thd, Event_parse_data *parse_data, LEX_STRING *new_dbname, LEX_STRING *new_name)
bool Event_db_repository::drop_event (THD *thd, LEX_STRING db, LEX_STRING name, bool drop_if_exists)
bool Event_db_repository::find_named_event (LEX_STRING db, LEX_STRING name, TABLE *table)
void Event_db_repository::drop_schema_events (THD *thd, LEX_STRING schema)
bool Event_db_repository::load_named_event (THD *thd, LEX_STRING dbname, LEX_STRING name, Event_basic *et)
bool Event_db_repository::update_timing_fields_for_event (THD *thd, LEX_STRING event_db_name, LEX_STRING event_name, my_time_t last_executed, ulonglong status)
static bool Event_db_repository::check_system_tables (THD *thd)
bool Event_queue::init_queue (THD *thd)
bool Event_queue::create_event (THD *thd, Event_queue_element *new_element, bool *created)
void Event_queue::update_event (THD *thd, LEX_STRING dbname, LEX_STRING name, Event_queue_element *new_element)
void Event_queue::drop_event (THD *thd, LEX_STRING dbname, LEX_STRING name)
void Event_queue::drop_schema_events (THD *thd, LEX_STRING schema)
void Event_queue::recalculate_activation_times (THD *thd)
bool Event_queue::get_top_for_execution_if_time (THD *thd, Event_queue_element_for_exec **event_name)
void Event_queue::dump_internal_status ()
void Event_worker_thread::run (THD *thd, Event_queue_element_for_exec *event)
 Event_scheduler::Event_scheduler (Event_queue *event_queue_arg)
bool Event_scheduler::start (int *err_no)
bool Event_scheduler::run (THD *thd)
bool Event_scheduler::is_running ()
bool Event_scheduler::stop ()
void Event_scheduler::dump_internal_status ()
static bool Events::check_if_system_tables_error ()
static int Events::reconstruct_interval_expression (String *buf, interval_type interval, longlong expression)
static bool Events::create_event (THD *thd, Event_parse_data *parse_data, bool if_exists)
static bool Events::update_event (THD *thd, Event_parse_data *parse_data, LEX_STRING *new_dbname, LEX_STRING *new_name)
static bool Events::drop_event (THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists)
static void Events::drop_schema_events (THD *thd, char *db)
static bool Events::show_create_event (THD *thd, LEX_STRING dbname, LEX_STRING name)
static int Events::fill_schema_events (THD *thd, TABLE_LIST *tables, Item *)
static bool Events::init (my_bool opt_noacl)
static void Events::deinit ()
static void Events::init_mutexes ()
static void Events::dump_internal_status ()
static bool Events::start (int *err_no)
static bool Events::stop ()

Variables

pthread_attr_t connection_attrib
PSI_stage_info stage_waiting_on_empty_queue = { 0, "Waiting on empty queue", 0}
PSI_stage_info stage_waiting_for_next_activation = { 0, "Waiting for next activation", 0}
PSI_stage_info stage_waiting_for_scheduler_to_stop = { 0, "Waiting for the scheduler to stop", 0}
PSI_stage_info stage_waiting_on_empty_queue
PSI_stage_info stage_waiting_for_next_activation
PSI_stage_info stage_waiting_for_scheduler_to_stop
static ulong Events::opt_event_scheduler = Events::EVENTS_OFF

Detailed Description

Function Documentation

bool Events::check_if_system_tables_error ( )
static

Push an error into the error stack if the system tables are not up to date.

Definition at line 112 of file events.cc.

Here is the caller graph for this function:

bool Event_db_repository::check_system_tables ( THD *  thd)
static

Open mysql.db, mysql.user and mysql.event and check whether:

  • mysql.db exists and is up to date (or from a newer version of MySQL),
  • mysql.user has column Event_priv at an expected position,
  • mysql.event exists and is up to date (or from a newer version of MySQL)

This function is called only when the server is started.

Precondition
The passed in thread handle has no open tables.
Return values
FALSEOK
TRUEError, an error message is output to the error log.

Definition at line 1190 of file event_db_repository.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Event_queue::create_event ( THD *  thd,
Event_queue_element new_element,
bool *  created 
)

Adds an event to the queue.

Compute the next execution time for an event, and if it is still active, add it to the queue. Otherwise delete it. The object is left intact in case of an error. Otherwise the queue container assumes ownership of it.

Parameters
[in]thdthread handle
[in]new_elementa new element to add to the queue
[out]createdset to TRUE if no error and the element is added to the queue, FALSE otherwise
Return values
TRUEan error occured. The value of created is undefined, the element was not deleted.
FALSEsuccess

Definition at line 199 of file event_queue.cc.

Here is the caller graph for this function:

bool Event_db_repository::create_event ( THD *  thd,
Event_parse_data parse_data,
bool  create_if_not,
bool *  event_already_exists 
)

Creates an event record in mysql.event table.

Creates an event. Relies on mysql_event_fill_row which is shared with ::update_event.

Precondition
All semantic checks must be performed outside. This function only creates a record on disk.
The thread handle has no open tables.
Parameters
[in,out]thdTHD
[in]parse_dataParsed event definition
[in]create_if_notTRUE if IF NOT EXISTS clause was provided to CREATE EVENT statement
[out]event_already_existsWhen method is completed successfully set to true if event already exists else set to false
Return values
FALSEsuccess
TRUEerror

Definition at line 658 of file event_db_repository.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Events::create_event ( THD *  thd,
Event_parse_data parse_data,
bool  if_not_exists 
)
static

Create a new event.

Parameters
[in,out]thdTHD
[in]parse_dataEvent's data from parsing stage
[in]if_not_existsWhether IF NOT EXISTS was specified In case there is an event with the same name (db) and IF NOT EXISTS is specified, an warning is put into the stack.
See Also
Events::drop_event for the notes about locking, pre-locking and Events DDL.
Return values
FALSEOK
TRUEError (reported)

Definition at line 306 of file events.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Event_db_repository::drop_event ( THD *  thd,
LEX_STRING  db,
LEX_STRING  name,
bool  drop_if_exists 
)

Delete event record from mysql.event table.

Parameters
[in,out]thdthread handle
[in]dbDatabase name
[in]nameEvent name
[in]drop_if_existsDROP IF EXISTS clause was specified. If set, and the event does not exist, the error is downgraded to a warning.
Return values
FALSEsuccess
TRUEerror (reported)

Definition at line 888 of file event_db_repository.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Events::drop_event ( THD *  thd,
LEX_STRING  dbname,
LEX_STRING  name,
bool  if_exists 
)
static

Drops an event

Parameters
[in,out]thdTHD
[in]dbnameEvent's schema
[in]nameEvent's name
[in]if_existsWhen this is set and the event does not exist a warning is pushed into the warning stack. Otherwise the operation produces an error.
Note
Similarly to DROP PROCEDURE, we do not allow DROP EVENT under LOCK TABLES mode, unless table mysql.event is locked. To ensure that, we do not reset & backup the open tables state in this function - if in LOCK TABLES or pre-locking mode, this will lead to an error 'Table mysql.event is not locked with LOCK TABLES' unless it is locked. In pre-locked mode there is another barrier - DROP EVENT commits the current transaction, and COMMIT/ROLLBACK is not allowed in stored functions and triggers.
Return values
FALSEOK
TRUEError (reported)

Definition at line 556 of file events.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

void Events::drop_schema_events ( THD *  thd,
char *  db 
)
static

Drops all events from a schema

Note
We allow to drop all events in a schema even if the scheduler is disabled. This is to not produce any warnings in case of DROP DATABASE and a disabled scheduler.
Parameters
[in,out]thdThread
[in]dbASCIIZ schema name

Definition at line 609 of file events.cc.

pthread_handler_t event_worker_thread ( void *  arg)

Function that executes an event in a child thread. Setups the environment for the event execution and cleans after that.

SYNOPSIS event_worker_thread() arg The Event_job_data object to be processed

RETURN VALUE 0 OK

Definition at line 271 of file event_scheduler.cc.

Here is the call graph for this function:

bool Event_job_data::execute ( THD *  thd,
bool  drop 
)

Compiles and executes the event (the underlying sp_head object)

Return values
TRUEerror (reported to the error log)
FALSEsuccess

Definition at line 1329 of file event_data_objects.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Event_db_repository::fill_schema_events ( THD *  thd,
TABLE_LIST i_s_table,
const char *  db 
)

Fills I_S.EVENTS with data loaded from mysql.event. Also used by SHOW EVENTS

The reason we reset and backup open tables here is that this function may be called from any query that accesses INFORMATION_SCHEMA - including a query that is issued from a pre-locked statement, one that already has open and locked tables.

Return values
FALSEsuccess
TRUEerror

Definition at line 536 of file event_db_repository.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

int Events::fill_schema_events ( THD *  thd,
TABLE_LIST tables,
Item  
)
static

Check access rights and fill INFORMATION_SCHEMA.events table.

Parameters
[in,out]thdThread context
[in]tablesThe temporary table to fill.

In MySQL INFORMATION_SCHEMA tables are temporary tables that are created and filled on demand. In this function, we fill INFORMATION_SCHEMA.events. It is a callback for I_S module, invoked from sql_show.cc

Returns
Has to be integer, as such is the requirement of the I_S API
Return values
0success
1an error, pushed into the error stack

Definition at line 763 of file events.cc.

Here is the call graph for this function:

bool Event_db_repository::find_named_event ( LEX_STRING  db,
LEX_STRING  name,
TABLE table 
)

Positions the internal pointer of table to the place where (db, name) is stored.

In case search succeeded, the table cursor points at the found row.

Parameters
[in]dbdatabase name
[in]nameevent name
[in,out]tablemysql.event table
Return values
FALSEan event with such db/name key exists
TRUEno record found or an error occured.

Definition at line 949 of file event_db_repository.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Events::init ( my_bool  opt_noacl_or_bootstrap)
static

Initializes the scheduler's structures.

Parameters
opt_noacl_or_bootstrapTRUE if there is –skip-grant-tables or –bootstrap option. In that case we disable the event scheduler.
Note
This function is not synchronized.
Return values
FALSEPerhaps there was an error, and the event scheduler is disabled. But the error is not fatal and the server start up can continue.
TRUEFatal error. Startup must terminate (call unireg_abort()).

Definition at line 807 of file events.cc.

Here is the call graph for this function:

void Events::init_mutexes ( )
static

Inits Events mutexes

SYNOPSIS Events::init_mutexes() thd Thread

Definition at line 1011 of file events.cc.

bool Event_queue_element::load_from_row ( THD *  thd,
TABLE table 
)
virtual

Load an event's body from a row from mysql.event.

This method is silent on errors and should behave like that. Callers should handle throwing of error messages. The reason is that the class should not know about how to deal with communication.

Returns
Operation status
Return values
FALSEOK
TRUEError

Implements Event_basic.

Reimplemented in Event_timed.

Definition at line 452 of file event_data_objects.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Event_timed::load_from_row ( THD *  thd,
TABLE table 
)
virtual

Load an event's body from a row from mysql.event.

This method is silent on errors and should behave like that. Callers should handle throwing of error messages. The reason is that the class should not know about how to deal with communication.

Returns
Operation status
Return values
FALSEOK
TRUEError

Reimplemented from Event_queue_element.

Definition at line 590 of file event_data_objects.cc.

Here is the call graph for this function:

bool Event_job_data::load_from_row ( THD *  thd,
TABLE table 
)
virtual

Load an event's body from a row from mysql.event.

This method is silent on errors and should behave like that. Callers should handle throwing of error messages. The reason is that the class should not know about how to deal with communication.

Returns
Operation status
Return values
FALSEOK
TRUEError

Implements Event_basic.

Definition at line 391 of file event_data_objects.cc.

bool Event_db_repository::load_named_event ( THD *  thd,
LEX_STRING  dbname,
LEX_STRING  name,
Event_basic etn 
)

Looks for a named event in mysql.event and then loads it from the table.

Precondition
The given thread does not have open tables.
Return values
FALSEsuccess
TRUEerror

Definition at line 1060 of file event_db_repository.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Event_db_repository::open_event_table ( THD *  thd,
enum thr_lock_type  lock_type,
TABLE **  table 
)
static

Open mysql.event table for read.

It's assumed that the caller knows what they are doing:

  • whether it was necessary to reset-and-backup the open tables state
  • whether the requested lock does not lead to a deadlock
  • whether this open mode would work under LOCK TABLES, or inside a stored function or trigger.

Note that if the table can't be locked successfully this operation will close it. Therefore it provides guarantee that it either opens and locks table or fails without leaving any tables open.

Parameters
[in]thdThread context
[in]lock_typeHow to lock the table
[out]tableWe will store the open table here
Return values
TRUEopen and lock failed - an error message is pushed into the stack
FALSEsuccess

Definition at line 611 of file event_db_repository.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

int Events::reconstruct_interval_expression ( String buf,
interval_type  interval,
longlong  expression 
)
static

Reconstructs interval expression from interval type and expression value that is in form of a value of the smalles entity: For YEAR_MONTH - expression is in months DAY_MINUTE - expression is in minutes

SYNOPSIS Events::reconstruct_interval_expression() buf Preallocated String buffer to add the value to interval The interval type (for instance YEAR_MONTH) expression The value in the lowest entity

RETURN VALUE 0 OK 1 Error

Definition at line 145 of file events.cc.

void Event_worker_thread::run ( THD *  thd,
Event_queue_element_for_exec event 
)

Function that executes an event in a child thread. Setups the environment for the event execution and cleans after that.

SYNOPSIS Event_worker_thread::run() thd Thread context event The Event_queue_element_for_exec object to be processed

Definition at line 299 of file event_scheduler.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Events::show_create_event ( THD *  thd,
LEX_STRING  dbname,
LEX_STRING  name 
)
static

Implement SHOW CREATE EVENT statement

thd   Thread context
spn   The name of the event (db, name)
Return values
FALSEOK
TRUEerror (reported)

Definition at line 713 of file events.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Event_scheduler::start ( int *  err_no)

Starts the scheduler (again). Creates a new THD and passes it to a forked thread. Does not wait for acknowledgement from the new thread that it has started. Asynchronous starting. Most of the needed initializations are done in the current thread to minimize the chance of failure in the spawned thread.

Parameters
[out]err_no- errno indicating type of error which caused failure to start scheduler thread.
Returns
Return values
falseSuccess.
trueError.

Definition at line 386 of file event_scheduler.cc.

Here is the caller graph for this function:

bool Event_scheduler::stop ( )

Stops the scheduler (again). Waits for acknowledgement from the scheduler that it has stopped - synchronous stopping.

Already running events will not be stopped. If the user needs them stopped manual intervention is needed.

SYNOPSIS Event_scheduler::stop()

RETURN VALUE FALSE OK TRUE Error (not reported)

Definition at line 636 of file event_scheduler.cc.

bool Event_db_repository::update_event ( THD *  thd,
Event_parse_data parse_data,
LEX_STRING new_dbname,
LEX_STRING new_name 
)

Used to execute ALTER EVENT. Pendant to Events::update_event().

Parameters
[in,out]thdthread handle
[in]parse_dataparsed event definition
[in]new_dbnamenot NULL if ALTER EVENT RENAME points at a new database name
[in]new_namenot NULL if ALTER EVENT RENAME points at a new event name
Precondition
All semantic checks are performed outside this function, it only updates the event definition on disk.
We don't have any tables open in the given thread.
Return values
FALSEsuccess
TRUEerror (reported)

Definition at line 777 of file event_db_repository.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Events::update_event ( THD *  thd,
Event_parse_data parse_data,
LEX_STRING new_dbname,
LEX_STRING new_name 
)
static

Alter an event.

Parameters
[in,out]thdTHD
[in]parse_dataEvent's data from parsing stage
[in]new_dbnameA new schema name for the event. Set in the case of ALTER EVENT RENAME, otherwise is NULL.
[in]new_nameA new name for the event. Set in the case of ALTER EVENT RENAME

Parameter 'et' contains data about dbname and event name. Parameter 'new_name' is the new name of the event, if not null this means that RENAME TO was specified in the query

See Also
Events::drop_event for the locking notes.
Return values
FALSEOK
TRUEerror (reported)

Definition at line 431 of file events.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Event_db_repository::update_timing_fields_for_event ( THD *  thd,
LEX_STRING  event_db_name,
LEX_STRING  event_name,
my_time_t  last_executed,
ulonglong  status 
)

Update the event record in mysql.event table with a changed status and/or last execution time.

Precondition
The thread handle does not have open tables.

Definition at line 1114 of file event_db_repository.cc.

Here is the call graph for this function: