MySQL 8.0.40
Source Code Documentation
Event Scheduler
Collaboration diagram for Event Scheduler:

Files

file  event_data_objects.h
 
file  event_db_repository.h
 Data Dictionary related operations of Event Scheduler.
 
file  event_queue.h
 Queue of events awaiting execution.
 
file  event_scheduler.h
 Declarations of the scheduler thread class and related functionality.
 
file  events.h
 A public interface of Events_Scheduler module.
 

Namespaces

namespace  dd
 The version of the current data dictionary table definitions.
 

Classes

class  Event_creation_ctx
 Event_creation_ctx – creation context of events. More...
 
class  Event_queue_element_for_exec
 
class  Event_basic
 
class  Event_queue_element
 
class  Event_timed
 
class  Event_job_data
 
class  Event_db_repository
 
struct  Event_queue_less
 
class  Event_queue
 Queue of active events awaiting execution. More...
 
struct  scheduler_param
 
class  Is_worker
 This class implements callback for do_for_all_thd(). More...
 
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 LOCK_QUEUE_DATA()   lock_data(__func__, __LINE__)
 
#define UNLOCK_QUEUE_DATA()   unlock_data(__func__, __LINE__)
 
#define LOCK_DATA()   lock_data(__func__, __LINE__)
 
#define UNLOCK_DATA()   unlock_data(__func__, __LINE__)
 
#define COND_STATE_WAIT(mythd, abstime, stage)    cond_wait(mythd, abstime, stage, __func__, __FILE__, __LINE__)
 

Typedefs

typedef ulonglong sql_mode_t
 

Functions

void init_scheduler_psi_keys ()
 
static LEX_STRING make_lex_string (MEM_ROOT *mem_root, const dd::String_type &str)
 
static LEX_CSTRING make_lex_cstring (MEM_ROOT *mem_root, const dd::String_type &str)
 
static my_time_t add_interval (MYSQL_TIME *ltime, const Time_zone *time_zone, interval_type scale, Interval interval)
 
static bool get_next_time (const Time_zone *time_zone, my_time_t *next, my_time_t start, my_time_t time_now, int i_value, interval_type i_type)
 Computes the sum of a timestamp plus interval. More...
 
static void append_datetime (String *buf, Time_zone *time_zone, my_time_t secs, const char *name, uint len)
 
bool construct_drop_event_sql (THD *thd, String *sp_sql, LEX_CSTRING schema_name, LEX_CSTRING event_name)
 Get DROP EVENT statement to binlog the drop of ON COMPLETION NOT PRESERVE event. More...
 
bool event_basic_db_equal (LEX_CSTRING db, Event_basic *et)
 
bool event_basic_identifier_equal (LEX_CSTRING db, LEX_CSTRING name, Event_basic *b)
 
bool post_init_event_thread (THD *thd)
 
void deinit_event_thread (THD *thd)
 
void pre_init_event_thread (THD *thd)
 
static void * event_scheduler_thread (void *arg)
 
static void * event_worker_thread (void *arg)
 Function that executes an event in a child thread. More...
 
static bool load_events_from_db (THD *thd, Event_queue *event_queue)
 Loads all ENABLED events into a prioritized queue. More...
 
int sortcmp_lex_string (LEX_CSTRING s, LEX_CSTRING t, const CHARSET_INFO *cs)
 
static int create_query_string (THD *thd, String *buf)
 Create a new query string for removing executable comments for avoiding leak and keeping consistency of the execution on master and slave. More...
 
static bool send_show_create_event (THD *thd, Event_timed *et, Protocol *protocol)
 A helper function to generate SHOW CREATE EVENT output from a named event. More...
 
static void init_events_psi_keys (void)
 
static bool Event_creation_ctx::create_event_creation_ctx (const dd::Event &event_obj, Stored_program_creation_ctx **ctx)
 
bool Event_queue_element_for_exec::init (LEX_CSTRING dbname, LEX_CSTRING name)
 
void Event_queue_element_for_exec::claim_memory_ownership (bool claim)
 
 Event_queue_element_for_exec::~Event_queue_element_for_exec ()
 
 Event_basic::Event_basic ()
 
