Node switching method, device and system and computer readable storage medium

By using backup nodes to read heartbeat signals and data fingerprints in the blockchain system, the status of the master node and data consistency are verified, thus solving the problems of split-brain and data conflicts caused by network disconnection in computer systems and achieving stable node switching.

CN121125455APending Publication Date: 2025-12-12JINAN INSPUR DATA TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202511318645.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-15
Publication Date
2025-12-12

AI Technical Summary

Technical Problem

In computer systems, when the network between the primary node and the backup node is disconnected, existing technologies are prone to causing split-brain and data conflicts, and there is a lack of effective node switching methods.

Method used

Backup nodes periodically read the heartbeat signals and data fingerprints of the master nodes in the blockchain system to verify the master node's survival status and data consistency. They are promoted to master nodes only when the signals indicate that the master node is not alive and the data is consistent.

Benefits of technology

When the primary node and backup node are disconnected from the network, the backup node is prevented from blindly upgrading, thus preventing split-brain and data conflicts and ensuring system stability and data consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121125455A_ABST
    Figure CN121125455A_ABST
Patent Text Reader

Abstract

The invention discloses a node switching method, device and system and a computer readable storage medium, and belongs to the field of main and standby node switching, in the invention, a standby node can periodically read a heartbeat signal newly written by a main node in a block chain system, and then under the condition that the read heartbeat signal reflects that the main node is not survived, the standby node can be switched to the standby node; according to the method and the device, the data fingerprint newly written by the main node in the block chain system is read, and the self is upgraded to the main node of the computer system under the condition that the read data fingerprint reflects that the main node is consistent with the overall data of the self, and due to the standby node in the method and the device, the self can be upgraded to the main node of the computer system without depending on a network between the main node and the standby node. Through the heartbeat signal and the data fingerprint in the block chain system, the survival state of the main node and the data consistency between the main node and the standby node are verified, even if the network between the main node and the standby node is disconnected, the standby node cannot be blindly upgraded to the main node, and the brain split condition and the data conflict are avoided.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of master and backup node switching, in particular to a node switching method, device, system and computer readable storage medium. BACKGROUND

[0002] There is a dual hot backup in some computer systems, and the computer system with dual hot backup may have a split-brain situation, that is, the backup node is mistakenly promoted to the master node in the case that the master node is not faulty but the network between the master node and the backup node is disconnected, thereby causing two master nodes to exist in the computer system at the same time and triggering data conflicts, however, there is a lack of a mature node switching method in the related art, and the split-brain situation is prone to occur in the case that the network between the master node and the backup node is disconnected, thereby triggering data conflicts.

[0003] Therefore, how to provide a solution to the above technical problems is a problem that those skilled in the art need to solve at present. SUMMARY

[0004] The purpose of the present application is to provide a node switching method, device, system and computer readable storage medium, the backup node can periodically read the heartbeat signal newly written by the master node in the blockchain system, and then read the data fingerprint newly written by the master node in the blockchain system in the case that the read heartbeat signal reflects that the master node is not alive, and upgrade itself to the master node of the computer system in the case that the read data fingerprint reflects that the master node is consistent with the overall data of itself, since the backup node in the present application, the survival state of the master node and the data consistency between the master and backup nodes can be verified through the heartbeat signal and the data fingerprint in the blockchain system without relying on the network between the master node and the backup node, even in the case that the network between the master node and the backup node is disconnected, the backup node will not be blindly upgraded to the master node, avoiding the occurrence of the split-brain situation and triggering data conflicts.

[0005] To solve the above technical problems, the present application provides a node switching method applied to a backup node of a computer system, comprising:

[0006] periodically reading a heartbeat signal newly written by a master node in a blockchain system, the heartbeat signal comprising a heartbeat signal periodically written by the master node of the computer system to the blockchain system;

[0007] reading a data fingerprint newly written by the master node in the blockchain system in the case that the read heartbeat signal reflects that the master node is not alive, the data fingerprint comprising a data fingerprint of the overall data of itself periodically written by the master node to the blockchain system;

[0008] upgrading itself to the master node of the computer system in the case that the read data fingerprint reflects that the master node is consistent with the overall data of itself.

[0009] In another aspect, the heartbeat signal comprises corresponding heartbeat sub-signals periodically written by a master node of the computer system to the blockchain system through a plurality of writing manners, the writing manners corresponding to the heartbeat sub-signals;

[0010] The periodically reading the heartbeat signal newly written by the master node in the blockchain system comprises:

[0011] Periodically reading a target heartbeat sub-signal corresponding to a writing manner in the blockchain system; the target heartbeat sub-signal corresponding to the writing manner is a heartbeat sub-signal newly written by the master node to the blockchain system through the writing manner;

[0012] In the case that the read heartbeat signal reflects that the master node is not alive, reading a data fingerprint newly written by the master node in the blockchain system comprises:

[0013] According to the obtained target heartbeat sub-signal corresponding to the writing manner, judging whether the master node of the computer system is alive or not;

[0014] If not, reading a data fingerprint newly written by the master node in the blockchain system.

[0015] In another aspect, the judging whether the master node of the computer system is alive or not according to the obtained target heartbeat sub-signal corresponding to the writing manner comprises:

[0016] Judging whether a ratio of a first number of the target heartbeat sub-signals that have timed out to a second number of each of the obtained target heartbeat sub-signals reaches a preset ratio or not;

[0017] If yes, determining that the master node of the computer system is not alive;

[0018] If not, determining that the master node of the computer system is alive.

[0019] In another aspect, the judging whether the ratio of the first number of the target heartbeat sub-signals that have timed out to the second number of each of the obtained target heartbeat sub-signals reaches the preset ratio or not comprises:

