MySQL 8.0.40
Source Code Documentation
|
#include "restart_monitor_win.h"
#include <assert.h>
#include <windows.h>
#include <memory>
#include <vector>
#include <shellapi.h>
#include "my_sys.h"
#include "mysqld.h"
#include "sql/log.h"
#include "sql/message.h"
#include "sql/sql_const.h"
Functions | |
static int | monitor_mysqld (LPSTR cmdline) |
Spawn mysqld process. More... | |
static bool | initialize_events (void) |
Initialize event handles in monitor process. More... | |
bool | initialize_monitor_log () |
Initialize the monitor log. More... | |
void | deinitialize_monitor_log () |
Deinitialize the monitor log. More... | |
static WORD | get_event_type (Monitor_log_msg_type type) |
Map monitor msg type to corresponding event log type. More... | |
static void | log_in_eventlog (WORD type, LPCSTR msg) |
Log a message to the event log. More... | |
void | monitor_log_msg (Monitor_log_msg_type type, LPCTSTR format,...) |
Log an msg. More... | |
static void | signal_thr_open_event (const char *event_name) |
Signal an named event by the event name. More... | |
const char * | get_monitor_pid () |
Get char representation corresponding to MYSQLD_PARENT_PID. More... | |
void | signal_event (Signal_type signal_type) |
Signal an event of type Signal_type. More... | |
static HANDLE | get_service_status_pipe_in_mysqld () |
Get handle to service status pipe. More... | |
void | close_service_status_pipe_in_mysqld () |
Close mysqld service status pipe. More... | |
static bool | setup_service_status_pipe_in_monitor () |
Setup service status pipe. More... | |
static void | close_service_status_pipe_in_monitor () |
Close service status pipe. More... | |
bool | send_service_status (const Service_status_msg &msg) |
Send service status message to the monitor. More... | |
static bool | get_and_set_service_status () |
Get the service status command from the mysqld process and process it and set the status in the SCM. More... | |
static void | quote_arg (const std::string &arg, std::string *cmd_line) |
Add an argument to a command line adding quotes and backlashes for paths as necessary. More... | |
static std::string | construct_cmd_line (const std::vector< std::string > &args) |
Construct the command line that is to be passed to the spawned mysqld process. More... | |
static bool | is_early_short_option (const char ch) |
Check if the char representing is an early option. More... | |
static bool | is_early_option (const char *cur_arg) |
Check if the option specified is an early option. More... | |
bool | is_early_option (int argc, char **argv) |
Check if option is an early type or –gdb, –no-monitor. More... | |
bool | initialize_mysqld_monitor () |
Initialize the mysqld monitor. More... | |
bool | is_monitor_win_service () |
Check if the monitor is started under a windows service. More... | |
void | deinitialize_mysqld_monitor () |
Deinitialize the monitor. More... | |
bool | is_mysqld_monitor () |
Check if we are monitor process. More... | |
static void | set_event_names () |
This function assigns names to the shutdown event, service status command event, service status command processed event and the name of service status pipe. More... | |
bool | setup_service_status_cmd_processed_handle () |
Create an event handle to indicate service status command has been processed from the mysqld monitor parent to the mysqld child. More... | |
void | close_service_status_cmd_processed_handle () |
Close the Service Status Cmd Processed handle. More... | |
int | start_monitor () |
Start the monitor if we are called in parent (monitor) context. More... | |
Variables | |
static DWORD | my_monitor_pid |
static bool | mysqld_monitor_process |
static HANDLE | service_status_cmd_event |
static HANDLE | service_status_pipe |
static HANDLE | client_service_status_pipe = nullptr |
static HANDLE | service_status_cmd_processed_handle = nullptr |
static HANDLE | event_log_handle = nullptr |
static const int | NUM_WAIT_HANDLES = 2 |
static const int | MYSQLD_HANDLE = 0 |
static const int | SERVICE_STATUS_CMD_HANDLE = 1 |
static const int | EVENT_NAME_LEN = 32 |
static char | service_status_cmd_processed_event_name [EVENT_NAME_LEN] |
static char | shutdown_event_name [EVENT_NAME_LEN] |
static char | service_status_pipe_name [EVENT_NAME_LEN] |
static char | service_status_cmd_event_name [EVENT_NAME_LEN] |
void close_service_status_cmd_processed_handle | ( | ) |
Close the Service Status Cmd Processed handle.
|
static |
Close service status pipe.
This handle is closed in context of the monitor process.
void close_service_status_pipe_in_mysqld | ( | ) |
Close mysqld service status pipe.
Close the service status pipe.
This call shall made in context of the mysqld process.
|
static |
Construct the command line that is to be passed to the spawned mysqld process.
args | reference to vector of string arguments. |
void deinitialize_monitor_log | ( | ) |
Deinitialize the monitor log.
This method deregisters the event log.
void deinitialize_mysqld_monitor | ( | ) |
Deinitialize the monitor.
This method essentially closes any handles opened during initialization.
|
static |
Get the service status command from the mysqld process and process it and set the status in the SCM.
|
static |
Map monitor msg type to corresponding event log type.
type | Type of the message. |
const char * get_monitor_pid | ( | ) |
Get char representation corresponding to MYSQLD_PARENT_PID.
|
static |
Get handle to service status pipe.
This call will be in the context of mysqld process.
|
static |
Initialize event handles in monitor process.
bool initialize_monitor_log | ( | ) |
Initialize the monitor log.
In case mysqld is spawned from windows service, we use event log for logging error messages. (stderr/stdout is not available when started as as a service.)
bool initialize_mysqld_monitor | ( | ) |
Initialize the mysqld monitor.
This method is called from both the monitor and mysqld. It sets the variable that distinguishes the monitor and the mysqld. It also initialize the monitor logging subsystem if the process under which it is called is monitor.
|
inlinestatic |
Check if the option specified is an early option.
cur_arg | string representing an early option. |
bool is_early_option | ( | int | argc, |
char ** | argv | ||
) |
Check if option is an early type or –gdb, –no-monitor.
The early type options are verbose, help, initialize, version and initialize-insecure. These options print and do certain activities and allow the server to exit. In addition there are options like gdb, no-monitor where we do not spawn a monitor process.
argc | Count of arguments. |
argv | Vector of arguments. |
|
inlinestatic |
Check if the char representing is an early option.
ch | charactering representing an short option. |
bool is_monitor_win_service | ( | ) |
Check if the monitor is started under a windows service.
bool is_mysqld_monitor | ( | ) |
Check if we are monitor process.
|
inlinestatic |
Log a message to the event log.
type | Event log type. |
msg | Pointer to the message string. |
void monitor_log_msg | ( | Monitor_log_msg_type | type, |
LPCTSTR | format, | ||
... | |||
) |
Log an msg.
If the monitor is started as a windows service, then log it to the event log using apporirate type.
type | Type of message indicating whether it is information, warning, error. |
format | format string. |
|
static |
Spawn mysqld process.
Wait on spawned process handle for mysqld exit. On exit, retrieve exit code to check for restart and shutdown or abort exit. If we exit using MYSQLD_RESTART_EXIT code then we respawn this child process. In addition, if the mysqld process is instantiated as a windows service, then we create a named pipe. The pipe allows for communication from mysqld to send service status code. This service status code can then be relayed to the Service Control Manager using the service status handle. This is used to relay the service running status and set slow status timeout value.
|
static |
Add an argument to a command line adding quotes and backlashes for paths as necessary.
arg | string representing the argument. | |
[in,out] | cmd_line | command line to which the string should be appended with necessary quoting. |
bool send_service_status | ( | const Service_status_msg & | msg | ) |
Send service status message to the monitor.
This method is used by mysqld to send service status like running and setting the slow timeout value.
|
static |
This function assigns names to the shutdown event, service status command event, service status command processed event and the name of service status pipe.
bool setup_service_status_cmd_processed_handle | ( | ) |
Create an event handle to indicate service status command has been processed from the mysqld monitor parent to the mysqld child.
Setup the service status command processed handle.
|
static |
Setup service status pipe.
void signal_event | ( | Signal_type | signal | ) |
Signal an event of type Signal_type.
signal | type of the event. |
|
static |
Signal an named event by the event name.
event_name | pointer to char string representing the event. |
int start_monitor | ( | ) |
Start the monitor if we are called in parent (monitor) context.
In child context, set the event names and get the monitor process pid and return -1.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |