Data synchronization method and terminal equipment based on distributed storage technology

By selecting leader nodes and cluster head nodes in a distributed system and optimizing the data synchronization path, the problem of low data synchronization efficiency in distributed systems is solved, and efficient and reliable data synchronization is achieved.

CN109189855BActive Publication Date: 2024-11-01SHANGHAI XURONG NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201810920950.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-08-14
Publication Date
2024-11-01
Estimated Expiration
2038-08-14

AI Technical Summary

Technical Problem

In distributed systems, data synchronization suffers from significant network resource consumption and low efficiency.

Method used

By selecting a leader node in the distributed node system, data is synchronized to the cluster head node, which then synchronizes the data to every distributed node within the cluster. This avoids other nodes in the system directly obtaining data from the leader node, thereby reducing network congestion and latency by distributing data access through the cluster.

Benefits of technology

It improves the efficiency and reliability of data synchronization, reduces the transmission energy and data load consumption of distributed nodes, and ensures that all nodes in the system can achieve data synchronization efficiently and quickly.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN109189855B_ABST
    Figure CN109189855B_ABST
Patent Text Reader

Abstract

The present invention is applicable to the field of data processing technology, and provides a data synchronization method, terminal equipment and computer-readable storage medium based on distributed storage technology, including: selecting a leader node with the earliest data update time and relatively complete data from all distributed nodes in a distributed node system, and then dividing the other distributed nodes in the system except the leader node into at least two clusters, and selecting a cluster head node in each cluster, synchronizing the data of the leader node to the cluster head node, and then the cluster head node synchronizes the data to other nodes in the cluster, thereby avoiding network congestion and data delay caused by other nodes in the system directly obtaining data from the leader node, reducing the transmission energy and data load consumption of the distributed nodes during data synchronization, and ensuring that all nodes in the system can achieve data synchronization efficiently and quickly.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of data processing technology, and in particular relates to a data synchronization method, a terminal device and a computer-readable storage medium based on distributed storage technology. Background Art

[0002] The birth of big data technology has brought new breakthroughs in the performance of computer systems, and supports hardware to expand horizontally to obtain linear growth in performance and storage, which are not available in the past traditional relational databases. In addition, big data technology has also abandoned the rigid requirement that the operating environment must be good enough, but allows users to build large-scale clusters by combining batches of cheap X86 servers with local disks, thereby obtaining stronger computing power and more storage space than the vertical expansion of hardware in the past. By breaking down a large task into multiple small tasks and then completing them through distributed concurrent operations, the computing efficiency or storage capacity of the entire system can be improved. In a distributed environment, due to the lower hardware requirements, big data products must provide higher service quality.

[0003] In the prior art, a piece of data is stored or processed in multiple machines or multiple distributed nodes in an asynchronous or synchronous manner to ensure data security and service quality. However, after solving the problem of service quality, the distributed data processing method introduces a new technical problem, that is, in the entire distributed system, the network resources consumed in the data synchronization process between distributed nodes are large, and the data synchronization efficiency is low. Summary of the invention

[0004] In view of this, an embodiment of the present invention provides a data synchronization method, a terminal device and a computer-readable storage medium based on distributed storage technology to solve the problem in the prior art that in the entire distributed system, the network resource consumption is large during the data synchronization process between distributed nodes and the data synchronization efficiency is low.

[0005] A first aspect of an embodiment of the present invention provides a data synchronization method based on distributed storage technology, including:

[0006] Selecting a leader node from all distributed nodes in the distributed node system; the leader node is used to synchronize the data stored in the leader node to the other distributed nodes;

[0007] Dividing all the distributed nodes except the leader node to obtain at least two clusters, and determining a cluster head node in each cluster;

[0008] The data of the leader node is synchronized to each of the cluster head nodes, and then the data in each cluster head node is synchronized to each of the distributed nodes in the cluster group.

[0009] A second aspect of an embodiment of the present invention provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:

[0010] Selecting a leader node from all distributed nodes in the distributed node system; the leader node is used to synchronize the data stored in the leader node to the other distributed nodes;

[0011] Dividing all the distributed nodes except the leader node to obtain at least two clusters, and determining a cluster head node in each cluster;

[0012] The data of the leader node is synchronized to each of the cluster head nodes, and then the data in each cluster head node is synchronized to each of the distributed nodes in the cluster group.

[0013] A third aspect of an embodiment of the present invention provides a computer-readable storage medium, wherein the computer storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes the method of the first aspect.

[0014] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:

[0015] The embodiment of the present invention first selects a leader node from all distributed nodes in the distributed node system, then divides the other distributed nodes in the system except the leader node into at least two clusters, and selects a cluster head node in each cluster. By synchronizing the data of the leader node to the cluster head node, and then the cluster head node synchronizes the data to other nodes in the cluster, network congestion and data delay caused by other nodes in the system directly obtaining data from the leader node are avoided, the transmission energy and data load consumption of the distributed nodes during data synchronization are reduced, and it is ensured that all nodes in the system can achieve data synchronization efficiently and quickly. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0017] Figure 1 is a flow chart of a data synchronization method based on distributed storage technology provided in Embodiment 1 of the present invention;

[0018] Figure 2 is a specific implementation flow chart of the data synchronization method S101 based on the distributed storage technology provided in the second embodiment of the present invention;

[0019] Figure 3 is a specific implementation flow chart of the data synchronization method S102 based on the distributed storage technology provided in the third embodiment of the present invention;

[0020] Figure 4 is a schematic diagram of a terminal device provided in Embodiment 4 of the present invention;

[0021] Figure 5 It is a schematic diagram of a terminal device provided in Embodiment 5 of the present invention. DETAILED DESCRIPTION

[0022] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present invention. However, it should be clear to those skilled in the art that the present invention may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present invention.

[0023] In order to illustrate the technical solution of the present invention, a specific embodiment is provided below for illustration.

[0024] See also Figure 1 , Figure 1 1 is a flow chart of a data synchronization method based on distributed storage technology provided in the first embodiment of the present invention. The execution subject of the data synchronization method based on distributed storage technology in this embodiment includes but is not limited to a computer, a server, a tablet computer or a terminal and other devices, all of which have a data synchronization function. Figure 1 The data synchronization method based on distributed storage technology shown may include the following steps:

[0025] In S101, according to a preset election mechanism, one distributed node is selected from all distributed nodes of the distributed node system as a leader node; the leader node is used to synchronize the data stored in itself to the other distributed nodes.

[0026] A distributed system is a software system built on a network, which has a high degree of cohesion and transparency. Therefore, the difference between a network and a distributed system lies more in the high-level software, which has a high degree of cohesion and transparency. Each database distribution node in a distributed system is highly autonomous and has a local database management system. Moreover, each database distribution node is transparent to the user's application, and it is not clear whether it is local or remote. In a distributed database system, users do not feel that the data is distributed, that is, users do not need to know whether the relationship is split, whether there are copies, which site the data is stored on, and which site the transaction is executed on, etc.

[0027] In a distributed system, a group of independent computers present a unified whole to the user, as if it were a system. The system has a variety of common physical and logical resources, can dynamically allocate tasks, and the dispersed physical and logical resources exchange information through a computer network. There is a distributed operating system in the system that manages computer resources in a global manner. Usually, for users, there is only one model or paradigm for a distributed system. There is a layer of software middleware on top of the operating system that is responsible for implementing this model. A famous example of a distributed system is the World Wide Web, where everything looks like a document page.

[0028] In the distributed system of this embodiment, the central node is composed of one or more computers, data is centrally stored in this central node, and all business units of the entire system are centrally deployed on this central node, and all functions of the system are centrally processed by it. There is no master-slave distinction between computers in the distributed system, there is neither a host that controls the entire system nor a slave that is controlled, and all computer nodes that make up the distributed system are equal.

[0029] Furthermore, in order to provide highly available services to the outside world, data and services are replicated, and the same data is persisted on different distributed nodes. When the data stored on a distributed node is lost, the data can be read from the replica to solve the problem of data loss in the distributed system. In this embodiment, the modified service replica is used to indicate that multiple distributed nodes provide the same service, and each distributed node has the ability to accept requests from the outside and perform corresponding processing. At the same time, multiple distributed nodes in the same distributed system may concurrently operate some shared resources, such as databases or distributed storage.

[0030] Data synchronization in a distributed system is a huge challenge. If we only look at the physical timestamp, we cannot determine which version of the data is the latest, because we cannot ensure that the physical clocks of all entities are perfectly synchronized. For example, two synchronized servers write timestamps to the same system. If a server is slow by even a few milliseconds, it will soon lose the ability to know the true order of events. In order to solve this problem, in this embodiment, an election mechanism is used to select a distributed node from all distributed nodes in the distributed node system as a leader node, so that the data stored in the leader node itself can be synchronized to the other distributed nodes through the leader node.

[0031] It should be noted that since data synchronization in a distributed system requires the latest and most comprehensive data to be synchronized to all distributed nodes in the system, when selecting a leader node, we can measure the data update time and data comprehensiveness of each distributed node, and select the distributed node with the earliest update time and more complete data as the leader node. The data update time can be used as a logical clock to indicate the version of an event in a distributed system or the update time of the data. By viewing these ordered sets, the data logic in the system can be determined, which data is the latest, and which events are concurrent. After that, the distributed node corresponding to the latest data can be determined and this distributed node can be determined as the leader node.

[0032] Furthermore, in order to prevent the leader node from malfunctioning when a leader node is selected, so that the data of the leader node cannot be synchronized to other nodes in the network, in this embodiment, a lease is issued to a node through the central control node, indicating that the node can work as a leader node for a preset period of time. When a problem is found in the leader node, it is only necessary to wait until the lease of the leader node expires, and a new lease can be safely issued to the new leader node without the "dual master" problem. In actual applications, if a central control node is used as a configuration center to send a lease, there is also a great risk. Therefore, multiple central control nodes are used as copies of each other to form a small cluster. The small cluster has high availability and provides the function of issuing leases to the outside world.

[0033] In S102, all the distributed nodes except the leader node are divided to obtain at least two clusters, and a cluster head node in each cluster is determined.

[0034] After the leader node is determined, the data in its storage space can be sent to other distributed nodes in the distributed system through the leader node. However, if the leader node directly sends data to each distributed node, it will consume more memory and energy of the leader node, causing delays in the operation of the leader node itself. Considering this situation, in this embodiment, the distributed nodes other than the leader node in the distributed system are divided into clusters. The number of clusters can be two or more.

[0035] Since each distributed node in a distributed system has its own attributes and each distributed node needs to process events independently, the distributed nodes can be divided according to their attributes to determine the node members of each cluster.

[0036] Specifically, each distributed node in the distributed system can be numbered, and each distributed node has a unique ID. At the same time, the data access volume of the distributed node per unit time is measured, and the distributed nodes in the same interval are divided into the same cluster by setting a certain numerical segmentation interval. By dividing the clusters in this way of data access volume, distributed nodes with smaller or larger data access volumes can be placed in the same cluster. Then, through data load diversion, less bandwidth or network resources can be allocated to clusters with smaller data access volumes, and more network resources can be allocated to clusters with larger data access volumes, so as to provide a good data exchange environment and ensure that data in the distributed system can complete data synchronization efficiently and reliably.

[0037] After the distributed nodes in the distributed system are divided into clusters, a distributed node needs to be selected in each cluster as the cluster head node, so that the data of the leader node can be transmitted to the distributed nodes in the cluster through the cluster head node. Therefore, the selection of this cluster head node also determines the efficiency and accuracy of data synchronization.

[0038] In a cluster, the cluster head node is responsible for receiving synchronization data from the leader node, and then sending this data to all distributed nodes in the cluster. Therefore, the cluster head node has a higher data sending and receiving task, and requires more memory support and bandwidth support. In this embodiment, whether a distributed node is suitable to be a cluster head node is measured by determining the busyness of each distributed node in the process, the resources required to receive the leader node data, and the resources required to send data.

[0039] Specifically, when measuring whether a distributed node can become a cluster head node, determine the busyness of the distributed node and the total amount of resource consumption value when the node sends data to any distribution time in the cluster, and select the distributed node with lower busyness and total resource consumption value as the cluster head node.

[0040] In S103, the data of the leader node is synchronized to each of the cluster head nodes, and then the data in each cluster head node is synchronized to each of the distributed nodes in the cluster group.

[0041] After determining the leader node and the cluster head node of each cluster, the leader node synchronizes the data to each cluster head node, and then each cluster head node synchronizes the data to each distributed node in the cluster. After receiving the data, the nodes in the cluster overwrite the data in their own memory based on the data.

[0042] Specifically, after the cluster head node is determined in a cluster, the cluster head node sends its own node identifier and cluster group identifier to the leader node. After receiving the identifier, the leader node determines that the node corresponding to the node identifier is the cluster head node in the cluster corresponding to the cluster group identifier. The leader node sends data to the cluster head node. After receiving the data, the cluster head node sends a data reception success message to the leader node and broadcasts the data to other distributed nodes in the cluster at the same time. After receiving the broadcast data, the distributed nodes in the cluster can send a synchronization success message to the cluster head node.

[0043] Furthermore, after receiving the broadcast data, the distributed nodes in the cluster can also send synchronization success information to the leader node. In the distributed system of this embodiment, each distributed node has the node information of the entire system. The leader node checks the distributed nodes that have not been synchronized successfully based on the node information and synchronization success information, and directly sends data to the node for synchronization.

