Data synchronization method, device and system
Maintaining the main transaction log and sub-transaction log through cloud devices solves the problem of limited storage space on terminal devices, and achieves data consistency synchronization between multiple terminal devices, reducing the amount and complexity of synchronized data and avoiding cyclic data conflicts.
Patent Information
- Application Number
- CN202210841048.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-18
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2042-07-18
AI Technical Summary
The storage space of terminal devices is limited, resulting in limited storage of application data, and data synchronization between multiple terminal devices has consistency issues and data conflicts.
Cloud devices maintain master transaction logs and sub-transaction logs, manage data synchronization across multiple terminal devices through transaction identifiers, support parallel operations, resolve data conflicts, and reduce the amount and complexity of synchronized data.
It enables storage of application data in the cloud, solves the storage space limitations of terminal devices, ensures data consistency between multiple terminal devices, reduces the amount and complexity of synchronized data, and avoids cyclic data conflicts.
Smart Images

Figure CN117453807B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular to a data synchronization method, device, and system. Background Art
[0002] An application (APP) is a computer program used to complete a specific task.
[0003] Currently, there are a wide variety of applications, such as social applications, shopping applications, travel applications, utility applications, video applications, and financial applications, which can meet the different needs of users. When an application is run on a terminal device, some application data is usually generated.
[0004] In a traditional way, application data is stored in a terminal device, but due to the limited storage space of the terminal device, the amount of application data that can be stored is limited. Summary of the Invention
[0005] The present application provides a data synchronization method, device and system that can store application data in the cloud and synchronize application data between multiple devices.
[0006] To achieve the above objectives, this application adopts the following technical solutions:
[0007] In a first aspect, an embodiment of the present application provides a data synchronization method. The method is applied to a cloud device. The method includes:
[0008] The cloud device receives a synchronization request message from a first device, where the first device is any one of the multiple terminal devices bound to the cloud device. If the synchronization request message carries the first change data, the cloud device determines whether the first change data conflicts with the second change data stored in the cloud device. In the case where there is no transaction conflict between the first change data and the second change data, the cloud device generates a first transaction identifier in the master transaction log, and the first transaction identifier is used to indicate the first change data; or, in the case where there is a transaction conflict between the first change data and the second change data, the cloud device generates a second transaction identifier in the master transaction log, and the second transaction identifier is used to indicate the merged data obtained after processing the first change data and the second change data. The first change data is the change data of the first application in the first device, and the second change data is the change data of the first application in the second device of the multiple terminal devices. The second change data is indicated by the third transaction identifier in the master transaction log, and the third transaction identifier is the previous transaction identifier of the second transaction identifier, that is, the most recent transaction identifier generated by the master transaction log before the second transaction identifier is generated.
[0009] In the above scheme, each transaction identifier in the master transaction log is recorded in time sequence, and the third transaction identifier is referred to as the latest transaction identifier before completion of the current synchronization. When any terminal device bound to the cloud device initiates a current synchronization request, if the first change data carried in the synchronization request message has no transaction conflict with the change data indicated by the third transaction identifier, the transaction identifier corresponding to the first change data can be written in the master transaction log record; otherwise, the transaction conflict needs to be solved first, and then the transaction identifier corresponding to the first change data is written in the master transaction log record.
[0010] By maintaining the master transaction log by the cloud device, the application data of the plurality of terminal devices bound to the cloud device can be recorded, and the problem of limited storage of application data of the terminal device is solved. In addition, the synchronization mechanism among the plurality of terminal devices is improved, and the consistency problem when the data of the plurality of terminal devices is modified in parallel is solved. Unlike the scheme in which locking is performed during traditional end-side synchronization, the synchronization mechanism of the present application supports parallel synchronization operation of the plurality of terminal devices. During end-side synchronization, only the modification content of the master transaction log is synchronized, the amount and complexity of the synchronized data are reduced, and at the same time, no circular data is generated.
[0011] It should be noted that "the first change data and the second change data have no transaction conflict" means that no other device submits change data to the cloud device after the cloud device and the certain terminal device complete the last synchronization and before the terminal device requests the current synchronization from the cloud device. "The first change data and the second change data have transaction conflict" means that other devices submit change data to the cloud device after the cloud device and the certain terminal device complete the last synchronization and before the terminal device requests the current synchronization from the cloud device, and the two change data make different changes to the application.
[0012] In a possible implementation, the first device and the second device initiating the two synchronizations can be the same device or different devices, that is, any terminal device bound to the cloud device can initiate data synchronization to the cloud device at any time.
[0013] In a possible implementation, the cloud device maintains a plurality of sets of transaction logs, and the plurality of sets of transaction logs include a master transaction log and a sub-transaction log corresponding to each terminal device. One terminal device corresponds to one sub-transaction log. Each set of transaction logs records a set of transaction identifiers in time sequence. The master transaction log is used to record transactions finally agreed by all devices, and the transactions have no conflict, so the master transaction log is the main trunk stored by the cloud. The sub-transaction log corresponding to each terminal device is used to record data change of each terminal device and result data after conflict resolution, and the sub-transaction log is the branch stored by the cloud.
[0014] In a possible implementation, before determining whether the first change data and the second change data exist transaction conflict, the cloud device generates a fourth transaction identifier in the sub-transaction log corresponding to the first device, and the fourth transaction identifier is used to indicate the first change data. The first transaction identifier and the second transaction identifier are obtained according to the fourth transaction identifier. For example, if there is no transaction conflict, the first transaction identifier is the fourth transaction identifier; if there is transaction conflict, the first transaction identifier is the next transaction identifier generated after the first transaction identifier.
[0015] In a possible implementation, the synchronization request message can belong to any of the following cases:
[0016] The synchronization request message carries the first change data and the previous transaction identifier.
[0017] The synchronization request message carries the first change data and does not carry the previous transaction identifier.
[0018] The synchronization request message carries the previous transaction identifier and does not carry the first change data.
[0019] The synchronization request message does not carry the first change data and the previous transaction identifier.
[0020] The previous transaction identifier is a transaction identifier generated by the cloud device in the master transaction log when the cloud device and the first device complete the last data synchronization. It should be understood that the previous transaction identifier is the same transaction identifier as the latest transaction identifier, or the previous transaction identifier is a transaction identifier generated before the latest transaction identifier.
[0021] In a possible implementation, the synchronization request message carries the first change data and the previous transaction identifier. Accordingly, in the case that the first change data carried in the synchronization request message and the second change data stored by the cloud device do not exist transaction conflict, the cloud device generates the first transaction identifier in the master transaction log, including: in the case that the previous transaction identifier carried in the synchronization request message is the same as the fourth transaction identifier, the cloud device writes the fourth transaction identifier as the first transaction identifier into the master transaction log. It should be understood that, if the previous transaction identifier and the fourth transaction identifier are the same, it indicates that the first change data and the second change data do not exist transaction conflict, and then the cloud device can directly write the new transaction identifier generated in the sub-transaction log into the master transaction log, so as to realize data synchronization.
[0022] In one possible implementation, the synchronization request message carries the first change data and the previous transaction identifier. Accordingly, in the case where there is a transaction conflict between the first change data carried by the synchronization request message and the second change data stored in the cloud device, the cloud device generates a second transaction identifier in the master transaction log, including: in the case where the previous transaction identifier carried by the synchronization request message is different from the fourth transaction identifier, the cloud device obtains the merged data based on the fourth transaction identifier, and generates a second transaction identifier in the master transaction log. It should be understood that when the previous transaction identifier and the latest transaction identifier reported by the terminal device are different, it means that the change data was submitted by other devices before the current device was changed, and there is a transaction conflict. At this time, the cloud device needs to resolve the data conflict first and then synchronize the data.
[0023] In one possible implementation, the synchronization request message does not carry a preceding transaction identifier. Accordingly, in the event that there is a transaction conflict between the first change data carried by the synchronization request message and the second change data stored by the cloud device, the cloud device generates a second transaction identifier in the master transaction log, including: the cloud device obtains the merged data based on the fourth transaction identifier, and generates a second transaction identifier in the master transaction log. It should be understood that when the terminal device does not report the preceding transaction identifier, it means that this is the first time that the terminal device carries the existing local data for synchronization. Therefore, the data reported by the terminal device conflicts with the modification history saved by the cloud device. At this time, the cloud device needs to resolve the data conflict before synchronizing the data.
[0024] In one possible implementation, the cloud device obtains the merged data based on the fourth transaction identifier and generates a second transaction identifier in the main transaction log, including: the cloud device generates a data conflict list based on the first change data and the second change data; the cloud device obtains the merged data based on the data conflict list; the cloud device generates a merge transaction identifier in the sub-transaction log corresponding to the first device, the merge transaction identifier is used to indicate the merged data; the cloud device writes the merge transaction identifier as the second transaction identifier to the main transaction log. It should be understood that when there is a conflict between the modification history reported by the terminal device and the modification history saved by the cloud device, the data conflict can be resolved first, and then a new transaction can be generated in the sub-transaction log of the terminal device, and then the ID of the new transaction can be written to the main transaction log, thereby solving the consistency problem during parallel modification.
[0025] In one possible implementation, the cloud device obtains the merged data based on the data conflict list, including: the cloud device processes the conflicting data in the data conflict list to obtain the merged data; or the cloud device sends the data conflict list to the first device and receives the merged data from the first device, where the merged data is obtained based on the data conflict list. It should be understood that when a conflict exists between the modification history reported by the terminal device and the modification history stored by the cloud device, the data conflict can be resolved by the cloud device or the terminal device.
[0026] In a possible implementation, if the merged data is data obtained after the first change data and the second change data are processed by the cloud device, the method further includes: sending, by the cloud device, the merged data to the first device. It should be understood that when the data conflict is resolved by the cloud device, the terminal device does not know the conflict resolution manner, and therefore the cloud device sends the merged data after resolving the conflict to the terminal device, so that the terminal device can perform data synchronization.
[0027] In a possible implementation, after the cloud device generates the latest transaction identifier in the master transaction log, the cloud device sends the latest transaction identifier to the first device, so that the first device can take the latest transaction identifier as the previous transaction identifier in the next data synchronization.
[0028] In a possible implementation, the synchronization request message carries the previous transaction identifier and does not carry the first change data. Accordingly, the method further includes: determining, by the cloud device, third change data, and sending, by the cloud device, the third change data and the latest transaction identifier in the master transaction log to the first device. The third change data includes change data indicated by all transaction identifiers generated after the previous transaction identifier in the master transaction log. It should be understood that if the terminal device reports the previous transaction identifier and does not report the change data, it indicates that the terminal device has not modified the application program since the last synchronization, and therefore the cloud device can directly send the modification history recorded by the master transaction log since the last synchronization to the terminal device, so that the terminal device can perform data synchronization.
[0029] In a possible implementation, the synchronization request message does not carry the previous transaction identifier and the first change data. Accordingly, the method further includes: determining, by the cloud device, fourth change data, and sending, by the cloud device, the fourth change data and the latest transaction identifier in the master transaction log to the first device. The fourth change data includes change data indicated by all transaction identifiers in the master transaction log. It should be understood that if the terminal device does not report the previous transaction identifier and the change data, it indicates that this is the first time that the terminal device requests data synchronization, and therefore the cloud device can directly send all stored modification history to the terminal device, so that the terminal device can perform data synchronization.
[0030] In one possible implementation, the method includes: the cloud device deletes the transaction identifiers generated before the target time in the master transaction log and the sub-transaction log corresponding to each terminal device based on the generation time of each transaction identifier in the master transaction log and the generation time of each transaction identifier in the sub-transaction log corresponding to each terminal device. Alternatively, in a case where the preceding transaction identifiers of each terminal device are all target transaction identifiers, the cloud device deletes the transaction identifiers generated before the target transaction identifier in the master transaction log and the sub-transaction log corresponding to each terminal device, and the preceding transaction identifier of each terminal device is the transaction identifier generated by the cloud device in the sub-transaction log corresponding to each terminal device when the last data synchronization with each terminal device was completed. It should be understood that by deleting transaction identifiers and change data, historical data space can be released.
[0031] In a second aspect, an embodiment of the present application provides a data synchronization method. The method is applied to any one of multiple terminal devices bound to a cloud device. Taking the execution subject as the first device as an example, the method may include:
[0032] The first device sends a synchronization request message to the cloud device. The synchronization request message carries at least one of the first change data and the preceding transaction identifier, or the synchronization request message does not carry the first change data and the preceding transaction identifier. The first change data is the change data of the first application in the first device. The preceding transaction identifier is the transaction identifier generated in the master transaction log of the cloud device when the first device and the cloud device completed the last data synchronization. Each transaction identifier in the master transaction log is recorded in chronological order.
[0033] Through the above solution, any terminal device can initiate a synchronization request message to the cloud device, reporting the changed data and / or the previous transaction identifier, thereby facilitating the cloud device to synchronize data according to the synchronization request message.
[0034] In one possible implementation, the synchronization request message carries the first changed data and a preceding transaction identifier; or the synchronization request message carries the first changed data but does not carry a preceding transaction identifier. Accordingly, after the first device sends the synchronization request message to the cloud device, the method further includes the following two solutions:
[0035] In one solution, a first device receives first merged data from a cloud device and performs data synchronization based on the first merged data, wherein the first merged data is merged data obtained after processing first change data and second change data that have transaction conflicts, and the second change data is change data of the first application on the second device.
[0036] Another solution is that the first device receives a data conflict list from the cloud device, processes the conflicting data in the data conflict list to obtain second merged data, synchronizes data based on the second merged data, and sends the second merged data to the cloud device. The data conflict list is generated based on the first change data and the second change data in which the transaction conflict exists.
[0037] In one possible implementation, the synchronization request message carries a preceding transaction identifier but does not carry the first change data. Accordingly, after the first device sends a synchronization request message to the cloud device, the method further includes: the first device receives third change data from the cloud device, and the third change data includes the change data indicated by all transaction identifiers generated after the preceding transaction identifier in the master transaction log. It should be understood that if the terminal device reports the preceding transaction identifier but does not report the change data, it means that the terminal device has not modified the application since the last synchronization. Therefore, the terminal device can obtain the modification history after the last synchronization from the cloud device, thereby achieving data synchronization.
[0038] In one possible implementation, the synchronization request message does not carry the preceding transaction identifier and the first change data. Accordingly, after the first device sends the synchronization request message to the cloud device, the method further includes: the first device receives fourth change data from the cloud device, and the fourth change data includes the change data indicated by all transaction identifiers of the master transaction log. It should be understood that if the terminal device does not report the preceding transaction identifier and change data, it means that this is the first time the terminal device has requested data synchronization, so the terminal device can obtain all modification history from the cloud device to achieve data synchronization.
[0039] In one possible implementation, the method further includes: after the first device completes each data synchronization with the cloud device, the first device receives the latest transaction identifier from the cloud device, and uses the latest transaction identifier as the preceding transaction identifier for the next data synchronization. It should be understood that after the terminal device completes each data synchronization with the cloud device, the terminal device can store the preceding transaction identifier. This allows the cloud device to determine whether a transaction conflict exists based on the preceding transaction identifier and the latest transaction identifier when initiating the next synchronization.
[0040] In a third aspect, the present application provides a synchronization device, comprising units / modules for executing the method described in the first or second aspect. The device may be configured to execute the method described in the first or second aspect. For a description of the units / modules in the device, refer to the description of the first or second aspect above, and for the sake of brevity, these descriptions are omitted here.
[0041] In a fourth aspect, a cloud device is provided, comprising a processor, a memory, and a communication interface. The processor and the communication interface are coupled to the memory. The processor is configured to execute a computer program or instruction stored in the memory, so that the cloud device implements the data synchronization method according to any one of the first aspects.
[0042] In a fifth aspect, a terminal device is provided, comprising a processor, a memory, and a communication interface. The processor and the communication interface are coupled to the memory. The processor is configured to execute a computer program or instruction stored in the memory, so that the terminal device implements the data synchronization method according to any one of the second aspects.
[0043] In a sixth aspect, a chip is provided, which is coupled to a memory and is used to read and execute a computer program stored in the memory to implement a data synchronization method as described in any one of the first aspect or the second aspect.
[0044] In a seventh aspect, a computer-readable storage medium is provided, the computer-readable storage medium storing a computer program. When the computer program is executed on a cloud device, the cloud device executes the data synchronization method according to any one of the first aspects; or, when the computer program is executed on a terminal device, the terminal device executes the data synchronization method according to any one of the second aspects.
[0045] In an eighth aspect, a communication system is provided, comprising a cloud device as in the fourth aspect, and a terminal device as in the fifth aspect.
[0046] In a ninth aspect, a computer program product is provided. When the computer program product is run on a computer, the computer is caused to execute the data synchronization method as described in any one of the first aspect or the second aspect.
[0047] It can be understood that the beneficial effects of the third to ninth aspects mentioned above can be found in the relevant descriptions in the first or second aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 A schematic diagram of a distributed database synchronization mechanism provided in an embodiment of the present application;
[0049] Figure 2 A schematic diagram of a synchronization mechanism for quasi-synchronization marked speech provided in an embodiment of the present application;
[0050] Figure 3 A schematic diagram of a communication system provided in an embodiment of the present application;
[0051] Figure 4 A schematic diagram of transaction logs corresponding to application data of different terminal devices provided in an embodiment of the present application;
[0052] Figure 5 A schematic diagram of three groups of transaction logs provided in an embodiment of the present application;
[0053] Figure 6 A flowchart of a data synchronization method provided in an embodiment of the present application;
[0054] Figure 7 One of the schematic diagrams of the synchronization process provided in the embodiment of the present application;
[0055] Figure 8 The second schematic diagram of the synchronization process provided in the embodiment of the present application;
[0056] Figure 9 The third schematic diagram of the synchronization process provided in the embodiment of the present application;
[0057] Figure 10 Schematic diagram 4 of the synchronization process provided in an embodiment of the present application;
[0058] Figure 11 Schematic diagram 5 of the synchronization process provided in the embodiment of the present application;
[0059] Figure 12 A flowchart of another data synchronization method provided in an embodiment of the present application;
[0060] Figure 13 A schematic structural diagram of a synchronization device provided in an embodiment of the present application;
[0061] Figure 14 A schematic diagram of the structure of the cloud device provided in an embodiment of the present application;
[0062] Figure 15 A schematic diagram of the structure of the terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments.
[0064] In the description of this application, unless otherwise specified, " / " means or. For example, A / B can mean A or B. In the description of this application, "and / or" is simply a way to describe the association relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0065] The terms "first" and "second" and the like in the description and claims of the application are used for distinguishing between similar elements and not necessarily for describing a specific sequential or chronological order. For example, the first transaction and the second transaction are used for distinguishing between two different transactions and not necessarily for describing a specific sequential or chronological order. In the embodiments of the present application, "multiple" means two or more than two.
[0066] Reference in the specification to "one embodiment" or "some embodiments" means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the application. The appearances of the phrase "in one embodiment" or "in some embodiments" in various places in the specification are not necessarily all referring to the same embodiment, although it can. The terms "comprising," "including," "having," and the like are meant to be open-ended terms that specifically permit the specification of more than one component. Use of the terms "first," "second" and the other such
[0067] Firstly, some terms or nouns involved in the present application are explained.
[0068] Application data refers to data generated by an application for recording various operations of the application, such as insertion, update, deletion, submission, or rollback, and the like, in the process of running the application on a terminal device. For example, the application data can be chat records and contact records of a contact list, a short message, or an instant chat tool, can be bookmarks or browsing records of a browser, a video APP, or a shopping APP, can be records of newly taken photos or videos, and can be editing records of files, documents, work sheets, or databases, and the like, which are not limited in the embodiments of the present application.
[0069] In the traditional way, the application data is stored in the terminal device. However, due to the limited storage space of the terminal device, the application data stored in the terminal device is limited. In order to solve this problem, a cloud device can be used to store the application data. "Cloud" is a metaphor for the Internet or a large server cluster, which is composed of distributed Internet infrastructure, such as network devices, servers, storage devices, and security devices, and the like. The terminal device only needs to have a functional browser and install a simple operating system, and by accessing the "cloud" through the network, the computing resources in the cloud can be used. Cloud computing realizes the migration of complex and changing software and hardware to the cloud device, and the computing work of the terminal device is also migrated to the cloud device, which carries out the specific application computing tasks of the terminal device. The terminal device is connected to the cloud device through the network, and the cloud resources can be obtained, so that the software and hardware of the terminal device are greatly simplified.
[0070] The following introduces two cloud-based device synchronization mechanisms.
[0071] For example, Figure 1 A schematic diagram of a distributed database synchronization mechanism is shown. Figure 1 As shown, the cloud device, terminal device A and terminal device B all maintain transaction logs and databases.
[0072] When terminal device A or terminal device B makes modifications to the database—for example, a user modifies a cell corresponding to a specific row or column in the database—these changes are detected by the event monitor, which generates a new transaction log and stores it in the transaction cache. Terminal device A or terminal device B then sends the transaction log to the cloud device. The cloud device may receive transaction logs from one or more devices. If it receives transaction logs from multiple devices, the cloud device can first compare these transaction logs to determine whether there are any conflicts. If there are no conflicts, the transaction logs are applied to the database. If there are conflicts, the cloud device determines whether the conflicting transactions can be merged. If so, the merged transactions are applied to the database. When the cloud device and terminal devices synchronize data, the cloud device broadcasts the transaction logs to each terminal device. Each terminal device reconstructs its data based on the received transaction logs. In this synchronization mechanism, each terminal device may generate a large number of transactions, and the cloud device must broadcast each transaction to all terminal devices, resulting in a large amount of synchronized data. Furthermore, in this synchronization mechanism, data conflict resolution is based on transactions, which may lead to data loss.
[0073] For example, Figure 2 A schematic diagram of a synchronization mechanism similar to SyncML is shown. Figure 2 As shown, the cloud device maintains a database. Terminal device A and terminal device B both maintain a database and data to be synchronized.
[0074] Taking terminal device A as an example, the data synchronization process is described as follows: Terminal device A and the cloud device initiate data synchronization. Terminal device A sends a verification message to the cloud device containing a data fingerprint corresponding to the data stored in its own database. The cloud device verifies the verification message and, based on the comparison result, determines the data to be synchronized. It then sends a response message containing the identification of the data to be synchronized to terminal device A. Terminal device A determines the data to be synchronized based on the response message and sends the data to the cloud device. The cloud device returns a response message to terminal device A confirming the completion of data synchronization. Terminal device A synchronizes the data in its own database based on the data carried in the response message returned by the cloud device. Terminal device A sends a message to the cloud device confirming the completion of data synchronization. After receiving this message, the cloud device saves the synchronization completion status and sends a response message to terminal device A confirming the completion of data synchronization, thus completing the data synchronization process. This synchronization mechanism requires at least three steps: downloading changes from the cloud, applying the changes locally and resolving conflicts, and uploading the local changes. Excessive interactions can lead to long synchronization cycles, especially under poor network conditions. Furthermore, if terminal device A and terminal device B make changes concurrently, cyclic data conflicts may occur. In addition, there is no complete change history record in the cloud device, and only the version after conflict resolution is saved. That is, the data changed on the terminal device must be uploaded to the cloud after the data conflict is resolved.
[0075] In view of the problems existing in the above-mentioned synchronization mechanism, an embodiment of the present application provides an improved data synchronization method, which is not only applicable to files, but also to structured data with unique IDs. For each application that supports personal cloud in multiple terminal devices, the cloud device maintains multiple groups of transaction logs, and each group of transaction logs records a group of transaction identifications (IDs) in chronological order. When a terminal device initiates synchronization, the terminal device first reports the changed data and the previous transaction ID of the terminal device to the cloud device, and then, when the previous transaction ID is different from the latest transaction ID (that is, there is a data conflict), the cloud device or the terminal device resolves the conflict. Afterwards, the cloud device sends the change data between the latest transaction ID and the previous transaction ID of the terminal device. By improving the synchronization mechanism between multiple terminal devices, the consistency problem of data modification in parallel between multiple terminal devices is solved, the amount and complexity of synchronized data are reduced, and the modification history of each data of each terminal device can be tracked and rolled back without generating circular data.
[0076] For example, Figure 3 FIG. 1 shows a schematic diagram of a communication system. Figure 3 As shown, the communication system includes a cloud device 01 and multiple terminal devices connected to the cloud device 01.
[0077] The cloud device 01 and the plurality of terminal devices establish a network connection via a mobile communication method or a wireless communication method, wherein the network can be a local area network, a wide area network or the Internet.
[0078] Cloud device 01 may be an internet infrastructure for providing "cloud" services, such as network equipment, servers, storage devices, and security devices. In some embodiments, the server provides storage and synchronization services for the terminal devices. It is understood that the devices used to provide cloud storage and synchronization services for the terminal devices may also include storage devices, etc., and may be adjusted based on actual needs.
[0079] The terminal device connected to the cloud device 01 can be Figure 3 The mobile phone 02, personal computer (PC) 03, personal digital assistant (PDA) 04, watch 05, and headset 06 are shown. Of course, the terminal device can also be any electronic device such as a tablet computer, a car-mounted device, an augmented reality (AR) device, a virtual reality (VR) device, a laptop computer, a smart screen, an ultramobile personal computer (UMPC) or a netbook, and the present embodiment of the application does not limit this. It should be noted that the present embodiment of the application does not limit the number and type of terminal devices connected to the cloud device.
[0080] In the embodiment of the present application, a transaction log is used to store all changes made to application data and record inserts, updates, deletes, commits, rollbacks, and database schema changes. A user can register a cloud account on a cloud device and bind multiple terminal devices associated with the cloud account. Each terminal device has one or more applications that support cloud storage installed. For each application that supports personal cloud, the cloud device maintains multiple sets of transaction logs, namely:
[0081] The main transaction log (main log) is used to record the final transaction consensus reached by all devices. The main transaction log is the backbone of cloud storage;
[0082] A branch log is used to record data changes and conflict resolution results for each terminal device. The branch log is a branch stored in the cloud, and different terminal devices correspond to different branch logs.
[0083] For example, Figure 4 FIG. 1 shows a schematic diagram of transaction logs corresponding to application data of different terminal devices. Figure 4As shown, user 1 and user 2 respectively register a cloud account in the cloud device. The cloud account of user 1 is bound to terminal device A, terminal device B and terminal device C. The cloud account of user 2 is bound to terminal device D, terminal device E and the like.
[0084] Each terminal device bound to each cloud account is provided with a synchronization manager and at least one application program supporting cloud storage. The synchronization manager is configured to send the changed data of the application program to the cloud device and receive the changed data of the application program from the cloud device. The at least one application program can be a social application program, a shopping application program, a travel application program, a tool application program, a video application program, a financial application program and the like. In some embodiments, when the user uses any one of the at least one application program, if the application program is operated, the terminal device will record each changed data. After the terminal device initiates synchronization, the changed data is reported to the cloud device through the synchronization manager.
[0085] The cloud device can include a plurality of logical containers, each of which is configured to store data from different cloud accounts or from different application programs of different cloud accounts. In some embodiments, the logical container can be a directory in a file system, a data structure or other data organization unit. Figure 4 As shown, for user 1, each of the application programs 1, 2, …, n has a separate container; for user 2, each of the application programs 1, 2, …, m has a separate container.
[0086] Taking the logical container of application program 1 as an example. The logical container stores the transaction log of terminal device A using application program 1, the transaction log of terminal device B using application program 1, and the transaction log of terminal device C using application program 1. The transaction log of each terminal device is configured to record the changed data of each device using application program 1 and the result data after resolving the conflict before merging into the main transaction. In addition, the logical container also stores the main transaction log, which is configured to record the result data of the transaction agreement reached by terminal device A, terminal device B and terminal device C for application program 1, i.e. the result data without transaction conflict.
[0087] In the embodiments of the present application, for the plurality of sets of transaction logs maintained by the cloud device, each set of transaction logs can record a plurality of transactions in chronological order, each transaction including a transaction ID and changed data. In some embodiments, each transaction can further include the transaction generation time and the source device of the changed data. If the changed content corresponding to the transaction ID is aggregated between the specified commit nodes, the data change between the two nodes can be determined.
[0088] Exemplarily,Figure 5 A schematic diagram showing three sets of transaction logs.
[0089] For terminal device A, the transaction log is initially empty. After the cloud device receives the changed data File1 and File2 from terminal device A, it generates transaction V1-A based on these changes. Later, the cloud device receives the changed data File3 and File4 from terminal device A and generates transaction V2-A based on these changes. If the specified nodes are V1-A and V2-A, the changed data between these two nodes is File3 and File4.
[0090] For the transaction log of terminal device B, the transaction log is initially empty. After the cloud device receives the changed data File4 and File5 from terminal device B, it generates transaction V3-B based on the changed data File4 and File5. Because the changed data from terminal device A and the changed data from terminal device B both include File4, there is a data conflict. After resolving the data conflict, the cloud device generates transaction V3-B-fix based on the resolved File4 and File5. If the designated nodes are V3-B and V3-B-fix, the conflict resolution method can be determined based on the changed data between these two nodes.
[0091] The primary transaction log is initially empty. If there are no data conflicts on the first node, the cloud device generates transaction V1 based on transaction V1-A. If there are no data conflicts on the second node, the cloud device generates transaction V2 based on transaction V2-A. If the data conflict is resolved on the third node, the cloud device generates transaction V3 based on transaction V3-B-fix. If the specified nodes are V1 and V3, based on the changed data between these two nodes, it can be determined that the changed data between these two nodes are File3, File4, and File5.
[0092] It should be noted that the data conflict in the embodiment of the present application, also known as transaction conflict, refers to when different terminal devices modify the data of the application. If the modification methods are different, different change data will be recorded (for example, two File4s will be recorded), which will cause a conflict after submission to the cloud device.
[0093] In this embodiment of the present application, each terminal device participating in synchronization will record the ID of the last transaction synchronized with the cloud device, called the previous transaction ID. By reporting the previous transaction ID and the changed application data (called change data or change information), the terminal device and the cloud device can achieve data synchronization.
[0094] Exemplarily, as shown in Figure 6 The terminal device can include the following S61-S66 in each synchronization process.
[0095] S61. The terminal device records the change data of the application and the previous transaction ID.
[0096] In the case that the user logs in to any terminal device using a cloud account, the terminal device will record each change data of the application during the running process of the application supported by the cloud storage in the terminal device. The data form of these change data can be a log file or structured data with a unique ID.
[0097] After each synchronization between the terminal device and the cloud device is completed, the terminal device can obtain the latest transaction ID, i.e., the ID of the last generated transaction, from the cloud device, and store the transaction ID in the terminal device. When the terminal device initiates synchronization next time, the transaction ID will be used as the previous transaction ID.
[0098] S62. After initiating synchronization, the terminal device reports the change data and the previous transaction ID to the cloud device.
[0099] When the terminal device initiates synchronization to the cloud device each time, the terminal device can use the commit command (instruction) to report one or more change data recorded from the completion of the last synchronization process to the initiation of the current synchronization process to the cloud device.
[0100] Exemplarily, the commit command can include the following contents:
[0101] The time (Data) when the terminal device initiates synchronization;
[0102] The device identification (From: Device) of the terminal device initiating synchronization, different terminal devices use different device identifications, for example, the device identification of terminal device A is Device A, and the device identification of terminal device B is Device B;
[0103] And the change data (Data: File) from the completion of the last synchronization process to the initiation of the current synchronization process.
[0104] S63. The cloud device generates a new transaction in the sub-transaction log corresponding to the terminal device according to the change data.
[0105] The cloud device maintains multiple groups of transaction logs: a main transaction log and a sub-transaction log corresponding to each terminal device. Each group of transaction logs can record multiple transactions in chronological order, and each transaction includes a transaction ID and change data.
[0106] For example, the cloud device can determine the terminal device initiating synchronization and the changed data between the completion of the previous synchronization process and the initiation of the current synchronization process based on the device identifier of the terminal device initiating synchronization included in the commit command. The cloud device then generates a new transaction in the transaction log corresponding to the terminal device, which is used to record the changed data.
[0107] S64. The cloud device compares the latest transaction ID in the master transaction log with the previous transaction ID reported by the terminal device to see if they are the same.
[0108] S65. If the latest transaction ID in the master transaction log is the same as the previous transaction ID reported by the terminal device, then the cloud device determines that no other transactions have been generated and there will be no transaction conflict. Therefore, the ID of the new transaction generated in the sub-transaction log is written to the master transaction log.
[0109] S66. If the latest transaction ID in the master transaction log differs from the previous transaction ID reported by the terminal device, the cloud device determines that the terminal device has generated at least one transaction since the previous transaction, resulting in a transaction conflict. Therefore, the ID of the new transaction generated in the branch transaction log cannot be directly written to the master transaction log. The cloud device writes the merged transaction ID to the master transaction log. The merged transaction ID is the transaction ID generated after merging the conflicting data.
[0110] To better understand the synchronization process, several examples are given below.
[0111] Example 1
[0112] For example, Figure 7 Two synchronization processes initiated by terminal device A are shown.
[0113] Step 01: When terminal device A initiates its first synchronization, since it has not yet synchronized with the cloud device, the previous transaction ID is not recorded locally on terminal device A. Therefore, the previous transaction ID is null. In addition, terminal device A's initial data, File1 and File2, are reported as changed data. For example, terminal device A can send a commit 1 command to the cloud device. The commit 1 command includes the following: synchronization initiation time: 2022-01-01; synchronization initiating device: terminal device A; changed data: File1 and File2.
[0114] Step 02: The cloud device saves the commit 1 command. Based on the commit 1 command, the cloud device determines that the synchronization initiator is terminal device A and writes the changed data, File1 and File2, to the transaction log V1-A corresponding to terminal device A. This creates transaction V1-A, which records the changed data, File1 and File2.
[0115] Step 03: The cloud device compares the latest transaction ID in the master transaction log with the previous transaction ID reported by terminal device A. Since the master transaction log is empty, and the previous transaction ID reported by terminal device A is also empty, there is no data conflict. The cloud device creates record V1 in the master transaction log, where V1 = V1 - A.
[0116] Step 4: Since the latest transaction ID in both the sub-transaction log and the main transaction log corresponding to terminal device A is V1-A, there is no data change. Therefore, the cloud device returns the latest transaction ID, V1, to terminal device A. Terminal device A receives the latest transaction ID V1 from the cloud device as the previous transaction ID and stores it. This completes the first synchronization process between terminal device A and the cloud device.
[0117] Step 5. If, between the completion of the first synchronization and the initiation of the second synchronization, terminal device A records the changes to File3 and File4, then when terminal device A initiates the second synchronization with the cloud device, it can send the preceding transaction ID: V1, along with the commit 2 command. The commit 2 command includes the following: synchronization initiation time: 2022-01-03; synchronization initiating device: terminal device A; and changed data: File3 and File4.
[0118] Step 6: The cloud device saves the commit 2 command. Based on the commit 2 command, the cloud device determines that the synchronization initiator is terminal device A and writes the changed data, File3 and File4, to the transaction log V2-A corresponding to terminal device A. This creates transaction V2-A, which records the changed data, File1 and File2.
[0119] Step 07: The cloud device compares the latest transaction ID in the master transaction log with the previous transaction ID reported by terminal device A. Since both are V1, there is no data conflict. The cloud device generates record V2 in the master transaction log, where V2 = V2-A.
[0120] Step 08, since the latest transaction ID of the sub-transaction log corresponding to the terminal device A and the master transaction log is V2-A, there is no data change, and the cloud device returns the latest transaction ID V2 to the terminal device A. The terminal device A receives the latest transaction ID V2 returned by the cloud device as the previous transaction ID, and stores the transaction ID. In this way, the terminal device A and the cloud device complete the second synchronization process.
[0121] It should be understood that since both synchronization processes are initiated by the terminal device A, and no other device submits data changes to the master transaction log during the process, there is no transaction conflict, and the new transaction ID can be directly written in the master transaction log.
[0122] Example 2
[0123] Exemplarily, Figure 8 The synchronization process initiated by the terminal device A and the terminal device B is shown. Unlike the synchronization process of Figure 7 The synchronization process initiated by the terminal device A and the terminal device B is shown. Unlike the synchronization process of Figure 8 The two synchronization processes shown are successively initiated by the terminal device A and the terminal device B, respectively.
[0124] In this synchronization process, the terminal device A and the cloud device first perform steps 01-04 described above, and then the terminal device B and the cloud device perform steps 09-13 described below. It should be noted that for steps 01-04, please refer to the description of example 1 above, which will not be repeated here.
[0125] Step 09, after the terminal device A and the cloud device complete the synchronization process, the terminal device B accesses the cloud device. Since the terminal device B has no local data, the synchronization request message sent by the terminal device B to the cloud device does not carry change data and previous transaction identification, and all change histories V1 can be directly downloaded from the master transaction log, the final consistent data is generated and saved in the terminal device B locally. In addition, the terminal device B takes the transaction ID: V1 as the previous transaction ID, and stores the transaction ID.
[0126] Step 10, the terminal device B records the change data File3 and File4, then when the terminal device B initiates synchronization with the cloud device, the terminal device B can send the previous transaction ID: V1 and the commit 2 command to the cloud device. The commit 2 command includes the following contents: synchronization initiation time: 2022-01-03; synchronization initiation device: terminal device B; change data: File3 and File4.
[0127] Step 11: The cloud device saves the commit 2 command. Based on the commit 2 command, the cloud device determines that the synchronization initiator is terminal device B and writes the changed data, File3 and File4, to the transaction log V2-B corresponding to terminal device B. In other words, the cloud device generates transaction V2-B, which records the changed data, File3 and File4.
[0128] Step 12: The cloud device compares the latest transaction ID in the master transaction log with the previous transaction ID reported by terminal device B. Since both are V1, there is no data conflict. The cloud device generates record V2 in the master transaction log, where V2 = V2-B.
[0129] In step 13, since the latest transaction ID in both the sub-transaction log and the main transaction log corresponding to terminal device B is V2-B, no data has changed. The cloud device only returns the latest transaction ID, V2, to terminal device B. Terminal device B receives the latest transaction ID, V2, from the cloud device as the previous transaction ID and stores it. This completes one synchronization process between terminal device B and the cloud device.
[0130] It should be understood that after terminal device A completes one synchronization process, terminal device B can directly download all data and modify it, as it has no local data. Then, when terminal device B initiates synchronization, since no other device has submitted data changes to the master transaction log during this period, there is no transaction conflict, and the new transaction ID can be directly written to the master transaction log.
[0131] Example 3
[0132] For example, Figure 9 The figure shows the synchronization process initiated by terminal device A and terminal device B. Figure 8 The data modification by a device is different. Figure 9 In the process, both terminal device A and terminal device B modified the data, resulting in a data conflict.
[0133] During this synchronization process, terminal device A and the cloud device first execute the above steps 01 to 08, and then terminal device B and the cloud device execute the following steps 14 to 22. It should be noted that steps 01 to 08 can refer to the description of Example 1 above and will not be repeated here.
[0134] Step 14: After device A completes the first synchronization with the cloud device, device B connects to the cloud device. Since device B has no local data, the synchronization request message it sends to the cloud device does not carry the change data or the previous transaction identifier. Therefore, device B can directly download the entire change history (V1) from the master transaction log, generate the final consistency data, and save it locally on device B. Furthermore, device B uses transaction ID V1 as the previous transaction ID and stores it.
[0135] In step 15, terminal device B modifies the data based on the initial data, recording the changes to File3 and File4. When terminal device B initiates synchronization with the cloud device, it sends the preceding transaction ID, V1, and the commit 3 command. The commit 3 command includes the following: synchronization initiation time: 2022-01-03; synchronization initiating device: terminal device B; and changed data: File4 and File5.
[0136] Step 16: The cloud device saves the commit 3 command. Based on the commit 3 command, the cloud device determines that the synchronization initiator is terminal device B and writes the changed data, File4 and File5, to the transaction log V3-B corresponding to terminal device B. This means that the cloud device generates transaction V3-B, which records the changed data, File4 and File5.
[0137] Step 17: Since the latest transaction ID in the primary transaction log is V2, and the previous transaction ID reported by terminal device B is V1, the two are different, resulting in a data conflict.
[0138] Step 18: The cloud device compares transaction V3-B with transaction V2 and generates a data conflict list. Then, the device executes step 19 below, or executes steps 20 and 21.
[0139] Step 19: The cloud device merges the conflicting changes based on the data conflict list, generates a new merge transaction ID: V3-B-fix, and records it in the transaction log corresponding to terminal device B. Transaction V3-B-fix records the conflict-resolved changes to File4 and File5. Furthermore, the cloud device sends the resolved changes to File4 and File5 to terminal device B, which then synchronizes data based on these changes.
[0140] Step 20: The cloud device sends a data conflict list to terminal device B. Terminal device B processes and merges the conflicting data based on the data conflict list, obtaining the conflict-resolved changed data, File4 and File5. Terminal device B sends a commit 4 (fix) command to the cloud device. The commit 4 (fix) command includes the following: synchronization initiation time: 2022-01-03; synchronization initiating device: terminal device B; and changed data: File3 and File4.
[0141] As an optional implementation, when terminal device B sends the commit 4 (fix) command to the cloud device, terminal device B can also send the previous transaction ID (V3-B) to the cloud device. It should be understood that reporting the previous transaction ID facilitates the cloud device's verification of data errors or command errors.
[0142] Step 21: The cloud device saves the commit 4 (fix) command. Based on the commit 4 (fix) command, the cloud device generates a new merge transaction ID, V3-B-fix, and records it in the transaction log corresponding to terminal device B. Transaction V3-B-fix records the changed data, File4 and File5, after the conflict is resolved.
[0143] Step 22: The cloud device generates record V3 in the primary transaction log, where V3 = V3-B-fix.
[0144] It should be noted that the above embodiment is illustrated by first executing steps 05-08 and then steps 14-16. In actual implementation, steps 14-16 may be executed first and then steps 05-08; or steps 05-08 and steps 14-16 may be executed in parallel. This can be determined based on actual usage requirements and is not limited in this embodiment.
[0145] It should be understood that after terminal device A completes one synchronization process, both terminal device A and terminal device B have made data changes. Therefore, when the latter submits the changed data, a data conflict will occur with the changed data submitted by the former. Data conflicts are resolved by the cloud device and the terminal device, ensuring that the data ultimately stored on the cloud device remains consistent.
[0146] Example 4
[0147] For example, Figure 10 The figure shows the synchronization process initiated by terminal device A and terminal device B. Figure 8 and Figure 9 The terminal device A has initial data, and the terminal device B does not have initial data. Figure 10In the example, terminal device A has initial data 1 and terminal device B has initial data 2.
[0148] During this synchronization process, terminal device A and the cloud device first execute the above steps 01 to 04, and then terminal device B and the cloud device execute the following steps 23 to 30. It should be noted that steps 01 to 04 can refer to the description of Example 1 above and will not be repeated here.
[0149] Step 23: After device A completes the first synchronization, device B connects to the cloud. Since device B has initial data 2 (File 3 and File 4) locally and lacks a previous transaction ID, it sends a commit 2 command to the cloud. The commit 2 command includes the following: synchronization initiation time: 2022-01-03; synchronization initiating device: device B; and changed data: File 3 and File 4.
[0150] Step 24: The cloud device saves the commit 2 command. Based on the commit 2 command, the cloud device determines that the synchronization initiator is terminal device B and writes the changed data, File3 and File4, to the transaction log V2-B corresponding to terminal device B. This generates transaction V2-B, which records the changed data, File3 and File4.
[0151] Step 25: Although terminal device B did not report the previous transaction ID, since this is the first time terminal device B requests synchronization and carries changed data, there must be a data conflict between transaction V2-B and transaction V1.
[0152] Step 26: The cloud device compares transaction V2-B with transaction V1 and generates a data conflict list. Then, the cloud device executes step 27 below, or executes steps 28 and 29.
[0153] Step 27: The cloud device processes and merges the conflicting changes based on the data conflict list, generates a new merge transaction ID: V2-B-fix, and records it in the sub-transaction log corresponding to terminal device B. Transaction V2-B-fix records the conflict-resolved changes to File1, File2, File3, and File4. Furthermore, the cloud device sends the conflict-resolved changes to File1, File2, File3, and File4 to terminal device B, which then synchronizes data based on the changes to File1, File2, File3, and File4.
[0154] Step 28: The cloud device sends a data conflict list to terminal device B. Terminal device B processes and merges the conflicting data based on the data conflict list, obtaining the conflict-resolved changed data: File1, File2, File3, and File4. Terminal device B sends a commit 3 (fix) command to the cloud device. The commit 3 (fix) command includes the following: synchronization initiation time: 2022-01-03; synchronization initiating device: terminal device B; changed data: File1, File2, File3, and File4.
[0155] As an optional implementation, when terminal device B sends the commit 3 (fix) command to the cloud device, terminal device B can also send the previous transaction ID (V2-B) to the cloud device. It should be understood that reporting the previous transaction ID facilitates the cloud device's verification of data errors or command errors.
[0156] Step 29: The cloud device saves the commit 3 (fix) command. Based on the commit 3 (fix) command, the cloud device generates a new merge transaction ID, V2-B-fix, and records it in the transaction log corresponding to terminal device B. Transaction V2-B-fix records the conflict-resolved changes to File1, File2, File3, and File4.
[0157] Step 30: The cloud device generates record V2 in the primary transaction log, where V2 = V2-B-fix.
[0158] It should be understood that after terminal device A completes one synchronization process, terminal device B synchronizes with the existing local data for the first time, which will inevitably cause data conflicts. Data conflicts are resolved by the cloud device and the terminal device, so that the data ultimately stored in the cloud remains consistent.
[0159] Example 5
[0160] For example, Figure 11 The figure shows the synchronization process initiated by terminal device A, terminal device B and terminal device C. Figure 9 The two terminal devices shown are different. Figure 11 Terminal device C is added.
[0161] During this synchronization process, first, the terminal device A and the cloud device execute the above steps 01 to 08, and the terminal device B and the cloud device execute the above step 14. Then, after the master transaction log generates record V2 (V2=V2-B), the terminal device C connects to the cloud device. Since there is no local data on terminal device C, the synchronization request message sent by terminal device C to the cloud device does not carry the change data and the previous transaction identifier. It can directly download all the change history V1+V2 from the master transaction log, generate the final consistency data and save it on terminal device C. In addition, terminal device C uses transaction ID: V2 as the previous transaction ID and stores the transaction ID. In addition, if terminal device B initiates synchronization, the terminal device completes the synchronization process of terminal device B according to the above steps 15 to 22.
[0162] It should be noted that, for steps 01 to 08 and steps 14 to 22, reference may be made to the description of the above-mentioned example 1 and example 3, which will not be repeated here.
[0163] After the main transaction log generates record V3 (V3=V3-B-fix), if terminal device A, terminal device B and / or terminal device C initiate synchronization, then referring to the method of the above embodiment, the terminal device reports the change data and the previous transaction ID to the cloud device. Based on the change data, the cloud device generates a new transaction in the sub-transaction log corresponding to the terminal device, and compares whether the latest transaction ID of the main transaction log is the same as the previous transaction ID reported by the terminal device. If the latest transaction ID of the main transaction log is the same as the previous transaction ID reported by the terminal device, the cloud device determines that no other transactions have been generated and there will be no transaction conflict, so the ID of the new transaction generated in the sub-transaction log is written into the main transaction log. If the latest transaction ID of the main transaction log is different from the previous transaction ID reported by the terminal device, the cloud device determines that the terminal device has generated at least one transaction after the previous transaction and there is a transaction conflict, so the cloud device writes the merged transaction ID into the main transaction log.
[0164] In combination with the descriptions of Examples 1 to 5 above, when a terminal device initiates data synchronization to a cloud device, it may or may not carry the previous transaction ID, and may or may not carry the changed data, which will result in different data synchronization methods.
[0165] For example, Figure 12 As shown, the embodiment of the present application provides another data synchronization method. The data synchronization method includes A1-A16.
[0166] A1. The cloud device receives a synchronization request from the terminal device.
[0167] The terminal device is any device bound to the user's cloud account.
[0168] The terminal device can initiate a synchronization request to the cloud device in any of the following situations:
[0169] The terminal device logs into the cloud account for the first time;
[0170] The target application on the terminal device is bound to the cloud account for the first time;
[0171] The terminal device periodically initiates synchronization requests to the cloud device, for example, initiating a synchronization process every other day;
[0172] When the cloud device detects that a new transaction ID is written to the master transaction log (i.e., there is a new data change), it broadcasts synchronization information to instruct the terminal device to initiate a synchronization request.
[0173] A2. The cloud device determines whether the primary transaction log is empty.
[0174] When the primary transaction log is empty, no data conflict occurs and the cloud device executes A3-A4 below.
[0175] If the primary transaction log is not empty, data conflicts may occur and the cloud device executes A5 below.
[0176] A3. The cloud device generates transaction 1 in the transaction log corresponding to the terminal device based on the change data carried in the synchronization request.
[0177] A4. The cloud device writes the ID of transaction 1 to the master transaction log. It should be understood that since the master transaction log is empty and the cloud device has not yet synchronized data with any other device, the cloud device does not need to determine whether the previous transaction ID is the same as the latest transaction ID in the master transaction log and directly generates a new transaction.
[0178] A5. Do the synchronization requests from the cloud device and terminal device carry the previous transaction ID and changed data?
[0179] If the synchronization request from the terminal device does not carry the previous transaction ID and the changed data, execute A6 below;
[0180] If the synchronization request of the terminal device does not carry the previous transaction ID but carries the changed data, execute the following A7-A9;
[0181] When the synchronization request of the terminal device carries the previous transaction ID and the changed data, execute the following A10-A14;
[0182] When the synchronization request of the terminal device carries the previous transaction ID but does not carry the changed data, execute the following A15-A16.
[0183] A6. The cloud device sends all changed data of the master transaction log to the terminal device.
[0184] It should be understood that when the synchronization request does not carry the previous transaction ID and the changed data, it can be determined that the terminal device initiates the synchronization to the cloud device for the first time, and there is no data conflict, therefore, the cloud device sends all changed data of the master transaction log to the terminal device, and the terminal device stores the changed data as the synchronization data.
[0185] A7. The cloud device generates transaction 2 in the sub-transaction log corresponding to the terminal device.
[0186] A8. After the data conflict is resolved by the cloud device or the terminal device, the cloud device generates transaction 3 in the sub-transaction log corresponding to the terminal device.
[0187] A9. The cloud device writes the ID of transaction 3 into the master transaction log.
[0188] It should be understood that when the synchronization request of the terminal device does not carry the previous transaction ID and carries the changed data, it can be determined that the terminal device initiates the synchronization to the cloud device for the first time, but there is a data conflict between the carried changed data and the cloud data, therefore, the data conflict needs to be resolved by the cloud device or the terminal device. Further, if the conflict is resolved by the terminal device, the terminal device stores the changed data after the conflict is resolved, thereby realizing the data synchronization. If the conflict is resolved by the cloud device, the cloud device sends the changed data after the conflict is resolved to the terminal device, and the terminal device stores the changed data after the conflict is resolved, thereby realizing the data synchronization.
[0189] A10. The cloud device generates transaction 4 in the sub-transaction log corresponding to the terminal device according to the changed data.
[0190] A11. The cloud device compares whether the latest transaction ID of the master transaction log is the same as the previous transaction ID.
[0191] A12. If the latest transaction ID of the master transaction log is the same as the previous transaction ID, the cloud device determines that there is no transaction conflict, and writes the ID of transaction 4 into the master transaction log.
[0192] A13. If the latest transaction ID of the master transaction log is different from the previous transaction ID, the cloud device determines that there is a transaction conflict, and generates transaction 5 in the sub-transaction log corresponding to the terminal device after the data conflict is resolved by the cloud device or the terminal device.
[0193] A14. The cloud device writes the ID of transaction 5 into the master transaction log.
[0194] It should be understood that when a terminal device's synchronization request carries the previous transaction ID and changed data, if the latest transaction ID in the master transaction log is the same as the previous transaction ID, then there is no data conflict, and the cloud device only needs to write the ID of transaction 4 to the master transaction log to achieve data synchronization. If the latest transaction ID in the master transaction log is different from the previous transaction ID, then there is a data conflict. If the conflict is resolved by the terminal device, the terminal device stores the changed data after the conflict is resolved, thereby achieving data synchronization. If the conflict is resolved by the cloud device, the cloud device sends the changed data after the conflict is resolved to the terminal device, and the terminal device stores the changed data after the conflict is resolved, thereby achieving data synchronization.
[0195] A15. The cloud device determines the change information between the two transactions corresponding to the latest transaction ID in the master transaction log and the previous transaction ID reported by the terminal device.
[0196] That is, the change data corresponding to the transaction ID generated after the previous transaction ID.
[0197] A16. The cloud device sends the change information to the terminal device. The terminal device can then synchronize data based on the change information, enabling data synchronization and information sharing across multiple devices.
[0198] It should be understood that when the synchronization request of the terminal device carries the previous transaction ID but does not carry the changed data, it can be determined that the terminal device has not made any data changes after completing the last synchronization process. Therefore, the cloud device only needs to send the change information between the previous transaction ID reported by the terminal device and the latest transaction ID in the current master transaction log.
[0199] The above embodiment introduces the commit command. Specifically, the terminal device can use the commit command to report the synchronization initiation time, synchronization initiation device, and changed data to the cloud device. The cloud device will generate a transaction log based on the commit command and also record the commit command. Using the recorded commit command, the cloud device can also perform the following functions:
[0200] The first function: data rollback and query function.
[0201] If a failure or error occurs during a transaction and the transaction cannot continue, the cloud device stores each commit command and can track and roll back the modification history of every data on each terminal device. The cloud device can query the commit command to undo all or part of the completed database operations in the transaction, rolling back to the previous transaction state.
[0202] The second function: pruning the transaction log.
[0203] Because the storage space of cloud devices is limited, you can use any of the following methods to prune the transaction log:
[0204] Method 1: Based on the synchronization initiation time carried in the commit command, the transaction logs that meet the time condition are pruned.
[0205] The cloud device uses the current time as a node and retains transaction logs for a preset time period before the node, deleting all other logs. The preset time period is pre-configured by the cloud device, pre-configured by the terminal device, specified by the protocol, or set by the user.
[0206] For example, Table 1 shows the correspondence between the master and sub-transaction logs, the sub-transaction logs of terminal device A, and the sub-transaction logs of terminal device B between January 1, 2022, and January 11, 2022. Assuming the current time is January 11, 2022, and the preset duration is 7 days, the terminal device can perform a rebase operation to prune the master transaction log from January 4, 2022, and earlier. The correspondence between the pruned master and sub-transaction logs, the sub-transaction logs of terminal device A, and the sub-transaction logs of terminal device B is shown in Table 2.
[0207] Table 1
[0208]
[0209]
[0210] Table 2
[0211]
[0212] Method 2: If the previous transaction IDs of all terminal devices bound to the cloud account are the same, the transaction log is pruned.
[0213] For example, Figure 11 As shown, after the cloud device writes transaction ID V3 to the master transaction log, it broadcasts a synchronization message. For example, the synchronization message carries the latest transaction ID V3 in the master transaction log. Subsequently, devices A, B, and C receive the synchronization message.
[0214] Terminal A's previous transaction ID, V2, differs from its latest transaction ID, V3. Terminal A determines that data synchronization is necessary. It sends the previous transaction ID, V2, to the cloud device. Based on the latest transaction ID, V3, in the master transaction log and the previous transaction ID, V2, reported by terminal A, the cloud device determines the change information between the two transactions. The cloud device sends this change information and transaction ID, V3, to terminal A. Terminal A synchronizes data based on this change information and uses transaction ID, V3, as the previous transaction ID.
[0215] The previous transaction ID of terminal device B: V3 is the same as the latest transaction ID: V3, and no data synchronization is required.
[0216] Terminal device C's previous transaction ID, V2, differs from its latest transaction ID, V3. Terminal device C determines that data synchronization is necessary. It sends the previous transaction ID, V2, to the cloud device. The cloud device uses the latest transaction ID, V3, in the master transaction log and the previous transaction ID, V2, reported by terminal device C to determine the change information between the two transactions. The cloud device sends this change information, transaction ID, V3, to terminal device C. Terminal device C synchronizes data based on this change information and uses transaction ID V3 as the previous transaction ID.
[0217] After the cloud device completes data synchronization and information sharing with each terminal device, the preceding transaction ID for each terminal device is transaction ID: V3. At this point, the cloud device can prune the transaction log before transaction V3, or prune the transaction log before and including transaction V3, immediately, after a period of time, or at a preset time.
[0218] It should be understood that regardless of the above-mentioned method 1 or method 2, the cloud device can flexibly adjust the space occupied by the cloud storage for transaction logs by trimming the transaction logs, thereby freeing up space for historical data.
[0219] It should be noted that after pruning the transaction log, it may happen that the previous transaction reported by the terminal device has been deleted by the cloud device. In this case, the synchronization process at this time is regarded as the first synchronization process, and data synchronization is performed according to the method provided in A7-A9 above, that is, a full data merge is performed.
[0220] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of the device. It is understandable that, in order to realize the above functions, the device includes a hardware structure or software module corresponding to each function, or a combination of the two. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0221] In the embodiment of the present application, the functional modules of the device can be divided according to the above method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above integrated modules can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. The following is an example of dividing each functional module corresponding to each function.
[0222] Figure 13 This is a structural diagram of a synchronization device provided in an embodiment of the present application. Figure 13 As shown, the synchronization device 300 may include a communication module 301 and a data processing module 302 .
[0223] In some embodiments, the synchronization apparatus 300 can be used to execute the steps performed by the cloud device in the above-described method embodiment. In this case, the communication module 301 is used to receive a synchronization request message from a first device, where the first device is any one of multiple terminal devices bound to the cloud device. The data processing module 302 is used to respond to the synchronization request message and perform processing actions corresponding to the synchronization request message.
[0224] Optionally, the synchronization request message may belong to any of the following situations:
[0225] The synchronization request message carries the first change data and the previous transaction identifier;
[0226] The synchronization request message carries the first change data but does not carry the previous transaction identifier.
[0227] The synchronization request message carries the previous transaction identifier but does not carry the first change data.
[0228] The synchronization request message does not carry the first change data and the previous transaction identifier.
[0229] The preceding transaction identifier is an identifier of a transaction generated by the cloud device in the master transaction log when the cloud device and the first device complete the last data synchronization. It should be understood that the preceding transaction identifier is the same as the latest transaction identifier, or the preceding transaction identifier is an identifier of a transaction generated before the latest transaction identifier.
[0230] Optionally, the cloud device maintains a plurality of sets of transaction logs, and the plurality of sets of transaction logs include a master transaction log and a sub-transaction log corresponding to each terminal device. Different terminal devices correspond to different sub-transaction logs. Each set of transaction logs records a set of transaction IDs in chronological order. The master transaction log is used to record transactions finally reached by all devices, and thus the master transaction log is the main trunk stored in the cloud. The sub-transaction log corresponding to each terminal device is used to record data changes of each terminal device and result data after conflict resolution, and the sub-transaction log is a branch stored in the cloud.
[0231] Optionally, the synchronization request message carries the first change data and the preceding transaction identifier. Correspondingly, the data processing module 302 is specifically configured to: generate a transaction identifier 1 used to indicate the first change data in the sub-transaction log corresponding to the first device. In the case that the preceding transaction identifier is the same as the latest transaction identifier, the transaction identifier 1 is written into the master transaction log; in the case that the preceding transaction identifier is different from the latest transaction identifier, the merged data of the first change data and second change data indicated by the latest transaction identifier is obtained, a merged transaction identifier is generated in the sub-transaction log corresponding to the first device, and the merged transaction identifier is written into the master transaction log.
[0232] Optionally, the synchronization request message carries the first change data and does not carry the preceding transaction identifier. Correspondingly, the data processing module 302 is specifically configured to: obtain merged data of the first change data and second change data indicated by the latest transaction identifier, generate a merged transaction identifier in the sub-transaction log corresponding to the first device, and write the merged transaction identifier into the master transaction log.
[0233] Optionally, the synchronization request message carries the preceding transaction identifier and does not carry the first change data. The data processing module 302 is specifically configured to determine third change data, and the third change data includes change data indicated by all transaction identifiers generated after the preceding transaction identifier in the master transaction log. The communication module 301 is further configured to send the third change data to the first device.
[0234] Optionally, the synchronization request message does not carry the preceding transaction identifier and the first change data. The data processing module 302 is specifically configured to determine fourth change data, and the fourth change data includes change data indicated by all transaction identifiers of the master transaction log. The communication module 301 is further configured to send the fourth change data to the first device.
[0235] In some embodiments, the synchronization apparatus 300 can be configured to perform the steps as performed by the terminal device in the above method embodiments. In this case, the communication module 301 is configured to send a synchronization request message to the cloud device, the first device being any one of the plurality of terminal devices bound to the cloud device. The synchronization request message carries at least one of the first change data and the previous transaction identifier, or the synchronization request message does not carry the first change data and the previous transaction identifier. The first change data is the change data of the first application in the first device, and the previous transaction identifier is the transaction identifier generated in the master transaction log of the cloud device when the last data synchronization between the first device and the cloud device is completed. Each transaction identifier in the master transaction log is recorded in chronological order.
[0236] Optionally, the synchronization request message carries the first change data and the previous transaction identifier, or the synchronization request message carries the first change data and does not carry the previous transaction identifier. Correspondingly, the communication module 301 is further configured to receive the first merged data from the cloud device, and the data processing module 302 is configured to perform data synchronization according to the first merged data. The first merged data is the merged data obtained by processing the first change data and the second change data that exist in transaction conflicts, and the second change data is the change data of the first application in the second device.
[0237] Optionally, the synchronization request message carries the first change data and the previous transaction identifier, or the synchronization request message carries the first change data and does not carry the previous transaction identifier. Correspondingly, the communication module 301 is further configured to receive the data conflict list from the cloud device, the data processing module 302 is configured to process the conflict data in the data conflict list to obtain the second merged data, and perform data synchronization according to the second merged data, and the communication module 301 is further configured to send the second merged data to the cloud device. The data conflict list is generated according to the first change data and the second change data that exist in transaction conflicts.
[0238] Optionally, the synchronization request message carries the previous transaction identifier and does not carry the first change data. Correspondingly, the communication module 301 is further configured to receive the third change data from the cloud device, the third change data including change data indicated by all transaction identifiers generated after the previous transaction identifier in the master transaction log.
[0239] Optionally, the synchronization request message does not carry the previous transaction identifier and the first change data. Correspondingly, the communication module 301 is further configured to receive the fourth change data from the cloud device, the fourth change data including change data indicated by all transaction identifiers in the master transaction log.
[0240] Optionally, the communication module 301 is further configured to: after the first device completes each data synchronization with the cloud device, the first device receives the latest transaction identifier from the cloud device, and uses the latest transaction identifier as a preceding transaction identifier for the next data synchronization.
[0241] Figure 14 The schematic diagram of the structure of the cloud device provided in the embodiment of the present application is shown. The cloud device includes at least one processor 401, a communication bus 402, a memory 403 and at least one communication interface 404.
[0242] The processor 401 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present application.
[0243] The communication bus 402 may include a pathway for transmitting information between the aforementioned components.
[0244] The communication interface 404 uses any transceiver or other device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area network (WLAN), etc.
[0245] The memory 403 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor via a bus. The memory may also be integrated with the processor.
[0246] The memory 403 is used to store application code for executing the solution of the present application, and the execution is controlled by the processor 401. The processor 401 is used to execute the application code stored in the memory 403, thereby implementing the data synchronization method in the above embodiment.
[0247] As an embodiment, the processor 401 may include one or more CPUs.
[0248] As an embodiment, the cloud device may include multiple processors, such as Figure 14 The two processors 401 in FIG. Each processor can be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor.
[0249] The cloud device can be a general cloud device or a dedicated cloud device. The cloud device can be a desktop computer, a network server, an embedded device, etc. The embodiment of the present application does not limit the type of cloud device.
[0250] Figure 15 FIG. 1 shows a schematic diagram of the structure of the terminal device provided in the embodiment of the present application. Figure 15 As shown, the terminal device may include: a processor 110, an external memory interface 120, an internal memory 121, a USB interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. Among them, the sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, and a bone conduction sensor 180M, etc.
[0251] The processor 110 may include one or more processing units. For example, the processor 110 may include a CPU, an image signal processor (ISP), a digital signal processor (DSP), a video codec, a neural network processing unit (NPU), a graphics processing unit (GPU), an application processor (AP), and / or a modem processor. In some embodiments, different processing units may be independent devices or integrated into one or more processors.
[0252] The CPU is the final execution unit for information processing and program execution. Its primary functions include processing instructions, executing operations, controlling time, and processing data. The CPU includes a controller, an arithmetic unit, cache memory, and a bus connecting these components. The controller serves as the nerve center and command center of the terminal device. Based on instruction opcodes and timing signals, the controller generates operational control signals to control instruction fetching and execution.
[0253] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly retrieve it from the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.
[0254] The wireless communication function of the terminal device can be implemented through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc. Among them, antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals.
[0255] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G applied to terminal devices. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. In some embodiments, the mobile communication module 150 can receive electromagnetic waves from other devices through the antenna 1, and filter, amplify, and process the electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.
[0256] The modem processor may include a modulator and a demodulator. The modulator may be used to modulate a low-frequency baseband signal to be transmitted into a medium- or high-frequency signal. The demodulator may be used to demodulate a received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After being processed by the baseband processor, the low-frequency baseband signal is passed to the application processor. The application processor outputs a sound signal through an audio device or displays an image or video through the display screen 194. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be provided in the same device as the mobile communication module 150 or other functional modules.
[0257] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as Wi-Fi networks), Bluetooth, global navigation satellite system (GNSS), FM, NFC, infrared technology (IR), etc. applied to the terminal device. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, frequency modulate it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2. In some embodiments, the wireless communication module 160 is based on GNSS, receives electromagnetic waves from the communication device via the antenna 2, frequency modulates and filters the electromagnetic wave signals, and obtains the location information of the terminal device.
[0258] In some embodiments, the antenna 1 and the mobile communication module 150 of the terminal device are coupled, and the antenna 2 and the wireless communication module 160 are coupled, so that the terminal device can communicate with the network and other devices through wireless communication technology. The wireless communication technology can include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology, etc. The GNSS can include global positioning system (GPS), global navigation satellite system (GLONASS), beidou navigation satellite system (BDS), quasi-zenith satellite system (QZSS), and / or satellite based augmentation systems (SBAS).
[0259] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the terminal device. The external memory card communicates with the processor 110 through the external memory interface 120 to realize the data storage function. For example, the user's behavior data is saved in the external memory card.
[0260] The internal memory 121 can be used to store computer executable program codes, and the executable program codes include instructions. The processor 110 executes various functional applications and data processing of the terminal device by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system, an application (application, APP) required for at least one function (such as a desktop APP and a payment APP), etc. The data storage area can store data created during the use of the terminal device (such as audio data, a phone book, etc.). In addition, the internal memory 121 may include a high-speed random access memory, 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.
[0261] It is understood that the structures illustrated in the embodiments of this application do not constitute specific limitations on the terminal device and cloud device. In other embodiments of this application, the terminal device and cloud device may include more or fewer components than shown, or combine or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0262] The present application also provides a computer-readable storage medium having computer instructions stored therein. When the computer-readable storage medium is run on a cloud device, the cloud device executes the method shown above. Alternatively, when the computer-readable storage medium is run on a terminal device, the terminal device executes the method shown above. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrations. The available medium can be a magnetic medium (e.g., a floppy disk, hard disk, or tape), an optical medium, or a semiconductor medium (e.g., a solid-state drive (SSD)).
[0263] An embodiment of the present application further provides a computer program product, which includes computer program code. When the computer program code runs on a computer, the computer executes the methods in the above embodiments.
[0264] An embodiment of the present application further provides a chip coupled to a memory, the chip being used to read and execute computer programs or instructions stored in the memory to perform the methods in the above embodiments. The chip may be a general-purpose processor or a dedicated processor. In some embodiments, the chip includes a processor, a transceiver, and a storage medium. The processor is used to support a cloud device or a terminal device in executing the technical solution shown above. The transceiver is used to accept control of the processor and to support the cloud device or the terminal device in executing the technical solution shown above.
[0265] It should be noted that the chip can be implemented using the following circuits or devices: one or more field programmable gate arrays (FPGAs), programmable logic devices (PLDs), controllers, state machines, gate logic, discrete hardware components, any other suitable circuits, or any combination of circuits that can perform the various functions described throughout this application.
[0266] The cloud device, terminal device, synchronization device, computer-readable storage medium, computer program product and chip provided in the above-mentioned embodiments of the present application are all used to execute the method provided above. Therefore, the beneficial effects that can be achieved can refer to the corresponding beneficial effects of the method provided above, and will not be repeated here.
[0267] It should be understood that the above is only to help those skilled in the art better understand the embodiments of the present application, and is not intended to limit the scope of the embodiments of the present application. Based on the above examples given, those skilled in the art can obviously make various equivalent modifications or changes. For example, certain steps in each embodiment of the above detection method may be unnecessary, or certain new steps may be added. Or a combination of any two or any multiple embodiments described above. Such modifications, changes, or combined solutions also fall within the scope of the embodiments of the present application.
[0268] It should also be understood that the above description of the embodiments of the present application focuses on emphasizing the differences between the various embodiments. The same or similar points that are not mentioned can be referenced with each other. For the sake of brevity, they will not be repeated here.
[0269] It should also be understood that the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0270] It should also be understood that in the embodiments of the present application, "pre-setting" and "pre-definition" can be achieved by pre-saving corresponding codes, tables or other methods that can be used to indicate relevant information in a device (for example, including an electronic device), and the present application does not limit its specific implementation method.
[0271] It should also be understood that the division of the modes, situations, categories and embodiments in the embodiments of the present application is only for the convenience of description and should not constitute a special limitation. The features of various modes, categories, situations and embodiments can be combined without contradiction.
[0272] It should also be understood that in the various embodiments of the present application, unless otherwise specified or there is a logical conflict, the terms and / or descriptions between different embodiments are consistent and can be referenced to each other, and the technical features in different embodiments can be combined to form new embodiments according to their internal logical relationships.
[0273] Finally, it should be noted that the above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A data synchronization method, characterized in that: The method comprises: The cloud device receives a synchronization request message from a first device, where the first device is any one of a plurality of terminal devices bound to the cloud device; The cloud device generates a first transaction identifier in a sub-transaction log corresponding to the first device, where the first transaction identifier is used to indicate first change data, where the first change data is change data of a first application in the first device; If the preceding transaction identifier carried in the synchronization request message is the same as the first transaction identifier, the cloud device writes the first transaction identifier into the primary transaction log, where the preceding transaction identifier is a transaction identifier generated by the cloud device in the primary transaction log when the cloud device completed the last data synchronization with the first device. When the preceding transaction identifier carried by the synchronization request message is different from the first transaction identifier, or the synchronization request message does not carry a preceding transaction identifier, the cloud device obtains the merged data after processing the first change data and the second change data based on the first transaction identifier, and generates a second transaction identifier in the master transaction log. The second change data is the change data of the first application in the second device of the multiple terminal devices. Each transaction identifier in the master transaction log is recorded in chronological order. The second change data is indicated by a third transaction identifier in the master transaction log. The third transaction identifier is a transaction identifier that is most recently generated before the second transaction identifier is generated.
2. The method according to claim 1, characterized in that The cloud device obtains, according to the first transaction identifier, merged data after processing the first change data and the second change data, and generates the second transaction identifier in the primary transaction log, including: The cloud device generates a data conflict list according to the first change data and the second change data; The cloud device obtains the merged data according to the data conflict list; The cloud device generates a merge transaction identifier in the sub-transaction log corresponding to the first device, where the merge transaction identifier is used to indicate the merged data; The cloud device writes the merged transaction identifier as the second transaction identifier into the main transaction log.
3. The method according to claim 2, characterized in that The cloud device obtains the merged data according to the data conflict list, including: The cloud device processes the conflicting data in the data conflict list to obtain the merged data; or, The cloud device sends the data conflict list to the first device, and receives the merged data from the first device, where the merged data is obtained according to the data conflict list.
4. The method according to claim 1, wherein The merged data is data obtained after the cloud device processes the first change data and the second change data; the method further includes: The cloud device sends the combined data to the first device.
5. The method according to claim 1, wherein The method further comprises: After the cloud device generates the latest transaction identifier in the primary transaction log, the cloud device sends the latest transaction identifier to the first device.
6. The method according to claim 1, characterized in that The method further comprises: When the synchronization request message carries the preceding transaction identifier but does not carry the first change data, the cloud device sends the third change data and the latest transaction identifier in the primary transaction log to the first device; Among them, the third change data includes the change data indicated by all transaction identifiers generated after the previous transaction identifier in the main transaction log, and the previous transaction identifier is the transaction identifier generated by the cloud device in the main transaction log when the last data synchronization with the first device was completed.
7. The method according to claim 1, characterized in that The method further comprises: In a case where the synchronization request message does not carry the preceding transaction identifier and the first change data, the cloud device sends fourth change data and the latest transaction identifier in the primary transaction log to the first device; The fourth change data includes change data indicated by all transaction identifiers of the primary transaction log, and the preceding transaction identifier is a transaction identifier generated by the cloud device in the primary transaction log when the last data synchronization with the first device was completed.
8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: The cloud device deletes the transaction identifiers generated before the target time in the main transaction log and the sub-transaction logs corresponding to each terminal device based on the generation time of each transaction identifier in the main transaction log and the generation time of each transaction identifier in the sub-transaction logs corresponding to each terminal device; or In a case where the preceding transaction identifier of each terminal device is the target transaction identifier, the cloud device deletes the transaction identifier generated before the target transaction identifier in the master transaction log and the branch transaction log corresponding to each terminal device. The preceding transaction identifier of each terminal device is the transaction identifier generated by the cloud device in the branch transaction log corresponding to each terminal device when the last data synchronization with the terminal device was completed; Each transaction identifier in the sub-transaction log corresponding to each terminal device is recorded in chronological order.
9. A data synchronization method, characterized in that: The method comprises: A first device sends a synchronization request message to a cloud device, where the first device is any one of a plurality of terminal devices bound to the cloud device; The first device receives first merged data from the cloud device and performs data synchronization based on the first merged data; wherein the first merged data is merged data obtained after processing the first change data and the second change data in which the transaction conflict exists, and the second change data is the change data of the first application in the second device; or, The first device receives the data conflict list from the cloud device, processes the conflicting data in the data conflict list to obtain second merged data, performs data synchronization based on the second merged data, and sends the second merged data to the cloud device; wherein the data conflict list is generated based on the first change data and the second change data with transaction conflicts. The synchronization request message carries the first change data and a preceding transaction identifier; or the synchronization request message carries the first change data but does not carry the preceding transaction identifier; The first change data is the change data of the first application in the first device, and the previous transaction identifier is the transaction identifier generated in the main transaction log of the cloud device when the first device and the cloud device completed the last data synchronization. Each transaction identifier in the main transaction log is recorded in chronological order.
10. The method according to claim 9, characterized in that The synchronization request message carries the preceding transaction identifier but does not carry the first change data; After the first device sends a synchronization request message to the cloud device, the method further includes: The first device receives third change data from the cloud device, where the third change data includes change data indicated by all transaction identifiers generated after the preceding transaction identifier in the primary transaction log.
11. The method according to claim 9, characterized in that The synchronization request message does not carry the preceding transaction identifier and the first change data; After the first device sends a synchronization request message to the cloud device, the method further includes: The first device receives fourth change data from the cloud device, where the fourth change data includes change data indicated by all transaction identifiers of the primary transaction log.
12. The method according to any one of claims 9 to 11, characterized in that The method further comprises: After the first device completes each data synchronization with the cloud device, the first device receives the latest transaction identifier from the cloud device and uses the latest transaction identifier as a preceding transaction identifier for the next data synchronization.
13. A cloud device, characterized in that: It includes a processor, a memory and a communication interface, the processor and the communication interface are coupled to the memory, and the processor is used to execute the computer program or instructions stored in the memory so that the cloud device implements the data synchronization method as described in any one of claims 1 to 8.
14. A terminal device, characterized in that: It includes a processor, a memory and a communication interface, the processor and the communication interface are coupled to the memory, and the processor is used to execute a computer program or instruction stored in the memory so that the terminal device implements the data synchronization method as described in any one of claims 9 to 12.
15. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program; when the computer program runs on a cloud device, the cloud device executes the data synchronization method as described in any one of claims 1 to 8; or, when the computer program runs on a terminal device, the terminal device executes the data synchronization method as described in any one of claims 9 to 12.
Citation Information
Patent Citations
Transaction execution method and device, computer equipment and storage medium
CN111143389A
Cited By
Mobile game cross-platform real-time interaction optimization method and device based on cloud data synchronization
CN121695486A
Mobile game cross-platform real-time interaction optimization method and device based on cloud data synchronization
CN121695486B