virtual Event_basic::~Event_basic ()
 
 Event_queue_element::Event_queue_element ()
 
 Event_queue_element::~Event_queue_element () override
 
 Event_timed::Event_timed ()
 
 Event_timed::~Event_timed () override
 
 Event_job_data::Event_job_data ()
 
void Event_timed::init ()
 
bool Event_job_data::fill_event_info (THD *thd, const dd::Event &event, const char *schema_name) override
 
bool Event_queue_element::fill_event_info (THD *thd, const dd::Event &event, const char *dbname) override
 
bool Event_timed::fill_event_info (THD *thd, const dd::Event &event, const char *schema_name) override
 
bool Event_queue_element::compute_next_execution_time (THD *thd)
 
void Event_queue_element::mark_last_executed (THD *thd)
 Set last execution time. More...
 
int Event_timed::get_create_event (const THD *thd, String *buf)
 Get SHOW CREATE EVENT as string. More...
 
bool Event_job_data::construct_sp_sql (THD *thd, String *sp_sql)
 Get an artificial stored procedure to parse as an event definition. More...
 
bool Event_job_data::execute (THD *thd, bool drop)
 Compiles and executes the event (the underlying sp_head object) More...
 
static bool Event_db_repository::create_event (THD *thd, Event_parse_data *parse_data, bool create_if_not, bool *event_already_exists)
 Creates an event object and persist to Data Dictionary. More...
 
static bool Event_db_repository::update_event (THD *thd, Event_parse_data *parse_data, const LEX_CSTRING *new_dbname, const LEX_CSTRING *new_name)
 Used to execute ALTER EVENT. More...
 
static bool Event_db_repository::drop_event (THD *thd, LEX_CSTRING db, LEX_CSTRING name, bool drop_if_exists, bool *event_exists)
 Delete event. More...
 
static bool Event_db_repository::drop_schema_events (THD *thd, const dd::Schema &schema)
 Drops all events in the selected database. More...
 
static bool Event_db_repository::load_named_event (THD *thd, LEX_CSTRING dbname, LEX_CSTRING name, Event_basic *et)
 Looks for a named event in the Data Dictionary and load it. More...
 
static bool Event_db_repository::update_timing_fields_for_event (THD *thd, LEX_CSTRING event_db_name, LEX_CSTRING event_name, my_time_t last_executed, ulonglong status)
 Update the event in Data Dictionary with changed status and/or last execution time. More...
 
 Event_queue::Event_queue ()
 
 Event_queue::~Event_queue ()
 
bool Event_queue::init_queue ()
 
void Event_queue::deinit_queue ()
 
bool Event_queue::create_event (THD *thd, Event_queue_element *new_element, bool *created)
 Adds an event to the queue. More...
 
void Event_queue::update_event (THD *thd, LEX_CSTRING dbname, LEX_CSTRING name, Event_queue_element *new_element)
 
void Event_queue::drop_event (THD *thd, LEX_CSTRING dbname, LEX_CSTRING name)
 
void Event_queue::drop_matching_events (LEX_CSTRING pattern, bool(*)(LEX_CSTRING, Event_basic *))
 
void Event_queue::drop_schema_events (LEX_CSTRING schema)
 
void Event_queue::find_n_remove_event (LEX_CSTRING db, LEX_CSTRING name)
 
void Event_queue::recalculate_activation_times (THD *thd)
 
void Event_queue::empty_queue ()
 
void Event_queue::dbug_dump_queue (time_t now)
 
bool Event_queue::get_top_for_execution_if_time (THD *thd, Event_queue_element_for_exec **event_name)
 
void Event_queue::lock_data (const char *func, uint line)
 
void Event_queue::unlock_data (const char *func, uint line)
 
void Event_queue::cond_wait (THD *thd, struct timespec *abstime, const PSI_stage_info *stage, const char *src_func, const char *src_file, uint src_line)
 
void Event_queue::dump_internal_status ()
 
void Event_worker_thread::print_warnings (THD *thd, Event_job_data *et)
 