[0044] It should be noted that, in this embodiment, the data synchronization time of the distributed nodes in the distributed system can be fixed, periodic, or can be real-time data synchronization by receiving instructions from the control system, which is not limited here. Since the data logic in the distributed system will change during execution and the synchronization time is uncertain, it is necessary to reselect the leader node, divide the clusters, and select the cluster head node of each cluster each time data synchronization is performed. In this way, it can be ensured that the distributed nodes can select a reasonable leader node in each synchronization process, thereby improving the reliability and applicability of node data synchronization.

[0045] In actual applications, if a distributed node fails, data cannot be passed quickly. In order to solve the problem of single point failure, we add a backup node for each node. When a node fails, it automatically switches to the backup node, similar to the master and slave of the database. However, it still cannot solve the problem of hash redistribution after adding or deleting nodes, that is, it is impossible to dynamically add or delete nodes. At this time, the concept of consistent hashing is introduced, which distributes all nodes to a hash ring. Each request falls at a certain position on this hash ring. The first node you find in a clockwise direction is the service node you need. When a node fails, you only need to find the next available node on the ring.

[0046] Furthermore, after step S103, the following steps may be further included:

[0047] Detecting whether the data of each of the distributed nodes is consistent;

[0048] If the data of each of the distributed nodes is consistent, the cluster head node sends a synchronization success message to the leader node;

[0049] If the data of each of the distributed nodes is inconsistent, the distributed node that fails to synchronize is determined, and the data of the leader node is synchronized to the distributed node that fails to synchronize.

[0050] Specifically, after all nodes in the distributed system have completed data synchronization, there may be nodes that fail to synchronize. Taking this situation into consideration, we first detect whether the data of each distributed node is consistent. If the data is consistent, it means that all distributed nodes have successfully synchronized their data, and the cluster head node sends a synchronization success message to the leader node. If the data of each distributed node is inconsistent, it means that there are nodes that fail to synchronize their data. By determining the distributed nodes that fail to synchronize, and sending the data of the leader node directly to the distributed nodes that fail to synchronize, data synchronization of all nodes in the distributed system is achieved.

[0051] The above scheme selects a leader node from all distributed nodes in the distributed node system, divides the other distributed nodes in the system except the leader node into at least two clusters, and selects a cluster head node in each cluster. By synchronizing the data of the leader node to the cluster head node, and then the cluster head node synchronizes the data to other nodes in the cluster, network congestion and data delay caused by other nodes in the system directly obtaining data from the leader node are avoided, the transmission energy and data load consumption of distributed nodes during data synchronization are reduced, and it is ensured that all nodes in the system can achieve data synchronization efficiently and quickly.

[0052] See also Figure 2 , Figure 2 This is a specific implementation flow chart of the data synchronization method S101 based on distributed storage technology provided in the second embodiment of the present invention. The execution subject of the data synchronization method based on distributed storage technology in this embodiment includes but is not limited to computers, servers, tablet computers or terminals and other devices, all of which have data synchronization functions. Figure 2 The data synchronization method based on distributed storage technology shown may include the following steps:

[0053] In S201, it is detected whether each distributed node in the distributed node system has received information from the cluster head node in its cluster group. If not, an instruction for re-voting and electing a leader node is sent to each distributed node.

[0054] Before selecting a leader node in the distributed system of this embodiment, first detect whether there is a leader node in the system. The specific detection method is to detect whether each of the distributed nodes in the distributed node system has received information from the cluster head node in the cluster group. If not, it means that there is no leader node in the current distributed system that sends data to the cluster head node. The cluster head node or the leader node may have been paralyzed, so the cluster group node cannot receive data from the cluster head node. In this case, it is necessary to re-select the leader node and its subordinate cluster head nodes to control each node in the distributed system to initiate voting.

[0055] The specific voting method is to set a waiting time in each distributed node in the distributed system, control the candidate to initiate voting invitations to other nodes, so that the remaining distributed nodes in the network vote for the node. If the node obtains the highest number of votes, the node is identified as the leader node. In the distributed network of this embodiment, an instruction to re-vote and elect a leader node is sent to each distributed node to control each distributed node to initiate voting and become a leader node through election. In this embodiment, the leader node has a function: within a preset time period, it is responsible for data synchronization between all nodes.

[0056] Furthermore, in order to avoid all distributed nodes in the distributed system from initiating elections at the same time, the time for initiating elections is staggered. During each node's own waiting time, the node must wait patiently, and only after this period of time can it initiate elections and strive to become the master node.

