Data synchronization method, device, equipment and storage medium

By obtaining and synchronizing the blockchain data in the data synchronization system, the problem of the difficulty of blockchain data query is solved, and efficient data synchronization and query have been achieved.

CN114564538BActive Publication Date: 2025-01-28CHINA UNIONPAY
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210153240.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-18
Publication Date
2025-01-28
Estimated Expiration
2042-02-18

AI Technical Summary

Technical Problem

When using KV format to store business data in blockchain, the business application system cannot directly query the data on the blockchain through structured query statements, which increases the difficulty of data query.

Method used

Through the data synchronization system, obtain the data to be synchronized from the blockchain system, and synchronize it to the database, and use the structured query capabilities of the database to achieve efficient query of blockchain data.

Benefits of technology

The complexity and time of data synchronization have been reduced, and the problem that cannot directly query the blockchain data is solved, and the efficient query and synchronization of the blockchain data is realized.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114564538B_ABST
    Figure CN114564538B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides a data synchronization method, device, equipment and storage medium, which relates to the field of blockchain technology. The method includes: a data synchronization system obtains data to be synchronized from a blockchain system, wherein the data to be synchronized carries a corresponding target data identifier. If the target data identifier does not exist in the key information cache area of ​​the data synchronization system, the target data identifier is added to the key information cache area, and the data to be synchronized is synchronized to the database. The data synchronization system not only receives the data update notification event sent by the blockchain system, obtains the data to be synchronized from the data update notification event, but also periodically pulls the data to be synchronized from the blockchain system, thereby enhancing the real-time and integrity of data synchronization. Since the data in the blockchain is consistent with the data in the database, the business application system can query the data in the database through a structured query statement, thereby solving the problem of being unable to query data on the blockchain.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of blockchain technology, and in particular to a data synchronization method, device, equipment and storage medium. Background Art

[0002] In order to achieve the purpose of data security sharing, enterprises have the need to store data in the blockchain. Since the business data on the blockchain is stored in the KV (key-value) format, when the business application system needs to query the business data in the blockchain, the business application system cannot directly query the business data on the blockchain through structured query statements. Therefore, using blockchain to store data increases the difficulty of querying this part of data. Summary of the invention

[0003] Embodiments of the present application provide a data synchronization method, apparatus, device, and storage medium for improving the timeliness of data synchronization.

[0004] On the one hand, an embodiment of the present application provides a data synchronization method, the method comprising:

[0005] Acquire the data to be synchronized from the blockchain system, the data to be synchronized carries the corresponding target data identifier, and the data to be synchronized is written into the blockchain system by the business application system through the blockchain operation;

[0006] If the target data identifier does not exist in the key information buffer area of ​​the data synchronization system, the target data identifier is added to the key information buffer area, and the data to be synchronized is synchronized to the database.

[0007] Optionally, obtaining the data to be synchronized from the blockchain system includes:

[0008] Receiving a data update event notification sent by the blockchain system, and obtaining the data to be synchronized from the data update event notification, wherein the data synchronization system subscribes to the data update event in the blockchain system in advance; or

[0009] The data to be synchronized is periodically pulled from the blockchain system.

[0010] Optionally, it also includes:

[0011] If the target data identifier exists in the key information cache area, then obtaining the historical synchronization state and historical update time corresponding to the target data identifier from the key information cache area;

[0012] If the historical synchronization state is synchronized, and the historical update time is earlier than the target update time carried by the data to be synchronized, the historical update time is updated to the target update time, the historical synchronization state is updated to synchronizing, and the data to be synchronized is synchronized to the database.

[0013] Optionally, it also includes:

[0014] If the historical synchronization state is in sync, and the data synchronization duration is greater than the synchronization duration threshold, the historical update time is updated to the target update time, the historical synchronization state is updated to in sync, and the data to be synchronized is synchronized to the database;

[0015] If the historical synchronization state is in synchronization, and the data synchronization time is less than or equal to the synchronization duration threshold, the process ends.

[0016] Optionally, it also includes:

[0017] If the data to be synchronized is successfully synchronized to the database, the historical synchronization status is updated to synchronized;

[0018] If the data to be synchronized fails to be synchronized to the database, the historical synchronization status is updated to synchronization failure.

[0019] Optionally, periodically pulling the data to be synchronized from the blockchain system includes:

[0020] Based on the historical synchronization data pulled in the previous cycle, the target block height for data pulling in the current cycle is determined at the corresponding historical block height in the blockchain system;

[0021] Based on the target block height, the corresponding target block in the blockchain system is determined, and the data in the target block is pulled as the data to be synchronized.

[0022] On the one hand, an embodiment of the present application provides a data synchronization device, the device comprising:

[0023] An acquisition module is used to acquire the data to be synchronized from the blockchain system, wherein the data to be synchronized carries a corresponding target data identifier, and the data to be synchronized is written into the blockchain system by the business application system through a blockchain operation;

[0024] The judgment module is used to add the target data identifier to the key information cache area if the target data identifier does not exist in the key information cache area of ​​the data synchronization system, and synchronize the data to be synchronized into the database.

[0025] Optionally, the acquisition module is specifically used for:

[0026] Receiving a data update event notification sent by the blockchain system, and obtaining the data to be synchronized from the data update event notification, wherein the data synchronization system subscribes to the data update event in the blockchain system in advance; or

[0027] The data to be synchronized is periodically pulled from the blockchain system.

[0028] Optionally, the judging module is further used for:

[0029] If the target data identifier exists in the key information cache area, then obtaining the historical synchronization state and historical update time corresponding to the target data identifier from the key information cache area;

[0030] If the historical synchronization state is synchronized, and the historical update time is earlier than the target update time carried by the data to be synchronized, the historical update time is updated to the target update time, the historical synchronization state is updated to synchronizing, and the data to be synchronized is synchronized to the database.

[0031] Optionally, the judging module is further used for:

[0032] If the historical synchronization state is in sync, and the data synchronization duration is greater than the synchronization duration threshold, the historical update time is updated to the target update time, the historical synchronization state is updated to in sync, and the data to be synchronized is synchronized to the database;

[0033] If the historical synchronization state is in synchronization, and the data synchronization time is less than or equal to the synchronization duration threshold, the process ends.

[0034] Optionally, the judging module is further used for:

[0035] If the data to be synchronized is successfully synchronized to the database, the historical synchronization status is updated to synchronized;

[0036] If the data to be synchronized fails to be synchronized to the database, the historical synchronization status is updated to synchronization failure.

[0037] Optionally, the acquisition module is specifically used for:

[0038] Based on the historical synchronization data pulled in the previous cycle, the target block height for data pulling in the current cycle is determined at the corresponding historical block height in the blockchain system;

[0039] Based on the target block height, the corresponding target block in the blockchain system is determined, and the data in the target block is pulled as the data to be synchronized.

[0040] On the one hand, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned data synchronization method when executing the program.

[0041] On the one hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program executable by a computer device. When the program is run on the computer device, the computer device executes the steps of the above-mentioned data synchronization method.

[0042] In an embodiment of the present application, the data synchronization system obtains the data to be synchronized from the blockchain system, wherein the data to be synchronized carries the corresponding target data identifier, and the data to be synchronized is written into the blockchain system by the business application system through the blockchain operation. If the target data identifier does not exist in the key information cache area of ​​the data synchronization system, the target data identifier is added to the key information cache area, and the data to be synchronized is synchronized to the database. Since the data to be synchronized is synchronized to the database while being added to the blockchain system, the complexity of data synchronization is reduced and the data synchronization time is reduced. Since the data in the blockchain system is consistent with the data in the database, the business application system can query the data in the database through structured query statements, which solves the problem of being unable to query data on the blockchain. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0044] Figure 1 A schematic diagram of a system architecture provided for an embodiment of the present application;

[0045] Figure 2 A flowchart of a data synchronization method provided in an embodiment of the present application;

[0046] Figure 3 A flowchart of a data synchronization method provided in an embodiment of the present application;

[0047] Figure 4 A schematic diagram of the structure of a data synchronization device provided in an embodiment of the present application;

[0048] Figure 5 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solution and beneficial effects of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0050] refer to Figure 1 , which is a data synchronization system architecture diagram applicable to an embodiment of the present application. The data synchronization system architecture at least includes a business application system 101, a blockchain system 102, a data synchronization system 103 and a database 104.

