Dual-machine active-standby adaptive switching method and device

CN123020334APending Publication Date: 2026-10-30CYG SUNRI CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611318461.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-27
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

[0004]本申请实施例提供了一种双机主备自适应切换方法和装置,旨在解决现有技术中心跳通信链路存在单点故障、切换决策维度单一导致切换不精准、以及切换过程不稳定易产生乒乓效应的现有问题

Benefits of technology

通过设置独立物理网络进行心跳通信,避免了因心跳链路单点故障导致的切换误判或双主冲突问题。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123020334A_ABST
    Figure CN123020334A_ABST
Patent Text Reader

Abstract

The application is suitable for the field of computer high availability technology, and provides a dual-machine master-slave adaptive switching method and device. The method comprises the following steps: determining a dynamic process weight based on a preset weight of a key process of a local machine; exchanging heartbeat frames with a peer machine through an independent physical network, wherein the frame body of the heartbeat frame carries the master-slave state and the dynamic process weight of the local machine; obtaining a heartbeat timeout detection result; driving a finite state machine to perform master-slave role arbitration and conversion according to the master-slave state of the local machine, the master-slave state of the peer machine, the dynamic process weight of the local machine, the dynamic process weight of the peer machine and the heartbeat timeout detection result, wherein the finite state machine comprises a master state, a standby state, a standby-to-master transition state, a master-to-standby transition state and an offline state; when the local machine enters the standby-to-master transition state or the master-to-standby transition state, if the state of the peer machine does not reach an expected conversion target within a waiting timeout time, the local machine is rolled back to a state before entering the transition state. Through the dual-network redundant heartbeat, the dynamic process weight and the finite state machine with timeout rollback, the reliability of the dual-machine master-slave switching is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of computer high availability technology, and in particular relates to a dual-machine primary / backup adaptive switching method and apparatus. Background Technology

[0002] In computing environments requiring high availability, dual-machine primary / standby systems are a key technology for ensuring business continuity. Existing technologies typically monitor each other's status by establishing a heartbeat mechanism between the primary and standby servers, allowing the standby server to take over services when the primary server fails.

[0003] However, existing technologies have the following drawbacks in implementing primary / standby failover. Most dual-machine systems rely on a single physical network link for heartbeat communication. When this heartbeat communication link fails due to network equipment malfunction or physical cable interruption, the standby server cannot receive heartbeat frames from the primary server, and the system determines that the primary server is offline. Existing systems primarily rely on whether the heartbeat frame times out, i.e., only assessing network layer connectivity. When the server's operating system and network protocol stack are running normally, but its critical business processes have terminated or become unresponsive, heartbeat frames can still be sent and received normally, and the system will not perform a failover. Furthermore, existing technologies lack a clear intermediate negotiation state during dual-machine state transitions. When the two servers experience inconsistent role states due to network interruption recovery or simultaneous startup, the system will exhibit repeated primary / standby role switching. Summary of the Invention

[0004] This application provides a dual-machine primary / backup adaptive handover method and apparatus, which aims to solve the existing problems of single point of failure in the center-pickup communication link, inaccurate handover due to a single handover decision dimension, and unstable handover process that is prone to ping-pong effect.

[0005] In a first aspect, embodiments of this application provide a dual-machine primary / standby adaptive switching method, applied to the local machine in a dual-machine system, the method comprising: Based on the preset weights of the key processes of the machine, the dynamic process weights of the machine are determined. The local heartbeat frame is sent to the peer machine through an independent physical network, and the primary / standby status and dynamic process weight of the local machine are carried in the frame body of the local heartbeat frame. The system receives the peer heartbeat frame sent by the peer through the independent physical network, and parses the primary / standby status and dynamic process weight of the peer from the frame body of the received peer heartbeat frame. Obtain heartbeat timeout detection results; Based on the primary / standby status of the local machine, the primary / standby status of the peer machine, the dynamic process weight of the local machine, the dynamic process weight of the peer machine, and the heartbeat timeout detection result, a finite state machine is driven to perform primary / standby role arbitration and transition; the finite state machine includes a primary state, a standby state, a transition state awaiting promotion to primary, a transition state awaiting demotion to secondary, and a disconnected state; When the local machine enters the transition state to become the master or the transition state to become the slave, if the state of the peer machine does not reach the expected transition target within the waiting timeout period of the current transition state, the local machine will revert to the state before entering the current transition state.

[0006] In one possible implementation of the first aspect, the frame body of the local heartbeat frame includes a primary / standby status field, a dynamic process weight field, a source IP address field, and a destination IP address field.

[0007] In one possible implementation of the first aspect, the number of independent physical networks is two; When the local machine is not the default host, the local machine sends request frames to the A network address and B network address of the peer machine at a fixed heartbeat interval. When the local machine is the default host, the local machine is in a receive waiting state. After receiving the request frame sent by the peer machine, the local machine replies with a response frame and returns the response frame to the peer machine along the same network that received the request frame.

[0008] In one possible implementation of the first aspect, determining the dynamic process weights of the local machine based on the preset weights of the key processes of the local machine includes: Detect whether the key processes of the machine are running; The preset weights of all the critical processes that are running are summed to obtain the dynamic process weights of the local machine.

[0009] In one possible implementation of the first aspect, when driving the finite state machine to perform master / slave role arbitration and transition, the transition conditions of the finite state machine include: When the local machine is in the standby state and the peer machine is in the primary state, if the dynamic process weight of the local machine is greater than the dynamic process weight of the peer machine, then it will enter the transition state to be promoted to primary. When the local machine is in the standby state and the peer machine is in the standby state, if the dynamic process weight of the local machine is greater than the dynamic process weight of the peer machine, or if the dynamic process weight of the local machine is equal to the dynamic process weight of the peer machine and the local machine is the default host, then it will enter the transition state of waiting to become the host. When the local machine is in the standby state and the peer machine is in the transition state to be demoted to slave, it transitions to the transition state to be promoted to master. When the local machine is in the master state and receives a manual switch to slave command, if the dynamic process weight of the local machine is less than or equal to the dynamic process weight of the peer machine, it will switch to the transition state of waiting to be demoted to slave. When the local machine is in the primary state and the peer machine is in the primary state, if the local machine is not the default host, it will switch to the transition state of waiting to be demoted to slave. When the local machine is in the master state and the peer machine is in the transition state to become master, if the dynamic process weight of the local machine is less than the dynamic process weight of the peer machine, then it will switch to the transition state to become slave.

