Data synchronization method, device and equipment for multi-terminal cooperation and storage medium
By using a collaborative data tree of CRDT data structure nested by mapping nodes in a multi-end collaboration system, the data synchronization problem under multi-user collaborative editing is solved, data consistency and efficient synchronization are achieved, data duplication and conflict are avoided, and the efficiency of multi-end collaboration is improved.
Patent Information
- Application Number
- CN202311806181.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-25
- Publication Date
- 2025-07-04
AI Technical Summary
In the multi-user collaborative editing scenario, how to achieve data synchronization generated by multi-person collaborative editing, so that the last data presented in each user side is consistent, avoiding data duplication and conflict.
A collaborative data tree based on the CRDT data structure formed by the nesting of mapping nodes is adopted. By receiving the operation data group of remote collaborative devices, the target mapping nodes are found and the collaboration data tree is updated, ensuring that duplicate applications and conflicts are avoided during the data synchronization process, and data consistency and efficient synchronization are achieved.
The operational data generated by remote collaboration devices is synchronized in the local collaboration devices, avoiding data duplication and conflicts, ensuring data consistency in each collaboration device, and improving data synchronization speed and multi-terminal collaboration efficiency.
Smart Images

Figure CN120256512A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present application relate to the field of online collaboration, and in particular, to a data synchronization method, apparatus, device, and storage medium for multi-terminal collaboration. Background Art
[0002] In the context of the current Internet era, there are more and more collaboration applications, and related products emerge in an endless stream. From the common multi-person ordering in a restaurant applet, to multi-person online collaborative documents, and then to novel multi-person collaborative drawing boards, the importance of "online collaboration" has gradually emerged.
[0003] Collaboration applications need to support multi-user collaborative editing. In the scenario of multi-user collaborative editing, how to synchronize the data generated by multi-person collaborative editing so that the finally presented data in each user terminal is consistent has become a technical problem that urgently needs to be solved. Summary of the Invention
[0004] Embodiments of the present application provide a data synchronization method, apparatus, device, and storage medium for multi-terminal collaboration to solve the problem of data synchronization in the scenario of multi-user collaborative editing.
[0005] In a first aspect, a data synchronization method for multi-terminal collaboration is provided, which is applied to a local collaboration device in a multi-terminal collaboration system. The multi-terminal collaboration system includes multiple collaboration devices, and each collaboration device stores a collaboration data tree. Each collaboration device displays a collaboration page based on the collaboration data tree. The collaboration data tree stores the collaboration data generated by multi-terminal collaboration in a tree-like structure formed by nested mapping nodes. The local collaboration device is any one of the multiple collaboration devices; the method includes:
[0006] Receiving a first operation data group sent by a remote collaboration device. The first operation data group includes first operation data and a first path. The remote collaboration device is any one of the multiple collaboration devices other than the local collaboration device. The first operation data is operation data corresponding to a user operation performed by the user on the remote collaboration device, and the first path is a search path corresponding to the first operation data in the collaboration data tree;
[0007] If the first operation data group is not in the first sequence list, taking the first operation data group as a target operation data group to be applied, and according to the path in the target operation data group, searching for a target mapping node corresponding to the target operation data in the target operation data group in the collaboration data tree. The first sequence list stores the operation data groups that have been applied to the collaboration data tree in the collaboration order, and the target mapping node is used to store the collaboration data corresponding to the target operation data in the collaboration data tree;
[0008] If the target mapping node is found, update the target mapping node in the collaborative data tree according to the target operation data group.
[0009] In this technical solution, the collaborative device displays a collaborative page based on the collaborative data tree. The collaborative data tree stores the collaborative data generated by multi-terminal collaboration in a tree structure formed by nested mapping nodes. After the local collaborative device receives the first operation data group sent by the remote collaborative device, if the first operation data group is not in the first sequence list, the first operation data group is used as the target operation data group to be applied, and the target mapping node corresponding to the target operation data group is searched in the collaborative data tree. The target mapping node is used to store the relevant information of the collaborative data. If the target mapping node is found, the relevant information corresponding to the target mapping node in the collaborative data tree is updated according to the target operation data in the target operation data group, realizing the synchronization of the operation data generated by the remote collaborative device in the local collaborative device, that is, realizing data synchronization. Since the first operation data is used as the target operation data group to be applied only when the first operation data group is not in the first sequence list, and the first sequence list is used to store the operation data groups that have been applied to the collaborative data tree, it can avoid the repeated application of the operation data generated by the remote collaborative device, thus avoiding data duplication in the data synchronization process. Since the target mapping node in the collaborative data tree is updated according to the target operation data only when the target mapping node is found, and the target mapping node in the collaborative data tree is used to store the collaborative data corresponding to the target operation data, it can realize the sequential processing of the operation data, thus ensuring data consistency in each collaborative device. Since the collaborative device displays the collaborative page based on the collaborative data tree, and the collaborative data tree stores the collaborative data generated by multi-terminal collaboration in a tree structure formed by nested multi-layer nodes, data synchronization is realized by searching and updating the collaborative data tree. Searching and deleting in the collaborative data tree is faster, so the speed of data synchronization can be improved, and the efficiency of multi-terminal collaboration can be enhanced.
[0010] Combined with the first aspect, in a possible implementation manner, before updating the target mapping node in the collaborative data tree according to the target operation data group, it further includes: determining whether the target operation data is valid; updating the target mapping node in the collaborative data tree according to the target operation data group, including: if the target operation data is valid, updating the target mapping node in the collaborative data tree according to the target operation data group. Only when the operation data is valid, the target mapping node in the collaborative data tree is updated according to the target operation data, which can realize the sequential processing of the operation data, thus ensuring data consistency in each collaborative device.
[0011] In combination with the first aspect, in a possible implementation manner, the collaborative data tree further includes a container node and a container identifier corresponding to the container node. The container node is a child node under the container node, and the container identifier is used to uniquely identify the container node in the collaborative data tree; the target operation data includes a target container identifier, and the target container identifier is used to uniquely identify the container node to which the collaborative data corresponding to the target operation data belongs in the collaborative data tree; determining whether the target operation data is valid includes: determining whether the target container identifier exists in the collaborative data tree; if the target container identifier does not exist in the collaborative data tree, determining that the target operation data is valid.
[0012] In combination with the first aspect, in a possible implementation manner, the collaborative data tree further includes a collaboration identifier, and the collaboration identifier is used to uniquely indicate the collaboration order of the collaborative data stored in the container node in the collaborative data tree; the target operation data group further includes a target collaboration identifier, and the target collaboration identifier is used to uniquely identify the collaboration order of the collaborative data corresponding to the target operation data in the collaborative data tree; determining whether the target operation data is valid further includes: if the target container identifier exists in the collaborative data tree, comparing the target collaboration identifier with the collaboration identifier of the target container node corresponding to the target operation data; if the target collaboration identifier is greater than the collaboration identifier of the target container node corresponding to the target operation data, determining that the target operation data is valid; if the target collaboration identifier is less than or equal to the collaboration identifier of the target container node corresponding to the target operation data, determining that the target operation data is invalid. Since the collaboration identifier can indicate the collaboration order of the collaborative data, by comparing the sizes of the collaboration identifiers to determine whether the operation data is valid, it can ensure that the collaborative data in the collaborative data tree is the latest collaborative data.
[0013] In combination with the first aspect, in a possible implementation manner, the method further includes: if the target operation data is invalid, adding the target operation data group to a second sequence list, and the second sequence list stores operation data groups that have not been applied to the collaborative data tree in the collaboration order. Since the second sequence list stores operation data groups that have not been applied to the collaborative data tree in the collaboration order, adding the operation data group to which the invalid operation data belongs to the second sequence list can process the operation data groups that have not been applied to the collaborative data tree in the collaboration order, can realize the sequential processing of the operation data, and thus ensure the data consistency in each collaborative device.
[0014] In combination with the first aspect, in a possible implementation, the method further includes: if the target mapping node is not found, adding the target operation data group to a second sequence list, where the second sequence list stores operation data groups that have not been applied to the collaborative data tree in the collaborative order. Since the second sequence list stores operation data groups that have not been applied to the collaborative data tree in the collaborative order, adding the operation data groups that do not have corresponding mapping nodes in the collaborative data tree to the second sequence list can process the operation data groups that have not been applied to the collaborative data tree in the collaborative order, enabling sequential processing of the operation data, thereby ensuring data consistency among various collaborative devices.
[0015] In combination with the first aspect, in a possible implementation, the target operation data group further includes a target collaboration identifier, where the target collaboration identifier is used to uniquely identify the collaborative order of the collaborative data corresponding to the target operation data in the collaborative data tree; the adding the target operation data group to the second sequence list includes: inserting the target operation data group between a second operation data group and a third operation data group in the second sequence list, where the third operation data group is the next operation data group after the second operation data group in the second sequence list, the collaboration identifier in the second operation data group is less than the target collaboration identifier, and the collaboration identifier in the third operation data group is greater than the target collaboration identifier.
[0016] In combination with the first aspect, in a possible implementation, after adding the target operation data group to the second sequence list, the method further includes: traversing the second sequence list, using the traversed operation data group as the target operation data group to be synchronized, and performing the step of searching for the target mapping node corresponding to the target operation data in the target operation data group in the collaborative data tree according to the path in the target operation data group.
[0017] In combination with the first aspect, in a possible implementation, the method further includes: generating a data snapshot corresponding to the collaborative data tree according to the first sequence list and the second sequence list, and persistently storing the data snapshot corresponding to the collaborative data tree. Generating and storing a data snapshot according to the first sequence list and the second sequence list can ensure that data is not lost.
[0018] In combination with the first aspect, in a possible implementation manner, the operation data in each operation data group includes a collaboration identifier, and the collaboration identifier is used to uniquely indicate the collaboration order of the collaboration data corresponding to the operation data in the collaboration data tree; before generating the data snapshot corresponding to the collaboration data tree according to the first sequence list and the second sequence list, it further includes: deleting the expired operation data in the expired operation data group in the first sequence list, where the expired operation data group and another operation data group other than the expired operation data group in the first sequence list correspond to the same mapping node in the collaboration data tree, and the collaboration identifier in the other operation data group is greater than the collaboration identifier in the expired operation data group. Deleting the past operation data in the expired operation data group in the first sequence list before generating and storing the data snapshot can streamline the operation data, save memory occupancy, and improve the running speed of the online collaboration application.
[0019] In combination with the first aspect, in a possible implementation manner, after updating the target mapping node in the collaboration data tree according to the target operation data group, it further includes: adding the target operation data group to the first sequence list.
[0020] In combination with the first aspect, in a possible implementation manner, the method further includes: if the first operation data group exists in the first sequence list, discarding the first operation data group.
[0021] In combination with the first aspect, in a possible implementation manner, the first operation data group further includes a first collaboration identifier, and the first collaboration identifier is used to uniquely identify the collaboration order of the collaboration data corresponding to the first operation data in the collaboration data tree; after receiving the first operation data group sent by the remote collaboration device, it further includes: according to the first clock value, updating the local clock value of the local collaboration device to: the maximum value of the first clock value and the local clock value of the local collaboration device plus one. Updating the local clock value of the local collaboration device according to the clock value in the remote operation data can ensure the consistency of the clocks between multiple collaboration devices, so that the operation data generated by multiple-end collaboration has sequentiality.
[0022] In combination with the first aspect, in a possible implementation manner, the method further includes: if the second operation data is obtained, adding one to the local clock value to obtain a second clock value, where the second operation data is the operation data corresponding to the user operation performed on the local collaboration device; generating a second operation data group according to the second clock value and the second operation data, where the second operation data group includes the second operation data and a second collaboration identifier, and the second collaboration identifier includes the second clock value.
[0023] Second aspect, a data synchronization device for multi-terminal collaboration is provided, which is applied to a local collaboration device in a multi-terminal collaboration system. The multi-terminal collaboration system includes multiple collaboration devices, and each collaboration device stores a collaboration data tree. Each collaboration device displays a collaboration page based on the collaboration data tree. The collaboration data tree stores collaboration data generated by multi-terminal collaboration in a tree-like structure formed by nested multi-layer nodes. The local collaboration device is any one of the multiple collaboration devices. The device includes:
[0024] A remote data receiving module, configured to receive a first operation data group sent by a remote collaboration device. The first operation data group includes first operation data and a first path. The remote collaboration device is any one of the multiple collaboration devices other than the local collaboration device. The first operation data is operation data corresponding to a user operation performed by the user on the remote collaboration device, and the first path is a search path corresponding to the first operation data in the collaboration data tree.
[0025] A search module, configured to, if the first operation data group is not in the first sequence list, use the first operation data group as a target operation data group to be applied, and according to the path in the target operation data group, search for a target mapping node corresponding to the target operation data in the target operation data group in the collaboration data tree. The first sequence list stores operation data groups that have been applied to the collaboration data tree in a collaboration order. The target mapping node is used to store collaboration data corresponding to the target operation data in the collaboration data tree.
[0026] An update module, configured to, if the target mapping node is found, update the target mapping node in the collaboration data tree according to the target operation data group.
[0027] Third aspect, a computer device is provided, including a memory and one or more processors. The memory is connected to the one or more processors. The one or more processors are configured to execute one or more computer programs stored in the memory. When the one or more processors execute the one or more computer programs, the computer device implements the data synchronization method for multi-terminal collaboration in the first aspect above.
[0028] Fourth aspect, a computer-readable storage medium is provided. The computer-readable storage medium stores a computer program. The computer program includes program instructions. When the above program instructions are executed by a processor, the processor executes the data synchronization method for multi-terminal collaboration in the first aspect above.
[0029] The embodiments of the present application can achieve the following technical effects: realizing the synchronization of operation data generated by a remote collaboration device in a local collaboration device, that is, realizing data synchronization; since the first operation data is used as the target operation data group to be applied only when the first operation data group is not in the first sequence list, and the first sequence list is used to store the operation data groups that have been applied to the collaboration data tree, it can avoid the repeated application of the operation data generated by the remote collaboration device, thereby avoiding data duplication during the data synchronization process; since the target mapping node is updated according to the target operation data only when the target mapping node is found, and the target mapping node is used to store the collaboration data corresponding to the target operation data in the collaboration data tree, it can achieve sequential processing of the operation data, thereby ensuring data consistency in each collaboration device; since the collaboration device displays the collaboration page based on the collaboration data tree, and the collaboration data tree stores the collaboration data generated by multi-end collaboration in a tree structure formed by nested mapping nodes, data synchronization is achieved by searching and updating the collaboration data tree, and searching and deleting in the collaboration data tree is faster, thereby improving the speed of data synchronization and enhancing the efficiency of multi-end collaboration. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments of the present application. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0031] Figure 1 Schematic diagram of the collaboration data tree provided by the embodiments of the present application;
[0032] Figure 2 Schematic diagram of the operation data group provided by the embodiments of the present application;
[0033] Figure 3 Schematic diagram of the multi-end collaboration system provided by the embodiments of the present application;
[0034] Figure 4 Schematic flow chart of a data synchronization method for multi-end collaboration provided by the embodiments of the present application;
[0035] Figures 5A - 5C Schematic diagram of the node tree provided by the embodiments of the present application;
[0036] Figure 6 Structural schematic diagram of a data synchronization device for multi-end collaboration provided by the embodiments of the present application;
[0037] Figure 7 Structural schematic diagram of a computer device provided by the embodiments of the present application. Detailed implementation manners
[0038] In order to make the objectives, technical solutions and advantages of the present application more clear and understandable, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without making creative efforts shall fall within the protection scope of the present application.
[0039] It should be noted that if there is no conflict, the various features in the embodiments of the present application can be combined with each other, and all are within the protection scope of the present application. In addition, although functional module division is performed in the device schematic diagram and the logical sequence is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order from the module division in the device or the sequence in the flowchart. Furthermore, the terms "first", "second", "third", etc. used in the embodiments of the present application do not limit the data and execution order, but are only used to distinguish the same items or similar items with basically the same functions and effects.
[0040] The technical solution of the embodiment of the present application is applicable to a multi-terminal collaboration scenario, which refers to a scenario where multiple users collaborate to edit the same editing target (such as a document, a drawing board, etc.). The multi-terminal collaboration scenario includes but is not limited to a scenario of ordering dishes for multiple people, a scenario of collaborative document editing by multiple people, a scenario of collaborative drawing board by multiple people, and so on.
[0041] In a multi-terminal collaboration scenario, real-time synchronization is crucial. Two feasible real-time synchronization algorithms are respectively operational transformation (OT) and conflict-free replicated data type (CRDT).
[0042] The main principle of OT is that when performing a local operation, the local operation is transformed into a form adapted to remote operations, so that when multiple operations occur simultaneously, they can be correctly merged without causing conflicts. The implementation of OT is relatively complex and requires handling various operation combinations and boundary cases. When the number of users increases, each operation needs to be transformed with other operations, which will cause the operation to slow down and lead to performance problems.
[0043] The main principle of CRDT is to automatically merge and resolve conflicts according to certain rules to achieve data consistency between all replicas, without the need for complex operation transformation. The implementation method is simpler than the OT algorithm, and the processing overhead is small.
[0044] At the core of CRDT is the design of a data structure that can be replicated on multiple computers in a network. This data structure can be independently and concurrently updated on multiple computers without the need for coordination between them. By independently updating the data structure on multiple computers, multi-device synchronization can be achieved. Yjs is a mainstream CDRT database that supports real-time data synchronization and conflict resolution. The CRDT data structure of Yjs is based on a doubly linked list, which consumes more memory and has a slower query speed during multi-device collaboration.
[0045] In view of this, the embodiments of this application involve a CRDT data structure formed by nesting mapping nodes. This CRDT data structure is used as a collaborative data tree required for multi-device collaboration. The collaborative data tree is used as a data structure that can be replicated on multiple computers in a network. Multiple computers can achieve real-time data synchronization and conflict resolution by updating the locally stored collaborative data tree. The collaborative data tree consumes less memory during multi-device collaboration, thereby improving the speed of data synchronization and enhancing the efficiency of multi-device collaboration.
[0046] For ease of understanding, first, the collaborative data tree of the embodiments of this application and some concepts involved in the embodiments of this application will be introduced.
[0047] 1. Collaborative Data Tree
[0048] The collaborative data tree is a CRDT data structure designed by the embodiments of this application to solve data conflicts and data synchronization in multi-device collaboration. It stores the collaborative data generated by multi-device collaboration in a tree-like structure formed by nesting mapping nodes, and each layer of the tree-like structure is in the form of key-value pairs.
[0049] The collaborative data tree consists of multiple layers of nested mapping nodes. The collaborative data tree formed by multiple layers of nested mapping nodes can be as Figure 1As shown. The nesting depth between mapping nodes depends on the hierarchical relationship required by the collaborative application. For example, if the collaborative application is used for collaboration between PPT pages, the nesting depth of the mapping nodes is 2, that is, the collaborative data tree includes two layers of mapping nodes. The first layer of mapping nodes is the root node, which is used to describe the entire PPT. The second layer of mapping nodes is nested within the first layer of mapping nodes. The parent mapping node of the second layer of mapping nodes is the first layer of mapping nodes, which is used to describe each PPT page; if the collaborative application also needs to be used for collaboration at the element level within the PPT page, the nesting depth of the mapping nodes is 3, that is, the collaborative data tree includes three layers of mapping nodes. The third layer of mapping nodes is nested within the second layer of mapping nodes. The parent mapping node of the third layer of mapping nodes is the second layer of mapping nodes, which is used to describe each element in the PPT page. Another example is that if the collaborative application is used for whiteboard collaboration and needs to collaborate on the elements within the whiteboard, the collaborative data tree can include three layers of mapping nodes. The first layer of mapping nodes is the root node, which is used to describe the entire canvas and perform collaboration at the canvas level. The second layer of mapping nodes is nested within the first layer of mapping nodes. The parent mapping node of the second layer of mapping nodes is the first layer of mapping nodes, which is used to describe the set of elements in the whiteboard and perform collaboration at the element set level. The third layer of mapping nodes is nested within the sub-nodes of the second layer of mapping nodes. The parent mapping node of the third layer of mapping nodes is the second layer of mapping nodes, which is used to describe the elements and perform collaboration at the element level.
[0050] In the embodiments of the present application, the collaborative data tree can also be called an n-dimensional Dmap, which is obtained by encapsulating an n-dimensional map. Compared with the n-dimensional map, the n-dimensional Dmap has collaborative capabilities, that is, the collaborative data tree has collaborative capabilities. Among them, n in the n-dimensional map is the nesting depth of the mapping nodes. For example, if the nesting depth of the mapping nodes is 3, the collaborative data tree can also be called a 3-dimensional Dmap, including three layers of mapping nodes, and is obtained by encapsulating a 3-dimensional map.
[0051] The collaborative data tree stores collaborative data in the form of key-value pairs. In addition to mapping nodes, the collaborative data tree also contains container nodes. The container nodes are directly connected under the mapping nodes as the values of the mapping nodes. The container nodes are the sub-nodes of the mapping nodes and are used to store the content that the mapping nodes need to store. The specific content that the mapping nodes need to store can be called collaborative data, and the meaning of the collaborative data will be described in detail later. Mapping nodes nested within the mapping nodes can be connected under the container nodes. For example, if mapping node 1 is the sub-node of container node 1 and container node 1 is the sub-node of mapping node 2, it means that mapping node 1 is the mapping node nested within mapping node 2.
[0052] The keys in the collaborative data tree play an identification role and are used to uniquely identify the nodes in the collaborative data tree in the collaborative data tree. The keys in the collaborative data tree are divided into three types of identifications according to the identification role, and the three identifications are mapping identification, container identification, and collaboration identification.
[0053] The mapping identifier is used to uniquely indicate a mapping node in the collaboration tree. The key connected under each mapping node in the collaboration data tree is the mapping identifier. As Figure 1 shown, dmapA, dmapB, and dmapC are mapping nodes in the collaboration data tree. The keys "aaa", "bbb", and "ccc" under dmapA, dmapB, and dmapC are the mapping identifiers, which are used to identify the mapping nodes dmapA, dmapB, and dmapC in the collaboration data tree respectively. As Figure 1 can be seen, the mapping node dmapB is nested within the mapping node dmapA. The mapping node dmapA is the parent mapping node of the mapping node dmapB. The mapping node dmapC is nested within the mapping node dmapB. The mapping node dmapB is the parent mapping node of the mapping node dmapC.
[0054] Under a mapping node, there can be one or more container nodes. Different container nodes can be used to store different collaboration data. These one or more container nodes are connected in the form of key-value pairs in the value corresponding to the mapping identifier. To distinguish different container nodes, the keys of different container nodes are different. The key of a container node is the container identifier, and the container identifier is used to uniquely indicate a container node in the collaboration data tree. As Figure 1 shown, the key of the container node Content1 connected under the mapping node dmapA is childB. childB is the container identifier of the container node Content1 and is used to identify the container node Content1 in the collaboration data tree.
[0055] A container node also stores data in the form of key-value pairs. The key stored in a container node is the collaboration identifier, and the collaboration identifier is used to uniquely identify the collaboration order of the collaboration data stored in the container node. As Figure 1 shown, the key connected under the container node Content1 is ID1. ID1 is the collaboration identifier of the container node Content1 and is used to identify the collaboration order of the mapping node dmapB nested in the mapping node dmapA. The key connected under the container node Content2 is ID2. ID2 is the collaboration identifier of the container node Content2 and is used to represent the collaboration order of text. Further introduction about the collaboration identifier will be provided later.
[0056] Each mapping node corresponds to a search path in the collaboration data tree. The search path represents the path composed of the mapping identifiers corresponding to all the mapping nodes (excluding the root mapping node) and the container identifiers corresponding to all the container nodes that are experienced layer by layer from the root mapping node (referring to the mapping node that is the root node in the collaboration data tree) until the mapping node is found. As Figure 1As shown in the figure, the mapping node dmapB is the second - layer mapping node in the collaborative data tree, and its corresponding mapping identifier is "bbb". The mapping node dmapB is connected under the container node Content1 under the mapping node dmapA. The container identifier corresponding to the container node Content1 is childB. Therefore, the search path of dmapB is ['bbb::childB']; the mapping node dmapC is the third - layer mapping node in the collaborative data tree, and its corresponding mapping identifier is "ccc". The mapping node dmapC is connected under the container node Content3 under the mapping node dmapB. The container identifier corresponding to the container node Content3 is childC. Therefore, the search path of dmapC is ['bbb::childB', 'ccc::childC']. The search path corresponding to the mapping node is used to quickly search for the mapping node in the collaborative data.
[0057] By parsing the search path corresponding to the mapping node, the mapping identifier corresponding to the mapping node and the parent - child relationship of the mapping node in the collaborative data tree can be determined. For example, by parsing the search path corresponding to the mapping node dmapC, it can be determined that: the mapping identifier of the mapping node dmapC is ccc, the parent - level mapping node of the mapping node dmapC is dmapB, the mapping node dmapC belongs to the container node with the container identifier childC in the mapping node dmapB, the mapping identifier of the mapping node dmapB is bbb, the parent - level mapping node of the mapping node dmapB is dmapA, and the mapping node dmapB belongs to the container node with the container identifier childB in the mapping node dmapA.
[0058] 2. Operation data group (operation, op)
[0059] The operation data group is a data structure used to describe the user's operation behavior. Taking a drawing board as an example, when the user adds an element, deletes an element, modifies the position and size of an element, etc., these operation behaviors can all be described by a set of data, and these data can be understood as the operation data in the operation data group.
[0060] In the embodiments of the present application, the operation data group is as Figure 2 shown and contains the following three core data:
[0061] (1) Operation data (changes), which is used to record the specific change content of the user's operation.
[0062] The operation data is as Figure 2 shown and can be divided into the following three types:
[0063] Type 1: SetValueChange
[0064] SetValueChange can be generated based on the user's modification operation and is used to assign a normal data (i.e., a non-mapped node) to a specified key of a specified mapped node. In addition to carrying type to identify the type, SetValueChange also carries the normal value value.
[0065] Type 2: SetDMapChange
[0066] SetDMapChange can be generated based on the user's addition operation or insertion operation and is used to assign a new mapped node to a specified key of a specified mapped node. In addition to carrying type to identify the type, SetDMapChange also carries the necessary data for creating a new mapped node. The necessary data for creating a new mapped node is stored in the Djson structure, and the Djson structure is used to store all the key data of the mapped node.
[0067] Type 3: DeleteChange
[0068] DeleteChange can be generated based on the user's deletion operation, and DeleteChange is used to delete a specified mapped node and a specified key.
[0069] The type in the operation data is used to indicate the operation type. Based on the ttype in the operation data, the type of the user operation and the type of the operation to be performed on the collaborative data tree can be determined. For example, when type is 0, it can be determined that the user operation performed by the user is a modification-type user operation, indicating that the operation to be performed on the collaborative data tree is: assigning a normal data (i.e., a non-mapped node) to a specified key of a specified mapped node. The value in the operation data is used to represent the specific content of the operation.
[0070] (2) Collaboration identifier
[0071] The collaboration identifier in the operation data group has the same meaning as the collaboration identifier in the collaborative data tree. The collaboration identifier is used to uniquely identify the collaboration order of the collaborative data corresponding to the operation data group. The collaboration identifier can be used to sort the operation data in the operation data group in sequence, so that the collaborative data corresponding to the operation data can be applied in the collaborative data tree in a unified order, thereby keeping the content in the collaborative data tree of each collaborative device consistent. The larger the collaboration identifier, the later the collaboration order corresponding to the collaboration identifier, that is, it indicates that the collaborative data corresponding to the collaboration identifier is generated later.
[0072] In the embodiments of the present application, such as Figure 2As shown, the collaboration identifier includes a device identifier (clientId) and a clock value (clock). The device identifier is used to uniquely identify the collaborating device that generates the operation data. The device identifier is a static identifier and does not change over time. The clock value is used to describe the generation timing of the operation data, and the clock value is dynamically updated. In the application scenario of the embodiments of the present application, the update of the clock value is affected not only by local user operations but also by remote data synchronization. Specific rules regarding the update of the clock value will be described in subsequent technical solutions.
[0073] (3) Search path
[0074] The search path in the operation data group has the same meaning as the aforementioned mapping node in the collaboration data tree. According to the search path, the mapping node corresponding to the operation data in the operation data group in the collaboration data tree can be determined to implement the application of the operation data group to the corresponding mapping node on the collaboration data tree.
[0075] 3. Collaboration data
[0076] Collaboration data refers to the data finally presented on the collaboration data tree after applying the operation data group to the corresponding mapping node on the collaboration data tree. The collaboration data is transformed from the operation data. The collaboration data is the data stored in the value of the container node in the collaboration data tree, that is, the data connected under the container node. Refer to Figure 1 , from Figure 1 it can be seen that there are two container nodes connected under the mapping node dmapA. The value in the container node Content2 with the container identifier "childH" is text, and text is the collaboration data stored in the container node Content2 with the container identifier "childH"; the value in the container node Content1 with the container identifier "childB" is dmapB, and dmapB is the collaboration data stored in the container node Content1 with the container identifier "childB".
[0077] The collaboration data is the data presented on the collaboration data tree after performing the operation corresponding to the target operation type (hereinafter referred to as the target operation type) of the operation data on the collaboration data tree. For example, the type in operation data 1 is Figure 2 0 in Figure 1 , the value in the operation data is "Stext", and the search path corresponding to operation data 1 is Figure 1 ['childH'] in Figure 1In Content2, the value "text" in Content2 is updated to "Stext"; the data presented by the operation data on the collaborative data tree is "Stext", and "Stext" is the collaborative data corresponding to the operation data.
[0078] 4. Sequence List
[0079] In the embodiments of the present application, the sequence list is used to store operation data groups. The sequence list is divided into two types, namely the first sequence list and the second sequence list. The first sequence list is used to store the operation data groups that have been applied to the collaborative data tree; the second sequence list is used to store the operation data groups that have not been applied to the collaborative data tree.
[0080] Among them, applying an operation data group to the collaborative data tree means converting the operation data in the operation data group into collaborative data on the collaborative data tree, so as to update the collaborative data tree. If the operation corresponding to the operation type of the operation data has been performed on the collaborative data tree according to the operation data in the operation data group, and the collaborative data tree has been updated, it means that the operation data group has been applied to the collaborative data tree; if the operation corresponding to the operation type of the operation data has not been performed on the collaborative data tree according to the operation data in the operation data group, it means that the operation data group has not been applied to the collaborative data tree.
[0081] 5. Data Snapshot (Snapshot, abbreviated as S)
[0082] The data snapshot is a full amount of data content that can describe the current application data state. Taking a drawing board as an example, a snapshot refers to all the content of the current drawing board, including: how many elements the current drawing board has, the specific information and state of each element (such as size, position, color, type), etc. In an application built with data-driven, according to the data snapshot of the application at a certain moment, all the content of the application at that time can be restored using it.
[0083] Next, the technical solutions of the embodiments of the present application will be introduced. Among them, the technical solutions of the embodiments of the present application can be applied to a multi-terminal collaboration system, such as Figure 3 As shown, the multi-terminal collaboration system includes multiple collaboration devices, and each collaboration device stores a collaborative data tree. The structure of the collaborative data tree can be as Figure 1 shown. Each collaboration device displays a collaborative page based on the collaborative data tree. The multiple collaboration devices in the multi-terminal collaboration system establish connections through the network and communicate with each other to exchange the operation data generated by their respective operations, and then complete the update of their respective collaborative data trees. Among them, the multiple collaboration devices transfer the operation data generated by their respective operations through operation data groups, and the content included in the operation data group can be as Figure 2 shown.
[0084] SeeFigure 4 , Figure 4 is a schematic flowchart of a data synchronization method for multi - terminal collaboration provided by an embodiment of the present application. As Figure 4 shown, the method includes the following steps:
[0085] S101. The first collaboration device generates a first operation data group according to the operation data corresponding to the user operation executed by the user on the first collaboration device.
[0086] Here, the first collaboration device can be any collaboration device in the multi - terminal collaboration system. The first operation data group includes first operation data and a first path. The first operation data is the operation data corresponding to the user operation executed by the user on the first collaboration device. If the user operations executed on the first collaboration device are different, the types of the first operation data are different. The first operation data can be one of the three types introduced above.
[0087] The first path is the search path corresponding to the first operation data in the collaboration data tree. Based on the first path, the mapping node corresponding to the first operation data can be searched in the collaboration data tree to apply the first operation data to the collaborative data tree. Regarding the format and content of the first path, reference can be made to the description of the search path above, and details will not be elaborated here.
[0088] The first operation data group further includes a collaboration identifier corresponding to the first operation data (hereinafter referred to as the first collaboration identifier), and the first collaboration identifier is used to uniquely indicate the collaboration order of the collaboration data corresponding to the first operation data in the collaboration data tree.
[0089] The first collaboration identifier includes the local clock value of the first collaboration device (hereinafter referred to as the first clock value) and the device identifier of the first collaboration device. The device identifier of the first collaboration device is used to uniquely identify the first collaboration device. The local clock value of the first collaboration device is used to identify the generation timing of the first operation data in the first collaboration device. The local clock value of the first collaboration device can change with the operation data generated by the first collaboration device. For each operation data generated by the first collaboration device, the local clock value of the first collaboration device is incremented by one.
[0090] S102. The first collaboration device sends the first operation data group to the second collaboration device, and the second collaboration device receives the first operation data group.
[0091] Here, the first collaboration device sends the first operation data group to the second collaboration device through the Internet network, and the second collaboration device receives the second operation data group through the Internet network.
[0092] Among them, for the second collaboration device, the second collaboration device itself is the local collaboration device, and the first collaboration device is the remote collaboration device corresponding to the second collaboration device.
[0093] After receiving the first set of operation data, the second collaborative device can obtain the first collaboration identifier from the first set of operation data, obtain the first clock value from the first collaboration identifier, then compare the local clock value of the second collaborative device with the first clock value, and update the local clock value of the second collaborative device according to the first clock value and the local clock value of the second collaborative device to: the maximum value of the first clock value and the local clock value of the second collaborative device plus one.
[0094] For example, if the first clock value is 5 and the local clock value of the second collaborative device is 4, and the first clock value is greater than the local clock value of the second collaborative device, then the second collaborative device updates the local clock value of the second collaborative device to 6.
[0095] Updating the local clock value of the local collaborative device according to the clock value in the remote operation data can ensure the consistency of the clocks among multiple collaborative devices, so that the operation data generated by multi-end collaboration has orderliness.
[0096] Optionally, if the second collaborative device obtains the second operation data, the second collaborative device can also increment the local clock value of the second collaborative device by one to obtain the second clock value, and the second operation data is the operation data corresponding to the user operation to be executed on the second collaborative device. For example, the local clock value of the second collaborative device is 6, and when the second operation data is obtained, the second collaborative device updates the local clock value of the second collaborative device to 7.
[0097] It can be seen from this that the local clock value of the collaborative device is affected by local user operations and remote data synchronization. By updating the local clock value of the collaborative device, the operation data groups generated by multiple collaborative devices can be sorted, so that the operation data groups can be applied to the collaborative data tree in an orderly manner.
[0098] Further optionally, after obtaining the second clock value, the second collaborative device can also generate a second set of operation data according to the second clock value and the second operation data. The second set of operation data includes the second operation data and the second collaboration identifier, and the second collaboration identifier includes the second clock value and the device identifier of the second collaborative device.
[0099] Further optionally, after generating the second set of operation data, the second collaborative device can also send the second set of operation data to other collaborative devices including the first collaborative device.
[0100] S103. The second collaborative device determines whether the first set of operation data is in the first sequence list of the second collaborative device.
[0101] Here, the first sequence list of the second collaborative device is used to store the operation data group of the collaborative data tree that has not been applied to the second collaborative device yet. The operation data group not being applied to the collaborative data tree of the second collaborative device means that the second collaborative device has not updated the collaborative data tree in the second collaborative device according to this operation data group.
[0102] If the first operation data group is in the first sequence list of the second collaborative device, it indicates that the second collaborative device has applied the first operation data group to the collaborative data tree of the second collaborative device, that is, the second collaborative device has updated the collaborative data tree in the second collaborative device according to the first operation data group, and step S111 is executed; if the first operation data group is not in the first sequence list of the second collaborative device, it indicates that the second collaborative device has not applied the first operation data group to the collaborative data tree of the second collaborative device, that is, the second collaborative device has not updated the collaborative data tree in the second collaborative device according to the first operation data group, and step S104 is executed.
[0103] S104, the second collaborative device takes the first operation data group as the target operation data group to be applied.
[0104] Here, the content of the target operation data group can refer to the foregoing introduction to the operation data group, including the target operation data, the target path, and the collaborative identifier corresponding to the target operation data (hereinafter referred to as the target collaborative identifier). The target path is the search path corresponding to the target operation data in the collaborative data tree. Based on the target path, the mapping node corresponding to the target operation data can be found in the collaborative data to apply the target operation data to the collaborative data tree. The target collaborative identifier is used to uniquely indicate the collaborative order of the collaborative data corresponding to the target operation data in the collaborative data tree.
[0105] When taking the first operation data group as the target operation data group to be applied, the target operation data is the foregoing first operation data, the target path is the foregoing first path, and the target collaborative identifier is the foregoing first collaborative identifier.
[0106] S105, the second collaborative device determines whether the target mapping node corresponding to the target operation data in the target operation data group can be found in the collaborative data tree of the second collaborative device according to the path in the target operation data group.
[0107] Here, the target mapping node corresponding to the target operation data refers to the mapping node in the collaborative data tree used to store the collaborative data corresponding to the target operation data. Since the paths in the operation data group contain the mapping identifiers and container identifiers corresponding to all the mapping nodes experienced in finding the mapping node, it is possible to determine whether the last mapping identifier in the target operation data group exists in the collaborative data tree of the second collaborative device. If the last mapping identifier in the target operation data group exists in the collaborative data tree of the second collaborative device, it is determined that the target mapping node corresponding to the target operation data in the target operation data group is found in the collaborative data tree of the second collaborative device; if the last mapping identifier in the target operation data group does not exist in the collaborative data tree of the second collaborative device, it is determined that the target mapping node corresponding to the target operation data in the target operation data group is not found in the collaborative data tree of the second collaborative device.
[0108] Taking the paths in the target operation data group as ['bbb::childB', 'ccc::childC'], since ccc is the last mapping identifier in this path, it can be determined whether the mapping identifier ccc exists in the collaborative data tree of the second collaborative device. If the mapping identifier ccc exists, it is determined that the target mapping node corresponding to the target operation data in the target operation data group is found in the collaborative data tree of the second collaborative device; if the mapping identifier ccc does not exist, it is determined that the target mapping node corresponding to the target operation data in the target operation data group is not found in the collaborative data tree of the second collaborative device.
[0109] If the second collaborative device finds the target mapping node corresponding to the target operation data in the target operation data group in the collaborative data tree of the second collaborative device, step S106 is executed; if the second collaborative device does not find the target mapping node corresponding to the target operation data in the target operation data group in the collaborative data tree of the second collaborative device, step S109 is executed.
[0110] S106, the second collaborative device determines whether the target operation data is valid.
[0111] Among them, the second collaborative device can determine whether the target operation data is valid through the following steps:
[0112] A1. Determine whether the target container identifier exists in the collaborative data tree of the second collaborative device.
[0113] If the target container identifier exists in the collaboration data tree of the second collaboration device, it indicates that there is already a container node in the collaboration data tree of the second collaboration device for storing the collaboration data corresponding to the target operation data. It is necessary to further determine whether the collaboration data corresponding to the target operation data is the latest collaboration data, and execute step A2; if the target container identifier does not exist in the collaboration data tree of the second collaboration device, it indicates that there is no container node in the collaboration data tree of the second collaboration device for storing the collaboration data corresponding to the target operation data, and execute step A3.
[0114] A2. Compare the target collaboration identifier with the collaboration identifier corresponding to the target container node of the target operation data.
[0115] Here, the target container node corresponding to the target operation data refers to the container node for storing the collaboration data corresponding to the target operation data, and the collaboration identifier corresponding to the target container node is the key in the target container node. For Figure 1 example, assume that the target container node corresponding to the target operation data is Figure 1 Content1 in, then the collaboration identifier corresponding to the target container node is ID1.
[0116] Since the collaboration identifier includes a clock value and a device identifier, when comparing the target collaboration identifier with the collaboration identifier corresponding to the target container node, the clock value in the target collaboration identifier and the clock value in the collaboration identifier corresponding to the target container node can be compared first. If the clock value in the target collaboration identifier is greater than the clock value in the collaboration identifier corresponding to the target container node, it is determined that the target collaboration identifier is greater than the collaboration identifier corresponding to the target container node; if the clock value in the target collaboration identifier is less than the clock value in the collaboration identifier corresponding to the target container node, it is determined that the target collaboration identifier is less than the collaboration identifier corresponding to the target container node; if the clock value in the target collaboration identifier is equal to the clock value in the collaboration identifier corresponding to the target container node, then compare the device identifier in the target collaboration identifier and the device identifier in the collaboration identifier corresponding to the target container node; if the device identifier in the target collaboration identifier is greater than the device identifier in the collaboration identifier corresponding to the target container node, it is determined that the target collaboration identifier is greater than the collaboration identifier corresponding to the target container node; if the device identifier in the target collaboration identifier is less than the device identifier in the collaboration identifier corresponding to the target container node, it is determined that the target collaboration identifier is less than the collaboration identifier corresponding to the target container node.
[0117] If the target collaboration identifier is greater than the collaboration identifier corresponding to the target container node, it indicates that the collaboration order of the collaboration data corresponding to the target operation data is later than the collaboration order of the collaboration data stored in the container node. The collaboration data stored in the container node needs to be updated, and step A3 is executed; if the target collaboration identifier is greater than the collaboration identifier corresponding to the target container node, it indicates that the collaboration order of the target operation data is earlier than the collaboration order of the collaboration data stored in the container node. The collaboration data corresponding to the target operation data is not the latest collaboration data, and there is no need to update the collaboration data stored in the container node, and step A4 is executed.
[0118] A3. Determine that the target operation data is valid.
[0119] A4. Determine that the target operation data is invalid.
[0120] Since the collaboration identifier can indicate the collaboration order of the collaboration data, judging whether the operation data is valid by comparing the collaboration identifiers can ensure that the collaboration data in the collaboration data tree is the latest collaboration data.
[0121] If the target operation data is valid, step S107 is executed; if the target operation data is invalid, step S109 is executed.
[0122] S107. The second collaboration device updates the target mapping node in the collaboration data tree of the second collaboration device according to the target operation data group.
[0123] Here, the target operation data may have three types, and the three types are SetValueChange, SetDMapChange, and DeleteChange respectively.
[0124] If the type of the target operation data is SetValueChange, after finding the target container node according to the path in the target operation data group, assign the value in the target operation data to the value in the target container node, and assign the target collaboration identifier in the target operation data group to the collaboration identifier in the target container node.
[0125] If the type of the target operation data is SetDMapChange, after finding the target container node according to the path in the target operation data, create a new mapping node under the target container node according to the Djson structure carried in the target operation data. The newly created mapping node is used as the value of the target container node, and the target collaboration identifier in the target operation data group is assigned to the collaboration identifier in the target container node.
[0126] If the type of the target operation data is DeleteChange, after finding the target container node according to the path in the target operation data, set the value in the target container node to the deletion bit, and assign the target collaboration identifier in the target operation data group to the collaboration identifier in the target container node.
[0127] Only when the operation data is valid, update the relevant information corresponding to the target mapping node in the collaboration data tree according to the target operation data, which can realize the sequential processing of the operation data, thereby ensuring data consistency in each collaboration device.
[0128] S108, The second collaboration device adds the target operation data group to the first sequence list of the second collaboration device.
[0129] Among them, the second collaboration device can insert the target operation data group between the fourth operation data group and the fifth operation data group in the first sequence list, and the fifth operation data group is the next operation data group of the fourth operation data group in the first sequence list. The second collaboration device can sequentially traverse the operation data groups in the first sequence list, and compare the collaboration identifier in the traversed operation data group in the first sequence list with the target collaboration identifier. If the collaboration identifier in the traversed operation data group in the first sequence list is less than the target collaboration identifier, then traverse the next operation data group until the collaboration identifier in the traversed operation data group in the second sequence list is greater than the target collaboration identifier. Determine the operation data group with the collaboration identifier greater than the target collaboration identifier as the fifth operation data group, and insert the target operation data group before the fifth operation data group. The method of comparing the sizes of the collaboration identifiers can refer to the description in the foregoing step A2 and will not be elaborated here.
[0130] S109, The second collaboration device adds the target operation data group to the second sequence list of the second collaboration device.
[0131] Here, the second sequence list of the second collaboration device is used to store the operation data groups that have not been updated to the collaboration data tree of the second collaboration device.
[0132] Among them, the second collaborative device can insert the target operation data group between the second operation data group and the third operation data group in the second sequence list in the second collaborative device. The third operation data group is the next operation data group after the second operation data group in the second sequence list of the second collaborative device. The collaboration identifier in the second operation data group is less than the target collaboration identifier, and the collaboration identifier in the third operation data group is greater than the target collaboration identifier. The second collaborative device can sequentially traverse the operation data groups in the second sequence list and compare the collaboration identifier in the traversed operation data group in the second sequence list with the target collaboration identifier. If the collaboration identifier in the traversed operation data group in the second sequence list is less than the target collaboration identifier, then traverse the next operation data group until the collaboration identifier in the traversed operation data group in the second sequence list is greater than the target collaboration identifier. Determine the operation data group with the collaboration identifier greater than the target collaboration identifier as the third operation data group, and insert the target operation data group before the third operation data group. For the method of comparing the sizes of collaboration identifiers, reference can be made to the description in step A2 above, which will not be elaborated here.
[0133] Since the second sequence list stores the operation data groups that have not been applied to the collaboration data tree in collaboration order, adding the operation data group to which the invalid operation data belongs to the second sequence list can process the operation data groups that have not been applied to the collaboration data tree in collaboration order, and can achieve sequential processing of the operation data, thereby ensuring data consistency in each collaborative device.
[0134] S110. The second collaborative device traverses the second sequence list of the second collaborative device, takes the traversed operation data group as the target operation data group to be synchronized, and returns to execute step S105.
[0135] S111. The second collaborative device discards the first operation data group.
[0136] S112. The second collaborative device generates a data snapshot corresponding to the collaboration data tree in the second collaborative device according to the first sequence list and the second sequence list.
[0137] Among them, the data snapshot corresponding to the collaboration data tree in the second collaborative device is a combination of the first sequence list and the second sequence list.
[0138] Optionally, before generating the data snapshot corresponding to the collaboration data tree in the second collaborative device, the second collaborative device can also delete the expired operation data in the expired operation data group in the first sequence list. The expired operation data group and another operation data group other than the expired operation data group in the first sequence list correspond to the same mapping node in the collaboration data tree, and the collaboration identifier in the other operation data group other than the expired operation data group is greater than the collaboration identifier in the expired operation data group.
[0139] Among them, the operation data groups in the first sequence list can be constructed into a node tree. Traverse the operation data groups in the first sequence list, combine the paths in the operation data groups and each element in the operation data to form node paths, generate corresponding nodes, and determine whether the nodes corresponding to the positions have already been generated. If the nodes corresponding to the positions have already been generated, clear the content of the already generated nodes and the descendants of the already generated nodes. If the content of the entire operation data in the operation data group is cleared, it means that all the operation data in the operation data group are expired operation data, and then delete the operation data group. If there are no corresponding nodes, generate corresponding nodes until all the operation data groups in the first sequence list are traversed, so as to implement the expired operation data in the expired operation data groups in the first sequence list.
[0140] For example, the operation data group in the first sequence list traversed is as Figure 5A shown, then a node tree as Figure 5B shown can be created. If the node name in Figure 5B is generated by the operation data group traversed later, it means that Figure 5B the node name in and the descendants of the node name are expired nodes. Delete the content of the descendants of the node name, so as to obtain the operation data group as Figure 5C shown. If the node keyC in Figure 5B is generated by the operation data group traversed later, it means that Figure 5A the entire operation data group shown is expired, and delete the operation data group as Figure 5A shown.
[0141] Before generating and storing the data snapshot, deleting the past operation data in the expired operation data groups in the first sequence list can streamline the operation data, save memory occupancy, and improve the running speed of the online collaboration application.
[0142] S113, the second collaboration device persistently stores the data snapshot corresponding to the collaboration data tree in the second collaboration device.
[0143] In the above Figure 4In the corresponding technical solution, the collaboration device displays a collaboration page based on a collaboration data tree. The collaboration data tree stores collaboration data generated by multi-terminal collaboration in a tree structure formed by nested mapping nodes. After the local collaboration device receives a first operation data group sent by a remote collaboration device, if the first operation data group is not in the first sequence list, the first operation data group is used as the target operation data group to be applied, and the target mapping node corresponding to the target operation data group is searched for in the collaboration data tree. The target mapping node is used to store relevant information of the collaboration data. If the target mapping node is found, the relevant information corresponding to the target mapping node in the collaboration data tree is updated according to the target operation data in the target operation data group, realizing the synchronization of the operation data generated by the remote collaboration device in the local collaboration device, that is, realizing data synchronization. Since the first operation data is used as the target operation data group to be applied only when the first operation data group is not in the first sequence list, and the first sequence list is used to store the operation data groups that have been applied to the collaboration data tree, it is possible to avoid repeated application of the operation data generated by the remote collaboration device, thereby avoiding data duplication during the data synchronization process. Since the target mapping node is updated according to the target operation data only when the target mapping node is found, and the target mapping node is used to store the collaboration data corresponding to the target operation data in the collaboration data tree, it is possible to realize sequential processing of the operation data, thereby ensuring data consistency in each collaboration device. Since the collaboration device displays the collaboration page based on the collaboration data tree, and the collaboration data tree stores the collaboration data generated by multi-terminal collaboration in a tree structure formed by nested mapping nodes, data synchronization is realized by searching and updating the collaboration data tree. Searching and deleting in the collaboration data tree are faster, thereby improving the speed of data synchronization and enhancing the efficiency of multi-terminal collaboration.
[0144] The method of the embodiment of the present application is introduced above. Next, the device of the embodiment of the present application is introduced.
[0145] See Figure 6 , Figure 6 FIG. is a schematic structural diagram of a data synchronization device for multi-terminal collaboration provided by an embodiment of the present application, which is applied to a local collaboration device in a multi-terminal collaboration system. The multi-terminal collaboration system includes multiple collaboration devices, and each collaboration device stores a collaboration data tree. Each collaboration device displays a collaboration page based on the collaboration data tree. The collaboration data tree stores collaboration data generated by multi-terminal collaboration in a tree structure formed by nested mapping nodes. The local collaboration device is any one of the multiple collaboration devices. As Figure 6 shown, the data synchronization device 20 for multi-terminal collaboration includes:
[0146] The remote data receiving module 201 is configured to receive a first operation data group sent by a remote collaboration device. The first operation data group includes first operation data and a first path. The remote collaboration device is any one of the multiple collaboration devices other than the local collaboration device. The first operation data is operation data corresponding to a user operation performed by the user on the remote collaboration device. The first path is a search path corresponding to the first operation data in the collaboration data tree.
[0147] The search module 202 is configured to, if the first operation data group is not in the first sequence list, use the first operation data group as a target operation data group to be applied, and according to the path in the target operation data group, search for a target mapping node corresponding to the target operation data in the target operation data group in the collaboration data tree. The first sequence list stores operation data groups that have been applied to the collaboration data tree in the collaboration order. The target mapping node is used to store the collaboration data corresponding to the target operation data in the collaboration data tree.
[0148] The update module 203 is configured to, if the target mapping node is found, update the target mapping node in the collaboration data tree according to the target operation data group.
[0149] In a possible design, the above-mentioned search module 202 is further configured to: determine whether the target operation data is valid; the update module 203 is specifically configured to, if the target operation data is valid, update the target mapping node in the collaboration data tree according to the target operation data group.
[0150] In a possible design, the collaboration data tree further includes a container node and a container identifier corresponding to the container node. The container node is a child node under the mapping node. The container identifier is used to uniquely identify the container node in the collaboration data tree. The target operation data includes a target container identifier, and the target container identifier is used to uniquely identify the container node to which the collaboration data corresponding to the target operation data belongs in the collaboration data tree. The above-mentioned search module 202 is specifically configured to: determine whether the target container identifier exists in the collaboration data tree; if the target container identifier does not exist in the collaboration data tree, determine that the target operation data is valid.
[0151] In a possible design, the collaborative data tree further includes a collaborative identifier, which is used to uniquely indicate the collaborative order of the collaborative data stored in the container node in the collaborative data tree; the target operation data group further includes a target collaborative identifier, which is used to uniquely identify the collaborative order of the collaborative data corresponding to the target operation data in the collaborative data tree; specifically, the above-mentioned search module 202 is configured to: if the target container identifier exists in the collaborative data tree, compare the target collaborative identifier with the collaborative identifier of the target container node corresponding to the target operation data; if the target collaborative identifier is greater than the collaborative identifier of the target container node corresponding to the target operation data, determine that the target operation data is valid; if the target collaborative identifier is less than or equal to the collaborative identifier of the target container node corresponding to the target operation data, determine that the target operation data is invalid.
[0152] In a possible design, the above-mentioned search module 202 is further configured to: if the target operation data is invalid, add the target operation data group to a second sequence list, and the second sequence list stores operation data groups that have not been applied to the collaborative data tree in the collaborative order.
[0153] In a possible design, the above-mentioned search module 202 is further configured to: if the target mapping node is not found, add the target operation data group to a second sequence list, and the second sequence list stores operation data groups that have not been applied to the collaborative data tree in the collaborative order.
[0154] In a possible design, the target operation data group further includes a target collaborative identifier, which is used to uniquely identify the collaborative order of the collaborative data corresponding to the target operation data in the collaborative data tree; specifically, the above-mentioned search module 202 is configured to: insert the target operation data group between a second operation data group and a third operation data group in the second sequence list, where the third operation data group is the next operation data group after the second operation data group in the second sequence list, the collaborative identifier in the second operation data group is less than the target collaborative identifier, and the collaborative identifier in the third operation data group is greater than the target collaborative identifier.
[0155] In a possible design, the above-mentioned search module 202 is further configured to: traverse the second sequence list, use the traversed operation data group as the target operation data group to be synchronized, and execute the step of searching for the target mapping node corresponding to the target operation data in the target operation data group in the collaborative data tree according to the path in the target operation data group.
[0156] In a possible design, the above-mentioned data synchronization device 20 for multi-terminal collaboration further includes a storage module 204, which is used to generate a data snapshot corresponding to the collaboration data tree according to the first sequence list and the second sequence list, and persistently store the data snapshot corresponding to the collaboration data tree.
[0157] In a possible design, the above-mentioned search module 202 is further used to: delete the expired operation data in the expired operation data group in the first sequence list, where the expired operation data group and another operation data group other than the expired operation data group in the first sequence list correspond to the same mapping node in the collaboration data tree, and the collaboration identifier in the other operation data group is greater than the collaboration identifier in the expired operation data group.
[0158] In a possible design, the above-mentioned update module 203 is further used to: add the target operation data group to the first sequence list.
[0159] In a possible design, the above-mentioned search module 202 is further used to: if the first operation data group exists in the first sequence list, discard the first operation data group.
[0160] In a possible design, the first operation data group further includes a first collaboration identifier, which is used to uniquely identify the collaboration order of the collaboration data corresponding to the first operation data in the collaboration data tree, and the first collaboration identifier includes a first clock value; the above-mentioned data synchronization device 20 for multi-terminal collaboration further includes a clock update module 204, which is used to update the local clock value of the local collaboration device according to the first clock value to: the maximum value of the first clock value and the local clock value of the local collaboration device plus one.
[0161] In a possible design, the above-mentioned clock update module 204 is further used to: if a second operation data is obtained, add one to the local clock value to obtain a second clock value, where the second operation data is the operation data corresponding to a user operation performed by the user on the local collaboration device; generate a second operation data group according to the second clock value and the second operation data, where the second operation data group includes the second operation data and a second collaboration identifier, and the second collaboration identifier includes the second clock value.
[0162] It should be noted that Figure 6 For the content not mentioned in the corresponding embodiments, reference can be made to the description of the foregoing method embodiments, which will not be elaborated here.
[0163] After receiving the first operation data group sent by the remote collaboration device, if the first operation data group is not in the first sequence list, the first operation data group is used as the target operation data group to be applied, and the target mapping node corresponding to the target operation data group is searched in the collaboration data tree. The target mapping node is used to store the relevant information of the collaboration data. If the target mapping node is found, the relevant information corresponding to the target mapping node in the collaboration data tree is updated according to the target operation data in the target operation data group, realizing the synchronization of the operation data generated by the remote collaboration device in the local collaboration device, that is, realizing data synchronization. Since the first operation data is used as the target operation data group to be applied only when the first operation data group is not in the first sequence list, and the first sequence list is used to store the operation data groups that have been applied to the collaboration data tree, it can avoid the repeated application of the operation data generated by the remote collaboration device, thus avoiding data duplication in the data synchronization process. Since the relevant information of the target mapping node in the collaboration data tree is updated according to the target operation data only when the target mapping node is found, and the target mapping node is used to store the collaboration data corresponding to the target operation data in the collaboration data tree, it can realize the sequential processing of the operation data, thus ensuring data consistency in each collaboration device. Since the collaboration device displays the collaboration page based on the collaboration data tree, and the collaboration data tree stores the collaboration data generated by multi-terminal collaboration in a tree structure formed by nested mapping nodes, data synchronization is realized by searching and updating the collaboration data tree. Searching and deleting in the collaboration data tree is faster, thus improving the data synchronization speed and enhancing the efficiency of multi-terminal collaboration.
[0164] See Figure 7 , Figure 7 FIG. is a schematic structural diagram of a computer device provided by an embodiment of the present application. The computer device 30 includes a processor 301 and a memory 302. The memory 302 is connected to the processor 301, for example, connected to the processor 301 through a bus. The collaboration data tree is stored in the computer device 30, and the computer device displays the collaboration page based on the collaboration data tree. The computer device 30 is a local collaboration device.
[0165] The processor 301 is configured to support the computer device 30 in performing the corresponding functions in the methods in the above method embodiments. The processor 301 may be a central processing unit (CPU), a network processor (NP), a hardware chip, or any combination thereof. The above hardware chip may be an application specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The above PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0166] The memory 302 is used to store program codes, etc. The memory 302 may include a volatile memory (VM), such as a random access memory (RAM); the memory 302 may also include a non-volatile memory (NVM), such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid-state drive (SSD); the memory 302 may further include a combination of the above types of memories.
[0167] The processor 301 may call the program code to perform the following operations:
[0168] Receiving a first operation data group sent by a remote collaboration device, the first operation data group including first operation data and a first path, the remote collaboration device being any one of a plurality of collaboration devices other than the local collaboration device, the first operation data being operation data corresponding to a user operation performed by the user on the remote collaboration device, and the first path being a search path corresponding to the first operation data in the collaboration data tree;
[0169] If the first operation data group is not in the first sequence list, use the first operation data group as the target operation data group to be applied. According to the path in the target operation data group, search for the target mapping node corresponding to the target operation data in the target operation data group in the collaboration data tree. The first sequence list stores the operation data groups that have been applied to the collaboration data tree in the collaboration order. The target mapping node is used to store the collaboration data corresponding to the target operation data in the collaboration data tree;
[0170] If the target mapping node is found, update the target mapping node in the collaboration data tree according to the target operation data group.
[0171] An embodiment of the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program. The computer program includes program instructions. When the program instructions are executed by a computer, the computer is caused to execute the method described in the foregoing embodiments.
[0172] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM), etc.
[0173] The foregoing disclosure is only for the preferred embodiments of the present application. Of course, the scope of the rights of the present application cannot be limited thereby. Therefore, equivalent changes made according to the claims of the present application still fall within the scope covered by the present application.
Claims
1. A data synchronization method for multi - terminal collaboration, characterized in that, A local collaboration device applied to a multi - device collaboration system. The multi - device collaboration system includes multiple collaboration devices. In each collaboration device, a collaboration data tree is stored. Each collaboration device displays a collaboration page based on the collaboration data tree. The collaboration data tree stores the collaboration data generated by multi - device collaboration in a tree - like structure formed by nested mapping nodes. The local collaboration device is any one of the multiple collaboration devices. The method includes: Receiving a first operation data group sent by a remote collaboration device. The first operation data group includes first operation data and a first path. The remote collaboration device is any one of the multiple collaboration devices other than the local collaboration device. The first operation data is the operation data corresponding to a user operation performed by the user on the remote collaboration device. The first path is the search path corresponding to the first operation data in the collaboration data tree. If the first operation data group is not in the first sequence list, taking the first operation data group as a target operation data group to be applied. According to the path in the target operation data group, searching for the target mapping node corresponding to the target operation data in the target operation data group in the collaboration data tree. The first sequence list stores the operation data groups that have been applied to the collaboration data tree in the collaboration order. The target mapping node is used to store the collaboration data corresponding to the target operation data in the collaboration data tree. If the target mapping node is found, updating the target mapping node in the collaboration data tree according to the target operation data group.
2. The method according to claim 1, wherein Before updating the target mapping node in the collaboration data tree according to the target operation data group, it further includes: Judging whether the target operation data is valid. Updating the target mapping node in the collaboration data tree according to the target operation data group includes: If the target operation data is valid, updating the target mapping node in the collaboration data tree according to the target operation data group.
3. The method according to claim 2, wherein The collaboration data tree further includes a container node and a container identifier corresponding to the container node. The container node is a child node under the mapping node. The container identifier is used to uniquely identify the container node in the collaboration data tree. The target operation data includes a target container identifier, and the target container identifier is used to uniquely identify the container node to which the collaboration data corresponding to the target operation data belongs in the collaboration data tree. Judging whether the target operation data is valid includes: Judging whether the target container identifier exists in the collaboration data tree. If the target container identifier does not exist in the collaboration data tree, determining that the target operation data is valid.
4. The method according to claim 3, characterized in that, The collaboration data tree further includes a collaboration identifier. The collaboration identifier is used to uniquely indicate the collaboration order of the collaboration data stored in the container node in the collaboration data tree. The target operation data group further includes a target collaboration identifier, and the target collaboration identifier is used to uniquely identify the collaboration order of the collaboration data corresponding to the target operation data in the collaboration data tree. Judging whether the target operation data is valid further includes: If the target container identifier exists in the collaborative data tree, compare the target collaboration identifier with the collaboration identifier of the target container node corresponding to the target operation data; If the target collaboration identifier is greater than the collaboration identifier of the target container node corresponding to the target operation data, determine that the target operation data is valid; If the target collaboration identifier is less than or equal to the collaboration identifier of the target container node corresponding to the target operation data, determine that the target operation data is invalid.
5. The method according to claim 2, wherein The method further includes: If the target operation data is invalid, add the target operation data group to a second sequence list, where the second sequence list stores operation data groups that have not been applied to the collaborative data tree in collaboration order.
6. The method according to claim 1, wherein The method further includes: If the target mapping node is not found, add the target operation data group to a second sequence list, where the second sequence list stores operation data groups that have not been applied to the collaborative data tree in collaboration order.
7. The method according to claim 5 or 6, characterized in that, The target operation data group further includes a target collaboration identifier, which is used to uniquely identify the collaboration order of the collaborative data corresponding to the target operation data in the collaborative data tree; The adding the target operation data group to the second sequence list includes: Insert the target operation data group between a second operation data group and a third operation data group in the second sequence list, where the third operation data group is the next operation data group after the second operation data group in the second sequence list, the collaboration identifier in the second operation data group is less than the target collaboration identifier, and the collaboration identifier in the third operation data group is greater than the target collaboration identifier.
8. The method according to claim 5 or 6, characterized in that, After adding the target operation data group to the second sequence list, it further includes: Traverse the second sequence list, use the traversed operation data group as the target operation data group to be synchronized, and execute the step of finding the target mapping node corresponding to the target operation data in the target operation data group in the collaborative data tree according to the path in the target operation data group.
9. The method according to claim 5 or 6, characterized in that, The method further includes: Generate a data snapshot corresponding to the collaborative data tree according to the first sequence list and the second sequence list, and persistently store the data snapshot corresponding to the collaborative data tree.
10. The method according to claim 9, characterized in that, The operation data in each operation data group includes a collaboration identifier, which is used to uniquely indicate the collaboration order of the collaborative data corresponding to the operation data in the collaborative data tree; Before generating the data snapshot corresponding to the collaborative data tree according to the first sequence list and the second sequence list, it further includes: Delete the expired operation data in the expired operation data group in the first sequence list, where the expired operation data group and another operation data group in the first sequence list except the expired operation data group correspond to the same mapping node in the collaborative data tree, and the collaboration identifier in the other operation data group is greater than the collaboration identifier in the expired operation data group.
11. The method according to claim 1, wherein After updating the target mapping node in the collaborative data tree according to the target operation data group, it further includes: Add the target operation data group to the first sequence list.
12. The method according to claim 1, characterized in that, The method further includes: If the first operation data group exists in the first sequence list, discard the first operation data group.
13. The method according to claim 1, wherein The first operation data group further includes a first collaboration identifier, which is used to uniquely identify the collaboration order of the collaboration data corresponding to the first operation data in the collaboration data tree. The first collaboration identifier includes a first clock value. After receiving the first operation data group sent by the remote collaboration device, it further includes: According to the first clock value, update the local clock value of the local collaboration device to: the maximum value of the first clock value and the local clock value of the local collaboration device plus one.
14. The method according to claim 13, wherein The method further includes: If the second operation data is obtained, increment the local clock value by one to obtain a second clock value. The second operation data is the operation data corresponding to the user operation performed by the user on the local collaboration device. Generate a second operation data group according to the second clock value and the second operation data. The second operation data group includes the second operation data and a second collaboration identifier, and the second collaboration identifier includes the second clock value.
15. A data synchronization device for multi - terminal collaboration, characterized in that, Applied to a local collaboration device in a multi-terminal collaboration system. The multi-terminal collaboration system includes multiple collaboration devices, and each collaboration device stores a collaboration data tree. Each collaboration device displays a collaboration page based on the collaboration data tree. The collaboration data tree stores the collaboration data generated by multi-terminal collaboration in a tree structure formed by nested multi-layer nodes. The local collaboration device is any one of the multiple collaboration devices. The device includes: A remote data receiving module, configured to receive a first operation data group sent by a remote collaboration device. The first operation data group includes first operation data and a first path. The remote collaboration device is any one of the multiple collaboration devices other than the local collaboration device. The first operation data is the operation data corresponding to the user operation performed by the user on the remote collaboration device. The first path is the search path corresponding to the first operation data in the collaboration data tree. A search module, configured to, if the first operation data group is not in the first sequence list, use the first operation data group as the target operation data group to be applied, and search for the target mapping node corresponding to the target operation data in the target operation data group in the collaboration data tree according to the path in the target operation data group. The first sequence list stores the operation data groups that have been applied to the collaboration data tree in the collaboration order. The target mapping node is used to store the collaboration data corresponding to the target operation data in the collaboration data tree. An update module, configured to, if the target mapping node is found, update the target mapping node in the collaboration data tree according to the target operation data group.
16. A computer device, characterized in that, Including a memory and a processor. The memory is connected to the processor. The processor is configured to execute one or more computer programs stored in the memory. When the processor executes the one or more computer programs, the computer device implements the method according to any one of claims 1-14.
17. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, and the computer program includes program instructions. When the program instructions are executed by a processor, the processor is caused to execute the method according to any one of claims 1-14.