void Event_worker_thread::run (THD *thd, Event_queue_element_for_exec *event)
 Function that executes an event in a child thread. More...
 
 Event_scheduler::Event_scheduler (Event_queue *event_queue_arg)
 
 Event_scheduler::~Event_scheduler ()
 
bool Event_scheduler::start (int *err_no)
 Starts the scheduler (again). More...
 
bool Event_scheduler::run (THD *thd)
 
bool Event_scheduler::execute_top (Event_queue_element_for_exec *event_name)
 
bool Event_scheduler::is_running ()
 
bool Event_scheduler::stop ()
 Stops the scheduler (again). More...
 
int Event_scheduler::workers_count ()
 
void Event_scheduler::lock_data (const char *func, uint line)
 
void Event_scheduler::unlock_data (const char *func, uint line)
 
void Event_scheduler::cond_wait (THD *thd, struct timespec *abstime, const PSI_stage_info *stage, const char *src_func, const char *src_file, uint src_line)
 
void Event_scheduler::dump_internal_status ()
 
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)
 Create a new event. More...
 
static bool Events::update_event (THD *thd, Event_parse_data *parse_data, const LEX_CSTRING *new_dbname, const LEX_CSTRING *new_name)
 Alter an event. More...
 
static bool Events::drop_event (THD *thd, LEX_CSTRING dbname, LEX_CSTRING name, bool if_exists)
 Drops an event. More...
 
static bool Events::lock_schema_events (THD *thd, const dd::Schema &schema)
 Take exclusive metadata lock on all events in a schema. More...
 
static bool Events::drop_schema_events (THD *thd, const dd::Schema &schema)
 Drops all events from a schema. More...
 
static bool Events::show_create_event (THD *thd, LEX_CSTRING dbname, LEX_CSTRING name)
 Implement SHOW CREATE EVENT statement. More...
 
static bool Events::init (bool opt_noacl)
 Initializes the scheduler's structures. More...
 
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

PSI_mutex_key key_LOCK_event_queue
 
PSI_cond_key key_COND_queue_state
 
my_thread_attr_t connection_attrib
 
static const LEX_CSTRING scheduler_states_names []
 
PSI_mutex_key key_LOCK_event_queue
 
PSI_mutex_key key_event_scheduler_LOCK_scheduler_state
 
static PSI_mutex_info all_events_mutexes []
 
PSI_cond_key key_event_scheduler_COND_state
 
PSI_cond_key key_COND_queue_state
 
static PSI_cond_info all_events_conds []
 
PSI_thread_key key_thread_event_scheduler
 
PSI_thread_key key_thread_event_worker
 
static PSI_thread_info all_events_threads []
 
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
 
PSI_memory_key key_memory_event_basic_root
 
PSI_stage_infoall_events_stages []
 
static PSI_memory_info all_events_memory []
 
PSI_mutex_key key_event_scheduler_LOCK_scheduler_state
 
PSI_cond_key key_event_scheduler_COND_state
 
PSI_thread_key key_thread_event_scheduler
 
PSI_thread_key key_thread_event_worker
 
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 PSI_statement_info Event_queue_element_for_exec::psi_info
 
static Event_queueEvents::event_queue
 
static Event_schedulerEvents::scheduler
 
static ulong Events::opt_event_scheduler = Events::EVENTS_OFF
 

Detailed Description

Macro Definition Documentation

◆ COND_STATE_WAIT

#define COND_STATE_WAIT (   mythd,
  abstime,
  stage 
)     cond_wait(mythd, abstime, stage, __func__, __FILE__, __LINE__)

◆ EVENT_QUEUE_INITIAL_SIZE

#define EVENT_QUEUE_INITIAL_SIZE   30

◆ LOCK_DATA

#define LOCK_DATA ( )    lock_data(__func__, __LINE__)

◆ LOCK_QUEUE_DATA

#define LOCK_QUEUE_DATA ( )    lock_data(__func__, __LINE__)

◆ UNLOCK_DATA

#define UNLOCK_DATA ( )    unlock_data(__func__, __LINE__)

◆ UNLOCK_QUEUE_DATA