[0020] Through a timeout judgment process, the timeout conditions of each of the obtained target heartbeat sub-signals are determined, so that the number of the target heartbeat sub-signals that have timed out is determined as the first number, and the timeout conditions include timeout and non-timeout;

[0021] The timeout judgment process comprises:

[0022] For any target heartbeat sub-signal obtained, it is determined whether a time difference value between a time on a timestamp of the target heartbeat sub-signal and a current time reaches a timeout time threshold corresponding to a writing mode to which the target heartbeat sub-signal belongs; the time on the timestamp is a time at which the target heartbeat sub-signal is written into the blockchain system;

[0023] If the corresponding timeout time threshold is reached, it is determined that the target heartbeat sub-signal is timed out;

[0024] If the corresponding timeout time threshold is not reached, it is determined that the target heartbeat sub-signal is not timed out;

[0025] The number of each target heartbeat sub-signal obtained is determined as a second number;

[0026] It is determined whether a ratio of the first number to the second number reaches a preset ratio.

[0027] On the other hand, the writing mode includes a first writing mode and a second writing mode, the first writing mode includes a user datagram protocol broadcast, and the second writing mode includes a blockchain transaction chaining;

[0028] The writing period corresponding to the first writing mode is less than the writing period corresponding to the second writing mode, and the writing period is a period in which a heartbeat signal is written into the blockchain system.

[0029] On the other hand, the computer system includes a plurality of backup nodes;

[0030] The upgrading of the computer system to a master node includes:

[0031] Writing a competition request containing a device identifier of the self device and a request generation time to the blockchain system;

[0032] Reading, within a preset competition time window, competition requests written by other backup nodes in the blockchain system;

[0033] Comparing the request generation time of the self competition request with the request generation time of the competition request of the other backup nodes, if the request generation time of the self competition request is the earliest, the self device is upgraded to the master node of the computer system;

[0034] If the request generation time of the self competition request is not the earliest, the upgrading operation is abandoned, and a step of periodically reading a heartbeat signal newly written by the master node in the blockchain system is performed.

[0035] On the other hand, the upgrading of the computer system to the master node in the case that the read data fingerprint reflects that the overall data of the master node and the self device is consistent includes:

[0036] Constructing a Merkle tree of the overall data of the self device at present;

[0037] The root hash value of the Merkle tree is determined and used as the data fingerprint of the backup node;

[0038] Determine whether the data fingerprint of the backup node matches the data fingerprint of the primary node;

[0039] If they match, the master node is determined to be consistent with its overall data, and it is promoted to the master node of the computer system.

[0040] The data fingerprint of the master node in the blockchain system includes the root hash value of the Merkle tree of the master node's overall data.

[0041] To address the aforementioned technical problems, the present invention also provides a node switching device applied to a backup node of a computer system, comprising:

[0042] The first reading module is used to periodically read the latest heartbeat signal written by the master node in the blockchain system. The heartbeat signal includes the heartbeat signal periodically written by the master node of the computer system to the blockchain system.

[0043] The second reading module is used to read the latest data fingerprint written by the master node in the blockchain system when the read heartbeat signal indicates that the master node is not alive. The data fingerprint includes the data fingerprint of the master node's overall data periodically written to the blockchain system.

[0044] The first action module is used to upgrade itself to become the master node of the computer system when the read data fingerprint reflects that the master node is consistent with its own overall data.

[0045] To address the aforementioned technical problems, the present invention also provides a node switching system, comprising:

[0046] The master node of the computer system is used to periodically write heartbeat signals to the blockchain system and periodically write its own data fingerprint to the blockchain system.

[0047] The backup node of the computer system is used to periodically read the latest heartbeat signal written by the master node in the blockchain system. If the read heartbeat signal indicates that the master node is not alive, it reads the latest data fingerprint written by the master node in the blockchain system. If the read data fingerprint indicates that the master node is consistent with its own overall data, it will upgrade itself to become the master node of the computer system.

[0048] A blockchain system is used to provide read and write services of heartbeat signals and data fingerprints to master nodes and backup nodes through blockchain technology.

[0049] To address the aforementioned technical problems, the present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the node switching method described above.

[0050] Beneficial Effects: This invention provides a node switching method. Considering that the survival status of the master node can be determined through heartbeat signals, and data consistency can be verified through data fingerprints, and that the blockchain system has tamper-proof characteristics, in this invention, the backup node can periodically read the latest heartbeat signal written by the master node in the blockchain system. Then, if the read heartbeat signal indicates that the master node is not alive, it reads the latest data fingerprint written by the master node in the blockchain system. If the read data fingerprint indicates that the master node and its own overall data are consistent, it upgrades itself to become the master node of the computer system. Because the backup node in this invention can verify the survival status of the master node and the data consistency between the master and backup nodes through heartbeat signals and data fingerprints in the blockchain system without relying on the network between the master and backup nodes, even if the network between the master and backup nodes is disconnected, the backup node will not blindly upgrade to become the master node, avoiding split-brain situations and data conflicts.

[0051] The present invention also provides a node switching device, system, and computer-readable storage medium, which have the same beneficial effects as the node switching method described above. Attached Figure Description

[0052] To more clearly illustrate the technical solutions in the embodiments of the present invention, the relevant technologies and the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0053] Figure 1 A flowchart illustrating a node switching method provided by the present invention;

[0054] Figure 2 A schematic diagram of the structure of a node switching device provided by the present invention;

[0055] Figure 3 A schematic diagram of the structure of a node switching system provided by the present invention;

[0056] Figure 4 This is a schematic diagram of the structure of a computer-readable storage medium provided by the present invention. Detailed Implementation

