MySQL  8.0.16
Source Code Documentation
events.h
Go to the documentation of this file.
1 #ifndef _EVENT_H_
2 #define _EVENT_H_
3 /* Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
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 also distributed 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 included with MySQL.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License, version 2.0, for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
24 
25 /**
26  @defgroup Event_Scheduler Event Scheduler
27  @ingroup Runtime_Environment
28  @{
29 
30  @file sql/events.h
31 
32  A public interface of Events_Scheduler module.
33 */
34 
35 #include <stddef.h>
36 #include <sys/types.h>
37 
38 #include "lex_string.h"
39 #include "my_inttypes.h"
40 #include "my_psi_config.h"
41 #include "my_time.h" /* interval_type */
46 #include "mysql/psi/psi_memory.h" // PSI_memory_key
47 
49 class Event_parse_data;
50 class Event_queue;
51 class Event_scheduler;
52 class String;
53 class THD;
54 
55 namespace dd {
56 class Schema;
57 }
58 
59 struct CHARSET_INFO;
60 
61 #ifdef HAVE_PSI_INTERFACE
65 #endif /* HAVE_PSI_INTERFACE */
66 
68 
69 /* Always defined, for SHOW PROCESSLIST. */
73 
75 
76 /**
77  Convert name to lowercase.
78 
79  @param from the string to be converted to lowercase.
80  @param to Buffer space for the coverted lowercase string.
81  @param len Maximum length of the buffer.
82 */
83 
84 void convert_name_lowercase(const char *from, char *to, size_t len);
85 
86 /**
87  @brief A facade to the functionality of the Event Scheduler.
88 
89  Every public operation against the scheduler has to be executed via the
90  interface provided by a static method of this class. No instance of this
91  class is ever created and it has no non-static data members.
92 
93  The life cycle of the Events module is the following:
94 
95  At server start up:
96  init_mutexes() -> init()
97  When the server is running:
98  create_event(), drop_event(), start_or_stop_event_scheduler(), etc
99  At shutdown:
100  deinit(), destroy_mutexes().
101 
102  The peculiar initialization and shutdown cycle is an adaptation to the
103  outside server startup/shutdown framework and mimics the rest of MySQL
104  subsystems (ACL, time zone tables, etc).
105 */
106 
107 class Events {
108  public:
109  /*
110  the following block is to support --event-scheduler command line option
111  and the @@global.event_scheduler SQL variable.
112  See sys_var.cc
113  */
115  /* Protected using LOCK_global_system_variables only. */
117  static bool start(int *err_no);
118  static bool stop();
119 
120  static bool init(bool opt_noacl);
121 
122  static void deinit();
123 
124  static void init_mutexes();
125 
126  static bool create_event(THD *thd, Event_parse_data *parse_data,
127  bool if_exists);
128 
129  static bool update_event(THD *thd, Event_parse_data *parse_data,
130  LEX_STRING *new_dbname, LEX_STRING *new_name);
131 
132  static bool drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name,
133  bool if_exists);
134 
135  static bool lock_schema_events(THD *thd, const dd::Schema &schema);
136 
137  static bool drop_schema_events(THD *thd, const dd::Schema &schema);
138 
139  static bool show_create_event(THD *thd, LEX_STRING dbname, LEX_STRING name);
140 
141  /* Needed for both SHOW CREATE EVENT and INFORMATION_SCHEMA */
142  static int reconstruct_interval_expression(String *buf,
144  longlong expression);
145 
146  static void dump_internal_status();
147 
148  Events(const Events &) = delete;
149  void operator=(Events &) = delete;
150 
151  private:
154 };
155 
156 /**
157  @} (end of group Event Scheduler)
158 */
159 
160 #endif /* _EVENT_H_ */
static bool lock_schema_events(THD *thd, const dd::Schema &schema)
Take exclusive metadata lock on all events in a schema.
Definition: events.cc:700
static int interval
Definition: mysqladmin.cc:62
A facade to the functionality of the Event Scheduler.
Definition: events.h:107
Events(const Events &)=delete
Definition: mysql_lex_string.h:34
const string name("\ame\)
Some integer typedefs for easier portability.
static void dump_internal_status()
Definition: events.cc:1085
static bool start(int *err_no)
Definition: events.cc:1107
void operator=(Events &)=delete
PSI_stage_info stage_waiting_on_empty_queue
Definition: events.cc:1022
Performance schema instrumentation interface.
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:46
static void init_mutexes()
Definition: events.cc:1069
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:159
unsigned int PSI_mutex_key
Instrumented mutex key.
Definition: psi_mutex_bits.h:49
Definition: events.h:114
static Event_scheduler * scheduler
Definition: events.h:153
unsigned int PSI_cond_key
Instrumented cond key.
Definition: psi_cond_bits.h:41
interval_type
Available interval types used in any statement.
Definition: my_time.h:380
enum_opt_event_scheduler
Definition: events.h:114
PSI_thread_key key_thread_event_worker
Definition: events.cc:1014
Stage instrument information.
Definition: psi_stage_bits.h:71
Performance schema instrumentation interface.
PSI_mutex_key key_event_scheduler_LOCK_scheduler_state
Definition: events.cc:995
static bool update_event(THD *thd, Event_parse_data *parse_data, LEX_STRING *new_dbname, LEX_STRING *new_name)
Alter an event.
Definition: events.cc:482
Definition: event_parse_data.h:43
void convert_name_lowercase(const char *from, char *to, size_t len)
Convert name to lowercase.
Definition: events.cc:155
static Event_queue * event_queue
Definition: events.h:152
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
unsigned int len
Definition: dbug_analyze.cc:216
static bool drop_schema_events(THD *thd, const dd::Schema &schema)
Drops all events from a schema.
Definition: events.cc:750
long long int longlong
Definition: my_inttypes.h:70
Definition: events.h:114
t
Definition: dbug_analyze.cc:147
PSI_cond_key key_event_scheduler_COND_state
Definition: events.cc:1005
Definition: m_ctype.h:358
static bool show_create_event(THD *thd, LEX_STRING dbname, LEX_STRING name)
Implement SHOW CREATE EVENT statement.
Definition: events.cc:842
Instrumentation helpers for mutexes.
Definition: events.h:114
Queue of active events awaiting execution.
Definition: event_queue.h:101
static bool create_event(THD *thd, Event_parse_data *parse_data, bool if_exists)
Create a new event.
Definition: events.cc:338
int sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs)
Definition: events.cc:150
static bool stop()
Definition: events.cc:1113
PSI_stage_info stage_waiting_for_scheduler_to_stop
Definition: events.cc:1026
Performance schema instrumentation interface.
unsigned int PSI_thread_key
Instrumented thread key.
Definition: psi_thread_bits.h:48
Definition: event_scheduler.h:67
Performance schema instrumentation interface.
static ulong opt_event_scheduler
Definition: events.h:116
static void deinit()
Definition: events.cc:981
Definition: event_db_repository.h:88
static int reconstruct_interval_expression(String *buf, interval_type interval, longlong expression)
Definition: events.cc:179
Definition: schema.h:60
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
Interface for low level time utilities.
PSI_stage_info stage_waiting_for_next_activation
Definition: events.cc:1024
PSI_thread_key key_thread_event_scheduler
Definition: events.cc:1014
unsigned long ulong
Definition: my_inttypes.h:46
static bool drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists)
Drops an event.
Definition: events.cc:632
static bool init(bool opt_noacl)
Initializes the scheduler&#39;s structures.
Definition: events.cc:902
PSI_memory_key key_memory_event_basic_root
Definition: events.cc:1029
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:776
bool opt_noacl
Definition: mysqld.cc:1060