#define UNLOCK_QUEUE_DATA ( )    unlock_data(__func__, __LINE__)

Typedef Documentation

◆ sql_mode_t

Function Documentation

◆ Event_basic()

Event_basic::Event_basic ( )

◆ Event_job_data()

Event_job_data::Event_job_data ( )

◆ Event_queue()

Event_queue::Event_queue ( )

◆ Event_queue_element()

Event_queue_element::Event_queue_element ( )

◆ Event_scheduler()

Event_scheduler::Event_scheduler ( Event_queue event_queue_arg)

◆ Event_timed()

Event_timed::Event_timed ( )

◆ ~Event_basic()

Event_basic::~Event_basic ( )
virtual

◆ ~Event_queue()

Event_queue::~Event_queue ( )

◆ ~Event_queue_element()

Event_queue_element::~Event_queue_element ( )
overridedefault

◆ ~Event_queue_element_for_exec()

Event_queue_element_for_exec::~Event_queue_element_for_exec ( )

◆ ~Event_scheduler()

Event_scheduler::~Event_scheduler ( )

◆ ~Event_timed()

Event_timed::~Event_timed ( )
overridedefault

◆ add_interval()

static my_time_t add_interval ( MYSQL_TIME ltime,
const Time_zone time_zone,
interval_type  scale,
Interval  interval 
)
static

◆ append_datetime()

static void append_datetime ( String buf,
Time_zone time_zone,
my_time_t  secs,
const char *  name,
uint  len 
)
static

◆ claim_memory_ownership()

void Event_queue_element_for_exec::claim_memory_ownership ( bool  claim)

◆ compute_next_execution_time()

bool Event_queue_element::compute_next_execution_time ( THD thd)

◆ cond_wait() [1/2]

void Event_queue::cond_wait ( THD thd,
struct timespec *  abstime,
const PSI_stage_info stage,
const char *  src_func,
const char *  src_file,
uint  src_line 
)
private

◆ cond_wait() [2/2]

void Event_scheduler::cond_wait ( THD thd,
struct timespec *  abstime,
const PSI_stage_info stage,
const char *  src_func,
const char *  src_file,
uint  src_line 
)
private

◆ construct_drop_event_sql()

bool construct_drop_event_sql ( THD thd,
String sp_sql,
LEX_CSTRING  db_name,
LEX_CSTRING  event_name 
)

Get DROP EVENT statement to binlog the drop of ON COMPLETION NOT PRESERVE event.

Build an SQL drop event string.

Parameters
[in]thdThread handle
[in,out]sp_sqlPointer to String object where the SQL query will be stored
[in]db_nameThe schema name
[in]event_nameThe event name
Return values
falseThe drop event SQL query is built
trueOtherwise

◆ construct_sp_sql()

bool Event_job_data::construct_sp_sql ( THD thd,
String sp_sql 
)
private

Get an artificial stored procedure to parse as an event definition.

◆ create_event() [1/3]

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

Creates an event object and persist to Data Dictionary.

Precondition
All semantic checks must be performed outside.
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

◆ create_event() [2/3]

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

Create a new event.

Atomicity: The operation to create an event is atomic/crash-safe. Changes to the Data-dictionary and writing event to binlog are part of the same transaction. All the changes are done as part of the same transaction or do not have any side effects on the operation failure. Data-dictionary cache and event queues are in sync with operation state. Cache and event queue does not contain any stale/incorrect data in case of failure. In case of crash, there won't be any discrepancy between the data-dictionary table and the binary log.

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)

◆ create_event() [3/3]

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. 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 occurred. The value of created is undefined, the element was not deleted.
falsesuccess

◆ create_event_creation_ctx()

bool Event_creation_ctx::create_event_creation_ctx ( const dd::Event event_obj,
Stored_program_creation_ctx **  ctx 
)
static

◆ create_query_string()

static int create_query_string ( THD thd,
String buf 
)
static

Create a new query string for removing executable comments for avoiding leak and keeping consistency of the execution on master and slave.

Parameters
[in]thdThread handler
[in]bufQuery string
Returns
0 ok 1 error

◆ dbug_dump_queue()