[0051] The business application system 101, the blockchain system 102, the data synchronization system 103 and the database 104 are the backend servers of the data synchronization application, providing services for the data synchronization application. The business application system 101 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.

[0052] The blockchain system 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.

[0053] The data synchronization system 103 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), as well as big data and artificial intelligence platforms.

[0054] Database 104 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), as well as big data and artificial intelligence platforms.

[0055] The business application system 101 is connected to the blockchain system 102, and can be directly or indirectly connected through wired or wireless communication, which is not limited in this application. The blockchain system 102 is connected to the data synchronization system 103, and can be directly or indirectly connected through wired or wireless communication, which is not limited in this application. The data synchronization system 103 is connected to the database 104, and can be directly or indirectly connected through wired or wireless communication, which is not limited in this application.

[0056] The business application system 101 writes the data to be synchronized into the blockchain system 102 through blockchain operation, and the data synchronization system 103 obtains the data to be synchronized from the blockchain system 102, wherein the data to be synchronized carries the corresponding target data identifier. If the target data identifier does not exist in the key information cache area of ​​the data synchronization system, the target data identifier is added to the key information cache area, and the data to be synchronized is synchronized to the database.

[0057] based on Figure 1 The data synchronization system architecture diagram, the present application embodiment provides a process of a data synchronization method, such as Figure 2 As shown, the process of this method is Figure 1 The data synchronization system 103 shown in the figure performs the following steps:

[0058] Step S201, obtaining data to be synchronized from the blockchain system.

[0059] Specifically, the data to be synchronized obtained from the blockchain system can be one or more. The following data to be synchronized defaults to one. The data to be synchronized is written into the blockchain system by the business application system through blockchain operations.

[0060] There are two ways to obtain the data to be synchronized from the blockchain system. The data synchronization system executes two methods of obtaining the data to be synchronized at the same time, as follows:

[0061] Method 1: The data synchronization system receives the data update event notification sent by the blockchain system, and obtains the data to be synchronized from the data update event notification.

[0062] Among them, the data synchronization system subscribes to data update events in the blockchain system in advance, and the data update event notification sent by the blockchain system includes any one of the data addition operations, data deletion operations, and data modification operations performed by the business application system on the blockchain system.

[0063] Method 2: The data synchronization system periodically pulls the data to be synchronized from the blockchain system.

[0064] Specifically, the data synchronization system determines the target block height for data pulling in the current cycle based on the historical synchronization data pulled in the previous cycle and the corresponding historical block height in the blockchain system. Then, based on the target block height, the corresponding target block in the blockchain system is determined, and the data in the target block is pulled as the data to be synchronized.

[0065] The target block height is greater than the historical block height. The blocks between the target block height and the historical block height are used as target blocks. The number of target blocks determined in each cycle can be the same or different. The target block can be one block or multiple blocks. For example, if the historical block height is 6 and the target block height is 8, the blocks with a block height of 7 and a block height of 8 are used as target blocks.

[0066] In the present application, since the data synchronization system simultaneously executes the above two methods to obtain the data to be synchronized, the problem of inconsistent data synchronization caused by a failure in one of the methods when obtaining the data to be synchronized is avoided.

[0067] The data to be synchronized carries the corresponding target data identifier, as well as other data identifiers (one or more), target update time, target update method, etc. corresponding to the target data identifier. The target data identifier and target update time are selected from the data to be synchronized as data key information, and the target synchronization state is added to the data key information, and the target synchronization state is set to "synchronizing".

[0068] Among them, other data identifiers are data identifiers other than the target data identifier in the data to be synchronized. For example, if the data to be synchronized includes 4 data identifiers, namely order number, merchant name, product name, and consumer name, the order number is used as the target data identifier, and the merchant name, product name, and consumer name are used as other data identifiers.

[0069] The target update time is the time when the business application system writes the data to be synchronized into the blockchain system through blockchain operations.

[0070] When the data synchronization system receives the data update event notification sent by the blockchain system and obtains the data to be synchronized from the data update event notification, the target update mode is the receiving mode; when the data synchronization system periodically pulls the data to be synchronized from the blockchain system, the target update mode is the pulling mode.

[0071] Step S202: If the target data identifier does not exist in the key information cache area of ​​the data synchronization system, the target data identifier is added to the key information cache area, and the data to be synchronized is synchronized to the database.

[0072] Specifically, if the target data identifier does not exist in the key information cache of the data synchronization system, the target data identifier is added to the key information cache as a historical data identifier. At the same time, the target update time corresponding to the target data identifier in the data key information is added to the key information cache as the historical update time; the target synchronization state corresponding to the target data identifier is added to the key information cache as the historical synchronization state.

[0073] If the data to be synchronized is successfully synchronized to the database, the historical synchronization status corresponding to the data to be synchronized in the key information cache area is updated to synchronized.

[0074] If the data to be synchronized fails to be synchronized to the database, the historical synchronization status corresponding to the data to be synchronized in the key information cache area is updated to synchronization failure.

[0075] For example, the data to be synchronized is shown in Table 1, wherein the target data identifier is 01, other data identifiers are xx, the target update time is 09:00:30, and the target update mode is the receiving mode.

[0076] Table 1.

[0077] Target data identification Other data identifiers Target update time Target update method 01 xx 09:00:30 Receiving method

[0078] The key data information is determined according to the data to be synchronized corresponding to Table 1, as shown in Table 2, wherein the target data identifier is 01, the target update time is 09:00:30, and the target synchronization state is synchronizing.

[0079] Table 2.

[0080]

[0081]

[0082] Two pieces of historical key information are stored in the key information cache, each piece of which includes a historical data identifier, a historical update time, and a historical synchronization status. As shown in Table 3, in historical key information 1, the historical data identifier is 02, the historical update time is 19:00:30, and the historical synchronization status is synchronized. In historical key information 2, the historical data identifier is 04, the historical update time is 09:00:30, and the historical synchronization status is synchronizing.

[0083] Table 3.

[0084] Historical data identification Historical update time History synchronization status 02 19:00:30 Synchronized 04 09:00:30 Synchronizing

[0085] Since the target data identifier 01 does not exist in the key information cache area corresponding to Table 3, the data key information corresponding to Table 2 is used to update the historical key information in the key information cache area, that is, the target data identifier (01), target update time (09:00:30), and target synchronization status (synchronizing) in Table 2 are added to the key information cache area. The historical key information stored in the key information cache area is shown in Table 4. At the same time, the data to be synchronized corresponding to the target data identifier 01 is synchronized to the database.

[0086] Table 4.

[0087] Historical data identification Historical update time History synchronization status 02 19:00:30 Synchronized 04 09:00:30 Synchronizing 01 09:00:30 Synchronizing

[0088] When the to-be-synchronized data corresponding to the target data identifier 01 is successfully synchronized to the database, the historical synchronization status corresponding to the historical data identifier 01 in the key information buffer area corresponding to Table 4 is updated to synchronized, as shown in Table 5.

[0089] Table 5.

[0090]

[0091]

[0092] In the embodiment of the present application, the data synchronization system obtains the data to be synchronized from the blockchain system, wherein the data to be synchronized carries the corresponding target data identifier, and the data to be synchronized is written into the blockchain system by the business application system through the blockchain operation. If the target data identifier does not exist in the key information cache area of ​​the data synchronization system, the target data identifier is added to the key information cache area, and the data to be synchronized is synchronized to the database. Since the data in the blockchain system is consistent with the data in the database, the business application system can query the data in the database through structured query statements, which solves the problem of not being able to perform efficient data query on the blockchain.

[0093] Optionally, in the above step S202, if the target data identifier exists in the key information buffer of the data synchronization system, the historical synchronization state and historical update time corresponding to the target data identifier are obtained from the key information buffer. The following four situations are judged respectively:

[0094] First, if the historical synchronization status is synchronized, and the historical update time is earlier than the target update time carried by the data to be synchronized, the historical update time is updated to the target update time, the historical synchronization status is updated to synchronizing, and the data to be synchronized is synchronized to the database. If the data to be synchronized is successfully synchronized to the database, the historical synchronization status corresponding to the target data identifier is updated to synchronized. If the data to be synchronized fails to be synchronized to the database, the historical synchronization status corresponding to the target data identifier is updated to synchronization failure.

