Data synchronization method and device based on version chain, equipment and storage medium

Through the data synchronization method based on the version chain, the problem of high consumption of data synchronization resources in the prior art, susceptible to clock deviations, and inability to process data rollback scenarios is solved, and efficient and reliable data synchronization effect is achieved.

CN119848144APending Publication Date: 2025-04-18创优数字科技(广东)有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510117159.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-24
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

The existing data synchronization methods have problems such as high resource consumption, susceptibility to clock deviations, and inability to handle data rollback scenarios, resulting in poor synchronization effects.

Method used

The data synchronization method based on the version chain is adopted. By obtaining the current and synchronized version numbers of the data to be synchronized, it is determined whether the difference is 1, and whether to perform synchronization operations based on the results. The data receiver saves the data to be synchronized and updates the version chain and synchronized version number.

Benefits of technology

Data synchronization is managed through the version chain, and only the data that produces version changes is updated, reducing resource consumption, improving data synchronization effect and efficiency, and avoiding data loss and consistency problems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119848144A_ABST
    Figure CN119848144A_ABST
Patent Text Reader

Abstract

The invention discloses a version chain-based data synchronization method, apparatus and device, and a storage medium. The method comprises the following steps: when a data synchronization operation is triggered, obtaining a current data version number of to-be-synchronized data; acquiring a synchronized version number of the to-be-synchronized data; judging whether the difference value between the current data version number and the synchronized version number is 1 or not; if yes, synchronizing the to-be-synchronized data; when the synchronization of the to-be-synchronized data is completed, updating the synchronized version number into the current data version number, sending the to-be-synchronized data and the current data version number to the data receiver, storing the to-be-synchronized data by the data receiver, determining a version chain of the to-be-synchronized data, and sending the version chain of the to-be-synchronized data to the data receiver. And splicing the current data version number at the head of the version chain, and adopting the current data version number as a synchronized version number.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data synchronization technology, and in particular to a data synchronization method, device, equipment and storage medium based on a version chain. Background Art

[0002] In current distributed systems, data synchronization is a common and important technical requirement. The main existing synchronization solutions include:

[0003] 1. Full synchronization: synchronize all data regularly;

[0004] 2. Timestamp synchronization: synchronize according to data modification time;

[0005] 3. Mark synchronization: Use the mark bit (recording the version of the current data) to determine whether synchronization is required.

[0006] However, the above synchronization scheme has the following defects:

[0007] 1. Full synchronization consumes a lot of system resources, resulting in poor performance.

[0008] 2. Timestamp synchronization may cause data loss due to inconsistent server time and is easily affected by clock deviation. For example, the time of server A is 5 seconds slower than that of server B. Server A is responsible for the business of changing data, and server B is responsible for synchronizing data, synchronizing data every 3 seconds; assuming that server B synchronizes data at 07 seconds, the time of server A is 02 seconds at this time, and server A updates data at 03 seconds, so the update time of data is 03 seconds. At this time, server B performs synchronization operation at 10 seconds. It is determined that the update time of data is not within the range of 07-10 seconds, so no synchronization operation is performed, resulting in data loss.

[0009] 3. Tag synchronization cannot handle data rollback scenarios. For example, if there is 30 yuan in account A and 60 yuan in account B, and A transfers 10 yuan to B, the balance in A becomes 20 yuan and the balance in B becomes 70 yuan. If the data is synchronized to another database at this time, the synchronization of 20 yuan in account A is successful, but the synchronization of 70 yuan in account B fails, which leads to data consistency issues. Summary of the invention

[0010] The present invention provides a data synchronization method, device, equipment and storage medium based on a version chain, which are used to solve the technical problem that the existing data synchronization method has a poor synchronization effect.

[0011] The present invention provides a data synchronization method based on a version chain, which is applied to a data sender, wherein the data sender communicates with a data receiver; the method comprises:

[0012] When a data synchronization operation is triggered, the current data version number of the data to be synchronized is obtained;

[0013] Obtaining the synchronized version number of the data to be synchronized;

[0014] Determine whether the difference between the current data version number and the synchronized version number is 1;

[0015] If yes, synchronizing the data to be synchronized;

[0016] When the data to be synchronized completes synchronization, the synchronized version number is updated to the current data version number, and the data to be synchronized and the current data version number are sent to the data receiver. The data receiver saves the data to be synchronized, determines the version chain of the data to be synchronized, concatenates the current data version number to the head of the version chain, and uses the current data version number as the synchronized version number.

