Data synchronization method and electronic equipment
By detecting and processing data conflicts between electronic devices and generating the third and fourth data, the problem of data synchronization abnormality after multiple electronic devices modify the same user data is solved, and data consistency and user experience are improved.
Patent Information
- Application Number
- CN202311636512.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-29
- Publication Date
- 2025-06-06
AI Technical Summary
When multiple electronic devices modify the same user data, there may be problems with different amounts of data after data synchronization, resulting in data conflicts and synchronization abnormalities, affecting the user experience.
When the first electronic device receives the data sent by the second electronic device, it is judged whether there are conflicting data between the data, and processed based on the conflicting data, and ensures that the number of data is consistent after data synchronization.
It effectively avoids data synchronization exceptions, ensures improvement of user experience, and ensures data consistency through data conflict handling mechanism.
Smart Images

Figure CN120104693A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminals, and in particular to a data synchronization method and an electronic device. Background Art
[0002] With the development of terminal technology, the number of electronic devices owned by users is increasing, and the scenario in which users use multiple electronic devices at the same time is becoming more and more common.
[0003] Currently, when a user operates multiple electronic devices, in order to achieve data sharing between different electronic devices, data synchronization needs to be performed between the different electronic devices.
[0004] However, when multiple electronic devices have modified the same user data separately, the amount of data in the multiple electronic devices may be different after data synchronization, that is, the same user data corresponds to a conflict of multiple operation data. The electronic devices cannot handle the above situation, which leads to abnormalities in subsequent data synchronization and affects the user experience. Summary of the invention
[0005] The present application provides a data synchronization method and an electronic device to avoid data synchronization anomalies as much as possible and ensure the user experience.
[0006] In a first aspect, the present application provides a data synchronization method, which is applied to a first electronic device, the first electronic device is applied to a first communication system, the first communication system includes a first electronic device and a second electronic device, the method includes:
[0007] When receiving first data sent by a second electronic device, determine whether there is conflicting data between the first data and the second data, the first data is operation data generated by an operation on user data in the second electronic device, the second data is operation data generated by an operation on user data in the first electronic device, and the conflicting data is operation data generated by an operation on the same user data in the first data and the second data; when there is conflicting data between the first data and the second data, obtain third data based on the first data and the conflicting data, the third data includes first sub-data and second sub-data, the first sub-data is data generated latest in the conflicting data, and the second sub-data is data generated earlier than the first sub-data in the conflicting data and renamed; obtain fourth data based on the second data and the conflicting data, the fourth data includes the first sub-data and the second sub-data; send the fourth data to the second electronic device so that the second electronic device obtains the fourth data, and the total data quantity of the fourth data and the first data is the same as the total data quantity of the third data and the second data.
[0008] In the above method, when the first electronic device receives the first data sent by the second electronic device, it can determine whether there is conflicting data between the first data and the second data. Since the user may operate the same user data on the first electronic device and the second electronic device, thereby generating different operation data, there is conflicting data between the first data and the second data.
[0009] For example, the first data includes operation record data generated by modifying the nose part of the face in the face image 1; the second data includes operation record data generated by modifying the ear part of the face in the face image 1.
[0010] Then, the two pieces of data in the above example are conflicting data, that is, all of the first data are conflicting data, and all of the second data are conflicting data.
[0011] Based on this, the third data includes the data with the latest generation time in the conflicting data and the data with the generation time earlier than the first sub-data in the conflicting data and renamed. That is to say, the first electronic device can rename all the old data in the conflicting data by renaming all the data before the data with the latest generation time in the conflicting data, and retain the data with the latest generation time, so that all the first data synchronized from the second electronic device are retained, thereby realizing the synchronization of data from the second electronic device to the first electronic device.
[0012] In addition, the first electronic device can also obtain fourth data based on the second data and the conflicting data, and the fourth data includes the data in the conflicting data that is generated latest and the data in the conflicting data that is generated earlier than the first sub-data and is renamed. That is to say, the first electronic device can rename all the old data in the conflicting data by renaming all the data before the data in the conflicting data that is generated latest, and retain the data with the latest generation time, so that all the second data generated by the first electronic device can be synchronized to the second electronic device, and it is guaranteed that there is no data conflict after synchronization.
[0013] In addition, the first electronic device can also send fourth data to the second electronic device so that the second electronic device obtains the fourth data. In this way, after synchronization, the total data quantity of the fourth data and the first data is the same as the total data quantity of the third data and the second data. Therefore, the next time the second electronic device synchronizes the first data to the first electronic device, it can synchronize data to the first electronic device according to the maximum sequence value after the current synchronization to avoid the situation where the first electronic device misses to synchronize data to the first electronic device. As a result, abnormalities in subsequent synchronization of data can be avoided and the user experience can be improved.
[0014] In combination with the first aspect, in some implementations of the first aspect, the third data further includes third sub-data, and the third sub-data is data in the first data that is not conflicting data.
[0015] In combination with the first aspect, in some implementations of the first aspect, the fourth data further includes fourth sub-data, and the fourth sub-data is data in the second data that is not conflicting data.
[0016] For example, the first data includes operation record data generated by modifying the nose area of the face in face image 1 and operation record data generated by dialing mobile phone number 1.
[0017] The second data includes operation record data generated by modifying the ear area of the face in the face image 1, and operation record data generated by deleting part of the text in the file 1.
[0018] Then, the operation record data generated by modifying the nose part of the face in face image 1 in the first data in the aforementioned example and the operation record data generated by modifying the ear part of the face in face image 1 in the second data are conflicting data.
[0019] Then, the first data includes data belonging to conflicting data and data not belonging to conflicting data. Thus, the third data includes first sub-data, second sub-data and third sub-data, and the third sub-data is data in the first data not belonging to conflicting data.
[0020] Similarly, the second data includes data that is conflicting data and data that is not conflicting data. Thus, the fourth data includes the first sub-data, the second sub-data and the fourth sub-data. The fourth sub-data is the data that is not conflicting data in the second data.
[0021] In the above method, the third data includes the data with the latest generation time in the conflicting data, the data with the generation time earlier than the first sub-data in the conflicting data and renamed, and the data in the first data that does not belong to the conflicting data. That is to say, the first electronic device can rename all the old data in the conflicting data by renaming all the data before the data with the latest generation time in the conflicting data, and retain the data with the latest generation time, and obtain the third data with the data in the first data that does not belong to the conflicting data, so that all the first data synchronized by the second electronic device are retained, thereby realizing the synchronization of data from the second electronic device to the first electronic device.
[0022] In addition, the first electronic device can also obtain fourth data based on the second data and the conflicting data, and the fourth data includes the data in the conflicting data that is generated latest, the data in the conflicting data that is generated earlier than the first sub-data and is renamed, and the data in the second data that does not belong to the conflicting data. That is to say, the first electronic device can rename all the old data in the conflicting data by renaming all the data before the data in the conflicting data that is generated latest, and retain the data with the latest generation time, and obtain the fourth data with the data in the second data that does not belong to the conflicting data, so that all the second data generated by the first electronic device can be synchronized with the second electronic device, and it is guaranteed that there is no data conflict after synchronization.
[0023] In combination with the first aspect, in certain implementations of the first aspect, the first data includes first attribute information of operation data generated by operations on user data in the second electronic device, and the second data includes first attribute information of operation data generated by operations on user data in the first electronic device; determining whether there is conflicting data between the first data and the second data includes: determining whether the first attribute information of the first data and the first attribute information of the second data have the same attribute information.
[0024] In the above method, the first electronic device can determine whether there is conflicting data between the first data and the second data according to the first attribute information.
[0025] In combination with the first aspect, in certain implementations of the first aspect, the first attribute information includes at least one of a data sequence number, a data identifier, an operation content, and a generation time, and determining whether there is the same attribute information between the first attribute information of the first data and the first attribute information of the second data includes: determining whether there is the same data identifier between the data identifier of the first data and the data identifier of the second data.
[0026] In the above method, the first electronic device can determine whether there is conflicting data between the first data and the second data according to the data identifier in the first attribute information.
[0027] For example, the first data includes data 1, the data identifier of data 1 is key1, and the second data includes data 2, the data identifier of data 2 is key1. Then, the data identifier of the first data and the data identifier of the second data are the same, and there is conflicting data between the first data and the second data.
[0028] The first attribute information may also include a data type.
[0029] For example, the first attribute information may include data sequence number, data identifier, data type, operation content and generation time.
[0030] In combination with the first aspect, in certain implementations of the first aspect, the conflict data includes second attribute information corresponding to operation data generated by operations on the same user data in the first data and the second data, the second attribute information includes at least one of data identification, operation content, generation time and label information, the label information is used to indicate whether each data in the conflict data is the data with the latest generation time, and the label information is determined based on the generation time.
[0031] In the above method, the second attribute information further includes tag information, and through the tag information, the first electronic device can determine which data in the conflicting data is to be renamed and which data is not to be renamed.
[0032] The second attribute information may also include a data type.
[0033] For example, the third attribute information may include data identification, data type, operation content, generation time and label information.
[0034] In combination with the first aspect, in certain implementations of the first aspect, the third data includes third attribute information of the first sub-data, third attribute information of the second sub-data, and third attribute information of the third sub-data, and the third attribute information includes at least one of a data identifier and an operation content.
[0035] In the above method, the third attribute information may further include a data type.
[0036] For example, the third attribute information includes data identification, data type, and operation content.
[0037] In combination with the first aspect, in certain implementations of the first aspect, the fourth data includes first attribute information of the first sub-data, first attribute information of the second sub-data, and first attribute information of the fourth sub-data, and the first attribute information includes at least one of a data sequence number, a data identifier, an operation content, and a generation time.
[0038] In combination with the first aspect, in certain implementations of the first aspect, after obtaining the third data according to the first data and the conflicting data, the method further includes: storing the third data in a database of the first electronic device.
[0039] In the above method, after obtaining the third data, the first electronic device may store the third data in a database of the first electronic device.
[0040] In combination with the first aspect, in some implementations of the first aspect, the first communication system further includes a third electronic device, data transmission between the third electronic device and the second electronic device is completed through the first electronic device, and when the operation data generated by the operation on the user data in the first electronic device is the data sent by the third electronic device, when receiving the first data sent by the second electronic device, before the first data and the second data, the method further includes:
[0041] After receiving the second data sent by the third electronic device and obtaining the third data according to the first data and the conflicting data, the method further includes: sending the third data to the third electronic device.
[0042] In the above method, the second electronic device can send the third data to the third electronic device through the first electronic device, so that the second electronic device can successfully synchronize data with the third electronic device.
[0043] In a second aspect, the present application provides a data synchronization method, which is applied to a second electronic device, where the second electronic device is applied to a first communication system, where the first communication system includes the first electronic device and the second electronic device, and the method includes:
[0044] When data is generated after the original data in the second electronic device is detected, the data after the original data is determined as the first data; or the data after the original data is periodically determined as the first data, the first data is the operation data generated by the operation on the user data in the second electronic device; the first data is sent to the first electronic device; when the fourth data is received, the fifth data is obtained according to the fourth data; wherein the fourth data is obtained according to the second data and the conflicting data, the conflicting data is obtained according to the first data and the second data, the second data is the operation data generated by the operation on the user data in the first electronic device, the conflicting data is the operation data generated by the operation on the same user data in the first data and the second data, the fourth data includes the first sub-data and the second sub-data, and the generation time corresponding to the first sub-data and the second sub-data respectively, the first sub-data is the data with the latest generation time in the conflicting data, the second sub-data is the data in the conflicting data that is generated earlier than the first sub-data and renamed, the fifth data includes the first sub-data and the second sub-data, the total data quantity of the fifth data and the first data is the same as the total data quantity of the third data and the second data, the third data is obtained according to the first data and the conflicting data, and the third data includes the first sub-data and the second sub-data.
[0045] In the above method, as the user performs operations on the second electronic device, the second electronic device can generate first data, so the second electronic device can send the first data to the first electronic device, so as to synchronize the first data to the first electronic device.
[0046] In addition, since the first electronic device can send the fourth data to the second electronic device after obtaining the fourth data to be synchronized to the second electronic device, it is convenient to synchronize the fourth data to the second electronic device. After receiving the fourth data, the second electronic device can obtain the fifth data based on the fourth data, and the second electronic device can store the fifth data. Therefore, the first electronic device successfully synchronizes data with the second electronic device.
[0047] In combination with the second aspect, in some implementations of the second aspect, the third data further includes third sub-data, and the third sub-data is data in the first data that is not conflicting data.
[0048] In combination with the second aspect, in some implementations of the second aspect, the fourth data further includes fourth sub-data and generation time of the fourth sub-data, and the fourth sub-data is data in the second data that is not conflicting data.
[0049] In combination with the second aspect, in some implementations of the second aspect, the fifth data also includes fourth sub-data, and the fifth data includes third attribute information of the first sub-data, third attribute information of the second sub-data, and third attribute information of the fourth sub-data.
[0050] In combination with the second aspect, in some implementations of the second aspect, after receiving the fourth data and generating the fifth data according to the fourth data, the method further includes:
[0051] The fifth data is stored in a database of the second electronic device.
[0052] In the above method, after obtaining the fifth data, the second electronic device may store the fifth data in a database of the second electronic device.
[0053] In a third aspect, the present application provides a data synchronization device, which is used to execute the data synchronization method in the first aspect and any possible implementation of the first aspect.
[0054] In a fourth aspect, the present application provides a data synchronization device, which is used to execute the data synchronization method in the second aspect and any possible implementation manner of the second aspect.
[0055] In a fifth aspect, the present application provides an electronic device comprising one or more processors, a memory and one or more computer programs, wherein the one or more computer programs are stored in the memory, and when the computer programs are executed by one or more processors, the electronic device executes the data synchronization method in the first aspect and any possible implementation of the first aspect, and / or the data synchronization method in the second aspect and any possible implementation of the second aspect.
[0056] In a sixth aspect, the present application provides a chip system, which includes a processor for calling and running a computer program from a memory, so that an electronic device equipped with the chip system executes the data synchronization method in the first aspect and any possible implementation of the first aspect, and / or the data synchronization method in the second aspect and any possible implementation of the second aspect.
[0057] In the seventh aspect, the present application provides a computer-readable storage medium, including a computer program. When the computer program runs on an electronic device, the electronic device executes the data synchronization method in the first aspect and any possible implementation of the first aspect, and / or the data synchronization method in the second aspect and any possible implementation of the second aspect.
[0058] In an eighth aspect, the present application provides a computer program product. When the computer program product runs on a computer, it enables the computer to execute the data synchronization method in the first aspect and any possible implementation of the first aspect, and / or the data synchronization method in the second aspect and any possible implementation of the second aspect.
[0059] It can be understood that the beneficial effects of the third to eighth aspects can be found in the relevant descriptions of the first and / or second aspects, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] Figure 1 A schematic diagram of a scenario of a data synchronization method provided by the prior art;
[0061] Figure 2 A schematic diagram of a scenario of a data synchronization method provided by the prior art;
[0062] Figure 3 A schematic diagram of a scenario of a data synchronization method provided by the prior art;
[0063] Figure 4 A schematic diagram of a scenario of a data synchronization method provided in an embodiment of the present application;
[0064] Figure 5 A schematic diagram of a scenario of a data synchronization method provided in an embodiment of the present application;
[0065] Figure 6 A schematic diagram of the structure of a synchronization database provided in one embodiment of the present application;
[0066] Figure 7 A schematic diagram of the structure of an electronic device provided in one embodiment of the present application;
[0067] Figure 8 A flowchart of a data synchronization method provided in one embodiment of the present application;
[0068] Fig. 9 A schematic diagram of a scenario of a data synchronization method provided in an embodiment of the present application;
[0069] Fig.10 A flowchart of a data synchronization method provided in one embodiment of the present application;
[0070] Fig.11 A schematic diagram of a software architecture provided for an embodiment of the present application;
[0071] Fig.12 A flowchart of a data synchronization method provided in accordance with an embodiment of the present application. DETAILED DESCRIPTION
[0072] In this application, "at least one" means one or more, and "plurality" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c alone can represent: a, b, c, a and b, a and c, or a, b, and c, where a, b, and c can be single or multiple. In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance.
[0073] With the development of terminal technology, the number of electronic devices owned by users is increasing, and the scenario in which users use multiple electronic devices at the same time is becoming more and more common.
[0074] Currently, when a user operates multiple electronic devices, data synchronization is often required across devices. In order to achieve data sharing between different electronic devices, data synchronization needs to be performed between different electronic devices.
[0075] like Figure 1As shown, before the first electronic device adds new data, the first electronic device includes 1000 pieces of data. Based on the user's operation, the first electronic device adds two pieces of data, namely data 1001 and data 1002. At this time, the first electronic device includes 1002 pieces of data; before the second electronic device adds new data, the second electronic device includes 1000 pieces of data. Based on the user's operation, the second electronic device adds two pieces of data, namely data 1001 and data 1002. At this time, the second electronic device includes 1002 pieces of data.
[0076] When synchronizing data between two electronic devices, the first electronic device can send the newly added local data 1001 and data 1002 in the first electronic device to the second electronic device, and store them after the local data 1001 and data 1002 in the second electronic device to form data 1003 and data 1004, so that the second electronic device includes 1001, data 1002, data 1003 and data 1004. At this time, the second electronic device includes 1004 pieces of data.
[0077] Similarly, the second electronic device can send the newly added local data 1001 and data 1002 in the second electronic device to the first electronic device, and after storing the local data 1001 and data 1002 in the first electronic device, form data 1003 and data 1004, so that the first electronic device includes 1001, data 1002, data 1003 and data 1004. At this time, the first electronic device includes 1004 data.
[0078] Recombination Figure 2 It can be seen that the data in the first electronic device and the data in the second electronic device are completely different. If the first electronic device synchronizes data to the second electronic device, no data conflict will occur. Therefore, the data in the first electronic device can be directly synchronized to the second electronic device and stored after the local data of the second electronic device.
[0079] Similarly, if the second electronic device synchronizes data with the first electronic device, no data conflict will occur. Therefore, the data in the second electronic device can be directly synchronized to the first electronic device and stored after the local data of the first electronic device.
[0080] Thus, before synchronization, the number of data items in the first electronic device and the second electronic device is the same, both including 1002 items; after synchronization, the number of data items in the first electronic device and the second electronic device is also the same, both including 1004 items.
[0081] in, Figure 2 The key (key) is the key of the data corresponding to the operation record, and the value (value) is the value of the data corresponding to the operation record.
[0082] For example, Figure 2 In the example, key1 is used to represent face image 1, and value1 corresponding to key1 represents operation record data generated by modifying the nose part of the face in face image 1.
[0083] For another example, key2 is used to represent mobile phone number 1, and value2 corresponding to key2 represents the time when the mobile phone number 1 is dialed.
[0084] Recombination Figure 3 It can be seen that the keys corresponding to the data in the first electronic device and the data in the second electronic device are the same, which means that different operation record data obtained by processing the same user data exist in the first electronic device and the second electronic device.
[0085] For example, Figure 3 In the second electronic device, key1 is used to represent the face image 1, and value1 corresponding to key1 represents the operation record data generated by modifying the nose part of the face in the face image 1.
[0086] For example, Figure 3 In the first electronic device, key1 is used to represent the face image 1, and value11 corresponding to key1 represents the operation record data generated by modifying the ear part of the face in the face image 1.
[0087] Based on this, if the first electronic device synchronizes data to the second electronic device, a data conflict will occur. Value1 corresponding to key1 and value11 corresponding to key1 are conflicting data. The second electronic device will not be able to determine whether to store value1 corresponding to key1 in the second electronic device or value11 corresponding to key1 in the first electronic device.
[0088] It can be seen that the data in the first electronic device cannot be directly synchronized to the second electronic device, and is stored after the local data of the second electronic device.
[0089] Similarly, if the second electronic device synchronizes data with the first electronic device, a data conflict occurs and the first electronic device cannot determine whether to store value11 corresponding to key1 in the first electronic device or value1 corresponding to key1 in the second electronic device.
[0090] It can be seen that the data in the second electronic device cannot be directly synchronized to the first electronic device, and is stored after the local data of the first electronic device.
[0091] Taking the above situation into consideration, when synchronizing data from the first electronic device to the second electronic device, the second electronic device can store the data with the latest generation time (the latest data) among the operation record data generated by the operation on the same user data, and re-store the old data by renaming it (for example, adding a suffix).
[0092] Similarly, when the second electronic device synchronizes data with the first electronic device, the first electronic device can store the latest data in different operation record data corresponding to the same user data according to the timestamp, and re-store the old data by renaming (for example, adding a suffix).
[0093] in, Figure 3 The larger the timestamp value is, the later the time is; the smaller the timestamp value is, the earlier the time is.
[0094] For example, Figure 3 In the example, key1 is used to represent face image 1, value1 corresponding to key1 represents the operation record data generated by modifying the nose part of the face in face image 1, and value11 corresponding to key1 represents the operation record data generated by modifying the ear part of the face in face image 1. The time corresponding to timestamp 1 of value1 is earlier than the time corresponding to timestamp 3 of value11.
[0095] For another example, key2 is used to represent mobile phone number 1, and value2 corresponding to key2 represents the time when the mobile phone number 1 is dialed.
[0096] For another example, key3 is used to represent file 1, and value3 corresponding to key3 represents deleting part of the text in file 1.
[0097] It can be seen that value11 corresponding to key1 in the first electronic device and value1 corresponding to key1 in the second electronic device are different operation data obtained by processing the same user data, and are conflicting data.
[0098] Therefore, when the first electronic device synchronizes the data with serial numbers 1001 and 1002 in the first electronic device to the second electronic device, since according to the timestamp, the data generation time of value11 corresponding to key1 is later than the data generation time of value1 corresponding to key1, value11 corresponding to key1 is new data, and value1 corresponding to key1 is old data. The second electronic device can rename key1 corresponding to value1 to cf-key1 and save it, and do not process value11 corresponding to key1 but save it directly, and save the data of value3 corresponding to key3 in the first electronic device.
[0099] Similarly, when the second electronic device synchronizes data with serial numbers 1001 and 1002 in the second electronic device to the first electronic device, since according to the timestamp, the data generation time of value11 corresponding to key1 is later than the data generation time of value1 corresponding to key1, value11 corresponding to key1 is new data, and value1 corresponding to key1 is old data. The second electronic device can rename key1 corresponding to the data value1 sent by the second electronic device to cf-key1 and save it, and do not process value11 corresponding to key1.
[0100] Based on this, after the first electronic device synchronizes data to the second electronic device, and the second electronic device synchronizes data to the first electronic device, there are 1005 pieces of data in the second electronic device and 1004 pieces of data in the first electronic device, the amount of data in the first electronic device and the second electronic device is different, and the maximum sequence values (index) corresponding to the first electronic device and the second electronic device are different.
[0101] At this time, the maximum sequence value of the first electronic device is 1004, and the maximum sequence value of the second electronic device is 1005. If the user performs an operation on the second electronic device, causing the second electronic device to add a new piece of data (for example, deleting file 1), the data in the second electronic device becomes 1006, and the second electronic device can synchronize the 1006th piece of data to the first electronic device, and send the maximum sequence value 1005 to the first electronic device; if the user performs an operation on the first electronic device, causing the first electronic device to add two new pieces of data (for example, beautifying image 1 and adjusting the saturation of image 2), the data in the first electronic device can become 1006.
[0102] After receiving the 1006th piece of data and the maximum sequence value of 1005, the first electronic device can store the 1006th piece of data. Since the maximum sequence value sent by the second electronic device is 1005, the first electronic device can synchronize the data after the maximum sequence value in the first electronic device to the first electronic device based on the maximum sequence value sent by the second electronic device. In other words, the first electronic device can send the data after the sequence value 1005, i.e. the 1006th piece of data, to the second electronic device, resulting in the omission of sending the 1005th piece of data in the first electronic device to the second electronic device.
[0103] It can be seen that when multiple electronic devices modify the same user data, a conflict may occur where the identifier of the same user data corresponds to multiple operation data. It is difficult for the electronic devices to handle this situation, which may result in different amounts of data in multiple electronic devices after data synchronization, causing abnormalities in subsequent data synchronization and affecting the user experience.
[0104] In view of the above problems, the present application can provide a data synchronization method, an electronic device, a chip system, a computer-readable storage medium and a computer program product. When a first electronic device receives synchronization data sent by a second electronic device, it can determine the value data corresponding to the same key value in the synchronization data sent by the second electronic device and the local data in the first electronic device, that is, the conflicting data, rename the data generated earlier in the aforementioned conflicting data, save the renamed conflicting data, the unrenamed conflicting data, and the data that does not belong to the conflicting data in the aforementioned synchronization data to the first electronic device, and in addition, send the renamed conflicting data, the unrenamed conflicting data, and the data that does not belong to the conflicting data in the local data in the aforementioned first electronic device to the second electronic device for the second electronic device to save. This makes the amount of data stored in the first electronic device and the second electronic device the same, which can ensure the smooth progress of subsequent data synchronization and improve the user experience.
[0105] Among them, the data synchronization method provided in the present application can be applied to a communication system consisting of an electronic device and other electronic devices, and can also be applied to a communication system consisting of an electronic device, another electronic device and other electronic devices.
[0106] Specifically, an electronic device can directly synchronize data with other electronic devices; when an electronic device synchronizes data with other electronic devices, it can also first synchronize the data to another electronic device, and then the other electronic device synchronizes the data with the other electronic devices.
[0107] It should be noted that, in the above-mentioned method in which one electronic device synchronizes data to other electronic devices depending on another electronic device, the one electronic device and the other electronic devices need to add the other electronic device as a central device in advance, so that the one electronic device, the other electronic device and the other electronic devices form a communication system, so that the data synchronization between one electronic device and the other electronic devices depends on the other electronic device.
[0108] The one electronic device, the other electronic device and the other electronic device may be electronic devices of the same type or electronic devices of different types.
[0109] The above-mentioned electronic devices may be mobile phones, tablet computers, personal computers (PC), network attached storage (NAS), smart watches, vehicle-mounted devices, laptop computers, wearable devices, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), smart cars, smart TVs, robots and other devices.
[0110] It should be pointed out that in some possible implementations, the electronic device may also be called a terminal device, user equipment (UE), etc., which is not limited in the embodiments of the present application.
[0111] See also Figure 4 and Figure 5 , Figure 4 and Figure 5 A scenario diagram of a data synchronization method provided by an embodiment of the present application is shown.
[0112] The data synchronization method provided by this application can be Figure 4 This is achieved through the cooperation between the first electronic device and the second electronic device in the communication system shown.
[0113] For ease of explanation, Figure 4 In the present application, an example is given in which a first electronic device can synchronize data to a second electronic device, and a second electronic device can synchronize data to a first electronic device.
[0114] In some embodiments, when a user performs an operation (including adding, deleting, modifying, etc. data) on a first electronic device and generates new data, the first electronic device can synchronize the new data to a second electronic device and save it in a synchronization database of the second electronic device.
[0115] In other embodiments, when the user performs an operation on the second electronic device and generates new data, the second electronic device can synchronize the new data to the first electronic device and store it in the synchronization database of the first electronic device.
[0116] The data synchronization method provided by this application can also be used Figure 5 This is achieved through the cooperation among the first electronic device, the second electronic device and the third electronic device in the communication system shown.
[0117] Among them, when the first electronic device is turned on, it can create a synchronization group (sync group) as a central device. After the second electronic device is turned on, the second electronic device can add the second electronic device to the aforementioned synchronization group based on the user's operation. When the third electronic device is turned on, the third electronic device can add the third electronic device to the synchronization group based on the user's operation. Thus, a synchronization group can be formed between the second electronic device, the third electronic device and the first electronic device. The leader of the synchronization group is the first electronic device, and the group members are the second electronic device and the third electronic device. The synchronization of data within the synchronization group can be achieved by relying on the first electronic device.
[0118] In addition, when the first electronic device creates a synchronization group, a storage space in the random access memory (RAM) of the first electronic device can be used as the synchronization group storage space in the format of a folder. This means that the first electronic device can allocate a specific space in the RAM to store all the data of the synchronization group in the form of a folder (or similar folder).
[0119] Since the format of a folder is different from that of a database, the synchronization group storage space exists in the form of a folder. In order to more effectively manage and access the data therein, the first electronic device establishes a specific metadata library in the folder using the format of a database to quickly index, query and synchronize data.
[0120] In addition, after the second electronic device is turned on, the second electronic device can enable a data synchronization function based on user operations; when the third electronic device is turned on, the third electronic device can enable a data synchronization function based on user operations, so that data can be synchronized between the second electronic device and the third electronic device through the first electronic device.
[0121] For ease of explanation, Figure 5 In this application, the first electronic device is used as a central device, the second electronic device and the third electronic device are edge devices, and the first electronic device is used to synchronize data generated by the second electronic device to the third electronic device, and synchronize data generated by the third electronic device to the second electronic device.
[0122] For example, the second electronic device is a mobile phone, the third electronic device is a tablet computer, and the first electronic device is a network attached storage. Data synchronization between the mobile phone and the tablet computer can be achieved through the network attached storage.
[0123] Among them, the network attached storage is a device with data storage function. Therefore, the network attached storage can also be called "network storage", which is a dedicated data storage server.
[0124] In some embodiments, when a user performs an operation (including adding, deleting, modifying, etc. data) on the second electronic device and generates new data, the second electronic device can synchronize the new data to the first electronic device.
[0125] In other embodiments, when the user performs an operation on the third electronic device and generates new data, the new data can be synchronized to the first electronic device.
[0126] After receiving new data sent by the second electronic device and data sent by the third electronic device, the first electronic device can determine the value data corresponding to the same key value in the synchronization data sent by the second electronic device and the local data in the first electronic device, i.e., conflicting data, rename the data generated earlier in the aforementioned conflicting data, save the renamed conflicting data, the unrenamed conflicting data, and the data that is not conflicting data in the aforementioned synchronization data into the metadata database of the first electronic device, and in addition, send the renamed conflicting data, the unrenamed conflicting data, and the data that is not conflicting data in the local data in the aforementioned first electronic device to the second electronic device so that the second electronic device saves them in the synchronization database of the second electronic device.
[0127] The first electronic device, the second electronic device and the third electronic device may be electronic devices of the same type or of different types. The present application does not limit the types of the first electronic device, the second electronic device and the third electronic device.
[0128] The types of the metadata database and the synchronization database may be the same or different.
[0129] Among them, Figure 6 As shown, the synchronization database (syncableKVDB) is the underlying database used to support synchronization. The synchronization database may include a business database (dataDB) and a log database (logDB). The business database is used to store actual business data, and the log database is used to store operation logs. The business database is usually used to persist data and supports reading, writing, and querying data. The underlying implementation of the synchronization database relies on leveldb, and the storage format is key value (KV) type.
[0130] For example, if the user operation is to modify a picture, then the actual data corresponding to the service may include: picture name, creation time, size, type, etc.
[0131] For example, if the user operation is to modify a picture, then the operation log corresponding to the service may include: the name of the behavior of modifying the picture, and an operation log may be added each time the picture is modified.
[0132] The log database is the key to data synchronization between multiple electronic devices. Incremental synchronization between databases is achieved by sending logs from one electronic device and receiving logs from another electronic device. The operation log-related data stored in the log database and the format of the log-related data are shown in Table 1 below.
[0133] Table 1. Log DB structure diagram
[0134]
[0135] Among them, in Table 1, the maximum sequence value of the key (max index key): is used to store the maximum operation record sequence value (index) in the current logDB, and can be increased as the operation record is generated.
[0136] index for devId: records the maximum index of synchronized operation records of the device corresponding to devId. devId indicates the device corresponding to the data synchronized by the local device. The value corresponding to index for devId is the index value of the local device after the last data synchronization.
[0137] For example, the value corresponding to index for devId is 1000, which means that after the last data synchronization, the index value of the local electronic device is 1000.
[0138] The order value (index) of the operation record: used to mark the order of each operation record. The format of the operation record is shown in the table on the right.
[0139] Key: The key of the data corresponding to the operation record.
[0140] Value: The value of the data corresponding to the operation record.
[0141] Type: The type of data corresponding to the operation record, including insert (add) and delete (delete).
[0142] Source (src): The source of the corresponding data of the operation record, which may come from the local or synchronized with other devices.
[0143] Status: Whether the operation record has corresponding data. It is possible that the operation record has been written to the disk, but the data item has not been written to the disk. The operation record being written to the disk means that the data corresponding to the operation record is saved in the business database.
[0144] Timestamp: The timestamp of when the data corresponding to the operation record is generated. A larger timestamp value indicates that the data corresponding to the operation record is generated later, and a smaller timestamp value indicates that the data corresponding to the operation record is generated earlier.
[0145] For ease of explanation, Figure 7 In the description, the second electronic device is the electronic device 100, and the electronic device 100 is a mobile phone.
[0146] like Figure 7 As shown, the electronic device 100 may include a processor 101, a communication module 102, a display screen 103, a camera 104, a sensor 105, an internal memory 106, a USB interface 107, an external memory interface 108, a charging management module 109, a power management module 110, and a battery 111, etc.
[0147] The processor 101 may include one or more processing units, for example, the processor 101 may include an application processor (AP), a modem processor, a graphics processor, an image signal processor (ISP), a controller, a memory, a video stream codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated in one or more processors 101.
[0148] The internal memory 106 can be used to store computer executable program codes, which include instructions. The processor 101 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 106. The internal memory 106 can include a program storage area and a data storage area.
[0149] The program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 106 may include a random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0150] Optionally, the electronic device 100 may further include peripheral devices, such as a mouse, buttons, indicator lights, a keyboard, a speaker, a microphone, etc.
[0151] It can be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 100 .
[0152] In other embodiments, the electronic device 100 may include more or fewer components than shown, or combine some components, or separate some components, or arrange the components differently. The components shown may be implemented in hardware, software, or a combination of software and hardware.
[0153] Based on the above scenario description, below, this application takes an electronic device as an example, combined with the accompanying drawings and application scenarios, to elaborate on the data synchronization method provided in the embodiment of the present application.
[0154] Among them, the data synchronization method provided in the embodiment of the present application is applied to a first electronic device, the first electronic device is applied to a first communication system, and the first communication system includes a first electronic device and a second electronic device.
[0155] See also Figure 8 , Figure 8 A flow chart of a data synchronization method provided in an embodiment of the present application is shown.
[0156] like Figure 8 As shown, the data synchronization method provided by the present application may include:
[0157] S201. When receiving first data sent by a second electronic device, determine whether there is conflicting data between the first data and the second data.
[0158] The first data is operation data generated by an operation on user data in the second electronic device.
[0159] It should be understood that as the user performs operations on the second electronic device, the second electronic device may generate new data. When the second electronic device generates new data, the second electronic device may determine the data as the first data.
[0160] For example, the user modifies the nose of the face in the face image 1 in the second electronic device, and the operation record data generated by the modification may be the first data.
[0161] Specifically, the second electronic device may have a data monitoring function. The second electronic device may monitor the data in the second electronic device based on the data monitoring function. When data changes occur based on the original data, the second electronic device may determine that new data is generated, and the data is the first data.
[0162] It should be noted that the second electronic device can add the first electronic device as a device for synchronizing data in advance, and when the second electronic device generates the first data, it can send the first data to the first electronic device.
[0163] Thus, the second electronic device can send the first data to the first electronic device, and the first electronic device can receive the first data sent by the second electronic device.
[0164] The first data includes first attribute information of operation data generated by the operation on user data in the second electronic device, and the first attribute information includes at least one of data sequence number, data identifier, operation content, data type and generation time.
[0165] In some embodiments, the first data includes a data sequence number, a data identifier, an operation content, a data type, and a generation time of operation data generated by an operation on user data in the second electronic device.
[0166] The above data sequence number can be represented by index, the data identifier can be represented by key, the operation content can be represented by value, the data type can be represented by type, and the generation time can be represented by timestamp.
[0167] For example, the first data exists in the form of a table, and the first data may also be called synchronization data (syncMsg). The first data may be data shown in Table 2:
[0168] Table 2 First Data
[0169] index key value type timestamp 0 key1 value1 add 1
[0170] Among them, in Table 2, the index of the first row of data is 0, indicating that the data in the first row is the first stored data in the synchronization database of the second electronic device, and the key of the first row of data is key1, indicating that the identifier of the first stored data is "key1", the value of the first row of data is "value1", indicating that the actual operation content corresponding to the data in the first row is "value1", the type of the first row of data is "add", indicating that the data in the first row is data added to the synchronization database of the second electronic device, and the timestamp of the first row of data is 1, indicating that the time when the first row of data is generated is the time when the counter is 1.
[0171] For example, in Table 2, key1 is used to represent face image 1, and value1 corresponding to key1 represents operation record data generated by modifying the nose part of the face in face image 1.
[0172] For another example, the first data may be the data shown in Table 3:
[0173] Table 3 First Data
[0174] index key value type timestamp 0 key1 value1 add 1 1 key2 value2 add 2
[0175] Among them, in Table 3, the index of the first row of data is 0, indicating that the data in the first row is the first stored data in the synchronization database of the second electronic device, and the key of the first row of data is key1, indicating that the identifier of the first stored data is "key1", the value of the first row of data is "value1", indicating that the actual operation content corresponding to the data in the first row is "value1", the type of the first row of data is "add", indicating that the data in the first row is data added to the synchronization database of the second electronic device, and the timestamp of the first row of data is 1, indicating that the time when the first row of data is generated is the time when the counter is 1.
[0176] The index of the data in the second row is 1, indicating that the data in the second row is the second stored data in the synchronization database of the second electronic device, and the key of the data in the second row is key2, indicating that the identifier of the second stored data is "key2", and the value of the data in the second row is "value2", indicating that the actual operation content corresponding to the data in the second row is "value2", and the type of the data in the second row is "add", indicating that the data in the second row is data added to the synchronization database of the second electronic device, and the timestamp of the data in the second row is 2, indicating that the time when the second row of data is generated is when the counter is 2.
[0177] Timestamp is used to indicate the time when data was generated. The data corresponding to a timestamp value of 1 is generated earlier than the data corresponding to a timestamp value of 3, that is, the data with value1 was generated earlier than the data with value2.
[0178] For example, in Table 3, key1 is used to represent face image 1, and value1 corresponding to key1 represents operation record data generated by modifying the nose part of the face in face image 1.
[0179] For another example, in Table 3, key2 is used to represent mobile phone number 1, and value2 corresponding to key2 represents the time when the mobile phone number 1 is dialed.
[0180] The second data is operation data generated by the operation on the user data in the first electronic device.
[0181] Among them, the first communication system can also include a third electronic device, the first electronic device is a central device, and data transmission between the third electronic device and the second electronic device is completed through the first electronic device. The second data can be operation data generated by the first electronic device, or it can be sent by the third electronic device to the first electronic device, so that the first electronic device generates operation data.
[0182] In some embodiments, as the user performs an operation on the first electronic device, the first electronic device may generate new data. When the first electronic device generates new data, the first electronic device may determine the data as second data.
[0183] Specifically, the first electronic device may have a data monitoring function. The first electronic device may monitor the data in the first electronic device based on the data monitoring function. When data changes occur based on the original data, the first electronic device may determine that new data is generated, and the data is the second data.
[0184] In other embodiments, as the user performs operations on the third electronic device, the third electronic device may generate new data. When the third electronic device generates new data, the third electronic device may determine the data as second data.
[0185] Specifically, the third electronic device may have a data monitoring function, and the third electronic device may monitor the data in the third electronic device based on the data monitoring function. When data changes occur based on the original data, the third electronic device may determine that new data is generated, and the data is the second data.
[0186] Thus, the third electronic device can send the second data to the first electronic device, the first electronic device can receive the second data sent by the third electronic device, and the first electronic device can obtain the second data.
[0187] In some embodiments, the first communication system may further include a third electronic device, the first electronic device is a central device, data transmission between the third electronic device and the second electronic device is completed through the first electronic device, when the operation data generated by the first electronic device is the data sent by the third electronic device, when receiving the first data sent by the second electronic device, before determining whether there is conflicting data between the first data and the second data, the method of the present application also includes: receiving the second data sent by the third electronic device.
[0188] The second data includes first attribute information of operation data generated by the operation on user data in the first electronic device, and the first attribute information includes at least one of data sequence number, data identifier, operation content, data type and generation time.
[0189] In some embodiments, the second data includes a data sequence number, a data identifier, an operation content, a data type, and a generation time of operation data generated by an operation on user data in the first electronic device.
[0190] For example, the second data exists in the form of a table, and the second data may also be called synchronization data (syncMsg). The second data may be data shown in Table 4:
[0191] Table 4 Second Data
[0192] index key value type timestamp 0 key1 value11 add 3
[0193] Among them, in Table 4, the index of the first row of data is 0, indicating that the data in the first row is the first stored data in the synchronization database of the second electronic device, and the key of the first row of data is key1, indicating that the identifier of the first stored data is "key1", the value of the first row of data is "value11", indicating that the actual operation content corresponding to the data in the first row is "value11", the type of the first row of data is "add", indicating that the data in the first row is data added to the synchronization database of the second electronic device, and the timestamp of the first row of data is 3, indicating that the time when the first row of data is generated is when the counter is 3.
[0194] For example, in Table 4, value11 corresponding to key1 represents the operation record data generated by modifying the ear area of the face in face image 1.
[0195] For another example, the second data exists in the form of a table, the second data may also be called synchronization data (syncMsg), and the first data may be the data shown in Table 5:
[0196] Table 5 Second Data
[0197] index key value type timestamp 0 key1 value11 add 3 1 key3 value3 add 4
[0198] Among them, in Table 5, the index of the first row of data is 0, indicating that the data in the first row is the first stored data in the synchronization database of the second electronic device, and the key of the first row of data is key1, indicating that the identifier of the first stored data is "key1", the value of the first row of data is "value11", indicating that the actual operation content corresponding to the data in the first row is "value11", the type of the first row of data is "add", indicating that the data in the first row is data added to the synchronization database of the second electronic device, and the timestamp of the first row of data is 3, indicating that the time when the first row of data is generated is when the counter is 3.
[0199] The index of the data in the second row is 1, indicating that the data in the second row is the second stored data in the synchronization database of the second electronic device, and the key of the data in the second row is key3, indicating that the identifier of the second stored data is "key3", the value of the data in the second row is "value3", indicating that the actual operation content corresponding to the data in the second row is "value3", the type of the data in the second row is "add", indicating that the data in the second row is data added to the synchronization database of the second electronic device, and the timestamp of the data in the second row is 4, indicating that the second row of data is generated when the counter is 4.
[0200] Timestamp is used to indicate the time when data was generated. The data corresponding to a timestamp value of 3 is generated earlier than the data corresponding to a timestamp value of 4, that is, the data with value 11 was generated earlier than the data with value 3.
[0201] For example, in Table 5, value11 corresponding to key1 represents the operation record data generated by modifying the ear area of the face in face image 1.
[0202] For another example, in Table 5, key3 is used to represent file 1, and value3 corresponding to key3 represents deleting part of the text in file 1.
[0203] It can be understood that there may be conflicting data between the first data and the second data, and the conflicting data is operation data generated by operations on the same user data in the first data and the second data.
[0204] The conflict data includes second attribute information corresponding to the operation data generated by the operation on the same user data in the first data and the second data. The second attribute information includes at least one of the data identifier, operation content, data type, generation time and label information. The label information is used to indicate whether each data in the conflict data is the data with the latest generation time. The label information is determined according to the generation time.
[0205] In some embodiments, the second attribute information includes data identification, operation content, data type, generation time and label information.
[0206] The above-mentioned data tag information can be represented by whether it is new data (is newer). If it is the data generated latest among the conflicting data, it is represented by correct (true); if it is not the data generated latest among the conflicting data, it is represented by wrong (false).
[0207] For example, the conflicting data exists in the form of a table. When the first data is the data shown in Table 2 and the second data is the data shown in Table 4, the conflicting data may be the data shown in Table 6. When the first data is the data shown in Table 3 and the second data is the data shown in Table 5, the conflicting data may also be the data shown in Table 6:
[0208] Table 6 Conflict data
[0209]
[0210] In Table 6, the label information true corresponding to value11 indicates that the data is the data with the latest generation time among the conflicting data.
[0211] The label information false corresponding to value3 indicates that the data is not the latest generated data among the conflicting data.
[0212] For example, in combination with Table 2 and Table 4, or Table 3 and Table 5, key1 is used to represent face image 1, value1 corresponding to key1 represents the operation record data generated by modifying the nose part of the face in face image 1, and value11 corresponding to key1 represents the operation record data generated by modifying the ear part of the face in face image 1; it can be seen that the two data corresponding to value1 and value11 are both identified by key1, and value1 and value11 are conflicting data.
[0213] That is to say, the conflicting data is the operation data corresponding to the same identifier in the first data and the second data.
[0214] It should be noted that the second data involved in calculating the conflicting data is the data after the first quantity in the first electronic device. The first quantity is the total quantity of data in the second electronic device after the last time the first electronic device synchronized data with the second electronic device. When the second electronic device sends the first data to the first electronic device, it can send the aforementioned first quantity to the first electronic device.
[0215] That is, if the amount of data in the first electronic device is different from the amount of data in the second electronic device after the last data synchronization, the conflicting data obtained may be inaccurate, thereby causing the subsequently calculated third data and fourth data to be inaccurate.
[0216] If the first electronic device has not synchronized data with the second electronic device, or the second electronic device has not synchronized data with the first electronic device, then the first number is 0.
[0217] For example, after the first electronic device synchronized data with the second electronic device last time, the total number of data in the second electronic device was 1000, then the second data is the data after the 1000th data in the first electronic device.
[0218] S202: When conflicting data exists between the first data and the second data, obtain third data according to the first data and the conflicting data.
[0219] When conflicting data exists between the first data and the second data, the third data exists in two forms according to the situations of the first data and the second data.
[0220] In some embodiments, all the first data are conflicting data. Thus, the third data includes first sub-data and second sub-data. The first sub-data is the data generated latest among the conflicting data, and the second sub-data is the data generated earlier than the first sub-data and renamed among the conflicting data.
[0221] For example, in combination with Table 2 and Table 6, when the first data is the data shown in Table 2, all the first data are conflicting data.
[0222] In other embodiments, the first data includes data that is conflicting data and data that is not conflicting data. Thus, the third data includes first sub-data, second sub-data and third sub-data, and the third sub-data is data in the first data that is not conflicting data.
[0223] For example, in combination with Table 3 and Table 6, when the first data is the data shown in Table 3, the first data includes data that is conflicting data and data that is not conflicting data.
[0224] Since the conflicting data is operation data generated by the operation on the same user data in the first data and the second data, the generation time of each sub-data in the conflicting data may be different. The first electronic device can rename part of the sub-data included in the conflicting data according to the different generation times.
[0225] Specifically, no matter how many sub-data are included in the conflicting data, there is only one data with the latest generation time. Therefore, the first electronic device can rename all the data in the conflicting data except the data with the latest generation time, and will not rename the data with the latest generation time. In this way, the problem of conflicting data between the first data and the second data can be solved.
[0226] It is understandable that the conflicting data may include multiple sub-data. If the data with the latest generation time is renamed, and the data except the data with the latest generation time is not renamed, then the conflicting data still exists; if all the data except the data with the latest generation time is renamed, and the data with the latest generation time is not renamed, then there is no conflicting data.
[0227] For example, the conflict table includes data 1 and data 2, and data 1 is generated earlier than data 2. The first electronic device may rename data 1.
[0228] For another example, the conflict table includes data 1, data 2 and data 3. The generation time of data 1 and data 2 is earlier than that of data 3. Data 3 is the latest generated data among the conflicting data. The first electronic device can rename data 1 and data 2.
[0229] Based on the above description, the first electronic device may determine the data generated latest in the conflicting data as the first sub-data, and determine the data generated earlier than the first sub-data in the conflicting data and renamed as the second sub-data.
[0230] In addition, the first data also includes data that is not conflicting data. Therefore, the data that is not conflicting data in the first data can be determined as third sub-data. Thus, the first electronic device can obtain third data, which includes all data in the first data synchronized from the second electronic device to the first electronic device.
[0231] The third data includes third attribute information of the first sub-data, third attribute information of the second sub-data, and third attribute information of the third sub-data, and the third attribute information includes at least one of a data identifier, an operation content, and a data type.
[0232] In some embodiments, the third attribute information includes data identification, operation content and data type.
[0233] For example, the third data exists in the form of a table, and the third data may also be called batch write data. If the first data is the data shown in Table 2, the third data may be the data shown in Table 7:
[0234] Table 7 Third Data
[0235] key value type key1 value11 add cf-key1 value1 add
[0236] Among them, combined with Table 6, it can be seen that the data corresponding to value11 in the conflicting data is the data generated latest in the conflicting data, and the data corresponding to value1 in the conflicting data is generated earlier than value11. Therefore, the first electronic device can rename the data process corresponding to value1. As a result, the first electronic device can update the identifier of the data corresponding to value1 from key1 to cf-key1, and the identifier of the data corresponding to value11 remains unchanged.
[0237] For another example, if the first data is the data shown in Table 3, the third data may be the data shown in Table 8:
[0238] Table 8 Third Data
[0239] key value type key1 value11 add cf-key1 value1 add key2 value2 add
[0240] Among them, combined with Table 6, it can be seen that the data corresponding to value11 in the conflicting data is the data generated latest in the conflicting data, and the data corresponding to value1 in the conflicting data is generated earlier than value11. Therefore, the first electronic device can rename the data process corresponding to value1. As a result, the first electronic device can update the identifier of the data corresponding to value1 from key1 to cf-key1, and the identifier of the data corresponding to value11 remains unchanged.
[0241] It can be seen that in Table 8, the data corresponding to value11 and value1 are conflicting data, the data corresponding to value11 can be the first sub-data, the data corresponding to value1 can be the second sub-data, the identifier of the data corresponding to value1 is cf-key1, the identifier of the data corresponding to value11 remains unchanged, and the data corresponding to value2 can be the data in the first data that is not conflicting data.
[0242] It can be seen that the data corresponding to value1 and the data corresponding to value2 in Table 8 are both from the first data synchronized from the second electronic device to the first electronic device, and the second electronic device successfully synchronizes data with the first electronic device.
[0243] Based on the above description, the first electronic device can perform calculation based on the conflicting data and the data in the first data that is not conflicting data, thereby obtaining the third data, so that the second electronic device can successfully synchronize data with the first electronic device.
[0244] In some embodiments, after obtaining the third data based on the first data and the conflicting data, the method further includes: storing the third data in a database of the first electronic device.
[0245] That is, after obtaining the third data, the first electronic device may also store the third data in the synchronization database of the first electronic device, so that the first electronic device stores the data synchronized from the second electronic device.
[0246] Specifically, the first electronic device may store the third data in the service database of the synchronization database, so that the processed third data is stored in the disk of the first electronic device.
[0247] In some embodiments, the first communication system also includes a third electronic device, the first electronic device is a central device, data transmission between the first electronic device and the second electronic device is completed through the first electronic device, and after obtaining the third data based on the first data and the conflicting data, the method also includes: sending the third data to the third electronic device.
[0248] That is, the second electronic device can send the third data to the third electronic device through the first electronic device, so that the second electronic device successfully synchronizes data with the third electronic device.
[0249] S203: Obtain fourth data according to the second data and the conflicting data.
[0250] When conflicting data exists between the first data and the second data, the fourth data exists in two forms according to the situations of the first data and the second data.
[0251] In some embodiments, all the second data are conflicting data, and thus, the fourth data includes the first sub-data and the second sub-data.
[0252] For example, in combination with Table 4 and Table 6, when the second data is the data shown in Table 4, all the second data are conflicting data.
[0253] In other embodiments, the second data includes data that is conflicting data and data that is not conflicting data. Thus, the fourth data includes the first sub-data, the second sub-data and the fourth sub-data, and the fourth sub-data is the data in the second data that is not conflicting data.
[0254] For example, in combination with Table 5 and Table 6, when the second data is the data shown in Table 5, the second data includes data that is conflicting data and data that is not conflicting data.
[0255] In combination with the description of S202, the first electronic device may determine the data generated latest in the conflicting data as the first sub-data, and determine the data generated earlier than the first sub-data in the conflicting data and renamed as the second sub-data.
[0256] In addition, when the second data also includes data that is not conflicting data, the first electronic device can determine the data in the second data that is not conflicting data as fourth sub-data, thereby, the first electronic device can obtain the fourth sub-data, and the fourth data includes all data in the second data that the first electronic device needs to synchronize with the second electronic device.
[0257] The fourth data includes the first attribute information of the first sub-data, the first attribute information of the second sub-data, and the first attribute information of the fourth sub-data.
[0258] In some embodiments, the first attribute information includes data sequence number, data identifier, operation content, data type and generation time.
[0259] For example, the fourth data exists in the form of a table, and the fourth data may also be called synchronization data (syncMsg). If the second data is the data shown in Table 4, the fourth data may be the data shown in Table 9:
[0260] Table 9 Fourth Data
[0261] index key value type timestamp 0 key1 value11 add 3 1 cf-key1 value1 add 1
[0262] Among them, combined with Table 6, it can be seen that the data corresponding to value11 in the conflicting data is the data generated latest in the conflicting data, and the data corresponding to value1 in the conflicting data is generated earlier than value11. Therefore, the first electronic device can rename the data corresponding to value1. Thus, the first electronic device can update the identifier of the data corresponding to value1 from key1 to cf-key1, and the identifier of the data corresponding to value11 remains unchanged.
[0263] It can be seen that in Table 9, the data corresponding to value11 and value1 are both conflicting data, the data corresponding to value11 may be the first sub-data, the data corresponding to value1 may be the second sub-data, the identifier of the data corresponding to value1 is cf-key1, and the identifier of the data corresponding to value11 remains unchanged.
[0264] It can be seen that the data corresponding to value11 in Table 9 comes from the first electronic device, and data preparation can be done for the first electronic device to synchronize the first data in the first electronic device to the second electronic device.
[0265] Based on the above description, the first electronic device can perform calculation based on the data that is not conflicting data in the conflicting data and the second data to obtain fourth data, which can prepare data for the first electronic device to synchronize the first data in the first electronic device to the second electronic device.
[0266] For another example, if the second data is the data shown in Table 5, the fourth data may be the data shown in Table 10:
[0267] Table 10 Fourth Data
[0268] index key value type timestamp 0 key1 value11 add 3 1 cf-key1 value1 add 1 2 Key3 value3 add 4
[0269] Among them, combined with Table 6, it can be seen that the data corresponding to value11 in the conflicting data is the data generated latest in the conflicting data, and the data corresponding to value1 in the conflicting data is generated earlier than value11. Therefore, the first electronic device can rename the data corresponding to value1. Thus, the first electronic device can update the identifier of the data corresponding to value1 from key1 to cf-key1, and the identifier of the data corresponding to value11 remains unchanged.
[0270] It can be seen that in Table 10, the data corresponding to value11 and value1 are both conflicting data, the data corresponding to value11 can be the first sub-data, the data corresponding to value1 can be the second sub-data, the identifier of the data corresponding to value1 is cf-key1, the identifier of the data corresponding to value11 remains unchanged, and the data corresponding to value3 can be the data in the second data that is not conflicting data.
[0271] It can be seen that the data corresponding to value11 and the data corresponding to value3 in Table 10 both come from the first electronic device, which can prepare data for the first electronic device to synchronize the first data in the first electronic device to the second electronic device.
[0272] Based on the above description, the first electronic device can perform calculation based on the data that is not conflicting data in the conflicting data and the second data to obtain fourth data, which can prepare data for the first electronic device to synchronize the first data in the first electronic device to the second electronic device.
[0273] Among them, the execution order of S202 and S203 is not particular, and they can be executed sequentially or simultaneously.
[0274] S204: Send fourth data to the second electronic device, so that the second electronic device obtains the fourth data, and the total data quantity of the fourth data and the first data is the same as the total data quantity of the third data and the second data.
[0275] Based on S203, the first electronic device can obtain data synchronized with the second electronic device, that is, fourth data, and thus the first electronic device can send the fourth data to the second electronic device, so that the first electronic device completes data synchronization with the second electronic device.
[0276] For example, combining Table 5 and Table 6, it can be seen that the third data includes data corresponding to value11, data corresponding to value1, and data corresponding to value2, and the fourth data includes data corresponding to value11, data corresponding to value1, and data corresponding to value3. The third data and the fourth data both include three pieces of data.
[0277] In addition, it can be seen from Table 3 and Table 5 that the first data includes data corresponding to value1 and data corresponding to value2, and the second data includes data corresponding to value11 and data corresponding to value3, and both the first data and the second data include two pieces of data.
[0278] Based on the above description, it can be seen that the total number of data of the third data and the second data is five data, the total number of data of the fourth data and the first data is also five data, and the total number of data of the fourth data and the first data is the same as the total number of data of the third data and the second data.
[0279] Based on the above description, the first electronic device can calculate based on the data that is not conflicting data in the conflicting data and the second data to obtain fourth data, and send the fourth data to the second electronic device, so that the second electronic device can successfully synchronize data with the first electronic device.
[0280] Combination Fig. 9 In a specific embodiment, the second electronic device includes data 1000. When data 1001 and data 1002 are generated in the second electronic device, the second electronic device also includes data 1001 and data 1002. At this time, the second electronic device needs to synchronize data 1001 and data 1002 to the first electronic device, so that the second electronic device can send data 1001 and data 1002 to the first electronic device, and can also send the maximum sequence value (index) 1000 in the second electronic device to the first electronic device.
[0281] Furthermore, the first electronic device includes data 1000 , and when data 1001 and data 1002 are generated in the first electronic device, the first electronic device also includes data 1001 and data 1002 .
[0282] After receiving the data 1001 and the data 1002 in the second electronic device in the first electronic device, it can be determined whether there is conflicting data between the data 1001 and 1002 in the second electronic device and the data 1001 and the data 1002 after the maximum sequence value 1000 in the first electronic device. If there is conflicting data, the first electronic device can calculate the conflicting data between the data 1001 and 1002 in the second electronic device and the data 1001 and the data 1002 in the first electronic device.
[0283] Thus, the first electronic device can obtain the conflicting data, and then the first electronic device can calculate the data 1001 and the data 1002 in the second electronic device that are not conflicting data with the conflicting data, and rename the data before the data with the latest generation time in the conflicting data, so as to obtain batch write data, and the first electronic device can store the batch write data.
[0284] Thus, the data in the first electronic device includes data 1001 , data 1002 , data 1003 , data 1004 , and data 1005 .
[0285] In addition, the first electronic device can also calculate the data that is not conflicting data in the data 1001 and the data 1002 in the second electronic device with the conflicting data, and rename the data before the latest generated data in the conflicting data to obtain synchronization data (sync msg).
[0286] The first electronic device may send synchronization data to the second electronic device. When the second electronic device receives the synchronization data, it may obtain batch write data according to the synchronization data. The first electronic device may store the batch write data.
[0287] Thus, the data in the second electronic device includes data 1001 , data 1002 , data 1003 , data 1004 , and data 1005 .
[0288] It can be seen that no matter after the last synchronization or the current synchronization, the number of data in the first electronic device and the number of data in the second electronic device can be kept consistent. After the last synchronization, there were 1000 items, and after the current synchronization, there were 1005 items. The maximum sequence values (index) corresponding to the first electronic device and the second electronic device are the same.
[0289] At this time, the maximum sequence value of the first electronic device is 1005, and the maximum sequence value in the second electronic device is 1005. If the second electronic device adds a new data 1006, the data in the second electronic device becomes 1006, and the second electronic device can synchronize the data 1006 to the first electronic device and send the maximum sequence value 1005 to the first electronic device; if the first electronic device adds two new data, namely data 1006 and data 1007, the data in the first electronic device can become 1007.
[0290] After receiving data 1006 and the maximum sequence value 1005, the first electronic device can determine whether there is conflicting data between the data in the second electronic device and the data 1006 and data 1007 in the first electronic device. If there is conflicting data, the first electronic device can calculate the conflicting data between the data 1006 in the second electronic device and the data 1006 and data 1007 in the first electronic device.
[0291] Therefore, the first electronic device can rename the old data with an earlier generation time in the conflicting data and then store it, and will not rename the data with a later generation time in the conflicting data. After synchronization, the first electronic device includes 1009 data. Since the maximum sequence value sent by the second electronic device is 1005, the first electronic device can synchronize the data after the maximum sequence value in the first electronic device to the first electronic device according to the maximum sequence value sent by the second electronic device. That is to say, the first electronic device can calculate the conflicting data, the data 1006 after the sequence value 1005, and the data that does not belong to the conflicting data in the data 1007, obtain the data to be sent to the second electronic device, and send it to the second electronic device. After synchronization, the second electronic device includes 1009 data, which will not cause the data in the first electronic device to be missed in synchronization with the second electronic device.
[0292] In addition, there were 1005 pieces of data after the last synchronization, and 1009 pieces of data after the current synchronization. The amount of data is the same after each synchronization.
[0293] It can be seen that through the above method, abnormalities in subsequent data synchronization can be avoided, which can improve the user experience.
[0294] Based on the above description, the data synchronization method of the present application can implement four principles: Principle 1. Before synchronization, the index for the first electronic device on the second electronic device side is consistent with the index for the second electronic device on the first electronic device side; Principle 2. After synchronization, the index for the first electronic device on the second electronic device side is consistent with the index for the second electronic device on the first electronic device side; Principle 3. After synchronization, the data in the first electronic device is consistent with the data in the second electronic device, and the first electronic device and the second electronic device both include the same data; Principle 4. After synchronization, the order of the data in the first electronic device and the data in the second electronic device may be inconsistent.
[0295] In some embodiments, the first communication system also includes a third electronic device. The first electronic device can be referred to as a center device, the second electronic device and the third electronic device can be referred to as edge devices, and the second data can be data sent from the edge device corresponding to the third electronic device to the center device, or it can be data generated by the center device.
[0296] Based on this, in the above principle 1, the index for center on the edge device side is consistent with the index for edge on the central device side before synchronization; in principle 2, the index for center on the edge device side is consistent with the index for edge on the central device side after synchronization.
[0297] For example, combined with Fig. 9 Before synchronization, the index for center on the edge device side and the index for edge on the center device side are both 1000. After synchronization, the index for center on the edge device side and the index for edge on the center device side are both 1005.
[0298] In the data synchronization method of the present application, when the first electronic device receives the first data sent by the second electronic device, it can obtain conflicting data based on the first data and the second data. Since the user may operate the same user data on the first electronic device and the second electronic device, thereby generating different operation data, there is conflicting data between the first data and the second data. In this way, when the first electronic device receives the first data, it can determine the conflicting data between the first data and the second data based on the first data and the second data, thereby making data preparations for obtaining the third data synchronized to the second electronic device based on the conflicting data.
[0299] After obtaining the conflicting data, the first electronic device can also obtain third data based on the first data and the conflicting data, where the third data includes the data generated latest in the conflicting data, the data before and after the data generated latest in the conflicting data, and the data in the first data that does not belong to the conflicting data. That is, the first electronic device can rename all the old data in the conflicting data by renaming all the data before the data generated latest in the conflicting data, retain the data generated latest, and obtain the third data with the data that does not belong to the conflicting data in the first data, so that all the first data synchronized by the second electronic device are retained, thereby realizing data synchronization from the second electronic device to the first electronic device.
[0300] In addition, the first electronic device can also obtain fourth data based on the second data and the conflicting data, and the fourth data includes the data with the latest generation time in the conflicting data, the data before and after the data with the latest generation time in the conflicting data, and the data in the second data that does not belong to the conflicting data. That is to say, the first electronic device can rename all the old data in the conflicting data by renaming all the data before the data with the latest generation time in the conflicting data, and retain the data with the latest generation time, and obtain the fourth data with the data that does not belong to the conflicting data in the second data, so that all the second data generated by the first electronic device can be synchronized with the second electronic device, and it is guaranteed that there is no data conflict after synchronization.
[0301] In addition, the first electronic device can also send fourth data to the second electronic device so that the second electronic device obtains the fourth data. In this way, after synchronization, the total data quantity of the fourth data and the first data is the same as the total data quantity of the third data and the second data. Therefore, the next time the second electronic device synchronizes the first data to the first electronic device, it can synchronize data to the first electronic device according to the maximum sequence value after the current synchronization to avoid the situation where the first electronic device misses to synchronize data to the first electronic device. As a result, abnormalities in subsequent synchronization of data can be avoided and the user experience can be improved.
[0302] Based on the above Figure 8 According to the description of S201-S204, the first electronic device can receive the first data sent by the second electronic device, and the first electronic device can send the fourth data to the second electronic device. Then, the second electronic device needs to receive the fourth data sent by the first electronic device.
[0303] Among them, the data synchronization method provided in the embodiment of the present application is also applied to the second electronic device, and the second electronic device is applied to the first communication system, and the first communication system includes the first electronic device and the second electronic device.
[0304] See also Fig.10 , Fig.10 A flow chart of a data synchronization method provided in an embodiment of the present application is shown.
[0305] like Fig.10 As shown, the data synchronization method provided by the present application may include:
[0306] S301: When the second electronic device generates data after detecting original data in the second electronic device, the second electronic device determines the data after the original data as first data, or periodically determines the data after the original data as first data.
[0307] The second electronic device may determine the first data in at least one of the following ways:
[0308] Method 1: when data is generated after the original data in the second electronic device is detected, the data after the original data is determined as the first data.
[0309] Combination Fig. 9 In a specific embodiment, the second electronic device includes data 0-data 1000, and data 0-data 1000 are original data. When data 1001 and data 1002 are generated in the second electronic device, the second electronic device can determine data 1001 and data 1002 as first data.
[0310] That is, the original data are arranged in a preset order, and each original data corresponds to a sequence value (index). The second electronic device can determine the data 1001 and data 1002 generated after the data corresponding to the maximum index value 1000 as the first data.
[0311] Method 2: periodically determining the data after the original data as the first data.
[0312] Combination Fig. 9 In a specific embodiment, the second electronic device includes data 0-data 1000, where data 0-data 1000 are original data. The second electronic device can determine the data generated after data 1000 as the first data at a preset time interval.
[0313] It should be understood that if no data is generated after data 1000, the data after data 1000 is empty and the first data is empty.
[0314] For example, the preset time length is 5 minutes, the second electronic device includes data 0-data 1000 at 10:00, generates data 1001 and data 1002 at 10:02, and at 10:05, the second electronic device can determine data 1001 and data 1002 generated after data 1000 as the first data; the second electronic device includes data 0-data 1002 between 10:05 and 10:10, and no new data is generated. At 10:10, the second electronic device can determine that the data after the original data is empty.
[0315] S302: Send first data to a first electronic device.
[0316] The first data is operation data generated by an operation on user data in the second electronic device.
[0317] It should be understood that as the user performs operations on the second electronic device, the second electronic device may generate new data. When the second electronic device generates new data, the second electronic device may determine the data as the first data.
[0318] For example, the user modifies the nose of the face in the face image 1 in the second electronic device, and the operation record data generated by the modification may be the first data.
[0319] Specifically, the second electronic device can have a data monitoring function. The second electronic device can monitor the data in the second electronic device based on the data monitoring function. When the data changes on the basis of the original data, the second electronic device can determine that new data has been generated, and the data is the first data. Therefore, the second electronic device can send the data to the first electronic device.
[0320] S303. When the fourth data is received, obtain fifth data according to the fourth data.
[0321] Among them, the fourth data is obtained based on the second data and the conflict data, the conflict data is obtained based on the first data and the second data, the second data is the operation data generated by the operation of the user data in the first electronic device, the conflict data is the operation data generated by the operation of the same user data in the first data and the second data, the fourth data includes the first sub-data and the second sub-data, and the generation time corresponding to the first sub-data and the second sub-data respectively, the first sub-data is the data with the latest generation time in the conflict data, the second sub-data is the data in the conflict data that is generated earlier than the first sub-data and is renamed, the fifth data includes the first sub-data and the second sub-data, the total data quantity of the fifth data and the first data is the same as the total data quantity of the third data and the second data, the third data is obtained based on the first data and the conflict data, and the third data includes the first sub-data and the second sub-data.
[0322] In some embodiments, the third data further includes third sub-data, and the third sub-data is data in the first data that is not conflicting data.
[0323] In some embodiments, the fourth data further includes fourth sub-data and generation time of the fourth sub-data, and the fourth sub-data is data in the second data that is not conflicting data.
[0324] Based on S204, the first electronic device may send the fourth data to the second electronic device, so that the second electronic device may receive the fourth data.
[0325] When an electronic device synchronizes data with another electronic device, it can usually synchronize the log data corresponding to the data. Therefore, the first data that needs to be synchronized and sent by the second electronic device to the first electronic device is in the form of log data, and the fourth data that needs to be synchronized and sent by the first electronic device to the second electronic device is in the form of log data.
[0326] When an electronic device stores data synchronized from another electronic device, it can store business data corresponding to the data. Therefore, the third data stored in the first electronic device is in the form of business data, and the second electronic device also needs to convert the fourth data into the form of business data.
[0327] Based on this, when receiving the fourth data, the second electronic device can obtain the fifth data according to the fourth data. The fifth data is in the form of business data, which is convenient for the second electronic device to store.
[0328] In some embodiments, the fifth data also includes fourth sub-data. Specifically, the fifth data includes the third attribute information of the first sub-data, the third attribute information of the second sub-data, and the third attribute information of the fourth sub-data.
[0329] In some embodiments, the third attribute information includes data identification, operation content, data type, generation time and label information.
[0330] For example, the fifth data has the same format as the third data, the fifth data has the same data quantity as the third data, the fifth data also exists in the form of a table, and the fifth data may also be called write batch data. If the second data is the data shown in Table 4, the fifth data may be the data shown in Table 11:
[0331] Table 11 Fifth Data
[0332] key value type key1 value11 add cf-key1 value1 add
[0333] Among them, combined with Table 6, it can be seen that the data corresponding to value11 in the conflicting data is the data generated latest in the conflicting data, and the data corresponding to value1 in the conflicting data is generated earlier than value11. Therefore, the first electronic device can rename the data corresponding to value1. Thus, the first electronic device can update the identifier of the data corresponding to value1 from key1 to cf-key1, and the identifier of the data corresponding to value11 remains unchanged.
[0334] It can be seen that in Table 11, the data corresponding to value11 and value1 are both conflicting data, the data corresponding to value11 may be the first sub-data, the data corresponding to value1 may be the second sub-data, the identifier of the data corresponding to value1 is cf-key1, and the identifier of the data corresponding to value11 remains unchanged.
[0335] It can be seen that the data corresponding to value11 in Table 11 comes from the second data in the first electronic device, and the first electronic device successfully synchronizes data with the second electronic device.
[0336] In addition, it can be seen from Table 7 and Table 11 that the third data includes data corresponding to value11 and data corresponding to value1, the fifth data includes data corresponding to value11 and data corresponding to value1, and the third data and the fifth data each include two pieces of data.
[0337] In addition, it can be seen from Table 2 and Table 4 that the first data includes data corresponding to value1 and data corresponding to value2, and the second data includes data corresponding to value11 and data corresponding to value3, and both the first data and the second data include two pieces of data.
[0338] Based on the above description, it can be seen that the total data quantity of the third data and the second data is four data, the total data quantity of the fifth data and the first data is also four data, and the total data quantity of the fifth data and the first data is the same as the total data quantity of the third data and the second data.
[0339] For example, if the second data is the data shown in Table 5, the fifth data may be the data shown in Table 12:
[0340] Table 12 Fifth Data
[0341] key value type key1 value11 add cf-key1 value1 add key3 value3 add
[0342] Among them, combined with Table 6, it can be seen that the data corresponding to value11 in the conflicting data is the data generated latest in the conflicting data, and the data corresponding to value1 in the conflicting data is generated earlier than value11. Therefore, the first electronic device can rename the data corresponding to value1. Thus, the first electronic device can update the identifier of the data corresponding to value1 from key1 to cf-key1, and the identifier of the data corresponding to value11 remains unchanged.
[0343] It can be seen that in Table 12, the data corresponding to value11 and value1 are both conflicting data, the data corresponding to value11 can be the first sub-data, the data corresponding to value1 can be the second sub-data, the identifier of the data corresponding to value1 is cf-key1, the identifier of the data corresponding to value11 remains unchanged, and the data corresponding to value3 can be the data in the second data that is not conflicting data.
[0344] It can be seen that the data corresponding to value11 and the data corresponding to value3 in Table 12 both come from the second data in the first electronic device, and the first electronic device successfully synchronizes data with the second electronic device.
[0345] In addition, it can be seen from Table 8 and Table 12 that the third data includes data corresponding to value11, data corresponding to value1, and data corresponding to value2, and the fifth data includes data corresponding to value11, data corresponding to value1, and data corresponding to value3. The third data and the fifth data both include three pieces of data.
[0346] In addition, it can be seen from Table 3 and Table 5 that the first data includes data corresponding to value1 and data corresponding to value2, and the second data includes data corresponding to value11 and data corresponding to value3, and both the first data and the second data include two pieces of data.
[0347] Based on the above description, it can be seen that the total number of data of the third data and the second data is five data, the total number of data of the fifth data and the first data is also five data, and the total number of data of the fifth data and the first data is the same as the total number of data of the third data and the second data.
[0348] Based on the above description, the first electronic device can perform calculations based on the data that is not the conflicting data in the second data to obtain fourth data, and send the fourth data to the second electronic device. After the second electronic device receives the fourth data, it can obtain fifth data based on the fourth data, so that the second electronic device successfully synchronizes data with the first electronic device.
[0349] In some embodiments, upon receiving the fourth data, after generating fifth data according to the fourth data, the method further includes: storing the fifth data in a database of the second electronic device.
[0350] That is, after obtaining the fourth data, the second electronic device may further generate fifth data and store the fifth data in the synchronization database of the second electronic device, so that the second electronic device stores the data synchronized from the first electronic device.
[0351] Specifically, the second electronic device can store the fifth data in the log database in the synchronization database of the first electronic device, and then the log database processes the fifth data and stores the processed fifth data in the business database, so that the processed fifth data is stored in the second electronic device.
[0352] In the present application, as the user performs operations on the second electronic device, the second electronic device can generate first data, and thus the second electronic device can send the first data to the first electronic device, so as to synchronize the first data to the first electronic device.
[0353] In addition, after the first electronic device obtains the fourth data to be synchronized to the second electronic device based on the conflicting data and the data that is not conflicting data in the second data of the first electronic device, the fourth data can be sent to the second electronic device to facilitate synchronization of the fourth data to the second electronic device. After receiving the fourth data, the second electronic device can obtain the fifth data based on the fourth data, and the second electronic device can store the fifth data. As a result, the first electronic device successfully synchronizes data with the second electronic device.
[0354] Based on the above Figure 8 and Fig.10 In the following, the data synchronization method provided in the embodiment of the present application is described in detail in combination with the accompanying drawings and application scenarios.
[0355] Among them, the data synchronization method provided in the embodiment of the present application is applied to a first electronic device and a second electronic device, the first electronic device and the second electronic device are applied to a first communication system, and the first communication system includes the first electronic device and the second electronic device.
[0356] Among them, Fig.11 As shown, the first electronic device includes a first communication module, a first synchronization service module and a first database, and the second electronic device includes a second communication module, a second synchronization service module and a second database.
[0357] The first database and the second database are both used to store data.
[0358] The first communication module and the second communication module may be communication modules such as Bluetooth, wireless network, etc.
[0359] See also Fig.12 , Fig.12 A flow chart of a data synchronization method provided in an embodiment of the present application is shown.
[0360] like Fig.12 As shown, the data synchronization method provided by the present application may include:
[0361] S401: When the second synchronization service module generates data after detecting original data in the second electronic device, or periodically determines the data after the original data as first data.
[0362] Among them, S401 and Fig.10 The implementation of S301 in the illustrated embodiment is similar and will not be described in detail in this application.
[0363] S402: The second synchronization service module sends first data to the first communication module of the first electronic device through the second communication module.
[0364] After obtaining the first data, the second synchronization service module may send the first data to the first communication module of the first electronic device through the second communication module, so as to synchronize the first data with the first electronic device.
[0365] Among them, S402 and Fig.10 The implementation of S302 in the illustrated embodiment is similar and will not be described in detail in this application.
[0366] S403: The first communication module sends first data to the first synchronization service module.
[0367] After obtaining the first data, the first communication module may send the first data to the first synchronization service module, so that the first synchronization service module can process the first data.
[0368] S404. When the first synchronization service module receives the first data sent by the second electronic device, the first synchronization service module obtains conflicting data based on the first data and the second data, where the first data is operation data generated by the operation on the user data in the second electronic device, and the second data is operation data generated by the operation on the user data in the first electronic device. The conflicting data is operation data generated by the operation on the same user data in the first data and the second data.
[0369] S405. The first synchronization service module obtains third data based on the first data and the conflicting data. The third data includes first sub-data, second sub-data and third sub-data. The first sub-data is the data in the conflicting data that is generated latest. The second sub-data is the data in the conflicting data that is generated earlier than the first sub-data and is renamed. The third sub-data is the data in the first data that is not conflicting data.
[0370] Among them, S404 and S405 are respectively Fig. 9 The implementation methods of S201 and S202 in the illustrated embodiment are similar and will not be described in detail here.
[0371] S406: The first synchronization service module sends the third data to the first database.
[0372] After obtaining the third data, the first synchronization service module may also send the third data to the first database to facilitate the first database to store the third data.
[0373] S407: The first database stores the third data in a database of the first electronic device.
[0374] After obtaining the third data, the first database may also store the third data in the synchronization database of the first electronic device, so that the first electronic device stores the data synchronized from the second electronic device.
[0375] Specifically, the first database may store the third data in the business database of the synchronization database, so that the processed third data is stored in the first electronic device.
[0376] S408. The first synchronization service module obtains fourth data according to the second data and the conflicting data. The fourth data includes the first sub-data, the second sub-data and the fourth sub-data. The fourth sub-data is data in the second data that is not conflicting data.
[0377] S409: The first synchronization service module sends the fourth data to the second communication module through the first communication module, so that the second electronic device obtains the fourth data.
[0378] After obtaining the fourth data, the first synchronization service module may send the fourth data to the second communication module of the second electronic device through the first communication module, so as to synchronize the fourth data with the second electronic device.
[0379] Among them, S408 and S409 are respectively Fig. 9 The implementation methods of S203 and S204 in the illustrated embodiment are similar and will not be described in detail here.
[0380] S410. The second communication module sends fourth data to the second synchronization service module.
[0381] After obtaining the fourth data, the second communication module may send the fourth data to the second synchronization service module, so that the second synchronization service module can process the fourth data.
[0382] S411. When receiving the fourth data, the second synchronization service module obtains fifth data according to the fourth data.
[0383] Among them, S411 and Fig.10 The implementation of S303 in the illustrated embodiment is similar and will not be described in detail in this application.
[0384] S412. The second synchronization service module sends fifth data to the second database.
[0385] After obtaining the fifth data, the second synchronization service module may also send the fifth data to the second database to facilitate the second database to store the fifth data.
[0386] S413: The second database stores the fifth data in a database of the second electronic device.
[0387] After obtaining the fourth data, the second database may also generate fifth data and store the fifth data in the synchronization database of the second electronic device, so that the second electronic device stores the data synchronized from the first electronic device.
[0388] Specifically, the second database can store the fifth data in the log database in the synchronization database of the first electronic device, and then the log database processes the fifth data and stores the processed fifth data in the business database, so that the processed fifth data is stored in the second electronic device.
[0389] In the present application, as the user performs an operation on the second electronic device, the second electronic device can generate first data, and thus the second electronic device can send the first data to the first electronic device. The first electronic device can obtain third data based on the conflicting data and the data that does not belong to the conflicting data in the first data of the second electronic device, and store the third data, thereby realizing synchronization of the data in the second electronic device with the first electronic device.
[0390] In addition, after the first electronic device obtains the fourth data to be synchronized to the second electronic device based on the conflicting data and the data that is not conflicting data in the second data of the first electronic device, the fourth data can be sent to the second electronic device to facilitate synchronization of the fourth data to the second electronic device. As a result, the second electronic device can obtain the fifth data based on the fourth data and store the fifth data, thereby completing the data synchronization between the first electronic device and the second electronic device.
[0391] Exemplarily, the present application provides a data synchronization device, which is used to execute the data synchronization method executed by the first electronic device in the previous embodiment; the data synchronization device in the first electronic device may include a first communication module, a first synchronization service module and a first database.
[0392] Exemplarily, the present application provides a data synchronization device, which is used to execute the data synchronization method executed by the second electronic device in the previous embodiment; the data synchronization device in the second electronic device may include a second communication module, a second synchronization service module and a second database.
[0393] Exemplarily, the present application provides an electronic device, comprising one or more processors, a memory and one or more computer programs, wherein the one or more computer programs are stored in the memory, and when the computer programs are executed by one or more processors, the electronic device executes the data synchronization method in the foregoing embodiments.
[0394] Exemplarily, the present application provides a chip system, which includes a processor for calling and running a computer program from a memory, so that an electronic device equipped with the chip system executes the data synchronization method in the foregoing embodiment.
[0395] Exemplarily, the present application provides a computer-readable storage medium, including a computer program, which, when executed on an electronic device, enables the electronic device to execute the data synchronization method in the foregoing embodiment.
[0396] Exemplarily, the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the data synchronization method in the foregoing embodiments.
[0397] In the above embodiments, all or part of the functions can be implemented by software, hardware, or a combination of software and hardware. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer codes or instructions. When the computer program code or instructions are loaded and executed on a computer, the process or function according to the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer code or instructions can be stored in a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integration. Available media can be magnetic media, (e.g., floppy disk, hard disk, tape), optical media (e.g., DVD), or semiconductor media (e.g., solid state disk (SSD)), etc.
[0398] A person skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by a computer program to instruct the relevant hardware, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above-mentioned method embodiments. The aforementioned storage medium includes: a read-only memory (ROM) or a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
Claims
1. A data synchronization method, It is characterized in that Applied to a first electronic device, the first electronic device is applied to a first communication system, the first communication system includes a first electronic device and a second electronic device, the method includes: When receiving first data sent by the second electronic device, determining whether there is conflicting data between the first data and the second data, the first data being operation data generated by an operation on user data in the second electronic device, the second data being operation data generated by an operation on user data in the first electronic device, and the conflicting data being operation data generated by an operation on the same user data in the first data and the second data; When conflicting data exists between the first data and the second data, third data is obtained according to the first data and the conflicting data, the third data including first sub-data and second sub-data, the first sub-data being the data with the latest generation time among the conflicting data, and the second sub-data being the data among the conflicting data that is generated earlier than the first sub-data and is renamed; Obtain fourth data according to the second data and the conflicting data, wherein the fourth data includes the first sub-data and the second sub-data; The fourth data is sent to the second electronic device so that the second electronic device obtains the fourth data, and the total data quantity of the fourth data and the first data is the same as the total data quantity of the third data and the second data.
2. The method according to claim 1, It is characterized in that The third data further includes third sub-data, and the third sub-data is data in the first data that does not belong to the conflicting data.
3. The method according to claim 1 or 2, It is characterized in that The fourth data further includes fourth sub-data, and the fourth sub-data is data in the second data that does not belong to the conflicting data.
4. The method according to any one of claims 1 to 3, It is characterized in that The first data includes first attribute information of operation data generated by the operation on the user data in the second electronic device, and the second data includes the first attribute information of operation data generated by the operation on the user data in the first electronic device; Determining whether there is conflicting data between the first data and the second data includes: It is determined whether the first attribute information of the first data and the first attribute information of the second data have the same attribute information.
5. The method according to claim 4, It is characterized in that The first attribute information includes at least one of a data sequence number, a data identifier, an operation content, and a generation time, and the determining whether the first attribute information of the first data and the first attribute information of the second data have the same attribute information includes: Determine whether the data identifier of the first data and the data identifier of the second data have the same data identifier.
6. The method according to any one of claims 1 to 5, It is characterized in that The conflict data includes second attribute information corresponding to the operation data generated by the operation on the same user data in the first data and the second data, the second attribute information includes at least one of data identification, operation content, generation time and label information, the label information is used to indicate whether each data in the conflict data is the data with the latest generation time, and the label information is determined according to the generation time.
7. The method according to any one of claims 1 to 6, It is characterized in that The third data includes third attribute information of the first sub-data, the third attribute information of the second sub-data, and the third attribute information of the third sub-data, and the third attribute information includes at least one of a data identifier and an operation content.
8. The method according to any one of claims 1 to 7, It is characterized in that The fourth data includes the first attribute information of the first sub-data, the first attribute information of the second sub-data, and the first attribute information of the fourth sub-data, and the first attribute information includes at least one of a data sequence number, a data identifier, an operation content, and a generation time.
9. The method according to any one of claims 1 to 8, It is characterized in that After obtaining the third data according to the first data and the conflicting data, the method further includes: The third data is stored in a database of the first electronic device.
10. The method according to any one of claims 1 to 9, It is characterized in that The first communication system further includes a third electronic device, data transmission between the third electronic device and the second electronic device is completed through the first electronic device, when the operation data generated by the operation on the user data in the first electronic device is data sent by the third electronic device, when receiving the first data sent by the second electronic device, before determining whether there is conflicting data between the first data and the second data, the method further includes: receiving the second data sent by the third electronic device; After obtaining the third data according to the first data and the conflicting data, the method further includes: The third data is sent to the third electronic device.
11. A data synchronization method, It is characterized in that Applied to a second electronic device, the second electronic device is applied to a first communication system, the first communication system includes a first electronic device and a second electronic device, the method includes: When data is detected to be generated after the original data in the second electronic device, the data after the original data is determined as first data; or the data after the original data is periodically determined as first data, the first data being operation data generated by the operation on the user data in the second electronic device; sending the first data to the first electronic device; When receiving the fourth data, obtaining fifth data according to the fourth data; The fourth data is obtained based on the second data and the conflict data, the conflict data is obtained based on the first data and the second data, the second data is operation data generated by the operation on the user data in the first electronic device, the conflict data is operation data generated by the operation on the same user data in the first data and the second data, the fourth data includes the first sub-data and the second sub-data, and the generation time corresponding to the first sub-data and the second sub-data respectively, the first sub-data is the data with the latest generation time in the conflict data, the second sub-data is the data in the conflict data that is generated earlier than the first sub-data and is renamed, the fifth data includes the first sub-data and the second sub-data, the total data quantity of the fifth data and the first data is the same as the total data quantity of the third data and the second data, the third data is obtained based on the first data and the conflict data, and the third data includes the first sub-data and the second sub-data.
12. The method according to claim 11, It is characterized in that The third data further includes third sub-data, and the third sub-data is data in the first data that does not belong to the conflicting data.
13. The method according to claim 11 or 12, It is characterized in that The fourth data also includes fourth sub-data and a generation time of the fourth sub-data, and the fourth sub-data is data in the second data that does not belong to the conflicting data.
14. The method according to any one of claims 11 to 13, It is characterized in that The fifth data also includes fourth sub-data, and the fifth data includes the third attribute information of the first sub-data, the third attribute information of the second sub-data, and the third attribute information of the fourth sub-data.
15. The method according to any one of claims 10 to 14, It is characterized in that After generating fifth data according to the fourth data when the fourth data is received, the method further includes: The fifth data is stored in a database of the second electronic device.
16. An electronic device, It is characterized in that include: One or more processors, a memory, and one or more computer programs; wherein the one or more computer programs are stored in the memory, and when the computer programs are executed by the one or more processors, the electronic device executes the data synchronization method as described in any one of claims 1 to 10, and / or the data synchronization method as described in any one of claims 11 to 15.
17. A chip system, It is characterized in that The chip system includes a processor for calling and running a computer program from a memory, so that an electronic device equipped with the chip system executes the data synchronization method as described in any one of claims 1 to 10, and / or the data synchronization method as described in any one of claims 11 to 15.
18. A computer-readable storage medium comprising a computer program, It is characterized in that When the computer program is executed on a terminal device, the electronic device executes the data synchronization method according to any one of claims 1 to 10 and / or the data synchronization method according to any one of claims 11 to 15.
Citation Information
Patent Citations
Data synchronization implementing method and apparatus
CN101313506A
Data synchronization method and device
CN115878723A