[0010] In one possible implementation of the first aspect, in the transition state to be promoted to master: If, during the waiting timeout period of the pending master transition state, the peer machine transitions to the standby state or the pending slave transition state, then it transitions to the master state. If the peer device is still in the primary state or the pending primary transition state after the waiting timeout period of the pending primary transition state has elapsed, it will fall back to the standby state.

[0011] In one possible implementation of the first aspect, the state to be descended is in the transition state: When the peer machine is in the primary state or the transition state to become the primary, it switches to the standby state and sets the internal full event request flag. If the peer device is still in the standby state or the waiting transition state after the waiting timeout period of the waiting transition state has elapsed, it will fall back to the primary state.

[0012] In one possible implementation of the first aspect, the method further includes: When the state to be landed transitions from the transition state to the standby state, the internal full event request flag is set; In the standby state, it is periodically checked whether the peer machine is in the active state; After confirming that the peer machine is in the primary state, the upper-layer application is notified to request full event synchronization from the peer machine by setting the full event request flag in shared memory.

[0013] Secondly, embodiments of this application provide a dual-machine primary / standby adaptive switching method, applied to the local machine and the peer machine in a dual-machine system, the method comprising: Based on the preset weights of the key processes of the machine, the dynamic process weights of the machine are determined. Based on the preset weights of the critical processes of the peer machine, the dynamic process weights of the peer machine are determined. The local machine sends a local heartbeat frame to the peer machine through an independent physical network, and carries the local machine's primary / standby status and dynamic process weight in the frame body of the local machine's heartbeat frame; the peer machine sends a peer machine heartbeat frame to the local machine through the independent physical network, and carries the peer machine's primary / standby status and dynamic process weight in the frame body of the peer machine's heartbeat frame. The local machine receives the heartbeat frame sent by the peer machine through the independent physical network, and parses the primary / standby status and dynamic process weight of the peer machine from the frame body of the received heartbeat frame; the peer machine receives the local machine heartbeat frame sent by the local machine through the independent physical network, and parses the primary / standby status and dynamic process weight of the local machine from the frame body of the received local machine heartbeat frame. The local machine acquires the heartbeat timeout detection result, and the remote machine acquires the heartbeat timeout detection result; Based on the primary / standby status of the local machine, the primary / standby status of the peer machine, the dynamic process weight of the local machine, the dynamic process weight of the peer machine, and the heartbeat timeout detection result, the local machine drives a finite state machine to perform primary / standby role arbitration and transition; based on the primary / standby status of the peer machine, the primary / standby status of the local machine, the dynamic process weight of the peer machine, the dynamic process weight of the local machine, and the heartbeat timeout detection result, the peer machine drives a finite state machine to perform primary / standby role arbitration and transition; the finite state machine includes a primary state, a standby state, a transition state awaiting promotion to primary, a transition state awaiting demotion to secondary, and a disconnected state; When the local machine enters the transition state to become a master or the transition state to become a slave, if the state of the peer machine does not reach the expected transition target within the waiting timeout period of the current transition state, the local machine will revert to the state before entering the current transition state; when the peer machine enters the transition state to become a master or the transition state to become a slave, if the state of the local machine does not reach the expected transition target within the waiting timeout period of the current transition state, the peer machine will revert to the state before entering the current transition state.

[0014] Thirdly, embodiments of this application provide a dual-machine primary / standby adaptive switching device, applied to the local machine in a dual-machine system, the device comprising: The determination module is used to determine the dynamic process weights of the local machine based on the preset weights of the key processes of the local machine. The sending module is used to send a local heartbeat frame to the peer machine through an independent physical network, and to carry the primary / backup status of the local machine and the dynamic process weight of the local machine in the frame body of the local heartbeat frame. The parsing module is used to receive the peer heartbeat frame sent by the peer machine through the independent physical network, and to parse the primary / backup status of the peer machine and the dynamic process weight of the peer machine from the frame body of the received peer heartbeat frame. The acquisition module is used to obtain the heartbeat timeout detection results; The arbitration and switching module is used to drive a finite state machine to perform primary / standby role arbitration and switching based on the primary / standby status of the local machine, the primary / standby status of the peer machine, the dynamic process weight of the local machine, the dynamic process weight of the peer machine, and the heartbeat timeout detection result; the finite state machine includes a primary state, a standby state, a transition state to become primary, a transition state to become secondary, and a disconnected state; The rollback module is used to roll back to the state before entering the current transition state when the local machine enters the transition state to be promoted to master or the transition state to be demoted to slave. If the state of the peer machine does not reach the expected transition target within the waiting timeout period of the current transition state, the local machine will roll back to the state before entering the current transition state.

[0015] Fourthly, embodiments of this application provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the dual-machine primary / backup adaptive switching method described in any one of the first or second aspects above.

[0016] Fifthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the dual-machine primary / backup adaptive switching method described in any one of the first or second aspects above.

[0017] Sixthly, embodiments of this application provide a computer program product that, when run on a computer device, causes the computer device to execute the dual-machine primary / backup adaptive switching method described in any of the first or second aspects above.

[0018] According to the embodiments of this application, this application has the following beneficial effects: By setting up an independent physical network for heartbeat communication, the problems of misjudgment of handover or dual-master conflict caused by single point failure of the heartbeat link are avoided.

[0019] By carrying dynamic process weights in the heartbeat frame and using these dynamic process weights as the key basis for primary / backup arbitration, the switching decision can reflect the health status of the upper-layer business applications on the server.

[0020] By introducing a finite state machine containing a master transition state to be promoted and a slave transition state to be degraded, and combining it with a timeout rollback mechanism, a window for negotiation and confirmation is provided for the switching process, avoiding back-and-forth switching and system deadlock caused by state asynchrony or network latency.

[0021] By setting up a full event request synchronization mechanism after the switchover, the newly generated standby machine can supplement the event data during the switchover period from the new primary machine.

[0022] With built-in adaptive resolution logic for abnormal states such as dual master and dual slave, as well as automated processing flow for network disconnection and recovery, the system can automatically recover to a single master state under various abnormal scenarios.