void Event_queue::dbug_dump_queue ( time_t  now)
private

◆ deinit()

void Events::deinit ( )
static

◆ deinit_event_thread()

void deinit_event_thread ( THD thd)

◆ deinit_queue()

void Event_queue::deinit_queue ( )
private

◆ drop_event() [1/3]

bool Event_db_repository::drop_event ( THD thd,
LEX_CSTRING  db,
LEX_CSTRING  name,
bool  drop_if_exists,
bool *  event_exists 
)
static

Delete event.

Parameters
[in]thdTHD context
[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.
[out]event_existsSet to true if event exists. Set to false otherwise.
Return values
falsesuccess
trueerror (reported)

◆ drop_event() [2/3]

void Event_queue::drop_event ( THD thd,
LEX_CSTRING  dbname,
LEX_CSTRING  name 
)

◆ drop_event() [3/3]

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

Drops an event.

Atomicity: The operation to drop an event is atomic/crash-safe. Changes to the Data-dictionary and writing event to binlog are part of the same transaction. All the changes are done as part of the same transaction or do not have any side effects on the operation failure. Data-dictionary cache and event queues are in sync with operation state. Cache and event queue does not contain any stale/incorrect data in case of failure. In case of crash, there won't be any discrepancy between the data-dictionary table and the binary log.

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)

◆ drop_matching_events()

void Event_queue::drop_matching_events ( LEX_CSTRING  pattern,
bool(*)(LEX_CSTRING, Event_basic *)  comparator 
)
private

◆ drop_schema_events() [1/3]

void Event_queue::drop_schema_events ( LEX_CSTRING  schema)

◆ drop_schema_events() [2/3]

bool Event_db_repository::drop_schema_events ( THD thd,
const dd::Schema schema 
)
static

Drops all events in the selected database.

Parameters
thdTHD context
schemaThe database under which events are to be dropped.
Returns
true on error, false on success.

◆ drop_schema_events() [3/3]

bool Events::drop_schema_events ( THD thd,
const dd::Schema schema 
)
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]thdTHD handle.
[in]schemaSchema object.
Returns
true drop events from database failed.
false drop events from database succeeded.

◆ dump_internal_status() [1/3]

void Event_queue::dump_internal_status ( )

◆ dump_internal_status() [2/3]

void Event_scheduler::dump_internal_status ( )

◆ dump_internal_status() [3/3]

void Events::dump_internal_status ( )
static

◆ empty_queue()

void Event_queue::empty_queue ( )
private

◆ event_basic_db_equal()

bool event_basic_db_equal ( LEX_CSTRING  db,
Event_basic et 
)

◆ event_basic_identifier_equal()

bool event_basic_identifier_equal ( LEX_CSTRING  db,
LEX_CSTRING  name,
Event_basic b 
)

◆ event_scheduler_thread()

static void * event_scheduler_thread ( void *  arg)
static

◆ event_worker_thread()

static void * event_worker_thread ( void *  arg)
static

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

◆ execute()

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

◆ execute_top()

bool Event_scheduler::execute_top ( Event_queue_element_for_exec event_name)
private

◆ fill_event_info() [1/3]

bool Event_queue_element::fill_event_info ( THD thd,
const dd::Event event,
const char *  dbname 
)
overridevirtual

Implements Event_basic.

Reimplemented in Event_timed.

◆ fill_event_info() [2/3]

bool Event_timed::fill_event_info ( THD thd,
const dd::Event event,
const char *  schema_name 
)
overridevirtual

Reimplemented from Event_queue_element.

◆ fill_event_info() [3/3]

bool Event_job_data::fill_event_info ( THD thd,
const dd::Event event,
const char *  schema_name 
)
overrideprivatevirtual

Implements Event_basic.

◆ find_n_remove_event()

void Event_queue::find_n_remove_event ( LEX_CSTRING  db,
LEX_CSTRING  name 
)
private

◆ get_create_event()

int Event_timed::get_create_event ( const THD thd,
String buf 
)

Get SHOW CREATE EVENT as string.

Parameters
thdTHD context.
bufString*, should be already allocated. CREATE EVENT goes inside.
Return values
0OK

◆ get_next_time()

static bool get_next_time ( const Time_zone time_zone,
my_time_t next,
my_time_t  start,
my_time_t  time_now,
int  i_value,
interval_type  i_type 
)
static

Computes the sum of a timestamp plus interval.

Parameters
time_zoneevent time zone
nextthe sum
startadd interval_value to this time
time_nowcurrent time
i_valuequantity of time type interval to add
i_typetype of interval to add (SECOND, MINUTE, HOUR, WEEK ...)
Return values
0on success
1on error.
Note
  1. If the interval is conversible to SECOND, like MINUTE, HOUR, DAY, WEEK. Then we use TIMEDIFF()'s implementation as underlying and number of seconds as resolution for computation.
  2. In all other cases - MONTH, QUARTER, YEAR we use MONTH as resolution and PERIOD_DIFF()'s implementation

◆ get_top_for_execution_if_time()

bool Event_queue::get_top_for_execution_if_time ( THD thd,
Event_queue_element_for_exec **  event_name 
)

◆ init() [1/3]

void Event_timed::init ( )

◆ init() [2/3]

bool Events::init ( bool  opt_noacl_or_bootstrap)
static

Initializes the scheduler's structures.

Parameters
opt_noacl_or_bootstraptrue if there is –skip-grant-tables or –initialize. 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()).

◆ init() [3/3]

bool Event_queue_element_for_exec::init ( LEX_CSTRING  dbname,
LEX_CSTRING  name 
)

◆ init_events_psi_keys()

static void init_events_psi_keys ( void  )
static

◆ init_mutexes()

void Events::init_mutexes ( )
static

◆ init_queue()

bool Event_queue::init_queue ( )

◆ init_scheduler_psi_keys()

void init_scheduler_psi_keys ( )

◆ is_running()

bool Event_scheduler::is_running ( )

◆ load_events_from_db()

static bool load_events_from_db ( THD thd,
Event_queue event_queue 
)
static

Loads all ENABLED events into a prioritized queue.

This function is called during the server start up. It reads every event, computes the next execution time, and if the event needs execution, adds it to a prioritized queue. Otherwise, if ON COMPLETION DROP is specified, the event is automatically removed from the table.

Parameters
thdTHD context. Used for memory allocation in some cases.
event_queuePointer to Event_queue object.
Return values
falsesuccess
trueerror, the load is aborted
Note
Reports the error to the console

◆ load_named_event()

bool Event_db_repository::load_named_event ( THD thd,
LEX_CSTRING  dbname,
LEX_CSTRING  name,
Event_basic etn 
)
static

Looks for a named event in the Data Dictionary and load it.

Precondition
The given thread does not have open tables.
Return values
falsesuccess
trueerror

◆ lock_data() [1/2]

void Event_queue::lock_data ( const char *  func,
uint  line 
)
private

◆ lock_data() [2/2]

void Event_scheduler::lock_data ( const char *  func,
uint  line 
)
private

◆ lock_schema_events()

bool Events::lock_schema_events ( THD thd,
const dd::Schema schema 
)
static

Take exclusive metadata lock on all events in a schema.

Parameters
thdThread handle.
schemaSchema object.

◆ make_lex_cstring()

static LEX_CSTRING make_lex_cstring ( MEM_ROOT mem_root,
const dd::String_type str 
)
inlinestatic

◆ make_lex_string()

static LEX_STRING make_lex_string ( MEM_ROOT mem_root,
const dd::String_type str 
)
inlinestatic

◆ mark_last_executed()

void Event_queue_element::mark_last_executed ( THD thd)

Set last execution time.

Parameters
thdTHD context

◆ post_init_event_thread()

bool post_init_event_thread ( THD thd)

◆ pre_init_event_thread()

void pre_init_event_thread ( THD thd)

◆ print_warnings()

void Event_worker_thread::print_warnings ( THD thd,
Event_job_data et 
)
private

◆ recalculate_activation_times()

void Event_queue::recalculate_activation_times ( THD thd)

◆ reconstruct_interval_expression()

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

◆ run() [1/2]

bool Event_scheduler::run ( THD thd)