[0017] Optionally, it also includes:

[0018] When a data update operation is triggered, determine whether the version chain to be updated is in a synchronized state;

[0019] If yes, add 2 to the synchronized version number to obtain the updated version number of the data to be updated;

[0020] When the synchronization operation of the version chain to be updated is completed, the version chain to be updated is updated using the data to be updated;

[0021] If the version chain to be updated is not in a synchronized state, the data to be updated is spliced ​​to the head of the version chain to be updated.

[0022] Optionally, it also includes:

[0023] When the data receiver receives the data query request from the data sender, the data receiver obtains the current data version chain of the data receiver;

[0024] Using the first version number of the current data version chain as the query version number;

[0025] Determine whether the data corresponding to the query version number has been deleted;

[0026] If yes, return NULL to the data sender;

[0027] If not, determining whether the query version number is less than or equal to the synchronized version number;

[0028] If it is greater, the next data version number is used as the query version number, and the process returns to the step of determining whether the data corresponding to the query version number has been deleted;

[0029] If it is less than or equal to, the query version number is returned to the data sender to determine whether there is a synchronization anomaly through the query version number.

[0030] Optionally, it also includes:

[0031] When the data deletion operation is triggered, check in turn whether the head node of each version chain is marked for deletion;

[0032] If yes, delete the corresponding version chain.

[0033] The present invention also provides a version chain data synchronization device, which is applied to a data sender, and the data sender communicates with a data receiver; the device includes:

[0034] The current data version number acquisition module is used to obtain the current data version number of the data to be synchronized when the data synchronization operation is triggered;

[0035] A synchronized version number acquisition module, used to acquire the synchronized version number of the data to be synchronized;

[0036] A difference judgment module is used to judge whether the difference between the current data version number and the synchronized version number is 1;

[0037] A synchronization module, configured to synchronize the data to be synchronized;

[0038] A data sending module is used to update the synchronized version number to the current data version number when the data to be synchronized has completed synchronization, and send the data to be synchronized and the current data version number to the data receiver. The data receiver saves the data to be synchronized, determines the version chain of the data to be synchronized, splices the current data version number to the head of the version chain, and uses the current data version number as the synchronized version number.

[0039] Optionally, it also includes:

[0040] The synchronization status judgment module is used to judge whether the version chain to be updated is in a synchronization state when a data update operation is triggered;

[0041] A module for generating a version number to be updated, configured to, if yes, add 2 to the synchronized version number to obtain the version number to be updated as the version number to be updated of the data to be updated;

[0042] An updating module, configured to update the version chain to be updated with the data to be updated when the synchronization operation of the version chain to be updated is completed;

[0043] The splicing module is used to splice the data to be updated to the head of the version chain to be updated if the version chain to be updated is not in a synchronized state.

[0044] Optionally, it also includes:

[0045] A current data version chain acquisition module, used to acquire the current data version chain of the data recipient when the data recipient receives the data query request of the data sender;

[0046] A query version number determination module, used to use the first version number of the current data version chain as the query version number;

[0047] A deletion judgment module is used to judge whether the data corresponding to the query version number has been deleted;

[0048] A null return module, used for returning null to the data sender if yes;

[0049] A less than or equal to judgment module, used to judge whether the query version number is less than or equal to the synchronized version number;

[0050] The step return module is used to, if it is greater than, use the next data version number as the query version number, and return to the step of determining whether the data corresponding to the query version number has been deleted;

[0051] The query version number returning module is used to return the query version number to the data sender if it is less than or equal to, so as to determine whether there is a synchronization anomaly through the query version number.

[0052] Optionally, it also includes:

[0053] The deletion mark retrieval module is used to retrieve whether the head node of each version chain is marked as deleted when the data deletion operation is triggered;

[0054] The version chain deletion module is used to delete the corresponding version chain if so.

[0055] The present invention also provides an electronic device, the device comprising a processor and a memory:

[0056] The memory is used to store program code and transmit the program code to the processor;

[0057] The processor is used to execute the version chain-based data synchronization method as described in any one of the above items according to the instructions in the program code.

[0058] The present invention also provides a computer-readable storage medium, which is used to store program code, and the program code is used to execute the version chain-based data synchronization method as described in any one of the above items.