[0057] The core of this invention is to provide a node switching method, apparatus, system, and computer-readable storage medium. A backup node can periodically read the latest heartbeat signal written by the master node in the blockchain system. If the read heartbeat signal indicates that the master node is not alive, the backup node reads the latest data fingerprint written by the master node in the blockchain system. If the read data fingerprint indicates that the master node's overall data is consistent with its own, the backup node upgrades itself to become the master node of the computer system. Because the backup node in this invention can verify the master node's survival status and the data consistency between the master and backup nodes through heartbeat signals and data fingerprints in the blockchain system without relying on the network between the master and backup nodes, even if the network between the master and backup nodes is disconnected, the backup node will not blindly upgrade to become the master node, avoiding split-brain situations and data conflicts.

[0058] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0059] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating a node switching method provided by the present invention. The node switching method is applied to a backup node 32 of a computer system and includes:

[0060] S101: Periodically read the latest heartbeat signal written by the master node 31 in the blockchain system 33. The heartbeat signal includes the heartbeat signal periodically written by the master node 31 of the computer system to the blockchain system 33.

[0061] Specifically, considering the technical problems mentioned above, and taking into account that the survival status of the master node 31 can be determined by the heartbeat signal, data consistency can be verified by the data fingerprint, and the blockchain system 33 has anti-tampering characteristics, this embodiment of the invention intends to store the heartbeat signal and data fingerprint periodically written by the master node 31 of the computer system in the blockchain system 33, and enable the backup node 32 to acquire the heartbeat signal and data fingerprint to verify the survival status of the master node 31 and the data consistency between the backup node 32 and the master node 31. Therefore, in this step, the backup node 32 can periodically read the latest heartbeat signal written by the master node 31 in the blockchain system 33 (the heartbeat signal periodically written by the master node 31 of the computer system to the blockchain system 33) so as to use it as the data basis for subsequent steps.

[0062] S102: If the read heartbeat signal indicates that the master node 31 is not alive, read the latest data fingerprint written by the master node 31 in the blockchain system 33. The data fingerprint includes the data fingerprint of the overall data that the master node 31 periodically writes to the blockchain system 33.

[0063] Since master node 31 cannot write heartbeat signals to blockchain system 33 if it is not alive, the "latest heartbeat signal written by master node 31 in blockchain system 33" can theoretically reflect the survival status of master node 31. In the event that master node 31 is not alive, it can be promoted to master node 31 if the data of backup node 32 is consistent with that of master node 31. The "latest data fingerprint written by master node 31 in blockchain system 33" can verify the data consistency between backup node 32 and master node 31. Therefore, in this step, if the read heartbeat signal reflects that master node 31 is not alive, the latest data fingerprint written by master node 31 in blockchain system 33 (the data fingerprint of the overall data that master node 31 periodically writes to blockchain system 33) can be read to serve as the data basis for subsequent steps.

[0064] S103: If the read data fingerprint reflects that the master node 31 is consistent with its own overall data, it will upgrade itself to the master node 31 of the computer system.

[0065] Specifically, since the "latest data fingerprint written by the master node 31 in the blockchain system 33" can help verify the data consistency between the backup node 32 and the master node 31, in this step, if the read data fingerprint reflects that the master node 31 is consistent with its own overall data, it can upgrade itself to the master node 31 of the computer system. That is, it can upgrade to the master node 31 only if it ensures that the master node 31 is not alive and that the backup node 32 is consistent with the overall data of the master node 31. It will not blindly upgrade to the master node 31 because of the "network disconnection between the backup node 32 and the master node 31", thus avoiding the occurrence of split brain and data conflicts caused by the simultaneous existence of two nodes.

[0066] The computer system can be of various types, such as a cloud computing platform system, and this embodiment of the invention does not limit it.

[0067] Specifically, the blockchain system 33 can be of various types, such as a lightweight blockchain network (HLF, Hyperledger Fabric), and then the master node 31 and the backup node 32 of the computer system are both configured as member nodes of the blockchain network. This embodiment of the invention does not limit the scope of the invention.

[0068] Among them, the computer system refers to an electronic computing system with a dual-machine hot standby architecture of primary and backup nodes, used to carry out specific business data processing and service operation. Its core function is to provide stable business services to the outside world through the primary node, while the backup node synchronizes the data of the primary node in real time and is in a standby state to ensure seamless takeover of services in the event of a primary node failure, thus avoiding business interruption. The blockchain system refers to a distributed ledger system based on blockchain technology, which has decentralized and tamper-proof data characteristics. Its core function is to provide trusted heartbeat signals and data fingerprint storage and retrieval services for the primary and backup nodes of the computer system, serving as a "third-party trusted carrier" for verifying the survival status of the primary node and verifying the consistency of data between the primary and backup nodes.

[0069] This invention provides a node switching method. Considering that the survival status of the master node can be determined through heartbeat signals, and data consistency can be verified through data fingerprints, and that the blockchain system has tamper-proof characteristics, in this invention, the backup node can periodically read the latest heartbeat signal written by the master node in the blockchain system. Then, if the read heartbeat signal indicates that the master node is not alive, it reads the latest data fingerprint written by the master node in the blockchain system. If the read data fingerprint indicates that the master node's overall data is consistent with its own, it upgrades itself to become the master node of the computer system. Because the backup node in this invention can verify the survival status of the master node and the data consistency between the master and backup nodes through heartbeat signals and data fingerprints in the blockchain system without relying on the network between the master and backup nodes, even if the network between the master and backup nodes is disconnected, the backup node will not blindly upgrade to become the master node, avoiding split-brain situations and data conflicts.

[0070] Based on the above embodiments:

[0071] As an optional embodiment, the heartbeat signal includes a corresponding heartbeat sub-signal that the master node 31 of the computer system periodically writes to the blockchain system 33 through various writing methods, with the writing method corresponding to the heartbeat sub-signal;

[0072] The periodic reading of the latest heartbeat signal written by master node 31 in blockchain system 33 includes:

[0073] Periodically read the target heartbeat sub-signals in the blockchain system 33 that correspond one-to-one with the writing method; the target heartbeat sub-signals that correspond one-to-one with the writing method are: the heartbeat sub-signals that the master node 31 has recently written to the blockchain system 33 through the writing method;

[0074] If the read heartbeat signal indicates that master node 31 is not alive, the latest data fingerprint written by master node 31 in the blockchain system 33 includes:

[0075] Based on the target heartbeat sub-signals that correspond one-to-one with the writing method, determine whether the master node 31 of the computer system is alive;

[0076] If it is not alive, then read the latest data fingerprint written by master node 31 in blockchain system 33.

[0077] Specifically, considering that the heartbeat signal of a single write method is easily affected by factors such as network fluctuations and channel failures, which may lead to misjudgment of the survival status of the master node 31 by the backup node 32, this problem can be solved by using heartbeat signals of multiple different write methods. Therefore, this embodiment of the invention sets up a heartbeat sub-signal scheme for multiple write methods. The heartbeat sub-signals corresponding to multiple write methods can reflect the activity of the master node 31 from different dimensions. Even if a channel corresponding to a certain write method experiences a temporary failure, the backup node 32 can still judge the status of the master node 31 through the heartbeat sub-signals of other channels, reducing misjudgments caused by a single channel failure and improving the reliability of the master node 31 activity judgment.

[0078] The specific number of writing methods can be set independently, for example, there can be two, etc., and this embodiment of the invention does not limit it here.

[0079] Specifically, in one concrete instance, two writing methods can be set to generate corresponding heartbeat sub-signals. The two writing methods include:

[0080] The first writing method is UDP (User Datagram Protocol) broadcast. This method has a fast transmission speed and can quickly reflect network connectivity. The writing cycle can be set to 1Hz (i.e., once per second) to generate the first heartbeat sub-signal.

[0081] The second writing method: blockchain transactions are recorded on the chain, which can be implemented based on HLF. This method is immutable and can ensure the reliability of the heartbeat signal. The writing cycle can be set to 0.2Hz (i.e., once every 5 seconds) to generate the second heartbeat sub-signal.

[0082] The master node 31 writes the corresponding heartbeat sub-signals to the HLF using the two writing methods according to the above writing cycle; the backup node 32 reads the latest target heartbeat sub-signals (i.e., the first heartbeat sub-signal and the second heartbeat sub-signal) from the HLF at a cycle of 1 second / time, and combines the status of the two sub-signals to comprehensively determine whether the master node 31 is alive.

[0083] As an optional embodiment, determining whether the master node 31 of the computer system is alive based on the acquired target heartbeat sub-signals that correspond one-to-one with the writing method includes:

[0084] Determine whether the ratio of the first number of timed-out target heartbeat sub-signals to the second number of acquired target heartbeat sub-signals reaches a preset ratio.

[0085] If this condition is met, then the computer system's master node 31 is determined to be not alive.

[0086] If the condition is not met, the computer system's master node 31 is determined to be alive.

[0087] Specifically, considering that under the multi-write mode, the timeout of some heartbeat sub-signals may be caused by temporary channel failures (such as UDP channel timeout due to network jitter, but blockchain channel is normal). If the master node 31 is not alive based solely on the timeout of a single sub-signal, it is easy to cause misjudgment. Therefore, in this embodiment of the invention, a rule is set to judge the ratio of the number of timeout sub-signals to the total number of sub-signals. By comprehensively considering the status of multiple channels, the interference of a single channel's temporary failure on the judgment result can be effectively eliminated. When the ratio of the first number of timeout target heartbeat sub-signals to the second number of each acquired target heartbeat sub-signal reaches a preset ratio, the master node 31 is judged to be not alive. This can reduce unnecessary node switching operations and ensure the stability of system operation.

