Movatterモバイル変換


[0]ホーム

URL:


CN109690522B - Data updating method and device based on B+ tree index and storage device - Google Patents

Data updating method and device based on B+ tree index and storage device
Download PDF

Info

Publication number
CN109690522B
CN109690522BCN201880002420.XACN201880002420ACN109690522BCN 109690522 BCN109690522 BCN 109690522BCN 201880002420 ACN201880002420 ACN 201880002420ACN 109690522 BCN109690522 BCN 109690522B
Authority
CN
China
Prior art keywords
nodes
tree
node
data
physical
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN201880002420.XA
Other languages
Chinese (zh)
Other versions
CN109690522A (en
Inventor
袁振南
简怀兵
朱阅岸
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Quliantong Network Co ltd
Original Assignee
Quliantong Network Co ltd
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 Quliantong Network Co ltdfiledCriticalQuliantong Network Co ltd
Publication of CN109690522ApublicationCriticalpatent/CN109690522A/en
Application grantedgrantedCritical
Publication of CN109690522BpublicationCriticalpatent/CN109690522B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Classifications

Landscapes

Abstract

The application discloses a data updating method, a device and a storage device based on a B+ tree index, wherein the method modifies data by using a copy-on-write mode, and the method comprises the following steps: the method comprises the steps that nodes of data to be updated are obtained, wherein the nodes comprise physical nodes and virtual nodes, the physical nodes represent a physical memory address, and the virtual nodes represent a B+ tree node; copying the data to be updated into a new physical memory, and modifying the data in the new physical memory to form a new physical memory address; modifying the mapping table to enable the virtual node to point to a new physical memory address to form a new physical node; wherein the mapping table comprises a mapping of virtual nodes to physical nodes. By means of the method, the CoW B+ tree cascade CoW operation can be eliminated, and overhead is reduced.

Description

Data updating method and device based on B+ tree index and storage device
Technical Field
The present invention relates to the field of software technologies, and in particular, to a method and an apparatus for updating data based on a b+ tree index, and a storage device.
Background
Copy-on-Write (CoW) b+ tree (b+ -tree) technology is widely used in computer software, such as Btrfs (Butter FS) file system and LMDB (LMDB) Database. The CoW technique is a means to implement multi-version concurrency control, where a write operation triggers the system to generate a new version of data, while a read operation is still performed on the latest version that is currently completed. The read-write operation is performed on data of different versions, the read operation is not required to be blocked, and the efficiency is improved. Referring to fig. 1, fig. 1 is a schematic diagram of a read-write operation of copy-on-write in the prior art, if a process P1 needs to modify a leaf node C, it will not directly modify data on the data page C, but will copy a new data page C ', and then the process P1 modifies data on C'. In this case, the read-write operations do not conflict with each other, and locking is not needed. In long-term research, the inventor of the application finds that the method has certain disadvantages: first, the cost of such modifications is relatively large, and the modification of the leaf node may be propagated all the way up to the root node of the tree. As shown in FIG. 1, modification of leaf node C causes the CoW action to proceed along the path to root node A (C- - - > B- - - > A). Second, the CoW b+ tree performs a swiping action after the pointer modification is completed at the transaction commit time, which results in serious write amplification and random IO problems. Third, to minimize the cost of such copy-on-write, the CoW b+ tree does not link leaf nodes, which is very unfriendly to range finding.
Disclosure of Invention
The technical problem to be solved mainly by the application is to provide a data updating method, device and storage device based on B+ tree index, which can eliminate cascade operation of CoW B+ tree during updating and modifying, and reduce cost.
In order to solve the technical problems, one technical scheme adopted by the application is as follows: there is provided a data updating method based on a b+ tree index, wherein the method modifies data by means of copy-on-write, the method comprising: the method comprises the steps that nodes of data to be updated are obtained, wherein the nodes comprise physical nodes and virtual nodes, the physical nodes represent a physical memory address, and the virtual nodes represent a B+ tree node; copying the data to be updated into a new physical memory, and modifying the data in the new physical memory to form a new physical memory address; modifying the mapping table to enable the virtual node to point to a new physical memory address to form a new physical node; wherein the mapping table comprises a mapping of virtual nodes to physical nodes.
In order to solve the technical problems, one technical scheme adopted by the application is as follows: there is provided a data updating apparatus based on a b+ tree index, wherein the apparatus modifies data by means of copy-on-write, the apparatus comprising: the system comprises an acquisition module, a data updating module and a data updating module, wherein the acquisition module is used for acquiring nodes of data to be updated, the nodes comprise physical nodes and virtual nodes, the physical nodes represent a physical memory address, and the virtual nodes represent a B+ tree node; the updating module is used for copying the data to be updated into a new physical memory, and modifying the data in the new physical memory to form a new physical memory address; the mapping table modifying module is used for modifying the mapping table to enable the virtual node to point to a new physical memory address so as to form a new physical node; wherein the mapping table comprises a mapping of virtual nodes to physical nodes.
In order to solve the technical problems, another technical scheme adopted by the application is as follows: the data updating device based on the B+ tree index is provided, wherein the device modifies data in a copy-on-write mode, the device comprises a processor, the processor is used for acquiring nodes of the data to be updated, the nodes comprise physical nodes and virtual nodes, the physical nodes represent a physical memory address, and the virtual nodes represent a B+ tree node; the processor is also used for copying the data to be updated into a new physical memory, and modifying the data in the new physical memory to form a new physical memory address; the processor is further configured to modify the mapping table to enable the virtual node to point to a new physical memory address to form a new physical node; wherein the mapping table comprises a mapping of virtual nodes to physical nodes.
In order to solve the technical problems, another technical scheme adopted by the application is as follows: an apparatus having a storage function is provided, wherein the apparatus stores a program that when executed implements the above-described b+ tree index-based data updating method.
The beneficial effects of this application are: compared with the prior art, the method, the device and the storage device for updating the data based on the B+ tree index are provided, and the mapping table is added in the B+ tree index to map the physical nodes to the virtual nodes, so that the atomicity of modification of a plurality of references of a page can be ensured, and cascade operation of the CoW B+ tree during updating and modification can be eliminated, and the cost is reduced.
Drawings
FIG. 1 is a schematic diagram of a read-write operation of copy-on-write in the prior art;
FIG. 2 is a flow chart of a first embodiment of a data update method based on a B+ tree index according to the present application;
FIG. 3 is a flowchart of a second embodiment of a data update method based on a B+ tree index according to the present application;
fig. 4 is a schematic structural diagram of a first embodiment of a data updating apparatus based on b+ tree index according to the present application;
fig. 5 is a schematic structural diagram of a second embodiment of a data updating apparatus based on b+ tree index according to the present application;
fig. 6 is a schematic structural diagram of a first embodiment of a device with a memory function according to the present application.
Detailed Description
In order to make the objects, technical solutions and effects of the present application clearer and more specific, the present application will be further described in detail below with reference to the accompanying drawings and examples.
The application provides a data updating method, a device and a storage device based on a B+ tree index, wherein a CoW mechanism is used during data updating, the effect of no conflict between reading and writing is achieved, a mapping table is introduced during construction of the B+ tree index, the mapping table maps physical nodes to virtual nodes, atomicity of modification of multiple references of pages can be ensured, cascade operation of the CoW B+ tree during updating and modification can be eliminated, and cost is reduced.
Referring to fig. 2, fig. 2 is a flowchart illustrating a first embodiment of a data updating method based on b+ tree index according to the present application; in this embodiment, the method comprises the steps of:
s201: nodes requiring updated data are acquired.
The nodes comprise physical nodes and virtual nodes, wherein the physical nodes represent a physical memory address, and the virtual nodes represent a B+ tree node.
Specifically, a b+ tree is a balanced search tree designed for disk or other direct access secondary storage devices, preferably in terms of reducing disk I/O operands, and comprises a root node, an internal node, and leaf nodes, which may be a leaf node, or a node comprising two or more leaf nodes, as is commonly used in database and operating system file systems.
S202: and copying the data to be updated into a new physical memory, and modifying the data in the new physical memory to form a new physical memory address.
The method adopts the copy-on-write technology to modify and update the data, and can achieve the effect of no conflict between reading and writing through the copy-on-write technology. Specifically, the basic idea of copy-on-write is that if multiple callers (callers) request the same resource at the same time, they will commonly get the same index to point to the same resource, and until a caller (caller) attempts to modify the resource, the system will actually copy a copy (private copy) to the caller, so as to avoid the modified resource being directly perceived, which is transparent to other callers.
In other words, different processes in the virtual space (virtual node) point to the same physical space (physical node, memory area), when the behavior of changing the corresponding segment occurs in the process, the physical space is allocated to the corresponding segment of the process, and then the data is modified in the new physical space.
S203: modifying the mapping table to enable the virtual node to point to a new physical memory address to form a new physical node; wherein the mapping table comprises a mapping of virtual nodes to physical nodes.
The internal nodes of the B+ tree have no pointer pointing to specific information of the keywords, so that the internal nodes are smaller, if keywords of all the same internal nodes are stored in the same disk block, the more the number of the keywords which can be contained in the disk block is, the more the keywords which need to be searched in the memory are read at one time, and the relatively lower the IO read-write times, so that the disk read-write cost of the B+ tree is lower. Meanwhile, since the non-terminal node of the B+ tree is not the node which finally points to the file content, but is only the index of the key words in the leaf nodes, any key word search must take a path from the root node to the leaf nodes, and the path length of all key word queries is the same, so that the query efficiency of each data is equivalent, and the query efficiency of the B+ tree is more stable.
However, the copy-on-write b+ tree index is not friendly to the update operation because the CoW action can propagate up from the leaf node to the root node, and in addition, the random IO cost-effectiveness incurred in this process is large. In order to overcome the defects of the existing CoW B+ tree, a Mapping Table (Mapping Table) is added in the B+ tree index, and the Mapping Table comprises Mapping from virtual nodes to physical nodes, so that when the physical address of a data page is changed, only the corresponding entry in the Mapping Table needs to be changed, and only the Mapping relation between the virtual nodes and the physical nodes in the Mapping Table needs to be modified. The influence of data page change can be limited on a specific page by using the Mapping table, the cascade CoW phenomenon is avoided, the updating operation is accelerated, and the random IO is reduced.
In one embodiment, the method includes creating a tree index, where the tree index includes a mapping table and a b+ tree; the mapping table comprises the mapping from the virtual node to the physical node; the physical nodes represent a physical memory address and the virtual nodes are constructed to form a b+ tree. Because the mapping table isolates the physical address and the B+ tree node, the modification of the physical node does not affect the virtual node, so that the modification of the physical page caused by the CoW does not affect other pages, is atomic, and does not need to propagate the modification of the leaf to the root of the tree. However, the physical address Ptr corresponding to the page ID in the Mapping table changes with the change of the page.
In one embodiment, virtual nodes are linked by a logical link in the b+ tree index of the method. This is because the introduction of the mapping table eliminates the defect that the CoW action propagates along the path to the root node, affecting the entire index. Therefore, the leaf nodes can be linked together, and range finding and merging and splitting operations are better supported.
In one embodiment, the method can be used for modifying index page data, and can also be used for modifying a data structure of a tree, such as splitting a node or merging nodes. These modification operations all employ CoW technology.
Wherein, in one embodiment, the old physical node is reclaimed after modification is completed. Specifically, the Latch-free environment does not allow exclusive access to a shared data structure, that is, pages can be accessed even if they are being modified. We do not want to free a memory that is still being accessed. For example, at the time of solidification, threads swap old pages and new page states and reclaim the new states, but release when threads no longer access old pages. The reclamation mechanism is to protect previously accessed and released objects.
Referring to fig. 3, fig. 3 is a flowchart illustrating a second embodiment of a data updating method based on b+ tree index according to the present application; in one application scenario, the method comprises the steps of:
and establishing a tree index, wherein the tree index comprises a mapping table and a B+ tree, the mapping table comprises mapping (solid line pointer in the figure) from a virtual node (ID) to a physical node (Ptr), the physical node (Ptr) represents a physical memory address, and the virtual node (ID) is constructed to form the B+ tree. A B+ tree contains root nodes, internal nodes and leaf nodes, each node is composed of a combination of Pointer (P) data pairs (dotted pointers in the figure), key (Key, K) and file addresses represented by the Key, and a node is stored on a disk block.
When the page data modification or the tree structure modification is needed, the original page is copied and copied, then the modification is carried out on a new page, and after the modification, the new address is put into the page physical address column of the mapping table to form a new physical address.
When a CoW transaction needs to modify a record, it first looks for Leaf nodes that are located to the grey box. Specifically, from the root node, the root node information is read, a given keyword is searched in keywords K1, … … and Kn contained in the root node, and if the keyword which is equal to the given value is found, the search is successful; otherwise, it can be determined that the keyword to be searched is between Ki and Kj, and at this time, the node pointed by the pointer Pi is taken to continue searching (Pi is the pointer pointing to the root node of the subtree) until the keyword is found.
Then the transaction copies the corresponding leaf node to be output and carries out corresponding modification; after the modification is completed, the physical address Ptr is pointed to the internal memory address of the page where the modification is completed; thus, the subsequent operations access the page after the modification is completed. While gray pages wait to be reclaimed after all access operations are completed. In the embodiment, the cascade CoW problem of the original Copy-on-Write B+ tree can be eliminated by a layer of indirect layer Mapping table device, and the problems of Write amplification and random IO are reduced.
Based on the foregoing method, the present application further provides a data updating device based on a b+ tree index, referring to fig. 4, fig. 4 is a schematic structural diagram of a first embodiment of the data updating device based on a b+ tree index, in this embodiment, the device modifies data by using a copy-on-write manner, the device 40 includes a processor 401, the processor 401 is configured to obtain nodes of data to be updated, the nodes include physical nodes and virtual nodes, the physical nodes represent a physical memory address, and the virtual nodes represent a b+ tree node. The processor 401 is further configured to copy the data to be updated to a new physical memory, and modify the data in the new physical memory to form a new physical memory address. The processor 401 is further configured to modify the mapping table to enable the virtual node to point to a new physical memory address, thereby forming a new physical node; wherein the mapping table comprises a mapping of virtual nodes to physical nodes.
Wherein, in an embodiment, the processor 401 is further configured to build a tree index, where the tree index includes a mapping table and a b+ tree; the mapping table comprises the mapping from the virtual node to the physical node; the physical node represents a physical memory address and the virtual node is constructed to form the b+ tree.
In one embodiment, the processor 401 is further configured to associate virtual nodes through a logical link.
In one embodiment, the processor 401 is further configured to change the index page data or change the index tree structure.
In one embodiment, the processor 401 is further configured to perform node splitting or node merging on the tree structure.
Wherein in an embodiment the processor 401 is further configured to reclaim old physical nodes.
The data updating device based on the b+ tree index can be used for executing the data updating method based on the b+ tree index, and has the corresponding beneficial effects, and the specific process is described in the above embodiments and is not repeated herein. The device may be a stand-alone device independent of the background server, or may be a module or a processing unit in the server.
Referring to fig. 5, fig. 5 is a schematic structural diagram of a second embodiment of a b+ tree index-based data updating apparatus according to the present application, in this embodiment, the apparatus modifies data by using a copy-on-write method, and the apparatus 50 is a module in a processor, and specifically includes an obtaining module 501, an updating module 502, and a modifying mapping table module 503.
The acquiring module 501 is configured to acquire nodes of data to be updated, where the nodes include physical nodes and virtual nodes, the physical nodes represent a physical memory address, and the virtual nodes represent a b+ tree node.
The update module 502 is configured to copy the data to be updated into a new physical memory, and modify the data in the new physical memory to form a new physical memory address.
The modification mapping table module 503 is configured to modify the mapping table, so that the virtual node points to a new physical memory address to form a new physical node; wherein the mapping table comprises a mapping of virtual nodes to physical nodes.
Wherein, in an embodiment, the device further comprises a creating module, configured to create a tree index, where the tree index includes a mapping table and a b+ tree; the mapping table comprises the mapping from the virtual node to the physical node; the physical node represents a physical memory address and the virtual node is constructed to form the b+ tree.
In one embodiment, the update module 502 is further configured to change the index page data or change the index tree structure. The apparatus may be used to execute the above data updating method based on the b+ tree index, and the specific process is described in the above embodiment, and will not be described herein.
Referring to fig. 6, fig. 6 is a schematic structural diagram of a first embodiment of the device with storage function. In this embodiment, the storage device 60 stores a program 601, and the program 601 implements the data update method based on the b+ tree index described above when executed. The specific working process is identical to that of the above method embodiment, so that the detailed description thereof will be omitted herein, and the detailed description of the corresponding method steps will be referred to above. The device having the storage function may be a portable storage medium such as a U-disk, an optical disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or the like, or may be a terminal, a server, or the like.
According to the scheme, the data updating method based on the B+ tree index is provided, and the mapping table is introduced when the B+ tree index is constructed, so that the physical nodes are mapped to the virtual nodes by the mapping table, the atomicity of modification of a plurality of references of a page can be ensured, the cascade CoW operation of the CoW B+ tree can be eliminated, and the cost is reduced.
In the several embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the modules or units is merely a logical functional division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist alone physically, or two or more units may be integrated into one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be embodied in essence or a part contributing to the prior art or all or part of the technical solution, in the form of a software product stored in a storage medium, including several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of the methods described in the embodiments of the present application.
The foregoing description is only of embodiments of the present application, and is not intended to limit the scope of the patent application, and all equivalent structures or equivalent processes using the descriptions and the drawings of the present application or direct or indirect application in other related technical fields are included in the scope of the present application.

Claims (11)

CN201880002420.XA2018-08-272018-08-27Data updating method and device based on B+ tree index and storage deviceActiveCN109690522B (en)

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
PCT/CN2018/102555WO2020041950A1 (en)2018-08-272018-08-27Data update method, device, and storage device employing b+ tree indexing

Publications (2)

Publication NumberPublication Date
CN109690522A CN109690522A (en)2019-04-26
CN109690522Btrue CN109690522B (en)2024-02-27

Family

ID=66191858

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN201880002420.XAActiveCN109690522B (en)2018-08-272018-08-27Data updating method and device based on B+ tree index and storage device

Country Status (2)

CountryLink
CN (1)CN109690522B (en)
WO (1)WO2020041950A1 (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN111475508B (en)*2020-03-312022-05-03浙江大学 An Efficient Indexing Method for Optimizing Merge Operation of Leaf Nodes
CN112579602B (en)*2020-12-222023-06-09杭州趣链科技有限公司Multi-version data storage method, device, computer equipment and storage medium
CN112698956B (en)*2021-01-192024-04-12腾讯科技(深圳)有限公司Data object processing method, device, equipment and storage medium
US12117985B2 (en)2021-08-132024-10-15Samsung Electronics Co., Ltd.Host, storage system including the host, and operating method of the host
TWI789168B (en)*2021-12-162023-01-01威聯通科技股份有限公司File versioning management method and file system
CN115469810A (en)*2022-09-212022-12-13河南星环众志信息科技有限公司Data acquisition method, device, equipment and storage medium
CN115576868B (en)*2022-11-242023-03-03苏州浪潮智能科技有限公司Multi-level mapping framework, data operation request processing method and system
CN118467548B (en)*2024-07-122024-11-29杭州高新区(滨江)区块链与数据安全研究院 Database management method, system and storage medium based on tree structure

Citations (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN101425041A (en)*2007-10-302009-05-06安凯(广州)软件技术有限公司Optimizing method for establishing FAT file systems on NAND FLASH memory
CN105183915A (en)*2015-10-142015-12-23江苏师范大学Multi-version management method for reducing index maintenance overhead

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US6859808B1 (en)*2001-05-312005-02-22Oracle International CorporationMapping logical row identifiers for primary B+tree-like structures to physical row identifiers
US8412881B2 (en)*2009-12-222013-04-02Intel CorporationModified B+ tree to store NAND memory indirection maps
US9003162B2 (en)*2012-06-202015-04-07Microsoft Technology Licensing, LlcStructuring storage based on latch-free B-trees
CN103823865A (en)*2014-02-252014-05-28南京航空航天大学Database primary memory indexing method

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN101425041A (en)*2007-10-302009-05-06安凯(广州)软件技术有限公司Optimizing method for establishing FAT file systems on NAND FLASH memory
CN105183915A (en)*2015-10-142015-12-23江苏师范大学Multi-version management method for reducing index maintenance overhead

Also Published As

Publication numberPublication date
CN109690522A (en)2019-04-26
WO2020041950A1 (en)2020-03-05

Similar Documents

PublicationPublication DateTitle
CN109690522B (en)Data updating method and device based on B+ tree index and storage device
JP7410181B2 (en) Hybrid indexing methods, systems, and programs
US11080260B2 (en)Concurrent reads and inserts into a data structure without latching or waiting by readers
US9679003B2 (en)Rendezvous-based optimistic concurrency control
EP3117348B1 (en)Systems and methods to optimize multi-version support in indexes
US10067958B2 (en)Supporting transient snapshot with coordinated/uncoordinated commit protocol
JP6998928B2 (en) Methods, appliances, equipment, and media for storing and querying data
EP3170106B1 (en)High throughput data modifications using blind update operations
CN104021145B (en)The method and apparatus that a kind of mixed service concurrently accesses
US9501421B1 (en)Memory sharing and page deduplication using indirect lines
EP4137965A1 (en)Method and system for adaptively building and updating a column store database from a row store database based on query demands
US9922105B2 (en)Method and apparatus of maintaining data for online analytical processing in a database system
US10296497B2 (en)Storing a key value to a deleted row based on key range density
US11714794B2 (en)Method and apparatus for reading data maintained in a tree data structure
US10776344B2 (en)Index management in a multi-process environment
CN115344568A (en)Memory index mechanism processing method and device, electronic equipment and storage medium
CN111143232A (en)Method, apparatus and computer program product for storing metadata
US11347406B2 (en)Method, electronic device and computer program product for updating information
US20100131477A1 (en)Versioning file system
CN119396841A (en) Data management method and electronic device based on B+ tree

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp