Data checking method and device, equipment and storage medium

By using hash values ​​and Merkel trees in distributed systems, the problem of inefficiency of traditional data verification solutions in massive data scenarios is solved, efficient data verification and exception positioning are achieved, and the efficiency of data verification is improved. and accuracy.

CN119127882APending Publication Date: 2024-12-13CHINA MERCHANTS BANK
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411249755.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-06
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

In distributed systems, traditional data verification solutions will seriously waste network bandwidth and be inefficient in massive data scenarios, resulting in inefficient data verification.

Method used

By obtaining the time batch data to be checked, the hash value of each piece of data is calculated and rehashed, the Merkel tree is built to generate the root hash value, and the root hash value is checked to achieve data verification.

Benefits of technology

It alleviates the waste of network broadband and improves the efficiency of data verification. Through hash calculation and the construction of Merkel tree, data abnormalities can be quickly identified and located, improving the efficiency and accuracy of data verification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127882A_ABST
    Figure CN119127882A_ABST
Patent Text Reader

Abstract

The invention discloses a data checking method and device, equipment and a storage medium, and relates to the technical field of data processing, and the method comprises the steps: obtaining to-be-checked time batch data; calculating a hash value of each piece of data in the time batch data to obtain a single hash value of each piece of data; performing re-hash calculation on the single hash value of each piece of data to obtain a batch hash value of the batch of time batch data; forming a Merkel tree by taking the batch hash values of the preset batch number as leaf nodes, and obtaining root hash values on root nodes of the Merkel tree; and checking the root hash value on the Merkel root node to obtain a data checking result. According to the method, the Hash values are generated by performing the Hash calculation on the to-be-checked data of the plurality of data sources, and the Merkel tree is constructed according to the Hash values to perform data checking, so that the waste of network broadband is relieved, and the data checking efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] In a distributed system, data is usually backed up in multiple data sources and provided to different systems for use. Such scenarios have certain requirements for data consistency. In order to ensure data consistency, it is necessary to introduce a data verification function after data synchronization to verify and compensate the data from multiple data sources. The traditional verification solution is mainly to transmit the original data from multiple data sources over the network and compare the data. This method will seriously waste network bandwidth and is inefficient in massive data scenarios.

[0003] Therefore, there is an urgent need for an efficient data verification solution to improve the efficiency of data verification.