[0095] Second, if the historical synchronization status is synchronized, and the historical update time is not earlier than the target update time carried by the data to be synchronized, the processing is terminated.

[0096] Third, if the historical synchronization status is in sync, and the data synchronization duration is greater than the synchronization duration threshold, the historical update time is updated to the target update time, the historical synchronization status is updated to in sync, and the data to be synchronized is synchronized to the database. If the data to be synchronized is successfully synchronized to the database, the historical synchronization status corresponding to the target data identifier is updated to synchronized. If the data to be synchronized fails to be synchronized to the database, the historical synchronization status corresponding to the target data identifier is updated to synchronization failure.

[0097] Fourth, if the historical synchronization status is in synchronization, and the data synchronization time is less than or equal to the synchronization time threshold, the processing is terminated.

[0098] Specifically, the synchronization duration threshold may be set as a fixed value, or may be determined according to the synchronization duration of historical synchronization data.

[0099] For example, the historical key information stored in the key information buffer is shown in Table 5. The data to be synchronized is shown in Table 6, where the target data identifier is 01, other data identifiers are xxx, the target update time is 09:00:40, and the target update mode is pull mode.

[0100] Table 6.

[0101] Target data identification Other data identifiers Target update time Target update method 01 xxx 09:00:40 Pull method

[0102] The key data information is determined according to the data to be synchronized in Table 6, as shown in Table 7, wherein the target data identifier is 01, the target update time is 09:00:40, and the target synchronization state is synchronizing.

[0103] Table 7.

[0104] Target data identification Target update time Target Sync Status 01 09:00:40 Synchronizing

[0105] Since the target data identifier 01 exists in the key information cache area corresponding to Table 5, and the historical synchronization state corresponding to the target data identifier 01 is synchronized, the historical update time corresponding to the target data identifier 01 is 09:00:30, and the target update time corresponding to the target data identifier 01 is 09:00:40. Since 09:00:30 is earlier than 09:00:40, the target update time and target synchronization state in Table 7 are used to update the historical update time corresponding to the historical data identifier 01 in the key information cache area corresponding to Table 5 to 09:00:40, and the historical synchronization state is updated to synchronizing, as shown in Table 8. At the same time, since the historical synchronization data corresponding to the target data identifier 01 exists in the database, the data to be synchronized in Table 6 is used to synchronize the database.

[0106] Table 8.

[0107] Historical data identification Historical update time History synchronization status 02 19:00:30 Synchronized 04 09:00:30 Synchronizing 01 09:00:40 Synchronizing

[0108] The data to be synchronized in Table 6 is successfully synchronized to the database, and the historical synchronization state corresponding to the historical data identifier 01 in the key information buffer area corresponding to Table 8 is updated to synchronized, as shown in Table 9.

[0109] Table 9.

[0110] Historical data identification Historical update time History synchronization status 02 19:00:30 Synchronized 04 09:00:30 Synchronizing 01 09:00:40 Synchronized

[0111] For example, the historical key information stored in the key information buffer is shown in Table 9. The data to be synchronized is shown in Table 10, where the target data identifier is 04, the other data identifier is yy, the target update time is 09:00:50, and the target update mode is the receiving mode.

[0112] Table 10.

[0113] Target data identification Other data identifiers Target update time Target update method 04 yy 09:00:50 Receiving method

[0114] The key data information is determined according to the data to be synchronized in Table 10, as shown in Table 11, wherein the target data identifier is 04, the target update time is 09:00:50, and the target synchronization state is synchronizing.

[0115] Table 11.

[0116] Target data identification Target update time Target Sync Status 04 09:00:50 Synchronizing

[0117] Since the target data identifier 04 exists in the key information cache area corresponding to Table 9, and the historical synchronization state corresponding to the target data identifier 04 is in synchronization, the data synchronization duration corresponding to the target data identifier 04 is set to be greater than the synchronization duration threshold, and the target update time and target synchronization state in Table 11 are used to update the historical update time corresponding to the target data identifier 04 in the key information cache area corresponding to Table 9 to 09:00:50, and the historical synchronization state is updated to in synchronization, as shown in Table 12. At the same time, since the historical synchronization data corresponding to the target data identifier 04 exists in the database, the data to be synchronized in Table 10 is used to synchronize the database.

[0118] Table 12.

[0119]

[0120]

[0121] The data to be synchronized in Table 10 is successfully synchronized to the database, and the historical synchronization state corresponding to the historical data identifier 04 in the key information buffer area corresponding to Table 12 is updated to synchronized, as shown in Table 13.

[0122] Table 13.

[0123] Historical data identification Historical update time History synchronization status 02 19:00:30 Synchronized 04 09:00:50 Synchronized 01 09:00:40 Synchronized

[0124] For example, the historical key information stored in the key information buffer is shown in Table 9. When the data to be synchronized is shown in Table 14, the target data identifier is 04, the other data identifiers are zz, the target update time is 10:00:10, and the target update mode is the receiving mode.

[0125] Table 14.

[0126] Target data identification Other data identifiers Target update time Target update method 04 zz 10:00:10 Receiving method

[0127] The data key information is determined according to the data to be synchronized in Table 14, as shown in Table 15, wherein the target data identifier is 04, the target update time is 10:00:10, and the target synchronization state is synchronizing.

[0128] Table 15.

[0129] Target data identification Target update time Target Sync Status 04 10:00:10 Synchronizing

[0130] Since there is target data identifier 04 in the key information cache area corresponding to Table 9, and the historical synchronization state corresponding to target data identifier 04 is synchronizing, the data synchronization duration corresponding to target data identifier 04 is set to be less than or equal to the synchronization duration threshold, and the data synchronization system ends the processing.

[0131] In an embodiment of the present application, when there is a target data identifier in the key information cache area, a judgment is made based on the historical synchronization status and historical update time corresponding to the target data identifier in the key information cache area to determine whether the data to be synchronized is updated to the database, thereby ensuring the accuracy of the data to be synchronized in the process of synchronizing the data to the database. At the same time, it avoids repeated processing of redundant data and improves data synchronization efficiency.

[0132] In order to better explain the embodiments of the present application, a data synchronization method provided by the embodiments of the present application is taken as an example below with a specific implementation scenario. Figure 3 As shown, the following steps are included:

[0133] Step S301, obtaining data to be synchronized from the blockchain system.

[0134] The data to be synchronized carries the corresponding target data identifier, and the data to be synchronized is written into the blockchain system by the business application system through blockchain operations.

[0135] There are two ways to obtain the data to be synchronized from the blockchain system. The data synchronization system executes two methods of obtaining the data to be synchronized at the same time, as follows:

[0136] Method 1: The data synchronization system receives a data update event notification sent by the blockchain system, and obtains the data to be synchronized from the data update event notification, wherein the data synchronization system subscribes to the data update event in the blockchain system in advance.

[0137] Method 2: The data synchronization system periodically pulls the data to be synchronized from the blockchain system.

[0138] Step S302, determine whether there is a target data identifier in the key information buffer area of ​​the data synchronization system, if yes, execute step S310; otherwise, execute step S303.

[0139] Step S303, adding the target data identifier to the key information buffer area as a historical data identifier.

[0140] Step S304: Add the target update time corresponding to the target data identifier to the key information cache area as the historical update time.

[0141] Step S305: Add the target synchronization state corresponding to the target data identifier to the key information buffer area as a historical synchronization state.

[0142] Step S306, synchronizing the data to be synchronized into the database.

[0143] Step S307, determining whether the data to be synchronized is synchronized to the database successfully, if so, executing step S308; otherwise, executing step S309.

[0144] Step S308: Update the historical synchronization status to synchronized.

[0145] Step S309: Update the historical synchronization status to synchronization failure.

[0146] Step S310, obtaining the historical synchronization state and historical update time corresponding to the target data identifier from the key information buffer area.

[0147] Step S311, determine whether the historical synchronization status is synchronized, if so, execute step S312; otherwise, execute step S317.

[0148] Step S312, determine whether the historical update time is earlier than the target update time carried by the data to be synchronized, if so, execute step S313; otherwise, end.

[0149] Step S313, updating the historical update time to the target update time, updating the historical synchronization state to synchronizing, and synchronizing the data to be synchronized into the database.

[0150] Step S314, determining whether the data to be synchronized is successfully synchronized to the database, if so, executing step S315; otherwise, executing step S316.

[0151] Step S315: Update the historical synchronization status to synchronized.

