Data storage method, device, equipment and storage medium

By storing the value value to a preset file in the Merkel B+ tree and using storage location information, the problem of not compact storage and slow writing tree process is solved, and more efficient data storage and updates are achieved.

CN116301597BActive Publication Date: 2025-07-18HANGZHOU QULIAN TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310111372.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-01-16
Publication Date
2025-07-18
Estimated Expiration
2043-01-16

AI Technical Summary

Technical Problem

In the existing Merkel B+ tree, the value value in the key-value pair stored by the data node is large, resulting in poor storage of disk pages, resulting in wasted storage space and write enlargement, and the write tree process is slow.

Method used

Store the value value in a preset file, and use the storage location information as the value value in the Merkel B+ tree to build a data node, reduce the value size of the data storage in the disk page, update it through hash value, and reduce the number of memory reads.

Benefits of technology

It improves the storage space utilization of disk pages, reduces write amplification, shortens the write tree process time, and improves data storage and update efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116301597B_ABST
    Figure CN116301597B_ABST
Patent Text Reader

Abstract

The present application discloses a data storage method, apparatus, device, and storage medium, belonging to the field of computer technology. The method includes: storing the value of each first key-value pair among multiple first key-value pairs to be stored into a preset file; generating multiple second key-value pairs corresponding one-to-one to the multiple first key-value pairs, where the key of the second key-value pair is the key of the corresponding first key-value pair, and the value of the second key-value pair is the storage location information of the value of the corresponding first key-value pair; constructing a Merkle B+ tree according to the multiple second key-value pairs, where the data nodes in the Merkle B+ tree contain the second key-value pairs; storing the data of each node in the Merkle B+ tree to a disk page. In the present application, the value contained in the data nodes in the Merkle B+ tree is very small, so the data storage in the disk page is relatively compact, thereby not only reducing the waste of the storage space of the disk page, but also reducing the write amplification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technologies, and particularly to a data storage method, apparatus, device, and storage medium. Background Art

[0002] The Merkle B+ tree is a tree structure improved based on the B+ tree, which includes two types of nodes: index nodes and data nodes at the last layer. In the related art, the index nodes store the minimum key and hash value of their subordinate nodes, and the data nodes store key-value pairs (i.e., key-value). In the Merkle B+ tree, the data stored in each node is stored in a disk page.

[0003] To adapt to the read and write strategies of disks, it is usually specified that the size of each disk page is 4K (kilobytes). However, since the value in the key-value pair stored in the data node is usually relatively large, the data storage in the disk page is not compact. For example, a 4K disk page can only store a 3K value. And data reading and writing can only be performed in units of disk pages, so the reading and writing of node data smaller than the disk page size will cause the reading and writing of the entire disk page, which results in a large write amplification. Summary of the Invention

[0004] This application provides a data storage method, apparatus, device, and storage medium, which can reduce write amplification. The technical solution is as follows:

[0005] In a first aspect, a data storage method is provided. The method includes:

[0006] Obtain a plurality of first key-value pairs to be stored; store the value of each first key-value pair in the plurality of first key-value pairs into a preset file to obtain the storage location information of the value of each first key-value pair; generate a plurality of second key-value pairs corresponding one-to-one to the plurality of first key-value pairs, where the key of a second key-value pair is the key of a corresponding first key-value pair, and the value of a second key-value pair is the storage location information of the value of a corresponding first key-value pair; construct a Merkle B+ tree according to the plurality of second key-value pairs, where the data nodes in the Merkle B+ tree include the second key-value pairs; store the data of each node in the Merkle B+ tree into a disk page.

[0007] In this application, the value of the first key-value pair is stored in a preset file, and the storage location information of the value of the first key-value pair is stored as the value of the second key-value pair in the data node. In this case, the value contained in the data node in the Merkle B+ tree is very small, so the data storage in the disk page is relatively compact. In this way, a disk page can store many values, which can not only reduce the waste of the storage space of the disk page, but also reduce the write amplification.

[0008] Optionally, the storage location information of the value of the first key-value pair includes the file identifier of the preset file storing the value of the first key-value pair, the offset of the value of the first key-value pair in the preset file, and the byte length of the value of the first key-value pair.

[0009] Optionally, after storing the data of each node in the Merkle B+ tree into the disk page, it further includes:

[0010] Receiving a query instruction carrying a target key value; obtaining a specified key-value pair stored in the disk page according to the target key value, where the specified key-value pair is a key-value pair in the data node of the Merkle B+ tree whose key value is the target key value; determining the value at the storage location indicated by the value of the specified key-value pair in the preset file as the target value.

[0011] Optionally, before constructing the Merkle B+ tree according to the multiple second key-value pairs, it further includes:

[0012] Obtaining the hash value of the value of each first key-value pair in the multiple first key-value pairs;

[0013] The constructing the Merkle B+ tree according to the multiple second key-value pairs includes:

[0014] Constructing the Merkle B+ tree according to the multiple second key-value pairs and the hash value of the value of the first key-value pair corresponding to each second key-value pair in the multiple second key-value pairs; wherein, each data node in the Merkle B+ tree contains at least one specified data, and the specified data includes a second key-value pair and the hash value of the corresponding value of the first key-value pair; each index node in the Merkle B+ tree contains the minimum key and hash value of each subordinate node, the minimum key of the node is the smallest key value among all the key values contained in the node, and the hash value of the node is the hash value of the data obtained by splicing all the hash values contained in the node.

[0015] Optionally, after storing the data of each node in the Merkel B+ tree to the disk page, the method further includes:

[0016] Receiving an addition instruction, where the addition instruction carries a first target key-value pair; obtaining a hash value of the value of the first target key-value pair; storing the value of the first target key-value pair to the preset file to obtain storage location information of the value of the first target key-value pair; generating a second target key-value pair corresponding to the first target key-value pair, where the key of the second target key-value pair is the key of the first target key-value pair, and the value of the second target key-value pair is the storage location information of the value of the first target key-value pair; obtaining the data of a target data node stored in the disk page according to the key of the second target key-value pair, where the target data node is the data node to be inserted in the Merkel B+ tree for the second target key-value pair; adding specified target data to the data of the target data node to update the target data node, where the specified target data includes the second target key-value pair and the hash value of the value of the first target key-value pair; if the data volume of the updated target data node is less than or equal to the preset data volume, determining the smallest key among all the keys included in the updated target data node as the minimum key of the updated target data node, and determining the hash value of the data obtained by concatenating all the hash values included in the updated target data node as the hash value of the updated target data node; updating the index node in the Merkel B+ tree according to the minimum key and hash value of the updated target data node; storing the data of the updated target data node and the data of the updated index node to the disk page.

[0017] Optionally, after adding specified target data to the data of the target data node to update the target data node, the method further includes:

[0018] If the data volume of the updated target data node is greater than the preset data volume, splitting the updated target data node into at least two data nodes, where the data volume of each of the at least two data nodes is less than or equal to the preset data volume; for any one of the at least two data nodes, determining the smallest key among all the keys included in the one data node as the minimum key of the one data node, and determining the hash value of the data obtained by concatenating all the hash values included in the one data node as the hash value of the one data node; updating the index node in the Merkel B+ tree according to the minimum key and hash value of each of the at least two data nodes; storing the data of each of the at least two data nodes and the data of the updated index node to the disk page.

[0019] Optionally, the number of the preset files is one or more, the storage space sizes of the one or more preset files are the same, and the one or more preset files are created sequentially. The method further includes:

[0020] If the value of a key-value pair needs to be stored in the preset file, when the remaining storage space of the last preset file among all the created preset files is sufficient to store the value of the key-value pair, store the value of the key-value pair in the last preset file; when the remaining storage space of the last preset file is not sufficient to store the value of the key-value pair, create a new preset file and store the value of the key-value pair in the newly created preset file.

[0021] Optionally, the storage location information of the value of the first key-value pair includes the file identifier of the preset file storing the value of the first key-value pair, the offset of the value of the first key-value pair in the preset file, and the byte length of the value of the first key-value pair;

[0022] The method further includes:

[0023] Create a record table, where the record table includes the file identifier, file size, file discarded size, and transaction identifier of each preset file among all the created preset files. Among them, the preset file identified by the file identifier with the same file size and file discarded size in the record table is a historical preset file;

[0024] The method further includes:

[0025] If the Merkle B+ tree is updated after executing a transaction, determine the historical key-value pairs that are updated or deleted in the data nodes in the Merkle B+ tree during the execution of the transaction; increase the file discarded size corresponding to the file identifier in the value of the historical key-value pair in the record table by the byte length of the value of the historical key-value pair, and update the transaction identifier corresponding to the file identifier in the value of the historical key-value pair in the record table to the identifier of the transaction;

[0026] The method further includes:

[0027] If the identifier of the currently pending transaction is the sum of the transaction identifier corresponding to the file identifier of a historical preset file in the record table and the number of preset versions, delete the historical preset file, where the number of preset versions is the number of rollback versions supported by the Merkle B+ tree.

[0028] In a second aspect, a data storage device is provided, the device comprising:

[0029] A first acquisition module, configured to acquire a plurality of first key-value pairs to be stored;

[0030] A first storage module, configured to store the value of each first key-value pair among the plurality of first key-value pairs into a preset file, to obtain the storage location information of the value of each first key-value pair;

[0031] A generation module, configured to generate a plurality of second key-value pairs corresponding one-to-one to the plurality of first key-value pairs, where the key value of a second key-value pair is the key value of a corresponding first key-value pair, and the value of a second key-value pair is the storage location information of the value of a corresponding first key-value pair;

[0032] A construction module, configured to construct a Merkle B+ tree according to the plurality of second key-value pairs, where the data nodes in the Merkle B+ tree contain the second key-value pairs;

[0033] A second storage module, configured to store the data of each node in the Merkle B+ tree into a disk page.

[0034] In a third aspect, a computer device is provided, the computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, where when the computer program is executed by the processor, it implements the data storage method described in the first aspect above.

[0035] In a fourth aspect, a computer-readable storage medium is provided, the computer-readable storage medium storing a computer program, where when the computer program is executed by a processor, it implements the data storage method described in the first aspect above.

[0036] In a fifth aspect, a computer program product containing instructions is provided, which when running on a computer, causes the computer to execute the steps of the data storage method described in the first aspect above.

[0037] It can be understood that the beneficial effects of the above second aspect, third aspect, fourth aspect, and fifth aspect can refer to the relevant descriptions in the first aspect above, and will not be elaborated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0039] Figure 1 It is a schematic diagram of the first Merkel B+ tree provided by an embodiment of the present application;

[0040] Figure 2 It is a schematic diagram of the second Merkel B+ tree provided by an embodiment of the present application;

[0041] Figure 3 It is a flowchart of a data storage method provided by an embodiment of the present application;

[0042] Figure 4 It is a schematic diagram of the third Merkel B+ tree provided by an embodiment of the present application;

[0043] Figure 5 It is a schematic diagram of the key-value pair distribution and merging operations of a Merkel B+ tree provided by an embodiment of the present application;

[0044] Figure 6 It is a schematic diagram of the node splitting operation of a Merkel B+ tree provided by an embodiment of the present application;

[0045] Figure 7 It is a schematic diagram of a transaction updating a Merkel B+ tree provided by an embodiment of the present application;

[0046] Figure 8 It is a schematic diagram of the structure of a data storage device provided by an embodiment of the present application;

[0047] Figure 9 It is a schematic diagram of the structure of a computer device provided by an embodiment of the present application. Detailed implementation manners

[0048] To make the objectives, technical solutions, and advantages of the present application clearer, the following will further describe the embodiments of the present application in detail with reference to the accompanying drawings.

[0049] It should be understood that the "multiple" mentioned in the present application refers to two or more. In the description of the present application, unless otherwise specified, " / " means "or", for example, A / B can represent A or B; the "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, for the convenience of clearly describing the technical solutions of the present application, the same items or similar items with basically the same functions and effects are distinguished by using words such as "first" and "second". Those skilled in the art can understand that the words such as "first" and "second" do not limit the quantity and execution order, and the words such as "first" and "second" do not necessarily limit to be different.

[0050] Statements such as "an embodiment" or "some embodiments" described in this application mean that the specific features, structures, or characteristics described in the embodiment are included in one or more embodiments of this application. Thus, statements such as "in one embodiment", "in some embodiments", "in some other embodiments", "in still some other embodiments", etc. that appear in different parts of this application do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized. In addition, the terms "comprising", "including", "having" and their variants all mean "including but not limited to", unless otherwise specifically emphasized.

[0051] Before explaining the embodiments of this application in detail, the application scenarios of the embodiments of this application will be described first.

[0052] The embodiments of this application are applied to the scenario of data storage based on the Merkle B+ tree. For example, after a blockchain system executes all the transactions in a block, a series of ledger modification sets will be generated. In this case, the data storage method provided by the embodiments of this application can be used to store these ledger modification sets based on the Merkle B+ tree.

[0053] Next, the structure of the Merkle B+ tree will be introduced.

[0054] The Merkle B+ tree is a tree data structure. The Merkle B+ tree contains two types of nodes: index nodes (indexNode) and data nodes (dataNode) at the bottom layer. Both index nodes and data nodes are logical nodes.

[0055] Multiple key-value pairs are stored in the data node. Each key-value pair includes a key value and a value value. The data node has a minimum key and a hash value. The minimum key of the data node is the smallest key value among all the key values of the key-value pairs it stores. The hash value of the data node is the hash value of the data obtained by concatenating all the key-value pairs it stores.

[0056] The minimum key and hash value of each node among all its subordinate nodes are stored in the index node. The index node has a minimum key and a hash value. The minimum key of the index node is the smallest key value among all the minimum keys of the nodes it stores. The hash value of the index node is the hash value of the data obtained by concatenating all the hash values of the nodes it stores.

