Data synchronization method and device, equipment and storage medium

Through the total order relationship identification and causal change sequence, the difficulty of data synchronization between different devices and systems is solved, data consistency between data nodes is achieved, and causal and transaction consistency during the synchronization process are ensured.

CN118713784APending Publication Date: 2024-09-27THE FOURTH PARADIGM BEIJING TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410160135.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-02-04
Publication Date
2024-09-27

AI Technical Summary

Technical Problem

There are difficulties in data synchronization between different devices and systems, making data consistency difficult to achieve.

Method used

The total order relationship identifier is used to identify the size relationship between data records, the change data with the largest version number is selected, and the change data is sent in the order of causal changes to ensure the ultimate consistency of data synchronization.

Benefits of technology

It achieves data synchronization between different data nodes, ensures the consistency of the final results, and reduces the complexity of causal consistency and transaction consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118713784A
    Figure CN118713784A
Patent Text Reader

Abstract

The invention relates to a data synchronization method and device between nodes, equipment and a storage medium. Change data from at least one data node is received, the change data is provided with a total order relation identifier, and the total order relation identifier is used for identifying the size relation between the change data of the same data record; if the received change data comprises multiple pieces of change data for the same data record, based on the total order relationship identifier, selecting the change data of which the total order relationship identifier is large from the multiple pieces of change data for the same data record; and updating local data based on the selected change data to obtain data consistent with other data nodes. Therefore, the consistency of final results of data synchronization can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of data synchronization, and in particular to a data synchronization method, device, equipment and storage medium. Background Art

[0002] With the continuous advancement of technologies such as artificial intelligence and the Internet of Things, the interaction between various devices and systems has become more and more common. In practical applications, there is usually a need for data synchronization between different devices and systems, that is, between multiple devices, between multiple systems, and between devices and systems. Data synchronization can maintain data consistency between different devices and systems, that is, it can ensure that different devices and systems use consistent data. How to achieve data synchronization between different devices and systems is a problem that needs to be solved urgently. Summary of the invention

[0003] An object of the present disclosure is to provide a data synchronization solution between nodes.

[0004] According to a first aspect of the present disclosure, a data synchronization method is provided, which is applied to a data node, and includes: receiving change data from at least one data node, wherein the change data is provided with a total order relationship identifier, and the total order relationship identifier is used to identify the size relationship between the change data for the same data record; if the received change data includes multiple copies of change data for the same data record, based on the total order relationship identifier, selecting the change data identified as larger by the total order relationship identifier from the multiple copies of change data for the same data record; and updating local data based on the selected change data to obtain data consistent with other data nodes.

[0005] Optionally, the method further includes: acquiring the changed data to be synchronized; setting a total order relationship identifier for the changed data to be synchronized; and sending the changed data to be synchronized with the total order relationship identifier to the target data node.

[0006] Optionally, acquiring the changed data to be synchronized includes: monitoring a write-ahead log of a database, where the write-ahead log is used to record data changes in the database; in response to monitoring that the write-ahead log records data changes, acquiring the changed data to be synchronized from the write-ahead log.

[0007] Optionally, the method also includes: storing the total order relationship identifier of the data record in the data node in the form of a key-value pair in a preset key-value storage system, the key in the key-value pair is used to represent the primary key field value of the data record corresponding to the total order relationship identifier, and the value in the key-value pair is used to represent the total order relationship identifier; setting the total order relationship identifier for the change data to be synchronized includes: obtaining the total order relationship identifier of the change data to be synchronized from the preset key-value storage system.

[0008] Optionally, the global relationship identifier includes a logical timestamp, and the logical timestamp includes a version number, a first mark and a second mark, the version number is used to represent the version information of the change data, the first mark is used to represent whether the change is initiated by the data node to which the data record corresponding to the change data belongs, and the second mark is used to represent the level of the data node that initiates the change; if the received change data includes multiple change data for the same data record, based on the total order relationship identifier, selecting the change data identified as the largest by the total order relationship identifier from the multiple change data for the same data record includes: if the received change data includes multiple change data for the same data record, selecting the change data with the largest version number from the multiple change data for the same data record; if there are multiple copies of the change data with the largest version number, then selecting the change data initiated by the data node to which the data record belongs; if there are multiple copies of the change data with the largest version number and there is no change data initiated by the data node to which the data record belongs, then selecting the change data initiated by the data node with the highest level.

[0009] Optionally, different data nodes have a predetermined tree-like hierarchical relationship, and any data node except the root data node can only communicate directly with the upper data node and the lower data node of the data node. Then, receiving the change data from multiple data nodes includes: receiving the change data from the upper data node and / or the lower data node.

[0010] Optionally, the change data to be synchronized includes at least two copies; sending the change data to be synchronized with a total order relationship identifier to the target data node includes: determining the causal change order of the change data to be synchronized; sending the change data to be synchronized with a total order relationship identifier to the target data node in sequence according to the determined causal change order, wherein after sending the change data with an earlier causal change order to the target data node, after receiving the confirmation notification from the target data node, sending the next change data to be synchronized according to the causal change order until all the change data to be synchronized are sent.

[0011] Optionally, determining the causal change order corresponding to the change data to be synchronized includes: obtaining a sequence number of the change data to be synchronized in a database write-ahead log, and determining the causal change order of the change data to be synchronized according to the sequence number.

[0012] Optionally, determining the causal change order of the change data to be synchronized according to the serial number includes: writing the change data to be synchronized into a causal buffer, the causal buffer being used to sort the change stream according to the serial number of the change data in the write-ahead log in the causal change order; sending the change data to be synchronized with a total order relationship identifier to the target data node in sequence according to the determined causal change order includes: using a total order broadcaster to send the change data to be synchronized with a total order relationship identifier to the target data node in the causal change order.

[0013] Optionally, the method also includes: filtering the change data to be synchronized to remove the change data from the target data node in the change data; setting a total order relationship identifier for the change data to be synchronized includes: setting a total order relationship identifier for the filtered change data to be synchronized; sending the change data to be synchronized with the total order relationship identifier to the target data node includes: sending the filtered change data to be synchronized with the total order relationship identifier to the target data node.

[0014] Optionally, each change is associated with a transaction, a transaction includes one or more changes, the change data to be synchronized includes change data corresponding to at least one transaction, and the change data of each change is provided with a total order relationship identifier; sending the change data to be synchronized provided with the total order relationship identifier to the target data node includes: combining the change data of multiple changes corresponding to the same transaction, and sending the combined change data to the target data node.

[0015] Optionally, the change data to be synchronized includes change data corresponding to at least two transactions, and there is a causal change order between different transactions; sending the combined change data to the target data node includes: obtaining and determining the causal change order of the at least two transactions; sending the combined change data to the target data node in sequence according to the determined causal change order, wherein after sending the combined data of the transaction with an earlier causal change order to the target data node, after receiving the confirmation notification from the target data node, sending the combined data of the next transaction in the causal change order until the change data of the at least two transactions are sent.

[0016] According to a second aspect of the present disclosure, there is provided a data synchronization device, which is applied to a data node and includes: a receiving module, which is used to receive change data from at least one data node, wherein the change data is provided with a total order relationship identifier, and the total order relationship identifier is used to identify the size relationship between the change data for the same data record; a selection module, which is used to select the change data identified as larger by the total order relationship identifier from the multiple change data for the same data record based on the total order relationship identifier if the received change data includes multiple change data for the same data record; and an update module, which is used to update local data based on the selected change data to obtain data consistent with other data nodes.

[0017] Optionally, the device also includes: an acquisition module for acquiring the change data to be synchronized; a setting module for setting a total order relationship identifier for the change data to be synchronized; and a sending module for sending the change data to be synchronized with the total order relationship identifier to the target data node.

[0018] Optionally, the acquisition module monitors a write-ahead log of a database, where the write-ahead log is used to record data changes in the database, and in response to monitoring that the write-ahead log records data changes, acquires the changed data to be synchronized from the write-ahead log.

[0019] Optionally, the device also includes: a storage module, used to store the total order relationship identifier of the data record in the data node in the form of a key-value pair in a preset key-value storage system, the key in the key-value pair is used to represent the primary key field value of the data record corresponding to the total order relationship identifier, the value in the key-value pair is used to represent the total order relationship identifier, and the setting module obtains the total order relationship identifier of the changed data to be synchronized from the preset key-value storage system.

[0020] Optionally, the global relationship identifier includes a logical timestamp, which includes a version number, a first mark and a second mark, the version number is used to represent the version information of the change data, the first mark is used to represent whether the change is initiated by the data node to which the data record corresponding to the change data belongs, and the second mark is used to represent the level of the data node initiating the change; the selection module is used to select the change data with the largest version number from the multiple change data for the same data record if the received change data includes multiple copies of change data for the same data record, if there are multiple copies of the change data with the largest version number, then select the change data initiated by the data node to which the data record belongs, if there are multiple copies of the change data with the largest version number and there is no change data initiated by the data node to which the data record belongs, then select the change data initiated by the data node with the highest level.

[0021] Optionally, different data nodes have a predetermined tree-like hierarchical relationship, and any data node except the root data node can only directly communicate with the upper data node and lower data node of the data node, and the receiving module receives change data from the upper data node and / or lower data node.

[0022] Optionally, the change data to be synchronized includes at least two copies; the device also includes: a determination module for determining the causal change order of the change data to be synchronized; the sending module sends the change data to be synchronized with a total order relationship identifier to the target data node in sequence according to the determined causal change order, wherein after the change data with an earlier causal change order is sent to the target data node, after receiving the confirmation notification from the target data node, the next change data to be synchronized is sent in the causal change order until all the change data to be synchronized are sent.

[0023] Optionally, the determination module obtains a sequence number of the change data to be synchronized in a database write-ahead log, and determines a causal change order of the change data to be synchronized according to the sequence number.

[0024] Optionally, the determination module writes the change data to be synchronized into a causal buffer, and the causal buffer is used to sort the change stream in a causal change order according to a sequence number of the change data in the write-ahead log; the sending module uses a total order broadcaster to send the change data to be synchronized with a total order relationship identifier to the target data node in a causal change order.

[0025] Optionally, the device also includes: a filtering module, used to filter the change data to be synchronized to remove the change data from the target data node in the change data; the setting module sets a total order relationship identifier for the filtered change data to be synchronized; and the sending module sends the filtered change data to be synchronized with the total order relationship identifier to the target data node.

[0026] Optionally, each change is associated with a transaction, a transaction includes one or more changes, the change data to be synchronized includes change data corresponding to at least one transaction, and the change data of each change is provided with a total order relationship identifier; the sending module combines the change data of multiple changes corresponding to the same transaction, and sends the combined change data to the target data node.

[0027] Optionally, the change data to be synchronized includes change data corresponding to at least two transactions, and there is a causal change order between different transactions; the sending module obtains and determines the causal change order of the at least two transactions, and sends the combined change data to the target data node in sequence according to the determined causal change order, wherein after the combined data of the transaction with an earlier causal change order is sent to the target data node, after receiving the confirmation notification from the target data node, the combined data of the next transaction is sent according to the causal change order until the change data of the at least two transactions are sent.

[0028] According to a third aspect of the present disclosure, a computing device is provided, comprising: a processor; and a memory on which executable codes are stored, and when the executable codes are executed by the processor, the processor executes the method described in the first aspect above.

[0029] According to a fourth aspect of the present disclosure, a computer program product is provided, comprising an executable code, and when the executable code is executed by a processor of an electronic device, the processor is caused to execute the method as described in the first aspect above.