[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention

[0005] The main purpose of the present application is to provide a data verification method, device, equipment and storage medium, aiming to solve the technical problem of low efficiency when performing data verification on multi-source data.

[0006] To achieve the above purpose, the present application proposes a data verification method, which comprises:

[0007] Get the time batch data to be checked;

[0008] Calculate the hash value of each piece of data in the time batch data to obtain a single hash value for each piece of data;

[0009] Re-hash the hash value of each piece of data in the time batch data to obtain a batch hash value of the batch of time batch data;

[0010] The batch hash values ​​of the preset batch number are used as leaf nodes to form a Merkle tree, and the root hash value on the root node of the Merkle tree is obtained;

[0011] The root hash value on the root node of the Merkle tree is verified to obtain a data verification result.

[0012] In one embodiment, the step of obtaining the time batch data to be checked includes:

[0013] Determine the start maintenance time for data to be verified from multiple data sources;

[0014] Starting from the start maintenance time, batch reading operations are continuously performed from the data to be checked of multiple data sources at the same time interval to obtain time batch data to be checked.

[0015] In one embodiment, the step of calculating the hash value of each piece of data in the time batch data to obtain a single hash value of each piece of data includes:

[0016] Sort all the data in the time batch data according to the primary key;

[0017] The hash value of each piece of data in the time batch data is calculated in the order of primary key sorting to obtain a single hash value for each piece of data.

[0018] In one embodiment, the step of re-hashing the single hash value of each data in the time batch data to obtain the batch hash value of the batch of time batch data includes:

[0019] Concatenate the single hash value of each data in the time batch data according to the primary key order;

[0020] The concatenated hash values ​​are re-hashed to obtain a batch hash value corresponding to the time batch data.

[0021] In one embodiment, the step of using the batch hash values ​​of the preset batch number as leaf nodes to form a Merkle tree and obtaining the root hash value on the root node of the Merkle tree includes:

[0022] Initialize the batch hash values ​​of the preset batch number as leaf nodes in the order of reading time;

[0023] After splicing two adjacent leaf nodes, they are re-hashed to form a Merkle tree of the data source from bottom to top, and the root hash value on the root node of the Merkle tree is obtained.

[0024] In one embodiment, the step of verifying the root hash value on the Merkle tree root node to obtain a data verification result includes:

[0025] Generate multiple Merkle trees based on the data to be verified from multiple data sources;

[0026] Verify the root hash values ​​on multiple Merkle tree root nodes to obtain data verification results;

[0027] If the root hash values ​​on the root nodes of multiple Merkle trees are the same, the data verification result is normal;

[0028] If the root hash values ​​on the root nodes of multiple Merkle trees are different, the data verification result is abnormal.

[0029] In one embodiment, if the root hash values ​​on the root nodes of the multiple Merkle trees are different, the step of determining that the data verification result is abnormal further includes:

[0030] Determine the abnormal Merkle tree based on the root hash values ​​on the root nodes of multiple Merkle trees;

[0031] Compare the abnormal Merkle tree from top to bottom and locate the leaf node where the abnormality occurs;

[0032] The hash value of the time batch data corresponding to the abnormal leaf node is fully transmitted and compared to obtain the primary key corresponding to the abnormal hash value;

[0033] The abnormal data to be verified is located according to the primary key corresponding to the abnormal hash value, and retry transmission compensation is performed on the abnormal data to be verified.

[0034] In addition, to achieve the above purpose, the present application also proposes a data checking device, which includes:

[0035] A data acquisition module is used to acquire the time batch data to be checked;

[0036] A single hash module, used to calculate the hash value of each piece of data in the time batch data to obtain a single hash value of each piece of data;

[0037] The batch hash module is used to re-hash the single hash value of each data to obtain the batch hash value of the batch data of the batch time;

[0038] A tree module is constructed to form a Merkle tree using the batch hash values ​​of a preset number of batches as leaf nodes, and obtain the root hash value on the root node of the Merkle tree;

[0039] The data verification module is used to verify the root hash value on the Merkle tree root node to obtain a data verification result.

[0040] In addition, to achieve the above-mentioned purpose, the present application also proposes a data verification device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the data verification method described above.

[0041] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the data verification method described above are implemented.

[0042] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the data verification method described above are implemented.

[0043] One or more technical solutions proposed in this application have at least the following technical effects:

[0044] The embodiment of the present application proposes a data verification method, device, equipment and storage medium, which obtains time batch data to be verified; calculates the hash value of each data in the time batch data to obtain a single hash value of each data; re-hashes the single hash value of each data to obtain a batch hash value of the batch of time batch data; uses the batch hash values ​​of a preset batch number as leaf nodes to form a Merkle tree to obtain a root hash value on the root node of the Merkle tree; verifies the root hash value on the root node of the Merkle tree to obtain a data verification result. The present application alleviates the waste of network bandwidth and improves the efficiency of data verification by performing hash calculation on the data to be verified from multiple data sources to generate hash values, and constructing a Merkle tree based on the hash values ​​for data verification. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0046] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0047] Figure 1 A flowchart of the first embodiment of the data verification method of this application is provided;

[0048] Figure 2 A schematic diagram of a process for constructing a Merkle tree provided in an embodiment of the data verification method of the present application;

[0049] Figure 3 A brief flowchart of the data verification method provided in the data verification method embodiment of the present application;

[0050] Figure 4 This is a schematic diagram of the module structure of the data checking device according to an embodiment of the present application;

[0051] Figure 5 Schematic diagram of the device structure of the hardware operating environment involved in the data verification method in the embodiment of the present application.

[0052] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0053] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0054] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0055] The main solution of the embodiment of the present application is: obtain the time batch data to be verified; calculate the hash value of each data in the time batch data to obtain a single hash value of each data; re-hash the single hash value of each data to obtain the batch hash value of the batch of time batch data; use the batch hash values ​​of a preset batch number as leaf nodes to form a Merkle tree to obtain the root hash value on the root node of the Merkle tree; verify the root hash value on the root node of the Merkle tree to obtain the data verification result.

[0056] In this embodiment, for the convenience of description, the following description is made by taking the identification data verification device as the execution subject.

[0057] In distributed systems, data is usually backed up in multiple data sources and provided to different systems for use. Such scenarios have more or less certain requirements for data consistency. In order to ensure data consistency, it is necessary to introduce a data verification function after data synchronization to verify and compensate the data from multiple data sources. The traditional verification solution is mainly to transmit the original data from multiple data sources over the network and compare the data. This method will seriously waste network bandwidth and is inefficient in massive data scenarios. Therefore, an efficient data verification solution is urgently needed to improve the efficiency of data verification.

[0058] The present application performs hash calculation on the data to be verified from multiple data sources to generate hash values, and constructs a Merkle tree based on the hash values ​​for data verification, thereby alleviating the waste of network bandwidth and improving the efficiency of data verification.

[0059] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a data checking device, etc. The following takes the data checking device as an example to illustrate this embodiment and the following embodiments.

[0060] Based on this, the present application embodiment provides a data verification method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the data checking method of the present application.

[0061] In this embodiment, the data verification method includes steps S10 to S50:

[0062] Step S10, obtaining the time batch data to be checked;

[0063] It should be noted that the time batch data refers to batch data obtained by reading the data of the data source in batches at the same time interval.

[0064] In this embodiment, the data checking device (hereinafter referred to as the device) can obtain data to be checked from multiple data sources, thereby determining the time batch data to be checked. Specifically, the starting maintenance time of multiple data sources is first determined, and then starting from the starting maintenance time, batch reading operations are continuously performed from the data to be checked from the multiple data sources at the same time interval to obtain the time batch data to be checked.

[0065] Through the above steps, the device can accurately obtain time batch data that needs to be checked from multiple data sources, providing basic data support for subsequent data verification.

[0066] Step S20, calculating the hash value of each piece of data in the time batch data to obtain a single hash value of each piece of data.

[0067] It should be noted that the single hash value refers to the hash value obtained after a single piece of data is hashed using a preset hash algorithm.

[0068] Specifically, the data in the time batch data are first sorted according to the primary key, and then the hash value of each data in the time batch data is calculated by a preset hash algorithm in the order of the primary key to obtain a single hash value for each data.

[0069] Step S30, re-hash the single hash value of each data in the time batch data to obtain the batch hash value of the batch of time batch data.

[0070] It should be noted that the batch hash value refers to the hash value obtained by concatenating the single hash values ​​of a batch in the order of primary keys and then performing hash calculation.

[0071] Specifically, firstly, the single hash value of each data in the time batch data is spliced ​​according to the primary key order; then, the spliced ​​hash value is re-hashed by a preset hash algorithm to obtain the batch hash value corresponding to the time batch data.

[0072] Step S40, using the batch hash values ​​of the preset batch number as leaf nodes to form a Merkle tree, and obtaining the root hash value on the root node of the Merkle tree.

[0073] It should be noted that the Merkle tree, also known as a hash tree, is a data structure widely used in computer science and cryptography. It can efficiently and securely verify the contents of large data structures. The basic structure of a Merkle tree is a tree in which each leaf node is marked with a hash value of a data block, and each non-leaf node is marked with a hash of the hash value of its child node. The hash value is usually calculated using a cryptographic hash function such as SHA-2. The top node of the Merkle tree is called the root node.

[0074] In addition, it should be noted that the preset batch number is preferably a power of 2, because the Merkle tree is generally designed as a full binary tree, so the preset batch number is preferably a power of 2, such as 2, 4, 8, 16, 32, etc.; if the preset batch number is not a power of 2, it must be an even number. If the number of batch hash values ​​is odd, copy the last batch hash value to make it an even number.

[0075] Specifically, first, the batch hash values ​​of a preset batch number are initialized as leaf nodes of the corresponding Merkle tree in the order of reading time; then, two adjacent leaf nodes are concatenated and re-hashed to form a Merkle tree corresponding to the data source from bottom to top, and the root hash value on the root node of the Merkle tree is obtained.

[0076] Step S50, verifying the root hash value on the root node of the Merkle tree to obtain a data verification result.

[0077] Specifically, the root hash values ​​of the Merkle trees formed by the multiple data sources that need to be checked are obtained, and then the root hash values ​​that need to be checked are directly compared to obtain the data verification result. If the root hash values ​​on the root nodes of multiple Merkle trees are the same, the data verification result is normal; if the root hash values ​​on the root nodes of multiple Merkle trees are different, the data verification result is abnormal.

[0078] More specifically, the amount of data in each batch does not need to be consistent, only the batch needs to be complete. Even if a batch has no data, the empty batch needs to be included when participating in the construction of the Merkle tree, which ensures that the Merkle tree structure constructed by multiple parties is consistent.

[0079] This embodiment adopts the above scheme, by obtaining the time batch data to be checked; calculating the hash value of each data in the time batch data to obtain the single hash value of each data; re-hashing the single hash value of each data to obtain the batch hash value of the batch time batch data; using the batch hash values ​​of the preset batch number as leaf nodes to form a Merkle tree to obtain the root hash value on the root node of the Merkle tree; checking the root hash value on the root node of the Merkle tree to obtain the data verification result. By performing hash calculation on the data to be checked from multiple data sources to generate hash values, and constructing a Merkle tree according to the hash values ​​for data verification, the waste of network bandwidth is alleviated and the efficiency of data verification is improved.

[0080] Based on the above implementation scheme, in a feasible implementation scheme, the step of obtaining the time batch data to be checked includes steps S11 to S12:

[0081] Step S11, determining the start maintenance time of the data to be checked from multiple data sources.

[0082] It should be noted that multiple data sources mean that in a distributed system, data is usually backed up in multiple data sources and provided to different systems for use.

[0083] In addition, it should be noted that the start maintenance time refers to the time point when the time batch data of the data source is started to be read. From this time point, the time batch data is read from the data source uninterruptedly. A maintenance time attribute is maintained for multiple data source data, and the maintenance time is updated every time data is inserted or changed.

[0084] Specifically, in most business scenarios, data is generated smoothly over time, and the data can be split more evenly by using the time attribute. In this embodiment, the device first determines the common start maintenance time of multiple data sources that need to participate in the verification.

[0085] Step S12, starting from the start maintenance time, continuously performing batch reading operations from the data to be checked from multiple data sources at the same time interval to obtain the time batch data to be checked.

[0086] Specifically, starting from the starting maintenance time, the device continuously reads data from multiple data sources, performs batch reading operations from the data sources at the same time intervals, ensures that the time intervals of the read data are the same and continuous, and reads out the time batch data to be verified from the same time batches of multiple data sources.

[0087] Through the above scheme, this embodiment can ensure that the data of all data sources are considered and checked within the same time frame by determining the starting maintenance time, thereby helping to maintain the consistency between the data; reading the time batch data can provide basic data support for subsequent data verification.

[0088] Based on the above implementation scheme, in a feasible implementation manner, the step of calculating the hash value of each piece of data in the time batch data to obtain a single hash value of each piece of data includes steps S21 to S22:

[0089] Step S21, sorting all the data in the time batch data according to the primary key.

[0090] It should be noted that the primary key of data refers to the field used to uniquely identify each row of data records in the table, which is a combination of one or more fields. It ensures the uniqueness of each row of data in the table and does not allow it to be empty (NULL).

[0091] Specifically, first determine which field in the time batch data is set as the primary key, then read the data from the data source in batches according to time, and after reading a batch of time batch data, sort it within the batch according to the primary key. For example, the order data of a shopping software may contain fields such as order ID (primary key), customer ID, and order amount. Set the order ID as the primary key and sort it in ascending or descending order according to the order ID.

[0092] Step S22, calculating the hash value of each piece of data in the time batch data in the order of primary key sorting, and obtaining a single hash value of each piece of data.

[0093] Specifically, determine the function of the hash algorithm for calculating the hash value and the data segment for calculating the hash value. Common hash algorithms include MD5, SHA-1, SHA-2, SHA-256, etc. The data segment for calculating the hash value can select the entire record (i.e., all fields) or only select some key fields to calculate the hash value. For example, first convert the data into a format that can be calculated by the hash algorithm, and then use the SHA-2 hash algorithm to calculate the hash value based on all fields of each data in the time batch data to obtain a single hash value for each data. More specifically, in this solution, only the primary key and hash value of the data to be checked are stored in the memory of the data source to ensure that as much data as possible is stored in the memory.

[0094] Through the above scheme, this embodiment ensures the consistency and predictability of data during the processing by sorting by primary key, which is crucial for subsequent data analysis, comparison or verification, because any operation based on these data will be based on a fixed, ordered set, and sorting by primary key can simplify data storage and management; by calculating the hash value of the data to perform data verification, the integrity and security of the data to be verified can be guaranteed, and the efficiency of data verification can be greatly improved.

[0095] Based on the above implementation scheme, in a feasible implementation manner, re-hashing the single hash value of each data in the time batch data to obtain the batch hash value of the batch of time batch data includes steps S31 to S32:

[0096] Step S31, concatenate the single hash value of each data in the time batch data according to the primary key sequence.

[0097] Specifically, first create an empty string (or list) to store the concatenated hash values; then loop through the sorted single hash values, and in each loop, add the current hash value to the end of the created concatenated string. If necessary, you can choose to add some separators between the single hash values, such as commas, spaces, newlines, or specific character sequences, so that you can distinguish the individual hash values ​​when necessary; when all the hash values ​​are concatenated, store the final concatenated string in a variable.

[0098] Step S32, performing a re-hash calculation operation on the concatenated hash values ​​to obtain a batch hash value corresponding to the time batch data.

[0099] Specifically, first determine the hash function for re-hashing, which can be the same hash algorithm as that for calculating a single hash value, or another hash algorithm; if necessary, convert the concatenated string into the data format required by the re-hashing algorithm; then re-hash the concatenated string data using a preset re-hashing algorithm to generate a hash value of a fixed length, i.e., a batch hash value. The batch hash value can be used as a unique identifier for a batch of time batch data for data verification and integrity checking.

[0100] In this embodiment, through the above scheme, the batch hash value is used as a unique identifier of the entire time batch data, which can be used to verify the integrity and consistency of a batch of data. If any modification or damage occurs during the transmission, storage or processing of the data, it can be detected by recalculating the batch hash value of the data and comparing it with the original batch hash value, and the re-hashing calculation can further enhance the security of the data; compared with storing the original data or all single hash values, storing a batch hash value can significantly reduce the required storage space; when it is necessary to verify the integrity of the data or perform data comparison, it is only necessary to calculate and compare the batch hash value without checking the original data or single hash value one by one, which can greatly improve the processing efficiency, especially when processing large-scale data sets.

[0101] Based on the above implementation scheme, in a feasible implementation scheme, the process of using the batch hash values ​​of the preset batch number as leaf nodes to form a Merkle tree and obtaining the root hash value on the root node of the Merkle tree includes steps S41 to S42:

[0102] Step S41, initializing batch hash values ​​of a preset batch quantity as leaf nodes in the order of reading time.

[0103] Specifically, batch hash values ​​of a preset number of batches are obtained, and these hash values ​​are initialized as leaf nodes of the Merkle tree in the order of the time in which the collection is read, either from left to right or from right to left.

[0104] Step S42, concatenate two adjacent leaf nodes and perform hash calculation again, construct a Merkle tree of the data source from bottom to top, and obtain the root hash value on the root node of the Merkle tree.

[0105] Specifically, the hash values ​​of the leaf nodes are calculated upward to construct a Merkle tree, the two adjacent leaf nodes are spliced ​​together, and the spliced ​​hash values ​​are re-hashed through a preset hash algorithm to obtain the parent node of the two leaf nodes; the parent node generated in the previous step is regarded as a new "leaf node" (in the context of the construction process), and the above pairing, splicing and re-hashing steps are repeated until only one node is left. This node is the root node of the Merkle tree, and the root hash value of the root node of the Merkle tree is obtained.

[0106] For better understanding, please refer to Figure 2 , Figure 2 To construct a specific scenario instance of the Merkle tree, Figure 2 The process of constructing a four-layer Merkle tree (L0, L1, L2, L3) from the batch hash values ​​of 8 time batches of data is shown in Figure 1, where the time interval between batches is one day.

[0107] The first batch of data is B_1, which is the data to be verified on May 1, 2024, including single data data1, data 2...data n1 and other n1 data. Each data has a corresponding primary key (pk) and a single hash value (hash), for example Figure 2 The hash and pk under the single data 1 in the time batch data B_1 are the single hash value and primary key of data 1. By analogy, we can know Figure 2 The specific meaning of other single data in the second time batch data is B_2, which is the data to be verified on May 2, 2024, including single data data 1, data 2...data n2 and other n2 data. Each data has a corresponding primary key (pk) and a single hash value (hash); and so on, the specific meaning of the data in B_3, B_4, B_5, B_6, B_7 and B_8 can be known.

[0108] The batch hash value of the L3 layer is generated by concatenating and hashing the single hash value of each data in the 8 time batches. L3_1 = hash(B_1), that is, the hash value L3_1 is the batch hash value of B_1; L3_2 = hash(B_2), that is, L3_2 is the batch hash value of B_2; and so on, we can know the specific meanings of L3_3, L3_4, L3_5, L3_6, L3_7 and L3_8.

[0109] Then the hash values ​​in the L3 layer are concatenated and hashed to generate the hash values ​​of the L2 layer. L2_1 = hash (L3_1 + L3_2), that is, the hash value L2_1 is obtained by concatenating the batch hash values ​​L3_1 and L3_2 with a "+" operation, and then performing a hash calculation hash(); the hash value L2_2 is obtained by concatenating the batch hash values ​​L3_3 and L3_4 with a "+" operation, and then performing a hash calculation hash(); and so on, the specific meanings of L2_3 and L2_4 can be known.

[0110] Then the hash values ​​in the L2 layer are concatenated and hashed to generate the hash values ​​of the L1 layer. L1_1 = hash(L2_1 + L2_2), that is, the hash value L1_1 is obtained by concatenating the hash values ​​L2_1 and L2_2 with a "+" operation and then performing a hash calculation hash(); L1_2 = hash(L2_3 + L2_4), that is, the hash value L1_2 is obtained by concatenating the hash values ​​L2_3 and L2_4 with a "+" operation and then performing a hash calculation hash().

[0111] Finally, the hash values ​​in the L1 layer are concatenated and hashed to generate the root hash value on the root node of the L0 layer. L0_1 = hash (L1_1 + L1_2), that is, the hash value L0_1 is obtained by concatenating the hash values ​​L1_1 and L1_2 by "+", and then performing hash calculation hash() to obtain the root hash value L0_1.