[0152] Step S316: Update the historical synchronization status to synchronization failure.

[0153] Step S317, determine whether the historical synchronization status is in synchronization, if so, execute step S318; otherwise, end.

[0154] Step S318, determine whether the data synchronization duration is greater than the synchronization duration threshold, if so, execute step S313; otherwise, end the process.

[0155] In an embodiment of the present application, the data synchronization system obtains the data to be synchronized from the blockchain system, wherein the data to be synchronized carries the corresponding target data identifier, and the data to be synchronized is written into the blockchain system by the business application system through blockchain operations. If the target data identifier does not exist in the key information cache area of ​​the data synchronization system, the target data identifier is added to the key information cache area, and the data to be synchronized is synchronized to the database. Since the data synchronization system not only receives the data update notification event sent by the blockchain system, and obtains the data to be synchronized from the data update notification event; but also periodically pulls the data to be synchronized from the blockchain system, the real-time and integrity of data synchronization are enhanced. Since the data in the blockchain system is consistent with the data in the database, the business application system can query the data in the database through structured query statements, which solves the problem of being unable to query data on the blockchain.

[0156] Based on the same technical concept, the embodiment of the present application provides a data synchronization device, such as Figure 4 As shown, the data synchronization device 400 includes:

[0157] An acquisition module 401 is used to acquire data to be synchronized from a blockchain system, wherein the data to be synchronized carries a corresponding target data identifier, and the data to be synchronized is written into the blockchain system by a business application system through a blockchain operation;

[0158] The judgment module 402 is used to add the target data identifier to the key information cache area if the target data identifier does not exist in the key information cache area of ​​the data synchronization system, and synchronize the data to be synchronized into the database.

[0159] Optionally, the acquisition module 401 is specifically used for:

[0160] Receiving a data update event notification sent by the blockchain system, and obtaining the data to be synchronized from the data update event notification, wherein the data synchronization system subscribes to the data update event in the blockchain system in advance; or

[0161] The data to be synchronized is periodically pulled from the blockchain system.

[0162] Optionally, the judging module 402 is further configured to:

[0163] If the target data identifier exists in the key information cache area, then obtaining the historical synchronization state and historical update time corresponding to the target data identifier from the key information cache area;

[0164] If the historical synchronization state is synchronized, and the historical update time is earlier than the target update time carried by the data to be synchronized, the historical update time is updated to the target update time, the historical synchronization state is updated to synchronizing, and the data to be synchronized is synchronized to the database.

[0165] Optionally, the judging module 402 is further configured to:

[0166] If the historical synchronization state is in sync, and the data synchronization duration is greater than the synchronization duration threshold, the historical update time is updated to the target update time, the historical synchronization state is updated to in sync, and the data to be synchronized is synchronized to the database;

[0167] If the historical synchronization state is in synchronization, and the data synchronization time is less than or equal to the synchronization duration threshold, the process ends.

[0168] Optionally, the judging module 402 is further configured to:

[0169] If the data to be synchronized is successfully synchronized to the database, the historical synchronization status is updated to synchronized;

[0170] If the data to be synchronized fails to be synchronized to the database, the historical synchronization status is updated to synchronization failure.

[0171] Optionally, the acquisition module 401 is specifically used for:

[0172] Based on the historical synchronization data pulled in the previous cycle, the target block height for data pulling in the current cycle is determined at the corresponding historical block height in the blockchain system;

[0173] Based on the target block height, the corresponding target block in the blockchain system is determined, and the data in the target block is pulled as the data to be synchronized.

[0174] Based on the same technical concept, the embodiment of the present application provides a computer device, which may be a terminal or a server, such as Figure 5 As shown, it includes at least one processor 501 and a memory 502 connected to the at least one processor. The specific connection medium between the processor 501 and the memory 502 is not limited in the embodiment of the present application. Figure 5 For example, the processor 501 and the memory 502 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, etc.

[0175] In the embodiment of the present application, the memory 502 stores instructions that can be executed by at least one processor 501, and the at least one processor 501 can execute the steps included in the above-mentioned data synchronization method by executing the instructions stored in the memory 502.