[0088] One specific embodiment is as follows: with a preset ratio of 60% (which can be adjusted according to the system's reliability requirements), and the write method corresponding to two heartbeat sub-signals (i.e., the second quantity is 2), the backup node 32 performs timeout judgment on the two heartbeat sub-signals respectively: if the timestamp of the first heartbeat sub-signal (generated by UDP broadcast) differs from the current time by more than 3 seconds, it is judged as a timeout; if the timestamp of the second heartbeat sub-signal (generated by blockchain transaction upload) differs from the current time by more than 15 seconds, it is judged as a timeout; if the first heartbeat sub-signal times out and the second heartbeat sub-signal is normal, the number of timeout sub-signals (the first quantity) is 1, the ratio is 1 / 2 = 50%, which does not reach the preset ratio of 60%, and the master node 31 is judged to be alive; if both the first heartbeat signal and the second heartbeat signal time out, the first quantity is 2, the ratio is 2 / 2 = 100%, which reaches the preset ratio, and the master node 31 is judged to be not alive.

[0089] As an optional embodiment, determining whether the ratio of the first number of timed-out target heartbeat sub-signals to the second number of acquired target heartbeat sub-signals reaches a preset ratio includes:

[0090] The timeout judgment process determines the timeout status of each acquired target heartbeat sub-signal, thereby determining the number of timeout target heartbeat sub-signals as the first quantity. The timeout status includes timeout and no timeout.

[0091] The timeout determination process includes:

[0092] For any target heartbeat sub-signal obtained, determine whether the time difference between the time on the timestamp of the target heartbeat sub-signal and the current time reaches the timeout threshold corresponding to the writing method of the target heartbeat sub-signal; the time on the timestamp is the time when the target heartbeat sub-signal is written into the blockchain system 33;

[0093] If the corresponding timeout threshold is reached, the target heartbeat signal is determined to have timed out.

[0094] If the corresponding timeout threshold is not reached, the target heartbeat signal is determined not to have timed out.

[0095] The number of each target heartbeat sub-signal acquired is determined as the second quantity;

[0096] Determine whether the ratio of the first quantity to the second quantity reaches the preset ratio.

[0097] Specifically, considering that the heartbeat sub-signals of different writing methods have different writing cycles (e.g., short UDP broadcast cycle and long blockchain transaction on-chain cycle), if a uniform timeout threshold is used, long-cycle sub-signals will be frequently misjudged as timeouts, or short-cycle sub-signals will not be detected in time after timeout. Therefore, in this embodiment of the invention, a timeout threshold corresponding to the writing method is set to adapt to the transmission characteristics of different sub-signals. This allows for the customization of timeout thresholds for the characteristics of different writing methods, avoiding misjudgments caused by cycle differences, improving the accuracy of timeout judgment, and further ensuring the reliability of the master node 31 activity judgment result.

[0098] Of course, in addition to this specific method, other methods can be used to "determine whether the ratio of the first number of timed-out target heartbeat sub-signals to the second number of acquired target heartbeat sub-signals reaches a preset ratio", and this embodiment of the invention does not limit it here.

[0099] In one specific instance, timeout thresholds are set separately for the two write methods:

[0100] First write method (UDP broadcast): The write cycle is 1Hz (once per second), and the corresponding timeout threshold is set to 3 seconds (i.e., 3 times the write cycle) to ensure that temporary network jitter will not trigger false judgments.

[0101] The second writing method (blockchain transaction upload): the writing cycle is 0.2Hz (once every 5 seconds), and the corresponding timeout threshold is set to 15 seconds (i.e., 3 times the writing cycle), which is adapted to the latency characteristics of blockchain transaction upload.

[0102] After the backup node 32 obtains any target heartbeat sub-signal, it extracts the timestamp when the sub-signal is written to HLF (i.e., the time when the sub-signal is written to blockchain system 33); calculates the time difference between the current time and the timestamp; if the difference reaches the timeout threshold of the corresponding writing method, it determines that the target heartbeat sub-signal has timed out; it counts the number of timeouts (first number) and the total number (second number) of all target heartbeat sub-signals, and determines whether the ratio of the two reaches the preset ratio.

[0103] As an optional embodiment, the writing method includes a first writing method and a second writing method. The first writing method includes user datagram protocol broadcasting, and the second writing method includes blockchain transaction uploading.

[0104] The write cycle corresponding to the first write method is shorter than the write cycle corresponding to the second write method. The write cycle is the cycle during which the heartbeat signal is written into the blockchain system 33.

[0105] Specifically, considering that UDP broadcast has the characteristics of fast transmission speed and low latency, it is suitable for quickly probing the connectivity between master node 31 and the network; blockchain transaction on-chain has the characteristics of immutability, which can ensure the credibility of heartbeat signals, but the transmission latency is relatively high and the cycle is long; therefore, in this embodiment of the invention, the cycle difference between the two writing methods is set, so that UDP broadcast undertakes the responsibility of fast detection, and blockchain transaction on-chain undertakes the responsibility of credible verification. The short-cycle UDP broadcast can provide real-time feedback on the network connectivity status of master node 31, while the long-cycle blockchain transaction on-chain can ensure the credibility of heartbeat signals. The combination of the two achieves a balance between real-time detection and credible verification, which avoids the risk of misjudgment of unreliable short-cycle signals and avoids the problem of insufficient real-time performance of reliable long-cycle signals.

[0106] Of course, in addition to this specific form, the specific combination of writing methods and their corresponding writing cycles can be set according to actual needs, and the embodiments of the present invention are not limited here.

[0107] As an optional embodiment, the computer system includes multiple backup nodes 32;

[0108] Upgrading itself to a master node of the computer system 31 includes:

[0109] Write a competition request containing its own device identifier and the time of request generation to the blockchain system 33;

[0110] Within the preset competition time window, read the competition requests written by other backup nodes 32 in the blockchain system 33;

[0111] Compare the request generation time of its own competing request with the request generation time of other standby nodes 32. If its own competing request was generated earliest, it will be promoted to the master node 31 of the computer system.

[0112] If the request for competition is not generated earliest, the upgrade operation is abandoned and the following steps are performed: periodically read the latest heartbeat signal written by master node 31 in blockchain system 33.

[0113] Specifically, considering that when a computer system contains multiple backup nodes 32, if multiple backup nodes 32 simultaneously determine that the master node 31 is not alive and their own data is consistent with the master node 31, it is easy for multiple backup nodes 32 to be upgraded to the master node 31 at the same time, causing multi-master conflict. Therefore, in this embodiment of the invention, a competition request mechanism is set up. By comparing the timing of the competition request, a unique new master node 31 can be determined from multiple backup nodes 32 that meet the upgrade conditions, thus completely solving the multi-master conflict problem caused by the simultaneous upgrade of multiple backup nodes 32 and ensuring the uniqueness and data consistency of the system master node 31.

[0114] In one specific example, the computer system includes one master node 31 and three slave nodes 32 (slave nodes 32X, Y, and Z), all of which are member nodes of the blockchain system 33. When each slave node 32 determines that the master node 31 is not alive and its own data is consistent with that of the master node 31, it writes a competition request to the blockchain system 33. The request content includes its own device identifier (such as "slave-X", "slave-Y", "slave-Z") and the time of request generation (a timestamp accurate to milliseconds, such as "1718000000123", "1718000000125", "1718000000124"). The preset competition time window is 10 seconds. Each backup node 32 reads the competition requests of other backup nodes 32 in the blockchain system 33 within the window and compares the generation time of all requests: if the generation time of backup node 32X is the earliest (1718000000123), then backup node 32X will upgrade itself to become the master node 31 of the computer system; backup nodes 32Y and Z find that their own request generation time is not the earliest, abandon the upgrade operation, and resume periodically reading the heartbeat signal of the new master node 31 (backup node 32X).

[0115] As an optional embodiment, if the read data fingerprint reflects that the master node 31 is consistent with its own overall data, upgrading itself to the master node 31 of the computer system includes:

[0116] Construct a Merkle tree of its current overall data;

[0117] The root hash value of the Merkle tree is determined and used as the data fingerprint of backup node 32;

[0118] Determine whether the data fingerprint of the backup node 32 is consistent with the data fingerprint of the master node 31 read;

[0119] If they match, then the master node 31 is determined to be consistent with its own overall data, and it will be promoted to the master node 31 of the computer system.

[0120] Among them, the data fingerprint of the master node 31 in the blockchain system 33 includes the root hash value of the Merkle tree of the overall data of the master node 31.

[0121] Specifically, considering that directly comparing the full data of the primary and backup nodes 32 would consume a large amount of network and computing resources, resulting in extremely low verification efficiency; while the Root Hash of a Merkle Tree (MT) can serve as a "data fingerprint" for the entire data, the consistency of the full data can be determined by comparing the root hash value, and the hash value is unique, ensuring accurate verification results; therefore, this embodiment of the invention sets up a consistency verification scheme based on Merkle trees, replacing the comparison of the full data with the Merkle tree root hash value, which can significantly reduce the amount of data transmission and computation, and improve the efficiency of data consistency verification; at the same time, the uniqueness of the root hash value can ensure the accuracy of the verification results and avoid misjudgments caused by partial data consistency.

[0122] Specifically, in one instance, the data fingerprint of the master node 31 in the blockchain system 33 is the root hash value of the Merkle tree constructed from its overall data. Every preset period (e.g., 180 seconds), the master node 31 reconstructs the MT based on its current overall data and calculates the root hash value, writing the root hash value into the blockchain system 33. After determining that the master node 31 is not alive, the backup node 32 reads the latest root hash value of the master node 31 from the blockchain system 33. Subsequently, the backup node 32 constructs the MT based on its current overall data: it divides its own data into several data blocks in 200MB blocks, calculates the SHA-256 (Secure Hash Algorithm 256-bit) hash value of each block as the leaf node of the MT; starting from the leaf node, it concatenates the hash values ​​of two adjacent nodes layer by layer and calculates the SHA-256 hash value again as the hash value of the parent node, until the root hash value of the top layer (the data fingerprint of the backup node 32) is obtained. Compare the hash value of standby node 32 with the hash value of master node 31 read from blockchain system 33. If the two are completely consistent, it is determined that the overall data of master node 31 and standby node 32 are consistent, and standby node 32 performs the upgrade operation; if they are inconsistent, the standby state is maintained.

[0123] Additionally, as an optional embodiment, after determining that the master node 31 of the computer system is not alive and before reading the latest data fingerprint written by the master node 31 in the blockchain system 33, a secondary verification step for the survival of the master node 31 is also included, specifically including:

[0124] Write a liveness detection request for master node 31 to blockchain system 33. The liveness detection request for master node 31 includes the unique device identifier of master node 31, the unique device identifier of backup node 32 itself, and the timestamp of the detection request generation.

[0125] Set a preset detection waiting window. The duration of the preset detection waiting window is greater than the maximum theoretical time taken for the master node 31 to monitor and respond to the liveness detection request, and less than 1 / 2 of the heartbeat signal writing cycle of the master node 31.

[0126] Within the preset detection waiting window, the liveness response information associated with the unique device identifier of the master node 31 in the blockchain system 33 is periodically read. The liveness response information is generated by the master node 31 after detecting the liveness detection request of the master node 31 and written into the blockchain system 33, and includes the status identifier of the master node 31 confirming the liveness and the response generation timestamp.

[0127] If no liveness response information associated with the unique device identifier of master node 31 is read within the preset detection waiting window, the step of "reading the latest data fingerprint written by master node 31 in blockchain system 33" is executed.

[0128] If a liveness response is read within the preset detection waiting window, and the timestamp of the liveness response is later than the timestamp of the detection request, then the master node 31 is determined to be actually alive. The subsequent operation of reading data fingerprints is abandoned, and the process of "periodically reading the latest heartbeat signal written by the master node 31 in the blockchain system 33" is returned.

[0129] Specifically, considering that after initially determining that master node 31 is not alive, there may be scenarios such as temporary network fluctuations or delays in heartbeat signal uploading, which are not actual failures of master node 31, leading to misjudgment in the initial assessment; if the subsequent data fingerprint reading stage is directly entered, it is easy to cause unnecessary consumption of computing resources, and may even trigger erroneous node switching operations. Therefore, in this embodiment of the invention, combined with the trusted data interaction and tamper-proof characteristics of the blockchain system 33, a secondary verification step for the liveness of master node 31 is set up. By actively sending probe requests and receiving responses, the actual activity status of master node 31 is further verified. This can effectively filter out misjudgments of master node 31 activity caused by temporary network anomalies and signal transmission delays, avoid unnecessary subsequent data fingerprint reading and consistency verification operations, and reduce the consumption of system computing and storage resources; at the same time, relying on the blockchain system 33 to carry probe request and response information, the immutability of interactive data is guaranteed, ensuring the credibility of the secondary verification results, further reducing the system risk caused by misjudgment, and improving the stability of the dual-machine hot standby architecture.

[0130] Please refer to Figure 2 , Figure 2This is a schematic diagram of a node switching device provided by the present invention. The node switching device is applied to a backup node 32 of a computer system and includes:

[0131] The first reading module 21 is used to periodically read the latest heartbeat signal written by the master node 31 in the blockchain system 33. The heartbeat signal includes the heartbeat signal periodically written by the master node 31 of the computer system to the blockchain system 33.

[0132] The second reading module 22 is used to read the latest data fingerprint written by the master node 31 in the blockchain system 33 when the read heartbeat signal reflects that the master node 31 is not alive. The data fingerprint includes the data fingerprint of the overall data of the master node 31 periodically written to the blockchain system 33.

[0133] The first action module 23 is used to upgrade itself to become the master node 31 of the computer system when the read data fingerprint reflects that the master node 31 is consistent with its own overall data.

[0134] Based on the above embodiments:

[0135] As an optional embodiment, the heartbeat signal includes a corresponding heartbeat sub-signal that the master node 31 of the computer system periodically writes to the blockchain system 33 through various writing methods, with the writing method corresponding to the heartbeat sub-signal;

[0136] The first reading module 21 is specifically used for:

[0137] Periodically read the target heartbeat sub-signals in the blockchain system 33 that correspond one-to-one with the writing method; the target heartbeat sub-signals that correspond one-to-one with the writing method are: the heartbeat sub-signals that the master node 31 has recently written to the blockchain system 33 through the writing method;

[0138] The second reading module 22 includes:

[0139] The first judgment module is used to determine whether the master node 31 of the computer system is alive based on the target heartbeat sub-signals that are obtained one-to-one with the writing method. If it is not alive, the first reading sub-module is triggered.

[0140] The first reading submodule is used to read the latest data fingerprint written by the master node 31 in the blockchain system 33.

[0141] As an optional embodiment, the first determination module includes:

[0142] The second judgment module is used to determine whether the ratio of the first number of timed-out target heartbeat sub-signals to the second number of acquired target heartbeat sub-signals reaches a preset ratio. If it does, the first judgment module is triggered; if it does not, the second judgment module is triggered.

[0143] The first determination module is used to determine whether the master node 31 of the computer system is not alive;

[0144] The second determination module is used to determine whether the master node 31 of the computer system is alive.

[0145] As an optional embodiment, the second determination module is specifically used for:

[0146] The timeout judgment process determines the timeout status of each acquired target heartbeat sub-signal, thereby determining the number of timeout target heartbeat sub-signals as the first quantity. The timeout status includes timeout and no timeout.

[0147] The timeout determination process includes:

[0148] For any target heartbeat sub-signal obtained, determine whether the time difference between the time on the timestamp of the target heartbeat sub-signal and the current time reaches the timeout threshold corresponding to the writing method of the target heartbeat sub-signal; the time on the timestamp is the time when the target heartbeat sub-signal is written into the blockchain system 33;

[0149] If the corresponding timeout threshold is reached, the target heartbeat signal is determined to have timed out.

[0150] If the corresponding timeout threshold is not reached, the target heartbeat signal is determined not to have timed out.

[0151] The number of each target heartbeat sub-signal acquired is determined as the second quantity;

[0152] Determine whether the ratio of the first quantity to the second quantity reaches the preset ratio.

[0153] As an optional embodiment, the first action module 23 includes:

[0154] The first building module is used to construct the Merkle tree of its current overall data;

[0155] The first determining module is used to determine the root hash value of the Merkle tree, which serves as the data fingerprint of the backup node 32.

[0156] The third judgment module is used to determine whether the data fingerprint of the backup node 32 is consistent with the data fingerprint of the master node 31. If they are consistent, the third judgment module is triggered.

[0157] The third determination module is used to determine whether the master node 31 is consistent with its own overall data and to upgrade itself to the master node 31 of the computer system.

[0158] Among them, the data fingerprint of the master node 31 in the blockchain system 33 includes the root hash value of the Merkle tree of the overall data of the master node 31.

[0159] For a description of the node switching device provided in the embodiments of the present invention, please refer to the aforementioned embodiments of the node switching method; the embodiments of the present invention will not be repeated here.

[0160] Please refer to Figure 3 , Figure 3 This is a schematic diagram of a node switching system provided by the present invention. The node switching system includes:

[0161] The master node 31 of the computer system is used to periodically write heartbeat signals to the blockchain system and periodically write its own overall data fingerprint to the blockchain system.

[0162] The backup node 32 of the computer system is used to periodically read the latest heartbeat signal written by the master node in the blockchain system. If the read heartbeat signal indicates that the master node is not alive, it reads the latest data fingerprint written by the master node in the blockchain system. If the read data fingerprint indicates that the master node is consistent with its own overall data, it upgrades itself to become the master node of the computer system.

[0163] Blockchain system 33 is used to provide read and write services of heartbeat signals and data fingerprints to master nodes and backup nodes through blockchain technology.

[0164] For a description of the node switching system provided in this embodiment of the invention, please refer to the aforementioned embodiments of the node switching method; the embodiments of the present invention will not be repeated here.

[0165] Please refer to Figure 4 , Figure 4 This is a schematic diagram of a computer-readable storage medium provided by the present invention. The computer-readable storage medium 41 stores a computer program 42. When the computer program 42 is executed by the processor, it implements the steps of the node switching method described above.

[0166] For a description of the computer-readable storage medium provided in the embodiments of the present invention, please refer to the aforementioned embodiments of the node switching method; the embodiments of the present invention will not be repeated here.

[0167] This invention also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of the node switching method as described in the foregoing embodiments.

[0168] For a description of the computer program product provided in the embodiments of the present invention, please refer to the aforementioned embodiments of the node switching method; the embodiments of the present invention will not be repeated here.

[0169] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section. It should also be noted that in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising a..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0170] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily 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 invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A node switching method, characterized in that, Backup nodes used in computer systems include: The system periodically reads the latest heartbeat signals written by the master node in the blockchain system, including the heartbeat signals periodically written by the master node of the computer system to the blockchain system. If the read heartbeat signal indicates that the master node is not alive, read the latest data fingerprint written by the master node in the blockchain system. The data fingerprint includes the data fingerprint of the overall data that the master node periodically writes to the blockchain system. If the read data fingerprint reflects that the master node is consistent with its own overall data, it will upgrade itself to become the master node of the computer system.