[0057] For example, the time for each distributed node to initiate voting is determined by a timer, and the waiting time of node A is set to 100ms, the waiting time of node B is set to 200ms, and the waiting time of node C is set to 300ms. Everyone's timer starts from 0, and node A has the shortest waiting time. After 100ms, it takes the lead in initiating the election and casts a vote for itself. Since the waiting time of nodes B and C has not expired, they have to vote for node A. At the current moment, node A has a total of 3 votes, and node A becomes the leader node. Everyone resets their timer to 0, and node A can continue to initiate voting and continue to serve as the master node next time.

[0058] Furthermore, if Node A fails and cannot vote, it will not be able to initiate the election after 100ms, and Node B can initiate the election after 200ms and vote for itself. Node C can only vote for Node B, so Node B has 2 votes at the current moment, and Node B can be the leader node. If Node C fails and cannot vote, Node A and Node B will take turns in the election.

[0059] In S202, the distributed node with the largest number of votes is identified as the leader node.

[0060] As described above, after each normal distributed node in the distributed system votes, the number of votes of each distributed node is counted, and the distributed node with the most votes is determined as the leader node. By determining the distributed node with the highest number of votes as the leader node, the node can have a higher authority in the distributed system to send data to the cluster head node of the next layer, ensuring that the nodes in the distributed system have a stable hierarchical structure and can accurately synchronize data.

[0061] In S203, leader node information is generated, and the leader node information is sent to each of the distributed nodes.

[0062] After the leader node is determined in the distributed system, the leader node information is generated according to the node identifier of the leader node, and the leader node information is sent to each distributed node in the distributed system.

[0063] Furthermore, in order to avoid memory and network load consumption caused by sending data to each distributed node, considering that in this embodiment, the leader communicates data directly with the cluster head node without involving other nodes in the system, it is also possible to send leader node information only to the cluster head node in the distributed system, thereby reducing the objects of data communication, allowing the cluster head node of each cluster group to obtain the information of the leader node in the distributed system and receive the data that needs to be synchronized, thereby reducing redundant communications and network load in the system and improving the efficiency of data synchronization.

[0064] The above scheme detects whether the distributed nodes in the distributed node system have received information from the cluster head node in the cluster group, and instructs each distributed node to vote if it has not received the information, and selects the distributed node with the most votes as the leader node, generates leader node information, and sends the leader node information to each distributed node. By each distributed node in the distributed system participating in the voting to elect the leader node, the authority and credibility of the leader node among all distributed nodes are guaranteed, and the data of the leader node is synchronized to all distributed nodes in the distributed system, thereby improving the reliability of distributed node data synchronization.

[0065] See also Figure 3 , Figure 3 This is a specific implementation flow chart of the data synchronization method S102 based on distributed storage technology provided in the third embodiment of the present invention. The execution subject of the data synchronization method based on distributed storage technology in this embodiment includes but is not limited to computers, servers, tablet computers or terminals and other devices, all of which have data synchronization functions. Figure 3 The data synchronization method based on distributed storage technology shown may include the following steps:

[0066] In S301, all the distributed nodes except the leader node in the distributed node system are divided into uniform clusters, each of which contains the same number of distributed nodes.

[0067] After determining the leader node in the distributed system, the other distributed nodes except the leader node are divided into clusters. In this embodiment, all distributed nodes are divided into uniform clusters so that each cluster contains distributed nodes with the same amount of data to ensure the equality of each cluster and the stability of data transmission.

[0068] Furthermore, when it is impossible to ensure an even distribution of the number of nodes in a distributed system, for example, when there is a remainder after dividing the number of nodes in the network by the number of clusters, these remaining nodes are dispersed among the clusters so that the number of nodes in the clusters with a larger number of nodes and the clusters with a smaller number of nodes differs by only one node. This method can take into account the imbalance of the number of nodes in the distributed system and ensure a stable and relatively balanced number of nodes between clusters.

[0069] In S302, the cluster head node of each cluster is determined according to the node characteristics of the distributed nodes in each cluster.

[0070] After the clusters in the distributed system are determined, the cluster head node of each cluster is determined according to the node characteristics of the distributed nodes in each cluster.

[0071] Furthermore, in S302 of this embodiment, S3021 to S3024 may be specifically included:

[0072] In S3021, according to the transmission attributes of the leader node and each of the distributed nodes in the network, the leader node and each of the distributed nodes are coordinateized to obtain the coordinates of the distributed node i as (x i ,y i ), the coordinates of the leader node are (x Leader ,y Leader ).

[0073] In a distributed system, each node has its own corresponding function, and each node is connected through a certain communication method to complete the entire data processing task. According to the connection method of the distributed nodes in the distributed system, the coordinates of each distributed node are determined, and the coordinates of the distributed node i are obtained as (x i ,y i ), the coordinates of the leader node are (x Leader ,y Leader ).