[0030] According to a fifth aspect of the present disclosure, a non-temporary machine-readable storage medium is provided, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor executes the method described in the first aspect above.

[0031] After receiving the change data from at least one data node, if the received change data includes multiple change data for the same data record, the present disclosure selects the change data with the largest change data identified by the total order relationship identifier from the multiple change data for the same data record based on the total order relationship identifier, and updates the local data based on the selected change data to obtain data consistent with other data nodes. Thus, the final result consistency of data synchronization can be achieved under the effect of the total order relationship identifier set in the change data. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] The above and other objects, features and advantages of the present disclosure will become more apparent through a more detailed description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, wherein like reference numerals generally represent like components in the exemplary embodiments of the present disclosure.

[0033] Figure 1 A schematic flow chart of a data synchronization method according to an embodiment of the present disclosure is shown.

[0034] Figure 2 Shows Figure 1 The method shown may also include a flowchart of steps.

[0035] Figure 3 A schematic diagram of an application scenario of the present disclosure is shown.

[0036] Figure 4 A schematic diagram of the architecture principle of the data synchronization method disclosed in the present invention is shown.

[0037] Figure 5 Shows Figure 4 A structural diagram of the functional modules that a data synchronization service may have.

[0038] FIG. 6A to FIG. 6P A schematic diagram showing the working principles of the causal buffer and the FIFO broadcaster is shown.

[0039] Figure 7 A schematic structural diagram of a data synchronization device according to an embodiment of the present disclosure is shown.

[0040] Figure 8 A schematic diagram of the structure of a computing device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0041] Preferred embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings.

[0042] Although preferred embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.

[0043] Those skilled in the art should understand that the terms "first", "second", etc. in the present disclosure are used to distinguish similar objects, rather than to describe a specific order or sequence, and have no additional limiting effect.

[0044] The present disclosure is used to achieve data synchronization between different data nodes. The present disclosure does not limit the network conditions between different data nodes. The network between different data nodes can be stable or unstable (i.e., disconnected), and data synchronization between data nodes can be achieved based on the present disclosure regardless of whether it is stable or not. The data node in the present disclosure can refer to any node that can store data. The data node can specifically be, but is not limited to, a database or a cluster.

[0045] Figure 1 FIG. 1 is a schematic flow chart of a data synchronization method according to an embodiment of the present disclosure. Figure 1 The subject of the method shown may be a data node or a data synchronization device serving a data node. Figure 1 This describes the process of synchronizing data changes on other data nodes to this data node.

[0046] See also Figure 1 , in step S110 , receiving change data from at least one data node.

[0047] A total order relationship identifier is set in the change data. In the disclosed embodiment, the total order relationship identifier is used to identify the size relationship between the change data for the same data record. The total order relationship identifier is an identifier that can compare size relationships. The total order relationship identifier is an identifier that is set and maintained by the data node for the data record and can be recognized by other nodes. The Linux timestamp has a time drift problem, but the total order relationship identifier does not have a time drift problem.

[0048] In step S120, if the received change data includes multiple change data for the same data record, based on the total order relationship identifier, the change data with the largest total order relationship identifier is selected from the multiple change data for the same data record.

[0049] Generally speaking, for multiple copies of change data for the same data record, the larger the total order relationship identifier set in the change data, the newer the change data is, that is, the more recent the change. After receiving multiple copies of change data for the same data record, by selecting the change data with the largest total order relationship identifier, each data node can retain the change data with the largest total order relationship identifier, thereby achieving the final consistency of data synchronization. Final consistency refers to the consistency of the final results of different data nodes after data synchronization.

[0050] In step S130, local data is changed based on the selected changed data to obtain data consistent with other data nodes.

[0051] The change data may reflect the change information for the data record. The change data may include the change operation and / or the change result. The change result is the changed data. Local data refers to the data stored in this data node. Changing the local data based on the selected change data may refer to updating the local data according to the change operation and / or the changed data. In this way, changes occurring in other data nodes may be synchronized to this data node.

[0052] Figure 2 Shows Figure 1 The method shown may also include a flowchart of steps. Figure 2 It describes the synchronization process of synchronizing data changes occurring on this data node to other data nodes (i.e., target data nodes).

[0053] See also Figure 2 , in step S210, the changed data to be synchronized is obtained.

[0054] For changes that occur on this data node, you also need to synchronize the changes to other data nodes. The change data to be synchronized refers to the change data corresponding to the changes that occur on this data node.

[0055] It can be understood that when changes in other data nodes are synchronized to this data node, it is equivalent to that the data of this data node has also changed. Therefore, the table update data corresponding to the change can also be used as the change data to be synchronized and synchronized to other data nodes that need to maintain data consistency.

[0056] Exemplarily, the present disclosure can capture database changes in real time by monitoring the Write-Ahead Logging (WAL) of the database in the data node, that is, obtain the change data to be synchronized.

[0057] That is, when executing step S210, the write-ahead log of the database may be monitored, and in response to monitoring that the write-ahead log records data changes, the changed data to be synchronized is obtained from the write-ahead log.

[0058] The database may be, but is not limited to, a database of the type Postgres, MySQL, Oracle, etc. Postgres may also be called PostgreSQL, and Postgres, MySQL, and Oracle are all relational database management systems.

[0059] The write-ahead log is used to record data changes in the database. In a database system that uses a write-ahead log, data changes are first written to the write-ahead log before the data in the database is changed.

[0060] By monitoring the write-ahead log, data changes in this data node can be synchronized to other data nodes without affecting the normal performance of the database. And by adopting this event-driven data synchronization mechanism, all changes can be synchronized with other data nodes in real time, minimizing latency.

[0061] In step S220, a total order relation identifier is set for the changed data to be synchronized.