[0059] It can be seen from the above technical scheme that the present invention has the following advantages: the present invention provides a data synchronization method based on version chain, and specifically discloses: when the data synchronization operation is triggered, the current data version number of the data to be synchronized is obtained; the synchronized version number of the data to be synchronized is obtained; it is determined whether the difference between the current data version number and the synchronized version number is 1; if so, the data to be synchronized is synchronized; when the data to be synchronized is synchronized, the synchronized version number is updated to the current data version number, and the data to be synchronized and the current data version number are sent to the data receiver, the data receiver saves the data to be synchronized, determines the version chain of the data to be synchronized, splices the current data version number at the head of the version chain, and uses the current data version number as the synchronized version number. The present invention performs data synchronization management through the version chain, and by comparing the version numbers, it can be determined whether data synchronization is currently required, and at the same time, only the data that has generated version changes can be updated, which reduces resource consumption and improves data synchronization effect and synchronization efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0060] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, 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.

[0061] Figure 1 A flowchart of a data synchronization method based on a version chain provided by an embodiment of the present invention;

[0062] Figure 2 A schematic diagram of the version chain structure provided by an embodiment of the present invention;

[0063] Figure 3 A synchronous state diagram of a data sender provided by an embodiment of the present invention;

[0064] Figure 4 A synchronous state diagram of a data receiver provided by an embodiment of the present invention;

[0065] Figure 5 A data update state diagram provided by an embodiment of the present invention;

[0066] Figure 6 A data query state diagram provided by an embodiment of the present invention;

[0067] Figure 7 A data deletion state diagram provided by an embodiment of the present invention;

[0068] Figure 8 A data cleaning state diagram provided by an embodiment of the present invention;

[0069] Fig. 9 A structural block diagram of a version chain data synchronization device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0070] The embodiments of the present invention provide a data synchronization method, apparatus, device and storage medium based on a version chain, which are used to solve the technical problem that the existing data synchronization method has a poor synchronization effect.

[0071] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0072] See also Figure 1 , Figure 1 A flowchart of the steps of a data synchronization method based on a version chain provided in an embodiment of the present invention.

[0073] A data synchronization method based on a version chain provided by the present invention is applied to a data sender, and the data sender communicates with a data receiver; specifically, the method may include the following steps:

[0074] Step 101, when a data synchronization operation is triggered, the current data version number of the data to be synchronized is obtained;

[0075] Step 102, obtaining the synchronized version number of the data to be synchronized;

[0076] Step 103, determine whether the difference between the current data version number and the synchronized version number is 1;

[0077] Step 104: If yes, synchronize the data to be synchronized;

[0078] Step 105, when the data to be synchronized is synchronized, the synchronized version number is updated to the current data version number, and the data to be synchronized and the current data version number are sent to the data receiver. The data receiver saves the data to be synchronized, determines the version chain of the data to be synchronized, splices the current data version number at the head of the version chain, and uses the current data version number as the synchronized version number.

[0079] In the embodiment of the present invention, the version chain of data can be as follows: Figure 2 As shown, each version chain includes multiple versions of a data, and each version includes a version number, a pointer to the previous version, and an indicator of whether it has been deleted.

[0080] When the data synchronization operation is triggered on the data sender, the current data version number of the data to be synchronized and the synchronized version number of the data saved by the data sender can be obtained, and whether to perform the synchronization operation is selected by judging whether the value of the current data version number is 1 greater than the synchronized version number. When the current data version number is 1 greater than the value of the synchronized version number, it indicates that the data to be synchronized is the data that needs to be synchronized currently. At this time, the data to be synchronized can be synchronized to the storage space of the data sender, and the synchronized version number is updated to the current data version number of the data to be synchronized.

[0081] When the data receiver receives the data to be synchronized and its corresponding current data version number from the data sender, it can save the data to be synchronized, splice the current data version number to the head of the version chain saved by itself, and use the current data version number to update the synchronized version number.

[0082] like Figure 3 As shown in , when the synchronization operation is triggered, the data sender records the current state as being synchronized, and then starts from the head node of the version chain of the data to be synchronized, that is, the latest version of the data, to determine whether the current data version number is the synchronized version number plus 1. Figure 3 The current version number of the data to be synchronized in data1 is 3.0, and the synchronized version number is 2.0, so the data to be synchronized is saved, and the current data version number 3.0 is added to the version chain. The same is true for Data2.