[0074] In S3022, according to the coordinates of the leader node and the coordinates of each of the distributed nodes, the distance between the distributed nodes in the cluster and the leader node is calculated by the following formula:

[0075]

[0076] After the coordinates of the leader node and each distributed node are determined, the distance between each distributed node and the leader node is calculated to measure the amount of network resources consumed by data communication between each distributed node and the leader node in the distributed system, the efficiency of data transmission, etc. In this embodiment, the gap between the two nodes is determined by calculating the Euclidean distance between the distributed node and the leader node.

[0077] Furthermore, the Manhattan distance can be calculated by the following formula to determine the distance between the two:

[0078] Range(i)=|x i -x Leader |+|y i -y Leader |.

[0079] In addition, you can also calculate Minkowski distance, standardized Euclidean distance, Mahalanobis distance, etc. By calculating the distance between the two, the communication cost between each distributed node and the leader node is measured.

[0080] In S3023, the cluster head weight of the distributed node is calculated by the following formula: E(i)=n·Expen(i)+m·Range(i);

[0081] Wherein, Expen(i) is used to represent the energy consumption required for synchronizing the data of the distributed node i to each distributed node in the cluster to which it belongs; n and m are used to represent preset parameter constants, and m+n=1.

[0082] In this embodiment, the total energy consumption of each node in the cluster sending data to other nodes during data synchronization is determined to measure the communication cost of data transmission within the cluster. At the same time, the distance between the distributed node and the leader node is used to measure the communication cost between the leader node and the distributed node outside the cluster, and the weight of the two values ​​is determined. The weight of each distributed node becoming the cluster head node is determined by the formula E(i)=n·Expen(i)+m·Range(i).

[0083] It should be noted that, in this embodiment, n and m are used to represent preset parameter constants. These two data values ​​are obtained through multiple experimental calculations and satisfy m+n=1.

[0084] In S3024, the distributed node with the largest cluster head weight is identified as the cluster head node.

[0085] After determining the cluster head weight of each distributed node in the cluster group, determine the distributed node with the largest cluster head weight as the cluster head node. By using the distributed node with the largest cluster head weight as the cluster head node, it can be ensured that the cluster head node receives the data of the leader node and synchronizes it to other distributed nodes in the cluster, ensuring the reliability and efficiency of data transmission.

[0086] The above scheme first coordinates the leader node and each distributed node in the distributed system according to the transmission properties and connection methods of the system to obtain the coordinates of each node, and then calculates the distance between each node and the leader node based on the coordinates. At the same time, based on the energy consumption and network resources required for each distributed node in the cluster to transmit its data to other nodes, the cluster head weight of the distributed node in the cluster to become the cluster head node is determined, and the distributed node with the largest cluster head weight is determined to become the cluster head node in the cluster, so that the cluster head node can efficiently and reliably receive the data of the leader node, and transmit this data to other distributed nodes in the cluster. On the premise of reducing data transmission overhead and network load, the efficiency and reliability of data synchronization in the distributed system are improved.

[0087] See also Figure 4 , Figure 44 is a schematic diagram of a terminal device provided in the fourth embodiment of the present invention. The terminal device 400 may be a computer, a server or other device, and the device has a data synchronization function. The terminal device 400 of this embodiment includes various units for executing Figure 1 For details of the steps in the corresponding embodiments, please refer to Figure 1 and Figure 1 The terminal device 400 of this embodiment includes: a leader selection unit 401 , a cluster head selection unit 402 , and a data synchronization unit 403 .

[0088] A leader selection unit 401 is used to select a leader node from all distributed nodes in the distributed node system; the leader node is used to synchronize the data stored in itself to the other distributed nodes;

[0089] A cluster head selection unit 402, configured to divide all the distributed nodes except the leader node into at least two clusters, and determine a cluster head node in each of the clusters;

[0090] The data synchronization unit 403 is used to synchronize the data of the leader node to each of the cluster head nodes, and then synchronize the data in each cluster head node to each of the distributed nodes in the cluster group.

[0091] Furthermore, the leader selection unit 401 may include:

[0092] An information detection unit, used for detecting whether each of the distributed nodes in the distributed node system has received information from the cluster head node in the cluster group, and if not, instructing each of the distributed nodes to vote;

[0093] A leader voting unit, used to select the distributed node with the most votes as the leader node;

[0094] A leader information generating unit is used to generate leader node information and send the leader node information to each of the distributed nodes.

[0095] Further, the cluster head selection unit 402 may include:

[0096] A cluster division unit, used for dividing all the distributed nodes in the distributed node system except the leader node into uniform clusters, each of which contains the same number of distributed nodes;

