A node data synchronization method, device and computer readable storage medium
By building a red-black tree between nodes and transferring communication pressure to child nodes, the problem of high performance and bandwidth pressure on the master node under the traditional master-slave synchronization method is solved, and communication efficiency and data synchronization stability are improved.
Patent Information
- Application Number
- CN202210879796.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-25
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2042-07-25
AI Technical Summary
The traditional master-slave data synchronization method between nodes results in high performance pressure, high bandwidth pressure, and low communication efficiency on the master node, especially when there are many service nodes.
Using the node data synchronization method based on the red-black tree, by obtaining all nodes, determining the main node and building a red-black tree, the main node establishes a communication connection with the root node, and the communication content is transferred from the main node to the root node, and then from the root node to Its sub-nodes realize data synchronization between nodes, transfer communication pressure to sub-nodes, and reduce the load of the main node.
It effectively reduces the performance and bandwidth pressure of the master node, improves communication efficiency, ensures the stability of core services provided by the master node, and controls the size of the communication link through the tree structure to improve data synchronization efficiency.
Smart Images

Figure CN115242812B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of node communication technology, and in particular to a node data synchronization method, device, and computer-readable storage medium. Background Art
[0002] In today's era of big data, the Internet's network architecture has been developing in a distributed and highly concurrent direction. To ensure high availability and robustness of services, the stability and timeliness of communication between master and slave nodes are crucial.
[0003] Traditional master-slave data synchronization between nodes often uses a star-shaped structure, where all nodes synchronize data directly from the master node. When serving a large number of nodes, this synchronization approach often places significant performance and bandwidth pressure on the master node, hindering data transmission and reducing communication efficiency.
[0004] In view of the above problems, designing a node data synchronization method that can solve the problems of high performance pressure on the master node, high bandwidth pressure, and low communication efficiency in the traditional node data synchronization process is an urgent problem to be solved by technical personnel in this field. Summary of the Invention
[0005] The purpose of this application is to provide a node data synchronization method, device and computer-readable storage medium, which can solve the problems of high performance pressure on the master node, high bandwidth pressure and low communication efficiency in the traditional node data synchronization process.
[0006] To solve the above technical problems, the present application provides a node data synchronization method, including:
[0007] Get all nodes;
[0008] Determine a main node among the nodes, and construct a red-black tree based on the remaining nodes; wherein the red-black tree includes a root node and each child node under the root node;
[0009] Establishing a communication connection between the master node and the root node;
[0010] Sending communication content to the root node through the master node;
[0011] The communication content is sent to each of the child nodes under the root node through the root node, so that when each of the child nodes serves as a parent node, the communication content is transmitted to the corresponding new child node, thereby achieving data synchronization of all the nodes.
[0012] Preferably, the sending of the communication content to the root node through the master node includes:
[0013] generating, in the master node, the communication content including a message ID, a timestamp, a communication tree identifier, communication tree information, and a communication path, and sending the communication content to the root node;
[0014] The communication path is newly added with the node ID of the master node.
[0015] Preferably, before sending the communication content to each of the child nodes under the root node through the root node, the method further includes:
[0016] Determine whether the root node has the child node;
[0017] If so, the process proceeds to the step of sending the communication content to each of the child nodes under the root node through the root node, and adding the node ID of the root node to the communication path.
[0018] Preferably, it also includes:
[0019] If the child node does not receive the health heartbeat of the corresponding parent node within a preset time, the child node sends a health heartbeat request to the corresponding parent node;
[0020] If the request is confirmed to be successful, the child node is controlled to compare the historical synchronization content of the parent node according to the timestamp of the last request received to supplement the missing data content;
[0021] If the confirmation request is unsuccessful, confirm that the node receiving the health heartbeat request is a faulty node, and control the child node to skip the level and send the health heartbeat request to the parent node of the faulty node;
[0022] If the skip request is successful, the child node is controlled to compare the historical synchronization content of the parent node of the faulty node according to the timestamp of the last request received to supplement the missing data content, and report the information that the faulty node cannot be connected to the master node;
[0023] If the bypass request fails, the process returns to the step of confirming that the node receiving the health heartbeat request is a faulty node, and controls the child node to bypass the health heartbeat request and send it to the parent node of the faulty node, so as to continue requesting the health heartbeat from the superior node until the request reaches the master node.
[0024] Preferably, when requesting the health heartbeat from the master node, the method further includes:
[0025] Setting the parent node corresponding to the child node to an abnormal state to mark it as the faulty node;
[0026] Delete the faulty node and re-establish a new red-black tree.
[0027] Preferably, it also includes:
[0028] If the root node does not receive the health heartbeat of the master node within a preset time, a health heartbeat request is sent to the master node through the root node;
[0029] If the request is confirmed to be successful, data synchronization is performed;
[0030] If the confirmation request is unsuccessful, information about the master node failure is sent to all the nodes through the root node, so that each of the nodes becomes a free node and the red-black tree is rebuilt.
[0031] Preferably, it also includes:
[0032] When all the nodes complete data synchronization, information indicating that data synchronization is complete is output.
[0033] To solve the above technical problems, the present application also provides a node data synchronization device, comprising:
[0034] Acquisition module, used to obtain all nodes;
[0035] A construction module, configured to determine a main node among the nodes and construct a red-black tree based on the remaining nodes; wherein the red-black tree includes a root node and child nodes under the root node;
[0036] A communication module, configured to establish a communication connection between the master node and the root node;
[0037] A first sending module, configured to send communication content to the root node via the master node;
[0038] The second sending module is used to send the communication content to each of the child nodes under the root node through the root node, so as to transmit the communication content to the corresponding new child node when each of the child nodes serves as a parent node, so as to achieve data synchronization of all the nodes.
[0039] To solve the above technical problems, the present application also provides another node data synchronization device, including:
[0040] memory for storing computer programs;
[0041] A processor is used to implement the steps of the node data synchronization method described above when executing the computer program.
[0042] In order to solve the above technical problems, the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the node data synchronization method described above are implemented.
[0043] The node data synchronization method provided in the present application obtains all nodes; determines the master node among the nodes, and constructs a red-black tree based on the remaining nodes; wherein the red-black tree contains a root node and each child node under the root node; establishes a communication connection between the master node and the root node; sends the communication content to the root node through the master node; sends the communication content to each child node under the root node through the root node, so that when each child node serves as a parent node, the communication content is transmitted to the corresponding new child node, so as to achieve data synchronization of all nodes. It can be seen that the above scheme changes the communication mode of the master and slave nodes from star communication to tree communication. By utilizing the dynamic balance mechanism of the red-black tree, the pressure of communication is transferred from the master node to as many child nodes as possible, ensuring the stability of the core services provided by the master node. By utilizing the characteristic that the tree level nodes increase by 2n, the size of the communication link can still be controlled while the nodes are increasing, thereby ensuring the communication efficiency.
[0044] In addition, an embodiment of the present application also provides a node data synchronization device and a computer-readable storage medium, with the same effects as above. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0046] Figure 1 A flowchart of a node data synchronization method provided in an embodiment of the present application;
[0047] Figure 2 A schematic diagram of a communication tree provided in an embodiment of the present application;
[0048] Figure 3 A schematic diagram of a communication tree slave node failure provided in an embodiment of the present application;
[0049] Figure 4 A schematic diagram of a repaired communication tree provided in an embodiment of the present application;
[0050] Figure 5 A schematic diagram of a communication tree master node failure provided in an embodiment of the present application;
[0051] Figure 6 A schematic diagram of the structure of a node data synchronization device provided in an embodiment of the present application;
[0052] Figure 7 A schematic structural diagram of another node data synchronization device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0054] The core of this application is to provide a node data synchronization method, device and computer-readable storage medium.
[0055] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0056] Figure 1 This is a flowchart of a node data synchronization method provided in an embodiment of the present application. Figure 1 As shown, the node data synchronization method includes:
[0057] S10: Get all nodes.
[0058] S11: Determine the main node among the nodes, and construct a red-black tree based on the remaining nodes. The red-black tree includes a root node and each child node under the root node.
[0059] S12: Establish a communication connection between the master node and the root node.
[0060] S13: Send the communication content to the root node through the master node.
[0061] S14: Send the communication content to each child node under the root node through the root node, so that when each child node serves as a parent node, the communication content is transmitted to the corresponding new child node to achieve data synchronization of all nodes.
[0062] It is understandable that in the process of communicating with multiple service nodes, in order to solve the problem that the traditional master-slave synchronous communication method often adopts a star structure, that is, all nodes synchronize data directly from the master node; when there are many service nodes, it often puts greater performance and bandwidth pressure on the master node. In this embodiment, a master-slave node tree-shaped node communication solution based on a red-black tree is proposed. The red-black tree is a data structure used in computer science. It is a specialized AVL tree (balanced binary tree). It maintains the balance of the binary search tree through specific operations when performing insertion and deletion operations, thereby achieving higher search performance. Although it is complex, it is efficient in practice and can perform searches, insertions, and deletions in O(log n) time, where n is the number of elements in the tree. Furthermore, a red-black tree is a binary search tree in which each node has a color attribute and has the following characteristics: nodes are either red or black; the root node is black; all leaves are black (leaves are NIL nodes); both children of each red node are black, meaning that no path from each leaf to the root can have two consecutive red nodes; and all paths from any node to each of its leaves contain the same number of black nodes. These restrictions constrain the key properties of a red-black tree. Furthermore, because a red-black tree is a specialized binary search tree, read-only operations on it are the same as those on a normal binary search tree.
[0063] Therefore, based on the red-black tree structure, this embodiment first obtains all service nodes and prepares to establish a master-slave relationship. Once the service master-slave election is complete, the master node is determined. Unlike traditional star-shaped communication, which directly establishes connections between the master node and each child node, this embodiment uses the unique node identifiers of the remaining nodes as tree node keys to construct a red-black tree. A connection is then established between the master node and the root node of the red-black tree, completing the complete communication tree. Figure 2 Schematic diagram of the communication tree provided in the embodiment of the present application. Figure 2 As shown in the figure, the red-black tree composed of the master node and the remaining nodes together forms a communication tree. As can be seen in the figure, node 8 is the master node, node 4 is the root node of the red-black tree, and the remaining nodes are child nodes under the root node of the red-black tree. Node 8 establishes a communication connection with node 4, that is, a communication connection is established between the master node and the root node.
[0064] Furthermore, when the master node initiates data synchronization communication, it sends the communication content to the root node. The root node receives the communication content from the master node and initiates communication with its child nodes. Subsequent nodes, upon receiving the message, repeat the root node's operation until all nodes have received the message content. It should be noted that the specific communication content of node communications is not restricted in this embodiment and depends on the specific implementation.
[0065] In this embodiment, all nodes are obtained; the master node among the nodes is determined, and a red-black tree is constructed based on the remaining nodes; wherein the red-black tree includes a root node and each child node under the root node; a communication connection is established between the master node and the root node; the communication content is sent to the root node through the master node; the communication content is sent to each child node under the root node through the root node, so that when each child node serves as a parent node, the communication content is transmitted to the corresponding new child node, thereby achieving data synchronization of all nodes. It can be seen that the above scheme changes the communication mode of the master-slave node from star communication to tree communication. By utilizing the dynamic balance mechanism of the red-black tree, the pressure of communication is transferred from the master node to as many child nodes as possible, ensuring the stability of the core service provided by the master node. By utilizing the characteristic that the tree level nodes increase by 2n, the size of the communication link can still be controlled while the nodes are increasing, thereby ensuring the communication efficiency.
[0066] Based on the above embodiment:
[0067] As a preferred embodiment, sending the communication content to the root node through the master node includes:
[0068] Generate communication content including message ID, timestamp, communication tree identifier, communication tree information and communication path in the master node, and send the communication content to the root node;
[0069] Among them, the communication path has added the node ID of the master node.
[0070] In the above embodiment, there is no limitation on the specific communication content. As a preferred embodiment, the communication content includes a unified communication header, which includes a message ID, a timestamp, a communication tree identifier, communication tree information, and a communication path.
[0071] The message ID is a unique ID for a message, generated by the master node. The message content remains unchanged when it is subsequently transmitted between nodes. The timestamp is the timestamp of the message generation, which is consistent with the message ID and generated by the master node. The communication tree identifier is a unique identifier for the communication tree. If the communication tree structure changes, the communication tree identifier will also change. The purpose of communication tree information is to ensure that all nodes initiate communications with their own child nodes according to the communication tree during the communication content transmission process. In other words, each node clearly understands its position in the communication tree and thus synchronizes data. The communication path refers to the message transmission path, which is initiated by the master node. Each time a node passes through, the node adds its node number, ultimately forming a communication path.
[0072] Therefore, in this embodiment, when the master node sends communication content to the root node, communication content including a message ID, a timestamp, a communication tree identifier, communication tree information and a communication path is generated in the master node. The communication path is added with the node ID of the master node, thereby sending the communication content to the root node.
[0073] In this embodiment, the communication content between nodes includes message ID, timestamp, communication tree identifier, communication tree information and communication path, thereby achieving complete synchronization of data.
[0074] Based on the above embodiment:
[0075] As a preferred embodiment, before sending the communication content to each child node under the root node through the root node, the method further includes:
[0076] Determine whether the root node has child nodes;
[0077] If so, the process proceeds to the step of sending the communication content to each child node under the root node through the root node, and adding the node ID of the root node to the communication path.
[0078] As you can understand, a red-black tree is a tree structure consisting of a root node and its child nodes. However, in some cases, a red-black tree has only one root node and no child nodes. Therefore, before the root node can communicate with its child nodes, it must first determine whether the root node has any child nodes.
[0079] In practice, the root node receives the communication content from the master node and examines the communication tree. If it has any child nodes, it forwards the message, sending the communication content to the next child node. Before sending, it adds its node ID to the communication path of the communication content, leaving all other content unchanged. Finally, it initiates communication with its child node.
[0080] In this embodiment, before sending the communication content to the child nodes under the root node through the root node, it is determined whether the root node has child nodes; if so, the communication content is sent to the child nodes under the root node through the root node, and the node ID of the root node is added to the communication path, thereby realizing data synchronization of each node of the red-black tree.
[0081] During the service operation process, due to various situations such as network fluctuations, excessive service load, hardware abnormalities, etc., a single node in the communication tree may become abnormal and unable to operate normally. In order to locate abnormal nodes and perform abnormal recovery, a health check function is built into the communication module of each node. Regarding the above communication process, two levels of problems may occur in actual use, namely: slave node failure and master node failure. Therefore, as a preferred embodiment, it also includes:
[0082] If the child node does not receive the health heartbeat of the corresponding parent node within the preset time, the child node sends a health heartbeat request to the corresponding parent node;
[0083] If the request is confirmed to be successful, the child node is controlled to compare the historical synchronization content of the parent node based on the timestamp of the last request received to supplement the missing data content;
[0084] If the confirmation request is unsuccessful, the node that receives the health heartbeat request is confirmed to be a faulty node, and the child node is controlled to skip and send the health heartbeat request to the parent node of the faulty node;
[0085] If the skip request is successful, the control child node compares the historical synchronization content of the parent node of the faulty node based on the timestamp of the last request received to supplement the missing data content, and reports to the master node that the faulty node cannot connect;
[0086] If the bypass request fails, it returns to the step of confirming that the node receiving the health heartbeat request is a faulty node, and controls the child node to bypass and send the health heartbeat request to the parent node of the faulty node, so as to continue requesting the health heartbeat from the superior node until the request reaches the master node.
[0087] Figure 3 This is a schematic diagram of a communication tree slave node failure provided in an embodiment of the present application. Figure 3 As shown in the figure, for example, a cluster consisting of 10 nodes experiences a fault at some point. If node 9 fails to receive a new health heartbeat from parent node 6 within a predetermined communication interval, a health check will be initiated: node 9 will attempt to establish a connection with parent node 6 and proactively request a health heartbeat. It's important to note that health heartbeats are a form of communication and generally don't convey specific service information; they simply check the node's health.
[0088] If the request succeeds, it indicates that node 6 is experiencing intermittent network fluctuations and is not experiencing a fault. Data synchronization within this phase is performed, and the health check is complete. Data synchronization within a phase involves incrementally synchronizing missing data by comparing the parent node's historical synchronization content with the timestamp of the last request received.
[0089] If the request fails, it means that node 6 is in an abnormal state and is a faulty node; node 9 will try to bypass the node 6's parent node 4 to request it.
[0090] If the skip request succeeds, data synchronization for this phase will begin. Node 9 will report this health check to the master node, including information about unreachable nodes along the path. Nodes 4 and 9 will then establish a temporary joint connection. After a new message arrives, if the communication tree identifier remains unchanged, Node 4 will send additional communication content to the temporarily connected Node 9.
[0091] If the skip request fails, the health status request will be continued upward until the request reaches the primary node.
[0092] In this embodiment, when a child node fails to receive a health heartbeat from its parent node for an extended period, it sends a health request to the parent node. If the request to the parent node fails, a bypass request is made until the request reaches the master node. This ensures normal data synchronization among nodes in the communication tree.
[0093] Based on the above embodiment:
[0094] As a preferred embodiment, when requesting a health heartbeat from the master node, the following is also included:
[0095] Set the parent node corresponding to the child node to an abnormal state to mark it as a faulty node;
[0096] Delete the faulty node and rebuild a new red-black tree.
[0097] It is understandable that in Figure 3 When child node 9 requests the health heartbeat to the master node 8, the master node 8 receives the message from node 9 and learns that node 6 has failed, so it sets node 6 to an abnormal state. Figure 4 This is a schematic diagram of a repaired communication tree provided in an embodiment of the present application. Figure 4 As shown, when the message is transmitted next time, the red-black tree algorithm is used to delete the faulty node 6 and a new communication tree is established to ensure normal data transmission. At this time, the recovery process of the single slave node failure is completed.
[0098] In this embodiment, when a slave node fails, the master node sets the failed node to an abnormal state, marks it as a failed node, deletes the failed node, and re-establishes a new red-black tree, thereby achieving normal data synchronization.
[0099] In the above embodiment, the process of handling a communication tree slave node failure is described in detail. Furthermore, this embodiment handles a communication tree master node failure. Therefore, as a preferred embodiment, the following is also included:
[0100] If the root node does not receive the health heartbeat of the master node within the preset time, it sends a health heartbeat request to the master node through the root node;
[0101] If the request is confirmed to be successful, data synchronization is performed;
[0102] If the confirmation request is unsuccessful, the information about the master node failure is sent to all nodes through the root node, so that each node becomes a free node and the red-black tree is rebuilt.
[0103] Figure 5 This is a schematic diagram of a communication tree master node failure provided in an embodiment of the present application. Figure 5As shown, taking a cluster of 10 nodes as an example, the master node 8 of the communication tree fails. The root node 4 of the red-black tree fails to obtain the health heartbeat of the master node 8 within the preset time and enters the health check state.
[0104] Node 4 actively initiates a health check to the master node 8 and sends a health heartbeat request; if the request is successful, data synchronization is performed and the health check ends.
[0105] If the request fails, root node 4 will directly initiate a special broadcast to all nodes, announcing that master node 8 has failed. All nodes will then become free nodes from slave nodes, and a new master-slave election will begin. After the election is complete, the red-black tree is rebuilt, a new master node is generated among the service nodes, and service returns to normal.
[0106] In this embodiment, if the root node doesn't receive a health heartbeat from the master node within a preset time, it sends a health heartbeat request to the master node through the root node. If the request is confirmed to be successful, data synchronization is performed. If the confirmation request is unsuccessful, the root node sends a message indicating the master node failure to all nodes, causing each node to become a free node and rebuild the red-black tree. This allows the master node failure of the communication tree to be repaired, ensuring normal data synchronization between nodes.
[0107] Based on the above embodiment:
[0108] As a preferred embodiment, the present invention further comprises:
[0109] When all nodes complete data synchronization, the information indicating that data synchronization is complete is output.
[0110] As a preferred embodiment, after each node of the communication tree completes data synchronization once, information indicating that data synchronization is completed is output to prompt the user that data synchronization is completed, so that the user can perform subsequent related operations, including but not limited to maintaining the communication tree nodes, changing the communication tree structure or adding communication tree node operations. There is no restriction in this embodiment and it depends on the specific implementation situation.
[0111] In the above embodiments, the node data synchronization method is described in detail. This application also provides corresponding embodiments of the node data synchronization device. It should be noted that this application describes the embodiments of the device from two perspectives: one is based on the functional module perspective, and the other is based on the hardware structure perspective.
[0112] Figure 6 This is a schematic diagram of the structure of a node data synchronization device provided in an embodiment of the present application. Figure 6 As shown, the node data synchronization device includes:
[0113] An acquisition module 10 is used to acquire all nodes;
[0114] A construction module 11 is used to determine a main node among the nodes and construct a red-black tree based on the remaining nodes; wherein the red-black tree includes a root node and each child node under the root node;
[0115] Communication module 12, used to establish a communication connection between the master node and the root node;
[0116] A first sending module 13 is configured to send communication content to a root node via a master node;
[0117] The second sending module 14 is used to send the communication content to each child node under the root node through the root node, so as to transmit the communication content to the corresponding new child node when each child node serves as a parent node, so as to achieve data synchronization of all nodes.
[0118] The node data synchronization device provided by the present application includes an acquisition module, a construction module, a communication module, a first sending module and a second sending module. By acquiring all the nodes; determining the main node among the nodes, and building a red-black tree based on the remaining nodes; wherein the red-black tree contains a root node and each child node under the root node; establishing a communication connection between the main node and the root node; sending the communication content to the root node through the main node; sending the communication content to each child node under the root node through the root node, so as to transmit the communication content to the corresponding new child node when each child node serves as a parent node, so as to achieve data synchronization of all nodes. It can be seen that the above scheme changes the communication mode of the master-slave node from star communication to tree communication. By utilizing the dynamic balance mechanism of the red-black tree, the pressure of communication is transferred from the main node to as many child nodes as possible, ensuring the stability of the core service provided by the main node. By utilizing the characteristic that the tree level nodes increase by 2n, the size of the communication link can still be controlled while the nodes are increasing, thereby ensuring the communication efficiency.
[0119] Figure 7 This is a structural diagram of another node data synchronization device provided in an embodiment of the present application. Figure 7 As shown, the node data synchronization device includes:
[0120] The memory 20 is used to store computer programs.
[0121] The processor 21 is configured to implement the steps of the node data synchronization method mentioned in the above embodiment when executing a computer program.
[0122] The node data synchronization device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer, or a desktop computer.
[0123] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of a digital signal processor (DSP), a field programmable gate array (FPGA), and a programmable logic array (PLA). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a central processing unit (CPU); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a graphics processing unit (GPU), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.
[0124] The memory 20 may include one or more computer-readable storage media, which may be non-transitory. The memory 20 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 20 is at least used to store the following computer program 201, wherein, after the computer program is loaded and executed by the processor 21, it can implement the relevant steps of the node data synchronization method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 202 may include Windows, Unix, Linux, etc. The data 203 may include but is not limited to data involved in the node data synchronization method.
[0125] In some embodiments, the node data synchronization device may also include a display screen 22 , an input and output interface 23 , a communication interface 24 , a power supply 25 , and a communication bus 26 .
[0126] Those skilled in the art will understand that Figure 7 The structure shown in does not constitute a limitation on the node data synchronization device, and may include more or fewer components than shown in the figure.
[0127] The node data synchronization device provided in the present application includes a memory and a processor. The processor is used to implement the steps of the node data synchronization method mentioned in the above embodiment when executing a computer program. By obtaining all nodes; determining the main node among the nodes, and building a red-black tree based on the remaining nodes; wherein the red-black tree contains a root node and each child node under the root node; establishing a communication connection between the main node and the root node; sending the communication content to the root node through the main node; sending the communication content to each child node under the root node through the root node, so as to transmit the communication content to the corresponding new child node when each child node serves as a parent node, so as to achieve data synchronization of all nodes. It can be seen from this that the above scheme changes the communication mode of the master-slave node from star communication to tree communication. By utilizing the dynamic balance mechanism of the red-black tree, the pressure of communication is transferred from the main node to as many child nodes as possible, ensuring the stability of the core service provided by the main node. By utilizing the characteristic that the tree level nodes increase by 2n, the size of the communication link can still be controlled to ensure the communication efficiency when the nodes increase.
[0128] Finally, the present application also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps described in the above method embodiment.
[0129] It is understandable that if the method in the above embodiment is implemented in the form of 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, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium and executes all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0130] The computer-readable storage medium provided by the present application stores a computer program, and when the computer program is executed by the processor, the steps described in the above method embodiment are implemented. By obtaining all nodes; determining the main node among the nodes, and building a red-black tree based on the remaining nodes; wherein the red-black tree contains a root node and each child node under the root node; establishing a communication connection between the main node and the root node; sending the communication content to the root node through the main node; sending the communication content to each child node under the root node through the root node, so as to transmit the communication content to the corresponding new child node when each child node serves as a parent node, so as to achieve data synchronization of all nodes. It can be seen from this that the above scheme changes the communication mode of the master-slave node from star communication to tree communication. By utilizing the dynamic balance mechanism of the red-black tree, the pressure of communication is transferred from the main node to as many child nodes as possible, ensuring the stability of the core service provided by the main node. By utilizing the characteristic that the tree level nodes increase by 2n, the size of the communication link can still be controlled to ensure the communication efficiency when the nodes increase.
[0131] The above is a detailed introduction to a node data synchronization method, device and computer-readable storage medium provided by the present application. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of this application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of this application.
[0132] It should also be noted that, in this specification, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus comprising the element.
Claims
1. A node data synchronization method, characterized in that: include: Get all nodes; Determine a main node among the nodes, and construct a red-black tree based on the remaining nodes, so as to utilize the dynamic balance mechanism of the red-black tree to transfer the communication pressure from the main node to each child node; wherein the red-black tree includes a root node and each child node under the root node; Establishing a communication connection between the master node and the root node; Sending communication content to the root node through the master node; The communication content is sent to each of the child nodes under the root node through the root node, so that when each of the child nodes serves as a parent node, the communication content is transmitted to the corresponding new child node, so as to achieve data synchronization of all the nodes; The sending of the communication content to the root node through the master node comprises: Generate the communication content including a message ID, a timestamp, a communication tree identifier, communication tree information and a communication path in the master node, and send the communication content to the root node; The communication path is newly added with the node ID of the master node; the communication path is a message transmission path, which is initiated by the master node and adds its own node number each time it passes through a node; Before sending the communication content to each of the child nodes under the root node through the root node, the method further includes: Determine whether the root node has the child node; If yes, proceed to the step of sending the communication content to each of the child nodes under the root node through the root node, and adding the node ID of the root node to the communication path; Also includes: If the child node does not receive the health heartbeat of the corresponding parent node within a preset time, a health heartbeat request is sent to the corresponding parent node through the child node; If the request is confirmed to be successful, the child node is controlled to compare the historical synchronization content of the parent node according to the timestamp of the last request received to supplement the missing data content; If the confirmation request is unsuccessful, confirm that the node receiving the health heartbeat request is a faulty node, and control the child node to skip the level and send the health heartbeat request to the parent node of the faulty node; If the skip-level request is successful, the child node is controlled to compare the historical synchronization content of the parent node of the faulty node according to the timestamp of the last request received to supplement the missing data content, and report to the master node that the faulty node cannot be connected; If the skip-level request fails, return to the step of confirming that the node receiving the health heartbeat request is a faulty node, and control the child node to skip the health heartbeat request to the parent node of the faulty node, so as to continue to request the health heartbeat from the superior node until the request reaches the master node; When requesting the health heartbeat from the master node, it also includes: Setting the parent node corresponding to the child node to an abnormal state to mark it as the faulty node; Deleting the faulty node and re-establishing a new red-black tree; Also includes: If the root node does not receive the health heartbeat of the master node within a preset time, a health heartbeat request is sent to the master node through the root node; If the confirmation request is successful, data synchronization is performed; If the confirmation request is unsuccessful, information about the failure of the main node is sent to all the nodes through the root node, so that each of the nodes becomes a free node and the red-black tree is rebuilt; Also includes: When all the nodes complete data synchronization, information indicating that data synchronization is completed is output.
2. A node data synchronization device, characterized in that: include: Acquisition module, used to obtain all nodes; A construction module is used to determine a main node among the nodes, and to construct a red-black tree based on the remaining nodes, so as to utilize the dynamic balance mechanism of the red-black tree to transfer the communication pressure from the main node to each child node; wherein the red-black tree includes a root node and each child node under the root node; A communication module, used to establish a communication connection between the master node and the root node; A first sending module, used for sending communication content to the root node through the master node; A second sending module, used to send the communication content to each of the child nodes under the root node through the root node, so as to transmit the communication content to the corresponding new child node when each of the child nodes serves as a parent node, so as to achieve data synchronization of all the nodes; The sending of the communication content to the root node through the master node comprises: Generate the communication content including a message ID, a timestamp, a communication tree identifier, communication tree information and a communication path in the master node, and send the communication content to the root node; The communication path is newly added with the node ID of the master node; the communication path is a message transmission path, which is initiated by the master node and adds its own node number each time it passes through a node; Before sending the communication content to each of the child nodes under the root node through the root node, the method further includes: Determine whether the root node has the child node; If yes, proceed to the step of sending the communication content to each of the child nodes under the root node through the root node, and adding the node ID of the root node to the communication path; Also includes: If the child node does not receive the health heartbeat of the corresponding parent node within a preset time, a health heartbeat request is sent to the corresponding parent node through the child node; If the request is confirmed to be successful, the child node is controlled to compare the historical synchronization content of the parent node according to the timestamp of the last request received to supplement the missing data content; If the confirmation request is unsuccessful, confirm that the node receiving the health heartbeat request is a faulty node, and control the child node to skip the level and send the health heartbeat request to the parent node of the faulty node; If the skip-level request is successful, the child node is controlled to compare the historical synchronization content of the parent node of the faulty node according to the timestamp of the last request received to supplement the missing data content, and report to the master node that the faulty node cannot be connected; If the skip-level request fails, return to the step of confirming that the node receiving the health heartbeat request is a faulty node, and control the child node to skip the health heartbeat request to the parent node of the faulty node, so as to continue to request the health heartbeat from the superior node until the request reaches the master node; When requesting the health heartbeat from the master node, it also includes: Setting the parent node corresponding to the child node to an abnormal state to mark it as the faulty node; Deleting the faulty node and re-establishing a new red-black tree; Also includes: If the root node does not receive the health heartbeat of the master node within a preset time, a health heartbeat request is sent to the master node through the root node; If the confirmation request is successful, data synchronization is performed; If the confirmation request is unsuccessful, information about the failure of the main node is sent to all the nodes through the root node, so that each of the nodes becomes a free node and the red-black tree is rebuilt; Also includes: When all the nodes complete data synchronization, information indicating that data synchronization is completed is output.
3. A node data synchronization device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the node data synchronization method as claimed in claim 1 when executing the computer program.
4. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the node data synchronization method according to claim 1 are implemented.
