Disclosure of Invention
The embodiment of the application aims to provide a method, a device and a system for monitoring the copy state of a MYSQL database group, which are used for solving the problem that the copy state of the MYSQL database group is not monitored timely.
In a first aspect, a method for monitoring a group replication state of a MYSQL database is provided, which is applied to a group replication node proxy apparatus, and includes:
receiving a group copy state query instruction issued by a group copy state monitoring device;
inquiring the group replication state of a target group replication node according to the group replication state inquiry instruction, wherein the target group replication node corresponds to the group replication node proxy device and is used for performing group replication on the MYSQL database;
feeding back the group replication state to the group replication state monitoring device to indicate the group replication state monitoring device to judge whether the group replication state of the target group replication node is normal;
and when a group replication monitoring operation instruction issued by the group replication state monitoring device based on the group replication state is received, executing an operation corresponding to the group replication monitoring operation instruction on the target group replication node.
In a second aspect, a method for monitoring a group replication state of a MYSQL database is provided, which is applied to a group replication state monitoring apparatus, and includes:
issuing a group replication state query instruction to a target group replication node agent device, wherein the group replication state query instruction is used for indicating the target group replication node agent device to query a group replication state of a target group replication node, and the target group replication node corresponds to the group replication node agent device and is used for performing group replication on a MYSQL database;
receiving a group replication state fed back by the target group replication node proxy device based on the group replication state query instruction, and judging whether the group replication state of the target group replication node is normal or not according to the group replication state through a preset rule;
and when the group replication state of the target group replication node is abnormal, issuing a group replication monitoring operation instruction to the target group replication node proxy device according to the group replication state of the target group replication node so as to instruct the target group replication node proxy device to execute an operation corresponding to the group replication monitoring operation instruction on the target group replication node.
In a third aspect, a group replication node proxy apparatus is provided, including:
the first receiving module is used for receiving a group copy state query instruction issued by the group copy state monitoring device;
the first query module is used for querying the group replication state of a target group replication node according to the group replication state query instruction, wherein the target group replication node corresponds to the group replication node proxy device and is used for performing group replication on the MYSQL database;
the first feedback module feeds the group replication state back to the group replication state monitoring device to indicate the group replication state monitoring device to judge whether the group replication state of the target group replication node is normal;
and the first execution module is used for executing the operation corresponding to the group copy monitoring operation instruction on the target group copy node when receiving the group copy monitoring operation instruction issued by the group copy state monitoring device based on the group copy state.
In a fourth aspect, there is provided a group copy status monitoring apparatus, comprising:
the second sending module is used for issuing a group replication state query instruction to the target group replication node proxy device, wherein the group replication state query instruction is used for indicating the target group replication node proxy device to query the group replication state of the target group replication node, and the target group replication node corresponds to the group replication node proxy device and is used for performing group replication on the MYSQL database;
the second receiving module is used for receiving the group replication state fed back by the target group replication node proxy device based on the group replication state query instruction, and judging whether the group replication state of the target group replication node is normal or not according to the group replication state through a preset rule;
and the second control module is used for issuing a group replication monitoring operation instruction to the target group replication node proxy device according to the group replication state of the target group replication node when the group replication state of the target group replication node is abnormal so as to instruct the target group replication node proxy device to execute the operation corresponding to the group replication monitoring operation instruction on the target group replication node.
In a fifth aspect, a MYSQL database group replication status monitoring system is provided, which includes the group replication status monitoring apparatus of the fourth aspect and at least one group replication node agent apparatus of the third aspect communicatively connected to the group replication status monitoring apparatus through an external interface.
In a sixth aspect, an electronic device is provided, the electronic device comprising a processor, a memory and a computer program stored on the memory and executable on the processor, the computer program, when executed by the processor, implementing the steps of the method according to the first or second aspect.
In a seventh aspect, a computer-readable storage medium is provided, on which a computer program is stored which, when executed by a processor, implements the steps of the method of the first or second aspect.
In the embodiment of the application, a group copy state query instruction issued by a group copy state monitoring device is received, then the group copy state of a target group copy node is queried according to the group copy state query instruction, then the group copy state is fed back to the group copy state monitoring device, and when a group copy monitoring operation instruction issued by the group copy state monitoring device based on the group copy state is received, an operation corresponding to the group copy monitoring operation instruction is executed on the target group copy node. By the scheme provided by the embodiment, the group replication state of the target group replication node can be monitored in time, and corresponding operation is executed on the target group replication node when the group replication monitoring operation instruction is received. According to the scheme, the copy state of the MYSQL database group can be automatically inquired, and the copy state of the MYSQL database group can be adjusted in time according to the instruction, so that when the copy state of the MYSQL database group is abnormal, timely monitoring can be achieved through the scheme, and the problem that manual monitoring causes slow repair is avoided.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention. The reference numbers in the present application are only used for distinguishing the steps in the scheme and are not used for limiting the execution sequence of the steps, and the specific execution sequence is described in the specification.
The scheme provided by the embodiment can be applied to the MYSQL database and is used for monitoring the state of each group of copy nodes of the MYSQL database and adjusting abnormal nodes. The embodiment provides a MYSQL database group replication state monitoring method, a group replication node agent device, a group replication state monitoring device and a system.
Fig. 1 shows a schematic structural diagram of a MYSQL database group replication status monitoring system, and in the system provided in this embodiment, the system includes a group replication status monitoring apparatus and at least one group replication node proxy apparatus, which are communicatively connected through an external interface.
In practical application, the number of group replication node proxy devices in the system is related to the number of MYSQL database group replication members. In the system shown in fig. 1, one group replication state monitoring apparatus and three group replication node proxy apparatuses communicatively connected thereto are included. Each group replication node proxy device corresponds to one group replication node, namely, the group replication node proxy devices are respectively deployed at each node of database group replication, and each group replication node corresponds to one MYSQL database group replication member. The group replication status monitoring means may be provided outside the database group.
In the solution provided in this embodiment, the group replication state monitoring device performs data communication with each group replication node agent device, so as to obtain the state of the group replication node corresponding to each group replication node agent, and issue an instruction adjustment in time when the state of the group replication node is abnormal, thereby implementing monitoring on each group replication node, and further implementing monitoring on the MYSQL database group replication state.
The present embodiment provides a MYSQL database group replication state monitoring method applied to the group replication node proxy apparatus, as shown in fig. 2a, including the following steps:
s21: receiving a group copy state query instruction issued by a group copy state monitoring device;
s22: inquiring the group replication state of a target group replication node according to the group replication state inquiry instruction, wherein the target group replication node corresponds to the group replication node proxy device and is used for performing group replication on the MYSQL database;
s23: feeding back the group replication state to the group replication state monitoring device to indicate the group replication state monitoring device to judge whether the group replication state of the target group replication node is normal;
s24: and when a group replication monitoring operation instruction issued by the group replication state monitoring device based on the group replication state is received, executing an operation corresponding to the group replication monitoring operation instruction on the target group replication node.
A schematic structural diagram of the group replication node proxy apparatus described in this embodiment is shown in fig. 2b, and the group replication node proxy apparatus may be applied to a MYSQL database, and includes an external interface and an LUA virtual machine, where the external interface may be used to receive and transmit data, the group replication state query instruction may be received through the external interface, and the LUA virtual machine may be used to perform data processing, where the database proxy logic is implemented by LUA language, and the LUA virtual machine may further include other functional logics. For example, the external interface may be a rest (representational State transfer) access interface, which may be used to receive a set of copy State query instructions, which may be HTTP instructions.
In this embodiment, the external interface first parses the received HTTP command into a first message request and forwards the first message request to the LUA virtual machine for processing. The LUA virtual machine automatically loads the protocol adaptation logic LUA library of each service in advance according to the configuration so as to process the first message request subsequently. After preloading each protocol adaptation logic LUA library, the LUA virtual machine executes SQL statements in the corresponding MYSQL database, and the group replication state of the target group replication node can be obtained according to the result. In addition, the LUA virtual machine also provides connection database underlying protocol support for transforming LUA logic into database operations and responses.
An underlying protocol support module is also included in the group replication node proxy device and may be configured to provide an interface for the LUA virtual machine to access the MYSQL database, i.e., to enable the LUA business logic to interface with the MYSQL database SQL execution environment. Specifically, the underlying protocol support module can realize a toolkit for supporting LUA functions by a MYSQL database, such as character set transcoding, database connection management and the like. The bottom layer protocol support module can carry out classification control on SQL statements supported by the LUA virtual machine and provide related state response. In addition, the underlying protocol support module also supports interfacing with multiple MYSQL databases.
By the scheme provided by this embodiment, the group replication node agent device can feed back the group replication state of the target group replication node according to the group replication state query instruction issued by the group replication state monitoring device, and the group replication state can be used for the group replication state monitoring device to determine whether the group replication state of the target group replication node is normal, and issue a group replication monitoring operation instruction to adjust the group replication state of the target group replication node when the state is abnormal.
Preferably, step S22, querying the group replication status of the target group replication node according to the group replication status query instruction, as shown in fig. 3, includes the following steps:
s31: analyzing the group of the replication state query instruction to obtain a first message request;
s32: executing an SQL statement corresponding to the first message request on a target MYSQL database corresponding to the target group replication node according to the loaded service logic by the LUA virtual machine;
s33: and generating the group replication state of the target group replication node according to the response result of the target MYSQL database to the SQL statement.
The step S31 may be executed by the external interface, and the parsed first message request is sent to the LUA virtual machine by the external interface for processing. The first message request corresponds to a service, the LUA virtual machine executes SQL statements in the MYSQL database of the target node, and finally generates a group replication state of the target group replication node according to the response result.
By the scheme provided by the embodiment, the group replication state of the target group replication node can be queried in the MYSQL database through the LUA virtual machine, so that the generated group replication state corresponds to the actual state of the target group replication node.
Preferably, the group replication node agent device may be developed and implemented using LUA language, and generates the group replication state according to a result obtained by executing an SQL statement in the MYSQL database of the corresponding node. In the actual application process, the state codes of the nodes in various states can be predefined. For example, the group copy status code "1001" is defined in the state where the group copy node cannot access, such as failure to establish a connection, timeout to establish a connection, database not started, failure of query result, and so on. The offline state is handled in group replication at the group replication node, i.e., the database operates normally but is not added to the database group replication group, and a group replication state code "2001" is defined. When the group replication node is in the group replication group, but the group replication delay parameter is found to exceed the predetermined threshold value according to the executed SQL statement result, the group replication efficiency is judged to be seriously lagged, and a group replication status code '4001' is defined. After the state of the group replication node is determined, a group replication state can be generated according to a predefined group replication state code and fed back to the group replication state monitoring device.
Preferably, in step S24, when receiving a group copy monitoring operation instruction issued by the group copy status monitoring apparatus based on the group copy status, the method performs an operation corresponding to the group copy monitoring operation instruction on the target group copy node, as shown in fig. 4, and includes the following steps:
s41: analyzing the group of copy monitoring operation instructions to obtain a second message request;
s42: calling a service logic corresponding to the group of copy monitoring operation instructions through the LUA virtual machine;
s43: and executing the operation corresponding to the business logic on the target group replication node.
In this embodiment, the group copy monitoring operation instruction may be received through the external interface, and the second message request may be obtained through parsing. And then sending the second message request to the LUA virtual machine for data processing by the external interface, and calling the corresponding service logic by the LUA virtual machine to execute control operation on the target group replication node.
By the scheme provided by the embodiment, the group replication state of the target group replication node can be inquired, and the target group replication node is correspondingly adjusted when the group replication monitoring operation instruction is received. When the state of the target group copy node is abnormal, the abnormal state of the group copy node can be monitored in time through the scheme provided by the embodiment, the target group copy node is adjusted, the monitoring of the group copy state is realized, manual adjustment is not needed, and the abnormal state of the group copy node can be monitored in time and automatically adjusted.
In order to solve the problems in the prior art, the present embodiment provides a MYSQL database group replication state monitoring method applied to a group replication state monitoring apparatus, as shown in fig. 5a, including the following steps:
s51: issuing a group replication state query instruction to a target group replication node agent device, wherein the group replication state query instruction is used for indicating the target group replication node agent device to query a group replication state of a target group replication node, and the target group replication node corresponds to the group replication node agent device and is used for performing group replication on a MYSQL database;
s52: receiving a group replication state fed back by the target group replication node proxy device based on the group replication state query instruction, and judging whether the group replication state of the target group replication node is normal or not according to the group replication state through a preset rule;
s53: and when the group replication state of the target group replication node is abnormal, issuing a group replication monitoring operation instruction to the target group replication node proxy device according to the group replication state of the target group replication node so as to instruct the target group replication node proxy device to execute an operation corresponding to the group replication monitoring operation instruction on the target group replication node.
As shown in fig. 5b, the group copy state monitoring apparatus according to this embodiment may be applied to a MYSQL database, and specifically may include an external interface and a LUA virtual machine, where the external interface may be a REST interface. The external interface may be configured to encapsulate an instruction generated by the LUA virtual machine as an HTTP message, and send the HTTP message to the target group replication node proxy apparatus. And when the external interface receives the group copy state fed back by the target group copy node proxy device, analyzing the group copy state and sending an analysis result to the LUA virtual machine for processing.
The LUA virtual machine loads a protocol adaptation logic LUA library of each service according to configuration in advance, and then the LUA virtual machine can generate a group replication state query instruction according to the configured information and further send the group replication state query instruction to each target group replication node agent device through an external interface. And for the group replication state fed back by the target group replication node proxy device, the LUA virtual machine judges whether the group replication state is normal according to a preset rule, and if the group replication state is abnormal, the LUA virtual machine sends a corresponding operation instruction to the target group replication node proxy device to adjust the target group replication node, so that the stability of the MYSQL database group replication state is ensured.
Preferably, the step S52, receiving the group replication state fed back by the target group replication node proxy apparatus based on the group replication state query instruction, and determining whether the group replication state of the target group replication node is normal according to the group replication state by using a preset rule, includes:
judging that the group replication state of the target group replication node is abnormal when the group replication state of the target group replication node meets at least one of the following conditions: the target group replication node is inaccessible, the target group replication node is in an offline state, and the group replication efficiency of the target group replication node lags behind.
The group replication state of the target group replication node may be an inaccessible state, an offline state, and a group replication efficiency hysteresis state. When the group replication state of the target group replication node is abnormal, the MYSQL database group replication state is affected. The scheme provided by the embodiment can detect the abnormal state of the target group replication node in time so as to carry out targeted adjustment later.
Preferably, in step S53, when the group replication state of the target group replication node is abnormal, a group replication monitoring operation instruction is issued to the target group replication node proxy apparatus according to the group replication state of the target group replication node to instruct the target group replication node proxy apparatus to perform an operation corresponding to the group replication monitoring operation instruction on the target group replication node, including the following steps:
when the target group replication node cannot be accessed, issuing a group replication function starting instruction to the target group replication node proxy device to instruct the target group replication node proxy device to start a group replication function of the target group replication node;
when the target group replication node is in an off-line state, issuing a group replication starting instruction to the target group replication node proxy device to instruct the target group replication node proxy device to control the target group replication node to execute group replication;
and when the group replication efficiency of the target group replication node lags, issuing a group replication suspension instruction to the target group replication node proxy device to instruct the target group replication node proxy device to control the target group replication node to suspend group replication.
In an actual application process, a group replication state code corresponding to a group replication node state may be predefined, and when the group replication state fed back by the target group replication node proxy apparatus includes a preset group replication state code, a state represented by the group replication state code may be determined according to a predefined rule. For example, when the received group copy status includes the group copy status code "1001", the group copy monitoring operation command issued to the target group copy node proxy apparatus may include an operation command to start a database, set a group copy parameter, and start a group copy function. When the received group copy status includes the group copy status code "2001", the group copy monitoring operation instruction issued to the target group copy node proxy apparatus may include an operation instruction to start a group copy function and the like. When the received group copy status includes the group copy status code "4001", the group copy monitoring operation command issued to the target group copy node proxy apparatus may include stopping the group copy function, sleeping for a certain time, and starting the group copy function.
By the scheme provided by the embodiment, the group replication state of the target group replication node can be inquired, and when the node is in an abnormal state, the group replication monitoring operation instruction is issued according to the actually occurring abnormal state so as to correct the abnormal state of the node, so that the overall stability of the replication state of the MYSQL database group is ensured.
Preferably, as shown in fig. 6, step S51, the issuing a group replication status query command to the target group replication node proxy apparatus includes:
s61: encapsulating a message generated by the LUA virtual machine into a group replication state query instruction, and sending the group replication state query instruction to a target group replication node agent device;
step S52, receiving the group replication status fed back by the target group replication node proxy apparatus based on the group replication status query instruction, includes:
s62: and analyzing the received group of copy states, and sending an analysis result to the LUA virtual machine.
The group replication state monitoring device may issue a group replication state query instruction to the target group replication node agent device according to a preset period. The message generated by the LUA virtual machine can be encapsulated into a group replication state query instruction by the external interface, and then the group replication state query instruction is sent to the target group replication node proxy device.
When the target group replication node proxy apparatus feeds back the group replication state, the external interface may receive and analyze the group replication state, and then send an analysis result to the LUA virtual machine, so that the LUA virtual machine determines whether the state of the target group replication node is abnormal according to the analysis result.
In order to solve the problems in the prior art, as shown in fig. 7, the present embodiment provides a group replication node proxy apparatus 70, including:
a first receiving module 71, configured to receive a group copy status query instruction issued by the group copy status monitoring apparatus;
a first query module 72, configured to query a group replication state of a target group replication node according to the group replication state query instruction, where the target group replication node corresponds to the group replication node proxy apparatus and is used to perform group replication on a MYSQL database;
a first feedback module 73, configured to feed back the group replication state to the group replication state monitoring apparatus, so as to instruct the group replication state monitoring apparatus to determine whether the group replication state of the target group replication node is normal;
a first executing module 74, configured to, when receiving a group copy monitoring operation instruction issued by the group copy state monitoring apparatus based on the group copy state, execute an operation corresponding to the group copy monitoring operation instruction on the target group copy node.
Based on the group replication node proxy apparatus provided in the foregoing embodiment, preferably, the first query module 72 is configured to:
analyzing the group of the replication state query instruction to obtain a first message request;
executing an SQL statement corresponding to the first message request on a target MYSQL database corresponding to the target group replication node according to the loaded service logic by the LUA virtual machine;
and generating the group replication state of the target group replication node according to the response result of the target MYSQL database to the SQL statement.
Based on the group replication node proxy apparatus provided in the foregoing embodiment, preferably, the first executing module 74 is configured to:
analyzing the group of copy monitoring operation instructions to obtain a second message request;
calling a service logic corresponding to the group of copy monitoring operation instructions through the LUA virtual machine;
and executing the operation corresponding to the business logic on the target group replication node.
In order to solve the problems in the prior art, as shown in fig. 8, the present embodiment provides a group copy status monitoring apparatus 80, including:
a second sending module 81, configured to issue a group replication state query instruction to a target group replication node proxy apparatus, where the group replication state query instruction is used to instruct the target group replication node proxy apparatus to query a group replication state of a target group replication node, and the target group replication node corresponds to the group replication node proxy apparatus and is used to perform group replication on a MYSQL database;
a second receiving module 82, configured to receive a group replication state fed back by the target group replication node proxy apparatus based on the group replication state query instruction, and determine whether the group replication state of the target group replication node is normal according to the group replication state through a preset rule;
the second control module 83, when the group replication state of the target group replication node is abnormal, issues a group replication monitoring operation instruction to the target group replication node proxy apparatus according to the group replication state of the target group replication node, so as to instruct the target group replication node proxy apparatus to execute an operation corresponding to the group replication monitoring operation instruction on the target group replication node.
Based on the above-mentioned group copy status monitoring apparatus, preferably, the second receiving module 82 is configured to:
judging that the group replication state of the target group replication node is abnormal when the group replication state of the target group replication node meets at least one of the following conditions: the target group replication node is inaccessible, the target group replication node is in an offline state, and the group replication efficiency of the target group replication node lags behind.
Based on the above-mentioned group copy status monitoring apparatus, preferably, the second control module 83 is configured to:
when the target group replication node cannot be accessed, issuing a group replication function starting instruction to the target group replication node proxy device to instruct the target group replication node proxy device to start a group replication function of the target group replication node;
when the target group replication node is in an off-line state, issuing a group replication starting instruction to the target group replication node proxy device to instruct the target group replication node proxy device to control the target group replication node to execute group replication;
and when the group replication efficiency of the target group replication node lags, issuing a group replication suspension instruction to the target group replication node proxy device to instruct the target group replication node proxy device to control the target group replication node to suspend group replication.
Based on the above group copy status monitoring apparatus, preferably, the second sending module 81 is configured to:
encapsulating a message generated by the LUA virtual machine into a group replication state query instruction, and sending the group replication state query instruction to a target group replication node agent device;
receiving the group replication state fed back by the target group replication node proxy device based on the group replication state query instruction includes:
and analyzing the received group of copy states, and sending an analysis result to the LUA virtual machine.
In order to solve the problems in the prior art, referring to fig. 1, the present embodiment provides a MYSQL database group replication state monitoring system, which includes the group replication state monitoring apparatus described in the foregoing embodiment and at least one group replication node agent apparatus described in the foregoing embodiment, which is communicatively connected to the group replication state monitoring apparatus through an external interface.
Preferably, an embodiment of the present invention further provides an electronic device, which includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor, where the computer program, when executed by the processor, implements each process of the foregoing MYSQL database group copy status monitoring method embodiment, and can achieve the same technical effect, and in order to avoid repetition, details are not repeated here.
The embodiment of the invention also provides a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when being executed by a processor, the computer program realizes each process of the MYSQL database group replication state monitoring method embodiment, and can achieve the same technical effect, and in order to avoid repetition, the details are not repeated here. The computer-readable storage medium may be a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
While the present invention has been described with reference to the embodiments shown in the drawings, the present invention is not limited to the embodiments, which are illustrative and not restrictive, and it will be apparent to those skilled in the art that various changes and modifications can be made therein without departing from the spirit and scope of the invention as defined in the appended claims.