[0057] Exemplarily, Figure 1 is a schematic diagram of a Merkle B+ tree provided by the embodiments of this application. Refer to Figure 1 , this Merkle B+ tree includes multiple data nodes ( Figure 1 taking node n4, node n5, and node n6 as examples inFigure 1 Take nodes n1, n2, and n3 as examples. Among them, the subordinate nodes of node n1 include nodes n2 and n3, the subordinate nodes of node n2 include nodes n4 and n5, and the subordinate nodes of node n3 include node n6. In the embodiments of the present application, the index node at the top layer can be called the root node. For example, Figure 1 Node n1 in

[0058] Figure 1 The data node n4 in stores key-value pairs key: a - value: 1 and key: b - value: 2. The data node n5 stores key-value pairs key: c - value: 3 and key: d - value: 4. The data node n6 stores key-value pairs key: e - value: 5 and key: f - value: 6. In this case, the minimum key of data node n4 is the smaller value key: a between key: a and key: b, and the hash value of data node n4 is the hash value hash: H(n4) of the data obtained by concatenating key: a - value: 1 and key: b - value: 2. The minimum key of data node n5 is the smaller value key: c between key: c and key: d, and the hash value of data node n5 is the hash value hash: H(n5) of the data obtained by concatenating key: c - value: 3 and key: d - value: 4. The minimum key of data node n6 is the smaller value key: e between key: e and key: f, and the hash value of data node n6 is the hash value hash: H(n6) of the data obtained by concatenating key: e - value: 5 and key: f - value: 6.

[0059] Figure 1 The index node n2 in stores the minimum key key: a of its subordinate data node n4, the hash value hash: H(n4), the minimum key key: c of its subordinate data node n5, and the hash value hash: H(n5). The index node n3 stores the minimum key key: e of its subordinate data node n6 and the hash value hash: H(n6). And, the minimum key of index node n2 is the smaller value key: a between key: a and key: c, and the hash value of index node n2 is the hash value hash: H(n2) of the data obtained by concatenating hash: H(n4) and hash: H(n5). The minimum key of index node n3 is key: e, and the hash value of index node n3 is the hash value hash: H(n3) of hash: H(n6).

[0060] Figure 1The inode n1 (i.e., the root inode n1) stores the minimum key key: a of its subordinate inode n2, the hash value hash: H(n2), and the minimum key key: e of its subordinate inode n3, the hash value hash: H(n3).

[0061] The data stored in each node (including inodes and data nodes) of the Merkle B+-tree can be stored on disk, specifically in the disk pages of the disk. In some embodiments, to adapt to the read and write strategies of the disk, it is usually stipulated that the size of each disk page is 4K. In this case, in addition to including the minimum key and hash value of each subordinate node of this inode in the data of any inode, it can also include the page identifier (identity, ID) of this inode and the page identifiers of each subordinate node of this inode. The page identifier of a certain node is used to identify the disk page storing the data of this node. That is, the page identifier of this inode is used to identify the disk page storing the data of this inode, and the page identifier of a certain subordinate node of this inode is used to identify the disk page storing the data of this subordinate node of this inode.

[0062] In this case, if data processing is required based on the Merkle B+-tree, it is necessary to first read the node data stored in the disk page into memory according to the page identifier, process the read node data in memory, and then store the processed node data back to the disk page to complete the update of the Merkle B+-tree.

[0063] Among them, when reading the node data stored in the disk page into memory according to the page identifier, usually the operating system interface is called according to the page identifier, and the operating system returns the node data stored in the corresponding disk page according to this page identifier. Specifically, after obtaining the page identifier, the operating system first looks up the node data corresponding to this page identifier in the page cache (PageCache) of the kernel. If found, it directly returns the found node data. If not found, it reads the node data from the disk page corresponding to this page identifier and returns it.

[0064] The above Merkle B+-tree has the following two disadvantages:

[0065] 1. High storage pressure.

[0066] Since the value in the key-value pair stored in the data node is usually relatively large, and the size of each disk page is usually 4K, the data storage in the disk page is not compact, which will result in a waste of the storage space of the disk page. For example, a 4K disk page can only store a 3K value, or two 4K disk pages can only store a 5K value. Moreover, since data reading and writing can only be performed in units of disk pages, the reading and writing of node data smaller than the disk page size will cause the reading and writing of the entire disk page, resulting in a large write amplification.

[0067] 2. The write tree process is slow.

[0068] Since the value in the key-value pair stored in the data node is usually relatively large, the data of the data node stored in the disk is relatively large, which will cause the PageCache of the kernel to reach the storage bottleneck very early. After the PageCache of the kernel is full, the subsequent operating system needs to actually read the node data from the disk, resulting in a relatively large read time. For example, for an HDD (Hard Disk Drive) disk, a single read takes about 10 ms (milliseconds). The increase in read time will cause an increase in the time consumed when updating the Merkle B+ tree, that is, it causes the write tree process to be slow.

[0069] Therefore, the embodiments of the present application propose a new Merkle B+ tree model based on the idea of key-value separation, which can solve the problems of large storage pressure and slow write tree process.

[0070] The Merkle B+ tree provided by the embodiments of the present application will be described below.

[0071] Figure 2 is a schematic diagram of a Merkle B+ tree provided by the embodiments of the present application. As Figure 2 shown in Figure (a) in

[0072] As Figure 2As shown in Figure (b), the real value is stored in a preset file, and the real values can be stored sequentially in the preset file. The number of preset files can be one or more, and the storage space size of each preset file is the same. For example, the storage space size of each preset file can be greater than or equal to 4K. In some embodiments, the preset file can be referred to as a valueLog file.

[0073] Specifically, the Merkle B+ tree provided in the embodiments of the present application is a tree data structure, and the Merkle B+ tree includes two types of nodes: index nodes and data nodes at the bottom layer. Both index nodes and data nodes are logical nodes.

[0074] The data node stores multiple key-value pairs. Each key-value pair includes a key value and a value. The value in the key-value pair is not the real value, but the storage location information used to indicate the storage location of the real value in the preset file. For example, as Figure 2 shown in Figure (a), the data node stores the key-value pair "key: k1 - value: storage location information 1" and the key-value pair "key: k2 - value: storage location information 2".

[0075] The data node has a minimum key and a hash value. The minimum key of the data node is the smallest key value among all the key values of the key-value pairs it stores. The hash value of the data node is the hash value of the data obtained by concatenating the hash values of all the real values corresponding to the key-value pairs it stores. In some embodiments, not only key-value pairs but also the hash values of real values can be stored in the data nodes of the Merkle B+ tree. For example, as Figure 2 shown in Figure (a), the data node stores the hash value "hash: h1" of the real value corresponding to the key-value pair "key: k1 - value: storage location information 1" and the hash value "hash: h2" of the real value corresponding to the key-value pair "key: k2 - value: storage location information 2". In this case, the hash value of the data node is the hash value of the data obtained by concatenating all the hash values it stores.

[0076] The index node stores the minimum key and the hash value of each of all the nodes under it. The index node has a minimum key and a hash value. The minimum key of the index node is the smallest key value among all the minimum keys of the nodes it stores, and the hash value of the index node is the hash value of the data obtained by concatenating the hash values of all the nodes it stores.

[0077] All nodes in the Merkel B+ tree except the root node have key ranges. Specifically, for any node among all nodes at any layer in the Merkel B+ tree, if this node is the first node at this layer (generally the leftmost node at this layer), then the key range of this node is the range less than the minimum key of the next node after this node at this layer. If this node is the last node at this layer (generally the rightmost node at this layer), then the key range of this node is the range greater than or equal to the minimum key of this node. If this node is a node other than the first node and the last node at this layer, then the key range of this node is the range greater than or equal to the minimum key of this node and less than the minimum key of the next node after this node at this layer.

[0078] For example, a certain layer in the Merkel B+ tree includes index node n2 and index node n3. Among them, index node n2 stores the minimum key key:a, hash value hash:H(n4) of its subordinate data node n4, the minimum key key:c, and hash value hash:H(n5) of its subordinate data node n5. Index node n3 stores the minimum key key:e, hash value hash:H(n6) of its subordinate data node n6. And, the minimum key of index node n2 is the smaller value key:a between key:a and key:c, and the hash value of index node n2 is the hash value hash:H(n2) of the data obtained by concatenating hash:H(n4) and hash:H(n5). The minimum key of index node n3 is key:e, and the hash value of index node n3 is the hash value hash:H(n3) of hash:H(n6).

[0079] In this case, index node n2 is the first node at this layer, and the key range of index node n2 is the range less than the minimum key key:e of index node n3, that is, the key range of index node n2 is the range less than key:e. Index node n3 is the last node at this layer, and the key range of index node n3 is the range greater than or equal to the minimum key key:e of index node n3, that is, the key range of index node n3 is the range greater than or equal to key:e.

[0080] The Merkel B+ tree provided by the embodiments of this application can achieve the following effects:

[0081] 1. Reduce storage pressure.

[0082] The value stored in the data node of the novel Merkle B+ tree provided by the embodiment of the present application is extremely small, usually only a few bytes. In this case, the data storage in the disk page is relatively compact. In this situation, a disk page can store many value values, thereby reducing the waste of the storage space of the disk page and reducing the write amplification. In addition, since the real value values are stored sequentially in the preset file, the data storage in the preset file is also relatively compact, thus saving storage space.

[0083] 2. Fast write tree process.

[0084] Since the data of the data node is much reduced compared with before, the data of the data node stored in the disk is also much reduced compared with before. In this case, the PageCache of the kernel can store more node data. In this way, the operating system can often hit the node data in the PageCache, which is dozens of times faster than reading data from the disk. And, since the Merkle B+ tree can be updated directly according to the hash value stored in the data node when updating, without reading the real value value from the preset file, the time consumption for updating the Merkle B+ tree will also be reduced when the read time consumption of the operating system is reduced, that is, the write tree process can be accelerated.

[0085] The following is a detailed explanation of the data storage method implemented based on the Merkle B+ tree described in the above Figure 2 embodiment.

[0086] Figure 3 It is a flowchart of a data storage method provided by an embodiment of the present application. This method can be applied to a computer device. Optionally, the computer device can be a database system implemented based on the Merkle B+ tree. Refer to Figure 3 , this method includes the following steps:

[0087] Step 301: The computer device obtains multiple first key-value pairs to be stored.

[0088] The first key-value pair is a key-value pair that needs to be stored based on the Merkle B+ tree. The multiple first key-value pairs are key-value pairs used to construct the initial Merkle B+ tree.

[0089] The multiple first key-value pairs can be sent to the computer device by other systems. For example, after the execution module in the blockchain system finishes executing all transactions in a block, a series of ledger modification sets will be generated. These ledger modification sets can include multiple first key-value pairs that need to be stored. In this case, the execution module in the blockchain system can send the multiple first key-value pairs to the computer device to instruct the computer device to store the multiple first key-value pairs based on the Merkle B+ tree. At this time, the computer device can construct an initial Merkle B+ tree according to the multiple first key-value pairs.

[0090] Step 302: The computer device stores the value of each first key-value pair in the multiple first key-value pairs into a preset file to obtain the storage location information of the value of each first key-value pair.

[0091] The preset file is a file used to store the real value. Optionally, the number of preset files is one or more. The storage space size of each of the one or more preset files is the same. For example, the storage space size of each preset file can be greater than or equal to 4K. Optionally, the one or more preset files are created sequentially. The fact that the one or more preset files are created sequentially is reflected in: after creating a preset file, the value will be stored in this preset file until the remaining storage space of this preset file is not enough to store the new value, then a new preset file will be created to store this new value, and the file identifier of the newly created preset file is consecutive with the file identifier of the previous preset file. In other words, the file identifier of the newly created preset file can be obtained by incrementing the file identifier of the previous preset file. For example, if the file identifier of the previous preset file is file number 1, then 1 can be added to file number 1 to get file number 2, and file number 2 is used as the file identifier of the newly created preset file.

[0092] After the computer device obtains the multiple first key-value pairs to be stored, it can first sequentially store the value of each first key-value pair in the multiple first key-value pairs into the preset file to obtain the storage location information of the value of each first key-value pair. Since the value of each first key-value pair in the multiple first key-value pairs is sequentially stored in the preset file, the data storage in the preset file is relatively compact, thus saving storage space.

[0093] The storage location information of a certain value is used to indicate the storage location of this value in a preset file. Therefore, according to this storage location information, the corresponding value can be obtained from the preset file. For example, the storage location information of the value of a certain first key-value pair is used to indicate the storage location of the value of this first key-value pair in the preset file. Therefore, according to the storage location information of the value of this first key-value pair, the value of this first key-value pair can be obtained from the preset file.

[0094] Exemplarily, the storage location information of a certain value may include the file identifier (which can be called fid) of the preset file storing this value, the offset (which can be called offset) of this value in the preset file, and the byte length (which can be called valueSize) of this value. That is, the storage location information of the value of a certain first key-value pair may include the file identifier of the preset file storing the value of this first key-value pair, the offset of the value of this first key-value pair in the preset file, and the byte length of the value of this first key-value pair.

[0095] Among them, the fid in the storage location information is used to indicate which preset file the value corresponding to the storage location information is stored in. The offset in the storage location information is the offset between the starting address of the value corresponding to the storage location information and the starting address of this preset file. Therefore, the offset in the storage location information can be used to determine the starting address of the value corresponding to the storage location information in this preset file. According to this starting address and the valueSize in the storage location information, the ending address of the value corresponding to the storage location information in this preset file can be determined. According to this starting address and the ending address, the value corresponding to the storage location information can be obtained from this preset file, and the obtained value is the data stored at the storage location from this starting address to this ending address in this preset file.

[0096] In some embodiments, if there is a value of a key-value pair that needs to be stored in a preset file, when the remaining storage space of the last preset file among all the created preset files is sufficient to store the value of this key-value pair, the computer device stores the value of this key-value pair in the last preset file; and when the remaining storage space of the last preset file is not sufficient to store the value of this key-value pair, the computer device creates a new preset file and stores the value of this key-value pair in the newly created preset file.

[0097] In this case, before step 302, the computer device first creates an initial preset file. After that, in step 302, the computer device sequentially stores the value of each first key-value pair in the multiple first key-value pairs into the preset file. Specifically, for any one of the multiple first key-value pairs, if the value of this first key-value pair needs to be stored in the preset file in order, when the remaining storage space of the last preset file among all the created preset files is sufficient to store the value of this first key-value pair, the computer device stores the value of this first key-value pair in the last preset file; when the remaining storage space of the last preset file is not sufficient to store the value of this first key-value pair, the computer device creates a new preset file and stores the value of this first key-value pair in the newly created preset file.

[0098] Step 303: The computer device generates multiple second key-value pairs that correspond one-to-one to the multiple first key-value pairs.

[0099] The key value of a second key-value pair is the key value of the corresponding first key-value pair, and the value of a second key-value pair is the storage location information of the value of the corresponding first key-value pair. In this way, according to the value of a second key-value pair, it is possible to know the storage location of the value of the first key-value pair corresponding to this second key-value pair in the preset file, and based on this, the value of the first key-value pair corresponding to this second key-value can be obtained from the preset file.

[0100] It should be noted that compared with the value of the first key-value pair, the value of the second key-value pair (i.e., the storage location information of the value of the first key-value pair) is very small.

[0101] Furthermore, the computer device can also obtain the hash value of the value of each first key-value pair in the multiple first key-value pairs.

[0102] Step 304: The computer device constructs a Merkle B+ tree based on the multiple second key-value pairs, and the data nodes in the Merkle B+ tree contain the second key-value pairs.

[0103] Constructing a Merkle B+ tree based on the multiple second key-value pairs means storing the multiple second key-value pairs in the data nodes of the Merkle B+ tree. In this case, the values stored in the data nodes of the Merkle B+ tree are very small.

[0104] The data nodes in the Merkel B+ tree contain second key-value pairs. The data nodes have a minimum key and a hash value. The minimum key of a data node is the smallest key value among all the key values of the key-value pairs it contains. The hash value of a data node is the hash value of the data obtained by concatenating the hash values of the value values corresponding to the value values of all the key-value pairs it contains in a preset file. The index nodes in the Merkel B+ tree contain the minimum key and the hash value of each of all the nodes subordinate to it. The index nodes have a minimum key and a hash value. The minimum key of an index node is the smallest key value among all the minimum keys of the nodes it contains. The hash value of an index node is the hash value of the data obtained by concatenating the hash values of all the nodes it contains.

[0105] Among them, the operation of the computer device to construct the Merkel B+ tree according to the multiple second key-value pairs is similar to the operation of constructing the Merkel B+ tree according to multiple key-value pairs in the related art, and the embodiments of the present application do not elaborate on this in detail.

[0106] In some embodiments, the computer device may construct a Merkel B+ tree according to the multiple second key-value pairs and the hash values of the value values of the first key-value pairs corresponding to each second key-value pair in the multiple second key-value pairs.

[0107] In this case, the data nodes in the Merkel B+ tree not only contain second key-value pairs, but also contain the hash values of the value values of the first key-value pairs corresponding to the second keys. Specifically, each data node in the Merkel B+ tree contains at least one specified data, and the specified data includes a second key-value pair and the hash value of the value value of the corresponding first key-value pair. Each index node in the Merkel B+ tree contains the minimum key and the hash value of each of the subordinate nodes. In this case, whether it is a data node or an index node, the minimum key of the node is the smallest key value among all the key values contained in the node, and the hash value of the node is the hash value of the data obtained by concatenating all the hash values contained in the node.

[0108] Step 305: The computer device stores the data of each node in the Merkel B+ tree into disk pages.

[0109] It should be noted that after constructing the Merkel B+ tree in step 304, the computer device can also assign page identifiers to each newly generated node in the Merkel B+ tree. The page identifier of any node is the page identifier of the disk page used to store the data of this node subsequently. In this case, for any index node, the computer device can also add the page identifier of this index node and the page identifiers of each of the subordinate nodes of this index node to the data of this index node.

[0110] Another point to note is that the amount of data in each node of the Merkel B+ tree is less than or equal to the preset amount of data. Among them, the preset amount of data can be set in advance. For example, the preset amount of data can be the same as the storage space size of the disk page.

[0111] When the computer device stores the data of each node in the Merkel B+ tree into the disk page, it can store the data of each node into the corresponding disk page according to the page identifier of each node in the Merkel B+ tree. Since the value contained in the data node in the Merkel B+ tree is very small, the data storage in the disk page is relatively compact. In this case, a disk page can store many values, thereby reducing the waste of the storage space of the disk page and reducing the write amplification.

[0112] It should be noted that after the computer device stores the data of each node in the Merkel B+ tree into the disk page, it is equivalent to saving the logical tree of the Merkel B+ tree in the disk. In this case, the computer device can also record the page identifier of the root node in the Merkel B+ tree. According to the page identifier of the root node in the Merkel B+ tree, all the node data in the Merkel B+ tree can be obtained from the disk. Therefore, the page identifier of the root node in the Merkel B+ tree can correspond to the logical tree of the Merkel B+ tree saved in the disk. When the computer device subsequently updates the Merkel B+ tree, each time it is updated, a new version of the logical tree of the Merkel B+ tree will be saved in the disk, and the page identifier of the root node corresponding to this version of the logical tree (i.e., the page identifier of the root node in the updated Merkel B+ tree) will be recorded. In this case, not only the latest version of the logical tree is saved in the disk, but also at least one historical version of the logical tree is saved. The computer device can record the page identifier of the root node corresponding to the latest version of the logical tree, and can also record the page identifier of the root node corresponding to each historical version of the at least one historical version of the logical tree.

[0113] Through the above steps 301 to 305, the computer device constructs an initial Merkel B+ tree and saves all the node data in the Merkel B+ tree in the disk. Subsequently, the computer device can perform data processing based on the Merkel B+ tree, such as data query, data addition, data update, data deletion, etc. The following will explain this in detail.

[0114] Next, the data query process of the above Merkel B+ tree will be described. This data query process may include the following steps (1) to (3):

[0115] (1) The computer device receives a query instruction.

[0116] The query instruction carries a target key value. The query instruction is used to indicate a query for a target value corresponding to the target key value carried by the query instruction. The query instruction can be sent to the computer device by another system. For example, during the execution of transactions in a block by an execution module in a blockchain system, some keys that need to be queried are generated. The execution module can carry these keys as the target key values to be queried in the query instruction and send them to the computer device.

[0117] (2) The computer device obtains the specified key-value pair stored in the disk page according to the target key value.

[0118] The specified key-value pair is the key-value pair whose key value is the target key value included in the data node in the Merkle B+ tree. The value value of the specified key-value pair is the storage location information of the target value, which is used to indicate the storage location of the target value in the preset file.

[0119] The computer device records the page identifier of the root node corresponding to the latest version of the logical tree. The computer device can first obtain the data of the root node stored in the corresponding disk page according to the page identifier of the root node, then obtain the data of the target data node stored in the disk page according to the target key value and the data of the root node, and then obtain the specified key-value pair from the data of the target data node.

[0120] The data of the root node includes the page identifier of the root node, as well as the minimum key and hash value of each node subordinate to the root node, and the page identifier of each node subordinate to the root node. The key range of each node can be determined according to the minimum key of each node subordinate to the root node.

[0121] In this case, the computer device can compare the target key value with the key range of each node subordinate to the root node to determine which node's key range the target key value is within among the nodes subordinate to the root node. Then, according to the page identifier of this node included in the data of the root node, obtain the data of this node stored in the corresponding disk page.

[0122] After the computer device obtains the data of a node subordinate to the root node through the above method, if this node is a data node, the computer device can determine that this data node is the target data node. At this time, the data of the target data node is obtained, and the key-value pair whose key value is the target key value can be obtained from the data of the target data node as the specified key-value pair.

[0123] If this node is an index node, the computer device can continue to compare the target key value with the key ranges of each node subordinate to this index node according to the data of this index node, so as to determine which node's key range among the nodes subordinate to this index node the target key value is in. Then, according to the page identifier of this node included in the data of this index node, obtain the data of this node stored in the corresponding disk page. In this case, if this node is an index node, continue to repeat the above process until it is determined that the target key value is within the key range of a certain data node and the data of this data node is obtained. This data node is the target data node, and the key-value pair with the key value being the target key value can be obtained from the data of the target data node as the specified key-value pair.

[0124] It should be noted that the above process of obtaining the data of the target data node according to the target key value can be referred to as the process of distributing the target key value from the root node to the target data node in the Merkle B+ tree. The target key value is within the key range of the target data node.

[0125] In some embodiments, when the computer device obtains the node data stored in the corresponding disk page according to a certain page identifier, it reads the node data stored in the disk page into the memory according to this page identifier. Optionally, the computer device can call the operating system interface according to this page identifier, and the operating system returns the node data stored in the corresponding disk page to the memory according to this page identifier. Specifically, after obtaining this page identifier, the operating system can first search for the node data corresponding to this page identifier in the PageCache of the kernel. If found, directly return the found node data to the memory. If not found, read the node data from the disk page corresponding to this page identifier and return it to the memory.

[0126] (3) The computer device determines the value at the storage location indicated by the value of the specified key-value pair in the preset file as the target value.

[0127] Since the value of the specified key-value pair is used to indicate the storage location of the target value in the preset file, the computer device can obtain the value at the corresponding storage location in the preset file according to the value of the specified key-value pair as the target value. Then, the computer device can return the target value to the sender of the query instruction.

[0128] Next, the data deletion process of the above Merkle B+ tree will be described. This data deletion process may include the following steps A to E:

[0129] Step A: The computer device receives a deletion instruction.

[0130] The deletion instruction carries the target key value. The deletion instruction is used to indicate the deletion of the key-value pair to which the target key value carried by the deletion instruction belongs. The deletion instruction can be sent to the computer device by other systems. For example, after the execution module in the blockchain system finishes executing all the transactions in a block, some keys that need to be deleted will be generated. The execution module can carry these keys as the target key values to be deleted in the deletion instruction and send them to the computer device.

[0131] Step B: The computer device obtains the data of the target data node stored in the disk page according to the target key value.

[0132] The target data node is a data node that contains a specified key-value pair. The key value of the specified key-value pair is the same as the target key value. The target key value is within the key range of the target data node.

[0133] Among them, Step B is similar to the operation in Step (2) above where the computer device obtains the data of the target data node stored in the disk page according to the target key value, and this application embodiment will not elaborate on it here.

[0134] Step C: The computer device deletes the specified key-value pair from the data of the target data node to update the target data node.

[0135] In some embodiments, the data node contains specified data, and the specified data contains a key-value pair and a hash value. The hash value is the hash value of the value corresponding to the key-value pair in the preset file. In this case, the computer device can delete the specified target data from the data of the target data node. The specified target data is the specified data to which the specified key-value pair belongs, and the specified target data contains the specified key-value pair and the hash value of the value corresponding to the specified key-value pair in the preset file.

[0136] Step D: The computer device updates the index node in the Merkle B+ tree according to the updated target data node.

[0137] If the updated target data node is empty, that is, the updated target data node does not contain data, then delete the index entry (including the minimum key, hash value, and page identifier of the target data node) in the data of the index node to which the target data node belongs, and delete the page identifier of the index node contained in the data of the index node to update the index node. If the updated index node is empty, continue to trace back and update the upper-level index node until the root node is updated.

[0138] If the updated target data node is not empty, that is, the updated target data node contains data, assign a page identifier to the updated target data node, and determine the smallest key value among all the key values contained in the updated target data node as the minimum key of the updated target data node. Determine the hash value of the data obtained by concatenating all the hash values contained in the updated target data node as the hash value of the updated target data node. Update the index node in the Merkle B+ tree according to the minimum key, hash value, and page identifier of the updated target data node. Specifically, according to the minimum key, hash value, and page identifier of the updated target data node, update the index entry in the data of the index node to which the target data node belongs that points to the target data node, and delete the page identifier of this index node contained in the data of this index node to update this index node. After that, assign a page identifier to the updated index node, and then continue to trace upward and update the upper-level index node according to the minimum key, hash value, and page identifier of the updated index node until the root node is updated.

[0139] Step E: The computer device stores the data of the updated target data node and the data of the updated index node into the disk page to update the Merkle B+ tree.

[0140] The computer device can store the data of the updated target data node into the corresponding disk page according to the page identifier of the updated target data node, and store the data of the updated index node into the corresponding disk page according to the page identifier of the updated index node. In this way, the logical tree of the latest version of the Merkle B+ tree is saved on the disk. In this case, the computer device can record the page identifier of the root node in the updated index node as the page identifier of the root node corresponding to the latest version of the logical tree.

[0141] Next, the data update process of the above Merkle B+ tree will be described. This data update process may include the following steps a to step g:

[0142] Step a: The computer device receives an update instruction.

[0143] The update instruction carries a first target key-value pair. The update instruction is used to indicate that the key-value pair to which the key value of the first target key-value pair belongs in the Merkle B+ tree is updated to the first target key-value pair. The update instruction can be sent to the computer device by other systems. For example, after the execution module in the blockchain system finishes executing all the transactions in a block, some key-value pairs that need to be updated will be generated. The execution module can carry these key-value pairs as the first target key-value pairs to be updated in the update instruction and send them to the computer device.

[0144] Step b: The computer device obtains the hash value of the value of the first target key-value pair.

[0145] Step c: The computer device stores the value of the first target key-value pair into a preset file to obtain the storage location information of the value of the first target key-value pair.

[0146] Among them, step c is similar to the operation in step 302 above where the computer device stores the value of each first key-value pair among the multiple first key-value pairs into a preset file to obtain the storage location information of the value of each first key-value pair, and this is not elaborated in the embodiments of the present application.

[0147] Step d: The computer device generates a second target key-value pair corresponding to the first target key-value pair.

[0148] The key value of the second target key-value pair is the key value of the first target key-value pair, and the value of the second target key-value pair is the storage location information of the value of the first target key-value pair.

[0149] Among them, step d is similar to the operation in step 303 above where the computer device generates a plurality of second key-value pairs corresponding one by one to the plurality of first key-value pairs, and this is not elaborated in the embodiments of the present application.

[0150] Step e: The computer device obtains the data of the target data node stored in the disk page according to the key value of the second target key-value pair.

[0151] The target data node is a data node containing a specified key-value pair, and the key value of the specified key-value pair is the same as the key value of the second target key-value pair. The key value of the second target key-value pair is within the key range of the target data node.

[0152] Among them, step e is similar to the operation in step (2) above where the computer device obtains the data of the target data node stored in the disk page according to the target key value, and this is not elaborated in the embodiments of the present application.

[0153] Step f: The computer device updates the specified key-value pair in the data of the target data node to the second target key-value pair to update the target data node.

[0154] In some embodiments, the data node contains specified data, and the specified data contains key-value pairs and a hash value, where the hash value is the hash value of the value corresponding to the key-value pair in a preset file. In this case, the computer device can first determine the specified target data in the data of the target data node, where the specified target data is the specified data to which the specified key-value pair belongs, and the specified target data contains the specified key-value pair and the hash value of the value corresponding to the specified key-value pair in the preset file. Then, the computer device updates the specified key-value pair in the specified target data in the data of the target data node to a second target key-value pair, and updates the hash value in the specified target data to the hash value of the value of the first target key-value pair, so as to update the target data node.

[0155] Step g: The computer device updates the Merkle B+ tree according to the updated target data node.

[0156] If the data volume of the updated target data node is less than or equal to the preset data volume, there is no need to perform the data node splitting operation; if the data volume of the updated target data node is greater than the preset data volume, the data node splitting operation needs to be performed. Among them, the preset data volume can be set in advance. For example, the preset data volume can be the storage space size of a disk page, such as the preset data volume can be 4K. And, after updating the index node in the Merkle B+ tree according to the updated target data node, if the data volume of the updated index node is less than or equal to the preset data volume, there is no need to perform the index node splitting operation; if the data volume of the updated index node is greater than the preset data volume, the index node splitting operation needs to be performed. The following will elaborate on this:

[0157] In some embodiments, if the data volume of the updated target data node is less than or equal to the preset data volume, a page identifier is assigned to the updated target data node, and the smallest key among all the key values contained in the updated target data node is determined as the smallest key of the updated target data node, and the hash value of the data obtained by concatenating all the hash values contained in the updated target data node is determined as the hash value of the updated target data node. The index node in the Merkle B+ tree is updated according to the smallest key, hash value, and page identifier of the updated target data node. Specifically, according to the smallest key, hash value, and page identifier of the updated target data node, the index entry (i.e., the smallest key, hash value, and page identifier of the target data node) pointing to the target data node in the data of the index node above the target data node is updated, and the page identifier of the index node contained in the data of the index node is deleted to update the index node. Then, a page identifier is assigned to the updated index node, and then, according to the smallest key, hash value, and page identifier of the updated index node, the index node above is continuously traced back and updated upwards until the root node is updated.

[0158] After that, the computer device stores the data of the updated target data node and the data of the updated index node into disk pages to update the Merkle B+ tree. Optionally, the computer device may store the data of the updated target data node into the corresponding disk page according to the page identifier of the updated target data node, and store the data of the updated index node into the corresponding disk page according to the page identifier of the updated index node. In this way, the logical tree of the latest version of the Merkle B+ tree is saved on the disk. In this case, the computer device may record the page identifier of the root node in the updated index node as the page identifier of the root node corresponding to the logical tree of the latest version.

[0159] In some other embodiments, if the data volume of the updated target data node is greater than a preset data volume, the updated target data node is split into at least two data nodes, where the data volume of each of the at least two data nodes is less than or equal to the preset data volume, and each of the at least two data nodes contains at least one specified data, and the specified data includes a key-value pair and the hash value of the value corresponding to the key-value pair in a preset file. For any one of the at least two data nodes, the smallest key among all the key values included in this data node is determined as the minimum key of this data node, the hash value of the data obtained by concatenating all the hash values included in this data node is determined as the hash value of this data node, and a page identifier is assigned to this data node. After that, the index node in the Merkle B+ tree is updated according to the minimum key, hash value, and page identifier of each of the at least two data nodes. Specifically, the index entry of the target data node in the data of the index node to which the target data node belongs is updated to the index entry of each of the at least two data nodes (including the minimum key, hash value, and page identifier of the data node), and the page identifier of the index node included in the data of the index node is deleted to update the index node. If the data volume of the updated index node is less than or equal to the preset data volume, a page identifier is assigned to the updated index node, and then, according to the minimum key, hash value, and page identifier of the updated index node, the upper-level index node is continuously traced back and updated until the root node is updated. If the data volume of the updated index node is greater than the preset data volume, the updated index node is split into at least two index nodes, where the data volume of each of the at least two index nodes is less than or equal to the preset data volume, and each of the at least two index nodes contains at least one index entry of a data node; a page identifier is assigned to each of the at least two index nodes, and then, according to the minimum key, hash value, and page identifier of each of the at least two index nodes, the upper-level index node is continuously traced back and updated until the root node is updated.

[0160] After that, the computer device stores the data of each data node among the at least two data nodes and the data of the updated index node into disk pages to update the Merkle B+ tree. Optionally, the computer device may store the data of each data node into the corresponding disk page according to the page identifier of each data node among the at least two data nodes, and store the data of the updated index node into the corresponding disk page according to the page identifier of the updated index node. In this way, the logical tree of the latest version of the Merkle B+ tree is saved on the disk. In this case, the computer device may record the page identifier of the root node in the updated index node as the page identifier of the root node corresponding to the logical tree of the latest version.

[0161] Next, the data addition process of the above Merkle B+ tree will be described. This data addition process may include the following steps 1 to 7:

[0162] Step 1: The computer device receives an addition instruction.

[0163] The addition instruction carries a first target key-value pair. The addition instruction is used to indicate inserting the first target key-value pair carried by the addition instruction into the Merkle B+ tree. The addition instruction may be sent to the computer device by another system. For example, after the execution module in the blockchain system finishes executing all transactions in a block, some key-value pairs that need to be added will be generated. The execution module may carry these key-value pairs as the first target key-value pairs to be added in the addition instruction and send them to the computer device.

[0164] Step 2: The computer device obtains the hash value of the value of the first target key-value pair.

[0165] Step 3: The computer device stores the value of the first target key-value pair into a preset file to obtain the storage location information of the value of the first target key-value pair.

[0166] Among them, Step 3 is similar to the operation in the above Step 302 where the computer device stores the value of each first key-value pair among the multiple first key-value pairs into a preset file to obtain the storage location information of the value of each first key-value pair. This application embodiment will not elaborate on this anymore.

[0167] Step 4: The computer device generates a second target key-value pair corresponding to the first target key-value pair.

[0168] The key value of the second target key-value pair is the key value of the first target key-value pair, and the value of the second target key-value pair is the storage location information of the value of the first target key-value pair.

[0169] Among them, the operation in step four is similar to the operation in step 303 above where the computer device generates a plurality of second key-value pairs corresponding one-to-one to the plurality of first key-value pairs, and this is not elaborated in the embodiments of the present application.

[0170] Step five: The computer device obtains the data of the target data node stored in the disk page according to the key value of the second target key-value pair.

[0171] The target data node is the data node where the second target key-value pair needs to be inserted in the Merkle B+ tree. The key value of the second target key-value pair is within the key range of the target data node.

[0172] Among them, the operation in step five is similar to the operation in step (2) above where the computer device obtains the data of the target data node stored in the disk page according to the target key value, and this is not elaborated in the embodiments of the present application.

[0173] Step six: The computer device adds the second target key-value pair to the data of the target data node to update the target data node.

[0174] In some embodiments, the data node contains specified data, and the specified data contains a key-value pair and a hash value, and the hash value is the hash value of the value corresponding to the key-value pair in the preset file. In this case, the computer device can add specified target data to the data of the target data node to update the target data node, and the specified target data includes the second target key-value pair and the hash value of the value of the first target key-value pair.

[0175] Step seven: The computer device updates the Merkle B+ tree according to the updated target data node.

[0176] Among them, the operation in step seven is similar to the operation in step g above where the computer device updates the Merkle B+ tree according to the updated target data node, and this is not elaborated in the embodiments of the present application.

[0177] It should be noted that during the above process of data modification (including data deletion, data update, and data addition) based on the Merkle B+ tree, the computer device always calls the operating system interface according to the page identifier, and the operating system returns the node data stored in the corresponding disk page to the memory according to the page identifier, and then the computer device processes these node data in the memory and stores the processed node data to the disk page, thereby completing the update of the Merkle B+ tree.

[0178] In this case, since the value in the data node is relatively small, the amount of data stored in the data nodes on the disk is reduced. As a result, the PageCache of the kernel can store more node data. Usually, the operating system can hit the node data in the PageCache, which is dozens of times faster than reading data from the disk. Moreover, when updating the Merkle B+ tree as described above, the update can be directly performed according to the hash value stored in the data node without reading the value from the preset file. Therefore, when the read time consumption of the operating system is reduced, the time consumption for updating the Merkle B+ tree will also be reduced, that is, the write tree process can be accelerated.

[0179] Optionally, the above deletion instruction, update instruction, and addition instruction can be carried in a single message and sent to the computer device. Of course, they can also be sent to the computer device separately. The embodiments of the present application do not limit this. For example, after the execution module in the blockchain system finishes executing all the transactions in a block, a series of ledger modification sets will be generated. These ledger modification sets may include one or more of the keys to be deleted, the key-value pairs to be updated, and the key-value pairs to be added. The execution module can carry these ledger modification sets in a single message and send them to the computer device, or according to the different modification types, carry these ledger modification sets in multiple messages and send them to the computer device separately.

[0180] Optionally, the Merkle B+ tree in the embodiments of the present application supports batch modification. That is, the above deletion instruction can carry multiple key values to be deleted, the above update instruction can carry multiple key-value pairs to be updated, and the above addition instruction can carry multiple key-value pairs to be added. In this case, concurrent update of the nodes in the Merkle B+ tree can be achieved. The following is an example:

[0181] Exemplarily, in the Figure 4 shown Merkle B+ tree, it includes a root node [a1, b1, c2], index nodes [a1], [b1], [c2], data nodes [a1, a2], [b1], and [c2].

[0182] If it is necessary to add three key-value pairs [a3], [b2], and [c1] to the Figure 4 shown Merkle B+ tree, then as Figure 5 shown, first perform the distribution and merging operations of the key-value pairs. In Figure 5 , starting from the root node [a1, b1, c2], distribute the key-value pairs to the following nodes in turn. If the distributed node is an index node, continue to distribute downward. If the distributed node is a data node, perform the merging operation of the key-value pairs. As Figure 5As shown, the inserted [a3] is merged into the data nodes [a1, a2], and the data nodes [a1, a2] are updated to [a1, a2, a3]. The inserted [b2] is merged into the data node [b1], and the data node [b1] is updated to [b1, b2]. The inserted [c1] is merged into the data node [c2], and the data node [c2] is updated to [c1, c2].

[0183] After completing the distribution and merging operations of key-value pairs, the following node splitting operations (including data node splitting operations and index node splitting operations) are performed as Figure 6 shown. In Figure 6 , starting from the underlying data nodes, splitting is performed sequentially upwards. If the data volume of a data node is greater than the preset data volume, the data node is split to ensure that the data volume of each split node is less than or equal to the preset data volume. It can be seen that Figure 6 the data node [a1, a2, a3] in is split into two data nodes [a1, a2] and [a3], while the data nodes [b1, b2] and the data node [c1, c2] are not split. Next, continue to trace back and update upwards until the root node is updated. The root node is updated from [a1, b1, c2] to [a1, b1, c1].

[0184] The data rollback process of the above Merkle B+ tree is described below. This data rollback process can be: The computer device receives a rollback instruction, and the rollback instruction carries the page identifier of the target root node. The rollback instruction is used to indicate rolling back the node data of the Merkle B+ tree to the node data corresponding to the page identifier of the target root node. The computer device performs a rollback on the Merkle B+ tree according to the page identifier of the target root node.

[0185] The computer device records the page identifier of the root node corresponding to the latest version of the logical tree, and also records the page identifiers of the root nodes corresponding to each historical version in at least one historical version.

[0186] In this case, the operation of the computer device performing a rollback on the Merkle B+ tree according to the page identifier of the target root node can be: determining the version corresponding to the page identifier of the target root node as the target version, and then deleting the page identifiers of the root nodes in all the recorded root node page identifiers whose corresponding versions are greater than the target version, so as to use the logical tree corresponding to the page identifier of the target root node as the latest version of the logical tree.

[0187] It should be noted that in terms of multi-version control and data rollback, since the Merkle B+ tree is equivalent to storing multiple logical trees in the disk, when the Merkle B+ tree needs to be rolled back to a certain version, it only needs to point the current root node to the root node of the logical tree of this version.

[0188] In some embodiments, if multiple logical trees need to be saved, an idle page ID list, a list of pages to be released, and the maximum page ID need to be set. Suppose only two versions of data rollback are supported. When transaction 3 is completed, it can only be rolled back to the state of transaction 2 at most, which is equivalent to only saving two logical trees corresponding to transaction 2 and transaction 3 in the disk.

[0189] As Figure 7 shown, the page IDs of the three nodes in the Merkle B+ tree obtained after transaction 1 is executed are 1, 2, and 3 respectively. At this time, the maximum page ID of transaction 1 is 4, and both the idle page ID list and the list of pages to be released of transaction 1 are empty.

[0190] After that, transaction 2 is executed. After transaction 2 updates the key-value pairs, the data nodes with page IDs 2 and 3 become dirty, and the data node with page ID 2 splits into two data nodes. Since both the idle page ID list and the list of pages to be released are empty, the page IDs can only be allocated to each data node by incrementing the maximum page ID. The allocated page IDs are 4, 5, and 6. After the data node update is completed, trace back upward to update the root node. The root node with page ID 1 becomes dirty. Since both the idle page ID list and the list of pages to be released are empty, the page ID can only be allocated to the root node by incrementing the maximum page ID. The allocated page ID is 7. After transaction 2 is completed, the maximum page ID becomes 8, and the three page IDs 1, 2, and 3 are recycled. These three recycled page IDs will not be released immediately, that is, these three recycled page IDs will not enter the idle page ID list temporarily, but are first placed in the list of pages to be released. At this time, the maximum page ID of transaction 2 is 8, the idle page ID list of transaction 2 is empty, and the list of pages to be released of transaction 2 stores the page IDs to be released of transaction 1 {1, 2, 3}.

[0191] When transaction 3 starts, since only two versions of data rollback are supported, the page IDs to be released of transaction 1 in the list of pages to be released need to be released. At this time, the three page IDs 1, 2, and 3 are placed in the idle page ID list. After transaction 3 updates the key-value pairs, the data node with page ID 6 becomes dirty. Correspondingly, the root node with page ID 7 also becomes dirty. At this time, the two page IDs 1 and 2 can be taken from the idle page ID list for allocation, and the two page IDs 6 and 7 are placed in the list of pages to be released. At this time, the maximum page ID of transaction 3 is 8, the page IDs stored in the idle page ID list of transaction 3 are 3, and the list of pages to be released of transaction 3 stores the page IDs to be released of transaction 2 {6, 7}.

[0192] In this case, if it is necessary to roll back to Transaction 2, since the page ID of the root node of the logical tree corresponding to Transaction 2 has been recorded as 7, as well as the free page ID list and the list to be released of Transaction 2, it is only necessary to point the current root node to the root node with page ID 7, and replace the current free page ID list with the free page ID list of Transaction 2, and replace the current list to be released with the list to be released of Transaction 2. In this way, theoretically, it is possible to support the rollback of data of countless versions.

[0193] It should be noted that the preset file is continuously written sequentially. However, there is a problem that when the key-value pairs belonging to the same key value are updated multiple times or deleted, the corresponding value is discarded, and the storage space for storing these values should be released. Therefore, the embodiment of the present application provides a GC (Garbage Collection) mechanism for the preset file, which will be specifically described below:

[0194] The computer device creates a record table, which includes the file identifier, file size, file discarded size, and transaction identifier of each preset file in all the created preset files. It should be noted that the file size of the preset file is the total size of the values stored in the preset file. The preset file identified by the file identifier with the same file size and file discarded size in the record table is the historical preset file.

[0195] Exemplarily, as shown in Table 1 below, the computer device can create a DISCARD file (i.e., the record table described above), which contains multiple records, and each record corresponds to a preset file.

[0196] Table 1

[0197] FID TotalSize DiscardSize Seq File Identifier File Size File Discard Size Transaction Identifier

[0198] The embodiment of the present application only takes Table 1 above as an example to exemplarily illustrate the record table, and Table 1 above does not limit the embodiment of the present application.

[0199] In some embodiments, the value of the key-value pair of the data node in the Merkle B+ tree is the storage location information, and the storage location information includes the file identifier of the preset file storing the value corresponding to the storage location information, the offset of the value corresponding to the storage location information in the preset file, and the byte length of the value corresponding to the storage location information.

[0200] In this case, if the computer device updates the Merkle B+ tree after executing a transaction, determine the key-value pairs that are updated or deleted in the data nodes of the Merkle B+ tree during the execution of this transaction as historical key-value pairs; increase the file discard size corresponding to the file identifier in the record table for the value of this historical key-value pair by the byte length in the value of this historical key-value pair, and update the transaction identifier corresponding to the file identifier in the record table for the value of this historical key-value pair to the identifier of this transaction.

[0201] It can be understood that in the record table, the file discard size corresponding to the file identifier of a certain preset file is the size of the value that has been updated or deleted based on the Merkle B+ tree in the value stored in this preset file. The transaction identifier corresponding to the file identifier of this preset file is used to identify the transaction that has most recently updated or deleted the value stored in this preset file based on the Merkle B+ tree.

[0202] In this case, if the file size corresponding to a certain file identifier in the record table is the same as the file discard size, it means that all the values stored in the preset file (i.e., the historical preset file mentioned above) identified by this file identifier have been updated or deleted based on the Merkle B+ tree. At this time, this historical preset file should be deleted to release the corresponding storage space, but because multi-version data is supported, this historical preset file cannot be directly deleted. Suppose it is found that the file size corresponding to the file identifier of a certain preset file is the same as the file discard size when transaction 3 starts to execute, but because two versions of data rollback are supported, if the preset file is deleted at this time, then the value stored in this preset file cannot be read in transaction 2, and it will be impossible to roll back to transaction 2 normally.

[0203] Therefore, in the embodiments of this application, when the computer device starts to prepare to execute a certain transaction, when the identifier of the currently pending transaction is the sum of the transaction identifier corresponding to the file identifier of a historical preset file in the record table and the preset version number, then delete this historical preset file. Among them, the preset version number is the number of rollback versions supported by the Merkle B+ tree.

[0204] If the identifier of the current transaction to be executed is the sum of the transaction identifier corresponding to the file identifier of a historical preset file in the record table and the preset version number, it indicates that after starting to execute this transaction, it will no longer roll back to the transaction identified by the transaction identifier corresponding to the file identifier of this historical preset file. Since the transaction identifier corresponding to the file identifier of this historical preset file is used to identify the transaction that last updated or deleted the value stored in this historical preset file based on the Merkle B+ tree, all the value values stored in this historical preset file are the value values of historical versions that will not be rolled back. Therefore, at this time, this historical preset file can be deleted to release the corresponding storage space.

[0205] Figure 8 is a schematic structural diagram of a data storage device provided by an embodiment of the present application. This device can be implemented by software, hardware, or a combination of both as part or all of a computer device, and this computer device can be the computer device Figure 9 shown below. Refer to Figure 8 , this device includes: a first acquisition module 801, a first storage module 802, a generation module 803, a construction module 804, and a second storage module 805.

[0206] The first acquisition module 801 is configured to acquire a plurality of first key-value pairs to be stored;

[0207] The first storage module 802 is configured to store the value value of each first key-value pair in the plurality of first key-value pairs into a preset file to obtain the storage location information of the value value of each first key-value pair;

[0208] The generation module 803 is configured to generate a plurality of second key-value pairs corresponding one-to-one to the plurality of first key-value pairs. The key value of a second key-value pair is the key value of the corresponding first key-value pair, and the value value of a second key-value pair is the storage location information of the value value of the corresponding first key-value pair;

[0209] The construction module 804 is configured to construct a Merkle B+ tree according to the plurality of second key-value pairs. The data nodes in the Merkle B+ tree include the second key-value pairs;

[0210] The second storage module 805 is configured to store the data of each node in the Merkle B+ tree into a disk page.

[0211] Optionally, the storage location information of the value value of the first key-value pair includes the file identifier of the preset file storing the value value of the first key-value pair, the offset of the value value of the first key-value pair in the preset file, and the byte length of the value value of the first key-value pair.

[0212] Optionally, this device further includes:

[0213] A receiving module, configured to receive a query instruction, where the query instruction carries a target key value;

[0214] A second obtaining module, configured to obtain a specified key-value pair stored in a disk page according to the target key value, where the specified key-value pair is a key-value pair whose key value is the target key value and is included in a data node in a Merkle B+ tree;

[0215] A first determining module, configured to determine, as a target value value, the value value at a storage location indicated by the value value of a specified key-value pair in a preset file.

[0216] Optionally, the apparatus further includes:

[0217] A third obtaining module, configured to obtain a hash value of the value value of each first key-value pair among a plurality of first key-value pairs;

[0218] A construction module 804 is configured to:

[0219] Construct a Merkle B+ tree according to a plurality of second key-value pairs and hash values of the value values of the corresponding first key-value pairs of each second key-value pair among the plurality of second key-value pairs;

[0220] Wherein, each data node in the Merkle B+ tree includes at least one specified data, the specified data includes a second key-value pair and a hash value of the value value of a corresponding first key-value pair; each index node in the Merkle B+ tree includes the minimum key and hash value of each node among at least one subordinate node, the minimum key of the node is the minimum key value among all key values included in the node, and the hash value of the node is the hash value of the data obtained by concatenating all hash values included in the node.

[0221] Optionally, the apparatus further includes:

[0222] A receiving module, configured to receive an addition instruction, where the addition instruction carries a first target key-value pair;

[0223] A third obtaining module, configured to obtain a hash value of the value value of the first target key-value pair;

[0224] A first storage module 802 is further configured to store the value value of the first target key-value pair into a preset file to obtain storage location information of the value value of the first target key-value pair;

[0225] A generating module 803 is further configured to generate a second target key-value pair corresponding to the first target key-value pair, where the key value of the second target key-value pair is the key value of the first target key-value pair, and the value value of the second target key-value pair is the storage location information of the value value of the first target key-value pair;

[0226] A fourth acquisition module, configured to acquire data of a target data node stored in a disk page according to a key value of a second target key-value pair, where the target data node is a data node required to be inserted by the second target key-value pair in the Merkle B+ tree;

[0227] An addition module, configured to add specified target data to the data of the target data node to update the target data node, where the specified target data includes the second target key-value pair and a hash value of a value of the first target key-value pair;

[0228] A second determination module, configured to, if the data volume of the updated target data node is less than or equal to a preset data volume, determine the smallest key value among all key values included in the updated target data node as the minimum key of the updated target data node, and determine the hash value of the data obtained by concatenating all hash values included in the updated target data node as the hash value of the updated target data node;

[0229] A first update module, configured to update an index node in the Merkle B+ tree according to the minimum key and hash value of the updated target data node;

[0230] A second storage module 805 is further configured to store the data of the updated target data node and the data of the updated index node to a disk page.

[0231] Optionally, the apparatus further includes:

[0232] A splitting module, configured to, if the data volume of the updated target data node is greater than the preset data volume, split the updated target data node into at least two data nodes, where the data volume of each of the at least two data nodes is less than or equal to the preset data volume;

[0233] A third determination module, configured to, for any one of the at least two data nodes, determine the smallest key value among all key values included in one data node as the minimum key of one data node, and determine the hash value of the data obtained by concatenating all hash values included in one data node as the hash value of one data node;

[0234] A first update module, configured to update an index node in the Merkle B+ tree according to the minimum key and hash value of each of the at least two data nodes;

[0235] A second storage module 805 is further configured to store the data of each of the at least two data nodes and the data of the updated index node to a disk page.

[0236] Optionally, the number of preset files is one or more, the storage space sizes of the one or more preset files are the same, and the one or more preset files are created sequentially;

[0237] The first storage module 802 is further configured to, if there is a key-value pair to be stored in a preset file, store the value of a key-value pair in the last preset file among all the created preset files when the remaining storage space of the last preset file is sufficient to store the value of a key-value pair; and create a new preset file and store the value of a key-value pair in the newly created preset file when the remaining storage space of the last preset file is not sufficient to store the value of a key-value pair.

[0238] Optionally, the storage location information of the value of the first key-value pair includes the file identifier of the preset file storing the value of the first key-value pair, the offset of the value of the first key-value pair in the preset file, and the byte length of the value of the first key-value pair;

[0239] The apparatus further includes:

[0240] A creation module, configured to create a record table, where the record table includes the file identifier, file size, file discard size, and transaction identifier of each preset file among all the created preset files, and the preset file identified by the file identifier with the same file size and file discard size in the record table is a historical preset file;

[0241] The apparatus further includes:

[0242] A fourth determination module, configured to determine the historical key-value pairs updated or deleted in the data nodes in the Merkle B+ tree during the execution of a transaction if the Merkle B+ tree is updated after the execution of a transaction;

[0243] A second update module, configured to increase the file discard size corresponding to the file identifier in the record table of the value of the historical key-value pair by the byte length of the value of the historical key-value pair, and update the transaction identifier corresponding to the file identifier in the record table of the value of the historical key-value pair to the identifier of a transaction;

[0244] The apparatus further includes:

[0245] A deletion module, configured to delete a historical preset file if the identifier of the currently to-be-executed transaction is the sum of the transaction identifier corresponding to the file identifier of a historical preset file in the record table and the number of preset versions, where the number of preset versions is the number of rollback versions supported by the Merkle B+ tree.

[0246] In the embodiment of the present application, the value of the first key-value pair is stored in a preset file, and the storage location information of the value of the first key-value pair is stored as the value of the second key-value pair in the data node. In this case, the value contained in the data node in the Merkle B+ tree is very small, so the data storage in the disk page is relatively compact. In this way, a disk page can store many values, which can not only reduce the waste of the storage space of the disk page, but also reduce the write amplification.

[0247] It should be noted that when the data storage device provided in the above embodiment stores data, only the above-mentioned division of each functional module is used for illustration. In actual application, the above functions can be allocated to different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.

[0248] Each functional unit and module in the above embodiment can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of each functional unit and module are only for the convenience of mutual distinction and do not limit the protection scope of the embodiments of the present application.

[0249] The data storage device provided in the above embodiment and the data storage method embodiment belong to the same concept. For the specific working process and the technical effects brought by the units and modules in the above embodiment, reference can be made to the method embodiment part, which will not be elaborated here.

[0250] Figure 9 This is a schematic structural diagram of a computer device provided in an embodiment of the present application. As Figure 9 shown, the computer device 9 includes: a processor 90, a memory 91, and a computer program 92 stored in the memory 91 and executable on the processor 90. When the processor 90 executes the computer program 92, the steps in the data storage method in the above embodiment are implemented.

[0251] The computer device 9 can be a general computer device or a special computer device. In specific implementation, the computer device 9 can be a desktop computer, a portable computer, a network server, a palm computer, a mobile phone, a tablet computer, a wireless terminal device, a communication device or an embedded device. The embodiment of the present application does not limit the type of the computer device 9. Those skilled in the art can understand that Figure 9 This is only an example of the computer device 9 and does not constitute a limitation on the computer device 9. It may include more or fewer components than shown in the figure, or combine some components, or different components. For example, it may also include input and output devices, network access devices, etc.

[0252] The processor 90 can be a CPU (Central Processing Unit), and the processor 90 can also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.

[0253] In some embodiments, the memory 91 can be an internal storage unit of the computer device 9, such as the hard disk or memory of the computer device 9. In other embodiments, the memory 91 can also be an external storage device of the computer device 9, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc., equipped on the computer device 9. Further, the memory 91 can also include both the internal storage unit and the external storage device of the computer device 9. The memory 91 is used to store an operating system, application programs, a boot loader, data, and other programs, etc. The memory 91 can also be used to temporarily store data that has been output or is to be output.

[0254] The embodiments of the present application also provide a computer device, which includes: at least one processor, a memory, and a computer program stored in the memory and executable on the at least one processor, and when the processor executes the computer program, the steps in any of the above method embodiments are implemented.

[0255] The embodiments of the present application also provide a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments can be implemented.

[0256] The embodiments of the present application provide a computer program product, which when running on a computer, causes the computer to execute the steps in the above method embodiments.

[0257] When an integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, to implement all or part of the processes in the above method embodiments, this application can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium can at least include: any entity or device that can carry the computer program code to the photographing device / terminal device, recording medium, computer memory, ROM (Read-Only Memory), RAM (Random Access Memory), CD-ROM (Compact Disc Read-Only Memory), magnetic tape, floppy disk, and optical data storage device, etc. The computer-readable storage medium mentioned in this application can be a non-volatile storage medium, in other words, it can be a non-transitory storage medium.

[0258] It should be understood that all or part of the steps of implementing the above embodiments can be realized by software, hardware, firmware or any combination thereof. When implemented using software, it can be realized in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. The computer instructions can be stored in the above computer-readable storage medium.

[0259] In the above embodiments, the descriptions of each embodiment have their own emphases. For the parts not detailed or recorded in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0260] Those of ordinary skill in the art can realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.

