WO2022134128A1 - 多版本数据存储方法、装置、计算机设备及存储介质 - Google Patents

多版本数据存储方法、装置、计算机设备及存储介质 Download PDF

Info

Publication number
WO2022134128A1
WO2022134128A1 PCT/CN2020/139809 CN2020139809W WO2022134128A1 WO 2022134128 A1 WO2022134128 A1 WO 2022134128A1 CN 2020139809 W CN2020139809 W CN 2020139809W WO 2022134128 A1 WO2022134128 A1 WO 2022134128A1
Authority
WO
WIPO (PCT)
Prior art keywords
node
tree
hash value
data
version
Prior art date
Application number
PCT/CN2020/139809
Other languages
English (en)
French (fr)
Inventor
邱炜伟
李伟
黄方蕾
张珂杰
郑柏川
Original Assignee
杭州趣链科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 杭州趣链科技有限公司 filed Critical 杭州趣链科技有限公司
Publication of WO2022134128A1 publication Critical patent/WO2022134128A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2315Optimistic concurrency control
    • G06F16/2329Optimistic concurrency control using versioning
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the present application relates to the field of blockchain technology, and in particular, to a multi-version data storage method, device, computer equipment and storage medium.
  • MPT Merkle Patricia Tree
  • MPT Merkle Patricia Tree
  • leveldb database a database developed by Google
  • MPT is indexed by prefix, and the read path is long, resulting in many hash calculations and affecting access performance.
  • frequent encoding and decoding consumes a lot of computing resources, resulting in poor storage efficiency.
  • a multi-version data storage method comprising:
  • the second tree node data is modified according to the modification instruction, and a modified version of the MVB tree is generated according to the node data not in the index path and the modified second tree node data.
  • a multi-version data storage device comprising:
  • the receiving instruction module is used to receive the modification instruction to the specified node data of the MVB tree
  • a copying module configured to copy the first tree node data on the specified node data index path, and obtain the copied second tree node data
  • a modification module configured to modify the second tree node data according to the modification instruction, and generate a modified version of the MVB tree according to the node data not in the index path and the modified second tree node data .
  • a computer device comprising a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, the processor implementing the multi-version data storage when the processor executes the computer-readable instructions method.
  • One or more readable storage media storing computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the multi-version data storage method as described above.
  • the above-mentioned multi-version data storage method, device, computer equipment and storage medium save the newly modified data in a copying manner, form multi-version data of the MVB tree structure, can store node data at high speed, and the path of the MVB tree is short, when indexing The number of IOs is small, the efficiency is high, and the disk read and write time is greatly reduced.
  • this application also supports multi-version data and data rollback, splitting the tree and placing the data on the disk (stored in the disk) at the stable point, reducing the disk time and computing time, and splitting the content data during storage (the leaf node's data) and index files (data of non-leaf nodes), adopt different storage methods to achieve better storage performance and solve the problem of low storage efficiency of blockchain data.
  • FIG. 1 is a schematic diagram of an application environment of a multi-version data storage method in an embodiment of the present application
  • FIG. 2 is a schematic flowchart of a multi-version data storage method in an embodiment of the present application
  • FIG. 3 is a schematic structural diagram of an MVB tree when copying and modifying in an embodiment of the present application
  • FIG. 4 is a schematic structural diagram of a multi-version data storage device in an embodiment of the present application.
  • FIG. 5 is a schematic diagram of a computer device in an embodiment of the present application.
  • the multi-version data storage method provided in this embodiment can be applied in the application environment as shown in FIG. 1 , in which the client and the server communicate.
  • clients include but are not limited to various personal computers, notebook computers, smart phones, tablet computers and portable wearable devices.
  • the server can be implemented by an independent server or a server cluster composed of multiple servers.
  • a method for storing multi-version data is provided, and the method is applied to the server in FIG. 1 as an example for description, including the following steps S10-S30.
  • MVB tree (Multi-version verifiable) is a variant of Merkel B+ tree.
  • the MVB tree stores several node data in the structure of Merkel B+ tree.
  • the specified node data is the node data to be modified.
  • a modification instruction may refer to an instruction to modify node data, including but not limited to an instruction to add a node, delete a node, or change the content of node data.
  • version 1 in FIG. 3 is the structure of the MVB tree before modification
  • version 2 is the structure of the MVB tree after modification.
  • the specified node data may refer to node C3.
  • the first tree node data may include a plurality of node data on the index path of the specified node data.
  • the specified node data is node C3, and the first tree node data includes A1, B3 and C3.
  • the obtained second tree node data are A2, B2 and C2. Among them, A1 corresponds to A2, B3 corresponds to B2, and C3 corresponds to C2.
  • the second tree node data can be modified according to the modification instruction, and the modified version of the MVB tree is generated according to the node data not in the index path and the modified second tree node data to generate a modified version of the MVB tree.
  • data D1 is added at node C3 by modifying the instruction.
  • the modified second tree node data includes A2, B2, and C2 including D1. Since the key-value pair list of A2 and B2 is the same as that of A1 and B3, the node data B1 and its child nodes C1, which are not in the index path, and node data C5 are also in the modified version of the MVB tree.
  • D1 may be newly added data in node C2, or may be replaced data in node C2.
  • the node C2 does not contain the data D1, and after the modification, the data D1 is added.
  • node C2 contains data D2, and after modification, D2 is replaced by D1.
  • multi-version data storage method In the multi-version data storage method provided in this embodiment, newly modified data is saved in a copying manner to form multi-version data in an MVB tree structure, node data can be stored at high speed, and the path of the MVB tree is short, and the number of IOs when indexing is performed. Less, more efficient, greatly reducing the disk read and write time.
  • step S30 the second tree node data is modified according to the modification instruction, and the second tree node data is generated according to the node data not in the index path and the modified second tree node data.
  • the modified version of the MVB tree it also includes:
  • the MVB tree performs memory commit to generate the hash value of the root node of the modified version.
  • the modification instruction is generated based on the transaction to which it belongs.
  • a transaction can generate one or more modification instructions.
  • the conditions for reaching the stable point can be set according to actual needs. For example, when the number of completed transactions reaches a preset value, it can be considered that the transactions have reached a stable point. Otherwise, the transaction is considered not to have reached a stable point. If the transaction does not reach a stable point, the MVB tree performs memory commit to generate a modified version of the root node hash value.
  • Memory commit refers to the process by which the MVB tree computes the hash of the root node of the modified version stored in memory.
  • step S51 that is, if the transaction does not reach a stable point, the MVB tree performs memory commit, and generates a root node hash value of the modified version, including:
  • the first secondary node is a child node of the root node of the modified version.
  • node B2 is the first secondary node.
  • the hash value of node C2 and the hash value of node C5 form an array, and the hash value of the array is calculated, which is the hash value of node B2.
  • the hash value of the secondary node not in the index path and the hash value of the first secondary node form an array, and the hash value of the array is calculated, which is the hash value of the root node of the modified version.
  • the node A2 is the root node
  • the secondary node not in the index path is the node B1
  • the first secondary node is the node B2.
  • the hash value of node B1 and the hash value of node B2 form an array, and the hash value of the array is calculated, which is the hash value of the root node A2 of the modified version.
  • step S511 that is, calculating the hash value of the first secondary node of the modified second tree node data, including:
  • the key-value pairs stored in the child node can be formed into an array, and the hash value of the array is calculated, which is the hash value of the leaf node.
  • step S511 that is, calculating the hash value of the first secondary node of the modified second tree node data, including:
  • the hash value of the child node of the non-leaf node can be formed into data, and the hash value of the array can be calculated, that is, the hash value of the non-leaf node. hash value.
  • step S30 the second tree node data is modified according to the modification instruction, and the second tree node data is generated according to the node data not in the index path and the modified second tree node data.
  • the modified version of the MVB tree it also includes:
  • the MVB tree performs disk commit to generate a root node hash value of the modified version.
  • the modification instruction is generated based on the transaction to which it belongs.
  • a transaction can generate one or more modification instructions.
  • the conditions for reaching the stable point can be set according to actual needs. For example, when the number of completed transactions reaches a preset value, it can be considered that the transactions have reached a stable point. Otherwise, the transaction is considered not to have reached a stable point. If the transaction reaches a stable point, the MVB tree commits to disk to generate a modified version of the root node hash. Disk commit refers to the process by which the MVB tree computes the hash of the root node of the modified version stored on disk.
  • the hash value of the root node generated by the disk submission may be different from the root node hash value generated by the memory submission.
  • step S52 that is, if the transaction reaches a stable point, the MVB tree performs disk submission, and generates a root node hash value of the modified version, including:
  • the hash value of each node of the modified version can be calculated separately to form an array, and the hash value of the array is calculated, which is the hash value of the root node of the modified version.
  • Preset writing rules can be set according to actual needs.
  • the preset writing rule may specify that different types of node data correspond to different storage modes.
  • a dirty node refers to any node from the specified node data (inclusive) to the root node (inclusive).
  • all dirty nodes need to be written.
  • the root node of the modified version can be set as the root node of the MVB tree, and the root node of the original version is used as a child node of the current root node.
  • step S521 that is, calculating the hash value of the root node of the modified version, including:
  • the preset splitting condition may be determined based on the length of the list of node data. When the length of the list of node data exceeds the preset threshold, it needs to be split. If it does not exceed, it is not necessary to split. When all leaf nodes do not meet the preset splitting conditions, the flow of leaf node splitting processing is completed.
  • the non-leaf node needs to be split. Otherwise no splitting is required.
  • the split second tree node data can be obtained.
  • the hash value of the root node of the modified version after splitting can be calculated by referring to the method of calculating the hash value of the root node of the modified version when the split is not performed, and details are not repeated here.
  • step S5212 that is, according to the preset node splitting method, the modified second tree node data is split and processed, and the split second tree node data is generated, including:
  • S52123 Calculate the hash value of each of the split nodes, and insert the first key value of the key-value pair list corresponding to each of the split nodes into the parent node of the split node.
  • the preset threshold may be set according to actual needs. In some examples, the preset thresholds corresponding to nodes at different levels may be the same or different.
  • the specified leaf node can be the judgment object of the preset split condition. And satisfying the preset splitting condition means that the length of the key-value pair list of the specified leaf node exceeds the preset threshold. If the preset splitting conditions are met, the specified leaf node needs to be split into several split nodes whose length of the key-value pair list does not exceed the preset threshold. Then, the first key value of the key-value pair list corresponding to each split node is inserted into the parent node of the split node. If the preset splitting conditions are not met, the specified leaf node does not need to be split.
  • the first key value may refer to the first key value (Key) of the key-value pair list of the split node (leaf node).
  • the node splitting process needs to be performed according to the splitting method of the specified leaf node above. It is not repeated here.
  • the length of the key-value pair list of all nodes does not exceed the preset threshold, it means that the node splitting process has been completed.
  • step S5213 the calculation of the hash value of the second secondary node of the split second tree node data includes:
  • S52131 Calculate the hash value of the second secondary node according to the child nodes of the second secondary node. If the child nodes of the second secondary node are leaf nodes, calculate the hash value according to the key stored in the leaf node. The value pair calculates the hash value of the leaf node.
  • the hash value of the second secondary node may be calculated with reference to the calculation method of the hash value of the first secondary node, which will not be repeated here.
  • step S5213 the calculation of the hash value of the second secondary node of the split second tree node data includes:
  • S52132 Calculate the hash value of the second secondary node according to the child nodes of the second secondary node. If the child nodes of the second secondary node are non-leaf nodes, calculate the hash value according to the children of the non-leaf node. The hash value of the node calculates the hash value of the non-leaf node.
  • the hash value of the second secondary node may be calculated with reference to the calculation method of the hash value of the first secondary node, which will not be repeated here.
  • step S522 after the writing of the modified version of the dirty node to the disk according to the preset writing rule, further includes:
  • performing a memory cleanup operation may refer to clearing the memory list that maintains the root of the multi-version tree.
  • the occupation of computing resources can be reduced and the accessibility of the MVB tree can be improved.
  • the preset writing rules include:
  • Non-leaf nodes are stored in a single file, and the storage method is cache IO.
  • non-leaf nodes tend to take up less space than leaf nodes.
  • Leaf nodes can be stored in a single file and stored in a buffer IO (buffer IO).
  • buffer IO buffer IO
  • the file where the non-leaf node is located can be directly mapped into memory.
  • the files where the non-leaf nodes are located are cached in the memory, which improves the access performance of the non-leaf nodes.
  • the preset writing rules include:
  • Leaf nodes are stored in multiple files, and the storage method is direct IO.
  • leaf nodes take up a lot of space and cannot store all of them in memory. Therefore, it can be stored in the form of direct IO (direct IO). It only needs to read and write a certain disk page independently when reading and writing, and only load the data of one or more recently accessed leaf nodes into memory, reducing memory usage and speeding up access.
  • direct IO direct IO
  • step S10 that is, before receiving the modification instruction to the specified node data of the MVB tree, further includes:
  • transaction is a basic activity of blockchain, which can represent a transaction operation, such as transfer payment on the fund side.
  • a new transaction represents the occurrence of a transaction.
  • a transaction may trigger one or more modification instructions.
  • step S30 the second tree node data is modified according to the modification instruction, and the second tree node data is generated according to the node data not in the index path and the modified second tree node data.
  • the modified version of the MVB tree it also includes:
  • step S60 occurs after step S51 or S52.
  • MVB trees can generate Merkle proofs to prove the availability of node data in the database.
  • Merkel proofs include the node path from the data node where the specific data is located to the root node of the modified version (the modified version is the latest version).
  • a verification hash value can be calculated according to the node path, and compared with the root node hash value of the modified version (that is, the global data hash digest generated by the transaction), Then verify the availability of data in the database. When it is verified that the hash value is equal to the root node hash value, it is determined that specific data is stored in the MVB tree. When the verification hash value is not equal to the root node hash value, it is determined that the specific data is not stored in the MVB tree.
  • step S30 the second tree node data is modified according to the modification instruction, and the second tree node data is generated according to the node data not in the index path and the modified second tree node data.
  • a modified version of the MVB tree including:
  • the modified version of the MVB tree only contains the modified second tree node data, so the root node of the second tree node data can be set as the root node of the modified version.
  • the original reference path is retained.
  • a multi-version data storage device is provided, and the multi-version data storage device is in one-to-one correspondence with the multi-version data storage method in the above embodiment.
  • the multi-version data storage device includes a receiving instruction module 10 , a copying module 20 and a modifying module 30 .
  • the detailed description of each functional module is as follows:
  • the receiving instruction module 10 is used for receiving the modification instruction to the specified node data of the MVB tree
  • a copying module 20 configured to copy the first tree node data on the specified node data index path, and obtain the copied second tree node data
  • the modification module 30 is configured to modify the second tree node data according to the modification instruction, and generate the modification of the MVB tree according to the node data not in the index path and the modified second tree node data Version.
  • the multi-version data storage device further includes:
  • a stable point judgment module configured to judge whether the transaction reaches a stable point when the transaction to which the modification instruction belongs ends
  • a memory commit module configured to perform memory commit on the MVB tree if the transaction does not reach a stable point, and generate a hash value of the root node of the modified version.
  • the memory commit module includes:
  • a first secondary node computing unit configured to calculate the hash value of the first secondary node of the modified second tree node data, where the first secondary node is a child node of the root node of the modified version;
  • the first root node hash value calculation unit is configured to, if there is a secondary node that is not in the index path, calculate the said secondary node according to the hash value of the secondary node and the hash value of the first secondary node.
  • the hash value of the root node of the modified version, and the secondary node is a child node of the root node of the modified version.
  • the first secondary node computing unit includes:
  • the first leaf hash calculation unit is configured to calculate the hash value of the first secondary node according to the child nodes of the first secondary node, if the child nodes of the first secondary node are leaf nodes, according to The hash value of the leaf node is calculated from the key-value pair stored in the leaf node.
  • the first secondary node computing unit includes:
  • a first non-leaf hash calculation unit configured to calculate the hash value of the first secondary node according to the child nodes of the first secondary node, if the child nodes of the first secondary node are non-leaf nodes , and calculate the hash value of the non-leaf node according to the hash value of the child node of the non-leaf node.
  • the multi-version data storage device further includes:
  • a stable point judgment module configured to judge whether the transaction reaches a stable point when the transaction to which the modification instruction belongs ends
  • a disk commit module configured to perform disk commit on the MVB tree if the transaction reaches a stable point, and generate a hash value of the root node of the modified version.
  • the disk commit module includes:
  • a disk root hash unit used to calculate the root node hash value of the modified version
  • a disk writing unit configured to write the modified version of the dirty node into the disk according to a preset writing rule, and set the modified version's root node as the root node of the MVB tree.
  • the disk root hash unit includes:
  • a node splitting unit configured to perform splitting processing on the modified second tree node data according to a preset node splitting method to generate split second tree node data
  • a second secondary node calculation unit configured to calculate the hash value of the second secondary node of the split second tree node data, where the second secondary node is a child node of the root node of the modified version ;
  • the second root node hash value calculation unit is configured to, if there is a secondary node not in the index path, calculate the hash value of the secondary node according to the hash value of the secondary node and the hash value of the second secondary node
  • the hash value of the root node of the modified version, and the secondary node is a child node of the root node of the modified version.
  • the node-splitting unit includes:
  • Threshold judgment unit used for judging whether the length of the key-value pair list of the specified leaf node exceeds the preset threshold
  • a splitting unit configured to split the specified leaf node into a number of split nodes whose length of the key-value pair list does not exceed the preset threshold if the length of the key-value pair list of the specified leaf node exceeds the preset threshold;
  • a key value inserting unit configured to calculate the hash value of each of the split nodes, and insert the first key value of the key-value pair list corresponding to each of the split nodes into the parent node of the split node.
  • the second secondary node computing unit includes:
  • the second leaf hash calculation unit is configured to calculate the hash value of the second secondary node according to the child nodes of the second secondary node. If the child nodes of the second secondary node are leaf nodes, according to The hash value of the leaf node is calculated from the key-value pair stored in the leaf node.
  • the second secondary node computing unit includes:
  • a second non-leaf hash calculation unit configured to calculate the hash value of the second secondary node according to the child nodes of the second secondary node, if the child nodes of the second secondary node are non-leaf nodes , and calculate the hash value of the non-leaf node according to the hash value of the child node of the non-leaf node.
  • the disk commit module also includes:
  • Memory cleanup unit used to perform memory cleanup operations.
  • the preset writing rules include:
  • Non-leaf nodes are stored in a single file, and the storage method is cache IO.
  • the preset writing rules include:
  • Leaf nodes are stored in multiple files, and the storage method is direct IO.
  • the multi-version data storage device further includes:
  • generating a modification instruction unit configured to generate the modification instruction according to the transaction.
  • the multi-version data storage device further includes:
  • receiving a certification request unit for receiving a certification request for specific data when the transaction to which the modification instruction belongs ends;
  • a Merkle proof unit for generating a Merkle proof of the specific data, the Merkle proof including the data node of the specific data and the node path of the root node of the modified version;
  • a certification unit configured to determine that the specific data is stored in the MVB tree when the verification hash value is equal to the root node hash value.
  • the modification module 30 includes:
  • a node setting unit configured to set the root node of the second tree node data as the root node of the modified version.
  • Each module in the above-mentioned multi-version data storage device may be implemented in whole or in part by software, hardware and combinations thereof.
  • the above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
  • a computer device is provided, and the computer device may be a server, and its internal structure diagram may be as shown in FIG. 5 .
  • the computer device includes a processor, memory, a network interface, and a database connected by a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities.
  • the memory of the computer device includes a readable storage medium, an internal memory.
  • the readable storage medium stores an operating system, computer readable instructions and a database.
  • the internal memory provides an environment for the execution of the operating system and computer-readable instructions in the readable storage medium.
  • the database of the computer device is used to store the data involved in the multi-version data storage method.
  • the network interface of the computer device is used to communicate with an external terminal through a network connection.
  • the computer-readable instructions when executed by a processor, implement a multi-version data storage method.
  • the readable storage medium provided by this embodiment includes a non-volatile readable storage medium and a volatile readable storage medium.
  • a computer device comprising a memory, a processor, and computer-readable instructions stored on the memory and executable on the processor, and the processor implements the following steps when executing the computer-readable instructions:
  • the second tree node data is modified according to the modification instruction, and a modified version of the MVB tree is generated according to the node data not in the index path and the modified second tree node data.
  • one or more computer-readable storage media storing computer-readable instructions are provided, and the readable storage media provided in this embodiment include non-volatile readable storage media and volatile readable storage media storage medium.
  • Computer-readable instructions are stored on the readable storage medium, and when the computer-readable instructions are executed by one or more processors, implement the following steps:
  • the second tree node data is modified according to the modification instruction, and a modified version of the MVB tree is generated according to the node data not in the index path and the modified second tree node data.
  • Nonvolatile memory may include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory.
  • Volatile memory may include random access memory (RAM) or external cache memory.
  • RAM is available in various forms such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous chain Road (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

提供一种多版本数据存储方法、装置、计算机设备及存储介质,多版本数据存储方法包括:接收对MVB树的指定节点数据的修改指令(S10);复制所述指定节点数据索引路径上的第一树节点数据,获得复制后的第二树节点数据(S20);根据所述修改指令对所述第二树节点数据进行修改,根据不处于索引路径的节点数据和修改后的第二树节点数据生成MVB树的修改版本(S30)。多版本数据存储方法可以提高区块链数据的存储效率。

Description

多版本数据存储方法、装置、计算机设备及存储介质
本申请要求于2020年12月22日提交中国专利局、申请号为202011532673.3,发明名称为“多版本数据存储方法、装置、计算机设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及区块链技术领域,尤其涉及一种多版本数据存储方法、装置、计算机设备及存储介质。
背景技术
现有技术中,传统的默克尔B+树即在B+树的基础上加上计算节点哈希的过程,树的节点均存放在单个数据文件。而MPT(Merkle Patricia Tree,梅克尔帕特里夏树)则融合了前缀树与默克尔树的特点。发明人发现,MPT使用leveldb数据库(谷歌公司开发的一种数据库)存储数据,存在读放大写放大问题。另外,MPT按前缀索引,读取路径长,造成哈希计算次数多,影响访问性能。而且,数据存储过程中,频繁的编码解码,消耗了大量的计算资源,存储效率差。
申请内容
基于此,有必要针对上述技术问题,提供一种多版本数据存储方法、装置、计算机设备及存储介质,以解决现有区块链数据存储效率低的问题。
一种多版本数据存储方法,包括:
接收对MVB树的指定节点数据的修改指令;
复制所述指定节点数据索引路径上的第一树节点数据,获得复制后的第二树节点数据;
根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本。
一种多版本数据存储装置,包括:
接收指令模块,用于接收对MVB树的指定节点数据的修改指令;
复制模块,用于复制所述指定节点数据索引路径上的第一树节点数据,获得复制后的第二树节点数据;
修改模块,用于根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本。
一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机可读指令,所述处理器执行所述计算机可读指令时实现上述多版本数据存储方法。
一个或多个存储有计算机可读指令的可读存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如上述多版本数据存储方法。
上述多版本数据存储方法、装置、计算机设备及存储介质,以复制的方式保存新修改的数据,形成MVB树结构的多版本数据,可以高速存储节点数据,而且MVB树的路径短,进行索引时IO次数少,效率大,大大减少了磁盘读写时间。此外,本申请还支持多版本数据与数据回滚,在稳定点才进行树的分裂与以及数据落盘(存入磁盘),减少磁盘时间与计算时间,存储时拆分内容数据(叶子节点的数据)与索引文件(非叶子节点的数据),分别采取不同的存储方式,实现更佳的存储性能,解决了区块链数据存储效率低的问题。
本申请的一个或多个实施例的细节在下面的附图和描述中提出,本申请的其他特征和优点将从说明书、附图以及权利要求变得明显。
附图说明
为了更清楚地说明本申请实施例的技术方案,下面将对本申请实施例的描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1是本申请一实施例中多版本数据存储方法的一应用环境示意图;
图2是本申请一实施例中多版本数据存储方法的一流程示意图;
图3是本申请一实施例中MVB树进行复制修改时的结构示意图;
图4是本申请一实施例中多版本数据存储装置的一结构示意图;
图5是本申请一实施例中计算机设备的一示意图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
本实施例提供的多版本数据存储方法,可应用在如图1的应用环境中,其中,客户端与服务端进行通信。其中,客户端包括但不限于各种个人计算机、笔记本电脑、智能手机、平板电脑和便携式可穿戴设备。服务端可以用独立的服务器或者是多个服务器组成的服务器集群来实现。
在一实施例中,如图2所示,提供一种多版本数据存储方法,以该方法应用在图1中的服务端为例进行说明,包括如下步骤S10-S30。
S10、接收对MVB树的指定节点数据的修改指令。
可理解地,MVB树(Multi-version verifiable)为默克尔B+树的一种变体。MVB树以默克尔B+树的结构存储了若干节点数据。指定节点数据为待修改的节点数据。修改指令可以指对节点数据进行修改的指令,包括但不限于增加节点、删除节点或者改变节点数据内容的指令。如图3所示,图3中的版本1为修改前的MVB树的结构,版本2为修改后的MVB树的结构。在版本1中,指定节点数据可以指节点C3。
S20、复制所述指定节点数据索引路径上的第一树节点数据,获得复制后的第二树节点数据。
可理解地,第一树节点数据可以包括指定节点数据的索引路径上多个节点数据。在图3的示例中,指定节点数据为节点C3,第一树节点数据包括A1、B3和C3。通过复制,获得的第二树节点数据为A2、B2和C2。其中,A1与A2对应、B3与B2对应、C3与C2对应。
S30、根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本。
可理解地,可以根据修改指令对第二树节点数据进行修改,根据不处于索引路径的节点数据和修改后的第二树节点数据生成MVB树的修改版本生成MVB树的修改版本。在图3的示例中,通过修改指令,在节点C3增加了数据D1。修改后的第二树节点数据包括A2、B2和包含D1的C2。由于A2和B2的键值对列表与A1和B3相同,因而,不处于索引路径的节点数据B1及其子节点C1,节点数据C5也处于MVB树的修改版本中。需要注意的是,D1可以是节点C2中的新增数据,也可以是节点C2中的替换数据。例如, 修改前,节点C2不包含数据D1,修改后,新增数据D1。又如,修改前,节点C2包含数据D2,修改后,D2替换为D1。
在本实施例提供的多版本数据存储方法中,以复制的方式保存新修改的数据,形成MVB树结构的多版本数据,可以高速存储节点数据,而且MVB树的路径短,进行索引时IO次数少,效率大,大大减少了磁盘读写时间。
可选的,步骤S30,即所述根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本之后,还包括:
S40、当所述修改指令所属的事务结束时,判断所述事务是否达到稳定点;
S51、若所述事务未达到稳定点,所述MVB树进行内存提交,生成所述修改版本的根节点哈希值。
可理解的,修改指令是基于其所属的事务生成的。一个事务可以生成一个或多个修改指令。可以根据实际需要设置达到稳定点的条件。例如,当执行完毕的事务的个数达到预设值时,可视为事务达到稳定点。否则,则视为事务未达到稳定点。若事务未达到稳定点,MVB树进行内存提交,生成修改版本的根节点哈希值。内存提交指的是MVB树计算存储于内存中的修改版本的根节点哈希值的过程。
在稳定点前,若需要进行数据回滚,只需要将MVB树的当前树根节点设置为要回滚的树根,并清除维护多版本树根的内存列表即可。
可选的,步骤S51,即所述若所述事务未达到稳定点,所述MVB树进行内存提交,生成所述修改版本的根节点哈希值,包括:
S511、计算修改后的第二树节点数据的第一次级节点的哈希值,所述第一次级节点为所述修改版本的根节点的子节点;
S512、若存在不处于所述索引路径的次级节点,根据所述次级节点的哈希值和所述第一次级节点的哈希值计算所述修改版本的根节点哈希值,所述次级节点为所述修改版本的根节点的子节点。
可理解地,第一次级节点为修改版本的根节点的子节点。在图3的示例中,节点B2即为第一次级节点。节点C2的哈希值与节点C5的哈希值组成数组,计算该数组的哈希值,即为节点B2的哈希值。
不处于所述索引路径的次级节点的哈希值和第一次级节点的哈希值组成数组,计算该数组的哈希值,即为修改版本的根节点哈希值。在图3的示例中,节点A2为根节点,不处于所述索引路径的次级节点为节点B1,第一次级节点为节点B2。节点B1的哈希值与节点B2的哈希值组成数组,计算该数组的哈希值,即为修改版本的根节点A2的哈希值。
可理解地,步骤S511中,即所述计算修改后的第二树节点数据的第一次级节点的哈希值,包括:
S5111、根据所述第一次级节点的子节点计算所述第一次级节点的哈希值,若所述第一次级节点的子节点为叶子节点,根据所述叶子节点内存储的键值对计算所述叶子节点的哈希值。
可理解地,当第一次级节点的子节点为叶子节点时,可以将该子节点内存储的键值对组成数组,计算该数组的哈希值,即为叶子节点的哈希值。
可选的,步骤S511中,即所述计算修改后的第二树节点数据的第一次级节点的哈希值,包括:
S5111、根据所述第一次级节点的子节点计算所述第一次级节点的哈希值,若所述第一次级节点的子节点为非叶子节点,根据所述非叶子节点的子节点的哈希值计算所述非叶子节点的哈希值。
可理解地,当第一次级节点的子节点为非叶子节点时,可以将该非叶子节点的子节点 的哈希值组成数据,计算该数组的哈希值,即为该非叶子节点的哈希值。
可选的,步骤S30,即所述根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本之后,还包括:
S40、当所述修改指令所属的事务结束时,判断所述事务是否达到稳定点;
S52、若所述事务达到稳定点,所述MVB树进行磁盘提交,生成所述修改版本的根节点哈希值。
可理解的,修改指令是基于其所属的事务生成的。一个事务可以生成一个或多个修改指令。可以根据实际需要设置达到稳定点的条件。例如,当执行完毕的事务的个数达到预设值时,可视为事务达到稳定点。否则,则视为事务未达到稳定点。若事务达到稳定点,MVB树进行磁盘提交,生成修改版本的根节点哈希值。磁盘提交指的是MVB树计算存储于磁盘中的修改版本的根节点哈希值的过程。
由于修改版本在进行磁盘存储时,可能发生节点分裂,磁盘提交生成的根节点哈希值可能与内存提交生成的根节点哈希值存在差异。
可选的,步骤S52,即所述若所述事务达到稳定点,所述MVB树进行磁盘提交,生成所述修改版本的根节点哈希值,包括:
S521、计算所述修改版本的根节点哈希值;
S522、根据预设写入规则将所述修改版本的脏节点写入磁盘中,并将所述修改版本的根节点设置为所述MVB树的根节点。
本实施例中,可以分别计算修改版本各个节点的哈希值,组成数组,计算数组的哈希值,即为修改版本的根节点哈希值。
预设写入规则可以根据实际需要设置。在此处,预设写入规则可以规定不同类型节点数据对应不同的存储方式。脏节点指的是从指定节点数据(包括)至根节点(包括)上的任意一个节点。根据预设写入规则将修改版本的脏节点写入磁盘中时,所有脏节点都需要写入。在完成写入后,可以将修改版本的根节点设置为MVB树的根节点,而原来版本的根节点作为当前根节点的子节点。
可选的,步骤S521,即所述计算所述修改版本的根节点哈希值,包括:
S5211、获取修改后的第二树节点数据;
S5212、根据预设节点分裂方法对所述修改后的第二树节点数据进行分裂处理,生成分裂后的第二树节点数据;
S5213、计算所述分裂后的第二树节点数据的第二次级节点的哈希值,所述第二次级节点为所述修改版本的根节点的子节点;
S5214、若存在不处于所述索引路径的次级节点,根据所述次级节点的哈希值和所述第二次级节点的哈希值计算所述修改版本的根节点哈希值,所述次级节点为所述修改版本的根节点的子节点。
可理解地,在计算节点的哈希值前,需要判断是否需要对叶子节点进行分裂。若满足预设分裂条件,则需要对叶子进行分裂处理,形成若干个叶子节点。在一示例中,预设分裂条件可以是基于节点数据的列表长度决定的。当节点数据的列表长度超出预设阈值时,则需要进行分裂,若未超出,则不需要进行分裂。当所有叶子节点均不满足预设分裂条件时,则叶子节点分裂处理的流程完成。
同样的,当非叶子节点下的子叶节点超出预设节点数阈值时,需要对非叶子节点进行分裂。否则不需要进行分裂。
在完成节点分裂后,可以获得分裂后的第二树节点数据。可参照不进行分裂时计算修改版本的根节点哈希值的方法计算分裂后的修改版本的根节点哈希值,在此不再赘述。
可选的,步骤S5212,即所述根据预设节点分裂方法对所述修改后的第二树节点数据 进行分裂处理,生成分裂后的第二树节点数据,包括:
S52121、判断指定叶子节点的键值对列表长度是否超出预设阈值;
S52122、若指定叶子节点的键值对列表长度超出预设阈值,则将所述指定叶子节点分裂为若干个键值对列表长度不超出所述预设阈值的分裂节点;
S52123、计算各个所述分裂节点的哈希值,并将所述各个所述分裂节点对应的键值对列表第一个键值插入到所述分裂节点的父节点中。
本实施例中,预设阈值可以根据实际需要进行设置。在一些示例中,不同层级的节点对应的预设阈值,可以相同,也可以不同。指定叶子节点可以是预设分裂条件的判断对象。而满足预设分裂条件,指的是指定叶子节点的键值对列表长度超出预设阈值。若满足预设分裂条件,则需将该指定叶子节点分裂为若干个键值对列表长度不超出预设阈值的分裂节点。然后将各个分裂节点对应的键值对列表的第一键值插入到分裂节点的父节点中。若不满足预设分裂条件,则不需要对指定叶子节点进行分裂。在一示例中,第一键值可以指分裂节点(叶子节点)的键值对列表的第一个键值(Key)。
键值插入完成之后,需要判断父节点的键值对列表长度是否超出预设阈值。若父节点的键值对列表长度超出预设阈值,则需要按照上述指定叶子节点的分裂方式进行节点分裂处理。在此不再赘述。当所有节点的键值对列表长度均不超出预设阈值,则表示节点分裂处理已经完成。
可选的,步骤S5213中,即所述计算所述分裂后的第二树节点数据的第二次级节点的哈希值,包括:
S52131、根据所述第二次级节点的子节点计算所述第二次级节点的哈希值,若所述第二次级节点的子节点为叶子节点,根据所述叶子节点内存储的键值对计算所述叶子节点的哈希值。
可理解地,可参照第一次级节点的哈希值的计算方式计算第二次级节点的哈希值,在此不再赘述。
可选的,步骤S5213中,即所述计算所述分裂后的第二树节点数据的第二次级节点的哈希值,包括:
S52132、根据所述第二次级节点的子节点计算所述第二次级节点的哈希值,若所述第二次级节点的子节点为非叶子节点,根据所述非叶子节点的子节点的哈希值计算所述非叶子节点的哈希值。
可理解地,可参照第一次级节点的哈希值的计算方式计算第二次级节点的哈希值,在此不再赘述。
可选的,步骤S522,即所述根据预设写入规则将所述修改版本的脏节点写入磁盘中之后,还包括:
S523、执行内存清理操作。
在此处,执行内存清理操作可以指清除维护多版本树根的内存列表。通过内存清理操作,可以减少计算资源的占用,提高MVB树的可访问性。
可选的,所述预设写入规则包括:
非叶子节点存储于单文件中,存储方式为缓存IO。
在此处,非叶子节点的占用空间往往小于叶子节点。可以将叶子节点存储在单文件中,以缓存IO(buffer IO)方式存储。在读取非叶子节点时,非叶子节点所在的文件可以直接映射到内存中。以单文件的存储方式、缓存IO的形式,使非叶子节点所在的文件缓存在内存中,提高了非叶子节点的访问性能。
可选的,所述预设写入规则包括:
叶子节点存储于多文件中,存储方式为直接IO。
在此处,叶子节点的占用空间大,无法将其全部存在内存中。因而可以采用直接IO (direct IO)的方式存储。只需要在读写时单,独读写某个磁盘页,只加载最近访问的一个或者多个叶子节点数据于内存中,减少内存占用,加快访问速度。
可选的,步骤S10,即所述接收对MVB树的指定节点数据的修改指令之前,还包括:
S101、新建事务;
S102、根据所述事务生成所述修改指令。
在此处,事务(transaction)是区块链的一种基本活动,可以表示一种交易操作,如资金侧的转账支付。新建事务表示一个事务的发生。一个事务可能触发一个或多个修改指令。
可选的,步骤S30,即所述根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本之后,还包括:
S60、当所述修改指令所属的事务结束时,接收特定数据的证明请求;
S61、生成所述特定数据的默克尔证明,所述默克尔证明包括所述特定数据的数据节点以及所述修改版本的根节点的节点路径;
S62、根据所述默克尔证明计算所述特定数据的验证哈希值;
S63、当所述验证哈希值与所述根节点哈希值相等时,判定所述特定数据存储于所述MVB树中。
可理解地,步骤S60发生在步骤S51或S52之后。MVB树可以生成默克尔证明,来证明节点数据在数据库的可用性。默克尔证明包括特定数据所在的数据节点到修改版本(修改版本即为最新版本)根节点的节点路径。用户拿到默克尔证明后,可以根据该节点路径计算出一个验证哈希值,并与所述修改版本的根节点哈希值(即为事务生成的全局数据哈希摘要)进行比对,进而验证数据在数据库的可用性。当验证哈希值与根节点哈希值相等时,判定特定数据存储于MVB树中。当验证哈希值与根节点哈希值不相等时,判定特定数据不存储于MVB树中。
可选的,步骤S30,即所述根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本,包括:
S301、将所述第二树节点数据的根节点设置为所述修改版本的根节点。
可理解地,MVB树的修改版本仅包含修改后的第二树节点数据,因而可以将第二树节点数据的根节点设置为修改版本的根节点。而对于不处于索引路径的节点(如图3中的B1及其子节点C1、C4),则保留原有的引用路径。
应理解,上述实施例中各步骤的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。
在一实施例中,提供一种多版本数据存储装置,该多版本数据存储装置与上述实施例中多版本数据存储方法一一对应。如图4所示,该多版本数据存储装置包括接收指令模块10、复制模块20和修改模块30。各功能模块详细说明如下:
接收指令模块10,用于接收对MVB树的指定节点数据的修改指令;
复制模块20,用于复制所述指定节点数据索引路径上的第一树节点数据,获得复制后的第二树节点数据;
修改模块30,用于根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本。
可选的,多版本数据存储装置还包括:
稳定点判断模块,用于当所述修改指令所属的事务结束时,判断所述事务是否达到稳定点;
内存提交模块,用于若所述事务未达到稳定点,所述MVB树进行内存提交,生成所述修改版本的根节点哈希值。
可选的,内存提交模块包括:
第一次级节点计算单元,用于计算修改后的第二树节点数据的第一次级节点的哈希值,所述第一次级节点为所述修改版本的根节点的子节点;
第一根节点哈希值计算单元,用于若存在不处于所述索引路径的次级节点,根据所述次级节点的哈希值和所述第一次级节点的哈希值计算所述修改版本的根节点哈希值,所述次级节点为所述修改版本的根节点的子节点。
可选的,第一次级节点计算单元包括:
第一叶子哈希计算单元,用于根据所述第一次级节点的子节点计算所述第一次级节点的哈希值,若所述第一次级节点的子节点为叶子节点,根据所述叶子节点内存储的键值对计算所述叶子节点的哈希值。
可选的,第一次级节点计算单元包括:
第一非叶子哈希计算单元,用于根据所述第一次级节点的子节点计算所述第一次级节点的哈希值,若所述第一次级节点的子节点为非叶子节点,根据所述非叶子节点的子节点的哈希值计算所述非叶子节点的哈希值。
可选的,多版本数据存储装置还包括:
稳定点判断模块,用于当所述修改指令所属的事务结束时,判断所述事务是否达到稳定点;
磁盘提交模块,用于若所述事务达到稳定点,所述MVB树进行磁盘提交,生成所述修改版本的根节点哈希值。
可选的,磁盘提交模块包括:
磁盘根哈希单元,用于计算所述修改版本的根节点哈希值;
磁盘写入单元,用于根据预设写入规则将所述修改版本的脏节点写入磁盘中,并将所述修改版本的根节点设置为所述MVB树的根节点。
可选的,磁盘根哈希单元包括:
获取修改数据单元,用于获取修改后的第二树节点数据;
节点分裂单元,用于根据预设节点分裂方法对所述修改后的第二树节点数据进行分裂处理,生成分裂后的第二树节点数据;
第二次级节点计算单元,用于计算所述分裂后的第二树节点数据的第二次级节点的哈希值,所述第二次级节点为所述修改版本的根节点的子节点;
第二根节点哈希值计算单元,用于若存在不处于所述索引路径的次级节点,根据所述次级节点的哈希值和所述第二次级节点的哈希值计算所述修改版本的根节点哈希值,所述次级节点为所述修改版本的根节点的子节点。
可选的,节点分裂单元包括:
阈值判断单元,用于判断指定叶子节点的键值对列表长度是否超出预设阈值;
分裂单元,用于若指定叶子节点的键值对列表长度超出预设阈值,则将所述指定叶子节点分裂为若干个键值对列表长度不超出所述预设阈值的分裂节点;
键值插入单元,用于计算各个所述分裂节点的哈希值,并将所述各个所述分裂节点对应的键值对列表第一个键值插入到所述分裂节点的父节点中。
可选的,第二次级节点计算单元包括:
第二叶子哈希计算单元,用于根据所述第二次级节点的子节点计算所述第二次级节点的哈希值,若所述第二次级节点的子节点为叶子节点,根据所述叶子节点内存储的键值对计算所述叶子节点的哈希值。
可选的,第二次级节点计算单元包括:
第二非叶子哈希计算单元,用于根据所述第二次级节点的子节点计算所述第二次级节点的哈希值,若所述第二次级节点的子节点为非叶子节点,根据所述非叶子节点的子节点 的哈希值计算所述非叶子节点的哈希值。
可选的,磁盘提交模块还包括:
内存清理单元,用于执行内存清理操作。
可选的,所述预设写入规则包括:
非叶子节点存储于单文件中,存储方式为缓存IO。
可选的,所述预设写入规则包括:
叶子节点存储于多文件中,存储方式为直接IO。
可选的,多版本数据存储装置还包括:
建立事务单元,用于新建事务;
生成修改指令单元,用于根据所述事务生成所述修改指令。
可选的,多版本数据存储装置还包括:
接收证明请求单元,用于当所述修改指令所属的事务结束时,接收特定数据的证明请求;
默克尔证明单元,用于生成所述特定数据的默克尔证明,所述默克尔证明包括所述特定数据的数据节点以及所述修改版本的根节点的节点路径;
生成验证值单元,用于根据所述默克尔证明计算所述特定数据的验证哈希值;
证明单元,用于当所述验证哈希值与所述根节点哈希值相等时,判定所述特定数据存储于所述MVB树中。
可选的,修改模块30包括:
节点设置单元,用于将所述第二树节点数据的根节点设置为所述修改版本的根节点。
关于多版本数据存储装置的具体限定可以参见上文中对于多版本数据存储方法的限定,在此不再赘述。上述多版本数据存储装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。
在一个实施例中,提供了一种计算机设备,该计算机设备可以是服务器,其内部结构图可以如图5所示。该计算机设备包括通过系统总线连接的处理器、存储器、网络接口和数据库。其中,该计算机设备的处理器用于提供计算和控制能力。该计算机设备的存储器包括可读存储介质、内存储器。该可读存储介质存储有操作系统、计算机可读指令和数据库。该内存储器为可读存储介质中的操作系统和计算机可读指令的运行提供环境。该计算机设备的数据库用于存储多版本数据存储方法所涉及的数据。该计算机设备的网络接口用于与外部的终端通过网络连接通信。该计算机可读指令被处理器执行时以实现一种多版本数据存储方法。本实施例所提供的可读存储介质包括非易失性可读存储介质和易失性可读存储介质。
在一个实施例中,提供了一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机可读指令,处理器执行计算机可读指令时实现以下步骤:
接收对MVB树的指定节点数据的修改指令;
复制所述指定节点数据索引路径上的第一树节点数据,获得复制后的第二树节点数据;
根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本。
在一个实施例中,提供了一个或多个存储有计算机可读指令的计算机可读存储介质,本实施例所提供的可读存储介质包括非易失性可读存储介质和易失性可读存储介质。可读存储介质上存储有计算机可读指令,计算机可读指令被一个或多个处理器执行时实现以下步骤:
接收对MVB树的指定节点数据的修改指令;
复制所述指定节点数据索引路径上的第一树节点数据,获得复制后的第二树节点数据;
根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机可读指令来指令相关的硬件来完成,所述的计算机可读指令可存储于一非易失性可读取存储介质或易失性可读存储介质中,该计算机可读指令在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和/或易失性存储器。非易失性存储器可包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双数据率SDRAM(DDRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)等。
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,仅以上述各功能单元、模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元、模块完成,即将所述装置的内部结构划分成不同的功能单元或模块,以完成以上描述的全部或者部分功能。
以上所述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。

Claims (20)

  1. 一种多版本数据存储方法,其中,包括:
    接收对MVB树的指定节点数据的修改指令;
    复制所述指定节点数据索引路径上的第一树节点数据,获得复制后的第二树节点数据;
    根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本。
  2. 如权利要求1所述的多版本数据存储方法,其中,所述根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本之后,还包括:
    当所述修改指令所属的事务结束时,判断所述事务是否达到稳定点;
    若所述事务未达到稳定点,所述MVB树进行内存提交,生成所述修改版本的根节点哈希值。
  3. 如权利要求2所述的多版本数据存储方法,其中,所述若所述事务未达到稳定点,所述MVB树进行内存提交,生成所述修改版本的根节点哈希值,包括:
    计算修改后的第二树节点数据的第一次级节点的哈希值,所述第一次级节点为所述修改版本的根节点的子节点;
    若存在不处于所述索引路径的次级节点,根据所述次级节点的哈希值和所述第一次级节点的哈希值计算所述修改版本的根节点哈希值,所述次级节点为所述修改版本的根节点的子节点。
  4. 如权利要求3所述的多版本数据存储方法,其中,所述计算修改后的第二树节点数据的第一次级节点的哈希值,包括:
    根据所述第一次级节点的子节点计算所述第一次级节点的哈希值,若所述第一次级节点的子节点为叶子节点,根据所述叶子节点内存储的键值对计算所述叶子节点的哈希值;
    根据所述第一次级节点的子节点计算所述第一次级节点的哈希值,若所述第一次级节点的子节点为非叶子节点,根据所述非叶子节点的子节点的哈希值计算所述非叶子节点的哈希值。
  5. 如权利要求1所述的多版本数据存储方法,其中,所述根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本之后,还包括:
    当所述修改指令所属的事务结束时,判断所述事务是否达到稳定点;
    若所述事务达到稳定点,所述MVB树进行磁盘提交,生成所述修改版本的根节点哈希值。
  6. 如权利要求5所述的多版本数据存储方法,其中,所述若所述事务达到稳定点,所述MVB树进行磁盘提交,生成所述修改版本的根节点哈希值,包括:
    计算所述修改版本的根节点哈希值;
    根据预设写入规则将所述修改版本的脏节点写入磁盘中,并将所述修改版本的根节点设置为所述MVB树的根节点。
  7. 如权利要求6所述的多版本数据存储方法,其中,所述计算所述修改版本的根节点哈希值,包括:
    获取修改后的第二树节点数据;
    根据预设节点分裂方法对所述修改后的第二树节点数据进行分裂处理,生成分裂后的第二树节点数据;
    计算所述分裂后的第二树节点数据的第二次级节点的哈希值,所述第二次级节点为所述修改版本的根节点的子节点;
    若存在不处于所述索引路径的次级节点,根据所述次级节点的哈希值和所述第二次级节点的哈希值计算所述修改版本的根节点哈希值,所述次级节点为所述修改版本的根节点的子节点。
  8. 如权利要求7所述的多版本数据存储方法,其中,所述根据预设节点分裂方法对所述修改后的第二树节点数据进行分裂处理,生成分裂后的第二树节点数据,包括:
    判断指定叶子节点的键值对列表长度是否超出预设阈值;
    若指定叶子节点的键值对列表长度超出预设阈值,则将所述指定叶子节点分裂为若干个键值对列表长度不超出所述预设阈值的分裂节点;
    计算各个所述分裂节点的哈希值,并将所述各个所述分裂节点对应的键值对列表第一个键值插入到所述分裂节点的父节点中。
  9. 如权利要求7所述的多版本数据存储方法,其中,所述计算所述分裂后的第二树节点数据的第二次级节点的哈希值,包括:
    根据所述第二次级节点的子节点计算所述第二次级节点的哈希值,若所述第二次级节点的子节点为叶子节点,根据所述叶子节点内存储的键值对计算所述叶子节点的哈希值;
    根据所述第二次级节点的子节点计算所述第二次级节点的哈希值,若所述第二次级节点的子节点为非叶子节点,根据所述非叶子节点的子节点的哈希值计算所述非叶子节点的哈希值。
  10. 如权利要求6所述的多版本数据存储方法,其中,所述预设写入规则包括:
    非叶子节点存储于单文件中,存储方式为缓存IO;
    叶子节点存储于多文件中,存储方式为直接IO。
  11. 如权利要求1所述的多版本数据存储方法,其中,所述接收对MVB树的指定节点数据的修改指令之前,还包括:
    新建事务;
    根据所述事务生成所述修改指令。
  12. 如权利要求2或3所述的多版本数据存储方法,其中,所述根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本之后,还包括:
    当所述修改指令所属的事务结束时,接收特定数据的证明请求;
    生成所述特定数据的默克尔证明,所述默克尔证明包括所述特定数据的数据节点以及所述修改版本的根节点的节点路径;
    根据所述默克尔证明计算所述特定数据的验证哈希值;
    当所述验证哈希值与所述根节点哈希值相等时,判定所述特定数据存储于所述MVB树中。
  13. 一种多版本数据存储装置,其中,包括:
    接收指令模块,用于接收对MVB树的指定节点数据的修改指令;
    复制模块,用于复制所述指定节点数据索引路径上的第一树节点数据,获得复制后的第二树节点数据;
    修改模块,用于根据所述修改指令对所述第二树节点数据进行修改,根据不处于所述索引路径的节点数据和修改后的所述第二树节点数据生成所述MVB树的修改版本。
  14. 如权利要求13所述的多版本数据存储装置,其中,还包括:
    稳定点判断模块,用于当所述修改指令所属的事务结束时,判断所述事务是否达到稳定点;
    内存提交模块,用于若所述事务未达到稳定点,所述MVB树进行内存提交,生成所述修改版本的根节点哈希值。
  15. 如权利要求14所述的多版本数据存储装置,其中,内存提交模块包括:
    第一次级节点计算单元,用于计算修改后的第二树节点数据的第一次级节点的哈希值,所述第一次级节点为所述修改版本的根节点的子节点;
    第一根节点哈希值计算单元,用于若存在不处于所述索引路径的次级节点,根据所述次级节点的哈希值和所述第一次级节点的哈希值计算所述修改版本的根节点哈希值,所述次级节点为所述修改版本的根节点的子节点。
  16. 如权利要求15所述的多版本数据存储装置,其中,第一次级节点计算单元包括:
    第一叶子哈希计算单元,用于根据所述第一次级节点的子节点计算所述第一次级节点的哈希值,若所述第一次级节点的子节点为叶子节点,根据所述叶子节点内存储的键值对计算所述叶子节点的哈希值;
    第一非叶子哈希计算单元,用于根据所述第一次级节点的子节点计算所述第一次级节点的哈希值,若所述第一次级节点的子节点为非叶子节点,根据所述非叶子节点的子节点的哈希值计算所述非叶子节点的哈希值。
  17. 如权利要求13所述的多版本数据存储装置,其中,还包括:
    稳定点判断模块,用于当所述修改指令所属的事务结束时,判断所述事务是否达到稳定点;
    磁盘提交模块,用于若所述事务达到稳定点,所述MVB树进行磁盘提交,生成所述修改版本的根节点哈希值。
  18. 如权利要求17所述的多版本数据存储装置,其中,磁盘提交模块包括:
    磁盘根哈希单元,用于计算所述修改版本的根节点哈希值;
    磁盘写入单元,用于根据预设写入规则将所述修改版本的脏节点写入磁盘中,并将所述修改版本的根节点设置为所述MVB树的根节点。
  19. 一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机可读指令,其中,所述处理器执行所述计算机可读指令时实现如权利要求1至12中任一项所述多版本数据存储方法。
  20. 一个或多个存储有计算机可读指令的可读存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行如权利要求1至12中任一项所述多版本数据存储方法。
PCT/CN2020/139809 2020-12-22 2020-12-28 多版本数据存储方法、装置、计算机设备及存储介质 WO2022134128A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011532673.3A CN112579602B (zh) 2020-12-22 2020-12-22 多版本数据存储方法、装置、计算机设备及存储介质
CN202011532673.3 2020-12-22

Publications (1)

Publication Number Publication Date
WO2022134128A1 true WO2022134128A1 (zh) 2022-06-30

Family

ID=75138859

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/139809 WO2022134128A1 (zh) 2020-12-22 2020-12-28 多版本数据存储方法、装置、计算机设备及存储介质

Country Status (2)

Country Link
CN (1) CN112579602B (zh)
WO (1) WO2022134128A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116069788A (zh) * 2023-03-24 2023-05-05 杭州趣链科技有限公司 数据处理方法、数据库系统、计算机设备和存储介质
CN116627920A (zh) * 2023-07-24 2023-08-22 华能信息技术有限公司 一种基于工业互联网的数据存储方法

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114153848B (zh) * 2021-05-07 2024-06-28 支付宝(杭州)信息技术有限公司 区块链数据存储方法及装置、电子设备
CN112988912B (zh) * 2021-05-07 2021-11-02 支付宝(杭州)信息技术有限公司 区块链数据存储方法及装置、电子设备
CN112988909B (zh) * 2021-05-07 2021-09-28 支付宝(杭州)信息技术有限公司 区块链数据存储方法及装置、电子设备
CN114356927A (zh) * 2021-12-31 2022-04-15 杭州趣链科技有限公司 数据存储方法、装置、计算机设备和存储介质

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105868396A (zh) * 2016-04-19 2016-08-17 上海交通大学 内存文件系统的多版本控制方法
US20180189342A1 (en) * 2016-12-29 2018-07-05 EMC IP Holding Company LLC Method and system for tree management of trees under multi-version concurrency control
CN109325022A (zh) * 2018-07-20 2019-02-12 新华三技术有限公司 一种数据处理方法和装置
CN109992998A (zh) * 2019-03-31 2019-07-09 杭州复杂美科技有限公司 一种信息存储方法和系统、设备及存储介质
CN111324613A (zh) * 2020-03-13 2020-06-23 华东师范大学 一种面向联盟链的分片内数据组织管理方法
CN111444535A (zh) * 2020-03-20 2020-07-24 苏州链原信息科技有限公司 用于生成聚合数据标签的方法、设备及计算机存储介质
CN112035491A (zh) * 2020-09-30 2020-12-04 中山大学 基于区块链的数据存储方法、电子积分处理方法及系统

Family Cites Families (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100832222B1 (ko) * 2001-06-09 2008-05-23 자프 아게 메인 메모리 데이터베이스 시스템의 색인 구조를 위한캐쉬에 최적화된 동시성 제어방법
US8412689B2 (en) * 2010-07-07 2013-04-02 Microsoft Corporation Shared log-structured multi-version transactional datastore with metadata to enable melding trees
US8768977B2 (en) * 2012-07-31 2014-07-01 Hewlett-Packard Development Company, L.P. Data management using writeable snapshots in multi-versioned distributed B-trees
WO2014146240A1 (zh) * 2013-03-19 2014-09-25 华为技术有限公司 分布式存储系统的数据更新方法及服务器
CN109690522B (zh) * 2018-08-27 2024-02-27 袁振南 一种基于b+树索引的数据更新方法、装置及存储装置
CN110109927A (zh) * 2019-04-25 2019-08-09 上海新炬网络技术有限公司 基于LSM树的Oracle数据库数据处理方法
CN110688377B (zh) * 2019-08-30 2020-07-17 阿里巴巴集团控股有限公司 一种更新状态默克树的方法及装置
CN110602239B (zh) * 2019-09-20 2023-09-19 腾讯科技(深圳)有限公司 一种区块链信息存储方法及相关设备
CN111444542A (zh) * 2020-03-30 2020-07-24 陈兴芜 一种针对版权文件的数据处理方法、装置及存储介质
CN111475508B (zh) * 2020-03-31 2022-05-03 浙江大学 一种优化叶子节点合并操作的高效索引方法
CN111930309A (zh) * 2020-07-31 2020-11-13 中国人民解放军海军工程大学 基于数据分块技术的文件循环存储方法和装置

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105868396A (zh) * 2016-04-19 2016-08-17 上海交通大学 内存文件系统的多版本控制方法
US20180189342A1 (en) * 2016-12-29 2018-07-05 EMC IP Holding Company LLC Method and system for tree management of trees under multi-version concurrency control
CN109325022A (zh) * 2018-07-20 2019-02-12 新华三技术有限公司 一种数据处理方法和装置
CN109992998A (zh) * 2019-03-31 2019-07-09 杭州复杂美科技有限公司 一种信息存储方法和系统、设备及存储介质
CN111324613A (zh) * 2020-03-13 2020-06-23 华东师范大学 一种面向联盟链的分片内数据组织管理方法
CN111444535A (zh) * 2020-03-20 2020-07-24 苏州链原信息科技有限公司 用于生成聚合数据标签的方法、设备及计算机存储介质
CN112035491A (zh) * 2020-09-30 2020-12-04 中山大学 基于区块链的数据存储方法、电子积分处理方法及系统

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116069788A (zh) * 2023-03-24 2023-05-05 杭州趣链科技有限公司 数据处理方法、数据库系统、计算机设备和存储介质
CN116069788B (zh) * 2023-03-24 2023-06-20 杭州趣链科技有限公司 数据处理方法、数据库系统、计算机设备和存储介质
CN116627920A (zh) * 2023-07-24 2023-08-22 华能信息技术有限公司 一种基于工业互联网的数据存储方法
CN116627920B (zh) * 2023-07-24 2023-11-07 华能信息技术有限公司 一种基于工业互联网的数据存储方法

Also Published As

Publication number Publication date
CN112579602A (zh) 2021-03-30
CN112579602B (zh) 2023-06-09

Similar Documents

Publication Publication Date Title
WO2022134128A1 (zh) 多版本数据存储方法、装置、计算机设备及存储介质
US11693830B2 (en) Metadata management method, system and medium
US11442961B2 (en) Active transaction list synchronization method and apparatus
CN112559529B (zh) 数据存储方法、装置、计算机设备及存储介质
US10331641B2 (en) Hash database configuration method and apparatus
WO2017201977A1 (zh) 一种数据写、读方法、装置及分布式对象存储集群
WO2020093501A1 (zh) 文件存储方法、删除方法、服务器及存储介质
CN109446114B (zh) 一种空间数据缓存方法、装置和存储介质
CN110134335B (zh) 一种基于键值对的rdf数据管理方法、装置及存储介质
WO2021051782A1 (zh) 区块链的共识方法、装置及设备
WO2020041950A1 (zh) 一种基于b+树索引的数据更新方法、装置及存储装置
WO2016192057A1 (zh) 索引表的更新方法和设备
CN112785408A (zh) 基于哈希的对账方法及装置
Henry Howard chu on lightning memory-mapped database
CN101763433A (zh) 一种数据存储系统及方法
WO2015055035A1 (zh) 一种对元数据对象进行散列的方法及装置
CN115952195A (zh) 一种区块链数据溯源查询优化方法
WO2016175880A1 (en) Merging incoming data in a database
CN112764662B (zh) 用于存储管理的方法、设备和计算机程序产品
US10073657B2 (en) Data processing apparatus, data processing method, and computer program product, and entry processing apparatus
CN115794819A (zh) 一种数据写入方法及电子设备
CN113625938B (zh) 一种元数据存储方法及其设备
WO2020238750A1 (zh) 数据处理方法、装置、电子设备及计算机存储介质
US11669570B2 (en) Amortized execution of updates to a hardened hash table
KR20230083479A (ko) 블록체인 시뮬레이션 플랫폼 내의 복수의 가상 노드 사이에 공유된 데이터 액세스 방법 및 이를 이용하는 블록체인 시뮬레이션 플랫폼

Legal Events

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

Ref document number: 20966690

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20966690

Country of ref document: EP

Kind code of ref document: A1