2. The node switching method according to claim 1, characterized in that, The heartbeat signal includes corresponding heartbeat sub-signals that the master node of the computer system periodically writes to the blockchain system through various writing methods, and the writing methods correspond to the heartbeat sub-signals; The periodic reading of the latest heartbeat signal written by the master node in the blockchain system includes: Periodically read the target heartbeat signal in the blockchain system that corresponds one-to-one with the writing method; the target heartbeat signal corresponding one-to-one with the writing method is: the heartbeat signal that the master node has recently written to the blockchain system through the writing method; When the read heartbeat signal indicates that the master node is not alive, reading the latest data fingerprint written by the master node in the blockchain system includes: Based on the target heartbeat sub-signals that correspond one-to-one with the writing method, determine whether the master node of the computer system is alive; If it is not alive, then read the latest data fingerprint written by the master node in the blockchain system.

3. The node switching method according to claim 2, characterized in that, The step of determining whether the master node of the computer system is alive based on the acquired target heartbeat sub-signals that correspond one-to-one with the writing method includes: Determine whether the ratio of the first number of timed-out target heartbeat sub-signals to the second number of acquired target heartbeat sub-signals reaches a preset ratio. If this condition is met, the computer system's master node is determined to be not alive. If this condition is not met, the computer system's master node is considered alive.