[0112] Through the above scheme, this embodiment calculates the hash value of the data to be accounted for, performs multiple splicing and re-hashing operations to construct a Merkle tree, and can improve the integrity and security of the data; in the Merkle tree, to verify whether a specific data block (or batch) exists in the data source, it is only necessary to provide the hash value of the data block and the hash values ​​of all nodes on the path from the hash value to the root hash value. By repeatedly calculating the hash value, the existence and integrity of the data block can be quickly verified without downloading or verifying the entire data source, thereby simplifying the data verification process; since the root hash value of the Merkle tree can be used as the "digital fingerprint" of the entire data source, during the storage and transmission process, it is only necessary to save and transmit the root hash value, which greatly reduces the storage and transmission costs.

[0113] Based on the above implementation scheme, in a feasible implementation scheme, the root hash value on the root node of the Merkle tree is checked to obtain the data verification result, including steps S51 to S54:

[0114] Step S51, generating multiple Merkle trees based on the data to be verified from multiple data sources.

[0115] Specifically, the data to be verified of a data source can generate a Merkle tree. Because there are multiple data sources, multiple Merkle trees are generated based on the data to be verified of multiple data sources in a time period.

[0116] Step S52, verify the root hash values ​​on the root nodes of multiple Merkle trees to obtain data verification results.

[0117] Specifically, the root hash value of the Merkle tree composed of multiple data sources that need to be verified is obtained, and then the root hash values ​​that need to be verified are directly compared to obtain the result of data verification.

[0118] Step S53: If the root hash values ​​on the root nodes of multiple Merkle trees are the same, the data verification result is normal.

[0119] Specifically, the root hash values ​​that need to be verified are directly compared. If all the root hash values ​​involved in the verification are the same, it can be considered that the corresponding data set contents are consistent and the data verification result is normal.

[0120] Step S54: If the root hash values ​​on the root nodes of multiple Merkle trees are different, the data verification result is abnormal.

[0121] The root hash values ​​that need to be verified are directly compared. If different data appears in the root hash values ​​involved in the verification, the data verification result is abnormal.

[0122] Based on the above implementation scheme, in a feasible implementation scheme, if the root hash values ​​on the root nodes of the multiple Merkle trees are different, the step of the data verification result being abnormal further includes steps S541 to S544:

[0123] Step S541, determining an abnormal Merkle tree according to the root hash values ​​on the root nodes of multiple Merkle trees.

[0124] Specifically, when the data verification result after the root hash value comparison is abnormal, the abnormal Merkle tree is determined by the root hash value on the root node of the Merkle tree, and the tree whose root hash value is different from the hash value of other Merkle trees is the abnormal Merkle tree.

[0125] Step S542, compare the Merkle tree with the exception from top to bottom to locate the leaf node with the exception.

[0126] Specifically, the abnormal Merkle tree is directly compared with other normal Merkle trees from the root node from top to bottom and from left to right to find the abnormal node with different hash values. If there are hash nodes under the abnormal node, continue to perform direct comparison and repeat the process until the leaf node with inconsistent hash values ​​is found.

[0127] Step S543, the hash value of the time batch data corresponding to the abnormal leaf node is fully transmitted and compared to obtain the primary key corresponding to the abnormal hash value.

[0128] Specifically, the leaf node where the exception occurs is located. One leaf node corresponds to a batch of time batch data. The single hash value corresponding to each data under the time batch data corresponding to the abnormal leaf node is fully transmitted and compared to determine the data primary key corresponding to the single hash value where the exception occurs.

[0129] Step S544, locating the abnormal data to be checked according to the primary key corresponding to the abnormal hash value, and retrying transmission compensation for the abnormal data to be checked.

[0130] Specifically, a primary key can uniquely identify a piece of data, so after determining the data primary key corresponding to the single hash value with an exception, the abnormal data to be checked can be located; then the abnormal data is analyzed in depth to find out the specific reasons for the transmission failure or data error. This may involve multiple factors such as network problems, database problems, and data format problems; then, according to the abnormal cause and actual situation, a suitable retry transmission strategy is formulated. For example, for transmission failures caused by network problems, you can try to reestablish the connection and resend the data; for data format problems, you can first perform format verification and correction on the data before transmitting it. If the retry transmission still fails or the data is damaged and cannot be recovered, compensation measures need to be formulated to ensure the integrity and consistency of the data. This may include restoring data from backups, manually entering data, sending error notifications to users or downstream systems, etc.; finally, after the retry transmission and compensation operations are completed, the results are verified to ensure that the data has been correctly transmitted and restored.