[0083] like Figure 4 As shown in the figure, when the data receiver receives new data from the data sender, it can splice the current data version number of the new data to the head of the current version chain to obtain a new version chain, and use the current data version number to update the synchronized version number. For example, if the synchronized version number of data1 is 2.0 and the version number synchronized by the version chain is 2.0, after receiving the new data, the version number of the new data can be spliced ​​to the front of the version number 2.0, and the pointer points to version 2.0, and the synchronized version number is updated with the version number of the new data.

[0084] The present invention performs data synchronization management through a version chain. By comparing version numbers, it can be determined whether data synchronization is currently required. At the same time, only data with version changes can be updated, thereby reducing resource consumption and improving data synchronization effect and synchronization efficiency.

[0085] Further, in the embodiment of the present invention, when the data sender performs a synchronization operation, an update operation may be synchronously triggered, and the specific process may include the following steps:

[0086] S11, when a data update operation is triggered, determine whether the version chain to be updated is in a synchronized state;

[0087] S12, if yes, add 2 to the synchronized version number as the version number of the data to be updated;

[0088] S13, when the version chain to be updated completes the synchronization operation, the version chain to be updated is updated using the data to be updated;

[0089] S14: If the version chain to be updated is not in a synchronized state, the data to be updated is spliced ​​to the head of the version chain to be updated.

[0090] In the specific implementation, Figure 5 As shown, Figure 5 The data update status diagram is shown below. When the data sender receives an update operation for data2, it can first determine whether the current version chain to be updated is in a synchronized state. If so, the synchronized version number is obtained as 2.0, and the synchronized version number 2.0 is added by 2 to obtain version number 4.0, and version number 4.0 is used as the version number to be updated of the data to be updated. The purpose is to avoid conflicts between the version number of the data to be updated and the version number of the data currently being synchronized, resulting in missing synchronization of the data to be updated. When the version chain to be updated is synchronized, the version number to be updated can be spliced ​​to the head of the version chain after synchronization is completed, and the data to be updated is synchronized.

[0091] It should be noted that if multiple pieces of data are updated at the same time, the data updated at the same time need to be set with the same version number to ensure data consistency.

[0092] In addition, when a data update operation is triggered, if the version chain to be updated is not in a synchronized state, the version number of the data to be updated can be increased by 1 based on the synchronized version number, and the data update operation is performed. The specific process is the same as the data synchronization process.

[0093] Furthermore, in the embodiment of the present invention, it is possible to determine whether the data receiver has completed the data synchronization operation when receiving the synchronization data from the data sender by querying the data. The specific steps are as follows:

[0094] S21, when the data receiver receives the data query request from the data sender, the data receiver obtains the current data version chain;

[0095] S22, taking the first version number of the current data version chain as the query version number;

[0096] S23, determining whether the data corresponding to the query version number has been deleted;

[0097] S24, if yes, return null to the data sender;

[0098] S25, if not, determine whether the query version number is less than or equal to the synchronized version number;

[0099] S26, if it is greater, taking the next data version number as the query version number, and returning to the step of determining whether the data corresponding to the query version number has been deleted;

[0100] S27: If it is less than or equal to, the query version number is returned to the data sender to determine whether there is a synchronization anomaly through the query version number.

[0101] In the specific implementation, Figure 6 As shown, Figure 6 The following is a data query status diagram. When the data query operation is triggered, the search starts from the head of the current data version chain, and each version number is used as the query version number in turn; it is determined whether the data corresponding to the query version number has been deleted. If it has been deleted, it returns null to the data sender, otherwise it is determined whether the query version number is less than or equal to the synchronized version number. When the query version number is greater than the synchronized version number, it indicates that the data is in a synchronized state, and the synchronization cannot be guaranteed to be successful. At this time, the next version number is queried to obtain the version data actually saved by the current data receiver. When the query version number is equal to the synchronized version number, the data synchronization is completed. At this time, the query version number is returned to the data sender to inform the data sender of the data to complete the synchronization. When the query version number is less than the saved version number, it indicates that the data may be inconsistent. At this time, the query version number is sent to the data sender to inform the data sender that the data receiver may have data inconsistency problems at this time.