[0062] The complete state of a data record in this data node (i.e., in the local data) can be regarded as consisting of the data record content and the total order relationship identifier. In order to achieve zero intrusion on the data table schema, the logical timestamp of the data record in this data node can be stored in a preset key-value storage system in the form of a key-value pair. The key (key) in the key-value pair is used to represent the primary key field value of the data record corresponding to the total order relationship identifier, and the value (value) in the key-value pair is used to represent the total order relationship identifier. When executing step S220, the total order relationship identifier of the changed data to be synchronized can be obtained from the preset key-value storage system.

[0063] In step S230, the changed data to be synchronized and provided with a total order relationship identifier is sent to the target data node.

[0064] The target data node refers to the data node that needs to synchronize data with the current data node. For example, the target data node can be all data nodes that can communicate directly with the current data node. After receiving the changed data, the target data node can Figure 1 The method flow shown updates local data.

[0065] The change data to be synchronized obtained in step S210 may include at least two copies. When executing step S220, the causal change order of the change data to be synchronized may be determined first. The causal change order refers to the change order of the causal relationship between the change data to be synchronized.

[0066] For example, comments in a circle of friends and replies to the comments constitute a causal relationship. The causal change order of the two pieces of data, comments and replies, is that comments come first and replies come later. In the present disclosure, if it is necessary to synchronize these two pieces of data, it is necessary to first determine the causal change order of the two pieces of data so that the data can be synchronized according to the causal change order later.

[0067] Exemplarily, the sequence number (LSN) of the change data to be synchronized in the database write-ahead log may be obtained, and the causal change order of the change data to be synchronized may be determined according to the sequence number.

[0068] After determining the causal change order of the change data to be synchronized, the change data to be synchronized with a total order relationship identifier can be sent to the target data node in sequence according to the determined causal change order. Wherein, in the case of multiple target data nodes, the operation of sending the change data to be synchronized to multiple target data nodes can be performed in parallel. In addition, for each target data node, after sending the change data with an earlier causal change order to the target data node, after receiving the confirmation notification of the target data node, the next change data to be synchronized is sent to the target data node according to the causal change order until all the change data to be synchronized are sent. In this way, causal consistency can be ensured during the synchronization process. Causal consistency means that the change data received by the data node conforms to the causal change order, that is, the order of operations with a causal relationship is guaranteed.

[0069] Similarly, when the data node receives the change data from other data nodes, the other data nodes may also send the change data in the order of causal changes.

[0070] Exemplarily, causal consistency can be achieved through a causal buffer and a total order broadcaster. Specifically, the change data to be synchronized can be written into the causal buffer first, and the causal buffer is used to sort the change stream according to the causal change order according to the sequence number of the change data in the pre-write log; then the total order broadcaster can be used to send the change data to be synchronized with the total order relationship identifier to the target data node according to the causal change order.

[0071] In some database systems, each change can be associated with a transaction. A transaction can include one or more changes. The change data to be synchronized can include change data corresponding to at least one transaction, and each change data is provided with a total order relation identifier. When executing step S130, the change data of multiple changes corresponding to the same transaction can be combined, and the combined change data can be sent to the target data node.

[0072] That is, multiple change data belonging to the same transaction can be combined and sent to the target data node in units of transactions, so that the consistency of the transaction can be guaranteed. That is, either multiple change data belonging to the same transaction are sent successfully, or multiple change data belonging to the same transaction are not sent.

[0073] The change data to be synchronized obtained in step S210 may include change data corresponding to at least two transactions, and different transactions may have a causal change order. When sending the combined change data to the target data node, the causal change order of the at least two transactions can be determined, and the combined change data is sent to the target data node in sequence according to the determined causal change order, wherein after sending the combined data of the transaction with the earlier causal change order to the target data node, after receiving the confirmation notification from the target data node, the combined data of the next transaction is sent according to the causal change order until the change data of all transactions are sent. In this way, the causal consistency between transactions can be guaranteed.

[0074] The change data to be synchronized obtained in step S210 may come from other data nodes. Before sending the change data to the target data node, the change data can also be filtered to remove the change data from the target data node. The change data from the target data node is obviously the change data that does not need to be sent to the target data node. Exemplarily, after executing step S210, the change data to be synchronized can be filtered to remove the change data from the target data node in the change data; when executing step S220, a total order relationship identifier can be set for the filtered change data to be synchronized; when executing step S230, the filtered change data to be synchronized with the total order relationship identifier can be sent to the target data node. In addition, in the case of multiple target data nodes, the change data to be synchronized can also be filtered for each target data node after step S220 to remove the change data from the target data node, thereby obtaining the change data to be synchronized applicable to each target data node.

[0075] So far combined Figure 1 , Figure 2 The process of how to synchronize changes of other data nodes to the current data node and how to synchronize changes of the current data node to other data nodes is illustrated.

[0076] One application scenario of the present disclosure is the synchronization between nodes having a tree-like hierarchical relationship. The following is a further exemplary explanation of the details involved in the present disclosure under this application scenario. In this application scenario, different data nodes have a predetermined tree-like hierarchical relationship. Any data node except the root data node can only communicate directly with the upper-level data node and the lower-level data node of the data node. That is, any data node can only communicate with the adjacent data nodes of the data node. Among them, the upper-level data node refers to the data node that is adjacent to the data node and belongs to the parent node of the data node in the tree-like hierarchical relationship, that is, the upper-level data node; correspondingly, the lower-level data node refers to the data node that is adjacent to the data node and belongs to the child node of the data node in the tree-like hierarchical relationship, that is, the lower-level data node.

[0077] Figure 3 A tree-like hierarchical relationship diagram in the application scenario is shown.

[0078] See also Figure 3 , a data node can be connected to one parent data node and two child data nodes at the same time. The parent data node is the data node of the previous level, and the child data node is the data node of the next level. A data node has at least one parent data node or one child data node.

[0079] Specifically, the global relationship identifier may include a logical timestamp. The logical timestamp includes a version number, a first mark, and a second mark. The version number is used to represent the version information of the changed data. The first mark is used to represent whether the change is initiated by the data node to which the data record corresponding to the changed data belongs. The second mark is used to represent the level of the data node that initiated the change, which may specifically be a relative level.

[0080] The data node to which the data record belongs may refer to the data node to which the device associated with the data record (i.e., the device that generates the data record) belongs. In the AIoT (Artificial Intelligence Internet of Things) scenario, each data node can represent a cluster. As an important infrastructure in AIoT, the cluster can support the development and deployment of AIoT applications. For example, the cluster can provide powerful computing and storage capabilities to process and analyze large amounts of data. The cluster can also provide high availability and scalability to meet the growing needs of AIoT applications. Each cluster can manage one or more devices (such as edge devices). The data node to which the data record belongs is the cluster to which the device corresponding to the data record belongs.

[0081] When executing step S120, if the received change data includes multiple copies of change data for the same data record, the change data with the largest version number can be preferentially selected from the multiple copies of change data for the same data record; if there are multiple copies of the change data with the largest version number, the change data initiated by the data node to which the data record belongs can be further selected; if there are multiple copies of the change data with the largest version number and there is no change data initiated by the data node to which the data record belongs, the change data initiated by the data node with the highest level can be selected.

[0082] Therefore, for the data synchronization scenario between multiple data nodes with a hierarchical relationship (such as a multi-cluster environment with a hierarchical management relationship), the present disclosure defines a logical timestamp including a version number, a first mark, and a second mark, and designs corresponding conflict handling logic (i.e., the selection logic for multiple copies of changed data for the same data record) based on this, so that the final consistency of data synchronization can be achieved in a manner that conforms to this tree-like hierarchical relationship.

[0083] The network may be unstable or disconnected between data nodes, which may result in the change data received from other data nodes not being valid change data for this data node. That is, the received change data may contain changes that do not need to be processed by this data node. Therefore, after receiving the change data (i.e., after step S110 and before step S120), or after selecting the change data for the same data record from different data nodes (i.e., after step S120), the received change data or the selected change data can be filtered according to the version number of the data record in this data node to remove the change data that does not meet the requirements. Change data that does not meet the requirements is change data that does not need to be processed by the local node. Whether the change data is change data that does not meet the requirements can be determined by comparing the logical timestamp in the change data with the logical timestamp of the data record corresponding to the change data in this data node. Change data that does not meet the requirements may include: change data with a version number that is smaller than the version number of the data record in this data node; change data with a version number equal to the version number of the data record in this data node, and initiated by a node that is not the node to which the data record belongs and is relatively lower in level (i.e., lower in level than this node).

[0084] The complete state of a data record in a data node can be considered to consist of the data record content and the logical timestamp. In order to achieve zero intrusion on the data table schema, the logical timestamp of the data record in this data node can be stored in the key-value storage system in the form of a key-value pair. The key in the key-value pair is used to represent the primary key field value of the data record corresponding to the logical timestamp, and the value in the key-value pair is used to represent the logical timestamp.

[0085] The logical timestamp of the data record is the same or similar to the logical timestamp in the change data mentioned above, and also includes three fields, namely, the version number, the first mark and the second mark. The logical timestamp of the data record may refer to a logical timestamp determined based on the change data on which the current data record is generated. The change data on which the current data record is generated may come from other data nodes or from this data node (i.e., the change generated by this data node). If the change data on which the current data record is generated comes from other data nodes, the logical timestamp of the data record may be set based on the logical timestamp in the received change data, for example, the version number and the first mark may be kept unchanged and only the second mark in the received change logical timestamp may be updated, and the updated logical timestamp may be set as the logical timestamp of the current data record. If the change data on which the current data record is generated comes from this data node, the logical timestamp may be reset according to the definition of the logical timestamp. Among them, for changes from this data node, the version number is increased by one each time this node updates the data record.

[0086] Figure 4 A schematic diagram of an architectural principle of the data synchronization method disclosed in the present invention is shown.

[0087] See also Figure 4 , the present disclosure can use the database structure of "database + write-ahead log" to design a data synchronization service to achieve data synchronization between different data nodes. The database can be a database that supports add, delete, modify, and search operations, such as Postgres, MySQL, and Oracle, but is not limited to it. Write-Ahead Logging (WAL) is an operation log of the database that records operations on data in the database. The log is written before the data is written. That is, operations on data in the database will be recorded by WAL first, and then the data in the database will be changed.

[0088] A data synchronization service can be deployed for each data node. Under the action of the data synchronization services deployed for different data nodes, data synchronization between different data nodes can be achieved. The data synchronization service can achieve data synchronization between different data nodes by executing the data synchronization method disclosed in the present invention.

[0089] In summary, on the one hand, the data synchronization service can listen to the write-ahead log to obtain change events, and send the change events to other data nodes that need to be synchronized, so as to synchronize the changes occurring in this data node to other data nodes; on the other hand, the data synchronization service can also receive change events sent by other data nodes, and process the received change events to synchronize the changes occurring in other data nodes to this data node.

[0090] Figure 5 Shows Figure 4 A structural diagram of the functional modules that a data synchronization service may have.

[0091] See also Figure 5, the WAL monitoring module can be responsible for monitoring the DML (Data Manipulation Language) changes of the database WAL. The DML changes of the database WAL mean that when performing DML operations, the database will first record these changes in the WAL log, and then make actual data changes. DML (Data Manipulation Language) is a data manipulation language used to operate on the data in the database, such as query, insert, update and delete. DML changes refer to changes to the data in the database, such as insert, update or delete operations, rather than changes to the database structure. The WAL monitoring module is an event-driven mechanism. In response to the changes monitored by the WAL monitoring module, a data synchronization process that synchronizes the changes to other nodes can be triggered. By using the database's WAL mechanism to implement real-time monitoring of data change operations, the normal use of the database can be monitored while monitoring data change operations; and compared with the polling mechanism, the real-time response capability can be improved.

[0092] The WAL monitoring module can output the monitored changes in the form of transactions. A transaction may include one or more changes. The transaction processing module can set a logical timestamp for the transaction output by the WAL monitoring module, such as setting a logical timestamp for each change in the transaction. Each change corresponds to a data record, and the logical timestamp can be recorded in a logical timestamp database. The logical timestamp database corresponds to the key-value storage system mentioned above. For the logical timestamp database, please refer to the description of the key-value storage system above.

[0093] The transaction splitting module can split a transaction into changes that make up the transaction. A transaction can include multiple changes, and the transaction splitting module can group multiple changes belonging to the same transaction into one change. Thus, each change in the final change stream corresponds to all changes under one transaction. The changes in the change stream can have a causal change order, and the causal change order between changes in the change stream can be determined according to the causal change order between transactions.

[0094] A FIFO (First Input First Output) broadcaster can broadcast a change stream to N change streams in full order, where N is equal to the number of adjacent data nodes (i.e., the target data nodes mentioned above).

[0095] The duplicate change filtering module may also filter the change stream corresponding to each adjacent data node to remove duplicate changes to the adjacent data node, that is, changes from the adjacent data node.

[0096] The sending module can send the filtered change stream to the corresponding adjacent data nodes.

[0097] The receiving module can also receive changes sent by adjacent data nodes, such as obtaining changes of adjacent data nodes through GRPC requests.

[0098] The change processing module can determine whether the logical timestamp of the received change is qualified based on the logical timestamp data stored in the logical timestamp database, and mark the unqualified changes as unqualified. The change processing module can process changes from different adjacent data nodes in parallel. The invalid change filtering module can filter all unqualified changes. The judgment logic of whether the change is qualified or not can be found in the relevant description above. The filtered change stream from different adjacent data nodes may have multiple changes corresponding to the same data record. For multiple changes received for the same data record, the selection module can select a suitable change from them. The selection logic of the selection module can be found in the relevant description above. The writing module can write the final selected changes to the database (specifically, write to WAL first, and then write to the database). The writing module can be implemented as a single thread to ensure that there is no disorder.

[0099] The present disclosure can combine the order-preserving characteristics of the database WAL, and utilize a causal buffer and a fully-ordered broadcaster (FIFO broadcaster) so that when a change stream is sent to a corresponding target data node, the causal consistency in the stream can be guaranteed under high concurrency. Specifically, when a change stream is sent to a target data node, the change stream can be written into a causal buffer, and the causal buffer is used to sort the change stream in chronological order according to the sequence number of the changes in the change stream in the write-ahead log; then the changes in the change stream are sent to the target data node in order using a fully-ordered broadcaster.

[0100] The WAL database records the changes and sequence number (LSN) of each data record. When a record in the database is received by all neighboring nodes, the LSN of the data record is updated and persisted. Due to the characteristics of the WAL database, each data record is marked in causal order, so the causal relationship between each data record can be guaranteed.

[0101] FIFO broadcaster is a total order broadcaster. Causal buffer and FIFO broadcaster can ensure causal order in the stream under high concurrency. The change stream to be sent can be stored in the causal buffer first. For the working principle of causal buffer and FIFO broadcaster, please refer to FIG. 6A to FIG. 6P Description.

