MySQL 9.1.0
Source Code Documentation
events.h
Go to the documentation of this file.
1#ifndef _EVENT_H_
2#define _EVENT_H_
3/* Copyright (c) 2004, 2024, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26/**
27 @defgroup Event_Scheduler Event Scheduler
28 @ingroup Runtime_Environment
29 @{
30
31 @file sql/events.h
32
33 A public interface of Events_Scheduler module.
34*/
35
36#include <stddef.h>
37#include <sys/types.h>
38
39#include "lex_string.h"
40#include "my_inttypes.h"
41#include "my_psi_config.h"
42#include "my_time.h" /* interval_type */
47#include "sql/psi_memory_key.h"
48
51class Event_queue;
52class Event_scheduler;
53class String;
54class THD;
55
56namespace dd {
57class Schema;
58}
59
60struct CHARSET_INFO;
61
62#ifdef HAVE_PSI_INTERFACE
66#endif /* HAVE_PSI_INTERFACE */
67
68/* Always defined, for SHOW PROCESSLIST. */
72
74
75/**
76 @brief A facade to the functionality of the Event Scheduler.
77
78 Every public operation against the scheduler has to be executed via the
79 interface provided by a static method of this class. No instance of this
80 class is ever created and it has no non-static data members.
81
82 The life cycle of the Events module is the following:
83
84 At server start up:
85 init_mutexes() -> init()
86 When the server is running:
87 create_event(), drop_event(), start_or_stop_event_scheduler(), etc
88 At shutdown:
89 deinit(), destroy_mutexes().
90
91 The peculiar initialization and shutdown cycle is an adaptation to the
92 outside server startup/shutdown framework and mimics the rest of MySQL
93 subsystems (ACL, time zone tables, etc).
94*/
95
96class Events {
97 public:
98 /*
99 the following block is to support --event-scheduler command line option
100 and the @@global.event_scheduler SQL variable.
101 See sys_var.cc
102 */
104 /* Protected using LOCK_global_system_variables only. */
106 static bool start(int *err_no);
107 static bool stop();
108
109 static bool init(bool opt_noacl);
110
111 static void deinit();
112
113 static void init_mutexes();
114
115 static bool create_event(THD *thd, Event_parse_data *parse_data,
116 bool if_not_exists);
117
118 static bool update_event(THD *thd, Event_parse_data *parse_data,
119 const LEX_CSTRING *new_dbname,
120 const LEX_CSTRING *new_name);
121
122 static bool drop_event(THD *thd, LEX_CSTRING dbname, LEX_CSTRING name,
123 bool if_exists);
124
125 static bool lock_schema_events(THD *thd, const dd::Schema &schema);
126
127 static bool drop_schema_events(THD *thd, const dd::Schema &schema);
128
129 static bool show_create_event(THD *thd, LEX_CSTRING dbname, LEX_CSTRING name);
130
131 /* Needed for both SHOW CREATE EVENT and INFORMATION_SCHEMA */
134 longlong expression);
135
136 static void dump_internal_status();
137
138 Events(const Events &) = delete;
139 void operator=(Events &) = delete;
140
141 private:
144};
145
146/**
147 @} (end of group Event Scheduler)
148*/
149
150#endif /* _EVENT_H_ */
Definition: event_db_repository.h:87
Definition: event_parse_data.h:43
Queue of active events awaiting execution.
Definition: event_queue.h:102
Definition: event_scheduler.h:68
A facade to the functionality of the Event Scheduler.
Definition: events.h:96
enum_opt_event_scheduler
Definition: events.h:103
@ EVENTS_ON
Definition: events.h:103
@ EVENTS_OFF
Definition: events.h:103
@ EVENTS_DISABLED
Definition: events.h:103
void operator=(Events &)=delete
Events(const Events &)=delete
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: schema.h:63
static bool update_event(THD *thd, Event_parse_data *parse_data, const LEX_CSTRING *new_dbname, const LEX_CSTRING *new_name)
Alter an event.
Definition: events.cc:493
static bool drop_schema_events(THD *thd, const dd::Schema &schema)
Drops all events from a schema.
Definition: events.cc:777
static Event_queue * event_queue
Definition: events.h:142
PSI_cond_key key_event_scheduler_COND_state
Definition: events.cc:1030
int sortcmp_lex_string(LEX_CSTRING s, LEX_CSTRING t, const CHARSET_INFO *cs)
Definition: events.cc:153
static bool start(int *err_no)
Definition: events.cc:1133
PSI_thread_key key_thread_event_worker
Definition: events.h:65
PSI_thread_key key_thread_event_scheduler
Definition: events.cc:1039
static void deinit()
Definition: events.cc:1008
static bool drop_event(THD *thd, LEX_CSTRING dbname, LEX_CSTRING name, bool if_exists)
Drops an event.
Definition: events.cc:653
static bool lock_schema_events(THD *thd, const dd::Schema &schema)
Take exclusive metadata lock on all events in a schema.
Definition: events.cc:720
static void dump_internal_status()
Definition: events.cc:1112
static void init_mutexes()
Definition: events.cc:1096
PSI_stage_info stage_waiting_on_empty_queue
Definition: events.cc:1048
static ulong opt_event_scheduler
Definition: events.h:105
static bool init(bool opt_noacl)
Initializes the scheduler's structures.
Definition: events.cc:929
static bool show_create_event(THD *thd, LEX_CSTRING dbname, LEX_CSTRING name)
Implement SHOW CREATE EVENT statement.
Definition: events.cc:869
static bool stop()
Definition: events.cc:1139
static Event_scheduler * scheduler
Definition: events.h:143
PSI_mutex_key key_event_scheduler_LOCK_scheduler_state
Definition: events.cc:1020
PSI_stage_info stage_waiting_for_next_activation
Definition: events.cc:1050
static bool create_event(THD *thd, Event_parse_data *parse_data, bool if_not_exists)
Create a new event.
Definition: events.cc:350
PSI_stage_info stage_waiting_for_scheduler_to_stop
Definition: events.cc:1052
static int reconstruct_interval_expression(String *buf, interval_type interval, longlong expression)
Definition: events.cc:176
unsigned int PSI_cond_key
Instrumented cond key.
Definition: psi_cond_bits.h:44
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:52
unsigned int PSI_thread_key
Instrumented thread key.
Definition: psi_thread_bits.h:50
Some integer typedefs for easier portability.
long long int longlong
Definition: my_inttypes.h:55
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
Interface for low level time utilities.
interval_type
Available interval types used in any statement.
Definition: my_time.h:455
static int interval
Definition: mysqladmin.cc:71
bool opt_noacl
Definition: mysqld.cc:1312
Definition: buf0block_hint.cc:30
borrowable::session_track::Schema< true > Schema
Definition: classic_protocol_session_track.h:288
Definition: commit_order_queue.h:34
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
Performance schema instrumentation interface.
Instrumentation helpers for mutexes.
Performance schema instrumentation interface.
Performance schema instrumentation interface.
case opt name
Definition: sslopt-case.h:29
Definition: m_ctype.h:421
Definition: mysql_lex_string.h:40
Stage instrument information.
Definition: psi_stage_bits.h:74