Data synchronization method, data node, block chain and medium
Through blockchain technology and consensus mechanism, the problem of data synchronization between multiple shared data nodes is solved, data synchronization and filtering screening without master-slave relationships is realized, and the needs of multi-data sharing scenarios are met.
Patent Information
- Application Number
- CN202310789199.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-29
- Publication Date
- 2024-12-31
AI Technical Summary
The prior art is difficult to effectively synchronize data between multiple shared data nodes, especially in the absence of master-slave relationships, resulting in data inconsistency.
By introducing blockchain technology, a consensus mechanism is used to judge data changes and form a data synchronization strategy to ensure data synchronization between multiple data nodes, realize data synchronous synchronization, and avoid the limitations of master-slave relationships.
The data synchronization between multiple data nodes is achieved, which meets the needs of more data sharing scenarios, provides filtering and screening capabilities for data changes, and improves the efficiency of data updates.
Smart Images

Figure CN119226394A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure at least relates to the field of data technology, and in particular to a data synchronization method, a data node, a blockchain, and a computer-readable storage medium. Background Art
[0002] In applications such as enterprise data services, there is a demand for data to be used in multiple places. To meet this demand, multiple shared data nodes may be set up so that each node can quickly provide data that meets local usage needs. In the process of local data use, the data may be modified. When there are multiple application scenarios sharing a data indicator, this may cause data inconsistency between shared data nodes.
[0003] In some cases, data synchronization solutions can achieve data unification between master and slave data nodes, that is, through master-slave data synchronization, the data of the slave data node can be guaranteed to be consistent with the master data node. However, there is a relatively clear master-slave relationship between the data nodes. The slave data node can only passively synchronize the data of the master data node, and there is also a lack of a process for filtering and screening the master data. Therefore, its application has certain limitations.
[0004] It can be seen that there is currently no good technical solution for how to achieve data synchronization between shared data nodes.
[0005] Public Content
[0006] The technical problem to be solved by the present disclosure is to provide a data synchronization method, a data node, a blockchain and a computer-readable storage medium in response to the above-mentioned deficiencies in the prior art, so as to solve the problem of how to achieve data synchronization between shared data nodes.
[0007] In a first aspect, the present disclosure provides a data synchronization method, applied to a data node, the method comprising:
[0008] Obtain data synchronization strategy from blockchain. Data synchronization strategy is formed by blockchain in response to data changes of data nodes and judging whether to agree with data changes according to consensus mechanism. Consensus mechanism is pre-set on blockchain by multiple data nodes that collaborate to achieve data synchronization.
[0009] According to the data synchronization strategy and the operation records corresponding to the data changes, the data synchronization of multiple data nodes that collaborate to achieve data synchronization is completed.
[0010] In a second aspect, the present disclosure provides a data synchronization method, applied to a blockchain, the method comprising:
[0011] In response to data changes at data nodes, a data synchronization strategy is formed based on a consensus mechanism to determine whether the data changes are agreed upon. The consensus mechanism is pre-set on the blockchain by multiple data nodes that collaborate to achieve data synchronization.
[0012] A data synchronization strategy is provided to the data nodes, so that the data nodes complete data synchronization of multiple data nodes that collaboratively implement data synchronization according to the data synchronization strategy and the operation records corresponding to the data changes.
[0013] In a third aspect, the present disclosure provides a data node, including:
[0014] A synchronization strategy acquisition module is used to obtain a data synchronization strategy from the blockchain. The data synchronization strategy is formed by the blockchain in response to the data changes of the data nodes and judging whether the data changes are agreed according to the consensus mechanism. The consensus mechanism is pre-set on the blockchain by multiple data nodes that collaborate to achieve data synchronization.
[0015] The synchronization strategy execution module is connected to the synchronization strategy acquisition module, and is used to complete the data synchronization of multiple data nodes that collaboratively realize data synchronization according to the data synchronization strategy and the operation records corresponding to the data changes.
[0016] In a fourth aspect, the present disclosure provides a blockchain, including:
[0017] A synchronization strategy forming module is used to respond to data changes of data nodes and form a data synchronization strategy based on the consensus mechanism to determine whether to agree with the data changes. The consensus mechanism is pre-set on the blockchain by multiple data nodes that collaborate to achieve data synchronization;
[0018] The synchronization strategy providing module is connected to the synchronization strategy forming module and is used to provide data synchronization strategies to data nodes so that the data nodes can complete data synchronization of multiple data nodes that collaboratively realize data synchronization according to the data synchronization strategies and operation records corresponding to data changes.
[0019] In a fifth aspect, the present disclosure provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the data synchronization method as described above is implemented.
[0020] The present disclosure provides a data synchronization method, a data node, a blockchain, and a computer-readable storage medium. The blockchain is introduced between multiple data nodes that share data. A consensus mechanism is collaboratively preset on the blockchain through these data nodes. When data changes occur in any of the nodes, it is necessary to determine whether the data change is agreed to through the consensus mechanism preset on the blockchain. The blockchain provides a data synchronization strategy based on the determination result of whether the data change is agreed to. The data on these multiple data nodes can always be synchronized through the data synchronization strategy. There is no pre-set master-slave relationship between these multiple data nodes, and data synchronization can be controlled through the consensus mechanism, which can meet the needs of data sharing in more data sharing scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 is a flow chart of a data synchronization method according to an embodiment of the present disclosure;
[0022] Figure 2 is a structural diagram of a data synchronization system according to an embodiment of the present disclosure;
[0023] Figure 3 is a flow chart of another data synchronization method according to an embodiment of the present disclosure;
[0024] Figure 4 is a structural diagram of a data node according to an embodiment of the present disclosure;
[0025] Figure 5 It is a schematic diagram of the structure of a blockchain according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the technical solution of the present disclosure, the embodiments of the present disclosure will be further described in detail below with reference to the accompanying drawings.
[0027] It should be understood that the specific embodiments and drawings described herein are only used to explain the present disclosure rather than to limit the present disclosure.
[0028] It can be understood that, in the absence of conflict, the various embodiments of the present disclosure and the various features in the embodiments can be combined with each other.
[0029] It can be understood that, for the convenience of description, the drawings of the present disclosure only show parts related to the present disclosure, while parts irrelevant to the present disclosure are not shown in the drawings.
[0030] It can be understood that each unit and module involved in the embodiments of the present disclosure may correspond to only one physical structure, or may be composed of multiple physical structures, or multiple units and modules may be integrated into one physical structure.
[0031] It will be understood that, in the absence of conflict, the functions and steps marked in the flowcharts and block diagrams of the present disclosure may occur in an order different from that marked in the drawings.
[0032] It is understood that the flowcharts and block diagrams of the present disclosure illustrate the possible architectures, functions, and operations of the systems, devices, equipment, and methods according to the various embodiments of the present disclosure. Each box in the flowchart or block diagram may represent a unit, module, program segment, or code, which contains executable instructions for implementing the specified functions. Moreover, each box or combination of boxes in the block diagram and flowchart may be implemented by a hardware-based system that implements the specified functions, or may be implemented by a combination of hardware and computer instructions.
[0033] It can be understood that the units and modules involved in the embodiments of the present disclosure can be implemented by software or hardware, for example, the units and modules can be located in a processor.
[0034] Embodiment 1:
[0035] like Figure 1 As shown, the present disclosure provides a data synchronization method, which is applied to Figure 2 For any data node shown, the method comprises:
[0036] S11. Obtaining a data synchronization strategy from the blockchain. The data synchronization strategy is formed by the blockchain in response to data changes of data nodes and judging whether to agree with the data changes according to a consensus mechanism. The consensus mechanism is pre-set on the blockchain by multiple data nodes that collaborate to achieve data synchronization.
[0037] S12. According to the data synchronization strategy and the operation records corresponding to the data changes, complete the data synchronization of multiple data nodes that collaborate to achieve data synchronization.
[0038] Specifically, in this embodiment, if Figure 2As shown, first, a communication connection is established between multiple data nodes and the blockchain. The blockchain includes multiple blockchain nodes. The multiple data nodes collaborate to achieve data synchronization. The multiple blockchain nodes each store a preset consensus mechanism. The consensus mechanism is collaboratively preset by multiple data nodes. The data synchronization process includes: the blockchain responds to the data change of a certain data node, determines whether to agree to the data change according to the consensus mechanism, forms a data synchronization strategy according to the judgment result of whether to agree to the data change, the data node obtains the data synchronization strategy from the blockchain, the blockchain provides the data synchronization strategy to the data node, and the data node obtains the operation record corresponding to the data change according to the data synchronization strategy, and completes the data synchronization of multiple data nodes that collaborate to achieve data synchronization, that is, if the data change is agreed, the remaining data nodes should make the same data change as the certain data node, and if the data change is not agreed, the certain data node should be restored to the data state before the data change. Compared with some cases, such as using Ali Canal (an incremental data subscription and consumption component) for data synchronization, it uses the master-slave replication principle of MySQL (a relational database management system) database to ensure data synchronization between slave data and master data. For example, using Maxwell (an application) for data synchronization, its principle is the same as Canal, with only slight differences in data format, data collection mode, data landing, etc. Their shortcomings include at least that there is a master-slave data relationship, the slave can only passively synchronize the master's data, and cannot filter the data of the master node, which may not be able to achieve data unification in multi-source application scenarios. The present disclosure uses blockchain technology to participate in data synchronization to ensure that after a data node data changes, multiple data nodes can participate in the process of judging whether data changes are allowed based on the data change situation, and then achieve data synchronization based on the judgment result, which is conducive to achieving data unification in multi-source application scenarios.
[0039] In one embodiment, before obtaining the data synchronization strategy from the blockchain, the method further includes:
[0040] Send data application scenario information to the blockchain so that the blockchain responds to the data application scenario information received from multiple data nodes that collaborate to achieve data synchronization, and sets up a consensus mechanism based on all the data application scenario information, so that each node in the blockchain votes on whether to agree with the data changes of the data node based on the consensus mechanism, and the blockchain forms a data synchronization strategy based on the number of votes.
[0041] Specifically, in this embodiment, multiple data nodes can be set in different application scenarios, and each application scenario may have different requirements for data changes. Multiple data nodes coordinate their respective requirements for data changes through blockchain, and the voting mechanism of blockchain nodes can be used to filter unreasonable data changes. The consensus mechanism is equivalent to data filtering rules, which can realize data filtering services. For example, a person’s ID card information can be used for shopping, bank loans, and medical insurance, but his or her ID card information should not be changed at will. Therefore, through keyword filtering and other methods, when it is found that a data node has changed the information, it is required to filter the data change.
[0042] In one embodiment, the operation record specifically includes at least one of the following:
[0043] An operation record formed in response to the newly added data, including a newly added identifier, a location of the newly added data, and a value of the newly added data;
[0044] An operation record including a deletion indicator and a location of the deleted data formed in response to the deletion of the data;
[0045] An operation record is formed in response to changing the data, including a change identification, a location of the changed data, and a value of the data after the change.
[0046] Specifically, in this embodiment, data synchronization is achieved through operation records corresponding to data changes. The operation records adopt an incremental update mode, that is, after a certain data change, the incremental part of the data change is recorded. When updating, only the incremental part of the data change needs to be synchronized, and all data does not need to be synchronized, thereby improving the efficiency of data update. Data changes include adding, deleting or updating data, etc., and corresponding operation records are generated when adding, deleting, changing, etc. operations on data nodes.
[0047] In one embodiment:
[0048] The multiple data nodes that collaborate to achieve data synchronization include a first data node and a second data node, the first data node is a data node where data changes occur, and the second data node is a data node that synchronizes data changes;
[0049] The data synchronization strategy is a data update strategy or a data filtering strategy. The data update strategy is formed by the blockchain judging based on a consensus mechanism that it agrees with the first data change of the first data node. The data filtering strategy is formed by the blockchain judging based on a consensus mechanism that it disagrees with the second data change of the first data node.
[0050] Specifically, in this embodiment, the data nodes include the source node where the data has changed, i.e., the first data node, and also include other nodes that share the data, i.e., the second data node that synchronizes the data changed by the first data node. The blockchain node assists in completing the data synchronization of multiple data nodes. There are two ways to synchronize data. First, when the data of the first data node changes (including addition, deletion, and update), the blockchain nodes vote to reach a consensus on the data changes. The blockchain nodes record the data operation records, and other data nodes (second data nodes) download the operation records and update the data themselves. Voting refers to multiple blockchain nodes voting on the same data change (operation record). When more than half of all blockchain nodes agree to record this operation record, the blockchain node will record it. The second data node performs the same operation as the first data node in the memory according to the data operation record of the blockchain node, and obtains the same change as the first data node, thereby maintaining data synchronization; second, filtering services are provided for data. When the blockchain nodes cannot reach a consensus on the voting results of the data changes, the data filtering of the first data node is executed. The direction of data synchronization can be controlled through the consensus mechanism to agree or disagree with the data change, and filtering and screening of data changes can be achieved, so that the needs of data sharing in more data sharing scenarios can be met.
[0051] In one implementation, according to the data synchronization strategy and the operation records corresponding to the data changes, completing the data synchronization of multiple data nodes that collaborate to achieve data synchronization specifically includes:
[0052] In response to the data synchronization strategy being a data update strategy, the first data node causes the second data node to update the data identical to the first data change in itself according to the first operation record corresponding to the first data change;
[0053] Alternatively, in response to the data synchronization strategy being a data update strategy, the second data node updates the data identical to the first data change in itself according to the first operation record corresponding to the first data change;
[0054] Alternatively, in response to the data synchronization policy being a data filtering policy, the first data node filters its own second data changes according to the second operation record corresponding to the second data changes.
[0055] Specifically, in this embodiment, according to the different properties of the data node (the first data node or the second data node), or according to the different data synchronization strategies (the data update strategy or the data filtering strategy), the data synchronization operations performed are different, including, when data update needs to be performed, the first data node synchronizes its own data with the second data node through the first operation record, and the second data node synchronizes the data of the first data node through the first operation record; when data filtering needs to be performed, the second data node does not need to perform the operation, and the first data node filters out the changed data.
[0056] In one embodiment, the method is applied to a first data node;
[0057] Get data synchronization strategy from blockchain, including:
[0058] In response to a first data change of the first data node, a first operation record is formed, and a first data change request is sent to the blockchain;
[0059] receiving a data update strategy from a blockchain, the data update strategy being obtained by the blockchain in response to agreeing to the first data change request according to a consensus mechanism;
[0060] In response to the data synchronization strategy being a data update strategy, the first data node causes the second data node to update data identical to the first data change in itself according to the first operation record corresponding to the first data change, specifically including:
[0061] A first operation record is sent to the blockchain according to a data update strategy, so that the blockchain stores the first operation record, and the second data node responds to monitoring the first operation record on the blockchain, downloads the first operation record from the blockchain, and updates the second data node data according to the first operation record.
[0062] In one embodiment, the method is applied to a second data node;
[0063] Get data synchronization strategy from blockchain, including:
[0064] monitoring a first operation record on the blockchain, the first operation record being formed by the first data node in response to a first data change of the first data node, and being received and stored by the blockchain from the first data node in response to receiving a first data change request from the first data node, agreeing to the first data change request through a consensus mechanism, and sending a data update policy to the first data node;
[0065] In response to the data synchronization strategy being a data update strategy, the second data node updates the data identical to the first data change in itself according to the first operation record corresponding to the first data change, specifically including:
[0066] In response to monitoring a first operation record on the blockchain, the first operation record is downloaded from the blockchain, and the second data node data is updated according to the first operation record.
[0067] In one embodiment, the method is applied to a first data node;
[0068] Get data synchronization strategy from blockchain, including:
[0069] In response to a second data change of the first data node, a second operation record is formed, and a second data change request is sent to the blockchain;
[0070] receiving a data filtering policy from a blockchain, the data filtering policy being obtained by the blockchain in response to disagreeing with the second data change request according to a consensus mechanism;
[0071] In response to the data synchronization strategy being a data filtering strategy, the first data node filters its own second data changes according to the second operation record corresponding to the second data changes, specifically including:
[0072] The second data change of the first data node corresponding to the second operation record is restored according to the data filtering strategy.
[0073] Specifically, in this embodiment, the blockchain node can monitor multiple data nodes in different application scenarios to learn about data changes in the data nodes; when the first data node among the multiple data nodes performs operations such as adding, deleting, and changing data, an operation record can be formed, and the first data node can request the blockchain node whether to accept the data change; once the blockchain node finds that the data of the first data node has changed, specifically, it can receive a data change request. If the data change is agreed to according to the consensus mechanism of the blockchain node, a data update strategy can be formed, requiring the first data node to upload the operation record to the blockchain node and synchronize the operation record to other data nodes, otherwise filtering is performed and the data is not synchronized to the blockchain node; other data nodes can determine The blockchain node is monitored at all times. Once the operation record of the blockchain node is found to have changed, it is equivalent to knowing that the blockchain has formed a data update strategy. At this time, the second data node only needs to automatically synchronize the data, including automatically downloading the operation record, and updating its own data according to the operation record to achieve data synchronization; if the blockchain node disagrees with the data change, there is a filtering strategy. The blockchain node synchronizes the filtering strategy to the first data node, and the first data node converts the filtering strategy and filters the corresponding data in the process of forming the historical operation record, that is, restoring the data of this change to the state before the change; data synchronization can be achieved by adding Kafka (a high-throughput distributed publish-subscribe messaging system) service or other services to send incremental data information.
[0074] Embodiment 2:
[0075] like Figure 3 As shown, the present disclosure provides a data synchronization method, which is applied to blockchain, and the method includes:
[0076] S21. In response to the data change of the data node, determine whether to agree with the data change according to the consensus mechanism to form a data synchronization strategy, and the consensus mechanism is pre-set on the blockchain by multiple data nodes that collaborate to achieve data synchronization;
[0077] S22. Provide a data synchronization strategy to the data nodes, so that the data nodes complete data synchronization of multiple data nodes that collaboratively implement data synchronization according to the data synchronization strategy and the operation records corresponding to the data changes.
[0078] In one embodiment, before determining whether to agree with the data change according to the consensus mechanism and forming a data synchronization strategy, the method further includes:
[0079] Receive data application scenario information from data nodes, and in response to receiving data application scenario information from each of multiple data nodes that collaborate to achieve data synchronization, set a consensus mechanism based on all data application scenario information, so that each node in the blockchain votes on whether to agree with the data changes of the data node based on the consensus mechanism, and the blockchain forms a data synchronization strategy based on the number of votes.
[0080] In one embodiment, the operation record specifically includes at least one of the following:
[0081] An operation record formed in response to the newly added data, including a newly added identifier, a location of the newly added data, and a value of the newly added data;
[0082] An operation record including a deletion indicator and a location of the deleted data formed in response to the deletion of the data;
[0083] An operation record is formed in response to changing the data, including a change identification, a location of the changed data, and a value of the data after the change.
[0084] In one embodiment:
[0085] The multiple data nodes that collaborate to achieve data synchronization include a first data node and a second data node, the first data node is a data node where data changes occur, and the second data node is a data node that synchronizes data changes;
[0086] The data synchronization strategy is a data update strategy or a data filtering strategy. The data update strategy is formed by the blockchain judging based on a consensus mechanism that it agrees with the first data change of the first data node. The data filtering strategy is formed by the blockchain judging based on a consensus mechanism that it disagrees with the second data change of the first data node.
[0087] In one embodiment, providing a data synchronization strategy to a data node so that the data node completes data synchronization of multiple data nodes that collaborate to achieve data synchronization according to the data synchronization strategy and the operation record corresponding to the data change, specifically including:
[0088] In response to the data synchronization strategy being a data update strategy, providing the data update strategy to the first data node, so that the first data node causes the second data node to update the data identical to the first data change in itself according to the first operation record corresponding to the first data change according to the data update strategy;
[0089] Alternatively, in response to the data synchronization policy being a data filtering policy, the data filtering policy is provided to the first data node, so that the first data node filters its own second data changes according to the second operation record corresponding to the second data changes.
[0090] In one implementation, in response to data changes at data nodes, a data synchronization strategy is formed by determining whether to agree to the data changes based on a consensus mechanism, specifically including:
[0091] receiving a first data change request from a first data node, the first data change request being sent by the first data node to the blockchain in response to a first data change of the first data node forming a first operation record, and forming a data update strategy in response to agreeing to the first data change request according to a consensus mechanism;
[0092] In response to the data synchronization strategy being a data update strategy, providing the data update strategy to the first data node, so that the first data node causes the second data node to update data identical to the first data change in itself according to the first operation record corresponding to the first data change according to the data update strategy, specifically including:
[0093] Sending a data update strategy to the first data node, so that the first data node sends a first operation record to the blockchain according to the data update strategy;
[0094] Receive and store a first operation record from a first data node, and enable a second data node to download the first operation record from the blockchain in response to monitoring the first operation record on the blockchain, and update the second data node data according to the first operation record.
[0095] In one implementation, in response to data changes at data nodes, a data synchronization strategy is formed by determining whether to agree to the data changes based on a consensus mechanism, specifically including:
[0096] receiving a second data change request from the first data node, the second data change request being sent by the first data node to the blockchain in response to a second data change of the first data node forming a second operation record, and forming a data filtering strategy in response to disagreeing with the second data change request according to a consensus mechanism;
[0097] In response to the data synchronization strategy being a data filtering strategy, providing the data filtering strategy to the first data node so that the first data node filters its own second data changes according to the second operation record corresponding to the second data changes, specifically includes:
[0098] The data filtering policy is sent to the first data node, so that the first data node restores the second data change of the first data node corresponding to the second operation record according to the data filtering policy.
[0099] In one embodiment, in response to agreeing to the first data change request or disagreeing to the second data change request according to the consensus mechanism, forming a data update strategy or a data filtering strategy specifically includes:
[0100] Each node of the blockchain votes on whether to agree to the first data change request or the second data change request based on the consensus mechanism;
[0101] The number of votes of each node of the blockchain is counted, and a data update strategy is formed in response to the number of votes approving the first data change request being greater than or equal to a preset value, or a data filtering strategy is formed in response to the number of votes approving the second data change request being less than a preset value.
[0102] The method of Example 2 is applied to blockchain, and its process interacts with the method of Example 1. For detailed description, please refer to Example 1.
[0103] Embodiment 3:
[0104] like Figure 4 As shown, the present disclosure provides a data node, including:
[0105] A synchronization strategy acquisition module 11 is used to acquire a data synchronization strategy from the blockchain. The data synchronization strategy is formed by the blockchain in response to data changes of data nodes and judging whether to agree with the data changes according to a consensus mechanism. The consensus mechanism is pre-set on the blockchain by multiple data nodes that collaborate to achieve data synchronization.
[0106] The synchronization strategy execution module 12 is connected to the synchronization strategy acquisition module 11, and is used to complete the data synchronization of multiple data nodes that collaboratively realize data synchronization according to the data synchronization strategy and the operation records corresponding to the data changes.
[0107] In one embodiment, the data node further includes:
[0108] The scenario information providing module is connected to the synchronization strategy acquisition module 11, and is used to send data application scenario information to the blockchain, so that the blockchain responds to the data application scenario information received from multiple data nodes that collaborate to achieve data synchronization, and sets a consensus mechanism based on all the data application scenario information. The nodes of the blockchain vote on whether to agree with the data changes of the data node according to the consensus mechanism, and the blockchain forms a data synchronization strategy based on the number of votes.
[0109] In one embodiment, the operation record specifically includes at least one of the following:
[0110] An operation record formed in response to the newly added data, including a newly added identifier, a location of the newly added data, and a value of the newly added data;
[0111] An operation record including a deletion indicator and a location of the deleted data formed in response to the deletion of the data;
[0112] An operation record is formed in response to changing the data, including a change identification, a location of the changed data, and a value of the data after the change.
[0113] In one embodiment:
[0114] The multiple data nodes that collaborate to achieve data synchronization include a first data node and a second data node, the first data node is a data node where data changes occur, and the second data node is a data node that synchronizes data changes;
[0115] The data synchronization strategy is a data update strategy or a data filtering strategy. The data update strategy is formed by the blockchain judging based on a consensus mechanism that it agrees with the first data change of the first data node. The data filtering strategy is formed by the blockchain judging based on a consensus mechanism that it disagrees with the second data change of the first data node.
[0116] In one implementation, the synchronization strategy execution module 12 specifically includes:
[0117] A first execution unit, configured to, in response to the data synchronization strategy being a data update strategy, enable the first data node to cause the second data node to update data identical to the first data change in itself according to a first operation record corresponding to the first data change;
[0118] Alternatively, the second execution unit is configured to, in response to the data synchronization strategy being a data update strategy, cause the second data node to update data identical to the first data change in itself according to the first operation record corresponding to the first data change;
[0119] Alternatively, the third execution unit is configured to, in response to the data synchronization strategy being a data filtering strategy, cause the first data node to filter its own second data changes according to the second operation record corresponding to the second data changes.
[0120] In one embodiment, the method is applied to a first data node;
[0121] The synchronization strategy acquisition module 11 specifically includes:
[0122] A request unit, configured to generate a first operation record in response to a first data change of a first data node, and send a first data change request to the blockchain;
[0123] a receiving unit connected to the requesting unit, and configured to receive a data update strategy from the blockchain, the data update strategy being obtained by the blockchain in response to agreeing to the first data change request according to a consensus mechanism;
[0124] The first execution unit is connected to the receiving unit and is specifically used to:
[0125] A first operation record is sent to the blockchain according to a data update strategy, so that the blockchain stores the first operation record, and the second data node responds to monitoring the first operation record on the blockchain, downloads the first operation record from the blockchain, and updates the second data node data according to the first operation record.
[0126] In one embodiment, the method is applied to a second data node;
[0127] The synchronization strategy acquisition module 11 specifically includes:
[0128] a monitoring unit, configured to monitor a first operation record on the blockchain, the first operation record being formed by the first data node in response to a first data change of the first data node, and being received and stored by the blockchain from the first data node in response to receiving a first data change request from the first data node, agreeing to the first data change request through a consensus mechanism, and sending a data update policy to the first data node;
[0129] The second execution unit is connected to the monitoring unit and is specifically used for:
[0130] In response to monitoring a first operation record on the blockchain, the first operation record is downloaded from the blockchain, and the second data node data is updated according to the first operation record.
[0131] In one embodiment, the method is applied to a first data node;
[0132] The synchronization strategy acquisition module 11 specifically includes:
[0133] A request unit, configured to generate a second operation record in response to a second data change of the first data node, and send a second data change request to the blockchain;
[0134] a receiving unit connected to the requesting unit, and configured to receive a data filtering strategy from the blockchain, the data filtering strategy being obtained by the blockchain in response to disagreeing with the second data change request according to a consensus mechanism;
[0135] The third execution unit is connected to the receiving unit and is specifically used for:
[0136] The second data change of the first data node corresponding to the second operation record is restored according to the data filtering strategy.
[0137] Embodiment 4:
[0138] like Figure 5 As shown, the present disclosure provides a blockchain, including:
[0139] A synchronization strategy forming module 21, which is used to respond to data changes of data nodes and determine whether to agree with the data changes according to a consensus mechanism to form a data synchronization strategy. The consensus mechanism is pre-set on the blockchain by multiple data nodes that collaborate to achieve data synchronization;
[0140] The synchronization strategy providing module 22 is connected to the synchronization strategy forming module 21, and is used to provide data synchronization strategies to data nodes, so that the data nodes can complete the data synchronization of multiple data nodes that collaboratively realize data synchronization according to the data synchronization strategies and the operation records corresponding to the data changes.
[0141] In one embodiment, the blockchain further includes:
[0142] The consensus mechanism setting module is connected to the synchronization strategy forming module 21, and is used to receive data application scenario information from data nodes. In response to receiving data application scenario information from multiple data nodes that collaborate to achieve data synchronization, a consensus mechanism is set according to all data application scenario information, so that each node in the blockchain votes on whether to agree with the data changes of the data node according to the consensus mechanism, and the blockchain forms a data synchronization strategy according to the number of votes.
[0143] In one embodiment, the operation record specifically includes at least one of the following:
[0144] An operation record formed in response to the newly added data, including a newly added identifier, a location of the newly added data, and a value of the newly added data;
[0145] An operation record including a deletion indicator and a location of the deleted data formed in response to the deletion of the data;
[0146] An operation record is formed in response to changing the data, including a change identification, a location of the changed data, and a value of the data after the change.
[0147] In one embodiment:
[0148] The multiple data nodes that collaborate to achieve data synchronization include a first data node and a second data node, the first data node is a data node where data changes occur, and the second data node is a data node that synchronizes data changes;
[0149] The data synchronization strategy is a data update strategy or a data filtering strategy. The data update strategy is formed by the blockchain judging based on a consensus mechanism that it agrees with the first data change of the first data node. The data filtering strategy is formed by the blockchain judging based on a consensus mechanism that it disagrees with the second data change of the first data node.
[0150] In one implementation, the synchronization strategy providing module 22 specifically includes:
[0151] A first providing unit is configured to provide the data updating strategy to the first data node in response to the data synchronization strategy being the data updating strategy, so that the first data node causes the second data node to update the data identical to the first data change in itself according to the first operation record corresponding to the first data change according to the data updating strategy;
[0152] Alternatively, the second providing unit is configured to provide the data filtering policy to the first data node in response to the data synchronization policy being a data filtering policy, so that the first data node filters its own second data changes according to the second operation record corresponding to the second data changes.
[0153] In one embodiment, the synchronization strategy forming module 21 is specifically used for:
[0154] receiving a first data change request from a first data node, and in response to agreeing to the first data change request according to a consensus mechanism, forming a data update strategy, wherein the first data change request is sent by the first data node to a blockchain in response to a first data change of the first data node and forming a first operation record;
[0155] The first providing unit specifically includes:
[0156] A sending unit, connected to the synchronization strategy forming module 21, configured to send a data update strategy to the first data node, so that the first data node sends a first operation record to the blockchain according to the data update strategy;
[0157] The operation recording unit is connected to the sending unit, and is used to receive and store the first operation record from the first data node, and enable the second data node to download the first operation record from the blockchain in response to monitoring the first operation record on the blockchain, and update the second data node data according to the first operation record.
[0158] In one embodiment, the synchronization strategy forming module 21 is specifically used for:
[0159] receiving a second data change request from the first data node, the second data change request being sent by the first data node to the blockchain in response to a second data change of the first data node forming a second operation record, and forming a data filtering strategy in response to disagreeing with the second data change request according to a consensus mechanism;
[0160] The second providing unit is connected to the synchronization strategy forming module 21, and is specifically used for:
[0161] The data filtering policy is sent to the first data node, so that the first data node restores the second data change of the first data node corresponding to the second operation record according to the data filtering policy.
[0162] In one embodiment, the synchronization strategy forming module 21 specifically includes:
[0163] A voting unit, used for each node of the blockchain to vote on whether to approve the first data change request or the second data change request according to a consensus mechanism;
[0164] The statistical unit is connected to the voting unit and is used to count the number of votes of each node of the blockchain, and to form a data update strategy in response to the number of votes approving the first data change request being greater than or equal to a preset value, or to form a data filtering strategy in response to the number of votes approving the second data change request being less than a preset value.
[0165] Embodiment 5:
[0166] Embodiment 5 of the present disclosure provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the data synchronization method as described in Embodiment 1 or 2 is implemented.
[0167] The computer-readable storage medium includes volatile or non-volatile, removable or non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, computer program modules or other data). Computer-readable storage media include, but are not limited to, RAM (Random Access Memory), ROM (Read-Only Memory), EEPROM (Electrically Erasable Programmable read only memory), flash memory or other memory technology, CD-ROM (Compact Disc Read-Only Memory), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer.
[0168] In addition, the present disclosure may also provide a computer device, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor runs the computer program stored in the memory, the processor executes the data synchronization method described in Example 1 or 2, and the device is specifically the data node described in Example 3 or the blockchain described in Example 4.
[0169] The memory is connected to the processor, the memory may be a flash memory or a read-only memory or other memory, and the processor may be a central processing unit or a single-chip microcomputer.
[0170] Furthermore, if Figure 2 As shown, the present disclosure may also provide a data synchronization system, including a data node for implementing the data synchronization method as described in Example 1, and a blockchain for implementing the data synchronization method as described in Example 2.
[0171] Embodiments 1-5 of the present disclosure provide a data synchronization method, a data node, a blockchain, and a computer-readable storage medium. The blockchain is introduced between multiple data nodes that share data. A consensus mechanism is collaboratively pre-set on the blockchain through these data nodes. When data changes occur at any of the nodes, it is necessary to determine whether the data change is agreed to through the consensus mechanism pre-set on the blockchain. The blockchain provides a data synchronization strategy based on the result of the determination of whether the data change is agreed to. The data synchronization strategy is used to control the data on these multiple data nodes to always remain synchronized. There is no pre-set master-slave relationship between these multiple data nodes, and data synchronization can be controlled through a consensus mechanism, which can meet the needs of data sharing in more data sharing scenarios.
[0172] It is to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present disclosure, but the present disclosure is not limited thereto. For those of ordinary skill in the art, various modifications and improvements can be made without departing from the spirit and substance of the present disclosure, and these modifications and improvements are also considered to be within the scope of protection of the present disclosure.
Claims
1. A data synchronization method, characterized in that: Applied to a data node, the method comprises: Obtain data synchronization strategy from blockchain. Data synchronization strategy is formed by blockchain in response to data changes of data nodes and judging whether to agree with data changes according to consensus mechanism. Consensus mechanism is pre-set on blockchain by multiple data nodes that collaborate to achieve data synchronization. According to the data synchronization strategy and the operation records corresponding to the data changes, the data synchronization of multiple data nodes that collaborate to achieve data synchronization is completed.
2. The method according to claim 1, characterized in that Before obtaining the data synchronization strategy from the blockchain, the method further includes: Send data application scenario information to the blockchain so that the blockchain responds to the data application scenario information received from multiple data nodes that collaborate to achieve data synchronization, and sets up a consensus mechanism based on all the data application scenario information, so that each node in the blockchain votes on whether to agree with the data changes of the data node based on the consensus mechanism, and the blockchain forms a data synchronization strategy based on the number of votes.
3. The method according to claim 1, characterized in that The operation record specifically includes at least one of the following: An operation record formed in response to the newly added data, including a newly added identifier, a location of the newly added data, and a value of the newly added data; An operation record including a deletion indicator and a location of the deleted data formed in response to the deletion of the data; An operation record is formed in response to changing the data, including a change identification, a location of the changed data, and a value of the data after the change.
4. The method according to any one of claims 1 to 3, characterized in that: The multiple data nodes that collaborate to achieve data synchronization include a first data node and a second data node, the first data node is a data node where data changes occur, and the second data node is a data node that synchronizes data changes; The data synchronization strategy is a data update strategy or a data filtering strategy. The data update strategy is formed by the blockchain judging based on a consensus mechanism that it agrees with the first data change of the first data node. The data filtering strategy is formed by the blockchain judging based on a consensus mechanism that it disagrees with the second data change of the first data node.
5. The method according to claim 4, characterized in that According to the data synchronization strategy and the operation records corresponding to the data changes, the data synchronization of multiple data nodes that collaborate to achieve data synchronization is completed, including: In response to the data synchronization strategy being a data update strategy, the first data node causes the second data node to update the data identical to the first data change in itself according to the first operation record corresponding to the first data change; Alternatively, in response to the data synchronization strategy being a data update strategy, the second data node updates the data identical to the first data change in itself according to the first operation record corresponding to the first data change; Alternatively, in response to the data synchronization policy being a data filtering policy, the first data node filters its own second data changes according to the second operation record corresponding to the second data changes.
6. The method according to claim 5, characterized in that The method is applied to a first data node; Get data synchronization strategy from blockchain, including: In response to a first data change of the first data node, a first operation record is formed, and a first data change request is sent to the blockchain; receiving a data update strategy from a blockchain, the data update strategy being obtained by the blockchain in response to agreeing to the first data change request according to a consensus mechanism; In response to the data synchronization strategy being a data update strategy, the first data node causes the second data node to update data identical to the first data change in itself according to the first operation record corresponding to the first data change, specifically including: A first operation record is sent to the blockchain according to a data update strategy, so that the blockchain stores the first operation record, and the second data node responds to monitoring the first operation record on the blockchain, downloads the first operation record from the blockchain, and updates the second data node data according to the first operation record.
7. The method according to claim 5, characterized in that: The method is applied to a second data node; Get data synchronization strategy from blockchain, including: monitoring a first operation record on the blockchain, the first operation record being formed by the first data node in response to a first data change of the first data node, and being received and stored by the blockchain from the first data node in response to receiving a first data change request from the first data node, agreeing to the first data change request through a consensus mechanism, and sending a data update policy to the first data node; In response to the data synchronization strategy being a data update strategy, the second data node updates the data identical to the first data change in itself according to the first operation record corresponding to the first data change, specifically including: In response to monitoring a first operation record on the blockchain, the first operation record is downloaded from the blockchain, and the second data node data is updated according to the first operation record.
8. The method according to claim 5, characterized in that The method is applied to a first data node; Get data synchronization strategy from blockchain, including: In response to a second data change of the first data node, a second operation record is formed, and a second data change request is sent to the blockchain; receiving a data filtering policy from a blockchain, the data filtering policy being obtained by the blockchain in response to disagreeing with the second data change request according to a consensus mechanism; In response to the data synchronization strategy being a data filtering strategy, the first data node filters its own second data changes according to the second operation record corresponding to the second data changes, specifically including: The second data change of the first data node corresponding to the second operation record is restored according to the data filtering strategy.
9. A data synchronization method, characterized in that: Applied to blockchain, the method includes: In response to data changes at data nodes, a data synchronization strategy is formed based on a consensus mechanism to determine whether the data changes are agreed upon. The consensus mechanism is pre-set on the blockchain by multiple data nodes that collaborate to achieve data synchronization. A data synchronization strategy is provided to the data nodes, so that the data nodes complete data synchronization of multiple data nodes that collaboratively implement data synchronization according to the data synchronization strategy and the operation records corresponding to the data changes.
10. The method according to claim 9, characterized in that Before forming a data synchronization strategy by judging whether to agree with the data change according to the consensus mechanism, the method further includes: Receive data application scenario information from data nodes, and in response to receiving data application scenario information from each of multiple data nodes that collaborate to achieve data synchronization, set a consensus mechanism based on all data application scenario information, so that each node in the blockchain votes on whether to agree with the data changes of the data node based on the consensus mechanism, and the blockchain forms a data synchronization strategy based on the number of votes.
11. The method according to claim 9, characterized in that The operation record specifically includes at least one of the following: An operation record formed in response to the newly added data, including a newly added identifier, a location of the newly added data, and a value of the newly added data; An operation record including a deletion indicator and a location of the deleted data formed in response to the deletion of the data; An operation record is formed in response to changing the data, including a change identification, a location of the changed data, and a value of the data after the change.
12. The method according to any one of claims 9 to 11, characterized in that: The multiple data nodes that collaborate to achieve data synchronization include a first data node and a second data node, the first data node is a data node where data changes occur, and the second data node is a data node that synchronizes data changes; The data synchronization strategy is a data update strategy or a data filtering strategy. The data update strategy is formed by the blockchain judging based on a consensus mechanism that it agrees with the first data change of the first data node. The data filtering strategy is formed by the blockchain judging based on a consensus mechanism that it disagrees with the second data change of the first data node.
13. The method according to claim 12, characterized in that Providing a data synchronization strategy to the data node, so that the data node can complete the data synchronization of multiple data nodes that collaborate to achieve data synchronization according to the data synchronization strategy and the operation records corresponding to the data changes, specifically including: In response to the data synchronization strategy being a data update strategy, providing the data update strategy to the first data node, so that the first data node causes the second data node to update the data identical to the first data change in itself according to the first operation record corresponding to the first data change according to the data update strategy; Alternatively, in response to the data synchronization policy being a data filtering policy, the data filtering policy is provided to the first data node, so that the first data node filters its own second data changes according to the second operation record corresponding to the second data changes.
14. The method according to claim 13, characterized in that In response to the data changes of the data nodes, the consensus mechanism determines whether to agree with the data changes and forms a data synchronization strategy, which specifically includes: receiving a first data change request from a first data node, the first data change request being sent by the first data node to the blockchain in response to a first data change of the first data node forming a first operation record, and forming a data update strategy in response to agreeing to the first data change request according to a consensus mechanism; In response to the data synchronization strategy being a data update strategy, providing the data update strategy to the first data node, so that the first data node causes the second data node to update data identical to the first data change in itself according to the first operation record corresponding to the first data change according to the data update strategy, specifically including: Sending a data update strategy to the first data node, so that the first data node sends a first operation record to the blockchain according to the data update strategy; Receive and store a first operation record from a first data node, and enable a second data node to download the first operation record from the blockchain in response to monitoring the first operation record on the blockchain, and update the second data node data according to the first operation record.
15. The method according to claim 13, characterized in that In response to the data changes of the data nodes, the consensus mechanism determines whether to agree with the data changes and forms a data synchronization strategy, which specifically includes: receiving a second data change request from the first data node, the second data change request being sent by the first data node to the blockchain in response to a second data change of the first data node forming a second operation record, and forming a data filtering strategy in response to disagreeing with the second data change request according to a consensus mechanism; In response to the data synchronization strategy being a data filtering strategy, providing the data filtering strategy to the first data node so that the first data node filters its own second data changes according to the second operation record corresponding to the second data changes, specifically includes: The data filtering policy is sent to the first data node, so that the first data node restores the second data change of the first data node corresponding to the second operation record according to the data filtering policy.
16. The method according to claim 14 or 15, characterized in that: In response to agreeing to the first data change request or disagreeing to the second data change request according to the consensus mechanism, a data update strategy or a data filtering strategy is formed, specifically including: Each node of the blockchain votes on whether to agree to the first data change request or the second data change request based on the consensus mechanism; The number of votes of each node of the blockchain is counted, and a data update strategy is formed in response to the number of votes approving the first data change request being greater than or equal to a preset value, or a data filtering strategy is formed in response to the number of votes approving the second data change request being less than a preset value.
17. A data node, characterized in that: include: A synchronization strategy acquisition module is used to obtain a data synchronization strategy from the blockchain. The data synchronization strategy is formed by the blockchain in response to the data changes of the data nodes and judging whether the data changes are agreed according to the consensus mechanism. The consensus mechanism is pre-set on the blockchain by multiple data nodes that collaborate to achieve data synchronization. The synchronization strategy execution module is connected to the synchronization strategy acquisition module, and is used to complete the data synchronization of multiple data nodes that collaboratively realize data synchronization according to the data synchronization strategy and the operation records corresponding to the data changes.
18. A blockchain, characterized in that: include: A synchronization strategy forming module is used to respond to data changes of data nodes and form a data synchronization strategy based on the consensus mechanism to determine whether to agree with the data changes. The consensus mechanism is pre-set on the blockchain by multiple data nodes that collaborate to achieve data synchronization; The synchronization strategy providing module is connected to the synchronization strategy forming module and is used to provide data synchronization strategies to data nodes so that the data nodes can complete data synchronization of multiple data nodes that collaboratively realize data synchronization according to the data synchronization strategies and operation records corresponding to data changes.
19. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the data synchronization method as described in any one of claims 1-8 or 9-16 is implemented.