[0023] It is understood that the beneficial effects of the second to sixth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description

[0024] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0025] Figure 1 This is a schematic flowchart of a dual-machine primary / standby adaptive switching method provided in an embodiment of this application; Figure 2 This is a schematic diagram of the logical architecture of a dual-machine primary / backup adaptive switching system provided in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of the computer device provided in the embodiments of this application. Detailed Implementation

[0026] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.

[0027] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.

[0028] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0029] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."

[0030] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0031] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0032] Figure 1 A schematic flowchart illustrating a dual-machine primary / standby adaptive switching method according to an embodiment of this application is shown. This method can be applied to the local machine in a dual-machine system. The local machine and the peer machine are connected through at least two independent physical networks.

[0033] S101, Based on the preset weights of the key processes of the local machine, determine the dynamic process weights of the local machine.

[0034] Among them, critical processes refer to pre-configured application processes that characterize the core business functions of the machine, and their running status directly reflects the health of the machine's business.

[0035] Preset weights are numerical values ​​pre-assigned to each key process to indicate the importance of that process in the overall business.

[0036] Dynamic process weight refers to a comprehensive score that quantifies the local machine's service carrying capacity, calculated in real time based on the actual running status of the local critical processes. It is obtained by accumulating the preset weight values ​​of all processes that are preset as critical processes and are currently running. It is one of the core bases for primary / backup switchover arbitration.

[0037] In this embodiment of the application, by extending the basis for switching decisions from network connectivity to the running status of critical processes, the dynamic process weight can decrease and trigger a switch when the critical process is abnormal while the network is normal.

[0038] In one optional embodiment, S101 specifically includes: Step a1: Detect whether the key processes of the local machine are running.

[0039] The detection of whether a process is running can be achieved by calling the operating system's process query interface. In Linux systems, the process can be queried by combining the ps command with the full name of the process. In Windows systems, the process list can be traversed by using the Toolhelp32 snapshot application programming interface API. During the detection, the process of the tester itself should be excluded.

[0040] In this embodiment of the application, the running status changes of key processes can be obtained by periodically calling the operating system process query interface.

[0041] Step a2: The preset weights of all the key processes that are running are summed to obtain the dynamic process weight of the local machine.

[0042] The mathematical expression for the dynamic process weight is:

[0043] in, This is the sum of the weights of the currently critical processes on this machine; Total number of critical processes; For the first The preset weights of each key process are positive integers; For the first The indicator function for a critical process takes a value of 1 when the process is running, and a value of 0 otherwise.

[0044] In this embodiment of the application, by assigning different preset weights to different key processes, the dynamic process weights can reflect the integrity of the key processes and their respective importance.

[0045] S102, a local heartbeat frame is sent to the peer machine through an independent physical network, and the primary / standby status of the local machine and the dynamic process weight of the local machine are carried in the frame body of the local heartbeat frame.

[0046] Independent physical networks refer to network channels that are physically isolated from each other and do not have the risk of single point of failure.

[0047] Heartbeat frames are fixed-format data packets used to periodically exchange status information between two machines.

[0048] The primary / standby status is used to identify the current role of the machine, including primary status, standby status, transitional status awaiting promotion to primary, transitional status awaiting demotion to slave, and offline status.

[0049] In this embodiment of the application, by carrying dynamic process weights in the heartbeat frame, the peer machine can obtain the business health information of the local machine as a basis for arbitration.

[0050] In one optional embodiment, the frame body of the local heartbeat frame includes a primary / standby status field, a dynamic process weight field, a source IP address field, and a destination IP address field.

[0051] Among them, the primary / backup status field is used to synchronize role information, the dynamic process weight field is used to synchronize dynamic process weight, and the source IP address field and destination IP address field are used for network routing and authentication. The complete frame format of the heartbeat frame is: frame header (0xA5 0x5A, 2 bytes) + frame type (1 byte, 1=request, 2=response) + frame body length (1 byte) + frame body (tagScadaHeartFrame structure). The frame body contains: number of valid destination IPs (byValidDestIPCount), destination IP array (dwDestIP[2]), source IP (dwSourceIP), primary / backup status (byScadaState), frame count (wFrameCount), and process weight (wProcessWeight). The frame bodies of both the request frame and the response frame carry the sender's current primary / backup status and dynamic process weight. When the receiver receives any type of frame (request frame or response frame), it parses and caches the peer status (byScadaState) and peer process weight (wProcessWeight) as the basis for arbitration.

[0052] In one optional embodiment, the number of independent physical networks is two, namely network A and network B. Network A and network B are two independent networks that are physically isolated from each other. Each machine is configured with an independent IP address on network A and network B, and network A and network B share the same heartbeat port (which can be 13010 by default).

[0053] Dual-network heartbeat communication employs a request-response mode, which ensures that only one side actively sends a heartbeat at any given time, and that the arrival of a heartbeat frame from either network refreshes the online status of the other end. Specifically, this includes: Step b1: When the local machine is not the default host, the local machine sends request frames to the A network address and B network address of the peer machine at a fixed heartbeat interval.

[0054] The default host is a pre-configured server used as the basis for priority promotion in scenarios involving dual slaves or equal weight conflicts. The fixed heartbeat sending interval T_heart refers to the pre-set time period for periodically sending heartbeat request frames, with a default of 1 second.

[0055] Step b2: When the local machine is the default host, the local machine is in a receive waiting state. After receiving the request frame sent by the peer machine, the local machine replies with a response frame and returns the response frame to the peer machine along the same network that received the request frame.

[0056] The "receive and wait" state means that the default host does not actively send request frames, but instead listens continuously on the specified port (default 13010) and waits for request frames sent by non-default hosts.

[0057] In this embodiment, heartbeats are transmitted simultaneously through two independent networks, ensuring that the heartbeats are not interrupted when a single network fails; and a request-response mode is used to prevent both machines from actively sending heartbeats at the same time.

[0058] S103, receive the peer heartbeat frame sent by the peer through the independent physical network, and parse the primary / backup status of the peer and the dynamic process weight of the peer from the frame body of the received peer heartbeat frame.

[0059] Parsing refers to extracting the values ​​of each field from the received binary data packet according to a predefined frame format.