[0261] In the embodiments provided in the present application, it should be understood that the disclosed device / computer equipment and method can be implemented in other ways. For example, the device / computer equipment embodiments described above are only illustrative. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in electrical, mechanical or other forms.

[0262] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0263] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A data storage method, characterized in that, The method includes: Obtaining a plurality of first key-value pairs to be stored; Storing the value of each first key-value pair in the plurality of first key-value pairs into a preset file to obtain the storage location information of the value of each first key-value pair; the storage location information of the value of the first key-value pair includes the file identifier of the preset file storing the value of the first key-value pair, the offset of the value of the first key-value pair in the preset file, and the byte length of the value of the first key-value pair; Generating a plurality of second key-value pairs corresponding one-to-one to the plurality of first key-value pairs, where the key value of one second key-value pair is the key value of the corresponding first key-value pair, and the value of one second key-value pair is the storage location information of the value of the corresponding first key-value pair; Obtaining the hash value of the value of each first key-value pair in the plurality of first key-value pairs; Constructing a Merkle B+ tree according to the plurality of second key-value pairs and the hash value of the value of each first key-value pair corresponding to each second key-value pair in the plurality of second key-value pairs; wherein, each data node in the Merkle B+ tree contains at least one specified data, and the specified data includes a second key-value pair and the hash value of the value of the corresponding first key-value pair; each index node in the Merkle B+ tree contains the minimum key and hash value of each subordinate node, the minimum key of the node is the smallest key value among all the key values contained in the node, and the hash value of the node is the hash value of the data obtained by concatenating all the hash values contained in the node; Storing the data of each node in the Merkle B+ tree into a disk page.

