MySQL 8.4.2
Source Code Documentation
|
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 | |
using | sql_mode_t = uint64_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 () |
#define COND_STATE_WAIT | ( | mythd, | |
abstime, | |||
stage | |||
) | cond_wait(mythd, abstime, stage, __func__, __FILE__, __LINE__) |
#define EVENT_QUEUE_INITIAL_SIZE 30 |
#define LOCK_DATA | ( | ) | lock_data(__func__, __LINE__) |
#define LOCK_QUEUE_DATA | ( | ) | lock_data(__func__, __LINE__) |
#define UNLOCK_DATA | ( | ) | unlock_data(__func__, __LINE__) |
#define UNLOCK_QUEUE_DATA | ( | ) | unlock_data(__func__, __LINE__) |
using sql_mode_t = uint64_t |
Event_basic::Event_basic | ( | ) |
Event_job_data::Event_job_data | ( | ) |
Event_queue::Event_queue | ( | ) |
Event_queue_element::Event_queue_element | ( | ) |
Event_scheduler::Event_scheduler | ( | Event_queue * | event_queue_arg | ) |
Event_timed::Event_timed | ( | ) |
|
virtual |
Event_queue::~Event_queue | ( | ) |
|
overridedefault |
Event_queue_element_for_exec::~Event_queue_element_for_exec | ( | ) |
Event_scheduler::~Event_scheduler | ( | ) |
|
overridedefault |
|
static |
|
static |
void Event_queue_element_for_exec::claim_memory_ownership | ( | bool | claim | ) |
bool Event_queue_element::compute_next_execution_time | ( | THD * | thd | ) |
|
private |
|
private |
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.
[in] | thd | Thread handle |
[in,out] | sp_sql | Pointer to String object where the SQL query will be stored |
[in] | db_name | The schema name |
[in] | event_name | The event name |
false | The drop event SQL query is built |
true | Otherwise |
Get an artificial stored procedure to parse as an event definition.
|
static |
Creates an event object and persist to Data Dictionary.
[in,out] | thd | THD |
[in] | parse_data | Parsed event definition |
[in] | create_if_not | true if IF NOT EXISTS clause was provided to CREATE EVENT statement |
[out] | event_already_exists | When method is completed successfully set to true if event already exists else set to false |
false | Success |
true | Error |
|
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.
[in,out] | thd | THD |
[in] | parse_data | Event's data from parsing stage |
[in] | if_not_exists | Whether 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. |
false | OK |
true | Error (reported) |
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.
[in] | thd | thread handle |
[in] | new_element | a new element to add to the queue |
[out] | created | set to true if no error and the element is added to the queue, false otherwise |
true | an error occurred. The value of created is undefined, the element was not deleted. |
false | success |
|
static |
Create a new query string for removing executable comments for avoiding leak and keeping consistency of the execution on master and slave.
[in] | thd | Thread handler |
[in] | buf | Query string |
|
private |
|
static |
void deinit_event_thread | ( | THD * | thd | ) |
|
private |
|
static |
Delete event.
[in] | thd | THD context |
[in] | db | Database name |
[in] | name | Event name |
[in] | drop_if_exists | DROP IF EXISTS clause was specified. If set, and the event does not exist, the error is downgraded to a warning. |
[out] | event_exists | Set to true if event exists. Set to false otherwise. |
false | success |
true | error (reported) |
void Event_queue::drop_event | ( | THD * | thd, |
LEX_CSTRING | dbname, | ||
LEX_CSTRING | name | ||
) |
|
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.
[in,out] | thd | THD |
[in] | dbname | Event's schema |
[in] | name | Event's name |
[in] | if_exists | When this is set and the event does not exist a warning is pushed into the warning stack. Otherwise the operation produces an error. |
false | OK |
true | Error (reported) |
|
private |
void Event_queue::drop_schema_events | ( | LEX_CSTRING | schema | ) |
|
static |
Drops all events in the selected database.
thd | THD context |
schema | The database under which events are to be dropped. |
|
static |
Drops all events from a schema.
[in] | thd | THD handle. |
[in] | schema | Schema object. |
void Event_queue::dump_internal_status | ( | ) |
void Event_scheduler::dump_internal_status | ( | ) |
|
static |
|
private |
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 | ||
) |
|
static |
|
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
bool Event_job_data::execute | ( | THD * | thd, |
bool | drop | ||
) |
Compiles and executes the event (the underlying sp_head object)
true | error (reported to the error log) |
false | success |
|
private |
|
overridevirtual |
Implements Event_basic.
Reimplemented in Event_timed.
|
overridevirtual |
Reimplemented from Event_queue_element.
|
overrideprivatevirtual |
Implements Event_basic.
|
private |
Get SHOW CREATE EVENT as string.
thd | THD context. |
buf | String*, should be already allocated. CREATE EVENT goes inside. |
0 | OK |
|
static |
Computes the sum of a timestamp plus interval.
time_zone | event time zone |
next | the sum |
start | add interval_value to this time |
time_now | current time |
i_value | quantity of time type interval to add |
i_type | type of interval to add (SECOND, MINUTE, HOUR, WEEK ...) |
0 | on success |
1 | on error. |
bool Event_queue::get_top_for_execution_if_time | ( | THD * | thd, |
Event_queue_element_for_exec ** | event_name | ||
) |
void Event_timed::init | ( | ) |
|
static |
Initializes the scheduler's structures.
opt_noacl_or_bootstrap | true if there is –skip-grant-tables or –initialize. In that case we disable the event scheduler. |
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. |
true | Fatal error. Startup must terminate (call unireg_abort()). |
bool Event_queue_element_for_exec::init | ( | LEX_CSTRING | dbname, |
LEX_CSTRING | name | ||
) |
|
static |
|
static |
bool Event_queue::init_queue | ( | ) |
void init_scheduler_psi_keys | ( | ) |
bool Event_scheduler::is_running | ( | ) |
|
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.
thd | THD context. Used for memory allocation in some cases. |
event_queue | Pointer to Event_queue object. |
false | success |
true | error, the load is aborted |
|
static |
Looks for a named event in the Data Dictionary and load it.
false | success |
true | error |
|
private |
|
private |
|
static |
Take exclusive metadata lock on all events in a schema.
thd | Thread handle. |
schema | Schema object. |
|
inlinestatic |
|
inlinestatic |
void Event_queue_element::mark_last_executed | ( | THD * | thd | ) |
Set last execution time.
thd | THD context |
bool post_init_event_thread | ( | THD * | thd | ) |
void pre_init_event_thread | ( | THD * | thd | ) |
|
private |
void Event_queue::recalculate_activation_times | ( | THD * | thd | ) |
|
static |
bool Event_scheduler::run | ( | THD * | thd | ) |
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
|
static |
A helper function to generate SHOW CREATE EVENT output from a named event.
[in] | thd | THD handle. |
[in] | et | Pointer to Event_timed object. |
[in] | protocol | Pointer to Protocol object. |
|
static |
Implement SHOW CREATE EVENT statement.
thd Thread context spn The name of the event (db, name)
false | OK |
true | error (reported) |
int sortcmp_lex_string | ( | LEX_CSTRING | s, |
LEX_CSTRING | t, | ||
const CHARSET_INFO * | cs | ||
) |
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.
[out] | err_no | - errno indicating type of error which caused failure to start scheduler thread. |
false | Success. |
true | Error. |
|
static |
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)
|
static |
|
private |
|
private |
|
static |
Used to execute ALTER EVENT.
Pendant to Events::update_event().
[in] | thd | THD context |
[in] | parse_data | parsed event definition |
[in] | new_dbname | not NULL if ALTER EVENT RENAME points at a new database name |
[in] | new_name | not NULL if ALTER EVENT RENAME points at a new event name |
false | Success |
true | Error (reported) |
|
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.
[in,out] | thd | THD |
[in] | parse_data | Event's data from parsing stage |
[in] | new_dbname | A new schema name for the event. Set in the case of ALTER EVENT RENAME, otherwise is NULL. |
[in] | new_name | A 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
false | OK |
true | error (reported) |
void Event_queue::update_event | ( | THD * | thd, |
LEX_CSTRING | dbname, | ||
LEX_CSTRING | name, | ||
Event_queue_element * | new_element | ||
) |
|
static |
Update the event in Data Dictionary with changed status and/or last execution time.
|
private |
|
static |
|
static |
|
static |
PSI_stage_info* all_events_stages[] |
|
static |
|
extern |
|
staticprivate |
|
extern |
PSI_cond_key key_COND_queue_state |
PSI_cond_key key_event_scheduler_COND_state |
|
extern |
PSI_mutex_key key_event_scheduler_LOCK_scheduler_state |
|
extern |
|
extern |
PSI_mutex_key key_LOCK_event_queue |
PSI_memory_key key_memory_event_basic_root |
PSI_thread_key key_thread_event_scheduler |
|
extern |
PSI_thread_key key_thread_event_worker |
PSI_thread_key key_thread_event_worker |
|
static |
|
static |
|
staticprivate |
|
static |
PSI_stage_info stage_waiting_for_next_activation |
|
extern |
PSI_stage_info stage_waiting_for_scheduler_to_stop |
|
extern |
PSI_stage_info stage_waiting_on_empty_queue |
|
extern |