[0060] In one optional embodiment, during reception processing, source IP validity verification (must be the address of the peer's A or B network to identify which network the frame comes from), frame header verification (0xA5 0x5A), and frame body length verification are performed sequentially. Frames are discarded if verification fails. Non-blocking sockets are used in conjunction with a select timeout (10 milliseconds) for reception, and a maximum of 10 frames are processed continuously per round. This module maintains the timestamp of the last received heartbeat (m_lastRecvTime) for the master / slave switchover engine to determine whether the peer has disconnected from the network. When the resolved peer weight is an invalid flag value of 0xFFFF, it is compared with a weight of 0.

[0061] In this embodiment of the application, a dual-network redundant reception and frame verification mechanism is used to ensure that a single network failure does not affect the determination of the online status of the other end.

[0062] S104, obtain the heartbeat timeout detection result.

[0063] The heartbeat timeout detection result refers to a Boolean judgment result obtained by determining whether the difference between the last received heartbeat frame from the peer and the current time exceeds a preset no-response timeout threshold. The peer disconnection judgment conditions are as follows:

[0064] in, The current system time; The last time the heartbeat frame from the other end was received (refreshed when a valid frame is received on either network A or network B); This is the timeout threshold for no response, with a default value of 5 seconds.

[0065] In this embodiment of the application, by using the absence of frames arriving from both networks as the timeout determination condition, a momentary failure of a single network will not trigger a timeout.

[0066] S105, based on the primary / standby status of the local machine, the primary / standby status of the peer machine, the dynamic process weight of the local machine, the dynamic process weight of the peer machine, and the heartbeat timeout detection result, drive the finite state machine to perform primary / standby role arbitration and transition; the finite state machine includes primary state, standby state, transition state to become primary, transition state to become slave, and offline state.

[0067] In this context, a finite state machine (FSM) is a mathematical computational model used to drive the primary and backup roles of a dual-machine system based on preset transition conditions. The primary state (MASTER, enumeration value 1) refers to the server's role as the primary provider of business services and external functions. The backup state (SLAVE, enumeration value 0) refers to the server's role as a backup, not providing business services, and synchronizing data with the primary node. The readytomaster transition state (READYTOMASTER, enumeration value 2) is an intermediate transition state when the server transitions from backup to primary, indicating that the local machine has initiated a master promotion request and is waiting for the other end to cooperate. The readytoslave transition state (READYTOSLAVE, enumeration value 3) is an intermediate transition state when the server transitions from primary to backup, indicating that the local machine has initiated a slave demotion request and is waiting for the other end to take over. The offline state (OFFNET, enumeration value 4) is an isolated state entered by the server due to its own network interface malfunction or physical connection loss, and it does not participate in arbitration. The UNKNOWN state (-1) is defined separately and is only used in scenarios where the primary and backup processes have not started or the state acquisition has failed during external queries. It does not participate in state machine transitions. Timeout rollback is a fault-tolerance mechanism. When the local machine enters an intermediate transition state, if the state of the peer machine fails to reach the expected cooperative state within a preset timeout period, the local machine automatically returns from the current transition state to the state before entering that transition state.

[0068] In one optional embodiment, fault tolerance is performed every 20 seconds: if the local machine is in primary state or in single-machine (non-dual SCADA) mode, the primary state is forcibly rewritten to shared memory.

[0069] In an optional embodiment, when driving the finite state machine to perform primary / backup role arbitration and transition, the transition conditions of the finite state machine include: Step c1: When the local machine is in the standby state and the peer machine is in the primary state, if the dynamic process weight of the local machine is greater than the dynamic process weight of the peer machine, then the process transitions to the transition state awaiting primary status.

[0070] Step c2: When the local machine is in the standby state and the peer machine is in the standby state, if the dynamic process weight of the local machine is greater than the dynamic process weight of the peer machine, or the dynamic process weight of the local machine is equal to the dynamic process weight of the peer machine and the local machine is the default host, then the process transitions to the host transition state.

[0071] Step c3: When the local machine is in the standby state and the peer machine is in the transition state to be demoted, it transitions to the transition state to be promoted.

[0072] Step c4: When the local machine is in the master state and receives a manual switch to slave command, if the dynamic process weight of the local machine is less than or equal to the dynamic process weight of the peer machine, then it enters the transition state to be demoted to slave.

[0073] If the local machine has a higher weight, the demotion command will be rejected and the manual switching flag will be cleared.

[0074] Step c5: When the local machine is in the master state and the peer machine is in the master state, if the local machine is not the default master, then it will switch to the transition state of waiting to be demoted to slave.

[0075] The default host remains in primary mode.

[0076] Step c6: When the local machine is in the master state and the peer machine is in the transition state to become master, if the dynamic process weight of the local machine is less than the dynamic process weight of the peer machine, then the machine will switch to the transition state to become slave.

[0077] In the embodiments of this application, by combining the above-mentioned transition conditions, the finite state machine can automatically converge to a single master state in scenarios such as dual master, dual slave, and weight changes.

[0078] S106, when the local machine enters the transition state to be promoted to master or the transition state to be demoted to slave, if the state of the peer machine does not reach the expected transition target within the waiting timeout period of the current transition state, the local machine will revert to the state before entering the current transition state.

[0079] The waiting timeout period (T_waitSwitch) is the maximum threshold time set for the transition state to wait for the peer to respond cooperatively; the default is 10 seconds. The expected transition target refers to the cooperative state that the peer is expected to achieve in the current transition state—in the transition state awaiting promotion to master, the peer is expected to transition to a standby state or a transition state awaiting demotion to slave; in the transition state awaiting demotion to slave, the peer is expected to transition to a master state or a transition state awaiting promotion to master. Rollback refers to restoring the local machine's state to its original state before entering the transition state when negotiation fails. The conditions for determining transition state timeout rollback are as follows: Conditions for timeout rollback during master transition: Furthermore, the counterpart state ∈ {master state, transition state to be promoted to master}.

[0080] Conditions for timeout fallback from transition state: Furthermore, the opposite state ∈ {standby state, to be degraded from the transition state}.

[0081] in, This is the moment when the system enters the transition state.

[0082] In this embodiment, a timeout rollback mechanism is set in the transition state so that both machines can roll back when state negotiation fails.

[0083] In one optional embodiment, in the transition state to be promoted to master: Step d1: If, during the waiting timeout period of the pending master transition state, the peer machine transitions to the standby state or the pending slave transition state, then it transitions to the master state.

[0084] Step d2: If the peer machine is still in the primary state or the transition state to primary state after the waiting timeout period of the transition state to primary state has expired, then it will fall back to the standby state.

[0085] In one optional embodiment, in the transition state to be degraded: Step e1: When the peer machine is in the primary state or the transition state to primary, it switches to the standby state and sets the internal full event request flag.

[0086] The internal full event request flag (m_bIfRequestWholeEvent) is a boolean variable stored in local memory, used to mark that the local machine has been switched from primary to standby and needs to request the new primary machine to replenish the data events backlogged during the switchover.

[0087] Step e2: If the waiting timeout period of the waiting transition state exceeds the specified time, and the peer device is still in the standby state or the waiting transition state, then it will revert to the primary state.

[0088] In an optional embodiment, the method further includes: Step f1: When the state to be landed transitions from the transition state to the standby state, the internal full event request flag is set.

[0089] Step f2: In the standby state, periodically check whether the peer machine is in the active state.

[0090] Step f3: After confirming that the peer machine is in the primary state, the upper layer application is notified to request full event synchronization from the peer machine by setting the full event request flag in shared memory.

[0091] In a dual-machine system, shared memory is a data exchange area used for inter-process communication, allowing different processes to access the same memory space (ShmMachineState structure, shared memory file MachineState.db). The ShmMachineState structure contains: local state (iLocalState), peer state (iAnotherState), manual switch flag (bSwitchSlave), full event request flag (bQuestWholeEvent), last switch time (nLastSwitchTime, milliseconds), and last full event request time (nLastQuestWholeEventTime, milliseconds). The last switch time is automatically updated when the state is written to shared memory. Full event synchronization refers to copying all data acquisition events generated on the new primary machine during the switchover period to the new standby machine.

[0092] Upper-layer applications refer to business applications running on the local operating system. In this application embodiment, they are specifically data acquisition and monitoring (SCADA) applications used to perform data synchronization operations related to primary / standby switching.

[0093] In this embodiment, a two-step mechanism is used to first set the internal full event request flag and then set the full event request flag in the shared memory after the peer has stabilized as the primary user, so that full event synchronization requests are only issued after the role has stabilized.

[0094] In an optional embodiment, the method further includes: Step g1: If the local machine determines that it has not received the peer machine's heartbeat frame from the independent physical network for more than the no-response timeout threshold, and the local machine is not currently in the primary state, then it determines that the peer machine is disconnected from the network and enters the primary state.

[0095] Step g2: Check if the A network address and B network address configured on the local machine exist in the network card address list of the local machine. If neither the A network address nor the B network address exists in the network card address list, then determine that the local machine is offline and enter the offline state.

[0096] The network card address list refers to the set of IP addresses of all active network interfaces on the local machine maintained by the operating system, which is obtained by enumerating the IP addresses bound to the local network card driver.

[0097] Step g3: After the local network is restored, wait for a time length corresponding to the no-response timeout threshold to receive the peer's heartbeat frame and obtain the peer's status. Then, switch to the standby state, set the full event request flag through shared memory, and then perform primary / standby role arbitration and conversion according to the primary / standby status of the local machine, the primary / standby status of the peer, the dynamic process weight of the local machine, and the dynamic process weight of the peer.

[0098] In this embodiment, the system maintains a single-master state when the network is abnormal by a three-level process: when the peer is offline, the local machine becomes the master; when the local machine is offline, it enters an offline state; and the network is restored, the system re-enters with a delay.

[0099] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0100] Figure 2 This is a schematic diagram of the logical architecture of a dual-machine master-slave adaptive switching system provided in an embodiment of this application.

