MySQL 8.2.0
Source Code Documentation
restart_monitor_win.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef SQL_RESTART_MONITOR_WIN_H_
24#define SQL_RESTART_MONITOR_WIN_H_
25
26#include <stdlib.h>
27#include <string.h>
28
29/**
30 Type indicating the type of signals which involve communication
31 between the monitor and the mysqld.
32*/
33
34enum class Signal_type {
35 /**
36 Shutdown signal from monitor to mysqld. This is used
37 to relay the shutdown that comes from the SCM.
38 */
40
41 /**
42 Signal used to send the service status command to the monitor.
43 */
44
46
47 /**
48 Signal to the the mysqld from monitor indicating service status command
49 has been processed.
50 */
51
53};
54
55/**
56 Service status message providing an abstraction for the service message sent
57 by monitor to client.
58*/
59
61 private:
62 /**
63 Service status message indicating type of update to be done monitor to SCM.
64 */
65
66 char m_service_msg[32];
67
68 public:
69 /**
70 Constructor which initializes the service status message to a null string.
71 */
72
74
75 /**
76 Constructor initializes the service status with a particular message.
77
78 @param msg pointer to message string.
79 */
80
81 Service_status_msg(const char *msg) {
82 strncpy(m_service_msg, msg, sizeof(m_service_msg));
83 }
84
85 /**
86 Get service message.
87
88 @return pointer to the service message.
89 */
90
91 const char *service_msg() const { return m_service_msg; }
92};
93
94/**
95 Type of messages logged by monitor logging.
96*/
97
99 /**
100 Error log.
101 */
103
104 /**
105 Warning log.
106 */
108
109 /**
110 Information log.
111 */
113};
114
115/**
116 Initialize the mysqld monitor. This method is called from
117 both the monitor and mysqld. It sets the variable that
118 distinguishes the monitor and the mysqld. It also initialize the
119 monitor logging subsystem if the process under which it is called
120 is monitor.
121*/
122
124
125/**
126 Deinitialize the monitor.
127 This method essentially closes any handles opened during initialization.
128*/
129
131
132/**
133 Send service status message to the monitor. This method is used by mysqld to
134 send service status like running and setting the slow timeout value.
135*/
136
138
139/**
140 Close the service status pipe. This method is called by
141 the mysqld child process.
142*/
143
145
146/**
147 Get char representation corresponding to MYSQLD_PARENT_PID.
148
149 @return Pointer to string representing pid of the monitor.
150*/
151
152const char *get_monitor_pid();
153
154/**
155 Signal an event of type Signal_type.
156
157 @param signal type of the event.
158*/
159
161
162/**
163 Check if option is an early type or --gdb, --no-monitor.
164 The early type options are verbose, help, initialize, version
165 and initialize-insecure. These options print and do certain activities
166 and allow the server to exit. In addition there are options like gdb,
167 no-monitor where we do not spawn a monitor process.
168
169 @param argc Count of arguments.
170 @param argv Vector of arguments.
171
172 @return true if we are early option else false.
173*/
174
175bool is_early_option(int argc, char **argv);
176
177/**
178 Check if we are monitor process.
179
180 @return true if the current process is monitor else false.
181*/
182
183bool is_mysqld_monitor();
184
185/**
186 Check if the monitor is started under a windows service.
187
188 @return true if the monitor is started as a windows service.
189*/
190
192
193/**
194 Start the monitor if we are called in parent (monitor) context.
195 In child context, set the event names and get the monitor process
196 pid and return -1.
197
198 @return -1 if we are in child context else exit code of the mysqld process.
199*/
200
201int start_monitor();
202
203/**
204 Setup the service status command processed handle.
205 This method is called from mysqld context. This handle ensures the
206 synchronization required between the monitor and mysqld once the
207 monitor has handled the service status sent by client.
208*/
209
211
212/**
213 Close the Service Status Cmd Processed handle.
214*/
215
217
218// extern declarations.
219extern bool is_windows_service();
220class NTService;
222#endif // SQL_RESTART_MONITOR_WIN_H_
Definition: nt_servc.h:23
static int signal(mysql_cond_t *that, const char *, unsigned int)
Definition: mysql_cond_v1_native.cc:86
Signal_type
Type indicating the type of signals which involve communication between the monitor and the mysqld.
Definition: restart_monitor_win.h:34
@ SIGNAL_SERVICE_STATUS_CMD
Signal used to send the service status command to the monitor.
@ SIGNAL_SERVICE_STATUS_CMD_PROCESSED
Signal to the the mysqld from monitor indicating service status command has been processed.
@ SIGNAL_SHUTDOWN
Shutdown signal from monitor to mysqld.
void close_service_status_pipe_in_mysqld()
Close the service status pipe.
Definition: restart_monitor_win.cc:267
bool setup_service_status_cmd_processed_handle()
Setup the service status command processed handle.
Definition: restart_monitor_win.cc:616
bool is_early_option(int argc, char **argv)
Check if option is an early type or –gdb, –no-monitor.
Definition: restart_monitor_win.cc:559
bool is_mysqld_monitor()
Check if we are monitor process.
Definition: restart_monitor_win.cc:587
void close_service_status_cmd_processed_handle()
Close the Service Status Cmd Processed handle.
Definition: restart_monitor_win.cc:638
void deinitialize_mysqld_monitor()
Deinitialize the monitor.
Definition: restart_monitor_win.cc:585
Monitor_log_msg_type
Type of messages logged by monitor logging.
Definition: restart_monitor_win.h:98
@ MONITOR_LOG_INFO
Information log.
@ MONITOR_LOG_ERROR
Error log.
@ MONITOR_LOG_WARN
Warning log.
bool send_service_status(const Service_status_msg &)
Send service status message to the monitor.
Definition: restart_monitor_win.cc:318
bool is_monitor_win_service()
Check if the monitor is started under a windows service.
Definition: restart_monitor_win.cc:577
bool initialize_mysqld_monitor()
Initialize the mysqld monitor.
Definition: restart_monitor_win.cc:571
void signal_event(Signal_type signal)
Signal an event of type Signal_type.
Definition: restart_monitor_win.cc:214
NTService * get_win_service_ptr()
bool is_windows_service()
const char * get_monitor_pid()
Get char representation corresponding to MYSQLD_PARENT_PID.
Definition: restart_monitor_win.cc:212
int start_monitor()
Start the monitor if we are called in parent (monitor) context.
Definition: restart_monitor_win.cc:665
Service status message providing an abstraction for the service message sent by monitor to client.
Definition: restart_monitor_win.h:60
char m_service_msg[32]
Service status message indicating type of update to be done monitor to SCM.
Definition: restart_monitor_win.h:66
Service_status_msg(const char *msg)
Constructor initializes the service status with a particular message.
Definition: restart_monitor_win.h:81
Service_status_msg()
Constructor which initializes the service status message to a null string.
Definition: restart_monitor_win.h:73
const char * service_msg() const
Get service message.
Definition: restart_monitor_win.h:91