WO2023206142A1 - Data synchronization method and apparatus, computer device and storage medium - Google Patents

Data synchronization method and apparatus, computer device and storage medium Download PDF

Info

Publication number
WO2023206142A1
WO2023206142A1 PCT/CN2022/089570 CN2022089570W WO2023206142A1 WO 2023206142 A1 WO2023206142 A1 WO 2023206142A1 CN 2022089570 W CN2022089570 W CN 2022089570W WO 2023206142 A1 WO2023206142 A1 WO 2023206142A1
Authority
WO
WIPO (PCT)
Prior art keywords
blockchain
write operation
block
global data
data
Prior art date
Application number
PCT/CN2022/089570
Other languages
French (fr)
Chinese (zh)
Inventor
张作鹏
Original Assignee
西门子股份公司
西门子(中国)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 西门子股份公司, 西门子(中国)有限公司 filed Critical 西门子股份公司
Priority to PCT/CN2022/089570 priority Critical patent/WO2023206142A1/en
Publication of WO2023206142A1 publication Critical patent/WO2023206142A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions

Definitions

  • the present application relates to the field of data processing technology, and in particular, to a data synchronization method, device, computer equipment and storage medium.
  • the distributed system needs to maintain data consistency.
  • the distributed system includes multiple communication modules. The user needs to determine the status of each communication module, and each communication module needs to determine the online status of other communication modules. That is, it is necessary to ensure the consistency of communication module status data between communication modules.
  • the data of distributed systems are stored in centralized storage such as databases and file systems. All nodes included in the distributed system interact with centralized storage to ensure that each Nodes are able to read consistent data from centralized storage.
  • the data synchronization method, device, computer equipment and storage medium provided by this application can improve data security while ensuring data consistency.
  • a data synchronization method is provided, which is applied to a blockchain node.
  • the data synchronization method includes: monitoring the generation of new blocks on the blockchain, wherein the blockchain uses To store write operation instructions for global data; after monitoring that a new block is generated on the blockchain, obtain the write operation instructions stored in the new block; according to the write operation instructions stored in the new block, perform The global data cached locally by the blockchain node is updated. Since each node locally caches the latest global data, if any node fails, other nodes can still operate normally, thus ensuring the reliability of the distributed system operation. Since the write operation instructions for global data are stored on the blockchain, the security of global data can be improved based on the non-tamperable and traceable characteristics of data on the blockchain.
  • the global data is constructed based on each write operation instruction for the global data, and the constructed global data is cached locally in the blockchain node.
  • the constructed global data is cached locally in the blockchain node.
  • users of the blockchain node need to access global data, they can directly access the global data cached locally on the blockchain node, which reduces the delay in accessing global data and improves the user experience.
  • constructing global data based on each write operation instruction for global data includes: reading the write operation instructions for global data from each block of the blockchain; Each write operation instruction constructs global data. Based on the non-tamperable and traceable characteristics of data on the blockchain, the write operation instructions are read from the blockchain to construct global data, which ensures the accuracy of the constructed global data and ensures global data between blockchain nodes. consistency.
  • the method further includes: persisting the write operation instructions stored in the new block to the local storage of the blockchain node; the writing operation instructions based on the global data Constructing global data includes: determining new blocks on the blockchain during the period when the blockchain node stops running; persisting the write operation instructions stored in each of the new blocks to the block Local storage of the chain node; construct global data according to each write operation instruction persisted in the local storage of the blockchain node. After detecting that a new block is generated on the blockchain, the write operation instructions stored in the new block are persisted to the local storage of the blockchain node.
  • each blockchain node After each blockchain node is started or restored to operating status, it can be based on the local
  • the persistent write operation instructions in the storage are used to construct global data, without the need to read each block of the blockchain to obtain each write operation instruction, which shortens the time required to construct global data and improves the efficiency of constructing global data.
  • determining the newly added blocks on the blockchain during the period when the blockchain node stops running includes: determining the latest persistent write operation on the blockchain node. The first block corresponding to the instruction; determine the second block on the blockchain with a block sequence number greater than the first block as a new block on the blockchain during the period when the blockchain node stops running. .
  • the block sequence number of the first block can be and the block sequence number of each block on the blockchain to determine the new blocks generated when the blockchain node stops running, ensuring that the write operation instructions stored in each new block can be persisted to the local storage of the blockchain node , and then when constructing global data based on persistent write operation instructions on the blockchain node, the accuracy of the constructed global data is guaranteed.
  • determining the newly added blocks on the blockchain during the period when the blockchain node stops running includes: determining the latest persistent write operation on the blockchain node. Instruct the third block corresponding to the instruction; according to the timestamp stored in the block on the blockchain, determine the fourth block whose generation time indicated by the corresponding timestamp is later than that of the third block; transfer the fourth block The block is determined to be a newly added block on the blockchain during the period when the blockchain node stops running.
  • each fourth block can be determined as a block.
  • the new blocks generated when the blockchain node stops running ensure that the write operation instructions stored in each new block can be persisted to the local storage of the blockchain node, thus ensuring the accuracy of the global data.
  • the method further includes: receiving at least one write operation instruction for global data; creating a new block on the blockchain, and storing the received at least one write operation instruction. into the new block created.
  • a new block will be generated to store the current blockchain node’s write operation instructions for global data, so that each blockchain node can store the write operation instructions for global data on the blockchain, and can store the global data according to the instructions on the blockchain.
  • the write operation instructions update the global data.
  • the synchronization mechanism based on the blockchain can ensure the consistency of the global data among the blockchain nodes and also ensure the timeliness of synchronizing the global data.
  • the write operation instructions for global data include at least one of a data addition instruction, a data deletion instruction, and a data modification instruction.
  • Write operation instructions that change global data by adding, deleting, modifying, etc. will be stored on the blockchain, so that various changes to global data by each blockchain node can be synchronized to other blockchain nodes. , ensuring the reliability and effectiveness of global data synchronization between blockchain nodes.
  • a data synchronization device which is applied to a blockchain node.
  • the data synchronization device includes: a monitoring module for monitoring the generation of new blocks on the blockchain, wherein: The blockchain is used to store write operation instructions for global data; the acquisition module is used to obtain the write operation instructions stored in the new block after the monitoring module detects that a new block is generated on the blockchain. ; Update module, used to update the global data cached locally by the blockchain node according to the write operation instructions stored in the new block.
  • a computer device including: a processor, a communication interface, a memory, and a communication bus.
  • the processor, the memory, and the communication interface complete each other through the communication bus. communication between; the memory is used to store at least one executable instruction, the executable instruction causes the processor to perform operations corresponding to the data synchronization method provided in the first aspect.
  • a computer-readable storage medium is provided.
  • Computer instructions are stored on the computer-readable storage medium. When executed by a processor, the computer instructions cause the processor to execute Operations corresponding to the data synchronization method provided in the above first aspect.
  • a computer program product is provided, which is tangibly stored on a computer-readable medium and includes computer-executable instructions, which when executed At least one processor is caused to execute the data synchronization method provided by the above-mentioned first aspect or any possible implementation of the first aspect.
  • each node included in the distributed system serves as a blockchain node of the blockchain system.
  • the blockchain is used to store write operations for global data. After each blockchain node performs a write operation on global data, The corresponding write operation instructions will be stored in the new block of the blockchain, and based on the synchronization mechanism of the blockchain, the new block will be synchronized to the blockchain on each blockchain node, so when monitoring the blockchain After a new block is generated, the global data cached locally by the blockchain node can be updated according to the write operation instructions stored in the new block, ensuring that the local cache of each blockchain node has the same global data, realizing distributed Data consistency between nodes in the system.
  • each node locally caches the latest global data, other nodes can still operate normally if any node fails, thus ensuring the reliability of the distributed system operation. Since the write operation instructions for global data are stored on the blockchain, the security of global data can be improved based on the non-tamperable and traceable characteristics of data on the blockchain.
  • Figure 1 is a flow chart of a data synchronization method according to an embodiment of the present application
  • Figure 2 is a flow chart of a data synchronization method according to another embodiment of the present application.
  • Figure 3 is a schematic diagram of a data synchronization device according to an embodiment of the present application.
  • Figure 4 is a schematic diagram of a data synchronization device according to another embodiment of the present application.
  • Figure 5 is a schematic diagram of a data synchronization device according to another embodiment of the present application.
  • Figure 6 is a schematic diagram of a computer device according to an embodiment of the present application.
  • Data synchronization method 200 Data synchronization method 300: Data synchronization device
  • 602 Processor 604: Communication interface 606: Memory
  • the current technical means is to store the data of distributed systems in centralized storage, such as databases, file systems, etc.
  • centralized storage such as databases, file systems, etc.
  • Each node included in the distributed system Data interaction with centralized storage means that all nodes write data uniformly stored on the centralized storage and read data from the centralized storage, thus ensuring the consistency of data between nodes.
  • the centralized storage fails, all nodes will be unable to read and write to the centralized storage, and the entire distributed system will not be able to operate normally.
  • data on centralized storage is easily tampered with, resulting in low data security.
  • each node in the distributed system is a blockchain node.
  • the corresponding write operation instructions are stored in the block.
  • each write operation instruction will be synchronized to the blockchain of each node, and then each node can read the new write operation instruction from the blockchain, and based on The read write operation instructions update the global data to ensure the synchronization of global data between nodes. Since each node can obtain the latest global data based on the write operation instructions stored on the blockchain, if any node fails, other nodes can still operate normally, thus ensuring the reliability of the distributed system operation. Since the write operation instructions for global data are stored on the blockchain, the security of global data can be improved based on the non-tamperable and traceable characteristics of data on the blockchain.
  • FIG. 1 is a flow chart of a data synchronization method provided by an embodiment of the present application.
  • the data synchronization method is applied to blockchain nodes.
  • the blockchain system includes multiple blockchain nodes. Each node in the distributed system They are all a blockchain node, and each blockchain node stores a complete blockchain.
  • the synchronization mechanism between each blockchain node ensures the consistency of the data stored in the blockchain on each blockchain node.
  • the data synchronization method 100 includes the following steps:
  • Step 101 Monitor the generation of new blocks on the blockchain, where the blockchain is used to store write operation instructions for global data.
  • a new block will be generated on the blockchain to store the write operation instructions corresponding to the write operation.
  • the blockchain on each blockchain node will generate new blocks simultaneously to ensure that the same blocks are stored in the blockchain on each blockchain node. The data.
  • Write operation instructions are used to instruct the write operation of global data.
  • Global data is jointly maintained by nodes in the distributed system, that is, global data is maintained synchronously by multiple blockchain nodes.
  • Write operations include adding new global data, Delete and modify.
  • a write operation instruction can indicate that data a is added to the global data, data b in the global data is deleted, or data c in the global data is modified.
  • a new block can store one or more write operation instructions.
  • the multiple write operation instructions can correspond to the write operation of global data by the same blockchain node, or they can also correspond to the write operation of global data by different blockchain nodes.
  • Step 102 After detecting that a new block is generated on the blockchain, obtain the write operation instructions stored in the new block.
  • the blockchain node After the blockchain node detects that a new block is generated on the blockchain, it reads the new block on the blockchain and obtains the write operation instructions stored in the new block.
  • the number of new blocks on the blockchain can be one or more. When the number of new blocks on the blockchain is multiple, each new block is read separately to obtain the information stored in each new block. write operation instructions.
  • Step 103 Update the global data cached locally in the blockchain node according to the write operation instructions stored in the new block.
  • the blockchain node has global data cached locally. After obtaining the write operation instructions stored in the new block, the global data is updated according to the obtained write operation instructions. Since the write operation instruction indicates the write operation of one or more blockchain nodes to global data, the write operation instruction in the new block indicates the latest write operation to global data. According to the write operation instruction stored in the new block, the local The cached global data performs corresponding write operations, ensuring that the local storage of each blockchain node has the same global data.
  • each node included in the distributed system serves as a blockchain node of the blockchain system.
  • the blockchain is used to store write operations for global data.
  • Each blockchain node performs write operations on global data.
  • the corresponding write operation instructions will be stored in the new block of the blockchain, and based on the synchronization mechanism of the blockchain, the new block will be synchronized to the blockchain on each blockchain node, so when the area is monitored
  • the global data cached locally by the blockchain node can be updated according to the write operation instructions stored in the new block to ensure that the local cache of each blockchain node has the same global data. This is achieved Data consistency among nodes in a distributed system.
  • each node locally caches the latest global data, if any node fails, other nodes can still operate normally, thus ensuring the reliability of the distributed system operation. Since the write operation instructions for global data are stored on the blockchain, the security of global data can be improved based on the non-tamperable and traceable characteristics of data on the blockchain.
  • the global data can be constructed based on each write operation instruction for the global data, and the constructed global data can be cached locally on the blockchain node. storage.
  • each write operation instruction for global data indicates each write operation for global data, so the latest global data can be constructed based on each write operation instruction for global data. data.
  • the global data is constructed according to each write operation instruction of the global data, and the constructed global data is cached and stored locally in the blockchain node.
  • the blockchain node When users need to access global data, they can directly access the global data cached locally on the blockchain node, which reduces the delay in accessing global data and improves the user experience.
  • the write operation instructions for global data can be read from each block of the blockchain, and then based on each read write operation instruction Operation instructions build global data.
  • the write operation instructions stored in the new block can be persisted to the local storage of the blockchain node.
  • the block After the blockchain node starts or resumes operation it is possible to determine the new blocks on the blockchain during the period when the blockchain node stops running. That is, it is possible to determine whether other blockchain nodes have access to global data while the current blockchain node stops running. A write operation was performed. If there is a new blockchain, the write operation instructions stored in the new block will be persisted to the local storage of the blockchain node, and then global data will be constructed based on each write operation instruction persisted in the local storage of the blockchain node. . If there is no new block, global data will be constructed based on the persistent write operation instructions stored locally in the blockchain node.
  • the write operation instructions stored in the new block are persisted to the local storage of the blockchain node.
  • global data can be constructed based on the persistent write operation instructions in local storage without having to read each block of the blockchain to obtain each write operation instruction, shortening the time required to build global data. Improve the efficiency of building global data.
  • the first block corresponding to the latest persistent write operation instruction on the blockchain node can be determined, Then, the second block on the blockchain with a block sequence number greater than the first block is determined as a new block on the blockchain during the period when the blockchain node stops running.
  • the sequence number of the block in the blockchain increases.
  • the block sequence number of the first block in the blockchain is 0, the block sequence number of the second block is 1, and the block sequence number of the Nth block is 1.
  • the block sequence number of a block is N-1, and N is a positive integer greater than 2. Therefore, the generation order of blocks can be determined based on the block sequence number.
  • Each write operation instruction persisted in the local storage of the blockchain node has a block identifier.
  • the block identifier is the block sequence number corresponding to the block on the blockchain where the write operation instruction is stored. According to the latest persistence on the blockchain node
  • the block identifier of the written operation instruction can be used to determine the first block on the blockchain that stores the latest persistent write operation instruction, and then the second block on the blockchain with a block sequence number greater than the first block can be determined. Confirmed as a new block.
  • the block sequence number of the first block is N, and the block sequence number of the last block on the blockchain is also N, that is, the largest block sequence number among the blocks on the blockchain is N, then there is no second Block, that is, there are no new blocks on the blockchain during the period when the blockchain node stops running. If the block sequence number of the first block is N, and the block sequence number of the last block on the blockchain is greater than N, then the block corresponding to the block sequence number N on the blockchain is not the last one on the blockchain. Block, at this time, each block on the blockchain with a corresponding block number greater than N is determined as a new block.
  • the number of new blocks can be one or more.
  • the block serial numbers of the blocks on the blockchain increase sequentially according to the generation time, after determining the first block that stores the latest persistent write operation instructions on the blockchain node, it can be based on the first block.
  • the block sequence number of a block and the block sequence number of each block on the blockchain determine the new blocks generated when the blockchain node stops running, ensuring that the write operation instructions stored in each new block can be persisted to
  • the local storage of the blockchain node ensures the accuracy of the constructed global data when constructing global data based on persistent write operation instructions on the blockchain node.
  • the third block corresponding to the latest persistent write operation instruction on the blockchain node can be determined, Then, based on the timestamps stored in each block on the blockchain, the fourth block whose generation time indicated by the corresponding time window is later than the third block is determined, and then the fourth block is determined as the period during which the blockchain node stops running. New blocks on the blockchain.
  • Each block in the blockchain not only stores write operation instructions, but also stores the block sequence number and timestamp.
  • the timestamp can indicate the generation time of the corresponding block. Since blocks on the blockchain are generated sequentially in chronological order, the order in which blocks are generated can be determined based on the timestamps stored in the blocks.
  • the last block on the blockchain is the third block.
  • Each block whose timestamp indicates the time stored in the block is determined as the fourth block, and each fourth block is determined as a new block on the blockchain during the period when the blockchain node stops operating.
  • the number of fourth blocks Can be one or more.
  • the blocks on the blockchain are generated sequentially in chronological order, and new write operation instructions are stored in the new blocks, it is necessary to determine the storage of the latest persistent write operation instructions on the blockchain node.
  • the fourth block whose generation time is later than the third block can be determined based on the timestamp stored in the third block and the timestamps stored in each block on the blockchain, and then each block can be The fourth block is determined to be the new block generated when the blockchain node stops running. It ensures that the write operation instructions stored in each new block can be persisted to the local storage of the blockchain node, thereby ensuring that all the global Accuracy of data.
  • a user when a user writes global data through the current blockchain node, he or she can receive at least one write operation instruction for the global data, and then create a new block on the blockchain and receive Each write operation instruction is stored in the new block created.
  • the new block created by the current blockchain node will be synchronized to the blockchain on other blockchain nodes, making other blocks Chain nodes can update global data based on new blocks on the blockchain to ensure the consistency of global data between blockchain nodes.
  • the blockchain node can not only update the writing operations of other blockchain nodes on global data based on the new block, but also generate new blocks to store the writing operation instructions of the current blockchain node on global data, so that every Each blockchain node can store the write operation instructions for global data on the blockchain, and can update the global data based on the write operation instructions stored on the blockchain. Based on the synchronization mechanism of the blockchain, it can be guaranteed The consistency of global data among various blockchain nodes can also ensure the timeliness of synchronizing global data.
  • the write operation instructions for global data include at least one of a data addition instruction, a data deletion instruction, and a data modification instruction.
  • the data new instruction is used to add new data entries in the global data.
  • the global data includes data 1 to data 100, a total of 100 data.
  • the data new instruction is used to instruct the new data 101 in the global data. Based on this data, After the add instruction writes the global data, the global data includes data 1 to data 101, a total of 101 pieces of data.
  • the data deletion instruction is used to delete data entries in the global data.
  • the global data includes data 1 to data 101, a total of 101 pieces of data.
  • the data deletion instruction is used to instruct the deletion of data 1 and data 2 in the global data. Based on the data deletion After the instruction writes the global data, the global data includes a total of 99 pieces of data from data 3 to data 101.
  • the data modification instruction is used to modify one or more data items in the global data.
  • the global data includes data 1 to data 100, which counts 100 pieces of data.
  • the data modification instruction is used to instruct data 10 in the global data to be modified. After the global write operation is performed based on this data modification instruction, data 10 in the global data is modified to data 10'.
  • the write operation instructions include at least one of a data addition instruction, a data deletion instruction, and a data modification instruction. Therefore, any write operation instruction that changes global data through addition, deletion, modification, etc. will be Stored on the blockchain, all changes made by each blockchain node to global data can be synchronized to other blockchain nodes, ensuring the reliability and effectiveness of global data synchronization between blockchain nodes.
  • FIG. 2 is a flow chart of a data synchronization method according to another embodiment of the present application. As shown in Figure 2, the data synchronization method 200 includes the following steps:
  • Step 201 After the blockchain node starts or resumes operation, persist the write operation instructions stored in the newly added block to the local storage of the blockchain node.
  • Step 202 Load each write operation instruction persisted in the local storage of the blockchain node.
  • the write operation instructions stored in each block on the blockchain will be persisted to the local storage of the blockchain node.
  • load each write operation instruction persisted in the local storage of the blockchain node After persisting the write operation instructions stored in each new block to the local storage of the blockchain node, load each write operation instruction persisted in the local storage of the blockchain node. Operating instructions.
  • Step 203 Construct global data according to each write operation instruction, and store and cache the global data locally on the blockchain node.
  • each write operation instruction After loading each write operation instruction persisted in the local storage of the blockchain node, each write operation instruction is re-executed in sequence according to the time sequence of the corresponding write operation, the global data is constructed, and the constructed global data is cached in the area. Local storage of blockchain nodes.
  • Step 204 Monitor the generation of new blocks on the blockchain.
  • the blockchain node When the blockchain node is in running state, it detects the generation of new blocks on the blockchain. It should be noted that the generation method of new blocks on the blockchain and the synchronization method of the blockchain can be implemented through innovative methods or through existing methods, which are not limited by the embodiments of this application.
  • Step 205 Determine whether a new block is generated on the blockchain. If yes, execute step 206. If not, execute step 204.
  • Step 206 Update the global data according to the write operation instructions stored in the new block.
  • a new block When it is determined that a new block is generated on the blockchain, it means that a blockchain node has written to the global data, and the write operation instructions stored in the new block indicate the write operation to the global data, and the new block will The stored write operation instructions are persisted to the local storage of the blockchain node, and the local cached global data is updated according to the write operation instructions stored in the new block to achieve global data synchronization between each blockchain node.
  • blockchain nodes can monitor the online status of monitored devices such as PLCs and sensors.
  • the global data is the number of monitored devices online.
  • the number of monitored devices currently online is 0, that is, the global data is equal to 0.
  • the update process of the global data is 0+1+1-1, and the global data after the update is equal to 1.
  • FIG 3 is a schematic diagram of a data synchronization device according to an embodiment of the present application.
  • the data synchronization device is applied to a blockchain node.
  • the data synchronization device 300 includes:
  • Monitoring module 301 is used to monitor the generation of new blocks on the blockchain, where the blockchain is used to store write operation instructions for global data;
  • the acquisition module 302 is used to acquire the write operation instructions stored in the new block after the monitoring module detects that a new block is generated on the blockchain;
  • the update module 303 is used to update the global data cached locally by the blockchain node according to the write operation instructions stored in the new block.
  • the monitoring module 301 can be used to perform step 101 in the above method embodiment
  • the acquisition module 302 can be used to perform step 102 in the above method embodiment
  • the update module 303 can be used to perform the steps in the above method embodiment. 103.
  • FIG 4 is a schematic diagram of a data synchronization device according to another embodiment of the present application.
  • the data synchronization device 300 also includes a building module 304.
  • the building module 304 can construct global data based on each write operation instruction for the global data after the blockchain node starts or resumes running status, and caches the constructed global data into the local storage of the blockchain node.
  • the building module 304 when building global data based on each write operation instruction for global data, can read the write operation instructions for global data from each block of the blockchain, and then read the Each write operation instruction received constructs global data.
  • the acquisition module 302 can persist the write operation instructions stored in the new block to the local storage of the blockchain node.
  • the building module 304 can determine the new blocks on the blockchain during the period when the blockchain node stops running, and store the write operations in each new block. The instructions are persisted to the local storage of the blockchain node, and then global data is constructed based on each write operation instruction persisted in the local storage of the blockchain node.
  • the building module 304 when the building module 304 determines the new block on the blockchain during the period when the blockchain node stops running, it can determine the number of blocks corresponding to the latest persistent write operation instruction on the blockchain node. One block, and then determine the second block on the blockchain with a block sequence number greater than the first block as a new block on the blockchain during the period when the blockchain node stops running.
  • the building module 304 when the building module 304 determines the new block on the blockchain during the period when the blockchain node stops running, it can determine the number of blocks corresponding to the latest persistent write operation instruction on the blockchain node. Three blocks, and based on the timestamp stored in the block on the blockchain, determine the fourth block whose generation time indicated by the corresponding timestamp is later than the third block, and then determine the fourth block as the blockchain node New blocks on the blockchain during the shutdown period.
  • Figure 5 is a schematic diagram of a data synchronization device according to another embodiment of the present application. As shown in Figure 5, based on the data synchronization device shown in Figure 3, the data synchronization device 300 also includes a creation module 305.
  • the creation module 305 may receive at least one write operation instruction for global data, create a new block on the blockchain, and store the received at least one write operation instruction into the created new block.
  • the write operation instructions for global data include at least one of a data addition instruction, a data deletion instruction, and a data modification instruction.
  • Figure 6 is a schematic diagram of a computer device according to an embodiment of the present application.
  • the specific embodiment of the present application does not limit the specific implementation of the computer device.
  • the computer device 600 provided by the embodiment of the present application includes: a processor 602, a communication interface 604, a memory 606, and a communication bus 608. in:
  • the processor 602, communication interface 604, and memory 606 communicate through a communication bus 608.
  • Communication interface 604 is used to communicate with other computer devices or servers.
  • the processor 602 is configured to execute the program 610, and specifically may execute the relevant steps in any of the foregoing data synchronization method embodiments.
  • program 610 may include program code including computer operating instructions.
  • the processor 602 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present application.
  • the one or more processors included in the smart device can be the same type of processor, such as one or more CPUs; or they can be different types of processors, such as one or more CPUs and one or more ASICs.
  • Memory 606 is used to store programs 610.
  • Memory 606 may include high-speed RAM memory and may also include non-volatile memory, such as at least one disk memory.
  • the program 610 can be specifically used to cause the processor 602 to execute the data synchronization method in any of the foregoing embodiments.
  • each step in the program 610 please refer to the corresponding steps and corresponding descriptions in the units in any of the foregoing data synchronization method embodiments, and will not be described again here.
  • Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the above-described devices and modules can be referred to the corresponding process descriptions in the foregoing method embodiments, and will not be described again here.
  • each node included in the distributed system serves as a blockchain node of the blockchain system.
  • the blockchain is used to store write operations for global data, and each blockchain node performs operations on the global data.
  • the corresponding write operation instructions will be stored in the new block of the blockchain, and based on the synchronization mechanism of the blockchain, the new block will be synchronized to the blockchain on each blockchain node, so when monitoring After a new block is generated on the blockchain, the global data in the local cache of the blockchain node can be updated according to the write operation instructions stored in the new block to ensure that the local cache of each blockchain node has the same global data. Achieve data consistency between nodes in the distributed system.
  • each node locally caches the latest global data, if any node fails, other nodes can still operate normally, thus ensuring the reliability of the distributed system operation. Since the write operation instructions for global data are stored on the blockchain, the security of global data can be improved based on the non-tamperable and traceable characteristics of data on the blockchain.
  • the present application also provides a computer-readable storage medium that stores instructions for causing a machine to perform the data synchronization method as described herein.
  • a system or device equipped with a storage medium may be provided, on which the software program code that implements the functions of any of the above embodiments is stored, and the computer (or CPU or MPU) of the system or device ) reads and executes the program code stored in the storage medium.
  • the program code itself read from the storage medium can implement the functions of any one of the above embodiments, and therefore the program code and the storage medium storing the program code form part of this application.
  • Examples of storage media for providing program codes include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), Tapes, non-volatile memory cards and ROM.
  • the program code can be downloaded from the server computer via the communications network.
  • the program code read from the storage medium is written into the memory provided in the expansion board inserted into the computer or written into the memory provided in the expansion module connected to the computer, and then based on the program code
  • the instructions cause the CPU installed on the expansion board or expansion module to perform part or all of the actual operations, thereby realizing the functions of any of the above embodiments.
  • Embodiments of the present application also provide a computer program product, which is tangibly stored on a computer-readable medium and includes computer-executable instructions that, when executed, cause at least one processor to Execute the data synchronization method provided by the above embodiments. It should be understood that each solution in this embodiment has the corresponding technical effects in the above method embodiment, and will not be described again here.
  • the execution order of each step is not fixed and can be adjusted as needed.
  • the system structure described in the above embodiments may be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or may be implemented by multiple Some components in separate devices are implemented together.
  • the hardware module can be implemented mechanically or electrically.
  • a hardware module may include permanently dedicated circuitry or logic (such as a specialized processor, FPGA, or ASIC) to complete the corresponding operation.
  • Hardware modules may also include programmable logic or circuits (such as general-purpose processors or other programmable processors), which can be temporarily set by software to complete corresponding operations.
  • the specific implementation method mechanical method, or dedicated permanent circuit, or temporarily installed circuit

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The present application provides a data synchronization method and apparatus, a computer device and a storage medium, which are applied to a blockchain node. The data synchronization method comprises: monitoring generation of a new block on a blockchain, wherein the blockchain is used for storing a write operation instruction for global data (101); after it is monitored that the new block is generated on the blockchain, acquiring the write operation instruction stored in the new block (102); and updating, according to the write operation instruction stored in the new block, the global data locally cached by the blockchain node (103). According to the present solution, data security is improved while data consistency is ensured.

Description

数据同步方法、装置、计算机设备和存储介质Data synchronization method, device, computer equipment and storage medium 技术领域Technical field
本申请涉及数据处理技术领域,尤其涉及一种数据同步方法、装置、计算机设备和存储介质。The present application relates to the field of data processing technology, and in particular, to a data synchronization method, device, computer equipment and storage medium.
背景技术Background technique
在一些应用场景下,分布式系统需要保持数据的一致性,例如分布式系统包括有多个通信模块,用户需要确定每个通信模块的状态,每个通信模块需要确定其他通信模块的在线状态,即需要保证通信模块状态数据在各通信模块之间的一致性。In some application scenarios, the distributed system needs to maintain data consistency. For example, the distributed system includes multiple communication modules. The user needs to determine the status of each communication module, and each communication module needs to determine the online status of other communication modules. That is, it is necessary to ensure the consistency of communication module status data between communication modules.
目前,为了实现分布式系统中数据的一致性,将分布式系统的数据存储在数据库、文件系统等中心化存储中,分布式系统包括的所有节点都与中心化存储进行数据交互,从而保证各节点能够从中心化存储读取一致的数据。Currently, in order to achieve data consistency in distributed systems, the data of distributed systems are stored in centralized storage such as databases and file systems. All nodes included in the distributed system interact with centralized storage to ensure that each Nodes are able to read consistent data from centralized storage.
然而,将数据存储在中心化存储存在单点问题,中心化存储发生故障会导致各节点无法读取数据,整个分布式系统将无法正常运行,而且存储在中心化存储的数据容易被篡改,导致数据的安全性较低。However, there is a single point problem in storing data in centralized storage. Failure of the centralized storage will cause each node to be unable to read the data, and the entire distributed system will not be able to operate normally. Moreover, the data stored in the centralized storage is easily tampered with, resulting in Data is less secure.
发明内容Contents of the invention
有鉴于此,本申请提供的数据同步方法、装置、计算机设备和存储介质,可以在保证数据一致性的前提下,提高数据的安全性。In view of this, the data synchronization method, device, computer equipment and storage medium provided by this application can improve data security while ensuring data consistency.
根据本申请实施例的第一方面,提供了一种数据同步方法,应用于区块链节点,所述数据同步方法包括:监测区块链上新区块的生成,其中,所述区块链用于存储针对全局数据的写操作指令;在监测到所述区块链上有新区块生成后,获取所述新区块中存储的写操作指令;根据所述新区块中存储的写操作指令,对所述区块链节点本地缓存的全局数据进行更新。由于每个节点本地缓存有最新的全局数据,任何一个节点故障其他节点仍能够正常运行,从而可以保证分布式系统运行的可靠性。由于针对全局数据的写操作指令存储在区块链上,基于区块链上数据不可篡改和可追溯的特性,可以提高全局数据的安全性。According to the first aspect of the embodiment of the present application, a data synchronization method is provided, which is applied to a blockchain node. The data synchronization method includes: monitoring the generation of new blocks on the blockchain, wherein the blockchain uses To store write operation instructions for global data; after monitoring that a new block is generated on the blockchain, obtain the write operation instructions stored in the new block; according to the write operation instructions stored in the new block, perform The global data cached locally by the blockchain node is updated. Since each node locally caches the latest global data, if any node fails, other nodes can still operate normally, thus ensuring the reliability of the distributed system operation. Since the write operation instructions for global data are stored on the blockchain, the security of global data can be improved based on the non-tamperable and traceable characteristics of data on the blockchain.
在一种可能的实现方式中,在所述区块链节点启动或恢复运行状态后,基于针对全局数据的各写操作指令构建全局数据,并将构建的全局数据缓存到区块链节点的本地存储中,区块链节点的用户需要访问全局数据时,可以直接访问缓存在区块链节点本地存储的全局数据, 降低对全局数据进行访问的延时,提高了用户的使用体验。In a possible implementation, after the blockchain node starts or resumes its running state, the global data is constructed based on each write operation instruction for the global data, and the constructed global data is cached locally in the blockchain node. In storage, when users of the blockchain node need to access global data, they can directly access the global data cached locally on the blockchain node, which reduces the delay in accessing global data and improves the user experience.
在一种可能的实现方式中,所述基于针对全局数据的各写操作指令构建全局数据,包括:从所述区块链的各区块中读取针对全局数据的写操作指令;根据读取到的各写操作指令构建全局数据。基于区块链上数据不可篡改和可追溯的特性,从区块链上读取写操作指令来构建全局数据,保证了所构建全局数据的准确性,而且可以保证区块链节点之间全局数据的一致性。In a possible implementation, constructing global data based on each write operation instruction for global data includes: reading the write operation instructions for global data from each block of the blockchain; Each write operation instruction constructs global data. Based on the non-tamperable and traceable characteristics of data on the blockchain, the write operation instructions are read from the blockchain to construct global data, which ensures the accuracy of the constructed global data and ensures global data between blockchain nodes. consistency.
在一种可能的实现方式中,所述方法还包括:将所述新区块中存储的写操作指令持久化到所述区块链节点的本地存储;所述基于针对全局数据的各写操作指令构建全局数据,包括:确定在所述区块链节点停止运行期间所述区块链上的新增区块;将各所述新增区块中存储的写操作指令持久化到所述区块链节点的本地存储;根据所述区块链节点的本地存储持久化的各写操作指令,构建全局数据。在监测到区块链上有新区块生成后,将新区块中存储的写操作指令持久化到区块链节点的本地存储,区块链节点每次启动后或恢复运行状态后,可以基于本地存储中持久化的写操作指令来构建全局数据,而无需对区块链的每个区块进行读取以获得各写操作指令,缩短构建全局数据所需的时间,提高构建全局数据的效率。In a possible implementation, the method further includes: persisting the write operation instructions stored in the new block to the local storage of the blockchain node; the writing operation instructions based on the global data Constructing global data includes: determining new blocks on the blockchain during the period when the blockchain node stops running; persisting the write operation instructions stored in each of the new blocks to the block Local storage of the chain node; construct global data according to each write operation instruction persisted in the local storage of the blockchain node. After detecting that a new block is generated on the blockchain, the write operation instructions stored in the new block are persisted to the local storage of the blockchain node. After each blockchain node is started or restored to operating status, it can be based on the local The persistent write operation instructions in the storage are used to construct global data, without the need to read each block of the blockchain to obtain each write operation instruction, which shortens the time required to construct global data and improves the efficiency of constructing global data.
在一种可能的实现方式中,所述确定在所述区块链节点停止运行期间所述区块链上的新增区块,包括:确定所述区块链节点上最新持久化的写操作指令对应的第一区块;将所述区块链上区块序号大于第一区块的第二区块确定为所述区块链节点停止运行期间所述区块链上的新增区块。由于区块链上区块的区块序号按照生成时间依次递增,因此在确定存储区块链节点上最新持久化的写操作指令的第一区块后,可以根据第一区块的区块序号和区块链上各区块的区块序号,确定区块链节点停止运行期间生成的新增区块,保证可以将各新增区块存储的写操作指令持久化到区块链节点的本地存储,进而在基于区块链节点上持久化的写操作指令构建全局数据时,保证所构建全局数据的准确性。In one possible implementation, determining the newly added blocks on the blockchain during the period when the blockchain node stops running includes: determining the latest persistent write operation on the blockchain node. The first block corresponding to the instruction; determine the second block on the blockchain with a block sequence number greater than the first block as a new block on the blockchain during the period when the blockchain node stops running. . Since the block sequence numbers of blocks on the blockchain increase sequentially according to the generation time, after determining the first block that stores the latest persistent write operation instructions on the blockchain node, the block sequence number of the first block can be and the block sequence number of each block on the blockchain to determine the new blocks generated when the blockchain node stops running, ensuring that the write operation instructions stored in each new block can be persisted to the local storage of the blockchain node , and then when constructing global data based on persistent write operation instructions on the blockchain node, the accuracy of the constructed global data is guaranteed.
在一种可能的实现方式中,所述确定在所述区块链节点停止运行期间所述区块链上的新增区块,包括:确定所述区块链节点上最新持久化的写操作指令对应的第三区块;根据所述区块链上区块中存储的时间戳,确定对应时间戳所指示生成时间晚于所述第三区块的第四区块;将所述第四区块确定为所述区块链节点停止运行期间所述区块链上的新增区块。由于区块链上的区块按时间顺序依次生成,新的写操作指令存储在新的区块中,因此在确定存储区块链节点上最新持久化的写操作指令的第三区块后,可以根据第三区块中存储的时间戳和区块链上各区块中存储的时间戳,确定出生成时间晚于第三区块的第四区块,进而将各第四区块确定为区块链节点停止运行期间生成的新增区块,保证可以将各新增区块存储的写操作指令都持久化到区块链节点的本地存储,进而可以保证所全局数据的准确性。In one possible implementation, determining the newly added blocks on the blockchain during the period when the blockchain node stops running includes: determining the latest persistent write operation on the blockchain node. Instruct the third block corresponding to the instruction; according to the timestamp stored in the block on the blockchain, determine the fourth block whose generation time indicated by the corresponding timestamp is later than that of the third block; transfer the fourth block The block is determined to be a newly added block on the blockchain during the period when the blockchain node stops running. Since blocks on the blockchain are generated sequentially in chronological order, and new write operation instructions are stored in new blocks, after determining the third block that stores the latest persistent write operation instructions on the blockchain node, According to the timestamp stored in the third block and the timestamp stored in each block on the blockchain, the fourth block whose generation time is later than the third block can be determined, and then each fourth block can be determined as a block. The new blocks generated when the blockchain node stops running ensure that the write operation instructions stored in each new block can be persisted to the local storage of the blockchain node, thus ensuring the accuracy of the global data.
在一种可能的实现方式中,所述方法还包括:接收针对全局数据的至少一个写操作指令;在所述区块链上创建新区块,并将接收到的所述至少一个写操作指令存储到创建的新区块中。将生成新区块存储当前区块链节点对全局数据的写操作指令,从而每个区块链节点都可以将对全局数据的写操作指令存储到区块链上,而且可以根据区块链上存储的写操作指令对全局数据进行更新,基于区块链的同步机制,可以保证全局数据在各区块链节点之间的一致性,还能够保证对全局数据进行同步的及时性。In a possible implementation, the method further includes: receiving at least one write operation instruction for global data; creating a new block on the blockchain, and storing the received at least one write operation instruction. into the new block created. A new block will be generated to store the current blockchain node’s write operation instructions for global data, so that each blockchain node can store the write operation instructions for global data on the blockchain, and can store the global data according to the instructions on the blockchain. The write operation instructions update the global data. The synchronization mechanism based on the blockchain can ensure the consistency of the global data among the blockchain nodes and also ensure the timeliness of synchronizing the global data.
在一种可能的实现方式中,针对全局数据的写操作指令包括数据新增指令、数据删除指令和数据修改指令中的至少一个。通过新增、删除和修改等方式改变全局数据的写操作指令,均会被存储到区块链上,使得每个区块链节点对全局数据的各种改变均能够同步给其他区块链节点,保证区块链节点之间对全局数据进行同步的可靠性和有效性。In a possible implementation, the write operation instructions for global data include at least one of a data addition instruction, a data deletion instruction, and a data modification instruction. Write operation instructions that change global data by adding, deleting, modifying, etc. will be stored on the blockchain, so that various changes to global data by each blockchain node can be synchronized to other blockchain nodes. , ensuring the reliability and effectiveness of global data synchronization between blockchain nodes.
根据本申请实施例的第二方面,提供了一种数据同步装置,应用于区块链节点,所述数据同步装置包括:监测模块,用于监测区块链上新区块的生成,其中,所述区块链用于存储针对全局数据的写操作指令;获取模块,用于在所述监测模块监测到所述区块链上有新区块生成后,获取所述新区块中存储的写操作指令;更新模块,用于根据所述新区块中存储的写操作指令,对所述区块链节点本地缓存的全局数据进行更新。According to the second aspect of the embodiment of the present application, a data synchronization device is provided, which is applied to a blockchain node. The data synchronization device includes: a monitoring module for monitoring the generation of new blocks on the blockchain, wherein: The blockchain is used to store write operation instructions for global data; the acquisition module is used to obtain the write operation instructions stored in the new block after the monitoring module detects that a new block is generated on the blockchain. ; Update module, used to update the global data cached locally by the blockchain node according to the write operation instructions stored in the new block.
根据本申请实施例的第三方面,提供了一种计算机设备,包括:处理器、通信接口、存储器和通信总线,所述处理器、所述存储器和所述通信接口通过所述通信总线完成相互间的通信;所述存储器用于存放至少一可执行指令,所述可执行指令使所述处理器执行上述第一方面所提供数据同步方法对应的操作。According to a third aspect of the embodiment of the present application, a computer device is provided, including: a processor, a communication interface, a memory, and a communication bus. The processor, the memory, and the communication interface complete each other through the communication bus. communication between; the memory is used to store at least one executable instruction, the executable instruction causes the processor to perform operations corresponding to the data synchronization method provided in the first aspect.
根据本申请实施例的第四方面,提供了一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机指令,所述计算机指令在被处理器执行时,使所述处理器执行上述第一方面所提供数据同步方法对应的操作。According to a fourth aspect of the embodiment of the present application, a computer-readable storage medium is provided. Computer instructions are stored on the computer-readable storage medium. When executed by a processor, the computer instructions cause the processor to execute Operations corresponding to the data synchronization method provided in the above first aspect.
根据本申请实施例的第五方面,提供了一种计算机程序产品,所述计算机程序产品被有形地存储在计算机可读介质上并且包括计算机可执行指令,所述计算机可执行指令在被执行时使至少一个处理器执行如上述第一方面或第一方面的任一可能的实现方式提供的数据同步方法。According to a fifth aspect of the embodiments of the present application, a computer program product is provided, which is tangibly stored on a computer-readable medium and includes computer-executable instructions, which when executed At least one processor is caused to execute the data synchronization method provided by the above-mentioned first aspect or any possible implementation of the first aspect.
由上述技术方案,分布式系统包括的各节点作为区块链系统的区块链节点,区块链用于存储针对全局数据的写操作,每个区块链节点对全局数据执行写操作后,均会在区块链的新区块中存储对应的写操作指令,而且基于区块链的同步机制,新区块会同步到每个区块链节点上的区块链,因此在监测到区块链上有新区块生成后,可以根据新区块中存储到写操作指令,对区块链节点本地缓存的全局数据进行更新,保证每个区块链节点本地缓存有相同的全局数据,实现了分布式系统中各节点间数据的一致性。由于每个节点本地缓存有最新的全局 数据,任何一个节点故障其他节点仍能够正常运行,从而可以保证分布式系统运行的可靠性。由于针对全局数据的写操作指令存储在区块链上,基于区块链上数据不可篡改和可追溯的特性,可以提高全局数据的安全性。According to the above technical solution, each node included in the distributed system serves as a blockchain node of the blockchain system. The blockchain is used to store write operations for global data. After each blockchain node performs a write operation on global data, The corresponding write operation instructions will be stored in the new block of the blockchain, and based on the synchronization mechanism of the blockchain, the new block will be synchronized to the blockchain on each blockchain node, so when monitoring the blockchain After a new block is generated, the global data cached locally by the blockchain node can be updated according to the write operation instructions stored in the new block, ensuring that the local cache of each blockchain node has the same global data, realizing distributed Data consistency between nodes in the system. Since each node locally caches the latest global data, other nodes can still operate normally if any node fails, thus ensuring the reliability of the distributed system operation. Since the write operation instructions for global data are stored on the blockchain, the security of global data can be improved based on the non-tamperable and traceable characteristics of data on the blockchain.
附图说明Description of the drawings
图1是本申请一个实施例的数据同步方法的流程图;Figure 1 is a flow chart of a data synchronization method according to an embodiment of the present application;
图2是本申请另一个实施例的数据同步方法的流程图;Figure 2 is a flow chart of a data synchronization method according to another embodiment of the present application;
图3是本申请一个实施例的数据同步装置的示意图;Figure 3 is a schematic diagram of a data synchronization device according to an embodiment of the present application;
图4是本申请另一个实施例的数据同步装置的示意图;Figure 4 is a schematic diagram of a data synchronization device according to another embodiment of the present application;
图5是本申请又一个实施例的数据同步装置的示意图;Figure 5 is a schematic diagram of a data synchronization device according to another embodiment of the present application;
图6是本申请一个实施例的计算机设备的示意图。Figure 6 is a schematic diagram of a computer device according to an embodiment of the present application.
附图标记列表:List of reference signs:
100:数据同步方法        200:数据同步方法       300:数据同步装置100: Data synchronization method 200: Data synchronization method 300: Data synchronization device
600:计算机设备          301:监测模块           302:获取模块600: Computer equipment 301: Monitoring module 302: Acquisition module
303:更新模块            304:构建模块           305:创建模块303: Update module 304: Build module 305: Create module
602:处理器              604:通信接口           606:存储器602: Processor 604: Communication interface 606: Memory
608:通信总线            610:程序608: Communication bus 610: Program
101~103:方法100的步骤  201~206:方法200的步骤101~103: Steps of Method 100 201~206: Steps of Method 200
具体实施方式Detailed ways
如前所述,为了实现分布式系统中数据的一致性,目前采取的技术手段为将分布式系统的数据存储在中心化存储,比如数据库、文件系统等,分布式系统包括的每个节点都与中心化存储进行数据交互,即所有节点均对统一存储在中心化存储上的数据进行写操作,并从中心化存储上读取数据,从而保证了各节点之间数据的一致性。然而,将各节点的数据存储在中心化存储上存在单点问题,当中心化存储发生故障时,会导致所有节点都无法对中心化存储进行读写,进而整个分布式系统将无法正常运行,而且中心化存储上的数据容易被篡改,导致数据的安全性较低。As mentioned before, in order to achieve data consistency in distributed systems, the current technical means is to store the data of distributed systems in centralized storage, such as databases, file systems, etc. Each node included in the distributed system Data interaction with centralized storage means that all nodes write data uniformly stored on the centralized storage and read data from the centralized storage, thus ensuring the consistency of data between nodes. However, there is a single point problem in storing the data of each node on the centralized storage. When the centralized storage fails, all nodes will be unable to read and write to the centralized storage, and the entire distributed system will not be able to operate normally. Moreover, data on centralized storage is easily tampered with, resulting in low data security.
本申请实施例中,通过构建区块链系统,使分布式系统中的每个节点均为区块链节点,每个节点对全局数据进行写操作时,将相应的写操作指令存储到区块链上,基于区块链的同步机制,每个写操作指令均会被同步到各节点的区块链上,进而每个节点均可以从区块链上读取新的写操作指令,并基于读取到的写操作指令对全局数据进行更新,从而保证各节点间 全局数据的同步。由于每个节点均可以根据区块链上存储的写操作指令获得最新的全局数据,任何一个节点故障其他节点仍能够正常运行,从而可以保证分布式系统运行的可靠性。由于针对全局数据的写操作指令存储在区块链上,基于区块链上数据不可篡改和可追溯的特性,可以提高全局数据的安全性。In the embodiment of this application, by constructing a blockchain system, each node in the distributed system is a blockchain node. When each node performs a write operation on global data, the corresponding write operation instructions are stored in the block. On the chain, based on the synchronization mechanism of the blockchain, each write operation instruction will be synchronized to the blockchain of each node, and then each node can read the new write operation instruction from the blockchain, and based on The read write operation instructions update the global data to ensure the synchronization of global data between nodes. Since each node can obtain the latest global data based on the write operation instructions stored on the blockchain, if any node fails, other nodes can still operate normally, thus ensuring the reliability of the distributed system operation. Since the write operation instructions for global data are stored on the blockchain, the security of global data can be improved based on the non-tamperable and traceable characteristics of data on the blockchain.
下面结合附图对本申请实施例提供的数据同步方法、装置、计算机设备和存储介质进行详细说明。The data synchronization method, device, computer equipment and storage medium provided by the embodiments of the present application will be described in detail below with reference to the accompanying drawings.
数据同步方法Data synchronization method
图1是本申请实施例提供的一种数据同步方法的流程图,该数据同步方法应用于区块链节点,区块链系统包括有多个区块链节点,分布式系统中的每个节点都是一个区块链节点,每个区块链节点上存储有完整的区块链,各区块链节点之间通过同步机制,保证各区块链节点上区块链中所存储数据的一致性。如图1所示,数据同步方法100包括如下步骤:Figure 1 is a flow chart of a data synchronization method provided by an embodiment of the present application. The data synchronization method is applied to blockchain nodes. The blockchain system includes multiple blockchain nodes. Each node in the distributed system They are all a blockchain node, and each blockchain node stores a complete blockchain. The synchronization mechanism between each blockchain node ensures the consistency of the data stored in the blockchain on each blockchain node. As shown in Figure 1, the data synchronization method 100 includes the following steps:
步骤101、监测区块链上新区块的生成,其中,区块链用于存储针对全局数据的写操作指令。Step 101: Monitor the generation of new blocks on the blockchain, where the blockchain is used to store write operation instructions for global data.
当其中一个区块链节点对全局数据执行写操作后,区块链上会生成新区块,用于存储与该写操作相对应的写操作指令。一个区块链节点上区块链有新区块生成后,基于区块链的同步机制,各区块链节点上区块链会同步生成新区块,保证各区块链节点上区块链中存储有相同的数据。When one of the blockchain nodes performs a write operation on global data, a new block will be generated on the blockchain to store the write operation instructions corresponding to the write operation. After a new block is generated in the blockchain on a blockchain node, based on the synchronization mechanism of the blockchain, the blockchain on each blockchain node will generate new blocks simultaneously to ensure that the same blocks are stored in the blockchain on each blockchain node. The data.
写操作指令用于指示对全局数据进行的写操作,全局数据是由分布式系统中的节点共同维护,即全局数据由多个区块链节点同步维护,写操作包括对全局数据的新增、删除和修改。比如,写操作指令可以指示在全局数据中新增了数据a,还可以指示将全局数据中数据b删除,还可以指示对全局数据中的数据c进行修改。Write operation instructions are used to instruct the write operation of global data. Global data is jointly maintained by nodes in the distributed system, that is, global data is maintained synchronously by multiple blockchain nodes. Write operations include adding new global data, Delete and modify. For example, a write operation instruction can indicate that data a is added to the global data, data b in the global data is deleted, or data c in the global data is modified.
需要说明的,一个新区块可以存储一条或多条写操作指令。当一个新区块存储多条写操作指令时,该多条写操作指令可以对应于同一个区块链节点对全局数据的写操作,也可以对应不同区块链节点对全局数据的写操作。It should be noted that a new block can store one or more write operation instructions. When a new block stores multiple write operation instructions, the multiple write operation instructions can correspond to the write operation of global data by the same blockchain node, or they can also correspond to the write operation of global data by different blockchain nodes.
步骤102、在监测到区块链上有新区块生成后,获取新区块中存储的写操作指令。Step 102: After detecting that a new block is generated on the blockchain, obtain the write operation instructions stored in the new block.
在区块链节点监测到区块链上有新区块生成后,对区块链上的新区块进行读取,获得存储在新区块中的写操作指令。After the blockchain node detects that a new block is generated on the blockchain, it reads the new block on the blockchain and obtains the write operation instructions stored in the new block.
应理解,区块链上新区块的数量可以是一个或多个,当区块链上新区块的数量为多个时,分别对每个新区块进行读取,以获得每个新区块中存储的写操作指令。It should be understood that the number of new blocks on the blockchain can be one or more. When the number of new blocks on the blockchain is multiple, each new block is read separately to obtain the information stored in each new block. write operation instructions.
步骤103、根据新区块中存储的写操作指令,对区块链节点本地缓存的全局数据进行更新。Step 103: Update the global data cached locally in the blockchain node according to the write operation instructions stored in the new block.
区块链节点本地缓存有全局数据,当获取到新区块中存储的写操作指令后,根据获取到的写操作指令对全局数据进行更新。由于写操作指令指示了某一个或多个区块链节点对全局数据的写操作,新区块中的写操作指令指示了对全局数据的最新写操作,根据新区块中存储的写操作指令对本地缓存的全局数据执行相对应的写操作,保证了各区块链节点的本地存储有相同的全局数据。The blockchain node has global data cached locally. After obtaining the write operation instructions stored in the new block, the global data is updated according to the obtained write operation instructions. Since the write operation instruction indicates the write operation of one or more blockchain nodes to global data, the write operation instruction in the new block indicates the latest write operation to global data. According to the write operation instruction stored in the new block, the local The cached global data performs corresponding write operations, ensuring that the local storage of each blockchain node has the same global data.
在本申请实施例中,分布式系统包括的各节点作为区块链系统的区块链节点,区块链用于存储针对全局数据的写操作,每个区块链节点对全局数据执行写操作后,均会在区块链的新区块中存储对应的写操作指令,而且基于区块链的同步机制,新区块会同步到每个区块链节点上的区块链,因此在监测到区块链上有新区块生成后,可以根据新区块中存储到写操作指令,对区块链节点本地缓存的全局数据进行更新,保证每个区块链节点本地缓存有相同的全局数据,实现了分布式系统中各节点间数据的一致性。由于每个节点本地缓存有最新的全局数据,任何一个节点故障其他节点仍能够正常运行,从而可以保证分布式系统运行的可靠性。由于针对全局数据的写操作指令存储在区块链上,基于区块链上数据不可篡改和可追溯的特性,可以提高全局数据的安全性。In the embodiment of this application, each node included in the distributed system serves as a blockchain node of the blockchain system. The blockchain is used to store write operations for global data. Each blockchain node performs write operations on global data. Afterwards, the corresponding write operation instructions will be stored in the new block of the blockchain, and based on the synchronization mechanism of the blockchain, the new block will be synchronized to the blockchain on each blockchain node, so when the area is monitored After a new block is generated on the blockchain, the global data cached locally by the blockchain node can be updated according to the write operation instructions stored in the new block to ensure that the local cache of each blockchain node has the same global data. This is achieved Data consistency among nodes in a distributed system. Since each node locally caches the latest global data, if any node fails, other nodes can still operate normally, thus ensuring the reliability of the distributed system operation. Since the write operation instructions for global data are stored on the blockchain, the security of global data can be improved based on the non-tamperable and traceable characteristics of data on the blockchain.
在一种可能的实现方式中,在区块链节点启动或恢复运行状态后,可以基于针对全局数据的各写操作指令构建全局数据,并将构建出的全局数据缓存到区块链节点的本地存储。In one possible implementation, after the blockchain node starts or resumes its running state, the global data can be constructed based on each write operation instruction for the global data, and the constructed global data can be cached locally on the blockchain node. storage.
由于写操作指令可以指示对全局数据的新增、删除或修改,针对全局数据的各写操作指令指示了对全局数据的每一次写操作,因此根据全局数据的各写操作指令可以构建最新的全局数据。Since write operation instructions can indicate the addition, deletion or modification of global data, each write operation instruction for global data indicates each write operation for global data, so the latest global data can be constructed based on each write operation instruction for global data. data.
在本申请实施例中,在区块链节点启动或恢复运行状态后,根据全局数据的各写操作指令构建全局数据,并将构建的全局数据缓存在区块链节点本地存储,区块链节点的用户需要访问全局数据时,可以直接访问缓存在区块链节点本地存储的全局数据,降低对全局数据进行访问的延时,提高了用户的使用体验。In the embodiment of this application, after the blockchain node is started or restored to the operating state, the global data is constructed according to each write operation instruction of the global data, and the constructed global data is cached and stored locally in the blockchain node. The blockchain node When users need to access global data, they can directly access the global data cached locally on the blockchain node, which reduces the delay in accessing global data and improves the user experience.
在一种可能的实现方式中,在基于针对全局数据的写操作指令构建全局数据时,可以从区块链的各区块上读取针对全局数据的写操作指令,进而根据读取到的各写操作指令构建全局数据。In one possible implementation, when constructing global data based on write operation instructions for global data, the write operation instructions for global data can be read from each block of the blockchain, and then based on each read write operation instruction Operation instructions build global data.
在本申请实施例中,由于区块链上存储有针对全局数据的全部写操作指令,而根据全局数据的全部写操作指令可以构建出最新的全局数据,因此可以在区块链节点启动或恢复运行状态后,对区块链进行读取,获取区块链上每个区块中存储的写操作指令,进而根据获取到的全部写操作指令构建全局数据。基于区块链上数据不可篡改和可追溯的特性,保证了所构建全局数据的准确性,而且可以保证区块链节点之间全局数据的一致性。In the embodiment of this application, since all write operation instructions for global data are stored on the blockchain, and the latest global data can be constructed based on all write operation instructions for global data, it can be started or restored at the blockchain node. After the running state, the blockchain is read to obtain the write operation instructions stored in each block on the blockchain, and then the global data is constructed based on all the obtained write operation instructions. Based on the non-tamperable and traceable characteristics of data on the blockchain, the accuracy of the global data constructed is guaranteed, and the consistency of global data between blockchain nodes can be guaranteed.
在一种可能的实现方式中,在监测到区块链上有新区块生成后,可以将新区块中存储的写操作指令持久化到区块链节点的本地存储,在此基础上,当区块链节点启动或恢复运行状态后,可以确定区块链节点停止运行期间区块链上的新增区块,即确定当前区块链节点停止运行期间,是否有其他区块链节点对全局数据执行了写操作。如果存在新增区块链,则将新增区块中存储的写操作指令持久化到区块链节点的本地存储,然后根据区块链节点本地存储持久化的各写操作指令,构建全局数据。如果不存在新增区块,则根据区块链节点本地存储已持久化的各写操作指令,构建全局数据。In one possible implementation, after detecting that a new block is generated on the blockchain, the write operation instructions stored in the new block can be persisted to the local storage of the blockchain node. On this basis, when the block After the blockchain node starts or resumes operation, it is possible to determine the new blocks on the blockchain during the period when the blockchain node stops running. That is, it is possible to determine whether other blockchain nodes have access to global data while the current blockchain node stops running. A write operation was performed. If there is a new blockchain, the write operation instructions stored in the new block will be persisted to the local storage of the blockchain node, and then global data will be constructed based on each write operation instruction persisted in the local storage of the blockchain node. . If there is no new block, global data will be constructed based on the persistent write operation instructions stored locally in the blockchain node.
在本申请实施例中,在监测到区块链上有新区块生成后,将新区块中存储的写操作指令持久化到区块链节点的本地存储,区块链节点每次启动后或恢复运行状态后,可以基于本地存储中持久化的写操作指令来构建全局数据,而无需对区块链的每个区块进行读取以获得各写操作指令,缩短构建全局数据所需的时间,提高构建全局数据的效率。In the embodiment of this application, after it is detected that a new block is generated on the blockchain, the write operation instructions stored in the new block are persisted to the local storage of the blockchain node. After each startup or recovery of the blockchain node After the running state, global data can be constructed based on the persistent write operation instructions in local storage without having to read each block of the blockchain to obtain each write operation instruction, shortening the time required to build global data. Improve the efficiency of building global data.
在某一区块链节点停止运行期间,其他区块链节点可能会对全局数据进行一次或多个写操作,进而在该区块链节点停止运行期间区块链上会生成一个或多个新增区块,在该区块链节点启动或恢复运行状态后,可以确定在该区块链节点停止运行期间区块链上的新增区块,并将新增区块中的写操作指令持久化到该区块链节点的本地存储,进而在基于本地存储中持久化的各写操作指令构建全局数据时,能够保证所构建全局数据的准确性,进而保证各区块链节点之间全局数据的一致性。While a certain blockchain node stops running, other blockchain nodes may perform one or more write operations on global data, and then one or more new data will be generated on the blockchain while the blockchain node stops running. Add blocks. After the blockchain node starts or resumes operation, the newly added blocks on the blockchain during the period when the blockchain node stops running can be determined, and the write operation instructions in the newly added blocks can be persisted. into the local storage of the blockchain node, and then when constructing global data based on each write operation instruction persisted in the local storage, the accuracy of the constructed global data can be guaranteed, thereby ensuring the consistency of global data between each blockchain node. consistency.
在一种可能的实现方式中,在确定区块链节点停止运行期间区块链上的新增区块时,可以确定区块链节点上最新持久化的写操作指令对应的第一区块,进而将区块链上区块序号大于第一区块的第二区块确定为区块链节点停止运行期间区块链上的新增区块。In one possible implementation, when determining the new blocks on the blockchain during the period when the blockchain node stops running, the first block corresponding to the latest persistent write operation instruction on the blockchain node can be determined, Then, the second block on the blockchain with a block sequence number greater than the first block is determined as a new block on the blockchain during the period when the blockchain node stops running.
按照区块的生成时间,区块链中区块的序号递增,比如,区块链中第一个区块的区块序号为0,第二个区块的区块序号为1,第N个区块的区块序号为N-1,N为大于2的正整数,因此根据区块序号可以确定区块的生成顺序。According to the generation time of the block, the sequence number of the block in the blockchain increases. For example, the block sequence number of the first block in the blockchain is 0, the block sequence number of the second block is 1, and the block sequence number of the Nth block is 1. The block sequence number of a block is N-1, and N is a positive integer greater than 2. Therefore, the generation order of blocks can be determined based on the block sequence number.
区块链节点本地存储中持久化的每个写操作指令具有区块标识,区块标识为区块链上存储该写操作指令的区块对应的区块序号,根据区块链节点上最新持久化的写操作指令的区块标识,可以确定区块链上存储该最新持久化的写操作指令的第一区块,进而将区块链上区块序号大于第一区块的第二区块确定为新增区块。Each write operation instruction persisted in the local storage of the blockchain node has a block identifier. The block identifier is the block sequence number corresponding to the block on the blockchain where the write operation instruction is stored. According to the latest persistence on the blockchain node The block identifier of the written operation instruction can be used to determine the first block on the blockchain that stores the latest persistent write operation instruction, and then the second block on the blockchain with a block sequence number greater than the first block can be determined. Confirmed as a new block.
如果第一区块的区块序号为N,而区块链上最后一个区块的区块序号也为N,即区块链上各区块中最大的区块序号为N,则不存在第二区块,即区块链节点停止运行期间区块链上没有新增区块。如果第一区块的区块序号为N,而区块链上最后一个区块的区块序号大于N,此时区块链上对应区块序号为N的区块不是区块链上的最后一个区块,此时将区块链上对应 区块序号大于N的各区块确定为新增区块,新增区块的数量可以是一个或多个。If the block sequence number of the first block is N, and the block sequence number of the last block on the blockchain is also N, that is, the largest block sequence number among the blocks on the blockchain is N, then there is no second Block, that is, there are no new blocks on the blockchain during the period when the blockchain node stops running. If the block sequence number of the first block is N, and the block sequence number of the last block on the blockchain is greater than N, then the block corresponding to the block sequence number N on the blockchain is not the last one on the blockchain. Block, at this time, each block on the blockchain with a corresponding block number greater than N is determined as a new block. The number of new blocks can be one or more.
在本申请实施例中,由于区块链上区块的区块序号按照生成时间依次递增,因此在确定存储区块链节点上最新持久化的写操作指令的第一区块后,可以根据第一区块的区块序号和区块链上各区块的区块序号,确定区块链节点停止运行期间生成的新增区块,保证可以将各新增区块存储的写操作指令持久化到区块链节点的本地存储,进而在基于区块链节点上持久化的写操作指令构建全局数据时,保证所构建全局数据的准确性。In this embodiment of the present application, since the block serial numbers of the blocks on the blockchain increase sequentially according to the generation time, after determining the first block that stores the latest persistent write operation instructions on the blockchain node, it can be based on the first block. The block sequence number of a block and the block sequence number of each block on the blockchain determine the new blocks generated when the blockchain node stops running, ensuring that the write operation instructions stored in each new block can be persisted to The local storage of the blockchain node ensures the accuracy of the constructed global data when constructing global data based on persistent write operation instructions on the blockchain node.
在一种可能的实现方式中,在确定区块链节点停止运行期间区块链上的新增区块时,可以确定区块链节点上最新持久化的写操作指令对应的第三区块,进而根据区块链上各区块中存储的时间戳,确定对应时间窗所指示生成时间晚于第三区块的第四区块,进而将第四区块确定为区块链节点停止运行期间区块链上的新增区块。In one possible implementation, when determining the new blocks on the blockchain during the period when the blockchain node stops running, the third block corresponding to the latest persistent write operation instruction on the blockchain node can be determined, Then, based on the timestamps stored in each block on the blockchain, the fourth block whose generation time indicated by the corresponding time window is later than the third block is determined, and then the fourth block is determined as the period during which the blockchain node stops running. New blocks on the blockchain.
区块链中的每个区块,不仅存储有写操作指令,还存储有区块序号和时间戳,时间戳可以指示相应区块的生成时间。由于区块链上的区块按时间顺序依次生成,因此可以根据区块中存储的时间戳确定区块的生成顺序。Each block in the blockchain not only stores write operation instructions, but also stores the block sequence number and timestamp. The timestamp can indicate the generation time of the corresponding block. Since blocks on the blockchain are generated sequentially in chronological order, the order in which blocks are generated can be determined based on the timestamps stored in the blocks.
如果第三区块所存储时间戳指示的区块生成时间,与区块链上最后一个区块所存储时间戳指示的区块生成时间相同,则区块链上的最后一个区块即为第三区块,此时不存在第四区块,即区块链节点停止运行期间区块链上没有新增区块。如果第三区块所存储时间戳指示的区块生成时间,早于区块链上最后一个区块所存储时间戳指示的区块生成时间,则将所存储时间戳指示生成时间晚于第一区块所存储时间戳指示时间的各区块确定为第四区块,进而将各第四区块确定为区块链节点停止运行期间区块链上的新增区块,第四区块的数量可以是一个或多个。If the block generation time indicated by the timestamp stored in the third block is the same as the block generation time indicated by the timestamp stored in the last block on the blockchain, then the last block on the blockchain is the third block. Three blocks, there is no fourth block at this time, that is, there are no new blocks on the blockchain during the period when the blockchain node stops running. If the block generation time indicated by the timestamp stored in the third block is earlier than the block generation time indicated by the timestamp stored in the last block on the blockchain, the generation time indicated by the stored timestamp will be later than that of the first block. Each block whose timestamp indicates the time stored in the block is determined as the fourth block, and each fourth block is determined as a new block on the blockchain during the period when the blockchain node stops operating. The number of fourth blocks Can be one or more.
在本申请实施例中,由于区块链上的区块按时间顺序依次生成,新的写操作指令存储在新的区块中,因此在确定存储区块链节点上最新持久化的写操作指令的第三区块后,可以根据第三区块中存储的时间戳和区块链上各区块中存储的时间戳,确定出生成时间晚于第三区块的第四区块,进而将各第四区块确定为区块链节点停止运行期间生成的新增区块,保证可以将各新增区块存储的写操作指令都持久化到区块链节点的本地存储,进而可以保证所全局数据的准确性。In the embodiment of this application, since the blocks on the blockchain are generated sequentially in chronological order, and new write operation instructions are stored in the new blocks, it is necessary to determine the storage of the latest persistent write operation instructions on the blockchain node. After the third block, the fourth block whose generation time is later than the third block can be determined based on the timestamp stored in the third block and the timestamps stored in each block on the blockchain, and then each block can be The fourth block is determined to be the new block generated when the blockchain node stops running. It ensures that the write operation instructions stored in each new block can be persisted to the local storage of the blockchain node, thereby ensuring that all the global Accuracy of data.
在一种可能的实现方式中,当用户通过当前区块链节点对全局数据进行写操作时,可以接收针对全局数据的至少一个写操作指令,然后在区块链上创建新区块,并将接收到各写操作指令存储到创建的新区块中。In one possible implementation, when a user writes global data through the current blockchain node, he or she can receive at least one write operation instruction for the global data, and then create a new block on the blockchain and receive Each write operation instruction is stored in the new block created.
在当前区块链节点的用户对全局数据进行新增、删除或修改时,可以接收对全局数据进行新增、删除或修改时对应的写操作指令,然后在区块链上创建新区块,并将接收到的写操 作指令存储到新区块中,基于区块链的同步机制,当前区块链节点创建的新区块,会被同步到其他各区块链节点上的区块链,使得其他各区块链节点可以基于区块链上的新区块进行全局数据更新,保证各区块链节点之间全局数据的一致性。When the user of the current blockchain node adds, deletes or modifies global data, he or she can receive the corresponding write operation instructions when adding, deleting or modifying global data, and then create a new block on the blockchain, and Store the received write operation instructions into a new block. Based on the synchronization mechanism of the blockchain, the new block created by the current blockchain node will be synchronized to the blockchain on other blockchain nodes, making other blocks Chain nodes can update global data based on new blocks on the blockchain to ensure the consistency of global data between blockchain nodes.
在本申请实施例中,区块链节点不仅可以根据新区块更新其他区块链节点对全局数据的写操作,还将生成新区块存储当前区块链节点对全局数据的写操作指令,从而每个区块链节点都可以将对全局数据的写操作指令存储到区块链上,而且可以根据区块链上存储的写操作指令对全局数据进行更新,基于区块链的同步机制,可以保证全局数据在各区块链节点之间的一致性,还能够保证对全局数据进行同步的及时性。In the embodiment of this application, the blockchain node can not only update the writing operations of other blockchain nodes on global data based on the new block, but also generate new blocks to store the writing operation instructions of the current blockchain node on global data, so that every Each blockchain node can store the write operation instructions for global data on the blockchain, and can update the global data based on the write operation instructions stored on the blockchain. Based on the synchronization mechanism of the blockchain, it can be guaranteed The consistency of global data among various blockchain nodes can also ensure the timeliness of synchronizing global data.
在一种可能的实现方式中,针对全局数据的写操作指令包括数据新增指令、数据删除指令和数据修改指令中的至少一个。In a possible implementation, the write operation instructions for global data include at least one of a data addition instruction, a data deletion instruction, and a data modification instruction.
数据新增指令用于在全局数据中新增数据条目,比如,全局数据包括数据1至数据100共计100条数据,数据新增指令用于指示在全局数据中新增数据101,基于该数据新增指令对全局数据进行写操作后,全局数据包括数据1至数据101共计101条数据。The data new instruction is used to add new data entries in the global data. For example, the global data includes data 1 to data 100, a total of 100 data. The data new instruction is used to instruct the new data 101 in the global data. Based on this data, After the add instruction writes the global data, the global data includes data 1 to data 101, a total of 101 pieces of data.
数据删除指令用于删除全局数据中的数据条目,比如,全局数据包括数据1至数据101共计101条数据,数据删除指令用于指示将全局数据中的数据1和数据2删除,基于该数据删除指令对全局数据进行写操作后,全局数据包括数据3至数据101共计99条数据。The data deletion instruction is used to delete data entries in the global data. For example, the global data includes data 1 to data 101, a total of 101 pieces of data. The data deletion instruction is used to instruct the deletion of data 1 and data 2 in the global data. Based on the data deletion After the instruction writes the global data, the global data includes a total of 99 pieces of data from data 3 to data 101.
数据修改指令用于对全局数据中的一个或多个数据条目进行修改,比如,全局数据包括数据1至数据100统计100条数据,数据修改指令用于指示对全局数据中的数据10进行修改,基于该数据修改指令对全局进行写操作后,全局数据中的数据10被修改为数据10′。The data modification instruction is used to modify one or more data items in the global data. For example, the global data includes data 1 to data 100, which counts 100 pieces of data. The data modification instruction is used to instruct data 10 in the global data to be modified. After the global write operation is performed based on this data modification instruction, data 10 in the global data is modified to data 10'.
在本申请实施例中,写操作指令包括数据新增指令、数据删除指令和数据修改指令中的至少一个,因此,通过新增、删除和修改等方式改变全局数据的写操作指令,均会被存储到区块链上,使得每个区块链节点对全局数据的各种改变均能够同步给其他区块链节点,保证区块链节点之间对全局数据进行同步的可靠性和有效性。In the embodiment of the present application, the write operation instructions include at least one of a data addition instruction, a data deletion instruction, and a data modification instruction. Therefore, any write operation instruction that changes global data through addition, deletion, modification, etc. will be Stored on the blockchain, all changes made by each blockchain node to global data can be synchronized to other blockchain nodes, ensuring the reliability and effectiveness of global data synchronization between blockchain nodes.
图2是本申请另一个实施例的数据同步方法的流程图。如图2所示,该数据同步方法200包括如下步骤:Figure 2 is a flow chart of a data synchronization method according to another embodiment of the present application. As shown in Figure 2, the data synchronization method 200 includes the following steps:
步骤201、区块链节点启动或恢复运行状态后,将新增区块中存储的写操作指令持久化到区块链节点的本地存储。Step 201: After the blockchain node starts or resumes operation, persist the write operation instructions stored in the newly added block to the local storage of the blockchain node.
区块链节点启动或恢复运行状态后,确定区块链节点停止运行区间区块链上的新增区块链,进而将各新增区块中存储的写操作指令持久化到区块链节点的本地存储。After the blockchain node starts or resumes operation, it is determined that the blockchain node stops running the new blockchain on the interval blockchain, and then the write operation instructions stored in each new block are persisted to the blockchain node. local storage.
需要说明的是,前述实施例对新增区块的确定方法已进行了详细说明,在此不再进行赘述。It should be noted that the method for determining new blocks has been described in detail in the foregoing embodiments, and will not be described again here.
步骤202、加载区块链节点本地存储中持久化的各写操作指令。Step 202: Load each write operation instruction persisted in the local storage of the blockchain node.
区块链上各区块中存储的写操作指令均会被持久化到区块链节点的本地存储。在区块链上不存在新增区块时,加载区块链节点停止运行之前已持久化到区块链节点的本地存储中的各写操作指令。在区块链上存在新增区块时,将各新增区块中存储的写操作指令持久化到区块链节点的本地存储后,加载区块链节点的本地存储中持久化的各写操作指令。The write operation instructions stored in each block on the blockchain will be persisted to the local storage of the blockchain node. When there is no new block on the blockchain, load each write operation instruction that has been persisted to the local storage of the blockchain node before the blockchain node stops running. When there is a new block on the blockchain, after persisting the write operation instructions stored in each new block to the local storage of the blockchain node, load each write operation instruction persisted in the local storage of the blockchain node. Operating instructions.
步骤203、根据各写操作指令构建全局数据,并在区块链节点本地存储缓存全局数据。Step 203: Construct global data according to each write operation instruction, and store and cache the global data locally on the blockchain node.
在加载区块链节点本地存储中持久化的各写操作指令后,按对应写操作的时间顺序,依次对各个写操作指令进行重执行,构建全局数据,并将所构建的全局数据缓存在区块链节点的本地存储。After loading each write operation instruction persisted in the local storage of the blockchain node, each write operation instruction is re-executed in sequence according to the time sequence of the corresponding write operation, the global data is constructed, and the constructed global data is cached in the area. Local storage of blockchain nodes.
步骤204、监测区块链上新区块的生成。Step 204: Monitor the generation of new blocks on the blockchain.
区块链节点处于运行状态时,检测区块链上新区块的生成。需要说明的是,区块链上新区块的生成方法及区块链的同步方法,可以通过创新的方法实现,也可以通过现有的方式实现,对此本申请实施例不作限定。When the blockchain node is in running state, it detects the generation of new blocks on the blockchain. It should be noted that the generation method of new blocks on the blockchain and the synchronization method of the blockchain can be implemented through innovative methods or through existing methods, which are not limited by the embodiments of this application.
步骤205、判断区块链上是否有新区块生成,如果是Y,执行步骤206,如果否N,执行步骤204。Step 205: Determine whether a new block is generated on the blockchain. If yes, execute step 206. If not, execute step 204.
步骤206、根据新区块中存储的写操作指令,对全局数据进行更新。Step 206: Update the global data according to the write operation instructions stored in the new block.
在确定区块链上有新区块生成时,说明有区块链节点对全局数据进行了写操作,而新区块中存储的写操作指令指示了对全局数据所进行的写操作,将新区块中存储的写操作指令持久化到区块链节点的本地存储,并根据新区块中存储的写操作指令对本地缓存的全局数据进行更新,实现各区块链节点之间全局数据的同步。When it is determined that a new block is generated on the blockchain, it means that a blockchain node has written to the global data, and the write operation instructions stored in the new block indicate the write operation to the global data, and the new block will The stored write operation instructions are persisted to the local storage of the blockchain node, and the local cached global data is updated according to the write operation instructions stored in the new block to achieve global data synchronization between each blockchain node.
比如,区块链节点可以监控PLC、传感器等被监控设备的在线状态,全局数据为在线的被监控设备的数量,当前在线的被监控设备的数量为0,即全局数据等于0,在相继有两个被监控设备上线和一个被监控设备下线时,对全局数据的更新过程为0+1+1-1,更新后全局数据等于1。For example, blockchain nodes can monitor the online status of monitored devices such as PLCs and sensors. The global data is the number of monitored devices online. The number of monitored devices currently online is 0, that is, the global data is equal to 0. When two monitored devices come online and one monitored device goes offline, the update process of the global data is 0+1+1-1, and the global data after the update is equal to 1.
数据同步装置Data synchronization device
图3是本申请一个实施例的数据同步装置的示意图,该数据同步装置应用于区块链节点,如图3所示,该数据同步装置300包括:Figure 3 is a schematic diagram of a data synchronization device according to an embodiment of the present application. The data synchronization device is applied to a blockchain node. As shown in Figure 3, the data synchronization device 300 includes:
监测模块301,用于监测区块链上新区块的生成,其中,区块链用于存储针对全局数据的写操作指令; Monitoring module 301 is used to monitor the generation of new blocks on the blockchain, where the blockchain is used to store write operation instructions for global data;
获取模块302,用于在监测模块监测到区块链上有新区块生成后,获取新区块中存储的写操作指令;The acquisition module 302 is used to acquire the write operation instructions stored in the new block after the monitoring module detects that a new block is generated on the blockchain;
更新模块303,用于根据新区块中存储的写操作指令,对区块链节点本地缓存的全局数据进行更新。The update module 303 is used to update the global data cached locally by the blockchain node according to the write operation instructions stored in the new block.
在本申请实施例中,监测模块301可用于执行上述方法实施例中的步骤101,获取模块302可用于执行上述方法实施例中的步骤102,更新模块303可用于执行上述方法实施例中的步骤103。In this embodiment of the present application, the monitoring module 301 can be used to perform step 101 in the above method embodiment, the acquisition module 302 can be used to perform step 102 in the above method embodiment, and the update module 303 can be used to perform the steps in the above method embodiment. 103.
图4是本申请另一个实施例的数据同步装置的示意图,如图4所示,在图3所示数据同步装置的基础上,该数据同步装置300还包括构建模块304。构建模块304可以在区块链节点启动或恢复运行状态后,基于针对全局数据的各写操作指令构建全局数据,并将构建的全局数据缓存到区块链节点的本地存储中。Figure 4 is a schematic diagram of a data synchronization device according to another embodiment of the present application. As shown in Figure 4, based on the data synchronization device shown in Figure 3, the data synchronization device 300 also includes a building module 304. The building module 304 can construct global data based on each write operation instruction for the global data after the blockchain node starts or resumes running status, and caches the constructed global data into the local storage of the blockchain node.
在一种可能的实现方式中,构建模块304在基于针对全局数据的各写操作指令构建全局数据时,可以从区块链的各区块中读取针对全局数据的写操作指令,进而根据读取到的各写操作指令构建全局数据。In a possible implementation, when building global data based on each write operation instruction for global data, the building module 304 can read the write operation instructions for global data from each block of the blockchain, and then read the Each write operation instruction received constructs global data.
在一种可能的实现方式中,获取模块302可以将新区块中存储的写操作指令持久化到区块链节点的本地存储。构建模块304在基于针对全局数据的各写操作指令构建全局数据时,可以确定在区块链节点停止运行期间区块链上的新增区块,并将各新增区块中存储的写操作指令持久化到区块链节点的本地存储,进而根据区块链节点的本地存储持久化的各写操作指令,构建全局数据。In a possible implementation, the acquisition module 302 can persist the write operation instructions stored in the new block to the local storage of the blockchain node. When building the global data based on each write operation instruction for the global data, the building module 304 can determine the new blocks on the blockchain during the period when the blockchain node stops running, and store the write operations in each new block. The instructions are persisted to the local storage of the blockchain node, and then global data is constructed based on each write operation instruction persisted in the local storage of the blockchain node.
在一种可能的实现方式中,构建模块304在确定在区块链节点停止运行期间区块链上的新增区块时,可以确定区块链节点上最新持久化的写操作指令对应的第一区块,进而将区块链上区块序号大于第一区块的第二区块确定为区块链节点停止运行期间区块链上的新增区块。In a possible implementation, when the building module 304 determines the new block on the blockchain during the period when the blockchain node stops running, it can determine the number of blocks corresponding to the latest persistent write operation instruction on the blockchain node. One block, and then determine the second block on the blockchain with a block sequence number greater than the first block as a new block on the blockchain during the period when the blockchain node stops running.
在一种可能的实现方式中,构建模块304在确定在区块链节点停止运行期间区块链上的新增区块时,可以确定区块链节点上最新持久化的写操作指令对应的第三区块,并根据区块链上区块中存储的时间戳,确定对应时间戳所指示生成时间晚于第三区块的第四区块,进而将第四区块确定为区块链节点停止运行期间区块链上的新增区块。In a possible implementation, when the building module 304 determines the new block on the blockchain during the period when the blockchain node stops running, it can determine the number of blocks corresponding to the latest persistent write operation instruction on the blockchain node. Three blocks, and based on the timestamp stored in the block on the blockchain, determine the fourth block whose generation time indicated by the corresponding timestamp is later than the third block, and then determine the fourth block as the blockchain node New blocks on the blockchain during the shutdown period.
图5是本申请又一个实施例的数据同步装置的示意图,如图5所示,在图3所示数据同步装置的基础上,该数据同步装置300还包括创建模块305。创建模块305可以接收针对全局数据的至少一个写操作指令,并在区块链上创建新区块,并将接收到的至少一个写操作指令存储到创建的新区块中。Figure 5 is a schematic diagram of a data synchronization device according to another embodiment of the present application. As shown in Figure 5, based on the data synchronization device shown in Figure 3, the data synchronization device 300 also includes a creation module 305. The creation module 305 may receive at least one write operation instruction for global data, create a new block on the blockchain, and store the received at least one write operation instruction into the created new block.
在一种可能的实现方式中,针对全局数据的写操作指令包括数据新增指令、数据删除指令和数据修改指令中的至少一个。In a possible implementation, the write operation instructions for global data include at least one of a data addition instruction, a data deletion instruction, and a data modification instruction.
需要说明的是,上述数据同步装置内的各模块之间的信息交互、执行过程等内容,由于 与前述数据同步方法实施例基于同一构思,具体内容可参见前述数据同步方法实施例中的叙述,此处不再赘述。It should be noted that the information interaction, execution process, etc. between the modules in the above-mentioned data synchronization device are based on the same concept as the aforementioned data synchronization method embodiment. For specific content, please refer to the description in the aforementioned data synchronization method embodiment. No further details will be given here.
计算机设备computer equipment
图6是本申请一个实施例的计算机设备的示意图,本申请具体实施例并不对计算机设备的具体实现做限定。参见图6,本申请实施例提供的计算机设备600包括:处理器602、通信接口604、存储器606、以及通信总线608。其中:Figure 6 is a schematic diagram of a computer device according to an embodiment of the present application. The specific embodiment of the present application does not limit the specific implementation of the computer device. Referring to Figure 6, the computer device 600 provided by the embodiment of the present application includes: a processor 602, a communication interface 604, a memory 606, and a communication bus 608. in:
处理器602、通信接口604、以及存储器606通过通信总线608完成通信。The processor 602, communication interface 604, and memory 606 communicate through a communication bus 608.
通信接口604,用于与其它计算机设备或服务器进行通信。 Communication interface 604 is used to communicate with other computer devices or servers.
处理器602,用于执行程序610,具体可以执行前述任一数据同步方法实施例中的相关步骤。The processor 602 is configured to execute the program 610, and specifically may execute the relevant steps in any of the foregoing data synchronization method embodiments.
具体地,程序610可以包括程序代码,该程序代码包括计算机操作指令。Specifically, program 610 may include program code including computer operating instructions.
处理器602可以是中央处理器CPU,或者是特定集成电路ASIC(Application Specific Integrated Circuit),或者是被配置成实施本申请实施例的一个或多个集成电路。智能设备包括的一个或多个处理器,可以是同一类型的处理器,如一个或多个CPU;也可以是不同类型的处理器,如一个或多个CPU以及一个或多个ASIC。The processor 602 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present application. The one or more processors included in the smart device can be the same type of processor, such as one or more CPUs; or they can be different types of processors, such as one or more CPUs and one or more ASICs.
存储器606,用于存储程序610。存储器606可以包含高速RAM存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器。 Memory 606 is used to store programs 610. Memory 606 may include high-speed RAM memory and may also include non-volatile memory, such as at least one disk memory.
程序610具体可以用于使得处理器602执行前述任一实施例中的数据同步方法。The program 610 can be specifically used to cause the processor 602 to execute the data synchronization method in any of the foregoing embodiments.
程序610中各步骤的具体实现可以参见前述任一数据同步方法实施例中的相应步骤和单元中对应的描述,在此不赘述。所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的设备和模块的具体工作过程,可以参考前述方法实施例中的对应过程描述,在此不再赘述。For the specific implementation of each step in the program 610, please refer to the corresponding steps and corresponding descriptions in the units in any of the foregoing data synchronization method embodiments, and will not be described again here. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the above-described devices and modules can be referred to the corresponding process descriptions in the foregoing method embodiments, and will not be described again here.
通过本申请实施例的计算机设备,分布式系统包括的各节点作为区块链系统的区块链节点,区块链用于存储针对全局数据的写操作,每个区块链节点对全局数据执行写操作后,均会在区块链的新区块中存储对应的写操作指令,而且基于区块链的同步机制,新区块会同步到每个区块链节点上的区块链,因此在监测到区块链上有新区块生成后,可以根据新区块中存储到写操作指令,对区块链节点本地缓存的全局数据进行更新,保证每个区块链节点本地缓存有相同的全局数据,实现了分布式系统中各节点间数据的一致性。由于每个节点本地缓存有最新的全局数据,任何一个节点故障其他节点仍能够正常运行,从而可以保证分布式系统运行的可靠性。由于针对全局数据的写操作指令存储在区块链上,基于区块链上数据不可篡改和可追溯的特性,可以提高全局数据的安全性。Through the computer equipment of the embodiment of the present application, each node included in the distributed system serves as a blockchain node of the blockchain system. The blockchain is used to store write operations for global data, and each blockchain node performs operations on the global data. After the write operation, the corresponding write operation instructions will be stored in the new block of the blockchain, and based on the synchronization mechanism of the blockchain, the new block will be synchronized to the blockchain on each blockchain node, so when monitoring After a new block is generated on the blockchain, the global data in the local cache of the blockchain node can be updated according to the write operation instructions stored in the new block to ensure that the local cache of each blockchain node has the same global data. Achieve data consistency between nodes in the distributed system. Since each node locally caches the latest global data, if any node fails, other nodes can still operate normally, thus ensuring the reliability of the distributed system operation. Since the write operation instructions for global data are stored on the blockchain, the security of global data can be improved based on the non-tamperable and traceable characteristics of data on the blockchain.
计算机可读存储介质computer readable storage media
本申请还提供了一种计算机可读存储介质,存储用于使一机器执行如本文所述的数据同步方法的指令。具体地,可以提供配有存储介质的系统或者装置,在该存储介质上存储着实现上述实施例中任一实施例的功能的软件程序代码,且使该系统或者装置的计算机(或CPU或MPU)读出并执行存储在存储介质中的程序代码。The present application also provides a computer-readable storage medium that stores instructions for causing a machine to perform the data synchronization method as described herein. Specifically, a system or device equipped with a storage medium may be provided, on which the software program code that implements the functions of any of the above embodiments is stored, and the computer (or CPU or MPU) of the system or device ) reads and executes the program code stored in the storage medium.
在这种情况下,从存储介质读取的程序代码本身可实现上述实施例中任何一项实施例的功能,因此程序代码和存储程序代码的存储介质构成了本申请的一部分。In this case, the program code itself read from the storage medium can implement the functions of any one of the above embodiments, and therefore the program code and the storage medium storing the program code form part of this application.
用于提供程序代码的存储介质实施例包括软盘、硬盘、磁光盘、光盘(如CD-ROM、CD-R、CD-RW、DVD-ROM、DVD-RAM、DVD-RW、DVD+RW)、磁带、非易失性存储卡和ROM。可选择地,可以由通信网络从服务器计算机上下载程序代码。Examples of storage media for providing program codes include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), Tapes, non-volatile memory cards and ROM. Alternatively, the program code can be downloaded from the server computer via the communications network.
此外,应该清楚的是,不仅可以通过执行计算机所读出的程序代码,而且可以通过基于程序代码的指令使计算机上操作的操作系统等来完成部分或者全部的实际操作,从而实现上述实施例中任意一项实施例的功能。In addition, it should be clear that the above embodiments can be implemented not only by executing the program code read by the computer, but also by causing the operating system etc. operating on the computer to complete some or all of the actual operations through instructions based on the program code. function of any embodiment.
此外,可以理解的是,将由存储介质读出的程序代码写到插入计算机内的扩展板中所设置的存储器中或者写到与计算机相连接的扩展模块中设置的存储器中,随后基于程序代码的指令使安装在扩展板或者扩展模块上的CPU等来执行部分和全部实际操作,从而实现上述实施例中任一实施例的功能。In addition, it can be understood that the program code read from the storage medium is written into the memory provided in the expansion board inserted into the computer or written into the memory provided in the expansion module connected to the computer, and then based on the program code The instructions cause the CPU installed on the expansion board or expansion module to perform part or all of the actual operations, thereby realizing the functions of any of the above embodiments.
计算机程序产品computer program product
本申请实施例还提供了一种计算机程序产品,所述计算机程序产品被有形地存储在计算机可读介质上并且包括计算机可执行指令,所述计算机可执行指令在被执行时使至少一个处理器执行上述各实施例提供的数据同步方法。应理解,本实施例中的各方案具有上述方法实施例中对应的技术效果,此处不再赘述。Embodiments of the present application also provide a computer program product, which is tangibly stored on a computer-readable medium and includes computer-executable instructions that, when executed, cause at least one processor to Execute the data synchronization method provided by the above embodiments. It should be understood that each solution in this embodiment has the corresponding technical effects in the above method embodiment, and will not be described again here.
需要说明的是,上述各流程和各系统结构图中不是所有的步骤和模块都是必须的,可以根据实际的需要忽略某些步骤或模块。各步骤的执行顺序不是固定的,可以根据需要进行调整。上述各实施例中描述的系统结构可以是物理结构,也可以是逻辑结构,即,有些模块可能由同一物理实体实现,或者,有些模块可能分由多个物理实体实现,或者,可以由多个独立设备中的某些部件共同实现。It should be noted that not all steps and modules in the above-mentioned processes and system structure diagrams are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in the above embodiments may be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or may be implemented by multiple Some components in separate devices are implemented together.
以上各实施例中,硬件模块可以通过机械方式或电气方式实现。例如,一个硬件模块可以包括永久性专用的电路或逻辑(如专门的处理器,FPGA或ASIC)来完成相应操作。硬件模块还可以包括可编程逻辑或电路(如通用处理器或其它可编程处理器),可以由软件进行临 时的设置以完成相应操作。具体的实现方式(机械方式、或专用的永久性电路、或者临时设置的电路)可以基于成本和时间上的考虑来确定。In the above embodiments, the hardware module can be implemented mechanically or electrically. For example, a hardware module may include permanently dedicated circuitry or logic (such as a specialized processor, FPGA, or ASIC) to complete the corresponding operation. Hardware modules may also include programmable logic or circuits (such as general-purpose processors or other programmable processors), which can be temporarily set by software to complete corresponding operations. The specific implementation method (mechanical method, or dedicated permanent circuit, or temporarily installed circuit) can be determined based on cost and time considerations.
上文通过附图和优选实施例对本申请进行了详细展示和说明,然而本申请不限于这些已揭示的实施例,基与上述多个实施例本领域技术人员可以知晓,可以组合上述不同实施例中的代码审核手段得到本申请更多的实施例,这些实施例也在本申请的保护范围之内。The present application has been shown and described in detail through the drawings and preferred embodiments above. However, the present application is not limited to these disclosed embodiments. Based on the above-mentioned multiple embodiments, those skilled in the art will know that different above-mentioned embodiments can be combined. The code review means in this application can lead to more embodiments of this application, and these embodiments are also within the protection scope of this application.

Claims (12)

  1. 一种数据同步方法(100),应用于区块链节点,所述数据同步方法包括:A data synchronization method (100), applied to blockchain nodes, the data synchronization method includes:
    监测区块链上新区块的生成,其中,所述区块链用于存储针对全局数据的写操作指令;Monitor the generation of new blocks on a blockchain used to store write operation instructions for global data;
    在监测到所述区块链上有新区块生成后,获取所述新区块中存储的写操作指令;After monitoring that a new block is generated on the blockchain, obtain the write operation instructions stored in the new block;
    根据所述新区块中存储的写操作指令,对所述区块链节点本地缓存的全局数据进行更新。According to the write operation instructions stored in the new block, the global data cached locally by the blockchain node is updated.
  2. 根据权利要求1所述的方法,其中,所述方法还包括:The method of claim 1, further comprising:
    在所述区块链节点启动或恢复运行状态后,基于针对全局数据的各写操作指令构建全局数据,并将构建的全局数据缓存到区块链节点的本地存储中。After the blockchain node is started or restored to operating status, global data is constructed based on each write operation instruction for global data, and the constructed global data is cached in the local storage of the blockchain node.
  3. 根据权利要求2所述的方法,其中,所述基于针对全局数据的各写操作指令构建全局数据,包括:The method according to claim 2, wherein said constructing global data based on each write operation instruction for global data includes:
    从所述区块链的各区块中读取针对全局数据的写操作指令;Read write operation instructions for global data from each block of the blockchain;
    根据读取到的各写操作指令构建全局数据。Build global data based on each read write operation instruction.
  4. 根据权利要求2所述的方法,其中,所述方法还包括:将所述新区块中存储的写操作指令持久化到所述区块链节点的本地存储;The method according to claim 2, wherein the method further comprises: persisting the write operation instructions stored in the new block to the local storage of the blockchain node;
    所述基于针对全局数据的各写操作指令构建全局数据,包括:The construction of global data based on each write operation instruction for global data includes:
    确定在所述区块链节点停止运行期间所述区块链上的新增区块;Determine new blocks on the blockchain during the period when the blockchain node stops operating;
    将各所述新增区块中存储的写操作指令持久化到所述区块链节点的本地存储;Persist the write operation instructions stored in each newly added block to the local storage of the blockchain node;
    根据所述区块链节点的本地存储持久化的各写操作指令,构建全局数据。Global data is constructed according to each write operation instruction persisted in the local storage of the blockchain node.
  5. 根据权利要求4所述的方法,其中,所述确定在所述区块链节点停止运行期间所述区块链上的新增区块,包括:The method according to claim 4, wherein the determining of new blocks on the blockchain during the period when the blockchain node stops operating includes:
    确定所述区块链节点上最新持久化的写操作指令对应的第一区块;Determine the first block corresponding to the latest persistent write operation instruction on the blockchain node;
    将所述区块链上区块序号大于第一区块的第二区块确定为所述区块链节点停止运行期间所述区块链上的新增区块。The second block on the blockchain with a block sequence number greater than the first block is determined as a new block on the blockchain during the period when the blockchain node stops running.
  6. 根据权利要求4所述的方法,其中,所述确定在所述区块链节点停止运行期间所述区块链上的新增区块,包括:The method according to claim 4, wherein the determining of new blocks on the blockchain during the period when the blockchain node stops operating includes:
    确定所述区块链节点上最新持久化的写操作指令对应的第三区块;Determine the third block corresponding to the latest persistent write operation instruction on the blockchain node;
    根据所述区块链上区块中存储的时间戳,确定对应时间戳所指示生成时间晚于所述第三区块的第四区块;According to the timestamp stored in the block on the blockchain, determine the fourth block whose generation time indicated by the corresponding timestamp is later than the third block;
    将所述第四区块确定为所述区块链节点停止运行期间所述区块链上的新增区块。The fourth block is determined to be a newly added block on the blockchain during the period when the blockchain node stops operating.
  7. 根据权利要求1所述的方法,其中,所述方法还包括:The method of claim 1, further comprising:
    接收针对全局数据的至少一个写操作指令;Receive at least one write operation instruction for global data;
    在所述区块链上创建新区块,并将接收到的所述至少一个写操作指令存储到创建的新区 块中。Create a new block on the blockchain, and store the received at least one write operation instruction into the created new block.
  8. 根据权利要求1-7中任一所述的方法,其中,针对全局数据的写操作指令包括数据新增指令、数据删除指令和数据修改指令中的至少一个。The method according to any one of claims 1 to 7, wherein the write operation instructions for global data include at least one of a data addition instruction, a data deletion instruction and a data modification instruction.
  9. 一种数据同步装置(300),应用于区块链节点,所述数据同步装置(300)包括:A data synchronization device (300), applied to blockchain nodes, the data synchronization device (300) includes:
    监测模块(301),用于监测区块链上新区块的生成,其中,所述区块链用于存储针对全局数据的写操作指令;Monitoring module (301), used to monitor the generation of new blocks on the blockchain, where the blockchain is used to store write operation instructions for global data;
    获取模块(302),用于在所述监测模块监测到所述区块链上有新区块生成后,获取所述新区块中存储的写操作指令;The acquisition module (302) is used to acquire the write operation instructions stored in the new block after the monitoring module detects that a new block is generated on the blockchain;
    更新模块(303),用于根据所述新区块中存储的写操作指令,对所述区块链节点本地缓存的全局数据进行更新。An update module (303), configured to update the global data cached locally by the blockchain node according to the write operation instructions stored in the new block.
  10. 一种计算机设备(600),包括:处理器(602)、通信接口(604)、存储器(606)和通信总线(608),所述处理器(602)、所述存储器(606)和所述通信接口(604)通过所述通信总线(608)完成相互间的通信;A computer device (600), including: a processor (602), a communication interface (604), a memory (606) and a communication bus (608), the processor (602), the memory (606) and the The communication interface (604) completes mutual communication through the communication bus (608);
    所述存储器(606)用于存放至少一可执行指令,所述可执行指令使所述处理器(602)执行如权利要求1-8中任一项所述的数据同步方法(100)对应的操作。The memory (606) is used to store at least one executable instruction. The executable instruction causes the processor (602) to execute the data synchronization method (100) corresponding to any one of claims 1-8. operate.
  11. 一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机指令,所述计算机指令在被处理器执行时,使所述处理器执行权利要求1-8中任一项所述的方法。A computer-readable storage medium. Computer instructions are stored on the computer-readable storage medium. When executed by a processor, the computer instructions cause the processor to execute the method described in any one of claims 1-8. method.
  12. 一种计算机程序产品,所述计算机程序产品被有形地存储在计算机可读介质上并且包括计算机可执行指令,所述计算机可执行指令在被执行时使至少一个处理器执行根据权利要求1-8中任一项所述的方法。A computer program product tangibly stored on a computer-readable medium and comprising computer-executable instructions which, when executed, cause at least one processor to perform a process according to claims 1-8 any one of the methods.
PCT/CN2022/089570 2022-04-27 2022-04-27 Data synchronization method and apparatus, computer device and storage medium WO2023206142A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/CN2022/089570 WO2023206142A1 (en) 2022-04-27 2022-04-27 Data synchronization method and apparatus, computer device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2022/089570 WO2023206142A1 (en) 2022-04-27 2022-04-27 Data synchronization method and apparatus, computer device and storage medium

Publications (1)

Publication Number Publication Date
WO2023206142A1 true WO2023206142A1 (en) 2023-11-02

Family

ID=88516636

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/089570 WO2023206142A1 (en) 2022-04-27 2022-04-27 Data synchronization method and apparatus, computer device and storage medium

Country Status (1)

Country Link
WO (1) WO2023206142A1 (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107944034A (en) * 2017-12-13 2018-04-20 国云科技股份有限公司 A kind of non-differentiation method of data based on block chain
CN108683738A (en) * 2018-05-16 2018-10-19 腾讯科技(深圳)有限公司 The calculating task dissemination method of diagram data processing method and diagram data
CN112597241A (en) * 2020-12-10 2021-04-02 浙江大学 Block chain-based distributed database storage method and system
US20210374693A1 (en) * 2020-05-26 2021-12-02 Derek Norman La Salle System and method for a decentralized portable information container supporting privacy protected digital information credentialing, remote administration, local validation, access control and remote instruction signaling utilizing blockchain distributed ledger and container wallet technologies

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107944034A (en) * 2017-12-13 2018-04-20 国云科技股份有限公司 A kind of non-differentiation method of data based on block chain
CN108683738A (en) * 2018-05-16 2018-10-19 腾讯科技(深圳)有限公司 The calculating task dissemination method of diagram data processing method and diagram data
US20210374693A1 (en) * 2020-05-26 2021-12-02 Derek Norman La Salle System and method for a decentralized portable information container supporting privacy protected digital information credentialing, remote administration, local validation, access control and remote instruction signaling utilizing blockchain distributed ledger and container wallet technologies
CN112597241A (en) * 2020-12-10 2021-04-02 浙江大学 Block chain-based distributed database storage method and system

Similar Documents

Publication Publication Date Title
US9367598B2 (en) Merging an out of synchronization indicator and a change recording indicator in response to a failure in consistency group formation
CN106815218B (en) Database access method and device and database system
CN108121782B (en) Distribution method of query request, database middleware system and electronic equipment
US20150213100A1 (en) Data synchronization method and system
US11188560B2 (en) Synchronizing object in local object storage node
US9229970B2 (en) Methods to minimize communication in a cluster database system
US20160041885A1 (en) Data Replicating System, Data Replicating Method, Node Device, Management Device and Computer Readable Medium
CN107451013B (en) Data recovery method, device and system based on distributed system
US11748215B2 (en) Log management method, server, and database system
US10048978B2 (en) Apparatus and method for identifying a virtual machine having changeable settings
CN103138912A (en) Data synchronizing method and data synchronizing system
US20180139280A1 (en) Methods and apparatuses for cluster switching
CN110019510A (en) A kind of method and device carrying out increment synchronization
CN112052230A (en) Multi-machine room data synchronization method, computing equipment and storage medium
CN110121712B (en) Log management method, server and database system
JPWO2015087509A1 (en) State storage / restoration apparatus, state storage / restoration method, and program
CN112000850B (en) Method, device, system and equipment for processing data
WO2023206142A1 (en) Data synchronization method and apparatus, computer device and storage medium
CN116303789A (en) Parallel synchronization method and device for multi-fragment multi-copy database and readable medium
CN112988880A (en) Data synchronization method and device, electronic equipment and computer storage medium
CN115328931A (en) Database cluster data verification method and device, storage medium and electronic equipment
US20120030155A1 (en) Model generating device and model generating method
CN113806309A (en) Metadata deleting method, system, terminal and storage medium based on distributed lock
CN111984460B (en) Metadata recovery method and device
CN110770702B (en) Information processing device, information processing system, information processing method, and recording medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22938996

Country of ref document: EP

Kind code of ref document: A1