◆ run() [2/2]

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

◆ send_show_create_event()

static bool send_show_create_event ( THD thd,
Event_timed et,
Protocol protocol 
)
static

A helper function to generate SHOW CREATE EVENT output from a named event.

Parameters
[in]thdTHD handle.
[in]etPointer to Event_timed object.
[in]protocolPointer to Protocol object.

◆ show_create_event()

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

Implement SHOW CREATE EVENT statement.

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

◆ sortcmp_lex_string()

int sortcmp_lex_string ( LEX_CSTRING  s,
LEX_CSTRING  t,
const CHARSET_INFO cs 
)

◆ start() [1/2]

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.
Return values
falseSuccess.
trueError.

◆ start() [2/2]

bool Events::start ( int *  err_no)
static

◆ stop() [1/2]

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)

◆ stop() [2/2]

bool Events::stop ( )
static

◆ unlock_data() [1/2]

void Event_queue::unlock_data ( const char *  func,
uint  line 
)
private

◆ unlock_data() [2/2]

void Event_scheduler::unlock_data ( const char *  func,
uint  line 
)
private

◆ update_event() [1/3]

bool Event_db_repository::update_event ( THD thd,
Event_parse_data parse_data,
const LEX_CSTRING new_dbname,
const LEX_CSTRING new_name 
)
static

Used to execute ALTER EVENT.

Pendant to Events::update_event().

Parameters
[in]thdTHD context
[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.
Return values
falseSuccess
trueError (reported)

◆ update_event() [2/3]

bool Events::update_event ( THD thd,
Event_parse_data parse_data,
const LEX_CSTRING new_dbname,
const LEX_CSTRING new_name 
)
static

Alter an event.

Atomicity: The operation to update an event is atomic/crash-safe. Changes to the Data-dictionary and writing event to binlog are part of the same transaction. All the changes are done as part of the same transaction or do not have any side effects on the operation failure. Data-dictionary cache and event queues are in sync with operation state. Cache and event queue does not contain any stale/incorrect data in case of failure. In case of crash, there won't be any discrepancy between the data-dictionary table and the binary log.

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)

◆ update_event() [3/3]

void Event_queue::update_event ( THD thd,
LEX_CSTRING  dbname,
LEX_CSTRING  name,
Event_queue_element new_element 
)

◆ update_timing_fields_for_event()

bool Event_db_repository::update_timing_fields_for_event ( THD thd,
LEX_CSTRING  event_db_name,
LEX_CSTRING  event_name,
my_time_t  last_executed,
ulonglong  status 
)
static

Update the event in Data Dictionary with changed status and/or last execution time.

◆ workers_count()

int Event_scheduler::workers_count ( )
private

Variable Documentation

◆ all_events_conds