[0102] Furthermore, in the embodiment of the present invention, if a certain data is to be deleted, a deletion mark can be added to the version information of the synchronized data, and when the deletion mark is detected, the complete data can be directly deleted. The specific steps are as follows:

[0103] S31, when a data deletion operation is triggered, the head node of each version chain is sequentially retrieved to see whether it is marked as deleted;

[0104] S32: If yes, delete the corresponding version chain.

[0105] like Figure 7 As shown, Figure 7 This is a data deletion state diagram. Data2 version 4.0 has a data deletion mark. When the useless data is regularly cleared, if the mark is detected, the entire data2 can be directly deleted.

[0106] Furthermore, if Figure 8 As shown, Figure 8 For the data cleaning state diagram, in order to avoid the resource pressure caused by the growing version chain, you can traverse the version chain and delete the Ith (such as 3, the specific number is selected according to the actual situation) node and the subsequent data.

[0107] See also Fig. 9 , Fig. 9A structural block diagram of a version chain data synchronization device provided in an embodiment of the present invention.

[0108] The embodiment of the present invention provides a version chain data synchronization device, which is applied to a data sender, and the data sender communicates with a data receiver; the device includes:

[0109] The current data version number acquisition module 901 is used to acquire the current data version number of the data to be synchronized when the data synchronization operation is triggered;

[0110] The synchronized version number acquisition module 902 is used to acquire the synchronized version number of the data to be synchronized;

[0111] The difference determination module 903 is used to determine whether the difference between the current data version number and the synchronized version number is 1;

[0112] A synchronization module 904, configured to synchronize the data to be synchronized if yes;

[0113] The data sending module 905 is used to update the synchronized version number to the current data version number when the data to be synchronized is synchronized, and send the data to be synchronized and the current data version number to the data receiver. The data receiver saves the data to be synchronized, determines the version chain of the data to be synchronized, splices the current data version number at the head of the version chain, and uses the current data version number as the synchronized version number.

[0114] In an embodiment of the present invention, it also includes:

[0115] The synchronization status judgment module is used to judge whether the version chain to be updated is in a synchronization state when a data update operation is triggered;

[0116] A module for generating a version number to be updated, for, if yes, adding 2 to the synchronized version number as the version number to be updated of the data to be updated;

[0117] An update module, used to update the version chain to be updated with the data to be updated when the version chain to be updated completes the synchronization operation;

[0118] The splicing module is used to splice the data to be updated to the head of the version chain to be updated if the version chain to be updated is not in a synchronized state.

[0119] In an embodiment of the present invention, it also includes:

[0120] The current data version chain acquisition module is used to acquire the current data version chain of the data receiver when the data receiver receives the data query request from the data sender;

[0121] A query version number determination module is used to use the first version number of the current data version chain as the query version number;

[0122] A deletion judgment module is used to judge whether the data corresponding to the query version number has been deleted;

[0123] The empty return module is used to return empty to the data sender if yes;

[0124] A less than or equal to judgment module is used to judge whether the query version number is less than or equal to the synchronized version number;

[0125] The step return module is used to, if it is greater than, use the next data version number as the query version number, and return to the step of determining whether the data corresponding to the query version number has been deleted;

[0126] The query version number return module is used to return the query version number to the data sender if it is less than or equal to, so as to determine whether there is a synchronization anomaly through the query version number.

[0127] In an embodiment of the present invention, it also includes:

[0128] The deletion mark retrieval module is used to retrieve whether the head node of each version chain is marked as deleted when the data deletion operation is triggered;

[0129] The version chain deletion module is used to delete the corresponding version chain if so.

[0130] An embodiment of the present invention further provides an electronic device, the device comprising a processor and a memory:

[0131] The memory is used to store the program code and transmit the program code to the processor;

[0132] The processor is used to execute the version chain-based data synchronization method of an embodiment of the present invention according to the instructions in the program code.

[0133] An embodiment of the present invention further provides a computer-readable storage medium, which is used to store program code, and the program code is used to execute the version chain-based data synchronization method of an embodiment of the present invention.

[0134] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0135] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0136] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0137] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0138] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0139] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0140] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0141] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0142] As described above, the above embodiments 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 thereof may be replaced by equivalents. However, these 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.

Claims