2. The method according to claim 1, characterized in that, After storing the data of each node in the Merkle B+ tree into the disk page, it further includes: Receiving a query instruction, where the query instruction carries a target key value; Obtaining the specified key-value pair stored in the disk page according to the target key value, where the specified key-value pair is the key-value pair whose key value is the target key value contained in the data node in the Merkle B+ tree; Determining the value at the storage location indicated by the value of the specified key-value pair in the preset file as the target value.

3. The method according to claim 1, wherein After storing the data of each node in the Merkle B+ tree into the disk page, it further includes: Receiving an addition instruction, where the addition instruction carries a first target key-value pair; Obtaining the hash value of the value of the first target key-value pair; Storing the value of the first target key-value pair into the preset file to obtain the storage location information of the value of the first target key-value pair; Generating a second target key-value pair corresponding to the first target key-value pair, where the key value of the second target key-value pair is the key value of the first target key-value pair, and the value of the second target key-value pair is the storage location information of the value of the first target key-value pair; Obtain the data of the target data node stored in the disk page according to the key value of the second target key-value pair, where the target data node is the data node to be inserted by the second target key-value pair in the Merkle B+ tree; Add specified target data to the data of the target data node to update the target data node, where the specified target data includes the second target key-value pair and the hash value of the value of the first target key-value pair; If the data volume of the updated target data node is less than or equal to the preset data volume, determine the smallest key value among all the key values included in the updated target data node as the minimum key of the updated target data node, and determine the hash value of the data obtained by concatenating all the hash values included in the updated target data node as the hash value of the updated target data node; Update the index node in the Merkle B+ tree according to the minimum key and hash value of the updated target data node; Store the data of the updated target data node and the data of the updated index node into the disk page.

4. The method according to claim 3, wherein After adding the specified target data to the data of the target data node to update the target data node, it further includes: If the data volume of the updated target data node is greater than the preset data volume, split the updated target data node into at least two data nodes, where the data volume of each of the at least two data nodes is less than or equal to the preset data volume; For any one of the at least two data nodes, determine the smallest key value among all the key values included in the one data node as the minimum key of the one data node, and determine the hash value of the data obtained by concatenating all the hash values included in the one data node as the hash value of the one data node; Update the index node in the Merkle B+ tree according to the minimum key and hash value of each of the at least two data nodes; Store the data of each of the at least two data nodes and the data of the updated index node into the disk page.

5. The method according to any one of claims 1 to 4, characterized in that, The number of the preset files is one or more, the storage space sizes of the one or more preset files are the same, and the one or more preset files are created sequentially. The method further includes: If the value of a key-value pair needs to be stored in the preset file, when the remaining storage space of the last preset file among all the created preset files is sufficient to store the value of the one key-value pair, store the value of the one key-value pair in the last preset file; when the remaining storage space of the last preset file is not sufficient to store the value of the one key-value pair, create a new preset file and store the value of the one key-value pair in the newly created preset file.

6. The method according to claim 5, characterized in that, The method further includes: Create a record table, where the record table includes the file identifier, file size, file discarded size, and transaction identifier of each preset file among all the created preset files. Among them, the preset file identified by the file identifier with the same file size and file discarded size in the record table is a historical preset file; The method further includes: If the Merkle B+ tree is updated after executing a transaction, determine the historical key-value pairs that are updated or deleted in the data nodes in the Merkle B+ tree during the execution of the transaction; Increase the file discarded size corresponding to the file identifier in the record table in the value of the historical key-value pair by the byte length in the value of the historical key-value pair, and update the transaction identifier corresponding to the file identifier in the record table in the value of the historical key-value pair to the identifier of the transaction; The method further includes: If the identifier of the currently pending transaction is the sum of the transaction identifier corresponding to the file identifier of a historical preset file in the record table and the preset version number, delete the historical preset file, where the preset version number is the number of rollback versions supported by the Merkle B+ tree.