[0101] The dual-machine system consists of two servers (the local machine and the peer machine), connected by two independent physical networks, network A and network B. Each server internally deploys a dual-network heartbeat communication module, a process weight management module, a primary / standby switchover engine, and a primary / standby status management module. The dual-network heartbeat communication module is responsible for simultaneously sending and receiving User Datagram Protocol (UDP) heartbeat frames on both networks A and B, using the default port 13010. The process weight management module is responsible for monitoring the running status of critical processes on the local machine. Every second, it calls the operating system's process query interface, traversing a list of critical processes predefined in an Extensible Markup Language (XML) configuration file. The primary / standby switchover engine is the core decision-making mechanism of the entire system. It runs periodically every 500 milliseconds, driving a five-state finite state machine to arbitrate and switch the primary / standby roles based on the dynamic process weight comparison results between the local and peer machines, the current real-time status of the peer machine, network connectivity, and manual switchover commands. The master / slave status management module provides a unified interface, responsible for writing the final state after the master / slave switchover engine decision to the local shared memory and simultaneously writing it to the external remote dictionary service Redis cache. The shared memory, serving as a data exchange area for inter-process communication within a single machine, stores the local state, peer state, manual switchover flag, full event request flag, and last switchover time. Remote dictionary service Redis writes are triggered in two ways: first, an immediate write when the local state enters a stable master or standby state; second, a periodic refresh and write every 2 seconds by the master / slave switchover engine's main loop. The remote dictionary service Redis key format is sys / machinestate / hostname, with a hash field MachineState and a field value of a state name string (e.g., MASTER, SLAVE). The key time-to-live (TTL) is 5 seconds and is refreshed with each write, allowing external systems to query the master / slave status of any node by hostname. The dual-network communication management module is responsible for loading network configuration and determining primary and backup role configurations. It prioritizes reading the dual-network addresses of the local machine and the peer machine from the primary and backup configuration table (jkcfghostnode, which includes the MAINHOSTNAME, SLAVEHOSTNAME fields and their respective A network and B network IP fields) in the configuration database. If no configuration is provided, it reverts to the plant mode and derives the primary and backup relationship and dual-network addresses from the node information table (rtnodeinfo) and the system information table (defaultmainserver, servermode, and netmode fields of sysinfotable).

