Data synchronization method and apparatus, electronic device, and storage medium
By receiving and analyzing the time parameters of electronic devices in a distributed network, target devices are selected for data synchronization, thus solving the redundancy problem caused by repeated synchronization in the Gossip protocol and improving data synchronization efficiency and network performance.
Patent Information
- Application Number
- CN202110826082.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-21
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2041-07-21
AI Technical Summary
In distributed networks, the existing Gossip protocol causes repeated synchronization during data synchronization, resulting in a large number of redundant messages, which reduces the efficiency of data synchronization and network performance.
By receiving time parameters broadcast by multiple electronic devices in the current synchronization period, the target electronic device is determined for data synchronization, avoiding duplicate synchronization. The time parameter attribute is used to select devices that have not completed synchronization for data transmission.
It reduces the probability of redundancy caused by repeated synchronization, improves the efficiency of data synchronization and the performance of the system, and ensures data consistency.
Smart Images

Figure CN115695444B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of distributed network, and particularly relates to a data synchronization method and device, electronic equipment and storage medium. BACKGROUND
[0002] With the development of network and the rapid increase of data, the traditional information processing technology has been difficult to effectively support, and new technologies have brought about a revolutionary change in the information technology system. From the "centralized traditional information technology system", it has evolved into today's "distributed new information technology system", and the software architecture has also been reshaped from "regional centralized network architecture" to "wide-area distributed network architecture". More and more enterprises realize that in order to continue the next step of development, it is necessary to realize the multi-center, multi-level and multi-region distributed network.
[0003] Generally, the distributed network includes multiple nodes, and in some application occasions, it is necessary to synchronize the data of each node in the distributed network. Therefore, how to ensure the accuracy of data synchronization of each node in the distributed network will directly affect the working performance of the distributed network. SUMMARY
[0004] Therefore, the present application provides a data synchronization method and device, electronic equipment and storage medium.
[0005] The present application provides a data synchronization method, applied to a first electronic equipment in a distributed network, wherein the distributed network includes multiple second electronic equipments to be synchronized, and the method comprises the following steps:
[0006] receiving multiple second time parameters broadcasted by the multiple second electronic equipments in a current synchronization period, wherein the multiple second time parameters correspond to the multiple second electronic equipments one by one, and each second time parameter in the multiple second time parameters is used to represent the number of synchronization periods experienced by the corresponding second electronic equipment in the current synchronization period;
[0007] determining a target electronic equipment from the multiple second electronic equipments based on the multiple second time parameters;
[0008] sending the to-be-synchronized data to the target electronic equipment.
[0009] On the basis of the above-mentioned embodiments, the present application further provides a data synchronization device, applied to a first electronic equipment in a distributed network, wherein the distributed network includes multiple second electronic equipments to be synchronized, and the device comprises a receiving module, a determining module and a sending module, wherein:
[0010] The receiving module is configured to receive a plurality of second time parameters broadcast by the plurality of second electronic devices in a current synchronization period, the plurality of second time parameters corresponding to the plurality of second electronic devices in a one-to-one manner, and each of the plurality of second time parameters being used to represent a number of synchronization periods experienced by a corresponding second electronic device in the current synchronization period.
[0011] The determining module is configured to determine a target electronic device from the plurality of second electronic devices based on the plurality of second time parameters.
[0012] The sending module is configured to send the to-be-synchronized data to the target electronic device.
[0013] On the basis of the above-mentioned embodiments, the embodiments of the present application further provide an electronic device, which comprises a processor and a memory for storing a computer program capable of running on the processor.
[0014] When the processor is used to run the computer program, the processor is configured to execute the steps of the method in the above-mentioned embodiments.
[0015] On the basis of the above-mentioned embodiments, the embodiments of the present application further provide a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the steps of the method in the above-mentioned embodiments.
[0016] The data synchronization method provided by the embodiments of the present application receives a plurality of second time parameters broadcast by a plurality of second electronic devices in a current synchronization period, the plurality of second time parameters corresponding to the plurality of second electronic devices in a one-to-one manner, and each of the plurality of second time parameters being used to represent a number of synchronization periods experienced by a corresponding second electronic device in the current synchronization period; determines a target electronic device from the plurality of second electronic devices based on the plurality of second time parameters; and sends to-be-synchronized data to the target electronic device. In this way, by receiving the second time parameters broadcast by the second electronic devices, the second electronic devices that have not completed data synchronization can be accurately found out, the to-be-synchronized data can be prevented from being repeatedly synchronized in the second electronic devices that have completed data synchronization, the probability of redundancy generated by repeated synchronization is reduced, the efficiency of data synchronization is improved, and the working performance of the system is improved. BRIEF DESCRIPTION OF DRAWINGS
[0017] Figure 1 is a synchronization diagram of a Gossip protocol in a first synchronization period in the related art;
[0018] Figure 2 is a synchronization diagram of a Gossip protocol in a second synchronization period in the related art;
[0019] Figure 3A flowchart of a data synchronization method provided by an embodiment of the present application is shown in FIG. 1.
[0020] Figure 4 A flowchart of another data synchronization method provided by an embodiment of the present application is shown in FIG. 2.
[0021] Figure 5 A flowchart of another data synchronization method provided by an embodiment of the present application is shown in FIG. 3.
[0022] Figure 6 A graph showing the change of the time parameter corresponding to the electronic device in a data synchronization method provided by an embodiment of the present application with the synchronization period is shown in FIG. 4.
[0023] Figure 7 A structural diagram of a data synchronization device provided by an embodiment of the present application is shown in FIG. 5.
[0024] Figure 8 An interaction flowchart of a data synchronization device provided by an embodiment of the present application is shown in FIG. 6.
[0025] Figure 9 A synchronization diagram of a data synchronization device provided by an embodiment of the present application in a first synchronization period is shown in FIG. 7.
[0026] Figure 10 A synchronization diagram of a data synchronization device provided by an embodiment of the present application in a second synchronization period is shown in FIG. 8.
[0027] Figure 11 A physical diagram of an electronic device provided by an embodiment of the present application is shown in FIG. 9. DETAILED DESCRIPTION
[0028] In order to enable a person skilled in the art to better understand the features and technical contents of the embodiments of the present application, the implementation of the embodiments of the present application will be described in detail below with reference to the accompanying drawings, which are only used for reference and do not limit the embodiments of the present application.
[0029] Unless otherwise defined, all technical and scientific terms used in the embodiments of the present application have the same meanings as commonly understood by one skilled in the art to which the present application belongs. The terms used in the embodiments of the present application are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.
[0030] Generally speaking, the Gossip protocol is an important protocol in the distributed network, mainly used for synchronizing data among various copy nodes in the distributed database system. The biggest advantage of the Gossip protocol is the eventual consistency, which can guarantee the data synchronization among various nodes in the distributed network system. Meanwhile, due to the characteristics of simplicity, high efficiency and strong fault tolerance, the Gossip protocol has been widely applied in the distributed field and the big data field.
[0031] Although the Gossip protocol is widely used in the field of distribution, the nodes of the network formed by the Gossip protocol are all peer nodes when synchronizing messages. Thus, the probability of selecting a target node by a source node is fixed, and therefore, a large number of redundant messages are generated due to repeated synchronization in the actual data synchronization process, and the efficiency of data synchronization is reduced. Figure 1 As shown in FIG. 1, in the first synchronization period, node O randomly sends a message to node A and node D. As shown in FIG. 2, in the second synchronization period, node A repeatedly synchronizes the message to node O, and node D repeatedly synchronizes the message to node A, causing unnecessary message redundancy and affecting the message synchronization rate. Figure 2 As shown in FIG. 1, in the first synchronization period, node O randomly sends a message to node A and node D. As shown in FIG. 2, in the second synchronization period, node A repeatedly synchronizes the message to node O, and node D repeatedly synchronizes the message to node A, causing unnecessary message redundancy and affecting the message synchronization rate.
[0032] In view of the above problems, the related art currently has the following solutions:
[0033] 1) Using a data structure (for example, a queue or a linked list) as an auxiliary tool, so that a new node has a higher probability of being selected as a target node, thereby reducing the degree of message redundancy and improving the efficiency of data synchronization. However, the data structure increases the additional storage space, and the data structure is synchronized as part of the message. As the synchronization proceeds, the size of the data structure increases, thereby affecting the message synchronization rate.
[0034] 2) Using an additional broadcast mechanism to reduce the probability of sending a message to a repeated node, reduce the generation of redundant messages, and improve the efficiency of data synchronization. However, the additional broadcast mechanism generates a large number of broadcast messages in the message synchronization process. Although the broadcast message only stores a small amount of information, a large number of broadcast messages may increase the network load and affect the network performance.
[0035] To solve the above problems in the related art, the embodiments of the present application provide a data synchronization method applied to a first electronic device in a distributed network, the distributed network comprising a plurality of second electronic devices to be synchronized, as shown in FIG. 3, the method can comprise the following steps: Figure 3
[0036] S301, receiving a plurality of second time parameters broadcasted by a plurality of second electronic devices in a current synchronization period, the plurality of second time parameters corresponding to the plurality of second electronic devices one by one; each second time parameter in the plurality of second time parameters is used to represent the number of synchronization periods experienced by the corresponding second electronic device in the current synchronization period.
[0037] Here, the first electronic device can be a source node in the distributed network, or a to-be-synchronized node that has received the to-be-synchronized data in the last data synchronization period. The to-be-synchronized data to be sent can be location information, state information, or other related parameter configuration information stored in the source node in the distributed network. In the Gossip protocol, all nodes periodically randomly select surrounding nodes to send messages, and the nodes receiving the messages also repeat the step, thereby realizing data synchronization. Data synchronization refers to replacing the local data of all to-be-synchronized nodes with the to-be-synchronized data, thereby ensuring the eventual consistency of the local data of all nodes. The first electronic device obtains the to-be-synchronized data stored in the source node, or the first electronic device receives the to-be-synchronized data sent by other nodes in the last data synchronization period.
[0038] Here, the second electronic device can be a device different from the first electronic device, and the second electronic device can be a to-be-synchronized node that has not received the to-be-synchronized data in the distributed network. In each data synchronization period of the to-be-synchronized data, the plurality of to-be-synchronized nodes determine their second time parameters according to the number of synchronization periods, and broadcast the second time parameters; after receiving the broadcasted plurality of second parameters, the first electronic device determines a plurality of second electronic devices as target electronic devices for data synchronization. The role of the second time parameter is defined here to selectively select target electronic devices, avoid redundancy caused by repeated data synchronization, and thereby ensure that the nodes receiving the to-be-synchronized data in each data synchronization period are to-be-synchronized nodes that have not received the to-be-synchronized data before.
[0039] It should be noted that the second time parameter corresponds to the second electronic device one-to-one, and is used to represent the number of synchronization periods experienced by the corresponding second electronic device in the current synchronization period. Specifically, if any one of the second electronic devices receives the to-be-synchronized data in any one of the data synchronization periods of the to-be-synchronized data, the second time parameter corresponding to the second electronic device has a correlation with the number of synchronization periods when the second electronic device receives the to-be-synchronized data; if any one of the second electronic devices does not receive the to-be-synchronized data in any one of the data synchronization periods of the to-be-synchronized data, the second time parameter corresponding to the second electronic device has a correlation with the number of synchronization periods in which the second electronic device is currently located.
[0040] S302, determining target electronic devices from the plurality of second electronic devices based on the plurality of second time parameters.
[0041] Here, the first electronic device will determine the second electronic device with the largest second time parameter as the target electronic device according to the received plurality of second time parameters.
[0042] S303, sending the to-be-synchronized data to the target electronic device.
[0043] Here, the first electronic device needs to send the to-be-synchronized data to the target electronic device after confirming the target electronic device of the current data synchronization period, so that the target electronic device performs data synchronization on the plurality of second electronic devices other than the target electronic device, and then completes the synchronization of the data, thereby ensuring that the data of all nodes has the final consistency.
[0044] It should be noted that if any one of the second electronic devices receives the to-be-synchronized data in any one of the data synchronization periods of the to-be-synchronized data, the second time parameter corresponding to the second electronic device remains unchanged as the number of synchronization periods increases;
[0045] If any one of the second electronic devices does not receive the to-be-synchronized data in any one of the data synchronization periods of the to-be-synchronized data, the second time parameter corresponding to the second electronic device increases as the number of synchronization periods increases, until the second electronic device receives the to-be-synchronized data.
[0046] Therefore, the data synchronization method provided by the embodiment of the application receives a plurality of second time parameters broadcast by a plurality of second electronic devices in a current synchronization period, the plurality of second time parameters correspond to the plurality of second electronic devices one by one; each second time parameter in the plurality of second time parameters is used to represent the number of synchronization periods experienced by the corresponding second electronic device in the current synchronization period; a target electronic device is determined from the plurality of second electronic devices based on the plurality of second time parameters; and to-be-synchronized data is sent to the target electronic device. In this way, by receiving the second time parameter broadcast by the second electronic device, the second electronic device that has not completed data synchronization can be accurately found, and the to-be-synchronized data is prevented from being repeatedly synchronized in the second electronic device that has completed data synchronization, thereby reducing the probability of redundancy caused by repeated synchronization, improving the efficiency of data synchronization, and improving the working performance of the system.
[0047] Based on the above embodiment, the current synchronization period in S301 is the kth synchronization period, and k is an integer greater than or equal to 3; before receiving the plurality of second time parameters broadcast by the plurality of second electronic devices in the current synchronization period in S301, the following steps can also be included:
[0048] S3011, obtaining to-be-synchronized data stored by a first electronic device; the first electronic device is an electronic device that has stored to-be-synchronized data before performing data synchronization; or
[0049] S3012, receiving to-be-synchronized data sent by a third electronic device; wherein the third electronic device is an electronic device that performs data synchronization in the k-2th synchronization period; and the first electronic device is an electronic device that performs data synchronization in the k-1th synchronization period.
[0050] Here, the first electronic device can be a source node or a target node in the last data synchronization period. When the first electronic device is a source node, the first electronic device directly obtains the to-be-synchronized data stored locally, and synchronizes the second electronic device. When the first electronic device is not a source node, the third electronic device is an electronic device that has synchronized the to-be-synchronized data in the k-2 synchronization period; the first electronic device is an electronic device that has synchronized the to-be-synchronized data in the k-1 synchronization period, the current synchronization period is the k synchronization period, and k is an integer greater than or equal to 3. The first electronic device receives the to-be-synchronized data sent by the source node (the third electronic device) in the last data synchronization period. The third electronic device can be a source node in the distributed network or a to-be-synchronized node in the distributed network that receives the to-be-synchronized data before the first electronic device.
[0051] Based on the above embodiment, before receiving the to-be-synchronized data sent by the third electronic device at S3012, the method further includes:
[0052] S3012a, broadcasting, to the third electronic device, a first time parameter corresponding to the first electronic device, so that the third electronic device sends the to-be-synchronized data to the first electronic device based on the first time parameter; the first time parameter is used to represent the number of synchronization periods experienced by the first electronic device in the k-1 synchronization period.
[0053] Here, when the first electronic device is a target node in the last data synchronization period, the first electronic device first determines the first time parameter according to the number of synchronization periods, and the first time parameter increases with the increase of the number of synchronization periods. For example, the first time parameter of the first electronic device in the first synchronization period is 1, and the first time parameter of the first electronic device in the second synchronization period is 2, and so on.
[0054] After determining the first time parameter according to the number of synchronization periods, the first electronic device broadcasts the first time parameter determined according to the number of current synchronization periods in each data synchronization period of the to-be-synchronized data, and the third electronic device receives the first time parameter determined by the first electronic device according to the number of current synchronization periods, and sends the to-be-synchronized data to the target electronic device according to the first time parameter.
[0055] Based on the above embodiment, after receiving the to-be-synchronized data sent by the third electronic device at S1032, the method further includes:
[0056] S1032b, stopping increasing the first time parameter with the increase of the number of synchronization periods, and broadcasting the first time parameter corresponding to the first electronic device in the k-1 synchronization period in each synchronization period.
[0057] Here, after the first electronic device receives the to-be-synchronized data sent by the third electronic device, the first electronic device has completed synchronization. Therefore, it is necessary to stop increasing the first time parameter with the increase of the number of synchronization periods. That is, the first time parameter at this time is the first time parameter corresponding to the time when the first electronic device receives the to-be-synchronized data. For example, if the first electronic device receives the to-be-synchronized data in the fifth synchronization period, the first time parameter of the first electronic device is 5 and remains unchanged.
[0058] After determining the first time parameter corresponding to the time when the first electronic device receives the to-be-synchronized data, in each synchronization period of the to-be-synchronized data, the first electronic device broadcasts the unchanged first time parameter. In this way, the target electronic device determined in the current period will only select other nodes with larger time parameters to send in the next synchronization period, and will not select the first electronic device for repeated sending. In this way, the probability of selecting a repeated node and the degree of redundancy of the message can be effectively reduced, and the efficiency of network data synchronization can be improved.
[0059] Based on the above embodiment, the first time parameter and / or the second time parameter include at least one of a timestamp parameter, a counter parameter, and a weight parameter.
[0060] Here, the first time parameter and / or the second time parameter can be at least one of a timestamp parameter, a counter parameter, and a weight parameter. Of course, the first time parameter and / or the second time parameter here are not limited to the above-mentioned parameters, and any parameter that can increase with the increase of the synchronization period and remain unchanged after a certain synchronization period can achieve the above function. In this way, the timestamp value, the count value, or the weight value can be increased with the increase of the data synchronization period, so as to ensure that the first time parameter and / or the second time parameter increase with the increase of the data synchronization period until the electronic device corresponding to the first time parameter and / or the second time parameter receives the to-be-synchronized data.
[0061] Based on the above embodiment, the target electronic device is determined from the plurality of second electronic devices based on the plurality of second time parameters in S302, which can be achieved by the following steps:
[0062] S3021, based on the plurality of second time parameters, the second electronic device with the largest second time parameter is determined as the target electronic device.
[0063] Here, the second time parameter has a similar association relationship with the second electronic device as the first time parameter has with the first electronic device. When any one of the second electronic devices receives the to-be-synchronized data in any one of the data synchronization periods, the second time parameter of the second electronic device has an association relationship with the number of synchronization periods in which the second electronic device receives the to-be-synchronized data. For example, when any one of the second electronic devices receives the to-be-synchronized data in the fifth data synchronization period, the second time parameter of the second electronic device is 5, and the second time parameter remains unchanged as the number of data synchronization periods increases.
[0064] Meanwhile, when any one of the second electronic devices does not receive the to-be-synchronized data in any one of the data synchronization periods, the second time parameter of the second electronic device has an association relationship with the number of synchronization periods in which the second electronic device currently stays. For example, when any one of the second electronic devices does not receive the to-be-synchronized data in the fifth data synchronization period, the second time parameter of the second electronic device is 5, and the second time parameter increases as the number of data synchronization periods increases.
[0065] Specifically, the first electronic device receives the multiple second time parameters broadcast by the multiple second electronic devices, determines the sizes of the multiple second time parameters, and determines the second electronic device with the largest second time parameter as the target electronic device. Then, the first electronic device sends the to-be-synchronized data to the target electronic device to complete the data synchronization. In this way, by selecting the second electronic device with the largest second time parameter, the same node can be avoided from being repeatedly selected for data synchronization, the probability of selecting a repeated node and the redundancy of messages can be reduced, and the efficiency of network data synchronization can be improved.
[0066] It can be seen that the data synchronization method provided by the embodiments of the present application receives multiple second time parameters broadcast by multiple second electronic devices in a current synchronization period, the multiple second time parameters correspond to the multiple second electronic devices one by one, each second time parameter in the multiple second time parameters represents the number of synchronization periods experienced by the corresponding second electronic device in the current synchronization period, a target electronic device is determined from the multiple second electronic devices based on the multiple second time parameters, and to-be-synchronized data is sent to the target electronic device. In this way, by receiving the second time parameter broadcast by the second electronic device, the second electronic device that has not completed data synchronization can be accurately found out, the to-be-synchronized data can be avoided from being repeatedly synchronized in the second electronic device that has completed data synchronization, the probability of redundancy caused by repeated synchronization can be reduced, the efficiency of data synchronization can be improved, and the working performance of the system can be improved.
[0067] On the basis of the above-mentioned embodiments, the present application further provides a data synchronization method applied to a first electronic device in a distributed network, the distributed network including multiple second electronic devices to be synchronized, such as Figure 4As shown, the method can include the following steps:
[0068] S401, obtaining the to-be-synchronized data stored in the first electronic device; the first electronic device is an electronic device that has stored the to-be-synchronized data before data synchronization is performed.
[0069] Here, the first electronic device can be a source node in a distributed network, and the source node stores the to-be-synchronized data before synchronization is started. In order to complete data synchronization of the distributed network, the source node needs to send the to-be-synchronized data to other nodes.
[0070] S402, receiving a plurality of second time parameters broadcast by a plurality of second electronic devices in the current synchronization period; the plurality of second time parameters correspond one-to-one to the plurality of second electronic devices; each of the plurality of second time parameters is used to represent the number of synchronization periods experienced by the corresponding second electronic device in the current synchronization period.
[0071] Here, the second electronic device can be a to-be-synchronized node in the distributed network. Each to-be-synchronized node corresponds to maintain a second time parameter, which has a correlation relationship with the number of synchronization periods of the to-be-synchronized data. The plurality of to-be-synchronized nodes broadcast their own second time parameters in each data synchronization period of the to-be-synchronized data, and the first electronic device receives the plurality of second parameters.
[0072] S403, based on the plurality of second time parameters, determining the second electronic device with the largest second time parameter as the target electronic device.
[0073] Here, after the first electronic device receives the plurality of second parameters, it will select a plurality of second electronic devices with the largest second time parameter and determine them as the target electronic device of the current data synchronization period for data synchronization.
[0074] It should be noted that for the source node, in the first data synchronization period of the to-be-synchronized data, the second time parameters of all to-be-synchronized nodes are the same, and therefore, a plurality of second electronic devices are randomly selected as the target electronic device for data synchronization in the first data synchronization period.
[0075] S404, sending the to-be-synchronized data to the target electronic device.
[0076] Here, after the target electronic device is determined, the to-be-synchronized data stored in the source node is sent to the target electronic device to complete the data synchronization in the first data synchronization period, so that the target electronic device synchronizes data with the plurality of second electronic devices other than the target electronic device.
[0077] Based on the above embodiments, the present application further provides a data synchronization method, which is applied to a first electronic device in a distributed network, wherein the distributed network includes a plurality of second electronic devices to be synchronized with data, such as Figure 5 As shown, the method may include the following steps:
[0078] S501. Broadcast a first time parameter corresponding to the first electronic device to a third electronic device, so that the third electronic device sends data to be synchronized to the first electronic device based on the first time parameter; the first time parameter is used to represent the number of synchronization cycles experienced by the first electronic device in the k-1th synchronization cycle.
[0079] Here, as Figure 6 As shown, the first electronic device may be a node to be synchronized in a distributed network. Each node to be synchronized maintains a first time parameter corresponding to the node to be synchronized. The first time parameter is used to represent the number of synchronization cycles experienced by the first electronic device in the k-1th synchronization cycle, where k is an integer greater than or equal to 3. The first time parameter increases as the number of synchronization cycles of the data to be synchronized increases until the first electronic device is determined to be the target electronic device.
[0080] Here, after determining the first time parameter, the first electronic device will broadcast the corresponding first time parameter to the third electronic device in each data synchronization cycle. The third electronic device that stores the data to be synchronized receives the first time parameter and sends the data to be synchronized to the first electronic device based on the first time parameter.
[0081] Here, the third electronic device can be a source node in the distributed network or a target node that received the data to be synchronized during the previous data synchronization cycle. It should be noted that each node only sends data once during data synchronization. Therefore, the source node determines the target electronic device during the first data synchronization cycle, which will serve as the source node for the next data synchronization cycle. And so on.
[0082] S502. Receive data to be synchronized sent by a third electronic device; the first electronic device is an electronic device that performs data synchronization in the k-1 synchronization period; the third electronic device is an electronic device that performs data synchronization in the k-2 synchronization period; the current synchronization period is the kth synchronization period, and k is an integer greater than or equal to 3.
[0083] The third electronic device is an electronic device that synchronizes the to-be-synchronized data in a k-2th synchronization period; the first electronic device is an electronic device that synchronizes the to-be-synchronized data in a k-1th period, and the current synchronization period is a kth synchronization period, where k is an integer greater than or equal to 3. The first electronic device receives the to-be-synchronized data sent by the source node (the third electronic device) in the last data synchronization period. The third electronic device can be a source node in the distributed network, or a to-be-synchronized node in the distributed network that receives the to-be-synchronized data before the first electronic device.
[0084] S503, stopping increasing the first time parameter with the increase of the number of synchronization periods, and broadcasting, in each synchronization period, the first time parameter corresponding to the first electronic device in a k-1th synchronization period.
[0085] Here, after receiving the to-be-synchronized data sent by the third electronic device, the first time parameter of the first electronic device will stop increasing with the increase of the number of synchronization periods of the to-be-synchronized data, and will remain the first time parameter corresponding to the k-1th synchronization period, that is, the first time parameter corresponding to the reception of the to-be-synchronized data.
[0086] Here, after receiving the to-be-synchronized data sent by the third electronic device, the first time parameter will remain the first time parameter corresponding to the reception of the to-be-synchronized data, and the first electronic device broadcasts the first time parameter corresponding to the reception of the to-be-synchronized data in each synchronization period of the to-be-synchronized data.
[0087] S504, receiving a plurality of second time parameters broadcast by a plurality of second electronic devices in the current synchronization period, the plurality of second time parameters corresponding to the plurality of second electronic devices one by one; each second time parameter in the plurality of second time parameters is used to represent the number of synchronization periods experienced by the corresponding second electronic device in the current synchronization period.
[0088] Here, the second electronic device can be a to-be-synchronized node in the distributed network. Each to-be-synchronized node corresponds to a second time parameter maintained by the to-be-synchronized node, and the second time parameter has a correlation with the number of synchronization periods of the to-be-synchronized data. The plurality of to-be-synchronized nodes broadcast their own second time parameters in each data synchronization period of the to-be-synchronized data, and the first electronic device receives the plurality of second parameters.
[0089] S505, determining, based on the plurality of second time parameters, a second electronic device with the largest second time parameter as a target electronic device.
[0090] Here, after receiving the plurality of second parameters, the first electronic device selects a plurality of second electronic devices with the largest second time parameters, and determines the plurality of second electronic devices as target electronic devices for data synchronization in the current data synchronization period.
[0091] It should be noted that, for the source node, in the first data synchronization period of the to-be-synchronized data, the second time parameters of all the to-be-synchronized nodes are the same, and therefore, a plurality of second electronic devices are randomly selected as target electronic devices in the first data synchronization period for data synchronization.
[0092] S506, sending the to-be-synchronized data to the target electronic device.
[0093] Here, after the target electronic device of the current data synchronization period is confirmed, the to-be-synchronized data needs to be sent to the target electronic device, so that the target electronic device synchronizes the data of a plurality of second electronic devices other than the target electronic device, to complete the synchronization of the data, thereby ensuring that the data of all nodes have the final consistency.
[0094] It should be noted that, if any one of the second electronic devices receives the to-be-synchronized data in any one of the data synchronization periods of the to-be-synchronized data, the second time parameter corresponding to the second electronic device remains unchanged as the number of synchronization periods increases;
[0095] If any one of the second electronic devices does not receive the to-be-synchronized data in any one of the data synchronization periods of the to-be-synchronized data, the second time parameter corresponding to the second electronic device increases as the number of synchronization periods increases, until the second electronic device receives the to-be-synchronized data.
[0096] Therefore, the data synchronization method provided by the embodiment of the application can accurately find the second electronic device that has not completed data synchronization by receiving the second time parameters broadcast by the second electronic devices, avoid repeated synchronization of the to-be-synchronized data in the second electronic devices that have completed data synchronization, reduce the probability of redundancy caused by repeated synchronization, improve the efficiency of data synchronization, and improve the working performance of the system.
[0097] On the basis of the above-mentioned embodiment, the application further provides a data synchronization device 70 applied to a first electronic device in a distributed network, wherein the distributed network includes a plurality of second electronic devices to be synchronized, as shown in the figure, the device 70 includes a receiving module 71, a determining module 72, and a sending module 73, wherein, Figure 7
[0098] The receiving module 71 is configured to receive a plurality of second time parameters broadcast by the plurality of second electronic devices in a current synchronization period, the plurality of second time parameters corresponding to the plurality of second electronic devices in one-to-one manner, and each of the plurality of second time parameters is used to represent a number of synchronization periods experienced by the corresponding second electronic device in the current synchronization period.
[0099] The determining module 72 is configured to determine a target electronic device from the plurality of second electronic devices based on the plurality of second time parameters.
[0100] The sending module 73 is configured to send the to-be-synchronized data to the target electronic device.
[0101] Based on the above-mentioned embodiments, the apparatus 70 can further include an obtaining module.
[0102] The obtaining module is configured to obtain the to-be-synchronized data stored by the first electronic device before receiving the plurality of second time parameters broadcast by the plurality of second electronic devices in the current synchronization period, and the first electronic device is an electronic device that has stored the to-be-synchronized data before data synchronization is performed.
[0103] Or configured to obtain the to-be-synchronized data sent by a third electronic device before receiving the plurality of second time parameters broadcast by the plurality of second electronic devices in the current synchronization period, the first electronic device is an electronic device that performs data synchronization in a k-1th synchronization period, the third electronic device is an electronic device that performs data synchronization in a k-2th synchronization period, the current synchronization period is a kth synchronization period, and k is an integer greater than or equal to 3.
[0104] Based on the above-mentioned embodiments, the receiving unit can further include a first broadcasting sub-module and a second broadcasting sub-module.
[0105] The first broadcasting sub-module is configured to broadcast a first time parameter corresponding to the first electronic device to the third electronic device before receiving the to-be-synchronized data sent by the third electronic device, so that the third electronic device sends the to-be-synchronized data to the first electronic device based on the first time parameter, and the first time parameter is used to represent a number of synchronization periods experienced by the first electronic device in the k-1th synchronization period.
[0106] The second broadcasting sub-module is configured to stop increasing the first time parameter along with an increase in the number of synchronization periods after receiving the target data sent by the third electronic device, and broadcast the first time parameter corresponding to the first electronic device in the k-1th synchronization period in each synchronization period.
[0107] Based on the above embodiment, the determining module 72 is specifically configured to determine, as the target electronic device, a second electronic device with the largest second time parameter based on the plurality of second time parameters.
[0108] The above device embodiments are similar to the descriptions of the above method embodiments, and have similar beneficial effects to the method embodiments. For technical details not disclosed in the device embodiments of the present application, please refer to the description of the method embodiments of the present application.
[0109] Based on the above embodiment, the present application combines Figure 8 The data interaction process of the data synchronization device is described as follows:
[0110] Step 1: In the receiving module, the to-be-synchronized nodes in the distributed network that need the latest data and the time parameter w of the to-be-synchronized nodes in the current synchronization period are obtained, and they are formed into a to-be-synchronized node list and then transmitted to the determining module;
[0111] Step 2: In the determining module, the k nodes with the highest w are selected, and they are formed into a target node list and then transmitted to the sending module;
[0112] Step 3: The sending node sends the message with the latest data to each node in the target node list;
[0113] Step 4: The target node receives the message and updates the local data according to the to-be-synchronized data in the message.
[0114] The time parameter w of the other remaining nodes in the to-be-synchronized node list is updated, the target node is determined as the sending node of the next synchronization period, and steps 1-3 are repeated to continue forwarding the message with the latest data to the other nodes in the to-be-synchronized node list until the data of all nodes in the distributed network are consistent and the latest.
[0115] Further, the present application combines Figure 9 and Figure 10 The data synchronization process of the data synchronization device is described as follows:
[0116] Before synchronization starts, all nodes in the distributed network initialize W, and the target node number is set to 2, and node O is the source node of the data owner. In the first synchronization period, since the W of the to-be-synchronized nodes in the network are the same, node O randomly selects node A and node D for data synchronization. At the end of the first synchronization period, the W of the data owner node O, node A and node B stop increasing, and the W of the nodes E, node B, node C and node F that do not receive data increase accordingly. In the second synchronization period, node A selects the nodes E and node B with higher W, and node D selects the nodes C and node F with higher W.
[0117] The embodiment of the present application proposes a data synchronization method and device, defines a time parameter attribute W for each node, and increases W of each node with the increase of synchronization period through embedded code, that is, can select new nodes for synchronization accurately in each synchronization period based on the time parameter changing with time, so as to reduce the number of redundant messages and improve the synchronization efficiency.
[0118] Meanwhile, the additional data structure and broadcast mechanism are not used to increase the burden of nodes and network, only a time parameter attribute is defined and appropriate code is embedded, the probability of selecting new nodes can be improved according to the weight, so as to achieve the same purpose as the prior art.
[0119] The embodiment of the present application further provides an electronic device corresponding to a database configuration method; Figure 11 As shown in the hardware component structure diagram of the electronic device of the embodiment of the present application, Figure 11 The electronic device proposed by the embodiment of the present application can include a processor 1101 and a memory 1102 storing executable instructions of the processor;
[0120] The processor 1101 and the memory 1102 are connected through a bus 1103;
[0121] The processor 1101, when running the computer program stored in the memory 1102, can execute the following instructions:
[0122] Receive a plurality of second time parameters broadcast by the plurality of second electronic devices in the current synchronization period, the plurality of second time parameters correspond one-to-one to the plurality of second electronic devices; each second time parameter in the plurality of second time parameters is used to represent the number of synchronization periods experienced by the corresponding second electronic device in the current synchronization period;
[0123] Determine a target electronic device from the plurality of second electronic devices based on the plurality of second time parameters;
[0124] Send the data to be synchronized to the target electronic device.
[0125] In the embodiments provided by the present application, the processor 1101 can be at least one of an Application Specific Integrated Circuit (ASIC), a Digital Signal Processor (DSP), a Digital Signal Processing Device (DSPD), a Programmable Logic Device (PLD), a Field Progmable Gate Array (FPGA), a Central Processing Unit (CPU), and a controller. It can be understood that, for different devices, the electronic device used to implement the functions of the processor can also be other devices, and the embodiments of the present application are not limited to specific implementations.
[0126] In actual applications, the memory 1102 can be a volatile memory (volatile memory), such as RAM, or a non-volatile memory (non-volatile memory), such as ROM, flash memory, a Hard Disk Drive (HDD) or a Solid-State Drive (SSD), or a combination of the above types of memories, and provides instructions and data to the processor 1101.
[0127] The embodiments of the present application also provide a computer storage medium, specifically a computer readable storage medium. The computer instructions are stored on the computer storage medium, and when the computer instructions are executed by the processor of the electronic device manufacturing apparatus, any step of the image processing method described above is implemented.
[0128] In several embodiments provided by the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, multiple units or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling or direct coupling or communication connection between the various components shown or discussed can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.
[0129] The units described as separate components above can or can not be physically separate, and the components shown as units can or can not be physical units, i.e., can be located in one place or distributed on multiple network units; part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
[0130] In addition, the functional units in each embodiment of the present application can be integrated into one processing unit, or each unit can be a separate unit, or at least two units can be integrated into one unit; the integrated unit can be realized in the form of hardware or in the form of hardware plus software functional unit.
[0131] Those skilled in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by program instruction related hardware, and the above-mentioned program can be stored in a computer readable storage medium, and the program executes the steps including the above-mentioned method embodiments when executed; and the above-mentioned storage medium includes mobile storage device, ROM, RAM, magnetic disc or optical disc and various storage program codes.
[0132] Alternatively, the integrated units of the present application, if implemented in the form of software functional modules and sold or used as independent products, can also be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the embodiments of the present application can be embodied in the form of software products, which are stored in a storage medium and include a number of instructions for making a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the methods described in the embodiments of the present application. The above-mentioned storage medium includes mobile storage device, ROM, RAM, magnetic disc or optical disc and various storage program codes.
[0133] It should be noted that the technical solutions described in the embodiments of the present application can be combined arbitrarily without conflict.
[0134] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical range disclosed in the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A data synchronization method, characterized by, The application discloses a method applied to a first electronic device in a distributed network, wherein the distributed network comprises a plurality of second electronic devices to be synchronized with data, and the method comprises the following steps: receiving a plurality of second time parameters broadcast by the plurality of second electronic devices in a current synchronization period, wherein the plurality of second time parameters correspond to the plurality of second electronic devices one by one; if a second electronic device receives the data to be synchronized in any data synchronization period of the data to be synchronized, the second time parameter corresponding to the second electronic device has a correlation with the number of synchronization periods when the second electronic device receives the data to be synchronized; if the second electronic device does not receive the data to be synchronized in any data synchronization period of the data to be synchronized, the second time parameter corresponding to the second electronic device has a correlation with the number of synchronization periods in which the second electronic device is currently located; determining a target electronic device from the plurality of second electronic devices based on the plurality of second time parameters; sending the data to be synchronized to the target electronic device; the method further comprises the following steps: determining the second electronic device with the largest second time parameter as the target electronic device based on the plurality of second time parameters.
2. The method of claim 1, wherein, Before the step of receiving the plurality of second time parameters broadcast by the plurality of second electronic devices in the current synchronization period, the method further comprises the following step: obtaining the data to be synchronized stored in the first electronic device; the first electronic device is an electronic device that has stored the data to be synchronized before data synchronization.
3. The method of claim 1, wherein, The current synchronization period is the kth synchronization period, and k is an integer greater than or equal to 3; Before the step of receiving the plurality of second time parameters broadcast by the plurality of second electronic devices in the current synchronization period, the method further comprises the following step: receiving the data to be synchronized sent by a third electronic device; wherein the third electronic device is an electronic device that performs data synchronization in the k-2th synchronization period; and the first electronic device is an electronic device that performs data synchronization in the k-1th synchronization period.
4. The method of claim 3, wherein, Before the step of receiving the data to be synchronized sent by the third electronic device, the method further comprises the following step: broadcasting a first time parameter corresponding to the first electronic device to the third electronic device, so that the third electronic device sends the data to be synchronized to the first electronic device based on the first time parameter; the first time parameter is used to represent the number of synchronization periods experienced by the first electronic device in the k-1th synchronization period.
5. The method of claim 4, wherein, After the step of receiving the data to be synchronized sent by the third electronic device, the method further comprises the following step: stopping increasing the first time parameter with the increase of the number of synchronization periods, and broadcasting the first time parameter corresponding to the first electronic device in the k-1th synchronization period in each synchronization period.
6. The method of claim 4, wherein, The first time parameter and / or the second time parameter comprises at least one of a timestamp parameter, a counter parameter and a weight parameter.
7. A data synchronization apparatus applied to a first electronic device in a distributed network, wherein a plurality of second electronic devices to be synchronized are included in the distributed network, and the data synchronization apparatus is characterized in that, The device comprises a receiving module, a determining module and a sending module. The receiving module is configured to receive a plurality of second time parameters broadcast by the plurality of second electronic devices in a current synchronization period, the plurality of second time parameters corresponding to the plurality of second electronic devices in a one-to-one manner; if a second electronic device receives the to-be-synchronized data in any data synchronization period of the to-be-synchronized data, the second time parameter corresponding to the second electronic device has a correlation relationship with the number of synchronization periods when the second electronic device receives the to-be-synchronized data; if the second electronic device does not receive the to-be-synchronized data in any data synchronization period of the to-be-synchronized data, the second time parameter corresponding to the second electronic device has a correlation relationship with the number of synchronization periods in which the second electronic device currently stays; The determining module is configured to determine a target electronic device from the plurality of second electronic devices based on the plurality of second time parameters; specifically, based on the plurality of second time parameters, a second electronic device with the largest second time parameter is determined as the target electronic device; The sending module is configured to send the to-be-synchronized data to the target electronic device.
8. An electronic device, comprising: The electronic device includes a processor and a memory for storing a computer program capable of running on the processor; When the processor runs the computer program, the processor is configured to perform the steps of the method in any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, the computer program being executed by a processor to implement the steps of the method in any one of claims 1 to 6.
Citation Information
Patent Citations
Information synchronization method and device
CN111988345A
Multi-terminal data synchronization method and device, equipment and medium
CN112311840A