[0176] The processor 501 is the control center of the computer device, and can use various interfaces and lines to connect various parts of the computer device, and synchronize data by running or executing instructions stored in the memory 502 and calling data stored in the memory 502. Optionally, the processor 501 may include one or more processing units, and the processor 501 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 501. In some embodiments, the processor 501 and the memory 502 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on independent chips.

[0177] The processor 501 may be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.

[0178] The memory 502 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 502 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 502 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 502 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.

[0179] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program executable by a computer device. When the program runs on the computer device, the computer device executes the steps of the above-mentioned data synchronization method.

[0180] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0181] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0182] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0183] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0184] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A data synchronization method, applied to a data synchronization system, characterized in that: include: Acquire the data to be synchronized from the blockchain system, the data to be synchronized carries the corresponding target data identifier, and the data to be synchronized is written into the blockchain system by the business application system through the blockchain operation; If the target data identifier does not exist in the key information buffer area of ​​the data synchronization system, the target data identifier is added to the key information buffer area, and the data to be synchronized is synchronized to the database; When the target data identifier exists in the key information cache area, a judgment is made based on the historical synchronization status and historical update time corresponding to the target data identifier in the key information cache area to determine whether the data to be synchronized is updated to the database; the historical update time is the time when the business application system writes data into the blockchain system through blockchain operations; The data in the database is queried through a structured query statement, and the data in the blockchain system is consistent with the data in the database.

2. The method according to claim 1, characterized in that The obtaining of data to be synchronized from the blockchain system includes: Receiving a data update notification event sent by the blockchain system, and obtaining the data to be synchronized from the data update notification event, wherein the data synchronization system subscribes to the data update event in the blockchain system in advance; or The data to be synchronized is periodically pulled from the blockchain system.

3. The method according to claim 2, characterized in that Also includes: If the target data identifier exists in the key information cache area, then obtaining the historical synchronization state and historical update time corresponding to the target data identifier from the key information cache area; If the historical synchronization state is synchronized, and the historical update time is earlier than the target update time carried by the data to be synchronized, the historical update time is updated to the target update time, the historical synchronization state is updated to synchronizing, and the data to be synchronized is synchronized to the database.

4. The method according to claim 3, characterized in that Also includes: If the historical synchronization state is in sync, and the data synchronization duration is greater than the synchronization duration threshold, the historical update time is updated to the target update time, the historical synchronization state is updated to in sync, and the data to be synchronized is synchronized to the database; If the historical synchronization state is in synchronization, and the data synchronization time is less than or equal to the synchronization duration threshold, the process ends.

5. The method according to any one of claims 1 to 4, characterized in that: Also includes: If the data to be synchronized is successfully synchronized to the database, the historical synchronization status is updated to synchronized; If the data to be synchronized fails to be synchronized to the database, the historical synchronization status is updated to synchronization failure.

6. The method according to claim 2, characterized in that The periodically pulling the data to be synchronized from the blockchain system includes: Based on the historical synchronization data pulled in the previous cycle, the target block height for data pulling in the current cycle is determined at the corresponding historical block height in the blockchain system; Based on the target block height, the corresponding target block in the blockchain system is determined, and the data in the target block is pulled as the data to be synchronized.

7. A data synchronization device, characterized in that: include: An acquisition module is used to acquire the data to be synchronized from the blockchain system, wherein the data to be synchronized carries a corresponding target data identifier, and the data to be synchronized is written into the blockchain system by the business application system through a blockchain operation; A judgment module, configured to add the target data identifier to the key information cache area if the target data identifier does not exist in the key information cache area of ​​the data synchronization system, and synchronize the data to be synchronized into the database; When the target data identifier exists in the key information cache area, a judgment is made based on the historical synchronization status and historical update time corresponding to the target data identifier in the key information cache area to determine whether the data to be synchronized is updated to the database; the historical update time is the time when the business application system writes data into the blockchain system through blockchain operations; The data in the database is queried through a structured query statement, and the data in the blockchain system is consistent with the data in the database.

8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of any one of the methods of claims 1 to 6 are implemented.

9. A computer-readable storage medium, characterized in that: It stores a computer program executable by a computer device. When the program is run on the computer device, the computer device executes the steps of any method described in claims 1 to 6.

Citation Information

Patent Citations

  • System and method for improving block-chain querying efficiency

    CN107391649A