[0102] See also FIG. 6A to FIG. 6G , the first data ( Fig. 6AAfter ①) in is input into the causal buffer, when the first data is output to the node in the AIOT network, the causal buffer marks the status of the first data as completed (done: ①). Similarly, when the second data ( Figure 6C After the second piece of data is input into the causal buffer, when the second piece of data is output to a node in the AIOT network, the causal buffer marks the status of the second piece of data as completed after the first piece of data (done: ①②). Fig. 6E As shown in the figure, at this time, the fourth data is input into the causal buffer, but the fourth data has not yet been sent to the node in the AIOT scenario, and the third data is input into the causal buffer. At this time, the causal buffer caches the fourth data in the Buffer ( Fig. 6F When the third and fourth data need to be sent to other nodes of the AIOT network, the causal relationship can be obtained through the labels (such as LSN) of the third and fourth data, and the order of the data can be arranged according to the causal relationship before being sent to the nodes of the AIOT network.

[0103] like Figure 6H As shown in the figure, there are three pieces of data that need to be synchronized to all nodes in the AIOT network. Fig.6I As shown, after the first data is input into the FIFO broadcaster, when the first node in the AIOT network ( Fig.6I The network is in good condition, while the second node ( Fig.6I When the network status of the output node on the lower right side of the figure fails, the FIFO broadcaster broadcasts the first data to the first node, then the consumption status of the first node is recorded as having consumed the first data, while the consumption status of the second node is recorded as empty (i.e., no data has been consumed).

[0104] like Figure 6J As shown in the figure, after the second data is input into the FIFO broadcaster, since the second node has not consumed the first data, the FIFO broadcaster caches the first data in its own cache queue. Figure 6J The network is in good condition, while the second node ( Figure 6J When the network status of the output node on the lower right side of the figure fails, the FIFO broadcaster broadcasts the second data to the first node, then the consumption status record of the first node is that the first data and the second data have been consumed, while the consumption status record of the second node is still recorded as empty (i.e., no data has been consumed).

[0105] like Figure 6KAs shown in the figure, after the third data is input into the FIFO broadcaster, since the second node has not consumed the second data, the FIFO broadcaster also caches the second data in its own cache queue. At this time, the cache queue contains the first data and the second data. When the first node in the AIOT network ( Figure 6K The network is in good condition, while the second node ( Figure 6K When the network status of the output node on the lower right side of the figure fails, the FIFO broadcaster broadcasts the third data to the first node, and the consumption status record of the first node is that the first data, the second data, and the third data have been consumed, while the consumption status record of the second node is still recorded as empty (that is, no data has been consumed). Figure 6L As shown, since the second node network has not consumed the third data yet, the FIFO broadcaster also caches the third data in its own cache queue. At this time, the cache queue contains the first data, the second data and the third data, and so on.

[0106] like Figures 6M to 6O As shown, when the network status of the second node is restored, the FIFO buffer sends the data cached in the cache queue to the second node in sequence, and each time a piece of data is sent, the data is removed from the data in the cache queue.

[0107] like Figure 6P As shown in the figure, all transactions monitored from the WAL can be processed concurrently, and the causal buffer can ensure causality. Then the transactions can be sent to the corresponding neighboring nodes one by one in order by total order broadcast. After each transaction is sent to all neighboring nodes, the LSN pointer can be updated to send the next transaction.

[0108] Different from the data synchronization mechanism based on timer / timing trigger, the present disclosure adopts an event-driven data synchronization mechanism. The changes on the current node can be synchronized with the adjacent nodes in real time, thereby minimizing the delay. Causal consistency can be guaranteed in high concurrency situations through a full-order broadcaster and a causal cache, combined with the characteristics of the database pre-write log. The present disclosure does not need to record the progress of adjacent nodes, and can obtain relevant information through communication processes such as data synchronization with adjacent nodes, and does not require full table transfer. When the process crashes and restarts, it can be replayed from the latest LSN. The idempotence of the merge operation ensures that the playback will not affect consistency and accuracy.

[0109] The data synchronization method disclosed in the present invention may also be implemented as a data synchronization device. Figure 7 The structure diagram of the data synchronization device according to an embodiment of the present disclosure is shown. The functional units of the data synchronization device can be implemented by hardware, software, or a combination of hardware and software that implements the principles of the present disclosure. It can be understood by those skilled in the art that Figure 7The functional units described can be combined or divided into sub-units to implement the principles of the above invention. Therefore, the description herein can support any possible combination, division, or further limitation of the functional units described herein. The following is a brief description of the functional units that the data synchronization device can have and the operations that each functional unit can perform. For the details involved, please refer to the relevant description above, which will not be repeated here.

[0110] See also Figure 7 The data synchronization device 700 may include a receiving module 710 , a selecting module 720 and an updating module 730 .

[0111] The receiving module 710 is used to receive the change data from at least one data node, and the change data is provided with a total order relationship identifier, which is used to identify the size relationship between the change data for the same data record. The selecting module 720 is used to select the change data with the total order relationship identifier as the largest one from the multiple change data for the same data record if the received change data includes multiple change data for the same data record. The updating module 730 is used to update the local data based on the selected change data to obtain data consistent with other data nodes.

[0112] The global relationship identifier may include a logical timestamp, and the logical timestamp includes a version number, a first mark, and a second mark. The version number is used to represent the version information of the changed data, the first mark is used to represent whether the change is initiated by the data node to which the data record corresponding to the changed data belongs, and the second mark is used to represent the level of the data node that initiated the change. The selection module 720 can be used to select the change data with the largest version number from the multiple change data for the same data record if the received change data includes multiple copies of change data for the same data record. If there are multiple copies of the change data with the largest version number, the change data initiated by the data node to which the data record belongs is selected. If there are multiple copies of the change data with the largest version number and there is no change data initiated by the data node to which the data record belongs, the change data initiated by the data node with the highest level is selected.

[0113] Different data nodes may have a predetermined tree-like hierarchical relationship. Any data node except the root data node can only directly communicate with the upper data node and lower data node of the data node. The receiving module receives change data from the upper data node and / or lower data node.

[0114] The data synchronization device 700 may also include an acquisition module, a setting module, and a sending module. The acquisition module is used to acquire the change data to be synchronized; the setting module is used to set a total order relationship identifier for the change data to be synchronized; and the sending module is used to send the change data to be synchronized with the total order relationship identifier to the target data node. Exemplarily, the acquisition module can monitor the write-ahead log of the database, which is used to record the data changes of the database, and in response to monitoring that the write-ahead log records the data changes, the change data to be synchronized is acquired from the write-ahead log.

[0115] The data synchronization device 700 may further include a storage module. The storage module is used to store the total order relationship identifier of the data record in the data node in the form of a key-value pair in a preset key-value storage system, the key in the key-value pair is used to represent the primary key field value of the data record corresponding to the total order relationship identifier, and the value in the key-value pair is used to represent the total order relationship identifier. The setting module can obtain the total order relationship identifier of the change data to be synchronized from the preset key-value storage system.

[0116] The changed data to be synchronized may include at least two copies; the data synchronization device 700 may also include a determination module. The determination module is used to determine the causal change order of the changed data to be synchronized. The sending module may send the changed data to be synchronized with a total order relationship identifier to the target data node in sequence according to the determined causal change order, wherein after sending the change data with the first causal change order to the target data node, after receiving the confirmation notification from the target data node, the next change data to be synchronized is sent in the causal change order until all the change data to be synchronized are sent.

[0117] Exemplarily, the determination module can obtain the sequence number of the change data to be synchronized in the database pre-write log, and determine the causal change order of the change data to be synchronized according to the sequence number. The determination module can write the change data to be synchronized into a causal buffer, and the causal buffer is used to sort the change stream according to the causal change order according to the sequence number of the change data in the pre-write log; the sending module uses a full-order broadcaster to send the change data to be synchronized with a full-order relationship identifier to the target data node according to the causal change order.

[0118] The data synchronization device 700 may further include a filtering module. The filtering module is used to filter the change data to be synchronized to remove the change data from the target data node in the change data; the setting module sets a total order relationship identifier for the filtered change data to be synchronized; and the sending module sends the filtered change data to be synchronized with the total order relationship identifier to the target data node.

[0119] Each change is associated with a transaction, and a transaction includes one or more changes. The change data to be synchronized includes the change data corresponding to at least one transaction, and the change data of each change is set with a total order relationship identifier; the sending module combines the change data of multiple changes corresponding to the same transaction, and sends the combined change data to the target data node.

[0120] The change data to be synchronized may include change data corresponding to at least two transactions, and there is a causal change order between different transactions. The sending module can obtain and determine the causal change order of at least two transactions, and send the combined change data to the target data node in sequence according to the determined causal change order, wherein after sending the combined data of the transaction with the earlier causal change order to the target data node, after receiving the confirmation notification from the target data node, the combined data of the next transaction is sent in the causal change order until the change data of at least two transactions are sent.

[0121] Figure 8 A schematic diagram of the structure of a computing device that can be used to implement the above-mentioned data synchronization method according to an embodiment of the present disclosure is shown.

[0122] See also Figure 8 , the computing device 800 includes a memory 810 and a processor 820 .

[0123] The processor 820 may be a multi-core processor or may include multiple processors. In some embodiments, the processor 820 may include a general-purpose main processor and one or more special coprocessors, such as a graphics processing unit (GPU), a digital signal processor (DSP), etc. In some embodiments, the processor 820 may be implemented using a customized circuit, such as an application-specific integrated circuit (ASIC) or a field programmable gate array (FPGA).

[0124] The memory 810 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, ROM can store static data or instructions required by the processor 820 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 810 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 810 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (e.g., DVD-ROM, double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (e.g., SD card, mini SD card, Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and transient electronic signals transmitted wirelessly or wired.

[0125] The memory 810 stores executable codes, and when the executable codes are processed by the processor 820 , the processor 820 can execute the data synchronization method mentioned above.

[0126] The data synchronization method, apparatus and device according to the present disclosure have been described above in detail with reference to the accompanying drawings.

[0127] In addition, the method according to the present disclosure may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing the above steps defined in the above method of the present disclosure.

[0128] Alternatively, the present disclosure may also be implemented as a non-temporary machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium) on which executable code (or computer program, or computer instruction code) is stored. When the executable code (or computer program, or computer instruction code) is executed by a processor of an electronic device (or computing device, server, etc.), the processor executes the various steps of the above-mentioned method according to the present disclosure.

[0129] Those skilled in the art will further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or a combination of both.

[0130] The flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the system and method according to multiple embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0131] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A data synchronization method, applied to a data node, characterized in that: include: Receiving change data from at least one data node, wherein the change data is provided with a total order relationship identifier, and the total order relationship identifier is used to identify the size relationship between the change data for the same data record; If the received change data includes multiple change data for the same data record, based on the total order relation identifier, select the change data with the largest change identifier from the multiple change data for the same data record; Update local data based on the selected changed data to obtain data consistent with other data nodes.

2. The method according to claim 1, characterized in that The method further comprises: Get the changed data to be synchronized; Setting a total order relation identifier for the changed data to be synchronized; The changed data to be synchronized and provided with a total order relation identifier is sent to the target data node.

3. The method according to claim 2, characterized in that The obtaining of the change data to be synchronized includes: Monitor the database's write-ahead log, which is used to record data changes in the database; In response to monitoring that the write-ahead log records a data change, the change data to be synchronized is obtained from the write-ahead log.

4. The method according to any one of claims 1 to 3, characterized in that: The global relationship identifier includes a logical timestamp, and the logical timestamp includes a version number, a first mark, and a second mark. The version number is used to represent the version information of the changed data. The first mark is used to represent whether the change is initiated by the data node to which the data record corresponding to the changed data belongs. The second mark is used to represent the level of the data node that initiates the change. If the received change data includes multiple change data for the same data record, based on the total order relation identifier, selecting the change data with a larger total order relation identifier from the multiple change data for the same data record includes: If the received change data includes multiple copies of change data for the same data record, the change data with the largest version number is selected from the multiple copies of change data for the same data record. If there are multiple copies of the change data with the largest version number, the change data initiated by the data node to which the data record belongs is selected. If there are multiple copies of the change data with the largest version number and there is no change data initiated by the data node to which the data record belongs, the change data initiated by the data node with the highest level is selected.

5. The method according to claim 4, characterized in that There is a predetermined tree-like hierarchical relationship between different data nodes, and any data node except the root data node can only directly communicate with the upper-level data node and the lower-level data node of the data node. Then, receiving the change data from multiple data nodes includes: Receive change data from upper-level data nodes and / or lower-level data nodes.

6. The method according to claim 2, characterized in that The changed data to be synchronized includes at least two copies; The sending the change data to be synchronized and provided with the total order relation identifier to the target data node comprises: Determining a causal change order of the change data to be synchronized; According to the determined causal change order, the change data to be synchronized with the total order relationship identifier are sent to the target data node in sequence, wherein the change data with the earlier causal change order is sent to the target data node, and after receiving the confirmation notification from the target data node, the next change data to be synchronized is sent according to the causal change order until all the change data to be synchronized are sent.

7. The method according to claim 6, characterized in that Determining the causal change order corresponding to the changed data to be synchronized includes: Obtain a sequence number of the change data to be synchronized in the database write-ahead log, and determine a causal change order of the change data to be synchronized according to the sequence number.

8. A data synchronization device, applied to a data node, characterized in that: include: A receiving module, used for receiving change data from at least one data node, wherein the change data is provided with a total order relationship identifier, and the total order relationship identifier is used for identifying the size relationship between the change data for the same data record; A selection module, configured to select, if the received change data includes multiple change data for the same data record, the change data with the largest change data identified by the total order relation identifier from the multiple change data for the same data record based on the total order relation identifier; The update module is used to update local data based on the selected changed data to obtain data consistent with other data nodes.

9. A computing device comprising: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 7.

10. A non-transitory machine-readable storage medium having executable codes stored thereon, which, when executed by a processor of an electronic device, causes the processor to execute the method according to any one of claims 1 to 7.