1 #ifndef _EVENT_H_ 2 #define _EVENT_H_ 3 /* Copyright (c) 2004, 2013, 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 events.h 31 32 A public interface of Events_Scheduler module. 33 */ 34 35 #ifdef HAVE_PSI_INTERFACE 36 extern PSI_mutex_key key_event_scheduler_LOCK_scheduler_state; 37 extern PSI_cond_key key_event_scheduler_COND_state; 38 extern PSI_thread_key key_thread_event_scheduler, key_thread_event_worker; 39 #endif /* HAVE_PSI_INTERFACE */ 40 41 /* Always defined, for SHOW PROCESSLIST. */ 42 extern PSI_stage_info stage_waiting_on_empty_queue; 43 extern PSI_stage_info stage_waiting_for_next_activation; 44 extern PSI_stage_info stage_waiting_for_scheduler_to_stop; 45 46 #include "sql_string.h" /* LEX_STRING */ 47 #include "my_time.h" /* interval_type */ 48 49 class Event_db_repository; 50 class Event_parse_data; 51 class Event_queue; 52 class Event_scheduler; 53 struct TABLE_LIST; 54 class THD; 55 typedef struct charset_info_st CHARSET_INFO; 56 57 int 58 sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs); 59 60 /** 61 @brief A facade to the functionality of the Event Scheduler. 62 63 Every public operation against the scheduler has to be executed via the 64 interface provided by a static method of this class. No instance of this 65 class is ever created and it has no non-static data members. 66 67 The life cycle of the Events module is the following: 68 69 At server start up: 70 init_mutexes() -> init() 71 When the server is running: 72 create_event(), drop_event(), start_or_stop_event_scheduler(), etc 73 At shutdown: 74 deinit(), destroy_mutexes(). 75 76 The peculiar initialization and shutdown cycle is an adaptation to the 77 outside server startup/shutdown framework and mimics the rest of MySQL 78 subsystems (ACL, time zone tables, etc). 79 */ 80 81 class Events 82 { 83 public: 84 /* 85 the following block is to support --event-scheduler command line option 86 and the @@global.event_scheduler SQL variable. 87 See sys_var.cc 88 */ 89 enum enum_opt_event_scheduler { EVENTS_OFF, EVENTS_ON, EVENTS_DISABLED }; 90 /* Protected using LOCK_global_system_variables only. */ 91 static ulong opt_event_scheduler; 92 static bool check_if_system_tables_error(); 93 static bool start(int *err_no); 94 static bool stop(); 95 96 public: 97 /* A hack needed for Event_queue_element */ 98 static Event_db_repository * get_db_repository()99 get_db_repository() { return db_repository; } 100 101 static bool 102 init(my_bool opt_noacl); 103 104 static void 105 deinit(); 106 107 static void 108 init_mutexes(); 109 110 static void 111 destroy_mutexes(); 112 113 static bool 114 create_event(THD *thd, Event_parse_data *parse_data, bool if_exists); 115 116 static bool 117 update_event(THD *thd, Event_parse_data *parse_data, 118 LEX_STRING *new_dbname, LEX_STRING *new_name); 119 120 static bool 121 drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists); 122 123 static void 124 drop_schema_events(THD *thd, char *db); 125 126 static bool 127 show_create_event(THD *thd, LEX_STRING dbname, LEX_STRING name); 128 129 /* Needed for both SHOW CREATE EVENT and INFORMATION_SCHEMA */ 130 static int 131 reconstruct_interval_expression(String *buf, interval_type interval, 132 longlong expression); 133 134 static int 135 fill_schema_events(THD *thd, TABLE_LIST *tables, Item * /* cond */); 136 137 static void 138 dump_internal_status(); 139 140 private: 141 142 static bool 143 load_events_from_db(THD *thd); 144 145 private: 146 static Event_queue *event_queue; 147 static Event_scheduler *scheduler; 148 static Event_db_repository *db_repository; 149 /* Set to TRUE if an error at start up */ 150 static bool check_system_tables_error; 151 152 private: 153 /* Prevent use of these */ 154 Events(const Events &); 155 void operator=(Events &); 156 }; 157 158 /** 159 @} (end of group Event Scheduler) 160 */ 161 162 #endif /* _EVENT_H_ */ 163