4. The node switching method according to claim 3, characterized in that, Whether the ratio of the first number of time-out target heartbeat sub-signals to the second number of acquired target heartbeat sub-signals reaches a preset ratio includes: The timeout judgment process determines the timeout status of each acquired target heartbeat sub-signal, thereby determining the number of timeout target heartbeat sub-signals as the first quantity. The timeout status includes timeout and no timeout. The timeout determination process includes: For any target heartbeat sub-signal obtained, determine whether the time difference between the time on the timestamp of the target heartbeat sub-signal and the current time reaches the timeout threshold corresponding to the writing method of the target heartbeat sub-signal; the time on the timestamp is the time when the target heartbeat sub-signal is written into the blockchain system; If the corresponding timeout threshold is reached, the target heartbeat signal is determined to have timed out. If the corresponding timeout threshold is not reached, the target heartbeat signal is determined not to have timed out. The number of each target heartbeat sub-signal acquired is determined as the second quantity; Determine whether the ratio of the first quantity to the second quantity reaches a preset ratio.

5. The node switching method according to claim 2, characterized in that, The writing method includes a first writing method and a second writing method. The first writing method includes user datagram protocol broadcasting, and the second writing method includes blockchain transaction on-chaining. The write cycle corresponding to the first write method is shorter than the write cycle corresponding to the second write method. The write cycle is the cycle during which the heartbeat signal is written into the blockchain system.