[0097] The cluster head determination unit is used to determine the cluster head node of each of the clusters according to the node characteristics of the distributed nodes in each of the clusters.

[0098] Further, the cluster head determination unit may include:

[0099] A coordinate determination unit is used to coordinate the leader node and each of the distributed nodes according to the transmission attributes of the leader node and each of the distributed nodes in the network, and obtain the coordinate of the distributed node i as (x i ,y i ), the coordinates of the leader node are (x Leader ,y Leader );

[0100] A distance determination unit is used to calculate the distance between the distributed nodes in the cluster and the leader node according to the coordinates of the leader node and the coordinates of each of the distributed nodes by the following formula:

[0101]

[0102] The weight calculation unit is used to calculate the cluster head weight of the distributed node by the following formula:

[0103] E(i)=n·Expen(i)+m·Range(i);

[0104] Wherein, Expen(i) is used to represent the energy consumption required for synchronizing the data of the distributed node i to each distributed node in the cluster to which it belongs; n and m are used to represent preset parameter constants, and m+n=1;

[0105] The cluster head identification unit is used to identify the distributed node with the largest cluster head weight as the cluster head node.

[0106] Furthermore, the terminal device may also include:

[0107] A data detection unit, used to detect whether the data of each of the distributed nodes is consistent;

[0108] A synchronization success unit, configured to cause the cluster head node to send synchronization success information to the leader node if the data of each of the distributed nodes are consistent;

[0109] A supplementary synchronization unit is used to determine the distributed node that fails to synchronize if the data of each distributed node is inconsistent, and synchronize the data of the leader node to the distributed node that fails to synchronize.

[0110] The above scheme selects a leader node from all distributed nodes in the distributed node system, divides the other distributed nodes in the system except the leader node into at least two clusters, and selects a cluster head node in each cluster. By synchronizing the data of the leader node to the cluster head node, and then the cluster head node synchronizes the data to other nodes in the cluster, network congestion and data delay caused by other nodes in the system directly obtaining data from the leader node are avoided, the transmission energy and data load consumption of distributed nodes during data synchronization are reduced, and it is ensured that all nodes in the system can achieve data synchronization efficiently and quickly.

[0111] Figure 5 Schematic diagram of a terminal device provided in Embodiment 5 of the present invention. Figure 5 As shown, the terminal device 5 of this embodiment includes: a processor 50, a memory 51, and a computer program 52 stored in the memory 51 and executable on the processor 50. When the processor 50 executes the computer program 52, the steps in the above-mentioned data synchronization method embodiments based on distributed storage technology are implemented, for example Figure 1 Alternatively, when the processor 50 executes the computer program 52, the functions of each module / unit in the above-mentioned device embodiments are realized, for example, Figure 4 The functions of units 401 to 403 are shown.

[0112] Exemplarily, the computer program 52 may be divided into one or more modules / units, which are stored in the memory 51 and executed by the processor 50 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program 52 in the terminal device 5.

[0113] The terminal device 5 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The terminal device may include, but is not limited to, a processor 50 and a memory 51. Those skilled in the art will appreciate that Figure 5 It is only an example of the terminal device 5 and does not constitute a limitation of the terminal device 5. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device may also include input and output devices, network access devices, buses, etc.

[0114] The processor 50 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0115] The memory 51 may be an internal storage unit of the terminal device 5, such as a hard disk or memory of the terminal device 5. The memory 51 may also be an external storage device of the terminal device 5, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card (FC), etc. equipped on the terminal device 5. Further, the memory 51 may also include both an internal storage unit and an external storage device of the terminal device 5. The memory 51 is used to store the computer program and other programs and data required by the terminal device. The memory 51 may also be used to temporarily store data that has been output or is to be output.

[0116] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0117] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

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

[0119] If the integrated module / unit 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 present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing related hardware through a computer program, and the computer program can be stored in a computer-readable storage medium.

[0120] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.

Claims