[0102] The master / standby switchover engine internally maintains a five-state finite state machine, including the following five states: master state, standby state, master-to-master transition state, slave-to-slave transition state, and offline state. The transition conditions between each state include: the dynamic process weight comparison result between the local and peer ends, the current state of the peer end, whether a manual switchover command has been received, network connectivity, and a timeout timer. The initial state allocation at system startup follows the default master priority principle: the default master directly enters the master-to-master transition state after system startup, while non-default masters directly enter the slave-to-slave transition state. Subsequently, the system converges to either the master state or the standby state through an arbitration process. During the startup delay period (T_delay=5 seconds), no switchover logic is executed; only heartbeats are received to obtain the peer's state. If the default master discovers that the peer is already in the master state during the delay period, it proactively transitions to the slave-to-slave transition state. After the startup delay ends, the switchover logic loop officially begins, with a decision cycle (T_loop) of 500 milliseconds. Every 2 seconds, the current primary / standby status of the local machine is written to the remote Redis dictionary service (key sys / machinestate / hostname, field MachineState, time-to-live 5 seconds, refreshed on write). An additional immediate write occurs when the status enters a stable primary or standby state. When the local machine is offline, after network recovery, it waits for a no-response timeout period to reacquire the peer's status, then switches to standby state and sets the request for all events flag. Finally, the final primary / standby role is determined according to the dynamic process weight comparison logic.

[0103] In one optional embodiment, the process of a primary / backup switchover is illustrated by taking the crash of a critical process of the local machine (default host) in a dual-machine system as an example.

[0104] The system logical architecture of this embodiment consists of two servers (the local machine and the peer machine), which are connected through two independent physical networks, network A and network B. Network A can be configured as a 192.168.1.x network segment, and network B can be configured as a 192.168.2.x network segment. Each server is configured with an independent IP address on both network A and network B: Network A IP: Master 192.168.1.1, Peer 192.168.1.2; Network B IP: Master 192.168.2.1, Peer 192.168.2.2. One server (the local machine) is configured as the default master (defaultMain=true), and the other is configured as the default slave (defaultMain=false).

[0105] In a Supervisory Control And Data Acquisition (SCADA) application scenario, the list of key processes defined in the Extensible Markup Language (XML) configuration file and the preset weights of each key process are as follows: cygrdbservice (weight 40, real-time database service), cygykopsrv (weight 20, remote operation service), cygiedopsrv (weight 20, IED communication service), and cygcommonopsrv (weight 20, general operation service). Configuration items must simultaneously satisfy `deployed="true"`, have a non-empty `name` attribute, and have a positive integer `priority` to be included in the key process list. The process weight management module checks the running status of the above key processes every 1 second. When all key processes are running normally, the maximum weight of the local machine is 100 (40+20+20+20=100), and the total weight ranges from 0 to 100. In the plant deployment mode, the key process list is nb_manager, rtdb, and scada, with each key process having a preset weight of 100 and a total weight range of 0 to 300.

[0106] Initially, the local machine is in the master state (MASTER), and the peer machine is in the standby state (SLAVE). All critical processes on both sides are running, and the dynamic process weights are both 100. When the cygrdbservice process (weight 40) on the local machine abnormally exits, its process weight management module detects this change and recalculates the dynamic process weights, determining that the local machine's dynamic process weight has decreased to 60. The local machine sends a heartbeat frame to the peer machine via network A and network B, carrying its new dynamic process weight value of 60 and master state. After receiving the heartbeat frame, the peer machine parses out the local machine's state as master state and its dynamic process weight as 60. Its master / standby switchover engine arbitrates and finds that it is in the standby state, the peer machine is in the master state, and its own dynamic process weight (100) is greater than the peer machine's dynamic process weight (60). After the transition conditions from the standby state to the master transition state are met, the peer machine drives its finite state machine to transition from the standby state to the master transition state (READYTOMASTER).

[0107] The peer machine sends a heartbeat frame containing the state of the transitional phase before becoming the master to the local machine. Upon receiving this heartbeat frame, the local machine's master / standby switchover engine arbitrates. The local machine is in the master state, the peer machine is in the transitional phase before becoming the master, and the local machine's dynamic process weight (60) is less than the peer machine's dynamic process weight (100), satisfying the transition condition from the master state to the transitional phase before becoming the slave. The local machine then drives its finite state machine to transition from the master state to the transitional phase before becoming the slave (READYTOSLAVE). After receiving the local machine's transitional phase state, the peer machine's finite state machine transitions from the transitional phase before becoming the master to the master state (MASTER). After receiving the peer machine's master state, the local machine's finite state machine transitions from the transitional phase before becoming the slave to the standby state (SLAVE). After transitioning from the transitional phase before becoming the slave to the standby state, the local machine sets the internal full event request flag (m_bIfRequestWholeEvent = true). When the local machine is in standby mode, its master-slave failover engine, upon detecting that the peer machine is in master mode, notifies the SCADA application on the local machine to request full event synchronization from the peer machine by setting the full event request flag (bQuestWholeEvent) in shared memory. The above failover process is completed under the constraints of the no-answer timeout threshold (T_noanswer=5 seconds) and the transition state wait timeout (T_waitSwitch=10 seconds).

[0108] In an optional implementation, a configurable static priority value is used instead of the default host's static rules as the final arbitration basis. A static priority configuration item is added to the configuration file for each server, and the system structure and other configurations are the same as in the aforementioned embodiments. For example, the local machine's priority is configured as 100, and the peer machine's priority is configured as 200. The arbitration logic of the master-slave switching engine is modified accordingly: when handling dual-master or dual-slave conflicts where both parties have equal dynamic process weights, the static priorities of both parties are compared, and the one with the higher priority gains the right to be promoted to master first. For example, when the system is in a dual-slave state and both parties have equal dynamic process weights, the peer machine, due to its higher static priority, is the first to switch to the transitional state awaiting master promotion and initiates the promotion, while the local machine remains in standby mode. The system automatically converges to a stable state where the peer machine is the master and the local machine is the standby.

[0109] In an optional embodiment, the state machine model within the master / standby switchover engine can omit the transition states to be promoted to master and to be demoted to slave, containing only three states: master, standby, and offline. The timeout rollback logic is removed accordingly. In this simplified model, when the standby machine detects through heartbeat that its dynamic process weight is greater than that of the master machine, it directly switches to the master state. When the master machine detects in the next decision cycle that its dynamic process weight is lower and the peer is already in the master state, it directly switches to the standby state. When the dynamic process weight fluctuates near a critical value or network latency causes state information asynchrony, the two machines may alternately become the master, resulting in back-and-forth switching of master / standby roles.