PSI_cond_info all_events_conds[]
static
Initial value:
= {
{&key_event_scheduler_COND_state, "Event_scheduler::COND_state",
{&key_COND_queue_state, "COND_queue_state", PSI_FLAG_SINGLETON, 0,
}
#define PSI_DOCUMENT_ME
Definition: component_common.h:29
#define PSI_FLAG_SINGLETON
Singleton flag.
Definition: component_common.h:35
PSI_cond_key key_event_scheduler_COND_state
Definition: events.cc:1015
PSI_cond_key key_COND_queue_state
Definition: events.cc:1015

◆ all_events_memory

PSI_memory_info all_events_memory[]
static
Initial value:
= {
{&key_memory_event_basic_root, "Event_basic::mem_root",
"Event base class with root used for definiton etc."}}
PSI_memory_key key_memory_event_basic_root
Definition: events.cc:1040
#define PSI_FLAG_ONLY_GLOBAL_STAT
Global stat only flag.
Definition: psi_bits.h:112

◆ all_events_mutexes

PSI_mutex_info all_events_mutexes[]
static
Initial value:
=
{
{ &key_event_scheduler_LOCK_scheduler_state, "Event_scheduler::LOCK_scheduler_state", PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME}
}
PSI_mutex_key key_LOCK_event_queue
Definition: events.cc:1005
PSI_mutex_key key_event_scheduler_LOCK_scheduler_state
Definition: events.cc:1005

◆ all_events_stages

PSI_stage_info* all_events_stages[]
Initial value:
PSI_stage_info stage_waiting_on_empty_queue
Definition: events.cc:1033
PSI_stage_info stage_waiting_for_next_activation
Definition: events.cc:1035
PSI_stage_info stage_waiting_for_scheduler_to_stop
Definition: events.cc:1037

◆ all_events_threads

PSI_thread_info all_events_threads[]
static
Initial value:
= {
{&key_thread_event_scheduler, "event_scheduler", "evt_sched",
{&key_thread_event_worker, "event_worker", "evt_wkr", 0, 0,
PSI_thread_key key_thread_event_worker
Definition: events.cc:1024
PSI_thread_key key_thread_event_scheduler
Definition: events.cc:1024

◆ connection_attrib

my_thread_attr_t connection_attrib
extern

◆ event_queue

Event_queue * Events::event_queue
staticprivate

◆ key_COND_queue_state [1/2]

PSI_cond_key key_COND_queue_state
extern

◆ key_COND_queue_state [2/2]

PSI_cond_key key_COND_queue_state

◆ key_event_scheduler_COND_state [1/2]

PSI_cond_key key_event_scheduler_COND_state

◆ key_event_scheduler_COND_state [2/2]

PSI_cond_key key_event_scheduler_COND_state
extern

◆ key_event_scheduler_LOCK_scheduler_state [1/2]

PSI_mutex_key key_event_scheduler_LOCK_scheduler_state

◆ key_event_scheduler_LOCK_scheduler_state [2/2]

PSI_mutex_key key_event_scheduler_LOCK_scheduler_state
extern

◆ key_LOCK_event_queue [1/2]

PSI_mutex_key key_LOCK_event_queue
extern

◆ key_LOCK_event_queue [2/2]

PSI_mutex_key key_LOCK_event_queue

◆ key_memory_event_basic_root

PSI_memory_key key_memory_event_basic_root

◆ key_thread_event_scheduler [1/2]

PSI_thread_key key_thread_event_scheduler

◆ key_thread_event_scheduler [2/2]

PSI_thread_key key_thread_event_scheduler
extern

◆ key_thread_event_worker [1/2]

PSI_thread_key key_thread_event_worker

◆ key_thread_event_worker [2/2]

PSI_thread_key key_thread_event_worker

◆ opt_event_scheduler

ulong Events::opt_event_scheduler = Events::EVENTS_OFF
static

◆ psi_info

PSI_statement_info Event_queue_element_for_exec::psi_info
static
Initial value:
= {0, "event", 0,

◆ scheduler

Event_scheduler * Events::scheduler
staticprivate

◆ scheduler_states_names

const LEX_CSTRING scheduler_states_names[]
static
Initial value:
= {
{STRING_WITH_LEN("INITIALIZED")},
{STRING_WITH_LEN("RUNNING")},
{STRING_WITH_LEN("STOPPING")}}
#define STRING_WITH_LEN(X)
Definition: m_string.h:315

◆ stage_waiting_for_next_activation [1/2]

PSI_stage_info stage_waiting_for_next_activation
Initial value:
= {
0, "Waiting for next activation", 0, PSI_DOCUMENT_ME}

◆ stage_waiting_for_next_activation [2/2]

PSI_stage_info stage_waiting_for_next_activation
extern

◆ stage_waiting_for_scheduler_to_stop [1/2]

PSI_stage_info stage_waiting_for_scheduler_to_stop
Initial value:
= {
0, "Waiting for the scheduler to stop", 0, PSI_DOCUMENT_ME}

◆ stage_waiting_for_scheduler_to_stop [2/2]

PSI_stage_info stage_waiting_for_scheduler_to_stop
extern

◆ stage_waiting_on_empty_queue [1/2]

PSI_stage_info stage_waiting_on_empty_queue
Initial value:
= {0, "Waiting on empty queue", 0,

◆ stage_waiting_on_empty_queue [2/2]

PSI_stage_info stage_waiting_on_empty_queue
extern