1. A data synchronization method based on distributed storage technology, characterized in that: include: Select one leader node from all distributed nodes in the distributed node system; The leader node is used to synchronize the data stored in itself to the other distributed nodes; Divide all the distributed nodes except the leader node into at least two cluster groups, and determine the cluster head node in each cluster group; wherein, after the cluster head node is determined in a cluster group, the cluster head node sends its node identifier and cluster group identifier to the leader node, and after receiving the identifier, the leader node determines that the node corresponding to the node identifier is the cluster head node in the cluster group corresponding to the cluster group identifier, and the leader node sends data to the cluster head node, and after receiving the data, the cluster head node sends data reception success information to the leader node, and broadcasts the data to other distributed nodes in the cluster; Synchronize the data in the leader node to each of the cluster head nodes, and then synchronize the data in each cluster head node to each of the distributed nodes in the cluster group; The dividing all the distributed nodes except the leader node to obtain at least two clusters, and determining the cluster head node in each cluster, includes: Dividing all the distributed nodes in the distributed node system except the leader node into uniform clusters, each of which contains the same number of distributed nodes; Determining the cluster head node of each of the clusters according to the node characteristics of the distributed nodes in each of the clusters; The step of determining the cluster head node of each cluster according to the node characteristics of the distributed nodes in each cluster includes: According to the transmission attributes of the leader node and each of the distributed nodes in the network, the leader node and each of the distributed nodes are coordinateized to obtain the coordinates of the distributed node i as follows: , the coordinates of the leader node are ; According to the coordinates of the leader node and the coordinates of each of the distributed nodes, the distance between the distributed nodes in the cluster and the leader node is calculated by the following formula: ; The cluster head weight of the distributed node is calculated by the following formula: ; in, Used to represent the energy consumption required for synchronizing the data of the distributed node i to each distributed node in the cluster where it is located; is used to represent a preset parameter constant, and ; The distributed node with the largest cluster head weight is identified as the cluster head node.

2. The data synchronization method based on distributed storage technology according to claim 1, characterized in that: The step of selecting a leader node from among all distributed nodes in the distributed node system includes: Detecting whether each of the distributed nodes in the distributed node system has received information from the cluster head node in the cluster group, and if not, sending an instruction to re-vote and elect a leader node to each of the distributed nodes; Identify the distributed node with the most votes as the leader node; Generate leader node information, and send the leader node information to each of the distributed nodes.

3. The data synchronization method based on distributed storage technology according to claim 1 or 2, characterized in that: After synchronizing the data of the leader node to each of the cluster head nodes, and then synchronizing the data in each cluster head node to each of the distributed nodes in the cluster group, the method further includes: Detecting whether the data of each of the distributed nodes is consistent; If the data of each of the distributed nodes is consistent, the cluster head node sends a synchronization success message to the leader node; If the data of each of the distributed nodes is inconsistent, the distributed node that fails to synchronize is determined, and the data of the leader node is synchronized to the distributed node that fails to synchronize.

4. A terminal device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and wherein when the processor executes the computer program, the following steps are implemented: Selecting a leader node from all distributed nodes in the distributed node system; the leader node is used to synchronize the data stored in the leader node to the other distributed nodes; Divide all the distributed nodes except the leader node to obtain at least two clusters, and determine the cluster head node in each cluster; wherein, after the cluster head node is determined in a cluster, the cluster head node sends its node identifier and cluster group identifier to the leader node, and after receiving the identifier, the leader node determines that the node corresponding to the node identifier is the cluster head node in the cluster corresponding to the cluster group identifier, and the leader node sends data to the cluster head node, and after receiving the data, the cluster head node sends data reception success information to the leader node, and broadcasts the data to other distributed nodes in the cluster at the same time; Synchronize the data of the leader node to each of the cluster head nodes, and then synchronize the data in each cluster head node to each of the distributed nodes in the cluster group; The dividing all the distributed nodes except the leader node to obtain at least two clusters, and determining the cluster head node in each cluster, includes: Dividing all the distributed nodes in the distributed node system except the leader node into uniform clusters, each of which contains the same number of distributed nodes; Determining the cluster head node of each of the clusters according to the node characteristics of the distributed nodes in each of the clusters; The step of determining the cluster head node of each cluster according to the node characteristics of the distributed nodes in each cluster includes: According to the transmission attributes of the leader node and each of the distributed nodes in the network, the leader node and each of the distributed nodes are coordinateized to obtain the coordinates of the distributed node i as follows: , the coordinates of the leader node are ; According to the coordinates of the leader node and the coordinates of each of the distributed nodes, the distance between the distributed nodes in the cluster and the leader node is calculated by the following formula: ; The cluster head weight of the distributed node is calculated by the following formula: ; in, Used to represent the energy consumption required for synchronizing the data of the distributed node i to each distributed node in the cluster where it is located; is used to represent a preset parameter constant, and ; The distributed node with the largest cluster head weight is identified as the cluster head node.

5. The terminal device according to claim 4, characterized in that: The step of selecting a leader node from among all distributed nodes in the distributed node system includes: Detecting whether each of the distributed nodes in the distributed node system has received information from the cluster head node in the cluster group where it is located, and if not, instructing each of the distributed nodes to vote; Select the distributed node with the most votes as the leader node; Generate leader node information, and send the leader node information to each of the distributed nodes.

6. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 3 are implemented.