[0110] In one alternative implementation, the dynamic process weight is calculated by combining the real-time resource consumption of critical processes, and is not limited to a binary sum of whether the critical processes are alive or not. The functionality of the process weight management module is enhanced; in addition to checking the existence of critical processes, it also periodically obtains the CPU and memory usage of these critical processes. The dynamic process weight calculation formula can be modified as follows:

[0111] in, This represents the current dynamic process weight of this machine; Total number of critical processes; For the first The preset weights of each key process are positive integers; For the first The indicator function for a critical process takes a value of 1 when the process is running, and a value of 0 otherwise. For the first Normalized CPU utilization of key processes, with values ​​ranging from 0 to 1; For the first Normalized memory usage of key processes, with values ​​ranging from 0 to 1; This is the CPU utilization attenuation coefficient, with a value ranging from 0 to 1; This is a decay coefficient for memory usage, ranging from 0 to 1. When a critical process on the local machine does not crash but its dynamic process weight drops below that of the peer machine due to excessive resource consumption, the system will also trigger a primary / standby switchover.

[0112] Corresponding to the dual-machine primary / standby adaptive switching method described in the above embodiments, this application also provides a dual-machine primary / standby adaptive switching device, applied to the local machine in a dual-machine system, the device comprising: The determination module is used to determine the dynamic process weights of the local machine based on the preset weights of the key processes of the local machine. The sending module is used to send a local heartbeat frame to the peer machine through an independent physical network, and to carry the primary / backup status of the local machine and the dynamic process weight of the local machine in the frame body of the local heartbeat frame. The parsing module is used to receive the peer heartbeat frame sent by the peer machine through the independent physical network, and to parse the primary / backup status of the peer machine and the dynamic process weight of the peer machine from the frame body of the received peer heartbeat frame. The acquisition module is used to obtain the heartbeat timeout detection results; The arbitration and switching module is used to drive a finite state machine to perform primary / standby role arbitration and switching based on the primary / standby status of the local machine, the primary / standby status of the peer machine, the dynamic process weight of the local machine, the dynamic process weight of the peer machine, and the heartbeat timeout detection result; the finite state machine includes a primary state, a standby state, a transition state to become primary, a transition state to become secondary, and a disconnected state; The rollback module is used to roll back to the state before entering the current transition state when the local machine enters the transition state to be promoted to master or the transition state to be demoted to slave. If the state of the peer machine does not reach the expected transition target within the waiting timeout period of the current transition state, the local machine will roll back to the state before entering the current transition state.

[0113] It should be noted that the information interaction and execution process between the above modules or components are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, which will not be repeated here.

[0114] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the system can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0115] This application also provides a computer device, which includes: at least one processor, a memory, and a computer program stored in the memory and executable on the at least one processor. When the processor executes the computer program, it implements the steps in any of the above method embodiments.

[0116] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in the above-described method embodiments.

[0117] This application provides a computer program product that, when run on a computer device, enables the computer device to execute the steps described in the various method embodiments above.

[0118] Figure 3 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Figure 3 As shown, the computer device of this embodiment includes: at least one processor 30 ( Figure 3 (Only one is shown in the diagram), memory 31, and computer program 32 stored in the memory 31 and executable on the at least one processor 30, wherein the processor 30 executes the computer program 32 to implement the steps in any of the above embodiments of the dual-machine primary / standby adaptive switching method.

[0119] The computer device may include, but is not limited to, a processor 30 and a memory 31. Those skilled in the art will understand that... Figure 3 The examples of computer devices are merely examples and do not constitute a limitation on computer devices. They may include more or fewer components than shown in the illustration, or combinations of certain components, or different components. For example, they may also include input / output devices, network access devices, etc.

[0120] The processor 30 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.

[0121] In some embodiments, the memory 31 may be an internal storage unit of the computer device, such as a hard drive or memory. In other embodiments, the memory 31 may be an external storage device of the computer device, such as a plug-in hard drive, smart media card (SMC), secure digital (SD) card, flash card, etc. Furthermore, the memory 31 may include both internal and external storage units of the computer device. The memory 31 is used to store the operating system, applications, bootloader, data, and other programs, such as the program code of the computer program. The memory 31 can also be used to temporarily store data that has been output or will be output.

[0122] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or system capable of carrying computer program code to a system / computer device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium, such as a USB flash drive, a portable hard drive, a magnetic disk, or an optical disk.

[0123] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0124] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0125] In the embodiments provided in this application, it should be understood that the disclosed systems / computer devices and methods can be implemented in other ways. For example, the system / computer device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0126] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0127] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A dual-machine primary / standby adaptive switching method, applied to the local machine in a dual-machine system, characterized in that, The method includes: Based on the preset weights of the key processes of the machine, the dynamic process weights of the machine are determined. The local heartbeat frame is sent to the peer machine through an independent physical network, and the primary / standby status and dynamic process weight of the local machine are carried in the frame body of the local heartbeat frame. The system receives the peer heartbeat frame sent by the peer through the independent physical network, and parses the primary / standby status and dynamic process weight of the peer from the frame body of the received peer heartbeat frame. Obtain the heartbeat timeout detection result; Based on the primary / standby status of the local machine, the primary / standby status of the peer machine, the dynamic process weight of the local machine, the dynamic process weight of the peer machine, and the heartbeat timeout detection result, a finite state machine is driven to perform primary / standby role arbitration and transition; the finite state machine includes a primary state, a standby state, a transition state awaiting promotion to primary, a transition state awaiting demotion to secondary, and a disconnected state; When the local machine enters the transition state to become the master or the transition state to become the slave, if the state of the peer machine does not reach the expected transition target within the waiting timeout period of the current transition state, the local machine will revert to the state before entering the current transition state.

2. The method according to claim 1, characterized in that, The frame body of the local heartbeat frame includes a primary / standby status field, a dynamic process weight field, a source IP address field, and a destination IP address field.

3. The method according to claim 1, characterized in that, The number of independent physical networks is two; When the local machine is not the default host, the local machine sends request frames to the A network address and B network address of the peer machine at a fixed heartbeat interval. When the local machine is the default host, the local machine is in a receive waiting state. After receiving the request frame sent by the peer machine, the local machine replies with a response frame and returns the response frame to the peer machine along the same network that received the request frame.