1. A data synchronization method based on version chain, characterized in that: Applied to a data sender, the data sender communicates with a data receiver; the method comprises: When a data synchronization operation is triggered, the current data version number of the data to be synchronized is obtained; Obtaining the synchronized version number of the data to be synchronized; Determine whether the difference between the current data version number and the synchronized version number is 1; If yes, synchronizing the data to be synchronized; When the data to be synchronized completes synchronization, the synchronized version number is updated to the current data version number, and the data to be synchronized and the current data version number are sent to the data receiver. The data receiver saves the data to be synchronized, determines the version chain of the data to be synchronized, concatenates the current data version number to the head of the version chain, and uses the current data version number as the synchronized version number.

2. The method according to claim 1, characterized in that Also includes: When a data update operation is triggered, determine whether the version chain to be updated is in a synchronized state; If yes, add 2 to the synchronized version number to obtain the updated version number of the data to be updated; When the synchronization operation of the version chain to be updated is completed, the version chain to be updated is updated using the data to be updated; If the version chain to be updated is not in a synchronized state, the data to be updated is spliced ​​to the head of the version chain to be updated.

3. The method according to claim 1, characterized in that Also includes: When the data receiver receives the data query request from the data sender, the data receiver obtains the current data version chain of the data receiver; Using the first version number of the current data version chain as the query version number; Determine whether the data corresponding to the query version number has been deleted; If yes, return NULL to the data sender; If not, determining whether the query version number is less than or equal to the synchronized version number; If it is greater, the next data version number is used as the query version number, and the process returns to the step of determining whether the data corresponding to the query version number has been deleted; If it is less than or equal to, the query version number is returned to the data sender to determine whether there is a synchronization anomaly through the query version number.

4. The method according to claim 1, characterized in that: Also includes: When the data deletion operation is triggered, check in turn whether the head node of each version chain is marked for deletion; If yes, delete the corresponding version chain.

5. A version chain data synchronization device, characterized in that: Applied to a data sender, the data sender communicates with a data receiver; the device comprises: The current data version number acquisition module is used to obtain the current data version number of the data to be synchronized when the data synchronization operation is triggered; A synchronized version number acquisition module, used to acquire the synchronized version number of the data to be synchronized; A difference judgment module is used to judge whether the difference between the current data version number and the synchronized version number is 1; A synchronization module, configured to synchronize the data to be synchronized; A data sending module is used to update the synchronized version number to the current data version number when the data to be synchronized has completed synchronization, and send the data to be synchronized and the current data version number to the data receiver. The data receiver saves the data to be synchronized, determines the version chain of the data to be synchronized, splices the current data version number to the head of the version chain, and uses the current data version number as the synchronized version number.

6. The device according to claim 5, characterized in that Also includes: The synchronization status judgment module is used to judge whether the version chain to be updated is in a synchronization state when a data update operation is triggered; A module for generating a version number to be updated, configured to, if yes, add 2 to the synchronized version number to obtain the version number to be updated as the version number to be updated of the data to be updated; An updating module, configured to update the version chain to be updated with the data to be updated when the synchronization operation of the version chain to be updated is completed; The splicing module is used to splice the data to be updated to the head of the version chain to be updated if the version chain to be updated is not in a synchronized state.

7. The device according to claim 5, characterized in that Also includes: A current data version chain acquisition module, used to acquire the current data version chain of the data recipient when the data recipient receives the data query request of the data sender; A query version number determination module, used to use the first version number of the current data version chain as the query version number; A deletion judgment module, used to judge whether the data corresponding to the query version number has been deleted; A null return module, used for returning null to the data sender if yes; A less than or equal to judgment module, used to judge whether the query version number is less than or equal to the synchronized version number; The step return module is used to, if it is greater than, use the next data version number as the query version number, and return to the step of determining whether the data corresponding to the query version number has been deleted; The query version number returning module is used to return the query version number to the data sender if it is less than or equal to, so as to determine whether there is a synchronization anomaly through the query version number.

8. The device according to claim 5, characterized in that Also includes: The deletion mark retrieval module is used to retrieve whether the head node of each version chain is marked as deleted when the data deletion operation is triggered; The version chain deletion module is used to delete the corresponding version chain if so.

9. An electronic device, characterized in that: The device comprises a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is used to execute the version chain-based data synchronization method described in any one of claims 1-4 according to the instructions in the program code.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store program code, and the program code is used to execute the version chain-based data synchronization method described in any one of claims 1-4.