[0131] Through the above scheme, this embodiment can quickly identify which Merkle tree has an abnormality by comparing the root hash value, without the need to conduct a comprehensive check of all data, thereby improving the efficiency of data verification; the top-down comparison method can accurately locate the leaf node where the abnormality occurs, that is, which specific batch of data has a problem, thereby reducing the scope and difficulty of error troubleshooting; when comparing the full transmission, although the hash value of the entire batch of data needs to be transmitted, the hash value is smaller in size and has a higher transmission efficiency than transmitting the original data; once the specific abnormal data is located, retry transmission compensation can be carried out in a targeted manner, avoiding unnecessary repeated transmission and verification work; through the verification mechanism of the Merkle tree, the stability and reliability of the system can be improved. In the event of data loss or damage, the abnormal data can be quickly located and restored through the Merkle tree, reducing the time and cost of data recovery and improving data recovery efficiency.

[0132] For example, in order to help understand the implementation process of the data verification method of this embodiment, this embodiment provides a specific scenario description of the solution, please refer to Figure 3 , Figure 3 The flowchart of the data verification method is as follows:

[0133] 1. The device obtains time batch data with a time interval of one day through data source 1 and data source 2. For example, the time batch data A_1 on May 1, 2024 is obtained from data source 1, and the time batch data A_2 on May 2, 2024 is obtained; the time batch data B_1 on May 1, 2024 is obtained from data source 2, and the time batch data B_2 on May 2, 2024 is obtained; in the time batch data, each data Data has a corresponding primary key (pk) and a single hash value (hash). For example, in the time batch data A_1, the single data Data1_1 has a corresponding primary key (pk) and a single hash value (hash), and the single data Data1_2 also has a corresponding primary key (pk) and a single hash value (hash). By analogy, the specific meaning of other single data can be known.

[0134] Second, construct a Merkle tree with the collected time batch data, and finally obtain the root hash value of the Merkle tree, and check the root hash values ​​of data source 1 and data source 2 to obtain the verification result. If the root hash values ​​on the root nodes of the Merkle tree are the same, the verification result is normal; if the root hash values ​​on the root nodes of the Merkle tree are different, the verification result is abnormal; when the verification result is abnormal, locate the abnormal data to be verified, and then retry transmission compensation for the abnormal data.

[0135] This application also provides a data verification device, please refer to Figure 4 , the data checking device comprises:

[0136] The data acquisition module 401 is used to acquire the time batch data to be checked;

[0137] A single hash module 402 is used to calculate the hash value of each piece of data in the time batch data to obtain a single hash value of each piece of data;

[0138] The batch hash module 403 is used to perform a hash calculation on the single hash value of each data to obtain the batch hash value of the batch data of the batch time;

[0139] A tree building module 404 is used to use batch hash values ​​of a preset batch number as leaf nodes to form a Merkle tree, and obtain a root hash value on the root node of the Merkle tree;

[0140] The data verification module 405 is used to verify the root hash value on the root node of the Merkle tree to obtain a data verification result.

[0141] The data verification device provided by the present application adopts the data verification method in the above embodiment, which can solve the technical problem of low efficiency when performing data verification on multi-source data. Compared with the prior art, the beneficial effects of the data verification device provided by the present application are the same as the beneficial effects of the data verification method provided by the above embodiment, and other technical features in the data verification device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0142] The present application provides a data verification device, which includes: at least one processor; and a memory that is communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data verification method in the above-mentioned embodiment one.

[0143] Reference below Figure 5 , which shows a schematic diagram of the structure of a data checking device suitable for implementing the embodiment of the present application. The data checking device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable App Displays), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The data checking device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0144] like Figure 5 As shown, the data checking device may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read On ly Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. Various programs and data required for the operation of the data checking device are also stored in the RAM 1004. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 can allow the data checking device to communicate with other devices wirelessly or by wire to exchange data. Although the data checking device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have alternatively.

[0145] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0146] The data verification device provided by the present application adopts the data verification method in the above embodiment, which can solve the technical problem of low efficiency when performing data verification on multi-source data. Compared with the prior art, the beneficial effects of the data verification device provided by the present application are the same as the beneficial effects of the data verification method provided by the above embodiment, and the other technical features in the data verification device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0147] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0148] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0149] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the data verification method in the above-mentioned embodiment.

[0150] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read On ly Memory), an erasable programmable read-only memory (EPROM: Erasable Programmab le Read On ly Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read On ly Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.

[0151] The computer-readable storage medium may be included in the data checking device; or may exist independently without being assembled into the data checking device.

[0152] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the data verification device, the data verification device: obtains the time batch data to be verified; calculates the hash value of each data in the time batch data to obtain a single hash value of each data; re-hash the single hash value of each data to obtain a batch hash value of the batch of time batch data; uses a preset batch number of batch hash values ​​as leaf nodes to form a Merkle tree to obtain a root hash value on the root node of the Merkle tree; verifies the root hash value on the root node of the Merkle tree to obtain a data verification result.

[0153] The computer program code for performing the operation of the present application can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).

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