4. The method according to claim 1, characterized in that, The determination of dynamic process weights of the local machine based on the preset weights of the key processes of the local machine includes: Detect whether the key processes of the machine are running; The preset weights of all the critical processes that are running are summed to obtain the dynamic process weights of the local machine.

5. The method according to claim 1, characterized in that, When the finite state machine is driven to perform primary / backup role arbitration and transition, the transition conditions of the finite state machine include: When the local machine is in the standby state and the peer machine is in the primary state, if the dynamic process weight of the local machine is greater than the dynamic process weight of the peer machine, then it will enter the transition state to be promoted to primary. When the local machine is in the standby state and the peer machine is in the standby state, if the dynamic process weight of the local machine is greater than the dynamic process weight of the peer machine, or if the dynamic process weight of the local machine is equal to the dynamic process weight of the peer machine and the local machine is the default host, then it will enter the transition state of waiting to become the host. When the local machine is in the standby state and the peer machine is in the transition state to be demoted to slave, it transitions to the transition state to be promoted to master. When the local machine is in the master state and receives a manual switch to slave command, if the dynamic process weight of the local machine is less than or equal to the dynamic process weight of the peer machine, it will switch to the transition state of waiting to be demoted to slave. When the local machine is in the primary state and the peer machine is in the primary state, if the local machine is not the default host, it will switch to the transition state of waiting to be demoted to slave. When the local machine is in the master state and the peer machine is in the transition state to become master, if the dynamic process weight of the local machine is less than the dynamic process weight of the peer machine, then it will switch to the transition state to become slave.

6. The method according to claim 5, characterized in that, In the aforementioned primary transition state to be promoted: If, during the waiting timeout period of the pending master transition state, the peer machine transitions to the standby state or the pending slave transition state, then it transitions to the master state. If the peer device is still in the primary state or the pending primary transition state after the waiting timeout period of the pending primary transition state has elapsed, it will fall back to the standby state.

7. The method according to claim 5, characterized in that, In the transition state to be descended: When the peer machine is in the primary state or the transition state to become the primary, it switches to the standby state and sets the internal full event request flag. If the peer device is still in the standby state or the waiting transition state after the waiting timeout period of the waiting transition state has elapsed, it will fall back to the primary state.

8. The method according to claim 7, characterized in that, The method further includes: When the state to be landed transitions from the transition state to the standby state, the internal full event request flag is set; In the standby state, it is periodically checked whether the peer machine is in the active state; After confirming that the peer machine is in the primary state, the upper-layer application is notified to request full event synchronization from the peer machine by setting the full event request flag in shared memory.

9. A dual-machine primary / backup adaptive switching method, applied to the local and peer machines in a dual-machine system, characterized in that, The method includes: Based on the preset weights of the key processes of the machine, the dynamic process weights of the machine are determined. Based on the preset weights of the critical processes of the peer machine, the dynamic process weights of the peer machine are determined. The local machine sends a local heartbeat frame to the peer machine through an independent physical network, and carries the local machine's primary / standby status and dynamic process weight in the frame body of the local machine's heartbeat frame; the peer machine sends a peer machine heartbeat frame to the local machine through the independent physical network, and carries the peer machine's primary / standby status and dynamic process weight in the frame body of the peer machine's heartbeat frame. The local machine receives the heartbeat frame sent by the peer machine through the independent physical network, and parses the primary / standby status and dynamic process weight of the peer machine from the frame body of the received heartbeat frame; the peer machine receives the local machine heartbeat frame sent by the local machine through the independent physical network, and parses the primary / standby status and dynamic process weight of the local machine from the frame body of the received local machine heartbeat frame. The local machine acquires the heartbeat timeout detection result, and the remote machine acquires the heartbeat timeout detection result; Based on the primary / standby status of the local machine, the primary / standby status of the peer machine, the dynamic process weight of the local machine, the dynamic process weight of the peer machine, and the heartbeat timeout detection result, the local machine drives a finite state machine to perform primary / standby role arbitration and transition; based on the primary / standby status of the peer machine, the primary / standby status of the local machine, the dynamic process weight of the peer machine, the dynamic process weight of the local machine, and the heartbeat timeout detection result, the peer machine drives a finite state machine to perform primary / standby role arbitration and transition; the finite state machine includes a primary state, a standby state, a transition state awaiting promotion to primary, a transition state awaiting demotion to secondary, and a disconnected state; When the local machine enters the transition state to become a master or the transition state to become a slave, if the state of the peer machine does not reach the expected transition target within the waiting timeout period of the current transition state, the local machine will revert to the state before entering the current transition state; when the peer machine enters the transition state to become a master or the transition state to become a slave, if the state of the local machine does not reach the expected transition target within the waiting timeout period of the current transition state, the peer machine will revert to the state before entering the current transition state.

10. A dual-machine master-slave adaptive switching device, applied to the local machine in a dual-machine system, characterized in that, The device includes: The determination module is used to determine the dynamic process weights of the local machine based on the preset weights of the key processes of the local machine. The sending module is used to send a local heartbeat frame to the peer machine through an independent physical network, and to carry the primary / backup status of the local machine and the dynamic process weight of the local machine in the frame body of the local heartbeat frame. The parsing module is used to receive the peer heartbeat frame sent by the peer machine through the independent physical network, and to parse the primary / backup status of the peer machine and the dynamic process weight of the peer machine from the frame body of the received peer heartbeat frame. The acquisition module is used to obtain the heartbeat timeout detection results; The arbitration and switching module is used to drive a finite state machine to perform primary / standby role arbitration and switching based on the primary / standby status of the local machine, the primary / standby status of the peer machine, the dynamic process weight of the local machine, the dynamic process weight of the peer machine, and the heartbeat timeout detection result; the finite state machine includes a primary state, a standby state, a transition state to become primary, a transition state to become secondary, and a disconnected state; The rollback module is used to roll back to the state before entering the current transition state when the local machine enters the transition state to be promoted to master or the transition state to be demoted to slave. If the state of the peer machine does not reach the expected transition target within the waiting timeout period of the current transition state, the local machine will roll back to the state before entering the current transition state.