A master-slave switching method, device, equipment and readable storage medium
By receiving and analyzing the connection status information of the two data service nodes, judging and switching the master data service node and its transmission route, the "double master" or "double slave" problem during master-slave structure switching in the prior art is solved, and the service availability is improved.
Patent Information
- Application Number
- CN202211537115.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-02
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2042-12-02
AI Technical Summary
The existing master-slave or master-slave structure switching methods cannot accurately judge the connection situation when the connection between the master data service node and the slave data service node is abnormal, resulting in the possibility of "double master" or "double slave" situation, which reduces the availability of services.
By receiving the connection status information of the two data service nodes, the current main data service node and its transmission route are obtained, and the connection status of the main data service node and the hardware device is judged. If it is abnormal, the target main data service node and the target transmission route are determined based on the connection status information, and the switching is performed.
This greatly reduces the probability that two data service nodes cannot communicate, improves the fault tolerance of the service on the master-slave handover, and thus improves the availability of the service.
Smart Images

Figure CN116112346B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communications, and more specifically, to a master-slave switching method, device, equipment, and readable storage medium. Background Art
[0002] Currently, in industrial sites, services are often required to run uninterruptedly around the clock. However, such services are often prone to single point failures or cross-network failures, that is, if a point in the system fails, the entire system will not function. In order to cope with this situation, services are usually designed with redundancy to improve the high availability of services. Common redundant designs include master-slave structure and master-slave structure.
[0003] The switching method of the master-slave structure or master-backup structure in existing services is usually that the master data service node and the slave data service node directly connect and communicate, send the connection status of the nodes to each other, and immediately switch the master from the slave when an abnormality occurs on one side. However, in this method, once the connection between the master data service node and the slave data service node is abnormal, the master data service node and the slave data service node cannot know each other's connection status, and it is very easy to have a "double master" or "double slave" situation, which greatly reduces the fault tolerance of the service in the master-slave switching, thereby reducing the availability of the service. Summary of the invention
[0004] The embodiments of the present application provide a master-slave switching method, apparatus, device and readable storage medium, which can greatly reduce the probability that two data service nodes cannot communicate, improve the fault tolerance of the service in master-slave switching, and thus improve the availability of the service.
[0005] In view of this, an embodiment of the present application provides an active switching method, which is applied to a redis cluster, including:
[0006] Respectively receiving first connection status information and second connection status information sent by a first data service node and a second data service node, wherein the first connection status information includes a connection status between the first data service node and a hardware device, and the second connection status information includes a connection status between the second data service node and the hardware device;
[0007] Obtain the current master data service node and the transmission route between the master data service node and the hardware device;
[0008] Determining whether the connection status between the primary data service node and the hardware device is normal according to the first connection status information and the second connection status information;
[0009] If the connection status between the master data service node and the hardware device is abnormal, determining a target master data service node and a target transmission line between the target master data service node and the hardware device according to the first connection status information and the second connection status information;
[0010] The master data service node at the current moment is switched to the target master data service node, and the transmission line is switched to the target transmission line.
[0011] Optionally, the first connection status information includes the connection status of the first data service node with the first data acquisition node and the second data acquisition node respectively, and also includes the connection status between the first data acquisition node and the hardware device, and the connection status between the second data acquisition node and the hardware device; the second connection status information includes the connection status of the second data service node with the first data acquisition node and the second data acquisition node respectively; and also includes the connection status between the first data acquisition node and the hardware device, and the connection status between the second data acquisition node and the hardware device.
[0012] Optionally, judging whether the connection status between the primary data service node and the hardware device is normal according to the first connection status information and the second connection status information includes:
[0013] Acquire the connection status between the master data service node and the master data collection node and the connection status between the master data collection node and the hardware device from the first status information and the second status information, wherein the master data collection node is a data collection node connected to the master data service node in the transmission line;
[0014] Determine whether the connection status between the master data service node and the master data acquisition node and the connection status between the master data acquisition node and the hardware device are both normal;
[0015] If the connection status between the master data service node and the master data collection node and the connection status between the master data collection node and the hardware device are both normal, then determining that the connection status between the master data service node and the hardware device is normal;
[0016] If at least one of the connection status between the master data service node and the master data collection node and the connection status between the master data collection node and the hardware device is abnormal, it is determined that the connection status between the master data service node and the hardware device is abnormal.
[0017] Optionally, determining a target master data service node and a target transmission line between the target master data service node and the hardware device according to the first connection state information and the second connection state information includes:
[0018] Determine a target master data service node and a target master data collection node from the first connection status information and the second connection status information, the connection status between the target master data service node and the target master data collection node is normal, and the connection status between the target master data collection node and the hardware device is normal;
[0019] A target transmission line is generated according to the target master data service node and the master data acquisition node.
[0020] Optionally, after switching the master data service node at the current moment to the target master data service node and switching the transmission line to the target transmission line, the method further includes:
[0021] The connection status of the target transmission line is recorded, and the connection status of the target transmission line is sent to the first data service node and the second data service node respectively.
[0022] Optionally, if the connection status between the master data service node and the hardware device is normal, the connection status between the master data service node and the hardware device is sent to the first data service node and the second data service node respectively.
[0023] The embodiment of the present application also provides a master-slave switching device, which is applied to a redis cluster, including:
[0024] A receiving unit, configured to respectively receive first connection status information and second connection status information sent by a first data service node and a second data service node, wherein the first connection status information includes a connection status between the first data service node and a hardware device, and the second connection status information includes a connection status between the second data service node and the hardware device;
[0025] An acquisition unit, used to acquire the master data service node at the current moment and a transmission route between the master data service node and the hardware device;
[0026] a judging unit, configured to judge whether the connection status between the primary data service node and the hardware device is normal according to the first connection status information and the second connection status information;
[0027] a determining unit, configured to determine a target master data service node and a target transmission line between the target master data service node and the hardware device according to the first connection status information and the second connection status information if the connection status between the master data service node and the hardware device is abnormal;
[0028] The switching unit is used to switch the master data service node at the current moment to the target master data service node, and switch the transmission line to the target transmission line.
[0029] Optionally, the first connection status information includes the connection status of the first data service node with the first data acquisition node and the second data acquisition node respectively, and also includes the connection status between the first data acquisition node and the hardware device, and the connection status between the second data acquisition node and the hardware device; the second connection status information includes the connection status of the second data service node with the first data acquisition node and the second data acquisition node respectively; and also includes the connection status between the first data acquisition node and the hardware device, and the connection status between the second data acquisition node and the hardware device.
[0030] The embodiment of the present application also provides a computer device, including: a memory, a processor, and a bus system;
[0031] Wherein, the memory is used to store programs;
[0032] The processor is used to execute the program in the memory to implement any one of the master-slave switching methods described above;
[0033] The bus system is used to connect the memory and the processor so that the memory and the processor can communicate with each other.
[0034] The embodiment of the present application also provides a computer-readable storage medium storing instructions, which, when executed on a computer, enables the computer to execute any one of the master-slave switching methods described above.
[0035] The embodiment of the present application provides a master-slave switching method, which is applied to a redis cluster, including: receiving first connection status information and second connection status information sent by a first data service node and a second data service node respectively, wherein the first connection status information includes the connection status between the first data service node and the hardware device, and the second connection status information includes the connection status between the second data service node and the hardware device; obtaining the master data service node at the current moment and the transmission route between the master data service node and the hardware device; judging whether the connection status between the master data service node and the hardware device is normal according to the first connection status information and the second connection status information; if the connection status between the master data service node and the hardware device is abnormal, determining the target master data service node and the target transmission line between the target master data service node and the hardware device according to the first connection status information and the second connection status information; switching the master data service node at the current moment to the target master data service node, and switching the transmission line to the target transmission line. It can be seen that the present application can obtain the connection status information of two data service nodes respectively based on the redis cluster, and when the connection status of the master data service node is abnormal, the current master data service node can be immediately switched to the target master data service node with a normal connection. Since the two data service nodes are connected based on the redis cluster, the probability of the two data service nodes being unable to communicate is greatly reduced, the fault tolerance of the service in master-slave switching is improved, and the availability of the service is thereby improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0037] Figure 1 A schematic diagram of a master-slave switching method provided in an embodiment of the present application;
[0038] Figure 2 A flowchart of another master-slave switching method provided in an embodiment of the present application;
[0039] Figure 3 A schematic diagram of the structure of a master-slave switching device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0040] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0041] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0042] The switching method of the master-slave structure or master-backup structure in existing services is usually that the master data service node and the slave data service node directly connect and communicate, send the connection status of the nodes to each other, and immediately switch the master from the slave when an abnormality occurs on one side. However, in this method, once the connection between the master data service node and the slave data service node is abnormal, the master data service node and the slave data service node cannot know each other's connection status, and it is very easy to have a "double master" or "double slave" situation, which greatly reduces the fault tolerance of the service in the master-slave switching, thereby reducing the availability of the service.
[0043] Therefore, in response to the above problems, the embodiments of the present application provide a master-slave switching method, apparatus, device and readable storage medium, which can greatly reduce the probability that two data service nodes cannot communicate, improve the fault tolerance of the service in master-slave switching, and thereby improve the availability of the service.
[0044] See also Figure 1 A master-slave switching method provided in an embodiment of the present application includes the following steps.
[0045] S101. Receive first connection status information and second connection status information sent by a first data service node and a second data service node respectively, wherein the first connection status information includes a connection status between the first data service node and a hardware device, and the second connection status information includes a connection status between the second data service node and the hardware device.
[0046] In this embodiment, the redis cluster can receive the first connection status information and the second connection status information sent by the first data service node and the second data service node respectively, wherein the first connection status information includes the connection status between the first data service node and the hardware device, and wherein the second connection status information includes the connection status between the second data service node and the hardware device. It can be understood that the first data service node and the second data service node can establish a communication connection with the redis cluster, the first data service node and the second data service node can obtain their own connection status information, and send their own connection status information to the redis cluster in real time, so that the redis cluster can grasp the connection status of the first data service node and the second data service node in real time, that is, one of the data service nodes can subscribe to the connection status of another data service node from the redis cluster at any time.
[0047] Specifically, the first data service node can be connected to the first data acquisition node and the second data acquisition node respectively, and the second data service node can also be connected to the first data acquisition node and the second data acquisition node respectively. The first data acquisition node and the second data acquisition node are both connected to the hardware device.
[0048] In one possible implementation, the first connection status information includes the connection status of the first data service node with the first data acquisition node and the second data acquisition node respectively, and also includes the connection status between the first data acquisition node and the hardware device and the connection status between the second data acquisition node and the hardware device; the second connection status information includes the connection status of the second data service node with the first data acquisition node and the second data acquisition node respectively; and also includes the connection status between the first data acquisition node and the hardware device and the connection status between the second data acquisition node and the hardware device. It can be understood that the first data service node and the second data service node can obtain the connection status of themselves with the first data acquisition node and the second data acquisition node respectively, and obtain the connection status between the first data acquisition node and the second data acquisition node and the hardware device, and package all the obtained connection status and send them to the redis cluster, where the connection status can be normal or abnormal.
[0049] S102: Acquire the current master data service node and the transmission route between the master data service node and the hardware device.
[0050] In this embodiment, the redis cluster can obtain the master data service node at the current moment and the transmission route between the master data service node and the hardware device. It can be understood that under normal operation, the first data service node and the second data service node have a master data service node and a slave data service node. If the first data service node is the master data service node, the second data service node is the slave data service node; if the second data service node is the master data service node, the first data service node is the slave data service node. And the master data service node at this time also has a transmission route that is being used to communicate with the hardware device. For example, when the first data service node is the master data service node, the transmission route being used by the master data service node and the hardware device at this time can be the first data service node-first data acquisition node-hardware device.
[0051] S103: Determine whether the connection status between the primary data service node and the hardware device is normal according to the first connection status information and the second connection status information.
[0052] In this embodiment, it is possible to determine whether the connection status between the main data service node and the hardware device is normal based on the first connection status information and the second connection status information. It is understandable that after determining the main data service node at the current moment and the transmission route between the main data service node and the hardware device, it is possible to determine whether the connection status between the main data service node and the hardware device is normal based on the first connection status information and the second connection status information. For example, when the first data service node is the main data service node, and the transmission route currently being used by the main data service node and the hardware device is the first data service node-first data acquisition node-hardware device, it is possible to extract from the first connection status information whether the connection status between the first data service node and the first data acquisition node and the connection status between the first data acquisition node and the hardware device is normal for the connection status between the main data service node and the hardware device.
[0053] In one possible implementation, the connection status between the main data service node and the main data acquisition node and the connection status between the main data acquisition node and the hardware device can be obtained from the first status information and the second status information, wherein the main data acquisition node is a data acquisition node connected to the main data service node in the transmission line; it is determined whether the connection status between the main data service node and the main data acquisition node and the connection status between the main data acquisition node and the hardware device are both normal; if the connection status between the main data service node and the main data acquisition node and the connection status between the main data acquisition node and the hardware device are both normal, it is determined that the connection status between the main data service node and the hardware device is normal; if at least one of the connection status between the main data service node and the main data acquisition node and the connection status between the main data acquisition node and the hardware device is abnormal, it is determined that the connection status between the main data service node and the hardware device is abnormal. For example, when the first data service node is the main data service node, and the transmission route being used by the main data service node and the hardware device is the first data service node-first data acquisition node-hardware device, then the first data acquisition node is the main data acquisition node, and the connection status between the first data service node and the first data acquisition node can be extracted from the first status information, and the connection status between the first data acquisition node and the hardware device can be extracted. When the connection status between the first data service node and the first data acquisition node is normal, and the connection status between the first data acquisition node and the hardware device is also normal, it can be confirmed that the connection status between the main data service node and the hardware device is normal at this time, otherwise it is considered that the connection status between the main data service node and the hardware device is abnormal.
[0054] S104: If the connection status between the master data service node and the hardware device is abnormal, determine a target master data service node and a target transmission line between the target master data service node and the hardware device according to the first connection status information and the second connection status information.
[0055] In this embodiment, if the connection status between the master data service node and the hardware device is abnormal, the target master data service node and the target transmission line between the target master data service node and the hardware device are determined based on the first connection status information and the second connection status information. It can be understood that if it is determined that the connection status between the master data service node and the hardware device at the current moment is abnormal, it means that a new master data service node and the transmission line between the new master data service node and the hardware device need to be re-determined to ensure the high availability of the service. At this time, the target master data service node with a normal connection status and the target transmission line with a normal connection status between the target master data service node and the hardware device can be determined based on the first connection status information and the second connection status information.
[0056] In one possible implementation, the target master data service node and the target master data acquisition node can be determined from the first connection status information and the second connection status information, wherein the connection status between the target master data service node and the target master data acquisition node is normal, and the connection status between the target master data acquisition node and the hardware device is normal; the target transmission line is generated according to the target master data service node and the master data acquisition node. For example, if the first connection status information and the second connection status information show that the connection status between the second data service node and the first data acquisition node is normal, and the connection status between the first data acquisition node and the hardware device is normal, then the second data service node can be used as the target master data service node, the first data acquisition node can be used as the target master data acquisition node, and the second data service node-first data acquisition node-hardware device can be used as the target transmission line between the target master data service node and the hardware device.
[0057] S105: Switch the current master data service node to the target master data service node, and switch the transmission line to the target transmission line.
[0058] In this embodiment, the master data service node at the current moment can be switched to the target master data service node, and the transmission line can be switched to the target transmission line. It can be understood that after determining the new target master data service node and the target transmission line between the target master data service node and the hardware device, the master data service node at the current moment can be switched to the target master data service node, and the transmission line can be switched to the target transmission line, thereby completing the master-slave switching in the service.
[0059] In one possible implementation, after the current master data service node is switched to the target master data service node and the transmission line is switched to the target transmission line, the connection status of the target transmission line can also be recorded and sent to the first data service node and the second data service node respectively, so that the first data service node and the second data service node can obtain the updated master data service node and the connection status of the target transmission line between the master data service node and the hardware device, avoiding the situation of "dual master" or "dual slave".
[0060] In one possible implementation, if the connection status between the master data service node and the hardware device is normal, the connection status between the master data service node and the hardware device can be sent to the first data service node and the second data service node respectively. It can be understood that if the connection status between the master data service node and the hardware device is normal, the current master data service node and the transmission line between the master data service node and the hardware device can be unchanged, and the connection status between the master data service node and the hardware device can be sent to the first data service node and the second data service node respectively, to avoid the situation of "dual master" or "dual slave".
[0061] It can be seen that the embodiment of the present application provides a master-slave switching method, which is applied to the redis cluster, including: receiving the first connection status information and the second connection status information sent by the first data service node and the second data service node respectively, the first connection status information includes the connection status of the first data service node and the hardware device, and the second connection status information includes the connection status of the second data service node and the hardware device; obtaining the master data service node at the current moment and the transmission route between the master data service node and the hardware device; judging whether the connection status between the master data service node and the hardware device is normal according to the first connection status information and the second connection status information; if the connection status between the master data service node and the hardware device is abnormal, determining the target master data service node and the target transmission line between the target master data service node and the hardware device according to the first connection status information and the second connection status information; switching the master data service node at the current moment to the target master data service node, and switching the transmission line to the target transmission line. It can be seen that the present application can obtain the connection status information of the two data service nodes respectively based on the redis cluster, and when the connection status of the master data service node is abnormal, the current master data service node can be immediately switched to the target master data service node with normal connection. Since the two data service nodes are connected based on the redis cluster, the probability of the two data service nodes being unable to communicate is greatly reduced, the fault tolerance of the service in master-slave switching is improved, and the availability of the service is thereby improved.
[0062] See also Figure 2 ,The following will introduce another master-slave switching method in combination with ,specific application scenarios.
[0063] The real-time data service is an asymmetric service, deployed on nodes A and B respectively; the data collection service is a symmetric service, deployed on nodes C and D; the scheduling management service is a symmetric service, deployed on nodes A, B, C, and D; Redis is deployed on each node and built into a Redis cluster.
[0064] After data acquisition services C and D are started, they will connect to the PLC device and be able to obtain the connection status (1: normal, 0: abnormal); after real-time data services A and B are started, they will establish connections with data acquisition services C and D respectively and be able to obtain the connection status (1: normal, 0: abnormal).
[0065] Real-time data services A and B periodically publish connection status information to the Redis cluster. For example, real-time data service A publishes information "real-time data A: AC11, AD11", and real-time data service B publishes information "real-time data B: BC11, BD11".
[0066] The scheduling management subscribes to the main information of the real-time data service from Redis, such as "real-time data AB:AC11", and subscribes to the information published by the real-time data services A and B for calculation, and only retains the real-time data service and data acquisition service, and the data acquisition service and PLC device connection status are normal, such as "AC11, AD11, BC11, BD11", and determines whether the main information of the real-time data service is in the above list. If so, continue to publish the information, such as "real-time data AB:AC11"; if not, select the real-time data service with the smaller IP address from the list as the main one, and then publish the message to the Redis cluster.
[0067] Real-time data services A and B subscribe to the real-time service master information published by the scheduling management, such as "real-time data AB:AC11". At this time, real-time data services A and B both know that the real-time service master is A, and it subscribes to data from data collection service C. Real-time data service A runs internal scripts and logic, and real-time data service B retains the data subscribed from data collection service C to ensure data consistency between real-time data services A and B.
[0068] The master-slave switching method provided in the embodiment of the present application greatly reduces the probability that two data service nodes cannot communicate, improves the fault tolerance of the service in master-slave switching, and thus improves the availability of the service.
[0069] See also Figure 3 The embodiment of the present application also provides a master-slave switching device, which is applied to a redis cluster, including:
[0070] A receiving unit 301 is configured to receive first connection status information and second connection status information sent by a first data service node and a second data service node, respectively, wherein the first connection status information includes a connection status between the first data service node and a hardware device, and the second connection status information includes a connection status between the second data service node and the hardware device;
[0071] An acquisition unit 302 is used to acquire the master data service node at the current moment and the transmission route between the master data service node and the hardware device;
[0072] A judging unit 303 is configured to judge whether the connection status between the primary data service node and the hardware device is normal according to the first connection status information and the second connection status information;
[0073] A determining unit 304 is configured to determine a target master data service node and a target transmission line between the target master data service node and the hardware device according to the first connection status information and the second connection status information if the connection status between the master data service node and the hardware device is abnormal;
[0074] The switching unit 305 is configured to switch the master data service node at the current moment to the target master data service node, and switch the transmission line to the target transmission line.
[0075] Optionally, the first connection status information includes the connection status of the first data service node with the first data acquisition node and the second data acquisition node respectively, and also includes the connection status between the first data acquisition node and the hardware device, and the connection status between the second data acquisition node and the hardware device; the second connection status information includes the connection status of the second data service node with the first data acquisition node and the second data acquisition node respectively; and also includes the connection status between the first data acquisition node and the hardware device, and the connection status between the second data acquisition node and the hardware device.
[0076] Optionally, the judging unit 303 is specifically configured to:
[0077] Acquire the connection status between the master data service node and the master data collection node and the connection status between the master data collection node and the hardware device from the first status information and the second status information, wherein the master data collection node is a data collection node connected to the master data service node in the transmission line;
[0078] Determine whether the connection status between the master data service node and the master data acquisition node and the connection status between the master data acquisition node and the hardware device are both normal;
[0079] If the connection status between the master data service node and the master data collection node and the connection status between the master data collection node and the hardware device are both normal, then determining that the connection status between the master data service node and the hardware device is normal;
[0080] If at least one of the connection status between the master data service node and the master data collection node and the connection status between the master data collection node and the hardware device is abnormal, it is determined that the connection status between the master data service node and the hardware device is abnormal.
[0081] Optionally, the determining unit 304 is specifically configured to:
[0082] Determine a target master data service node and a target master data collection node from the first connection status information and the second connection status information, the connection status between the target master data service node and the target master data collection node is normal, and the connection status between the target master data collection node and the hardware device is normal;
[0083] A target transmission line is generated according to the target master data service node and the master data acquisition node.
[0084] Optionally, the device further comprises:
[0085] a recording unit, configured to record the connection status of the target transmission line;
[0086] A sending unit is used to send the connection status of the target transmission line to the first data service node and the second data service node respectively.
[0087] Optionally, the device further comprises:
[0088] The sending unit is configured to send the connection status between the primary data service node and the hardware device to the first data service node and the second data service node respectively if the connection status between the primary data service node and the hardware device is normal.
[0089] The embodiment of the present application also provides a computer device, including: a memory, a processor, and a bus system;
[0090] Wherein, the memory is used to store programs;
[0091] The processor is used to execute the program in the memory to implement any one of the master-slave switching methods described above;
[0092] The bus system is used to connect the memory and the processor so that the memory and the processor can communicate with each other.
[0093] The embodiment of the present application also provides a computer-readable storage medium storing instructions, which, when executed on a computer, enables the computer to execute any one of the master-slave switching methods described above.
[0094] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0095] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A master-slave switching method, characterized in that: Applied to redis cluster, including: Respectively receive first connection status information and second connection status information sent by a first data service node and a second data service node, the first connection status information includes the connection status between the first data service node and a hardware device, the second connection status information includes the connection status between the second data service node and the hardware device, the first connection status information includes the connection status between the first data service node and the first data acquisition node and the second data acquisition node, respectively, and also includes the connection status between the first data acquisition node and the hardware device and the connection status between the second data acquisition node and the hardware device; the second connection status information includes the connection status between the second data service node and the first data acquisition node and the second data acquisition node, respectively; and also includes the connection status between the first data acquisition node and the hardware device and the connection status between the second data acquisition node and the hardware device; Obtain the current master data service node and the transmission route between the master data service node and the hardware device; Determining whether the connection status between the primary data service node and the hardware device is normal according to the first connection status information and the second connection status information; If the connection status between the master data service node and the hardware device is abnormal, determining a target master data service node and a target transmission line between the target master data service node and the hardware device according to the first connection status information and the second connection status information; The master data service node at the current moment is switched to the target master data service node, and the transmission line is switched to the target transmission line.
2. The method according to claim 1, characterized in that The determining, according to the first connection status information and the second connection status information, whether the connection status between the primary data service node and the hardware device is normal includes: Acquire the connection status between the master data service node and the master data collection node and the connection status between the master data collection node and the hardware device from the first connection status information and the second connection status information, wherein the master data collection node is a data collection node connected to the master data service node in the transmission line; Determine whether the connection status between the master data service node and the master data acquisition node and the connection status between the master data acquisition node and the hardware device are both normal; If the connection status between the master data service node and the master data collection node and the connection status between the master data collection node and the hardware device are both normal, then determining that the connection status between the master data service node and the hardware device is normal; If at least one of the connection status between the master data service node and the master data collection node and the connection status between the master data collection node and the hardware device is abnormal, it is determined that the connection status between the master data service node and the hardware device is abnormal.
3. The method according to claim 1, characterized in that The determining, according to the first connection state information and the second connection state information, a target master data service node and a target transmission line between the target master data service node and the hardware device comprises: Determine a target master data service node and a target master data collection node from the first connection status information and the second connection status information, the connection status between the target master data service node and the target master data collection node is normal, and the connection status between the target master data collection node and the hardware device is normal; A target transmission line is generated according to the target master data service node and the master data acquisition node.
4. The method according to claim 1, characterized in that: After switching the master data service node at the current moment to the target master data service node and switching the transmission line to the target transmission line, the method further includes: The connection status of the target transmission line is recorded, and the connection status of the target transmission line is sent to the first data service node and the second data service node respectively.
5. The method according to claim 1, characterized in that If the connection status between the master data service node and the hardware device is normal, the connection status between the master data service node and the hardware device is sent to the first data service node and the second data service node respectively.
6. A master-slave switching device, characterized in that: Applied to redis cluster, including: A receiving unit, used to receive first connection status information and second connection status information sent by a first data service node and a second data service node, respectively, wherein the first connection status information includes the connection status between the first data service node and a hardware device, and the second connection status information includes the connection status between the second data service node and the hardware device, the first connection status information includes the connection status between the first data service node and the first data acquisition node and the second data acquisition node, respectively, and also includes the connection status between the first data acquisition node and the hardware device and the connection status between the second data acquisition node and the hardware device; the second connection status information includes the connection status between the second data service node and the first data acquisition node and the second data acquisition node, respectively; and also includes the connection status between the first data acquisition node and the hardware device and the connection status between the second data acquisition node and the hardware device; An acquisition unit, used to acquire the master data service node at the current moment and a transmission route between the master data service node and the hardware device; a judging unit, configured to judge whether the connection status between the primary data service node and the hardware device is normal according to the first connection status information and the second connection status information; a determining unit, configured to determine a target master data service node and a target transmission line between the target master data service node and the hardware device according to the first connection status information and the second connection status information if the connection status between the master data service node and the hardware device is abnormal; The switching unit is used to switch the master data service node at the current moment to the target master data service node, and switch the transmission line to the target transmission line.
7. A computer device, characterized in that: include: Memory, processor, and bus system; Wherein, the memory is used to store programs; The processor is used to execute the program in the memory to implement the method according to any one of claims 1 to 5; The bus system is used to connect the memory and the processor so that the memory and the processor can communicate with each other.
8. A computer-readable storage medium, characterized in that: The device stores instructions which, when executed on a computer, cause the computer to execute the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Control switch method of main machine and standby machine
CN103057572A
Redis node master-slave switching method and device
CN110659262A