[0155] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0156] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned data verification method, and can solve the technical problem of low efficiency when performing data verification on multi-source data. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the data verification method provided by the above-mentioned embodiment, and will not be elaborated here.

[0157] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned data verification method when executed by a processor.

[0158] The computer program product provided by the present application can solve the technical problem of low efficiency when performing data verification on multi-source data. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the data verification method provided by the above embodiment, which will not be repeated here.

[0159] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A data verification method, characterized in that: The method comprises: Get the time batch data to be checked; Calculate the hash value of each piece of data in the time batch data to obtain a single hash value for each piece of data; Re-hash the hash value of each piece of data in the time batch data to obtain a batch hash value of the batch of time batch data; The batch hash values ​​of the preset batch number are used as leaf nodes to form a Merkle tree, and the root hash value on the root node of the Merkle tree is obtained; The root hash value on the root node of the Merkle tree is verified to obtain a data verification result.

2. The method according to claim 1, characterized in that The step of obtaining the time batch data to be checked includes: Determine the start maintenance time for data to be verified from multiple data sources; Starting from the start maintenance time, batch reading operations are continuously performed from the data to be checked of multiple data sources at the same time interval to obtain time batch data to be checked.

3. The method according to claim 1, characterized in that The step of calculating the hash value of each piece of data in the time batch data to obtain a single hash value of each piece of data comprises: Sort all the data in the time batch data according to the primary key; The hash value of each piece of data in the time batch data is calculated in the order of primary key sorting to obtain a single hash value for each piece of data.

4. The method according to claim 1, characterized in that The step of re-hashing the single hash value of each data in the time batch data to obtain the batch hash value of the batch of time batch data comprises: Concatenate the single hash value of each data in the time batch data according to the primary key order; The concatenated hash values ​​are re-hashed to obtain a batch hash value corresponding to the time batch data.

5. The method according to claim 1, characterized in that The step of using the batch hash values ​​of the preset batch number as leaf nodes to form a Merkle tree and obtaining the root hash value on the root node of the Merkle tree comprises: Initialize the batch hash values ​​of the preset batch number as leaf nodes in the order of reading time; After splicing two adjacent leaf nodes, they are re-hashed to form a Merkle tree of the data source from bottom to top, and the root hash value on the root node of the Merkle tree is obtained.

6. The method according to claim 1, characterized in that The step of verifying the root hash value on the Merkle tree root node to obtain a data verification result comprises: Generate multiple Merkle trees based on the data to be verified from multiple data sources; Verify the root hash values ​​on multiple Merkle tree root nodes to obtain data verification results; If the root hash values ​​on the root nodes of multiple Merkle trees are the same, the data verification result is normal; If the root hash values ​​on the root nodes of multiple Merkle trees are different, the data verification result is abnormal.

7. The method according to claim 6, characterized in that The step of: if the root hash values ​​on the root nodes of the multiple Merkle trees are different, then the data verification result is abnormal further includes: Determine the abnormal Merkle tree based on the root hash values ​​on the root nodes of multiple Merkle trees; Compare the abnormal Merkle tree from top to bottom and locate the leaf node where the abnormality occurs; The hash value of the time batch data corresponding to the abnormal leaf node is fully transmitted and compared to obtain the primary key corresponding to the abnormal hash value; The abnormal data to be verified is located according to the primary key corresponding to the abnormal hash value, and retry transmission compensation is performed on the abnormal data to be verified.

8. A data checking device, characterized in that: The device comprises: A data acquisition module is used to acquire the time batch data to be checked; A single hash module, used to calculate the hash value of each piece of data in the time batch data to obtain a single hash value of each piece of data; The batch hash module is used to re-hash the single hash value of each data to obtain the batch hash value of the batch data of the batch time; A tree module is constructed to form a Merkle tree using the batch hash values ​​of a preset number of batches as leaf nodes, and obtain the root hash value on the root node of the Merkle tree; The data verification module is used to verify the root hash value on the Merkle tree root node to obtain a data verification result.

9. A data checking device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the data checking method according to any one of claims 1 to 7.

10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the data verification method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Data checking method and device and computer storage medium

    CN107392764A

  • Merkel tree-based batch flight plan error correction method, device and system

    CN111915931A

  • Merkel tree-based transaction account checking method and system

    CN114266578A