Data generation method for distributed database, electronic device, and storage medium
The method generates verifiable data with a tree structure and synchronizes it through a binary log to ensure consistent mirror data across nodes, addressing data integrity and anti-tampering issues in distributed databases.
Patent Information
- Application Number
- US19/430703
- Authority / Receiving Office
- US · United States
- Patent Type
- Applications(United States)
- Current Assignee / Owner
- Priority Date
- 2025-05-26
- Filing Date
- 2025-12-23
- Publication Date
- 2026-11-26
AI Technical Summary
In distributed database systems, the asynchronous operation of primary and slave database nodes leads to inconsistencies in verifiable data, impairing the data anti-tampering function and causing synchronization and data integrity issues.
A data generation method involving the primary database node generates verifiable data with a tree structure, synchronizing it with target data through a binary log to slave nodes, ensuring consistent mirror data and enabling data integrity verification.
Ensures data integrity and normal operation of the anti-tampering function across all database nodes by maintaining synchronized verifiable data, enhancing data security and resource utilization.
Smart Images

Figure US20260379669A1-D00000_ABST
Abstract
Description
CROSS-REFERENCE TO RELATED APPLICATION
[0001] The present application claims the priority to Chinese Patent Application No. 202510686509.4, filed on May 26, 2025, the entire disclosure of which is incorporated herein by reference as portion of the present application.TECHNICAL FIELD
[0002] The present disclosure relates to a data generation method for a distributed database, an apparatus, and a device.BACKGROUND
[0003] A distributed database is a database system that stores data dispersedly on multiple nodes and communicates and collaborates through a network. Distributed database is widely used in the data service industry because of its advantages such as high scalability and high availability. A distributed database system usually includes a primary database node (master) and multiple slave database nodes (slave). The primary database node may provide both data write and read services, while the slave database nodes only provide data read services.
[0004] In order to realize a data anti-tampering function, a database node may record original data written into a database and generate corresponding verifiable data, so as to perform comparison and verification on the original data stored in the database node through the verifiable data, thereby ensuring the integrity of the original data at the database node.
[0005] However, in the distributed database system, because the primary database node and the slave database nodes run asynchronously, there may be a problem that the verifiable data generated by the primary database node is inconsistent with the verifiable data generated by the slave database nodes, which in turn affects the normal operation of the data anti-tampering function of the slave database nodes.SUMMARY
[0006] At least one embodiment of the present disclosure provides a data generation method for a distributed database, an apparatus, and a device.
[0007] At least one embodiment of the present disclosure provides a data generation method for a distributed database, including:
[0008] acquiring target data in a primary database node of the distributed database, where the target data includes at least two data records; generating corresponding verifiable data based on the target data, where the verifiable data includes at least one data group with a tree structure, leaf nodes of the data group are configured to map the data records, a tree root node of the data group is generated based on the leaf nodes, and the tree root node of each of the data groups is configured to jointly verify data integrity of the verifiable data; and synchronizing the target data and the verifiable data to a slave database node of the distributed database through a binary log to generate, at the slave database node, mirror data corresponding to the target data and the verifiable data, respectively.
[0009] At least one embodiment of the present disclosure provides a data generation apparatus for a distributed database, including:
[0010] an acquiring module, configured to acquire target data in a primary database node of the distributed database, where the target data includes at least two data records;
[0011] a generation module, configured to generate corresponding verifiable data based on the target data, where the verifiable data includes at least one data group with a tree structure, leaf nodes of the data group are configured to map the data records, a tree root node of the data group is generated based on the leaf nodes, and the tree root node of each of the data groups is configured to jointly verify data integrity of the verifiable data; and
[0012] a synchronization module, configured to synchronize the target data and the verifiable data to a slave database node of the distributed database through a binary log to generate, at the slave database node, mirror data corresponding to the target data and the verifiable data, respectively.
[0013] At least one embodiment of the present disclosure provides an electronic device, including: a processor and a memory;
[0014] the memory stores computer-executable instructions; and
[0015] the processor executes the computer-executable instructions stored in the memory to cause the processor to execute the data generation method for the distributed database according to at least one embodiment of the present disclosure.
[0016] At least one embodiment of the present disclosure provides a computer-readable storage medium, where computer-executable instructions are stored in the computer-readable storage medium, and when the computer-executable instructions are executed by a processor, the
[0017] data generation method for the distributed database according to at least one embodiment of the present disclosure is implemented.
[0018] At least one embodiment of the present disclosure provides a computer program product, including a computer program, where when the computer program is executed by a processor, the data generation method for the distributed database according to at least one embodiment of the present disclosure is implemented.BRIEF DESCRIPTION OF DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in at least one embodiment of the present disclosure, the drawings required in describing at least one embodiment of the present disclosure or the prior art will be briefly introduced below. Apparently, the drawings in the following description are some embodiments of the present disclosure, and for those skilled in the art, other drawings may also be obtained from these drawings without paying any creative labor.
[0020] FIG. 1 is a schematic diagram of an application scenario of an anti-tampering function provided by at least one embodiment of the present disclosure;
[0021] FIG. 2 is a first flowchart of a data generation method for a distributed database provided by at least one embodiment of the present disclosure;
[0022] FIG. 3 is a schematic structural diagram of verifiable data provided by at least one embodiment of the present disclosure;
[0023] FIG. 4 is a flowchart of a specific implementation of step S102 in the embodiment shown in FIG. 2;
[0024] FIG. 5 is a schematic diagram of a process of generating mirror data at a slave database node provided by at least one embodiment of the present disclosure;
[0025] FIG. 6 is a second flowchart of a data generation method for a distributed database provided by at least one embodiment of the present disclosure;
[0026] FIG. 7 is a flowchart of a specific implementation of step S204 in the embodiment shown in FIG. 6;
[0027] FIG. 8 is a schematic diagram of a process of generating verifiable log data provided by at least one embodiment of the present disclosure;
[0028] FIG. 9 is a structural block diagram of a data generation apparatus for a distributed database provided by at least one embodiment of the present disclosure;
[0029] FIG. 10 is a schematic structural diagram of an electronic device provided by at least one embodiment of the present disclosure; and
[0030] FIG. 11 is a schematic diagram of a hardware structure of an electronic device provided by at least one embodiment of the present disclosure.DETAILED DESCRIPTION
[0031] In order to make the purpose, technical solutions and advantages of at least one embodiment of the present disclosure clearer, the technical solutions in at least one embodiment of the present disclosure will be described clearly and completely below in combination with the drawings in at least one embodiment of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of them. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without paying creative labor belong to the protection scope of the present disclosure.
[0032] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present disclosure are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrance for users to choose authorization or rejection.
[0033] The application scenarios of at least one embodiment of the present disclosure are explained below:
[0034] The data generation method for the distributed database provided by at least one embodiment of the present disclosure may be applied to an application scenario of anti-tampering data generation of a distributed database system. Specifically, this solution may be applied to a server or an electronic device with similar functions that deploys a primary database node or an independent control node in the distributed database system. The server or the electronic device may implement the data generation method for the distributed database provided by at least one embodiment of the present disclosure by running various computer-executable instructions or computer programs. For example, the computer-executable instructions may be program-level commands, machine instructions or software instructions. The computer program may be a native program or a software module in an operating system; it may be a local application, that is, a program that needs to be installed in the operating system to run, or it may be a mini-program embedded in any APP, that is, a program that runs based on a browser environment. In summary, the above computer-executable instructions may be any form of instructions, and the above computer programs may be any form of applications, modules or plugins, and the specific implementation may be configured as needed.
[0035] FIG. 1 is a schematic diagram of an application scenario of an anti-tampering function provided by at least one embodiment of the present disclosure. As shown in FIG. 1, the distributed database includes a primary database node and multiple slave database nodes. The primary database node may generate original data in a database by receiving a write instruction sent by a terminal device operated by a user, and may synchronize the original data to the slave database nodes to form mirror data. At the same time, the primary database node may also receive a read instruction sent by the terminal device to access the original data in the above database. The slave database nodes only provide a data read service, that is, access the mirror data in the above database by receiving the read instruction sent by the terminal device. In the above distributed database system, in order to realize a data anti-tampering function, the primary database node may construct corresponding verifiable data based on the original data, so as to perform comparison and verification on the original data stored in the database node through the verifiable data, thereby ensuring the integrity of the original data at the database node.
[0036] However, the above process of constructing the verifiable data is performed asynchronously by the primary database node relative to the process of writing the original data and the process of synchronizing to the slave database nodes, for example, periodically obtaining the newly written original data and constructing it into the verifiable data. Since the original data obtained in each period may be different, the data size and content of the verifiable data constructed based on the original data may have certain randomness. In this case, if the slave database nodes also autonomously construct the corresponding verifiable data based on the received original data, it will lead to inconsistency between the verifiable data constructed by the slave database nodes and the verifiable data of the primary database node, which in turn leads to the inability to normally perform functions such as data synchronization and abnormal data location of the slave database nodes, that is, the failure of the data anti-tampering function.
[0037] At least one embodiment of the present disclosure provides a data generation method for a distributed database to solve the above problem.
[0038] Referring to FIG. 2, FIG. 2 is a first flowchart of a data generation method for a distributed database provided by at least one embodiment of the present disclosure. The method of at least one embodiment of the present disclosure may be applied to a server or other electronic devices used to deploy a primary database node or a control node in a distributed database system. Exemplarily, the data generation method for the distributed database provided by at least one embodiment of the present disclosure includes the following steps.
[0039] Step S101: acquiring target data in a primary database node of the distributed database, where the target data includes at least two data records.
[0040] Step S102: generating corresponding verifiable data based on the target data, where the verifiable data includes at least one data group with a tree structure, leaf nodes of the data group are configured to map the data records, a tree root node of the data group is generated based on the leaf nodes, and the tree root node of each of the data groups is configured to jointly verify data integrity of the verifiable data.
[0041] Step S103: synchronizing the target data and the verifiable data to a slave database node of the distributed database through a binary log to generate, at the slave database node, mirror data corresponding to the target data and the verifiable data, respectively.
[0042] Referring to the schematic diagram of the application scenario shown in FIG. 1, in at least one embodiment of the present disclosure, a server is used as an execution body to introduce the provided data generation method for the distributed database. Exemplarily, the server may acquire the target data in the primary database node of the distributed database based on a fixed period or other trigger conditions configured by a user. The server asynchronously acquires the target data in the primary database node, that is, the process in which the server acquires the target data in the primary database node by maintaining an independent processing process is independent of the process of writing data into the primary database node. The target data may be one or more data tables, each data table includes multiple data records, and the data records, that is, specific user data, may be stored in the data table in the form of data rows, such as specific business data such as commodity data and transaction data. The specific content of the data records is not limited here.
[0043] Then, the server constructs the verifiable data with a special data format based on the target data. Specifically, the verifiable data includes at least one data group with a tree structure, the leaf nodes of the data group are configured to map the data records, the tree root node of the
[0044] data group is generated based on the leaf nodes, and the tree root node of each of the data groups is configured to jointly verify the data integrity of the verifiable data.
[0045] Specifically, the verifiable data is a data structure with a forest structure (including one or more tree structures). The data group that constitutes the verifiable data is equivalent to a subset of the verifiable data, which is a structure with a tree structure. The tree structure is a data structure composed of leaf nodes, root nodes, a tree root node and other parts, including, for example, a complete binary tree, a Merkle tree, etc. The leaf nodes are at the end of the data group, and the leaf nodes are configured to store or map the target data. In a possible implementation, the leaf nodes store data digests of the target data, and the data digests are data that represents record content of the data records and is obtained by performing, for example, hash calculation on the data records in the target data. One or more data records may be subjected to hash mapping to obtain a corresponding data digest, which is then stored in the leaf nodes. When the data records are modified, the above data digests obtained through the hash mapping will change. By comparing the data in the leaf nodes of the anti-tampering data, it may be detected that the data records have been modified.
[0046] Further, the data group with the tree structure further includes at least one tree root node at the top layer of the tree structure, and the root node data is generated based on the corresponding leaf nodes. In a possible implementation, the tree root node is adjacent to the leaf nodes, that is, the tree root node is a parent node of the leaf nodes, and the corresponding tree root node may be directly obtained by performing hash calculation on at least two leaf nodes. In another possible implementation, the data group further includes at least one intermediate layer node between the tree root node and the leaf nodes, that is, at least two leaf nodes are concatenated and subjected to hash calculation to obtain a corresponding intermediate node, and then at least two pieces of intermediate node data are concatenated and subjected to hash calculation to obtain a parent node of the intermediate node, and so on for recursive calculation, and finally the tree root node of the data group is calculated.
[0047] Still further, the verifiable data with the forest structure includes one or more data groups, and accordingly, the tree root node data of each of the data groups is used to jointly verify the data integrity of the verifiable data. For example, after log records are acquired from a database, hash mapping is performed multiple times on the log records according to the data structure of the data group (the same as the previous calculation process of generating the data group) to obtain a
[0048] calculated hash value. Then, the calculated hash value is compared with a verification hash value calculated based on the tree root node of each of the data groups in the verifiable data corresponding to the target data. If the calculated hash value is the same as the verification hash value of the verifiable data, it indicates that the data records corresponding to the target data are complete and have not been tampered with; otherwise, it indicates that the data records have been tampered with. The verification hash value calculated based on the tree root node corresponding to each of the data groups in the verifiable data is configured as an unchangeable state.
[0049] FIG. 3 is a schematic structural diagram of verifiable data provided by at least one embodiment of the present disclosure. As shown in FIG. 3, the verifiable data includes a data group T1, a data group T2 and a data group T3. The data group T1 includes a leaf node P1, a leaf node P2, a leaf node P3 and a leaf node P4 in a leaf node layer; the data group T2 includes a leaf node P5 and a leaf node P6 in the leaf node layer; the data group T3 includes a leaf node P7 and a leaf node P8 (shown as P1, P2, P3, P4, P5, P6, P7 and P8 in the figure) in the leaf node layer; the above leaf nodes P1 to P8 are continuously arranged, and the leaf nodes P1 to P8 respectively store data digests of data records R1, R2, R3, R4, ..., R32 in the target data. Further, the data group T1 includes a tree root node Root_1 in a tree root node layer, the data group T2 includes a tree root node Root_2 in the tree root node layer, and the data group T3 includes a tree root node Root_3 in the tree root node layer. The tree root node Root_2 in the data group T2 is directly generated based on the corresponding leaf node P5 and the corresponding leaf node P6, for example, obtained by concatenating the leaf node P5 and the leaf node P6 and performing hash calculation; the tree root node Root_3 in the data group T3 is directly generated based on the corresponding leaf node P7 and the corresponding leaf node P8. The tree root node Root_1 in the data group T1 is obtained by first calculating the leaf node P1, the leaf node P2, the leaf node P3 and the leaf node P4 in pairs to obtain an intermediate node M1 and an intermediate node M2, and then performing hash calculation on the intermediate node M1 and the intermediate node M2 (shown as M1 and M2 in the figure). The tree root node at the top of each of the data groups represents the data integrity of one data record group in the target data corresponding to the data group respectively. When any data record in the data record group in the target data is changed, the value of the tree root node will change. When the value of the tree root node changes, the calculated hash value generated after calculation based on each tree root node will change, so that the verification hash value of the verifiable data corresponding to the target data cannot be matched, which in turn leads to the failure of consistency verification of the target data, that is, it is detected that the target data has been modified. Through the above method, the anti-tampering function of the target data may be realized.
[0050] In a possible implementation, as shown in FIG. 4, a specific implementation of step S102 includes steps S1021 to S1023.
[0051] In step S1021, a preset maximum data length is acquired.
[0052] In step S1022, data records in the target data are read based on the maximum data length to obtain at least one data record group, where a length of the data record group is not greater than the maximum data length.
[0053] In step S1023, a data group corresponding to each of the data record groups is constructed, and the verifiable data is obtained based on a set of the data groups.
[0054] Exemplarily, before constructing the verifiable data, the server selects data records not exceeding a preset maximum data length (for example, 100) through an independent asynchronous thread to determine a data record group (block). When there are a large number of data records to be processed in the target data, the data length of the formed data record group is relatively large, otherwise it is relatively small. Therefore, the data length of the data record group has certain randomness. Then, the corresponding data group is constructed based on the data record group, and the verifiable data is further constructed based on the set of the data groups. The maximum data length determines the anti-tampering performance of data. The larger the maximum data length, the more data records for generating the same data group, thereby making the space utilization rate higher, but the anti-tampering performance worse. Therefore, in a possible implementation, the maximum data length may be determined based on a data type of the target data, that is, the maximum data length is acquired according to the data type of the target data, and the corresponding maximum data length is determined through different data types, so that the data type matches the performance requirements of the anti-tampering function, and the resource utilization rate of the storage space is improved.
[0055] The above process of generating the verifiable data may be executed in the primary database node. Then, the primary database node and the slave database nodes synchronize data through a binary log (binlog), so as to synchronize the target data and the verifiable data corresponding to the target data to the slave database nodes, to generate, at the slave database nodes, the same mirror data as the target data and the verifiable data in the primary database node.
[0056] Thus, the slave database nodes also have the data anti-tampering function. After that, a user may access the verifiable data corresponding to the target data at the slave database nodes to verify the integrity of the target data and prevent the data from being tampered with.
[0057] FIG. 5 is a schematic diagram of a process of generating mirror data at a slave database node provided by at least one embodiment of the present disclosure. The above process will be further introduced below in combination with FIG. 5. As shown in FIG. 5, after a user writes original data by sending a write instruction to a primary database node, a server asynchronously configures part of the above original data stored in the primary database node as target data with an anti-tampering function, and then constructs corresponding verifiable data based on the target data. After the verifiable data is generated, the target data and the corresponding verifiable data are synchronized to the slave database node through a binary log in a distributed database system, and mirror data of the target data and mirror data of the verifiable data are generated, so that the target data and the verifiable data stored in the slave database node are consistent with the target data and the verifiable data in the primary database node.
[0058] Further, in a possible implementation, a target data table is stored in the primary database node, and before step S101, the method further includes step S100.
[0059] Step S100: configuring the target data table as an anti-tampering data table in response to a first configuration statement input by a user.
[0060] Accordingly, a specific implementation of step S101 includes step S101A.
[0061] Step S101A: asynchronously acquiring data records in the target data table in the primary database node.
[0062] Exemplarily, before executing the above generation of the verifiable data corresponding to the target data, the server may configure, according to the first configuration statement input by the user, a data table specified by the first configuration statement as an anti-tampering data table. Specifically, for example, a data table sheet_1, a data table sheet_2 and a data table sheet_3 are stored in the primary database node, and the above data tables are respectively used to store different business data. On this basis, by responding to the first configuration statement input by the user, the data table sheet_2 is configured as the anti-tampering data table. After that, the server will use the data table sheet_2 as the target data, acquire data records in the data table sheet_2, and construct verifiable data corresponding to the data table sheet_2 based on the data records, thereby realizing an anti-tampering function of the data table
[0063] sheet_2 and improving configuration flexibility. In another possible implementation, the server may also automatically determine a data table of a target business type as the target data according to a business type of each data table in the primary database node, and generate corresponding verifiable data, thereby starting an anti-tampering function of the data table of the target business type and improving data security.
[0064] In this embodiment, target data in a primary database node of a distributed database is acquired, where the target data includes at least two data records; corresponding verifiable data is generated based on the target data, where the verifiable data includes at least one data group with a tree structure, leaf nodes of the data group are configured to map the data records, a tree root node of the data group is generated based on the leaf nodes, and the tree root node of each of the data groups is configured to jointly verify data integrity of the verifiable data; and the target data and the verifiable data are synchronized to a slave database node of the distributed database through a binary log to generate, at the slave database node, mirror data corresponding to the target data and the verifiable data, respectively. The target data is acquired in the primary database node, and the target data is converted into the verifiable data including a plurality of data groups with tree structures, and then is synchronized to the slave database node through the binary log to generate the mirror data, thereby ensuring that the mirror data in the slave database node is consistent with the target data and the verifiable data in the primary database node, and enabling a data anti-tampering function of the slave database node to operate normally.
[0065] Referring to FIG. 6, FIG. 6 is a second flowchart of a data generation method for a distributed database provided by at least one embodiment of the present disclosure. In this embodiment, on the basis of the embodiment shown in FIG. 2, step S102 is further detailed, and a step of generating verifiable log data is added. The data generation method for the distributed database includes steps S201 to S207.
[0066] In step S201, new data input by a user is written into the primary database node through a first processing process.
[0067] In step S202, the new data in the primary database node is periodically read through a second processing process to obtain the target data.
[0068] Exemplarily, for the application scenario of the distributed database, the primary database node generates the verifiable data asynchronously. Specifically, the primary database node responds to an input instruction of the user through the first processing process, and writes
[0069] the new data input by the user into the database of the primary database node. On the other hand, the primary database node periodically reads the above new data from the primary database node through an independent second processing process, and uses the new data as the target data to construct the corresponding verifiable data, thereby enabling the above new data to become data with anti-tampering capability. The verifiable data is generated asynchronously, which may achieve full use of computing resources and improve resource use efficiency.
[0070] Step S203: reading, through the second processing process, the data records in the target data based on a maximum data length to obtain at least one data record group, where a length of the data record group is not greater than the maximum data length.
[0071] Step S204: constructing, through the second processing process, a data group corresponding to each of the data record groups.
[0072] Step S205: obtaining, through the second processing process, the verifiable data based on a set of the data groups.
[0073] Exemplarily, after the target data is selected, the data records in the target data are periodically read through the second processing process based on the maximum data length, and the data records are combined into at least one data record group based on the number of the data records, where the length of the data record group is not greater than the maximum data length. Then, the corresponding data group is constructed based on the data record group.
[0074] In a possible implementation, as shown in FIG. 7, a specific implementation of step S204 includes steps S2041 to S2044.
[0075] In step S2041, a data digest of each of the data records in the data record group is calculated, where the data digest is used to represent record content of the data record.
[0076] In step S2042, the data digests are grouped as leaf nodes to obtain at least one leaf node group.
[0077] In step S2043, data digests corresponding to the leaf nodes in each of the leaf node groups are concatenated, and hash mapping is performed on a concatenated result to obtain an upper-layer root node corresponding to each of the leaf node groups.
[0078] In step S2044, a tree root node of the data group is calculated based on upper-layer root nodes to obtain the data group.
[0079] Exemplarily, for a specific implementation of constructing the data group, firstly, through the second processing process, data digest extraction is performed on each of the data records in the data record group, for example, hash calculation is performed on the data records to obtain data digests representing the record content of the data records. After that, the data digests are used as the leaf nodes of the data group, and a series of leaf nodes arranged in series may be obtained. Taking an example that the array structure of the data group is a complete binary tree, every two adjacent leaf nodes constitute a leaf node group. Certainly, it may be understood that when the data group is in other tree structures, more leaf nodes may constitute a leaf node group, for example, every four adjacent leaf nodes constitute a leaf node group. The specific implementation of the leaf node group is not limited here. Still after that, for each leaf node group, the data digests stored in the leaf nodes in the leaf node group are respectively concatenated, and after hash mapping is performed on the concatenated result, the upper-layer root node corresponding to the leaf node group may be obtained. By analogy, the above adjacent upper-layer root nodes continue to constitute a node group, and the upper root nodes in the node group are concatenated and hash-mapped to obtain an upper root node of the upper layer of the next level. The above process is repeated until the tree root node of the data group is calculated. Finally, based on the leaf nodes, intermediate nodes and the tree root node and the mapping relationship (that is, the tree structure) between them, the data group corresponding to the data record group is obtained. After that, the above process is repeated, and the data groups respectively corresponding to all data record values corresponding to the target data may be obtained. The data groups are combined to generate the verifiable data.
[0080] Exemplarily, the verifiable data includes a verifiable data table, and the steps in this embodiment further include step S2045.
[0081] Step S2045: writing non-tree root nodes in the data group into the verifiable data table, and writing the tree root node of the data group into a system metadata table.
[0082] Exemplarily, when the verifiable data is implemented in the form of a data table, after obtaining node data at each level corresponding to the data group, data corresponding to the leaf nodes and the intermediate nodes is written into the verifiable data table, and the tree root node of the data group is written into the system metadata table. The system metadata table has the characteristic of being non-modifiable, thereby ensuring the non-modifiable effect of the verifiable data. After that, based on the tree root node of each of the data groups, integrity verification of the target data may be realized.
[0083] Further, on the other hand, in addition to generating the verifiable data corresponding to the target data to realize anti-tampering of the target data, the server may also generate verifiable log data corresponding to target log data in the database node, thereby realizing an anti-tampering function for the target log data. Specifically, this embodiment further includes steps S206 and S207.
[0084] Step S206: asynchronously acquiring target log data in a target database node of the distributed database, where the target log data includes at least two operation log records, and the target database node is at least one of the primary database node or a slave database node.
[0085] Step S207: generating corresponding verifiable log data locally at the target database node based on the target log data.
[0086] Exemplarily, the log data is data used to record operation records for the database. For example, after a user accesses specific data in the database, corresponding access log data is generated to record the operation behavior. For such data logs, there is also a need for anti-tampering. In this embodiment, the anti-tampering function of the target log data (operation log records) may also be realized while realizing the anti-tampering function of the target data (data records). Specifically, the database node may generate the corresponding verifiable log data based on the target log data stored in the database. When the target log data is modified, a calculated hash value generated based on the target log data will be inconsistent with a verification hash value corresponding to the verifiable log data, thereby realizing the anti-tampering function for the target log data. The data structure of the verifiable log data is similar to that of the verifiable data, and both include data groups with tree structures. The leaf nodes of the data group of the verifiable log data are configured to map the operation log records, the tree root node of the data group is generated based on the leaf nodes, and the tree root node of each of the data groups is configured to jointly verify the data integrity of the verifiable log data. For the specific implementation of acquiring the target log data and generating the verifiable log data based on the target log data, reference may be made to the specific implementation of acquiring the target data and generating the verifiable data based on the target data in the previous embodiments, which will not be repeated here.
[0087] Further, the step of generating the verifiable log data corresponding to the target log data is similar to the step of generating the verifiable data, and is also asynchronously executed by the database node, that is, the process of generating the target log data and the process of generating
[0088] the verifiable log data in the database node are asynchronously executed by different threads / processes. However, different from the step of generating the verifiable data, the primary database node and the slave database node may respectively generate the log data, asynchronously acquire the target log data and generate the verifiable log data based on the target log data, and there is no need to synchronize the data of the verifiable log data through the binary log. That is, the target log data in a target database node of the distributed database is asynchronously acquired, and the corresponding verifiable log data is locally generated at the target database node based on the target log data, where the target database node is at least one of the primary database node or a slave database node.
[0089] In a possible implementation, the method in this embodiment further includes step S2060.
[0090] Step S2060: responding to a user access instruction through a third processing process, and generating, at the target database node receiving the user access instruction, an operation log record corresponding to the user access instruction.
[0091] Accordingly, a specific implementation of step S206 includes: periodically reading the operation log records in the target database node through a fourth processing process to obtain the target log data.
[0092] Exemplarily, the third processing process may be a process of the primary database node or a process of the slave database node, that is, after the user accesses data in the primary database node or the slave database node, the primary database node or the slave database node that receives the user access instruction will generate a response operation log record locally, for example, including information such as access time and visitor identification. After that, the primary database node or the slave database node will periodically read the operation log records in the target database node through an independent fourth processing process as the target log data, and in a subsequent step, construct the corresponding verifiable log data based on an anti-tampering data structure and the target log data. Thus, the anti-tampering function for the target log data is realized.
[0093] Optionally, a target log table is stored in the target database node, and before step S206, the method further includes:
[0094] configuring the target log table in the target database node as an anti-tampering log table in response to a second configuration statement input by the user. Accordingly, a specific implementation of step S206 includes: asynchronously acquiring log records in the target log table in the target database node.
[0095] Exemplarily, before acquiring the target log data, the log records are stored in the primary database node or the slave database node in the form of data of a log table. The primary database node or the slave database node may configure specific log records as data with an anti-tampering function by receiving a second configuration statement input by the user, that is, configure the target log table as an anti-tampering log table. After that, the log records in the target log table in the target database node are asynchronously acquired, and the verifiable log data is generated based on the log records in the target log table, to implement content recording of the target log table, thereby achieving a purpose of verifying the integrity of the target log table based on the verifiable log data.
[0096] FIG. 8 is a schematic diagram of a process of generating verifiable log data provided by at least one embodiment of the present disclosure. As shown in FIG. 8, the distributed database includes a primary database node P1, a slave database node P2 and a slave database node P3. After receiving a user access instruction input by a user, the primary database node P1, the slave database node P2 and the slave database node P3 respectively generate a corresponding operation log record locally at their own database nodes, such as an operation log record R1 is generated at the primary database node P1, an operation log record R2 is generated at the slave database node P2, an operation log record R3 is generated at the slave database node P3, etc. After that, the primary database node P1, the slave database node P2 and the slave database node P3 respectively asynchronously process the operation log records generated by them, and respectively generate corresponding verifiable log data locally, that is, verifiable log data mR1 is generated at the primary database node P1, verifiable log data mR2 is generated at the slave database node P2, and verifiable log data mR3 is generated at the slave database node P3. The above database nodes communicate with each other, but the verifiable log data in each database node is not synchronized, but is respectively used to verify the integrity of target log data in each database node, thereby realizing the anti-tampering function of the operation log records corresponding to each database node.
[0097] Corresponding to the data generation method for the distributed database in the above embodiments, FIG. 9 is a structural block diagram of a data generation apparatus for a distributed database provided by at least one embodiment of the present disclosure. The method introduced in
[0098] the above embodiments may be performed by the data generation apparatus for the distributed database, and the apparatus may be implemented by at least one of software or hardware, and the apparatus may be integrated in an electronic device with a certain data processing function. The electronic device may include, but is not limited to, a mobile terminal with big data processing capability, and a fixed terminal with big data processing capability, such as a desktop computer and a supercomputer.
[0099] For convenience of explanation, only parts related to at least one embodiment of the present disclosure are shown. Referring to FIG. 9, the data generation apparatus 3 for the distributed database includes an acquiring module 31, a generation module 32 and a synchronization module 33.
[0100] The acquiring module 31 is configured to acquire target data in a primary database node of the distributed database, where the target data includes at least two data records.
[0101] The generation module 32 is configured to generate corresponding verifiable data based on the target data, where the verifiable data includes at least one data group with a tree structure, leaf nodes of the data group are configured to map the data records, a tree root node of the data group is generated based on the leaf nodes, and the tree root node of each of the data groups is configured to jointly verify data integrity of the verifiable data.
[0102] The synchronization module 33 is configured to synchronize the target data and the verifiable data to a slave database node of the distributed database through a binary log to generate, at the slave database node, mirror data corresponding to the target data and the verifiable data, respectively.
[0103] According to one or more embodiments of the present disclosure, the generation module 32 is further configured to: acquire a maximum data length according to a data type of the target data; read the data records in the target data based on the maximum data length to obtain at least one data record group, where a length of the data record group is not greater than the maximum data length; and construct a data group corresponding to each of the data record groups, and obtain the verifiable data based on a set of the data groups.
[0104] According to one or more embodiments of the present disclosure, when constructing the data group corresponding to each of the data record groups, the generation module 32 is further configured to: calculate a data digest of each of the data records in the data record group, where the data digest is used to represent record content of the data record; group the data digests as leaf nodes to obtain at least one leaf node group; concatenate data digests corresponding to the leaf nodes in each of the leaf node groups, and perform hash mapping on a concatenated result to obtain an upper-layer root node corresponding to each of the leaf node groups; and calculate the tree root node of the data group based on the upper-layer root nodes to obtain the data group.
[0105] According to one or more embodiments of the present disclosure, the verifiable data includes a verifiable data table, and when obtaining the verifiable data based on the set of the data groups, the generation module 32 is further configured to: write non-tree root nodes in the data group into the verifiable data table, and write the tree root node of the data group into a system metadata table.
[0106] According to one or more embodiments of the present disclosure, before acquiring the target data in the primary database node of the distributed database, the acquiring module 31 is further configured to: write new data input by a user into the primary database node through a first processing process; when acquiring the target data in the primary database node of the distributed database, the acquiring module 31 is further configured to: periodically read the new data in the primary database node through a second processing process to obtain the target data.
[0107] According to one or more embodiments of the present disclosure, a target data table is stored in the primary database node; the acquiring module 31 is further configured to: configure the target data table as an anti-tampering data table in response to a first configuration statement input by a user; the acquiring module 31 is further configured to: asynchronously acquire data records in the target data table in the primary database node.
[0108] According to one or more embodiments of the present disclosure, the acquiring module 31 is further configured to: asynchronously acquire target log data in a target database node of the distributed database, where the target log data includes at least two operation log records, and the target database node is at least one of the primary database node or a slave database node; the generation module 32 is further configured to: generate corresponding verifiable log data locally at the target database node based on the target log data.
[0109] According to one or more embodiments of the present disclosure, the acquiring module 31 is further configured to: respond to a user access instruction through a third processing process, and generate, at the target database node receiving the user access instruction, an operation log record corresponding to the user access instruction; when asynchronously acquiring the target log data in the target database node of the distributed database, the acquiring module 31 is further configured to: periodically read the operation log records in the target database node through a fourth processing process to obtain the target log data.
[0110] According to one or more embodiments of the present disclosure, a target log table is stored in the target database node; the acquiring module 31 is further configured to: configure the target log table in the target database node as an anti-tampering log table in response to a second configuration statement input by the user; when asynchronously acquiring the target log data in the target database node of the distributed database, the acquiring module 31 is further configured to: asynchronously acquire log records in the target log table in the target database node.
[0111] The acquiring module 31, the generation module 32 and the synchronization module 33 are connected in sequence. The data generation apparatus 3 for the distributed database provided by this embodiment may perform the technical solutions of the above method embodiments, and the implementation principles and technical effects thereof are similar, which will not be repeated here in this embodiment.
[0112] FIG. 10 is a schematic structural diagram of an electronic device according to at least one embodiment of the present disclosure. As shown in FIG. 10, the electronic device 4 includes:
[0113] a processor 41, and a memory 42 communicatively connected to the processor 41;
[0114] the memory 42 stores computer-executable instructions; and
[0115] the processor 41 executes the computer-executable instructions stored in the memory 42 to implement the data generation method for the distributed database in the embodiments shown in FIG. 2 to FIG. 8.
[0116] Optionally, the processor 41 and the memory 42 are connected through a bus 43.
[0117] The relevant description may be understood by referring to the relevant description and effects corresponding to the steps in the embodiments corresponding to FIG. 2 to FIG. 8, and details are not repeated here.
[0118] At least one embodiment of the present disclosure provides a computer-readable storage medium, where computer-executable instructions are stored in the computer-readable storage medium, and when the computer-executable instructions are executed by a processor, the data generation method for the distributed database provided by any one of the embodiments corresponding to FIG. 2-FIG. 8 of the present disclosure is implemented.
[0119] At least one embodiment of the present disclosure provides a computer program product, including a computer program, where when the computer program is executed by a processor, the data generation method for the distributed database provided by any one of the embodiments corresponding to FIG. 2-FIG. 8 of the present disclosure is implemented.
[0120] In order to achieve the above embodiments, at least one embodiment of the present disclosure further provides an electronic device.
[0121] Referring to FIG. 11, it shows a schematic structural diagram of an electronic device 900 suitable for implementing at least one embodiment of the present disclosure, and the electronic device 900 may be a terminal device or a server. The terminal device may include, but is not limited to, mobile terminals such as a mobile phone, a notebook computer, a digital broadcast receiver, a personal digital assistant (abbreviated as PDA), a tablet computer, a portable media player (abbreviated as PMP), a vehicle-mounted terminal (such as a vehicle navigation terminal), etc., and fixed terminals such as a digital TV, a desktop computer, etc. The electronic device shown in FIG. 11 is only an example, and should not bring any limitation to the function and scope of use of the embodiments of the present disclosure.
[0122] As shown in FIG. 11, the electronic device 900 may include a processing apparatus (such as a central processing unit, a graphics processor and the like) 901, which may perform various appropriate actions and processing according to a program stored in a read-only memory (abbreviated as ROM) 902 or a program loaded from a storage apparatus 908 into a random access memory (abbreviated as RAM) 903. In the RAM 903, various programs and data required for operations of the electronic device 900 are also stored. The processing apparatus 901, the ROM 902 and the RAM 903 are connected to each other through a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0123] Generally, the following apparatuses may be connected to the I / O interface 905: an input apparatus 906 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope and the like; an output apparatus 907 including, for example, a liquid crystal display (abbreviated as LCD), a speaker, a vibrator and the like; the storage apparatus 908 including, for example, a magnetic tape, a hard disk and the like; and a communication apparatus 909. The communication apparatus 909 may allow the electronic device 900 to perform wireless or wired communication with other devices to exchange data. Although FIG. 11 shows the electronic device 900 with various apparatuses, it should be understood that it is not required to implement or have all the apparatuses shown. More or fewer apparatuses may be implemented or provided alternatively.
[0124] Particularly, according to at least one embodiment of the present disclosure, the process described above with reference to the flowchart may be implemented as a computer software program. For example, at least one embodiment of the present disclosure include a computer program product, which includes a computer program carried on a computer-readable medium, where the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication apparatus 909, or installed from the storage apparatus 908, or installed from the ROM 902. When the computer program is executed by the processing apparatus 901, the above-mentioned functions defined in the method of the embodiments of the present disclosure are executed.
[0125] It should be noted that the above computer-readable medium in the present disclosure may be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or any combination of the above. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection with one or more wires, a portable computer magnetic disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, the computer-readable storage medium may be any tangible medium that contains or stores a program, and the program may be used by or in combination with an instruction execution system, apparatus or device. In the present disclosure, the computer-readable signal medium may include a data signal propagated in a baseband or as a part of a carrier wave, and computer-readable program code is carried therein. This propagated data signal may take many forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer-readable signal medium may also be any computer-readable medium other than the computer-readable storage medium, and the computer-readable signal medium may send, propagate or transmit the program used by or in combination with the instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted by any suitable medium, including but not limited to: a wire, an optical cable, RF (radio frequency), etc., or any suitable combination of the above.
[0126] The above computer-readable medium may be included in the above electronic device, or may exist alone without being assembled into the electronic device.
[0127] The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by the electronic device, the electronic device is caused to execute the method shown in the above embodiments.
[0128] The computer program code for executing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, where the above programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as "C" language or similar programming languages. The program code may be executed entirely on a user's computer, partly executed on a user's computer, executed as an independent software package, partly executed on a user's computer and partly executed on a remote computer, or entirely executed on a remote computer or server. In the case of involving the remote computer, the remote computer may be connected to the user's computer through any kind of network, including a local area network (abbreviated as LAN) or a wide area network (abbreviated as WAN), or it may be connected to an external computer (for example, connected by using Internet provided by an Internet service provider).
[0129] The flowcharts and block diagrams in the drawings illustrate the possibly implemented architectures, functions and operations of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, program segment, or part of code, and the module, program segment, or part of code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that, in some alternative implementations, the functions marked in the blocks may also occur in an order different from that marked in the drawings. For example, two blocks shown in succession may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in at least one of the block diagram or the flowchart, and the combination of the blocks in at least one of the block diagram or the flowchart may be implemented by a dedicated hardware-based system that executes specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.
[0130] The involved units or modules described in the embodiments of the present disclosure may be implemented by software or by hardware. Among them, the name of a unit or module does not constitute a limitation on the unit itself under certain circumstances.
[0131] The functions described above herein may be performed at least partially by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate array (FPGA), application specific integrated circuit (ASIC), application specific standard product (ASSP), system on chip (SOC), complex programmable logical device (CPLD) and so on.
[0132] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store programs for use by or in combination with an instruction execution system, apparatus or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or any suitable combination of the above. More specific examples of the machine-readable storage medium will include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0133] According to one or more embodiments of the present disclosure, a data generation method for a distributed database is provided, including:
[0134] acquiring target data in a primary database node of the distributed database, where the target data includes at least two data records; generating corresponding verifiable data based on the target data, where the verifiable data includes at least one data group with a tree structure, leaf nodes of the data group are configured to map the data records, a tree root node of the data group is generated based on the leaf nodes, and the tree root node of each of the data groups is configured to jointly verify data integrity of the verifiable data; and synchronizing the target data and the verifiable data to a slave database node of the distributed database through a binary log to generate, at the slave database node, mirror data corresponding to the target data and the verifiable data, respectively.
[0135] According to one or more embodiments of the present disclosure, the generating the corresponding verifiable data based on the target data includes: acquiring a maximum data length according to a data type of the target data; reading the data records in the target data based on the maximum data length to obtain at least one data record group, where a length of the data record group is not greater than the maximum data length; and constructing a data group corresponding to each of the data record groups, and obtaining the verifiable data based on a set of the data groups.
[0136] According to one or more embodiments of the present disclosure, the constructing the data group corresponding to each of the data record groups includes: calculating a data digest of each of the data records in the data record group, where the data digest is used to represent record content of the data record; grouping the data digests as leaf nodes to obtain at least one leaf node group; concatenating data digests corresponding to the leaf nodes in each of the leaf node groups, and performing hash mapping on a concatenated result to obtain an upper-layer root node corresponding to each of the leaf node groups; and calculating the tree root node of the data group based on the upper-layer root nodes to obtain the data group.
[0137] According to one or more embodiments of the present disclosure, the verifiable data includes a verifiable data table, and the obtaining the verifiable data based on the set of the data groups includes: writing non-tree root nodes in the data group into the verifiable data table, and writing the tree root node of the data group into a system metadata table.
[0138] According to one or more embodiments of the present disclosure, before the acquiring the target data in the primary database node of the distributed database, the method further includes: writing, through a first processing process, new data input by a user into the primary database node; and the acquiring the target data in the primary database node of the distributed database includes: periodically reading, through a second processing process, the new data in the primary database node to obtain the target data.
[0139] According to one or more embodiments of the present disclosure, a target data table is stored in the primary database node, and the method further includes: configuring the target data table as an anti-tampering data table in response to a first configuration statement input by a user; and the acquiring the target data in the primary database node of the distributed database includes: asynchronously acquiring data records in the target data table in the primary database node.
[0140] According to one or more embodiments of the present disclosure, the method further includes: asynchronously acquiring target log data in a target database node of the distributed database, where the target log data includes at least two operation log records, and the target database node is at least one of the primary database node or a slave database node; and generating, based on the target log data, corresponding verifiable log data locally at the target database node.
[0141] According to one or more embodiments of the present disclosure, the method further includes: responding to a user access instruction through a third processing process, and generating, at the target database node receiving the user access instruction, an operation log record corresponding to the user access instruction; the asynchronously acquiring the target log data in the target database node of the distributed database includes: periodically reading, through a fourth processing process, the operation log records in the target database node to obtain the target log data.
[0142] According to one or more embodiments of the present disclosure, a target log table is stored in the target database node, and the method further includes: configuring the target log table in the target database node as an anti-tampering log table in response to a second configuration statement input by the user; and the asynchronously acquiring the target log data in the target database node of the distributed database includes: asynchronously acquiring log records in the target log table in the target database node.
[0143] According to one or more embodiments of the present disclosure, a data generation apparatus for a distributed database is provided, including:
[0144] an acquiring module, configured to acquire target data in a primary database node of the distributed database, where the target data includes at least two data records;
[0145] a generation module, configured to generate corresponding verifiable data based on the target data, where the verifiable data includes at least one data group with a tree structure, leaf nodes of the data group are configured to map the data records, a tree root node of the data group is generated based on the leaf nodes, and the tree root node of each of the data groups is configured to jointly verify data integrity of the verifiable data; and
[0146] a synchronization module, configured to synchronize the target data and the verifiable data to a slave database node of the distributed database through a binary log to generate, at the slave database node, mirror data corresponding to the target data and the verifiable data, respectively.
[0147] According to one or more embodiments of the present disclosure, the generation module is further configured to: acquire a maximum data length according to a data type of the target data; read the data records in the target data based on the maximum data length to obtain at least one data record group, where a length of the data record group is not greater than the maximum data length; and construct a data group corresponding to each of the data record groups, and obtain the verifiable data based on a set of the data groups.
[0148] According to one or more embodiments of the present disclosure, when constructing the data group corresponding to each of the data record groups, the generation module is further configured to: calculate a data digest of each of the data records in the data record group, where the data digest is used to represent record content of the data record; group the data digests as leaf nodes to obtain at least one leaf node group; concatenate data digests corresponding to the leaf nodes in each of the leaf node groups, and perform hash mapping on a concatenated result to obtain an upper-layer root node corresponding to each of the leaf node groups; and calculate the tree root node of the data group based on the upper-layer root nodes to obtain the data group.
[0149] According to one or more embodiments of the present disclosure, the verifiable data includes a verifiable data table, and when obtaining the verifiable data based on the set of the data groups, the generation module is further configured to: write non-tree root nodes in the data group into the verifiable data table, and write the tree root node of the data group into a system metadata table.
[0150] According to one or more embodiments of the present disclosure, before the acquiring the target data in the primary database node of the distributed database, the acquiring module is further configured to: write, through a first processing process, new data input by a user into the primary database node; when acquiring the target data in the primary database node of the distributed database, the acquiring module is further configured to: periodically read, through a second processing process, the new data in the primary database node to obtain the target data.
[0151] According to one or more embodiments of the present disclosure, a target data table is stored in the primary database node; the acquiring module is further configured to: configure the target data table as an anti-tampering data table in response to a first configuration statement input by a user; the acquiring module is further configured to: asynchronously acquire data records in the target data table in the primary database node.
[0152] According to one or more embodiments of the present disclosure, the acquiring module is further configured to: asynchronously acquire target log data in a target database node of the distributed database, where the target log data includes at least two operation log records, and the target database node is at least one of the primary database node or a slave database node; the generation module is further configured to: generate, based on the target log data, corresponding verifiable log data locally at the target database node.
[0153] According to one or more embodiments of the present disclosure, the acquiring module is further configured to: respond to a user access instruction through a third processing process, and generate, at the target database node receiving the user access instruction, an operation log record corresponding to the user access instruction; when asynchronously acquiring the target log data in the target database node of the distributed database, the acquiring module is further configured to: periodically read, through a fourth processing process, the operation log records in the target database node to obtain the target log data.
[0154] According to one or more embodiments of the present disclosure, a target log table is stored in the target database node; the acquiring module is further configured to: configure the target log table in the target database node as an anti-tampering log table in response to a second configuration statement input by the user; when asynchronously acquiring the target log data in the target database node of the distributed database, the acquiring module is further configured to: asynchronously acquire log records in the target log table in the target database node.
[0155] According to one or more embodiments of the present disclosure, an electronic device is provided, including: at least one processor and a memory;
[0156] the memory stores computer-executable instructions; and
[0157] the at least one processor executes the computer-executable instructions stored in the memory to cause the processor to execute the data generation method for the distributed database according to one or more embodiments of the present disclosure.
[0158] According to one or more embodiments of the present disclosure, a computer-readable storage medium is provided, where computer-executable instructions are stored in the computer-readable storage medium, and when the computer-executable instructions are executed by a processor, the data generation method for the distributed database according to one or more embodiments of the present disclosure.
[0159] According to one or more embodiments of the present disclosure, a computer program product is provided, including a computer program, where when the computer program is executed by a processor, the data generation method for the distributed database according to one or more embodiments of the present disclosure.
[0160] The above description is only preferred embodiments of the present disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the disclosure scope involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above technical features, but also covers other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above inventive concept. For example, the above features and the technical features provided in the present disclosure (but not limited to) with similar functions are replaced with each other to form a technical solution.
[0161] Additionally, although the various operations are depicted in a particular order, it should not be understood as requiring the operations to be performed in the particular order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, although the above discussion contains a number of specific implementation details, these should not be interpreted as limiting the scope of the present disclosure. Certain features described in the context of separate embodiments may also be implemented in a single embodiment in combination. Conversely, various features described in the context of a single embodiment may also be implemented in multiple embodiments individually or in any suitable sub-combination.
[0162] Although the subject matter has been described in language specific to at least one of structural features or method logic actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Conversely, the specific features and actions described above are merely exemplary forms for implementing the claims.
Claims
1. A data generation method for a distributed database, comprising:acquiring target data in a primary database node of the distributed database, wherein the target data comprises at least two data records;generating corresponding verifiable data based on the target data, wherein the verifiable data comprises at least one data group with a tree structure, leaf nodes of the data group are configured to map the data records, a tree root node of the data group is generated based on the leaf nodes, and the tree root node of each of data groups is configured to jointly verify data integrity of the verifiable data; andsynchronizing the target data and the verifiable data to a slave database node of the distributed database through a binary log to generate, at the slave database node, mirror data respectively corresponding to the target data and the verifiable data.
2. The data generation method of claim 1, wherein the generating the corresponding verifiable data based on the target data comprises:acquiring a maximum data length according to a data type of the target data;reading the data records in the target data based on the maximum data length to obtain at least one data record group, wherein a length of the data record group is not greater than the maximum data length; andconstructing a data group corresponding to each of data record groups, and obtaining the verifiable data based on a set of data groups.
3. The data generation method of claim 2, wherein the constructing the data group corresponding to each of the data record groups comprises:calculating a data digest of each of the data records in the data record group, wherein the data digest is configured to represent record content of each of the data records;grouping data digests as leaf nodes to obtain at least one leaf node group;concatenating the data digests corresponding to the leaf nodes in each of leaf node groups, and performing hash mapping on a concatenated result to obtain an upper-layer root node corresponding to each of the leaf node groups; andcalculating the tree root node of the data group based on upper-layer root nodes corresponding to the at least one leaf node group to obtain the data group.
4. The data generation method of claim 3, wherein the verifiable data comprises a verifiable data table, and the obtaining the verifiable data based on the set of the data groups comprises:writing non-tree root nodes in the data group into the verifiable data table, and writing the tree root node of the data group into a system metadata table.
5. The data generation method of claim 1, wherein before the acquiring the target data in the primary database node of the distributed database, the data generation method further comprises:writing, through a first processing process, new data input by a user into the primary database node; andthe acquiring the target data in the primary database node of the distributed database comprises:periodically reading, through a second processing process, the new data in the primary database node to obtain the target data.
6. The data generation method of claim 1, wherein a target data table is stored in the primary database node, and the data generation method further comprises:configuring the target data table as an anti-tampering data table in response to a first configuration statement input by a user; andthe acquiring the target data in the primary database node of the distributed database comprises:asynchronously acquiring data records in the target data table in the primary database node.
7. The data generation method of claim 1, wherein the data generation method further comprises:asynchronously acquiring target log data in a target database node of the distributed database, wherein the target log data comprises at least two operation log records, and the target database node is at least one of the primary database node or a slave database node; andgenerating, based on the target log data, corresponding verifiable log data locally at the target database node.
8. The data generation method of claim 7, further comprising:responding to a user access instruction through a third processing process, and generating, at the target database node receiving the user access instruction, an operation log record corresponding to the user access instruction; andthe asynchronously acquiring the target log data in the target database node of the distributed database comprises:periodically reading, through a fourth processing process, the operation log records in the target database node to obtain the target log data.
9. The data generation method of claim 7, wherein a target log table is stored in the target database node, and the data generation method further comprises:configuring the target log table in the target database node as an anti-tampering log table in response to a second configuration statement input by a user; andthe asynchronously acquiring the target log data in the target database node of the distributed database comprises:asynchronously acquiring log records in the target log table in the target database node.
10. An electronic device, comprising at least one processor and a memory,wherein the memory has computer-executable instructions stored thereon; andthe at least one processor is configured to execute the computer-executable instructions stored in the memory to implement a data generation method for a distributed database, and the data generation method comprises:acquiring target data in a primary database node of the distributed database, wherein the target data comprises at least two data records;generating corresponding verifiable data based on the target data, wherein the verifiable data comprises at least one data group with a tree structure, leaf nodes of the data group are configured to map the data records, a tree root node of the data group is generated based on the leaf nodes, and the tree root node of each of data groups is configured to jointly verify data integrity of the verifiable data; andsynchronizing the target data and the verifiable data to a slave database node of the distributed database through a binary log to generate, at the slave database node, mirror data respectively corresponding to the target data and the verifiable data.
11. The electronic device of claim 10, wherein the generating the corresponding verifiable data based on the target data comprises:acquiring a maximum data length according to a data type of the target data;reading the data records in the target data based on the maximum data length to obtain at least one data record group, wherein a length of the data record group is not greater than the maximum data length; andconstructing a data group corresponding to each of data record groups, and obtaining the verifiable data based on a set of data groups.
12. The electronic device of claim 11, wherein the constructing the data group corresponding to each of the data record groups comprises:calculating a data digest of each of the data records in the data record group, wherein the data digest is configured to represent record content of each of the data records;grouping data digests as leaf nodes to obtain at least one leaf node group;concatenating the data digests corresponding to the leaf nodes in each of leaf node groups, and performing hash mapping on a concatenated result to obtain an upper-layer root node corresponding to each of the leaf node groups; andcalculating the tree root node of the data group based on upper-layer root nodes corresponding to the at least one leaf node group to obtain the data group.
13. The electronic device of claim 12, wherein the verifiable data comprises a verifiable data table, and the obtaining the verifiable data based on the set of the data groups comprises:writing non-tree root nodes in the data group into the verifiable data table, and writing the tree root node of the data group into a system metadata table.
14. The electronic device of claim 10, wherein before the acquiring the target data in the primary database node of the distributed database, the data generation method further comprises:writing, through a first processing process, new data input by a user into the primary database node; andthe acquiring the target data in the primary database node of the distributed database comprises:periodically reading, through a second processing process, the new data in the primary database node to obtain the target data.
15. The electronic device of claim 10, wherein a target data table is stored in the primary database node, and the data generation method further comprises:configuring the target data table as an anti-tampering data table in response to a first configuration statement input by a user; andthe acquiring the target data in the primary database node of the distributed database comprises:asynchronously acquiring data records in the target data table in the primary database node.
16. The electronic device of claim 10, wherein the data generation method further comprises:asynchronously acquiring target log data in a target database node of the distributed database, wherein the target log data comprises at least two operation log records, and the target database node is at least one of the primary database node or a slave database node; andgenerating, based on the target log data, corresponding verifiable log data locally at the target database node.
17. The electronic device of claim 16, wherein the data generation method further comprises:responding to a user access instruction through a third processing process, and generating, at the target database node receiving the user access instruction, an operation log record corresponding to the user access instruction; andthe asynchronously acquiring the target log data in the target database node of the distributed database comprises:periodically reading, through a fourth processing process, the operation log records in the target database node to obtain the target log data.
18. The electronic device of claim 16, wherein a target log table is stored in the target database node, and the data generation method further comprises:configuring the target log table in the target database node as an anti-tampering log table in response to a second configuration statement input by a user; andthe asynchronously acquiring the target log data in the target database node of the distributed database comprises:asynchronously acquiring log records in the target log table in the target database node.
19. A non-transitory computer-readable storage medium, wherein computer-executable instructions are stored in the computer-readable storage medium, and when the computer-executable instructions are executed by at least one processor, a data generation method for a distributed database is implemented, the data generation method comprising:acquiring target data in a primary database node of the distributed database, wherein the target data comprises at least two data records;generating corresponding verifiable data based on the target data, wherein the verifiable data comprises at least one data group with a tree structure, leaf nodes of the data group are configured to map the data records, a tree root node of the data group is generated based on the leaf nodes, and the tree root node of each of data groups is configured to jointly verify data integrity of the verifiable data; andsynchronizing the target data and the verifiable data to a slave database node of the distributed database through a binary log to generate, at the slave database node, mirror data respectively corresponding to the target data and the verifiable data.
20. The non-transitory computer-readable storage medium of claim 19, wherein the generating the corresponding verifiable data based on the target data comprises:acquiring a maximum data length according to a data type of the target data;reading the data records in the target data based on the maximum data length to obtain at least one data record group, wherein a length of the data record group is not greater than the maximum data length; andconstructing a data group corresponding to each of data record groups, and obtaining the verifiable data based on a set of data groups.
