A service switching method, device, system and storage medium
By using the master lock failure and lock-up mechanism between the management node and the service node, the heartbeat information is used to promptly discover faults and select new master nodes, the problem of poor real-time switching of single-point deployment and multi-point deployment server information service is solved, and the problem of poor real-time switching of single-point deployment and multi-point deployment server information service is improved. The availability and quality of information services.
Patent Information
- Application Number
- CN202011627556.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-31
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2040-12-31
AI Technical Summary
In the prior art, the information service availability of a single-point deployment server is poor, and the real-time switching of information service in the event of a failure of a multi-point deployment server is poor, which affects the quality of information service.
By implementing the master lock failure and lock-up mechanism between the management node and the service node, using heartbeat information to promptly detect the master node failure, and selecting a new master node to handle client requests based on the lock-up information, improving the real-time and efficiency of service switching .
It realizes rapid detection of node failures, improves the real-time nature of information service switching, reduces the impact of failed service nodes on information services, and enhances the quality of information services.
Smart Images

Figure CN113904914B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of automation control technology, and in particular to a service switching method, device, system and storage medium. Background Art
[0002] With the development of communication network technology, information services have gradually become an indispensable part of life. The availability of information services depends greatly on the stable operation of servers. Existing servers provide information services in the following ways: 1. Single-point deployment, where only one server provides information services. 2. Multi-point deployment, where multiple servers provide information services. Each server node runs the same information service and uses load balancing to meet user service requests.
[0003] In the process of implementing the present invention, it is found that the prior art has the following technical problems:
[0004] For servers deployed at a single point, the information service availability they provide is poor. Once a server fails, the information service cannot be switched, resulting in the client being unable to obtain information services. For servers deployed at multiple points, a load balancing method is used to forward the information service requests from the user end to each service node. When a service node fails, the management node needs to actively detect the service node failure and adjust the forwarding rules for the information service request to achieve information service switching. This method takes a lot of time to detect and adjust the rules, resulting in poor real-time switching of information services, which affects the quality of information services. Summary of the invention
[0005] The present invention provides a service switching method, device, system and storage medium to realize rapid discovery of node failures, improve the real-time performance of information service switching, and improve the quality of information services.
[0006] In a first aspect, an embodiment of the present invention provides a service switching method, which is applied to a management node. The method includes:
[0007] If the heartbeat information of the master node is not received within the valid time of the master lock of the corresponding master node, the master lock is controlled to be invalid;
[0008] Receiving lock snatching information sent by a service node, wherein the service node includes at least one of a primary node and a backup node;
[0009] A new master node is selected from the service nodes according to the lock snatching information, wherein the master node is used to process the information service request sent by the client.
[0010] In a second aspect, an embodiment of the present invention further provides a service switching method, which is applied to a service node, and the method includes:
[0011] Send lock grabbing information and heartbeat information to the management node so that the management node can determine the new master node;
[0012] When receiving an information service request, it provides information services to the client based on the current node role.
[0013] In a third aspect, an embodiment of the present invention further provides a service switching device, which is applied to a management node, and the device includes:
[0014] A master lock failure module, used to control the master lock to fail if the heartbeat information of the master node is not received within the valid time of the master lock of the corresponding master node;
[0015] A lock grabbing trigger module, used to receive lock grabbing information sent by a service node, wherein the service node includes at least one of a primary node and a backup node;
[0016] The switching execution module is used to select a new master node from the service nodes according to the lock snatching information, wherein the master node is used to process the information service request sent by the client.
[0017] In a fourth aspect, an embodiment of the present invention further provides a service switching device, which is applied to a service node, and the device includes:
[0018] An information sending module, used for sending lock snatching information and heartbeat information to the management node, so that the management node determines a new master node;
[0019] The information service module is used to provide information services to the client according to the current node role when receiving an information service request.
[0020] In the fifth aspect, an embodiment of the present invention also provides a service switching system, which includes: a management node, a service node and a client; wherein the management node is used to execute any service switching method described in the embodiments of the present invention; the service node is used to execute any service switching method described in the embodiments of the present invention; the client is used to send an information server to the service node to obtain information services.
[0021] In a sixth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the service switching method as described in any one of the embodiments of the present invention is implemented.
[0022] In an embodiment of the present invention, the master lock is controlled to be invalid when it is determined that the heartbeat information of the master node is not received within the effective time of the master lock of the corresponding master node, and the lock grabbing information sent by the service node is obtained. The service node may include at least one of the master node and the backup node. The service node is selected as the new master node according to the lock grabbing information. The master node is used to process the information service request sent by the client, and the master node failure is discovered in time through the effective time of the master lock and the heartbeat information, and the new master node is selected through the lock grabbing information, thereby realizing the timeliness of service node failure discovery, improving the service switching efficiency, reducing the impact of the failed service node on the information service, and enhancing the quality of information services. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 is a flow chart of a service switching method provided by Embodiment 1 of the present invention;
[0024] Figure 2 is a flow chart of another service switching method provided by Embodiment 2 of the present invention;
[0025] Figure 3 is a flow chart of a service switching method provided by Embodiment 3 of the present invention;
[0026] Figure 4 This is an example diagram of a service switching method provided by Embodiment 3 of the present invention;
[0027] Figure 5 This is an example diagram of address feedback of a backup node provided in Embodiment 3 of the present invention;
[0028] Figure 6 is a structural diagram of a service switching device provided by Embodiment 4 of the present invention;
[0029] Figure 7 is a structural diagram of another service switching device provided in Embodiment 5 of the present invention;
[0030] Figure 8 is a structural diagram of a service switching system provided by Embodiment 6 of the present invention;
[0031] Fig. 9 It is a structural schematic diagram of an electronic device provided in Embodiment 6 of the present invention. DETAILED DESCRIPTION
[0032] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention are shown in the accompanying drawings, rather than all structures. In addition, the embodiments of the present invention and the features in the embodiments may be combined with each other without conflict.
[0033] Embodiment 1
[0034] Figure 1 is a flow chart of a service switching method provided in the first embodiment of the present invention. This embodiment is applicable to the case where a service node fails and switches the service to another service node. The method can be executed by a service switching device, which can be implemented in hardware and / or software and is generally integrated in a management node. Figure 1 The method provided in the embodiment of the present invention specifically includes the following steps:
[0035] Step 110: If the heartbeat information of the master node is not received within the valid time of the master lock of the corresponding master node, the master lock is controlled to fail.
[0036] Among them, the master node can be a node in which the system service provider provides information services to users, and a thread for information services can be set in the master node; the master lock can be information that locks the service node as the master node, and the effective time of the master lock can be the effective time of the service node as the master node, and the effective time of the master lock can be specifically determined by a timer; the heartbeat information can be information that the master node notifies the management node of its own normal operation, and the heartbeat information can include the master node identification information and status information.
[0037] In an embodiment of the present invention, the management node can continuously monitor the heartbeat information sent by the master node. When the heartbeat information is received, if the heartbeat information of the master node is not received for a time length corresponding to the effective time of the master node, the management node can determine that the master node is faulty and the master node cannot continue to provide information services to the user. At this time, the master lock corresponding to the master node can be controlled to fail, for example, the write-forbidden permission of the lock information of the master node is released, and other service nodes can change the lock information. Furthermore, if the heartbeat information of the master node is received within the effective time of the master lock, the effective time of the master lock can be extended so that the master node continues to provide information services.
[0038] Step 120: Receive lock snatching information sent by a service node, wherein the service node includes at least one of a primary node and a backup node.
[0039] The lock grabbing information may be information about the service node grabbing the main lock, which may include the service node's identification information and operation information, etc. The lock grabbing information may be used to change the main lock in the management node. The backup node may be a service node, which may be configured with the same service as the main node. When the main node fails, the backup node may take over the main node to provide information services. The main node and the backup node may be service nodes that back up each other. When the service node grabs the main lock, the service node may be the main node, and other service nodes that have not grabbed the main lock may be backup nodes.
[0040] Specifically, after the main lock controlled by the management node fails, it can receive lock-grabbing information sent by one or more service nodes, where the lock-grabbing information can be actively sent by the service node according to a timing, and the service node can send the lock-grabbing information to the management node once every 300 milliseconds. The management node can receive these lock-grabbing information after the main lock fails. The service node that sends the lock-grabbing information may include a service node that was previously judged to be a main node, and may also include a service node that was previously judged to be a backup node.
[0041] Step 130: Select a new master node from the service nodes according to the lock snatching information, wherein the master node is used to process the information service request sent by the client.
[0042] Among them, the client can provide the user with software and hardware programs for local services. The client can send an information service request to the main node to obtain information services. The information service request may include the type and duration of the requested information service.
[0043] In the embodiment of the present invention, a service node can be reselected as a new master node from one or more service nodes that sent the lock snatching information based on the received service information. The criteria for selecting the new master node may include the operating status included in the lock snatching information or the receiving time of the lock snatching information. For example, a service node with the smallest load can be selected as the new master node from the service nodes that sent the lock snatching information. A service node corresponding to the earliest receiving time can also be selected from the service nodes that sent the lock snatching information as the new master node. It is understandable that the original master node can also be selected as the new master node based on the corresponding lock snatching information.
[0044] The embodiment of the present invention controls the master lock to fail when the heartbeat information of the master node is not received within the master lock validity period of the master node, collects the lock grabbing information sent by each service node, selects the service node as the new master node according to the lock grabbing information, the master node is used to process the information service request sent by the client, timely discovers the master node failure through the master lock validity period and heartbeat information, and selects the new master node through the lock grabbing information, thereby realizing the timeliness of service node failure discovery, improving the service switching efficiency, reducing the impact of the faulty service node on the information service, and enhancing the information service quality.
[0045] Embodiment 2
[0046] Figure 2 is a flowchart of another service switching method provided by Embodiment 2 of the present invention. This embodiment of the present invention is a specific implementation of the above-mentioned embodiment of the invention. Figure 2 The method provided in the embodiment of the present invention specifically includes the following steps:
[0047] Step 210: After starting at least two service nodes at the same time, obtain the lock grabbing information of each service node.
[0048] In the embodiment of the present invention, when a service is started, the management node can control the service node corresponding to the service to start. After the service node is started, it can send lock grabbing information to the management node, and the management node can receive the lock grabbing information including the identification information and operation status information of the corresponding service node. It can be understood that one or more service nodes can be configured with relevant information for providing services, and the configuration information of service nodes corresponding to the same service can be the same.
[0049] Step 220: The service node corresponding to the first received lock snatching information is used as the master node, and a master lock of the master node is generated.
[0050] Specifically, when the management node receives the first lock snatching information, it can select the service node corresponding to the lock snatching information as the main node, and correspondingly, other service nodes that have not been selected as the main node can be recorded as backup nodes. When selecting the main node, the identification information of the service node can be recorded and an effective time can be set to implement the main lock of the main node, and the effective time can be the effective time of the main lock of the corresponding main node.
[0051] Step 230: If the heartbeat information of the master node is not received within the valid time of the master lock of the corresponding master node, the master lock is controlled to fail.
[0052] Step 240: Receive lock snatching information sent by a service node, wherein the service node includes at least one of a primary node and a backup node.
[0053] Further, based on the above-mentioned embodiment of the invention, the lock grabbing information sent by the service node is heartbeat information.
[0054] In the embodiment of the present invention, the service node may send heartbeat information to the management node regularly according to the heartbeat duration, and the master node may use the received heartbeat information as its corresponding lock grabbing information.
[0055] Step 250: Use the first received lock grabbing information as the target lock grabbing information, and obtain the target service node corresponding to the target lock grabbing information.
[0056] The target lock grabbing information may be lock grabbing information used to select the master node to use, and the target service node may be a service node corresponding to the target lock grabbing information.
[0057] In an embodiment of the present invention, the management node can use the lock grabbing information first received after the master lock fails as the target lock grabbing information, and can extract the service node identifier included in the target lock grabbing information, and select the corresponding service node as the target service node according to the service node identifier.
[0058] Step 260: Generate a master lock corresponding to the target service node, so that the target service node serves as a master node for processing the information service request sent by the client.
[0059] Specifically, a master lock can be generated for the target service node. The process of generating the master lock may include recording the service node identifier of the target service node and setting the effective time of the master lock. For example, the service node identifier can be stored in a fixed storage area, and a write-prohibited permission can be set for the fixed storage area. The effective time of the write-prohibited permission can be the effective time of the master lock of the master node.
[0060] According to an embodiment of the present invention, after starting at least two service nodes, the corresponding lock grabbing information of each service node is obtained, the service node corresponding to the lock grabbing information received first is selected as the master node and a corresponding master lock is generated, and when the heartbeat information of the master node is not received within the effective time of the master lock, the master node is controlled to be invalid, the heartbeat information of the service node is obtained as the lock grabbing information, and the lock grabbing information received first is used as the target lock grabbing information, the target service node corresponding to the target lock grabbing information is obtained, and a master lock of the target service node is generated, so that the target service node processes the information service request sent by the client, and the service node failure can be discovered in time, the information service can be quickly switched, the influence of the failed service node on the information service is reduced, and the information service quality is enhanced.
[0061] Further, on the basis of the above-mentioned embodiments of the invention, the generation of the master lock corresponding to the target service node includes: determining the reception time and node identifier of the target lock grabbing information; generating the master lock corresponding to the target service node according to the node identifier, and setting the master lock validity time of the master lock to the sum of the reception time and the preset heartbeat duration.
[0062] The receiving time may be the time when the management node receives the target lock grabbing information sent by the target service node, and the node identifier may be the node identifier of the target service node, which may be a node name or a node number.
[0063] In an embodiment of the present invention, the management node can obtain the receiving time of the target lock grabbing information and extract the node identifier of the target service node from the target lock grabbing information, and can generate a master lock corresponding to the node identifier. When generating the master lock, the master lock effective time is also set for the master lock, and the value of the master lock effective time can be the sum of the receiving time and the preset heartbeat duration, wherein the preset heartbeat duration can be the maximum heartbeat detection duration designed for the master node, and when the heartbeat information of the master node is not obtained within the preset heartbeat duration, it can be determined that the master node is faulty. Exemplarily, the etcd database can be used to store the node identifier of the target service node, and update permissions can be set for the storage record containing the node identifier, and the update permission effective time can be set to the sum of the receiving time and the preset heartbeat duration.
[0064] Figure 3 is a flow chart of a service switching method provided in Embodiment 3 of the present invention. This embodiment is applicable to the case where a service node fails and switches the service to another service node. The method can be executed by a service switching device, which can be implemented in hardware and / or software and is generally integrated in the service node. Figure 3 The method provided in the embodiment of the present invention specifically includes the following steps:
[0065] Step 310: Send lock grabbing information and heartbeat information to the management node so that the management node can determine the new master node.
[0066] In an embodiment of the present invention, the service node can periodically send lock grabbing information and heartbeat information to the management node, so that the management node can select the service node as the new master node based on the sent heartbeat information and lock grabbing information, wherein the time intervals for sending the lock grabbing information and the heartbeat information can be the same or different. For example, the service node can send its own lock grabbing information and heartbeat information to the management node at the same time, and the service node can also send the lock grabbing information and heartbeat information to the management node at different times.
[0067] Step 320: When an information service request is received, provide information service to the client according to the current node role.
[0068] The current node role may be a role of a service node currently providing services to a client, and may include a primary node that provides services to a client and a backup node that does not provide services to a client.
[0069] Specifically, when a service node receives an information service request, it can determine the current node role of the service node. If the service node is a primary node, it can respond to the information service request to provide information services to the client. If the service node is a backup node, it can refuse to respond to the information service request and not process it.
[0070] In the embodiment of the present invention, the service node sends lock grabbing information and heartbeat information to the management node, so that the management node determines the new master node. When the service node receives the information service request, it provides service to the client according to the current node role, thereby realizing timely discovery of faulty service nodes, improving service switching efficiency, reducing the impact of service node failures on information services, and enhancing the quality of information services.
[0071] Further, based on the above-mentioned embodiments of the invention, the sending of lock grabbing information and heartbeat information to the management node so that the management node selects a new master node includes: sending the heartbeat information to the management node according to a preset heartbeat period so that the management node uses the heartbeat information as lock grabbing information to determine the new master node.
[0072] In the embodiment of the present invention, the service node may send only heartbeat information to the management node. When receiving the heartbeat information, the management node may process the heartbeat information as lock grabbing information and select a new master node through the heartbeat information.
[0073] Furthermore, based on the above-mentioned embodiment of the invention, the method further includes: obtaining feedback information of the management node to obtain the Internet Protocol address of the master node.
[0074] The feedback information may be information sent by the management node to the service node, and the feedback information may carry the Internet Protocol address of the current master node.
[0075] In the embodiment of the present invention, the management node may send feedback information to the service node, where the feedback information includes an Internet Protocol address, and the service node may determine the location of the master node through the feedback information.
[0076] Further, based on the above-mentioned embodiments of the invention, when an information service request is received, information service is provided to the client according to the current node role, including: if the current node role is a master node, responding to the information service request to provide information service; if the current node role is a backup node, refusing to respond to the information service request and feeding back the Internet Protocol address of the master node.
[0077] Specifically, when the service node is a primary node, it can respond to information service requests sent by the client and provide information services to the client. When the service node is a backup node, it refuses to respond to information service requests sent by the client and sends the Internet Protocol address of the primary node to the client so that the client can obtain the location of the primary node.
[0078] In an exemplary embodiment, Figure 4 is an example diagram of a service switching method provided by Embodiment 3 of the present invention, see Figure 4 In the method provided in the embodiment of the present invention, the distributed consistency component can be used as a management node. The method can include two service nodes, and the two service nodes can include the same information service. When the service is started, two service nodes can be started. The two service nodes simultaneously seize the main lock from the consistency service component. Only one service node seizes the main lock. The service node serves as the master node, and the other service node serves as the backup node. For the master node, the main service logic is executed: maintain the heartbeat with the consistency service component once every 300 milliseconds; and process the information service request of the client. For the backup node, the backup service logic is executed: continue to seize the master lock once every 300 milliseconds. Once the heartbeat disappears, the backup seizes the master lock and becomes the master node; does not process the information service request of the client; after receiving the information service request of the client, informs the client of the address of the master node. Figure 5 This is an example diagram of a backup node address feedback provided by Embodiment 3 of the present invention, see Figure 5 The above picture occurs when the master-slave switch occurs. After the backup node receives the information service request from the client, it tells the client the Internet Protocol address of the primary node. After the client receives the return result from the backup node, it sends an information service request to the primary node.
[0079] Embodiment 4
[0080] Figure 6 is a schematic diagram of the structure of a service switching device provided by Embodiment 4 of the present invention, see Figure 6 , can execute the service switching method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method. The device can be implemented by software and / or hardware, generally integrated in the management node, and specifically includes: a master lock failure module 401, a lock snatching trigger module 402 and a switching execution module 403.
[0081] A master lock failure module 401 is used to control the master lock to fail if the heartbeat information of the master node is not received within the master lock validity period of the corresponding master node;
[0082] The lock grabbing triggering module 402 is used to receive the lock grabbing information sent by the service node, wherein the service node includes at least one of a primary node and a backup node;
[0083] The switching execution module 403 is used to select a new master node from the service nodes according to the lock grabbing information, wherein the master node is used to process the information service request sent by the client.
[0084] In the embodiment of the present invention, the master lock is controlled to fail when the master lock failure module does not receive the heartbeat information of the master node within the master lock validity time of the master node. The lock grabbing trigger module collects the lock grabbing information sent by each service node. The switching execution module selects the service node as the new master node according to the lock grabbing information. The master node is used to process the information service request sent by the client. The master node failure is discovered in time through the master lock validity time and the heartbeat information, and the new master node is selected through the lock grabbing information, thereby realizing the timeliness of service node failure discovery, improving the service switching efficiency, reducing the impact of the failed service node on the information service, and enhancing the information service quality.
[0085] Furthermore, based on the above-mentioned embodiments of the invention, the startup module is used to obtain the lock grabbing information of each service node after starting at least two service nodes at the same time; take the service node corresponding to the lock grabbing information received first as the main node, and generate the main lock of the main node.
[0086] Further, based on the above-mentioned embodiment of the invention, the lock grabbing information sent by the service node in the lock grabbing triggering module 402 is heartbeat information.
[0087] Further, based on the above-mentioned embodiment of the invention, the switching execution module 403 includes:
[0088] The node determination unit is used to use the first received lock grabbing information as the target lock grabbing information, and obtain the target service node corresponding to the target lock grabbing information.
[0089] The master lock setting unit is used to generate a master lock corresponding to the target service node, so that the target service node serves as a master node for processing the information service request sent by the client.
[0090] Furthermore, based on the above-mentioned embodiments of the invention, the master lock setting unit is specifically used to: determine the receiving time and node identifier of the target lock grabbing information; generate a master lock corresponding to the target service node according to the node identifier, and set the master lock effective time of the master lock to the sum of the receiving time and the preset heartbeat duration.
[0091] Embodiment 5
[0092] Figure 7 is a structural diagram of another service switching device provided in Embodiment 5 of the present invention, see Figure 7 , can execute the service switching method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method. The device can be implemented by software and / or hardware, generally integrated in the service node, and specifically includes: information sending module 501 and information service module 502.
[0093] The information sending module 501 is used to send lock grabbing information and heartbeat information to the management node, so that the management node can determine a new master node.
[0094] The information service module 502 is used to provide information service to the client according to the current node role when receiving an information service request.
[0095] In the embodiment of the present invention, the information sending module sends the lock grabbing information and the heartbeat information to the management node, so that the management node determines the new master node. When the information service module receives the information service request, it provides services to the client according to the current node role, thereby realizing the timely discovery of the faulty service node, improving the service switching efficiency, reducing the impact of the service node failure on the information service, and enhancing the quality of the information service.
[0096] Further, based on the above-mentioned embodiment of the invention, the information sending module 501 includes:
[0097] The heartbeat sending unit is used to send the heartbeat information to the management node according to a preset heartbeat period, so that the management node uses the heartbeat information as lock grabbing information to determine a new master node.
[0098] Further, based on the above-mentioned embodiment of the invention, the device further includes:
[0099] The master address module is used to obtain feedback information from the management node to obtain the Internet Protocol address of the master node.
[0100] Further, based on the above-mentioned embodiment of the invention, the information service module 502 includes:
[0101] The main processing unit is used to respond to the information service request to provide information service if the current node role is a master node.
[0102] A backup processing unit is used to refuse to respond to the information service request and feedback the Internet Protocol address of the primary node if the current node role is a backup node.
[0103] Figure 8 is a structural diagram of a service switching system provided by Embodiment 6 of the present invention, Figure 8 The system shown at least includes a management node, a service node and a client. The management node is connected to the service node to obtain lock snatching information and heartbeat information. The management node can perform any service switching method provided in the embodiments of the present invention. The method includes: if the heartbeat information of the master node is not received within the effective time of the master lock of the corresponding master node, the master lock is controlled to be invalid; receiving the lock snatching information sent by the service node, wherein the service node includes at least one of the master node and the backup node; selecting a new master node from the service node according to the lock snatching information, wherein the master node is used to process the information service request sent by the client. The service node is connected to the client and the management node respectively, sends heartbeat information and lock snatching information to the management node, receives the information service request sent by the user end and responds to the information service request according to the situation. The service node can perform any service switching method provided in the embodiments of the present invention. The method includes: sending lock snatching information and heartbeat information to the management node so that the management node determines the new master node; providing information service to the client according to the current node role when receiving the information service request. The client is used to send an information service request to the service node to obtain information service.
[0104] Furthermore, Fig. 9 is a schematic diagram of the structure of an electronic device provided by Embodiment 6 of the present invention, such as Fig. 9 As shown, the electronic device includes a processor 60, a memory 61, an input device 62 and an output device 63; the number of the processor 60 in the electronic device can be one or more. Fig. 9A processor 60 is taken as an example; the processor 60, the memory 61, the input device 62 and the output device 63 in the electronic device can be connected by a bus or other means. Fig. 9 The example of connecting through bus is taken in the following.
[0105] The memory 61 is a computer-readable storage medium that can be used to store software programs, computer executable programs and modules, such as the program modules corresponding to the service switching method in the embodiment of the present invention (for example, the main lock failure module 401, the lock snatching trigger module 402 and the switching execution module 403 or the information sending module 501 and the information service module 502 in the service switching device). The processor 60 executes various functional applications and data processing of the electronic device by running the software programs, instructions and modules stored in the memory 61, that is, realizing the above-mentioned service switching method.
[0106] The memory 61 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal, etc. In addition, the memory 61 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 61 may further include a memory remotely arranged relative to the processor 60, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0107] The input device 62 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the electronic device. The output device 63 may include a display device such as a display screen.
[0108] Embodiment 7
[0109] Embodiment 7 of the present invention further provides a storage medium including computer executable instructions, wherein the computer executable instructions are used to execute a service switching method when executed by a computer processor, the method comprising:
[0110] If the heartbeat information of the master node is not received within the valid time of the master lock of the corresponding master node, the master lock is controlled to be invalid;
[0111] Receiving lock snatching information sent by a service node, wherein the service node includes at least one of a primary node and a backup node;
[0112] A new master node is selected from the service nodes according to the lock snatching information, wherein the master node is used to process the information service request sent by the client.
[0113] or,
[0114] Send lock grabbing information and heartbeat information to the management node so that the management node can determine the new master node;
[0115] When receiving an information service request, it provides information services to the client based on the current node role.
[0116] Of course, the computer executable instructions of a storage medium containing computer executable instructions provided by an embodiment of the present invention are not limited to the method operations described above, and can also execute related operations in the service switching method provided by any embodiment of the present invention.
[0117] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0118] It is worth noting that in the embodiment of the above-mentioned service switching device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0119] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A service switching method, characterized in that: Applied to a management node, the method comprises: If the heartbeat information of the master node is not received within the valid time of the master lock of the corresponding master node, the master lock is controlled to be invalid; Receiving lock snatching information sent by a service node, wherein the service node includes a primary node and a backup node; the lock snatching information sent by the service node is heartbeat information; Selecting a new master node from the service nodes according to the lock snatching information, wherein the master node is used to process the information service request sent by the client; The selecting a new master node from the service nodes according to the lock snatching information includes: The first received lock snatching information is used as the target lock snatching information, and the target service node corresponding to the target lock snatching information is obtained; Generate a master lock corresponding to the target service node, so that the target service node serves as a master node for processing information service requests sent by the client; The generating a master lock corresponding to the target service node includes: Determine the receiving time and node identification of the target lock grabbing information; Generate a master lock corresponding to the target service node according to the node identifier, and set the master lock validity period of the master lock to the sum of the receiving time and the preset heartbeat duration; Among them, the preset heartbeat duration is the maximum heartbeat detection duration designed by the master node.
2. The method according to claim 1, characterized in that Also includes: After starting at least two service nodes at the same time, obtaining lock grabbing information of each of the service nodes; The service node corresponding to the lock snatching information received first is used as the master node, and a master lock of the master node is generated.
3. A service switching method, characterized in that: Applied to a service node, the method comprises: Send lock grabbing information and heartbeat information to the management node so that the management node can determine the new master node; When receiving an information service request, provide information services to the client according to the current node role; The sending of lock grabbing information and heartbeat information to the management node so that the management node selects a new master node includes: Send the heartbeat information to the management node according to a preset heartbeat period, so that the management node uses the heartbeat information as lock grabbing information to determine a new master node; The step of using the heartbeat information as lock grabbing information to determine a new master node includes: The first received lock snatching information is used as the target lock snatching information, and the target service node corresponding to the target lock snatching information is obtained; Generate a master lock corresponding to the target service node, so that the target service node serves as a master node for processing information service requests sent by the client; The generating a master lock corresponding to the target service node includes: Determine the receiving time and node identification of the target lock grabbing information; Generate a master lock corresponding to the target service node according to the node identifier, and set the master lock validity time of the master lock to the sum of the receiving time and the preset heartbeat duration; Among them, the preset heartbeat duration is the maximum heartbeat detection duration designed by the master node.
4. The method according to claim 3, characterized in that Also includes: Acquire feedback information of the management node to acquire the Internet Protocol address of the master node.
5. The method according to claim 4, characterized in that The providing information service to the client according to the current node role upon receiving the information service request includes: If the current node role is a master node, responding to the information service request to provide information service; If the current node role is a backup node, it refuses to respond to the information service request and feeds back the Internet Protocol address of the primary node.
6. A service switching device, characterized in that: Applied to a management node, the device comprises: A master lock failure module, used to control the master lock to fail if the heartbeat information of the master node is not received within the valid time of the master lock of the corresponding master node; The lock grabbing trigger module is used to receive the lock grabbing information sent by the service node, wherein the service node includes a primary node and a backup node; the lock grabbing information sent by the service node is a heartbeat information; A switching execution module, used to select a new master node from the service nodes according to the lock snatching information, wherein the master node is used to process the information service request sent by the client; The switching execution module includes: A node determination unit, configured to use the first received lock grabbing information as target lock grabbing information, and obtain a target service node corresponding to the target lock grabbing information; A master lock setting unit, used to generate a master lock corresponding to the target service node, so that the target service node serves as a master node for processing an information service request sent by a client; The master lock setting unit is specifically used to: determine the reception time and node identification of the target lock grabbing information; generate a master lock corresponding to the target service node according to the node identification, and set the master lock validity time of the master lock to the sum of the reception time and the preset heartbeat duration; Among them, the preset heartbeat duration is the maximum heartbeat detection duration designed by the master node.
7. A service switching device, characterized in that: Applied to a service node, the device comprises: An information sending module, used for sending lock snatching information and heartbeat information to the management node, so that the management node determines a new master node; An information service module is used to provide information services to the client according to the current node role when receiving an information service request; The information sending module includes: a heartbeat sending unit, which is used to send the heartbeat information to the management node according to a preset heartbeat period, so that the management node uses the heartbeat information as lock grabbing information to determine a new master node; The step of using the heartbeat information as lock grabbing information to determine a new master node includes: The first received lock snatching information is used as the target lock snatching information, and the target service node corresponding to the target lock snatching information is obtained; Generate a master lock corresponding to the target service node, so that the target service node serves as a master node for processing information service requests sent by the client; The generating a master lock corresponding to the target service node includes: Determine the receiving time and node identification of the target lock grabbing information; Generate a master lock corresponding to the target service node according to the node identifier, and set the master lock validity time of the master lock to the sum of the receiving time and the preset heartbeat duration; Among them, the preset heartbeat duration is the maximum heartbeat detection duration designed by the master node.
8. A service switching system, characterized in that: The system at least includes: a management node, a service node and a client; Wherein, the management node is used to execute the service switching method described in any one of claims 1-2; The service node is used to execute the service switching method described in any one of claims 3 to 5; The client is used to send an information service request to the service node to obtain information service.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the service switching method as described in any one of claims 1-2 or 3-5 is implemented.
Citation Information
Patent Citations
Server hot backup system and method
CN103530200A
Distributed storage system service node switching method and device
CN106856489A