6. The node switching method according to claim 1, characterized in that, The computer system includes multiple backup nodes; The process of upgrading itself to a master node of a computer system includes: A competition request containing its own device identifier and the time of request generation is written into the blockchain system; Within the preset competition time window, read the competition requests written by other backup nodes in the blockchain system; Compare the request generation time of its own contention request with the request generation time of other backup nodes. If its own contention request was generated earliest, it will be promoted to the master node of the computer system. If the request for competition is not generated earliest, the upgrade operation is abandoned and the following steps are performed: periodically read the latest heartbeat signal written by the master node in the blockchain system.

7. The node switching method according to any one of claims 1 to 6, characterized in that, The step of upgrading itself to become the master node of the computer system when the read data fingerprint reflects that the master node is consistent with its own overall data includes: Construct a Merkle tree of its current overall data; The root hash value of the Merkle tree is determined and used as the data fingerprint of the backup node; Determine whether the data fingerprint of the backup node matches the data fingerprint of the primary node; If they match, the master node is determined to be consistent with its overall data, and it is promoted to the master node of the computer system. The data fingerprint of the master node in the blockchain system includes the root hash value of the Merkle tree of the master node's overall data.

8. A node switching device, characterized in that, Backup nodes used in computer systems include: The first reading module is used to periodically read the latest heartbeat signal written by the master node in the blockchain system. The heartbeat signal includes the heartbeat signal periodically written by the master node of the computer system to the blockchain system. The second reading module is used to read the latest data fingerprint written by the master node in the blockchain system when the read heartbeat signal indicates that the master node is not alive. The data fingerprint includes the data fingerprint of the master node's overall data periodically written to the blockchain system. The first action module is used to upgrade itself to become the master node of the computer system when the read data fingerprint reflects that the master node is consistent with its own overall data.

9. A node switching system, characterized in that, include: The master node of the computer system is used to periodically write heartbeat signals to the blockchain system and periodically write its own data fingerprint to the blockchain system. The backup node of the computer system is used to periodically read the latest heartbeat signal written by the master node in the blockchain system. If the read heartbeat signal indicates that the master node is not alive, it reads the latest data fingerprint written by the master node in the blockchain system. If the read data fingerprint indicates that the master node is consistent with its own overall data, it will upgrade itself to become the master node of the computer system. A blockchain system is used to provide read and write services of heartbeat signals and data fingerprints to master nodes and backup nodes through blockchain technology.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the node switching method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method for performing node switching in case of node fault and related equipment

    CN112199240A

  • Master-slave node switching method and device

    CN112367198A

  • Block chain data security improvement method based on credit layering

    CN117278326A

  • Data processing method and device based on block chain network and storage medium

    CN119996164A

  • High-availability service split-brain state processing method, system and device and storage medium

    CN120086048A