7. A data storage device, characterized in that, The device includes: A first acquisition module, configured to acquire a plurality of first key-value pairs to be stored; A first storage module, configured to store the value of each first key-value pair in the plurality of first key-value pairs into a preset file to obtain the storage location information of the value of each first key-value pair; the storage location information of the value of the first key-value pair includes the file identifier of the preset file storing the value of the first key-value pair, the offset of the value of the first key-value pair in the preset file, and the byte length of the value of the first key-value pair; A generation module, configured to generate a plurality of second key-value pairs corresponding one-to-one to the plurality of first key-value pairs. The key value of a second key-value pair is the key value of the corresponding first key-value pair, and the value of a second key-value pair is the storage location information of the value of the corresponding first key-value pair; A third acquisition module, configured to acquire the hash value of the value of each first key-value pair in the plurality of first key-value pairs; A construction module, configured to construct a Merkle B+ tree according to the plurality of second key-value pairs and the hash value of the value of each first key-value pair corresponding to each second key-value pair in the plurality of second key-value pairs; where each data node in the Merkle B+ tree contains at least one specified data, and the specified data includes a second key-value pair and the hash value of the value of the corresponding first key-value pair; each index node in the Merkle B+ tree contains the minimum key and hash value of each subordinate node. The minimum key of the node is the smallest key value among all the key values contained in the node, and the hash value of the node is the hash value of the data obtained by splicing all the hash values contained in the node; A second storage module, configured to store the data of each node in the Merkle B+ tree into a disk page.

8. A computer device, characterized in that, The computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the method described in any one of claims 1 to 6 is implemented.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the method described in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Block chain data storage method and device, equipment and medium

    CN111209341A

  • Intra-fragment data organization and management method for alliance chain

    CN111324613A