Construction method and operation method of DRAM-NVM hybrid index structure

By adopting the design of the index layer, middle layer and data layer in the DRAM-NVM hybrid index structure, combined with the log persistence tree and caching mechanism, the problem of being unable to balance high read and write performance with fast fault recovery in the existing technology is solved, achieving for efficient data access and rapid recovery.

CN113590612BActive Publication Date: 2024-08-27HUAZHONG UNIV OF SCI & TECH +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110789870.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-13
Publication Date
2024-08-27
Estimated Expiration
2041-07-13

AI Technical Summary

Technical Problem

The existing DRAM-NVM hybrid media index structure cannot balance high read and write performance with fast fault recovery.

Method used

The construction method of the DRAM-NVM hybrid index structure is adopted, including the index layer, the middle layer and the data layer. The index layer and the middle layer are stored in DRAM. The data layer is composed of the log persistence tree LogTree, and the hot LogTree is cached in DRAM. , the middle layer is used to record access heat and perform backups to ensure rapid recovery in the event of system failure.

Benefits of technology

It improves the read and write performance of the index structure and greatly speeds up the fault recovery process while ensuring the read and write performance. It makes full use of the low latency and non-volatile characteristics of NVM to ensure efficient access and rapid recovery of data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113590612B
    Figure CN113590612B
Patent Text Reader

Abstract

The present invention discloses a construction method and an operation method of a DRAM-NVM hybrid index structure, wherein the constructed index structure comprises an index layer, an intermediate layer and a data layer; the index layer is stored in DRAM; the intermediate layer comprises metadata nodes, which are stored in DRAM and have a backup in NVM; the data layer comprises LogTree, which is a tree structure, the number of which is the same as the number of metadata nodes and corresponds one-to-one with the metadata nodes; in an initial state, LogTree is stored in NVM and is recorded as NvmTree; in a reading and writing process, a LogTree with an access heat greater than a preset access heat threshold is backed up and cached in DRAM to create a CacheTree; at this time, LogTree comprises NvmTree initially stored in NVM, CacheTree cached in DRAM and a log stored in NVM; the log is used to store a record of a write operation to CacheTree; the LogTree in the data layer is used to store a target keyword key and a pointer to value in a key-value pair written by a user; the present invention can greatly accelerate the process of fault recovery under the premise of ensuring the reading and writing performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of information storage technology, and more specifically, relates to a construction method and an operation method of a DRAM-NVM hybrid index structure. Background Art

[0002] Over the past decade, with the continuous development of computer and network technology, the scale of information data has exploded. The various storage devices in current computer systems vary greatly in performance, capacity, and persistence, which has a huge impact on the way data is stored. The index structure is the core component of modern databases. The changes in storage architecture and the characteristics of persistent memory have brought opportunities and challenges to the optimization of index structures. Therefore, it is of great significance to study an index structure.

[0003] The new non-volatile memory (NVM) has become an important storage device for building the next generation storage system because of its advantages such as byte addressability, non-volatility, low power consumption, high storage density, and performance close to DRAM. There are many existing index structures based on NVM or NVM and DRAM hybrid media, such as NovelLSM, Path Hash, NVTree, FPTree, etc. However, the existing index structures based on NVM or NVM and DRAM hybrid media cannot take into account both high read and write performance and fast fault recovery. Take FPTree as an example, which is a B+ tree index structure based on DRAM-NVM hybrid media. It persists leaf nodes in NVM and places intermediate nodes on DRAM. When recovering, it uses the persistent leaf nodes to rebuild the intermediate nodes in DRAM. The data inside the FPTree leaf node is arranged in disorder, and a 1B hash value is calculated for each keyword inside the leaf node as fingerprint data and stored in the same cache line. When querying, the location of the keyword is quickly located by scanning the fingerprint data. Although this structure can reduce the cache miss rate and improve query performance, the intermediate nodes of the B+ tree will be lost after the system loses power or fails. The intermediate nodes need to be rebuilt when the system recovers. When the amount of data is large, the recovery time is long, which affects the availability of the system. Summary of the invention

[0004] In view of the above defects or improvement needs of the prior art, the present invention provides a construction method and an operation method of a DRAM-NVM hybrid index structure to solve the technical problem that the prior art cannot take into account both high read and write performance and fast fault recovery.

[0005] In a first aspect, the present invention provides a method for constructing a DRAM-NVM hybrid index structure, including: constructing an index layer, an intermediate layer, and a data layer to obtain a DRAM-NVM hybrid index structure;

[0006] The index layer is a tree structure and is stored in DRAM; the middle layer includes one or more metadata nodes, which are stored in DRAM and have backups in NVM; and when there are multiple metadata nodes, each metadata node is connected front and back to form a linked list structure; the data layer includes a log persistence tree LogTree; LogTree is a tree structure, and its number is the same as the number of metadata nodes, and corresponds one to one with the metadata nodes; in the initial state, LogTree is stored in NVM and is recorded as NvmTree; during the reading and writing process, if the access heat of LogTree is greater than the preset access heat threshold, CacheTree is created by backing up LogTree and caching it in DRAM; at this time, LogTree includes NvmTree initially stored in NVM, CacheTree cached in DRAM, and log stored in NVM; wherein the log is used to store records of write operations to CacheTree;

[0007] The index layer is used to index the metadata nodes of the middle layer;

[0008] The middle layer is used to address the LogTree in the data layer and record the access popularity of each LogTree in the data layer; the metadata node in the middle layer includes the pointer to the CacheTree root node in the corresponding LogTree, the root node pointer of the NvmTree and the log pointer, as well as the access popularity of the corresponding LogTree;

[0009] LogTree in the data layer is used to store the target keyword key and the pointer to the value in the key-value pair written by the user.

[0010] Further preferably, the method for setting the preset access heat threshold includes:

[0011] The maximum capacity of the DRAM used to cache CacheTree is preset to M, the maximum storage capacity of CacheTree is preset to S, the first M / S access temperatures with the highest access heat of each LogTree in the data layer are obtained, and the minimum access heat among the first M / S access temperatures is used as the preset access heat threshold.

[0012] Further preferably, the index layer is a B+ tree; the LogTree is a B+ tree; when there are multiple metadata nodes, each metadata node is connected front and back to form a bidirectional linked list structure to improve traversal performance.

[0013] In a second aspect, a method for processing read and write requests of an index structure constructed by the method for constructing a DRAM-NVM hybrid index structure includes:

[0014] When a write request is received, the write operation is performed:

[0015] S11. Based on the target keyword key in the request, query the index layer, obtain the metadata node pointer corresponding to the target keyword key, determine the metadata node of the middle layer, and accumulate the access heat of the LogTree corresponding to the metadata node; allocate persistent space for the value in the request in NVM, and persist it to obtain a pointer to the value;

[0016] S12, determine whether the CacheTree in the LogTree corresponding to the metadata node is in the creation or synchronization operation of the CacheTree, if so, go to step S13; otherwise, go to step S14;

[0017] S13, write the target keyword key and the pointer to value into the log in the LogTree corresponding to the metadata node, and the operation ends;

[0018] S14, insert the target keyword key and the pointer pointing to value into the LogTree corresponding to the metadata node: determine whether there is a CacheTree in the LogTree corresponding to the metadata node. If so, insert the target keyword key and the pointer pointing to value into the CacheTree, and write the target keyword key and the pointer pointing to value into the log in the LogTree corresponding to the metadata node; otherwise, insert the target keyword key and the pointer pointing to value into the NvmTree;

[0019] When a read request is received, the read operation is performed:

[0020] S21. Based on the target keyword key in the request, query the index layer, obtain the metadata node pointer corresponding to the target keyword key, determine the metadata node of the middle layer, and accumulate the access heat of the LogTree corresponding to the metadata node;

[0021] S22, determine whether the CacheTree in the LogTree corresponding to the metadata node is in the creation or synchronization operation of the CacheTree, if so, go to step S23; otherwise, go to step S24;

[0022] S23, query the operation record corresponding to the target keyword key in the log in the LogTree corresponding to the metadata node. If it can be found, obtain the value through the pointer pointing to value in the operation record, and the operation ends; otherwise, go to step S24;

[0023] S24. Determine whether there is a CacheTree in the LogTree corresponding to the metadata node. If so, query the CacheTree based on the target keyword key to obtain a pointer to value, and obtain the value of value through the pointer to value; otherwise, query the NvmTree based on the target keyword key to obtain a pointer to value, and obtain the value of value through the pointer to value;

[0024] The synchronization operation of CacheTree includes: when the log size is larger than the preset log size, updating the NvmTree in the LogTree where the CacheTree is located to make it the same as the CacheTree.

[0025] Further preferably, the accumulated access heat of LogTree is:

[0026] HotDegree t+Δt =A*HotDegree t +Operate Δt

[0027] Among them, HotDegree t+Δt HotDegree is the access heat accumulated at the current time t+Δt; t is the access heat accumulated at the last moment t; Δt is the time difference between the current moment and the last moment; A is the proportional coefficient of the periodic decay of heat; Operate Δt is the number of read and write requests of LogTree within Δt time.

[0028] Further preferably, when the LogTree corresponding to the metadata node is a B+ tree, the write request processing method further includes: step S15 executed between step S12 and step S14;

[0029] Step S15 includes: when the LogTree root node is full and the height of the LogTree exceeds a preset height threshold, dynamically expanding the LogTree; specifically including:

[0030] S151, determine whether CacheTree exists in LogTree, if not, go to step S152; otherwise, go to step S153;

[0031] S152, dynamically expand the NvmTree in the LogTree: split the root node of the NvmTree in the LogTree into two new nodes, and record the LogTree before the split as the original LogTree; the split position m is the result of rounding down half of the number of keywords in the root node of the NvmTree; the new node composed of the first m keywords in the root node of the NvmTree is recorded as the first new node, and the new node composed of the remaining keywords is recorded as the second new node; the split keyword is the m+1th keyword in the root node of the NvmTree; create a new LogTree with the same structure as the original LogTree at the data layer, and use the second new node as the NvmTree in the new LogTree. ree's root node; replace the root node of the NvmTree in the original LogTree with the first new node, and modify the pointer information in the metadata node corresponding to the original LogTree accordingly; create a new metadata node in the middle layer, insert the new metadata node between the metadata node corresponding to the original LogTree and its next metadata node, corresponding to the new LogTree; insert the key-value pair consisting of the split keyword and the pointer pointing to the new metadata node into the tree structure of the index layer to form a new node in the index layer; wherein the left pointer of the new node in the index layer points to the metadata node corresponding to the original LogTree, and the right pointer points to the new metadata node corresponding to the new LogTree;

[0032] S153, synchronize the dirty data of CacheTree in LogTree back to NvmTree in LogTree, and record the write operation request to LogTree in the synchronization process in the log of LogTree; dynamically expand CacheTree and NvmTree in LogTree respectively according to the method described in step S152, and record the LogTree before dynamic expansion as the original LogTree; copy the newly added records in the log of the original LogTree to the two LogTrees after the dynamic expansion is completed.

[0033] Further preferably, the access heat of the two LogTrees after dynamic expansion is HotDegree, HotDegree=ηHotDegree0; wherein HotDegree0 is the access heat of the LogTree before dynamic expansion; η is the proportionality coefficient, 0<η<1.

[0034] Further preferably, the copy-on-write technology is used for NvmTree in LogTree to perform write operations greater than 8B to ensure data consistency.

[0035] In a third aspect, a fault recovery method for an index structure constructed by the method for constructing the above-mentioned DRAM-NVM hybrid index structure is used to perform fault recovery when the system where the index structure is located loses power or fails to ensure that normal operation and service can be provided, including the following steps:

[0036] 1) Restoration of the middle layer: traverse the metadata nodes of the middle layer backed up in NVM, determine whether there is data overlap in the NvmTree root nodes of the LogTree corresponding to adjacent metadata nodes, and if there is data overlap, split the NvmTree root nodes with data overlap, and correct the pointer information in the corresponding metadata nodes to ensure that the middle layer is restored to a consistent state, and then rebuild the metadata nodes of the middle layer on DRAM;

[0037] 2) LogTree recovery: If the power failure or failure does not occur during the synchronization or elimination of CacheTree, the CacheTree is constructed by backing up the NvmTree in the LogTree to DRAM, and then all operations from the start address of the log space to the current allocated address are played back to the CacheTree in order by scanning the log in the LogTree, so that it can be restored to the state before the data loss; if the power failure or failure occurs during the synchronization or elimination of the CacheTree, the NvmTree in the LogTree will be in an inconsistent state, and the CacheTree will be rebuilt using the consistent leaf nodes of the NvmTree, and then the LogTree will be scanned. e, and replay all operations from the starting address of the log space to the current allocated address in order into the CacheTree; wherein, the synchronization operation of the CacheTree includes: when the log size is larger than the preset log size, updating the NvmTree in the LogTree where the CacheTree is located to make it the same as the CacheTree; the elimination operation of the CacheTree includes: when the access heat of the LogTree where the CacheTree is located is less than the preset access heat threshold, after executing the synchronization operation of the CacheTree, releasing all nodes in the CacheTree, deleting the log of the LogTree where the CacheTree is located, and reclaiming the log space;

[0038] 3) Recovery of the index layer: Recreate a tree structure in DRAM, then traverse the metadata nodes in the middle layer, and insert the key-value pairs consisting of the pointer to the metadata node and the minimum keyword of the LogTree corresponding to the metadata node into the above tree structure in sequence.

[0039] In a fourth aspect, the present invention also provides a machine-readable storage medium, wherein the machine-readable storage medium stores machine executable instructions, and when the machine executable instructions are called and executed by a processor, the machine executable instructions prompt the processor to implement any one of the DRAM-NVM hybrid index structure construction methods described above, the read and write request processing method of the index structure constructed by the DRAM-NVM hybrid index structure construction method described above, and / or the fault recovery method of the index structure constructed by the DRAM-NVM hybrid index structure construction method described above.

[0040] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects:

[0041] 1. The present invention provides a method for constructing a DRAM-NVM hybrid index structure, including an index layer, an intermediate layer and a data layer. The index layer and the intermediate layer are both placed in DRAM. The intermediate layer is used to connect the index layer and the data layer and screen the hot data in the data layer. The data layer is composed of a large number of smaller log persistence trees LogTree. The LogTree is placed in NVM, and the LogTree with higher popularity is cached in DRAM, which greatly improves the read and write performance of the index structure. At the same time, the present invention caches the records of CacheTree write operations in a log manner. When the LogTree corresponding to the metadata node has a CacheTree in DRAM, the storage CacheTree of the data in the write request can be directly saved in the log at the same time, and the CacheTree is directly accessed to obtain the corresponding data during the read request, which greatly improves the read and write performance. In addition, since the CacheTree has a backup in the NVM, and its modifications are recorded in the form of logs, the intermediate layer also has a backup on the NVM, which reduces the blocking of the foreground service during the expansion process and speeds up the fault recovery process. Therefore, the present invention can greatly speed up the fault recovery process under the premise of ensuring the read and write performance.

[0042] 2. The construction method of the DRAM-NVM hybrid index structure provided by the present invention is designed based on the idea of ​​key-value separation. Only the key and value pointers of the key-value pair are saved in the index structure, and the real value is stored and managed by the NVM space management module. It can make full use of the NVM byte addressing and the characteristics of random performance and sequential performance, and perform random access to the value. When ensuring that the data is in order, it is only necessary to sort the key and value pointers in the index structure without moving the value itself, thereby reducing the expensive reordering overhead.

[0043] 3. The method for constructing the DRAM-NVM hybrid index structure provided by the present invention caches the records of the read and write operations of CacheTree through logs, thereby ensuring the reliability of the LogTree write request data cached in DRAM.

[0044] 4. The method for constructing the DRAM-NVM hybrid index structure provided by the present invention can give full play to the advantages of NVM's low latency, non-volatility, and byte addressing, ensuring efficient access, rapid recovery, and persistence of data.

[0045] 5. The present invention provides a method for processing read and write requests of an index structure constructed by the above-mentioned method for constructing a DRAM-NVM hybrid index structure. When a CacheTree exists in the DRAM for the LogTree corresponding to the metadata node, the data in the write request can be directly stored in the CacheTree and saved in the log at the same time. In addition, the CacheTree can be directly accessed to obtain the corresponding data during a read request, thereby greatly improving the read and write performance.

[0046] 6. The present invention provides a power failure or fault recovery method for the index structure constructed by the construction method of the above-mentioned DRAM-NVM hybrid index structure. The CacheTree is backed up in the NVM, and its modifications are recorded in the form of logs. The middle layer is also backed up on the NVM. Since the middle layer is actually equivalent to the leaf node of the index layer tree, the index layer is equivalent to the middle node of the tree. After the leaf node is restored, the middle node is restored, and the fault recovery process will be very fast. At the same time, it is noted that after the middle layer fault recovery, there is no keyword overlap between LogTrees, and the recovery of CacheTrees in different LogTrees can be executed concurrently. Therefore, the recovery of LogTree can be performed in a multi-threaded task queue manner, and the system fault recovery time will be further reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 A schematic diagram of a DRAM-NVM hybrid index structure provided in Example 1 of the present invention;

[0048] Figure 2 The tree structure of the index layer provided in Embodiment 1 of the present invention;

[0049] Figure 3 A schematic diagram of the structure of a metadata node in the middle layer provided by Embodiment 1 of the present invention;

[0050] Figure 4 A schematic diagram of the structure of a CacheTree node provided in Example 1 of the present invention;

[0051] Figure 5A schematic diagram of a log structure provided by Embodiment 1 of the present invention;

[0052] Figure 6 A flowchart of a method for processing read and write requests provided in Embodiment 2 of the present invention;

[0053] Figure 7 A schematic diagram of the synchronization process of CacheTree provided in Embodiment 2 of the present invention;

[0054] Figure 8 A schematic diagram of the LogTree dynamic expansion process provided by Example 2 of the present invention;

[0055] Fig. 9 A schematic diagram of NvmTree data insertion consistency provided by Embodiment 2 of the present invention;

[0056] Fig.10 A schematic diagram of the consistency of the synchronization process provided by Embodiment 2 of the present invention;

[0057] Fig.11 A schematic diagram of metadata node insertion consistency provided in Example 3 of the present invention. DETAILED DESCRIPTION

[0058] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0059] Embodiment 1,

[0060] A method for constructing a DRAM-NVM hybrid index structure includes: constructing an index layer, an intermediate layer, and a data layer to obtain a DRAM-NVM hybrid index structure; specifically, Figure 1As shown, the index layer is a tree structure, preferably a B+ tree, stored in DRAM; the middle layer includes one or more metadata nodes, which are stored in DRAM and have a backup in NVM; and when there are multiple metadata nodes, each metadata node is connected front and back to form a linked list structure, preferably a bidirectional linked list structure; the data layer includes a log persistence tree LogTree; LogTree is a tree structure, preferably a B+ tree, the number of which is the same as the number of metadata nodes, and corresponds one to one with the metadata nodes; in the initial state, LogTree is stored in NVM, recorded as NvmTree; during the reading and writing process, if the access heat of LogTree is greater than the preset access heat threshold, CacheTree is created by backing up LogTree and caching it in DRAM; at this time, LogTree includes NvmTree initially stored in NVM, CacheTree cached in DRAM and log stored in NVM; wherein the log is used to store records of write operations on CacheTree.

[0061] The index layer is used to index the metadata nodes of the middle layer. The data will be lost after the system loses power, but it can be restored through the persistent middle layer and data layer. Since the index layer is only used to find the metadata nodes of the middle layer and does not save key value data, it is only composed of middle nodes, and the lowest middle node points to the metadata node in the middle layer. Preferably, the tree structure of the index layer is a B+ tree, which can efficiently query the corresponding data; specifically, Figure 2 As shown; taking the metadata node where the query keyword 35 is located as an example, the search starts from the root node, and after comparison with the root node keyword 50, the middle node on the left of the next layer is located, and then compared with the keywords 20 and 30 in the middle node, the metadata node corresponding to the keyword 35 is located.

[0062] The middle layer is used to address the LogTree in the data layer and record the access popularity of each LogTree in the data layer; specifically, Figure 3 As shown, the metadata node in the middle layer includes a pointer to the CacheTree root node in the corresponding LogTree, a pointer to the root node of the NvmTree and a pointer to the log, as well as the access heat data of the corresponding LogTree. Each time a metadata node is accessed, heat data is accumulated for the corresponding LogTree to mark the hotness or coldness of the LogTree. In order to reduce the write overhead to the NVM node, the heat data does not need to be synchronized after each change, and periodic synchronization is sufficient. In addition, the metadata node also contains information such as the predecessor node pointer and the successor node pointer required to form a bidirectional linked list.

[0063] The LogTree in the data layer is used to store the target keyword key and the pointer to the value in the key-value pair written by the user. The LogTree with access heat greater than the preset access heat threshold is divided into the NvmTree in NVM and the cache CacheTree in DRAM; the CacheTree caches the heat data of the LogTree. Figure 4 As shown in the figure, the nodes of CacheTree are divided into two parts: header metadata and record data, and the current level is used to distinguish whether it is an intermediate node or a leaf node. The header metadata saves the basic information of the current node, including the leftmost pointer, the number of records, the number of levels, the node status and the NVM address; among them, the number of records indicates the number of records owned by the current node; the level of the leaf node is marked as 0, and from the leaf node upwards, the level of the intermediate node increases successively, and the root node has the highest level; the leftmost pointer of the intermediate node points to the first node of the next level of the node, and the leftmost pointer of the leaf node acts as a sibling node, connecting the leaf nodes in series for easy range query; the node status is used to mark the modification status of the CacheTree node, which is a clean node if it is not modified and a dirty node if it is modified; the NVM address records the offset position of the NvmTree node corresponding to the CacheTree node in the NVM, which is convenient for writing dirty node data back to the NVM. The NvmTree structure is consistent with the CacheTree structure, so it will not be repeated here.

[0064] In addition, the data layer also includes a log structure to ensure the data reliability of the LogTree cache in DRAM. Figure 5 As shown in the figure, the log structure mainly includes the starting address, the current allocation address and the end address, where the starting address and the end address limit the log space; the current allocation address is the tail address of the last valid record in the log space, which is used to append log records to the log space. Each log inside the LogTree corresponds to a log space for saving log records, and the log space is allocated and recycled by a large log pool. The log record only needs to save the operation type, key and value pointer, and there is no need to record the value itself. This can control the size of a single log record to a smaller level, thereby reducing the overhead of writing logs.

[0065] In summary, the constructed index structure can be recorded as a tree index structure HBTree, in which the CacheTree of the index layer, the middle layer and the data layer are located in DRAM, the NvmTree and the log of the data layer are located in NVM, and the middle layer is also backed up in NVM.

[0066] It should be noted that in order to avoid occupying too many DRAM resources, the maximum capacity M of the DRAM used to cache the CacheTree and the maximum storage capacity S of the CacheTree need to be set during initialization. In this way, it can be roughly calculated that about M / S LogTrees can build the CacheTree. Since each access to the LogTree must pass through the metadata node corresponding to it, the heat data of the LogTree is counted by the metadata node. Among all the LogTrees, the M / S LogTrees with the highest heat are regarded as the hotter LogTrees, and the CacheTree needs to be built. The rest are regarded as the colder LogTrees, and the CacheTree is not built, and the service is directly provided by the NvmTree. Specifically, the setting method of the preset access heat threshold includes: presetting the maximum capacity of the DRAM used to cache the CacheTree to M, presetting the maximum storage capacity of the CacheTree to S, obtaining the top M / S access heats with the highest access heats of each LogTree in the data layer, and taking the minimum access heat of the top M / S access heats as the preset access heat threshold. In this embodiment, M is 500MB and S is 0.5MB.

[0067] Embodiment 2,

[0068] The read and write request processing method of the index structure constructed by the construction method of the DRAM-NVM hybrid index structure described in Example 1 takes insert request and query request as an example. Figure 6 As shown, including:

[0069] When an insert request is received, the insert operation is performed:

[0070] S11. Based on the target keyword key in the request, query the index layer, obtain the metadata node pointer corresponding to the target keyword key, determine the metadata node of the middle layer, and accumulate the access heat of the LogTree corresponding to the metadata node; allocate persistent space for the value in the request in NVM, and persist it to obtain a pointer to the value;

[0071] S12, determine whether the CacheTree in the LogTree corresponding to the metadata node is in the creation or synchronization operation of the CacheTree, if so, go to step S13; otherwise, go to step S14;

[0072] S13, write the target keyword key and the pointer to value into the log in the LogTree corresponding to the metadata node, and the operation ends;

[0073] S14, insert the target keyword key and the pointer pointing to value into the LogTree corresponding to the metadata node: determine whether there is a CacheTree in the LogTree corresponding to the metadata node. If so, insert the target keyword key and the pointer pointing to value into the CacheTree, and write the target keyword key and the pointer pointing to value into the log in the LogTree corresponding to the metadata node; otherwise, insert the target keyword key and the pointer pointing to value into the NvmTree;

[0074] When a query request is received, the query operation is performed:

[0075] S21. Based on the target keyword key in the request, query the index layer, obtain the metadata node pointer corresponding to the target keyword key, determine the metadata node of the middle layer, and accumulate the access heat of the LogTree corresponding to the metadata node;

[0076] S22, determine whether the CacheTree in the LogTree corresponding to the metadata node is in the creation or synchronization operation of the CacheTree, if so, go to step S23; otherwise, go to step S24;

[0077] S23, query the operation record corresponding to the target keyword key in the log in the LogTree corresponding to the metadata node. If it can be found, obtain the value through the pointer pointing to value in the operation record, and the operation ends; otherwise, go to step S24;

[0078] S24. Determine whether there is a CacheTree in the LogTree corresponding to the metadata node. If so, query the CacheTree based on the target keyword key to obtain a pointer to value, and obtain the value of value through the pointer to value; otherwise, query the NvmTree based on the target keyword key to obtain a pointer to value, and obtain the value of value through the pointer to value.

[0079] The synchronization operation of CacheTree includes: when the log size is larger than the preset log size (the value in this embodiment is 5MB), updating the NvmTree in the LogTree where the CacheTree is located to make it the same as the CacheTree, specifically: starting from the root node of the CacheTree, traversing and performing the following operations:

[0080] If the current node of CacheTree is a dirty data node and the current node has a corresponding node at the corresponding position of NvmTree, the data in the current node is copied to the corresponding node in NvmTree;

[0081] If the current node of CacheTree is a dirty data node and there is no corresponding node at the corresponding position of NvmTree, a new node is created at the corresponding position of NvmTree, and the data in the current node is copied to the new node in NvmTree;

[0082] Repeat the above process until the CacheTree is traversed.

[0083] Specifically, an example of CacheTree synchronization operation provided by this embodiment is as follows: Figure 7 As shown; when CacheTree is synchronizing, it starts traversing from the root node and finds that node 2' and node 5' are dirty nodes and have corresponding nodes in NvmTree. It only needs to copy the node data (excluding the pointer in the record data) to the corresponding node in NvmTree; node 8' is a dirty node and has no corresponding node in NvmTree, indicating that it is a newly split CacheTree node. During the synchronization process, a new node needs to be created in NVM and the corresponding pointer in its parent node 2 needs to be modified.

[0084] In order to avoid blocking during the synchronization process and affecting system performance, the synchronization process is also completed by a background thread, and the log is used to continue to provide services to the foreground. In order to distinguish the log records before the start of synchronization from the log records after the synchronization, so as to recycle the log after the synchronization is completed, a new log will be created before the synchronization starts to record the subsequent write operations. For write requests, the operation record can be returned after writing it to the new log. For read requests, it is necessary to query the log record from the current allocated address position forward to the starting address position. If the target keyword is not found, go to CacheTree for query. After the CacheTree synchronization is completed, the old log will be recycled, and all the record operations in the new log will be played back to the CacheTree. The playback process will also briefly block the read and write requests to the LogTree.

[0085] It should be noted that, in an optional embodiment, the hotness of a LogTree can be determined by its historical access information, and then the access popularity of the LogTree can be accumulated. The core idea is: if a LogTree has a high historical access frequency, then the access frequency of the LogTree may also be high in the future, and it should be regarded as a hot LogTree.

[0086] When accumulating the popularity data of LogTree, considering that the frequency information of recent access should have a higher weight, the popularity data recorded in the metadata node will be proportionally decayed according to a certain time period; specifically, the accumulated access popularity of LogTree is:

[0087] HotDegree t+Δt =A*HotDegree t +Operate Δt

[0088] Where t represents the time of the previous time period, Δt represents the time elapsed from time t (less than one time period); HotDegree t Indicates the heat of LogTree at time t; HotDegree t+Δt represents the heat of LogTree at time t+Δt; A is the proportional coefficient of periodic heat decay, which is 0.5 in this embodiment; Operate Δt Indicates the number of read and write requests of LogTree within Δt time.

[0089] Furthermore, when too much data is inserted, the LogTree root node is full and the LogTree height exceeds a threshold, dynamic expansion is required. Specifically, in an optional implementation, when the LogTree corresponding to the metadata node is a B+ tree, the write request processing method further includes: step S15 executed between step S12 and step S14;

[0090] Step S15 includes: when the LogTree root node is full and the height of the LogTree exceeds a preset height threshold (the value is 3 in this embodiment), dynamically expanding the LogTree; specifically including the following steps:

[0091] S151, determine whether CacheTree exists in LogTree, if not, go to step S152; otherwise, go to step S153;

[0092] S152. Dynamically expand the NvmTree in the LogTree: split the root node of the NvmTree in the LogTree into two new nodes, and record the LogTree before the split as the original LogTree; the split position m is the result of rounding down half of the number of keywords in the root node of the NvmTree; the new node composed of the first m keywords in the root node of the NvmTree is recorded as the first new node, and the new node composed of the remaining keywords is recorded as the second new node; the split keyword is the m+1th keyword in the root node of the NvmTree; create a new LogTree with the same structure as the original LogTree at the data layer, and use the second new node as the NvmTree in the new LogTree. ee's root node; replace the root node of NvmTree in the original LogTree with the first new node, and modify the pointer information in the metadata node corresponding to the original LogTree accordingly; create a new metadata node in the middle layer, insert the new metadata node between the metadata node corresponding to the original LogTree and its next metadata node, corresponding to the new LogTree; insert the key-value pairs consisting of the split keyword and the pointer pointing to the new metadata node into the tree structure of the index layer in sequence to form a new node in the index layer; wherein the left pointer of the new node in the index layer points to the metadata node corresponding to the original LogTree, and the right pointer points to the new metadata node corresponding to the new LogTree;

[0093] S153, synchronize the dirty data of CacheTree in LogTree back to NvmTree in LogTree, and record the write operation request to LogTree in the synchronization process in the log of LogTree; dynamically expand CacheTree and NvmTree in LogTree respectively according to the method described in step S152, and record the LogTree before dynamic expansion as the original LogTree; copy the newly added records in the log of the original LogTree to the two LogTrees after the dynamic expansion is completed.

[0094] Specifically, in an optional implementation, the process of dynamic expansion is provided as follows: Figure 8As shown in the figure; LogTreeA does not construct CacheTree, but is directly operated by NvmTree. The NvmTree inside LogTree A reaches the height H, and the root node data is full, so dynamic expansion is required to avoid further increase in height. When performing dynamic expansion, the root node of its NvmTree is first split to generate two new nodes. The pointer corresponding to the record with the keyword 56 in the original root node is used as the leftmost pointer of the new node 2, and the keyword 56 is used as the split keyword and needs to be added to the parent node of the index layer; then the new node 2 is used as the NvmTree root node to generate a new LogTree B, and the metadata node of LogTree B is added to the metadata node linked list; next, the NvmTree root node of LogTreeA is replaced with the new node 1 to form LogTreeA', and the original root node is recycled; finally, the index data of its parent node is modified.

[0095] It should be noted that when a LogTree is dynamically expanded, two LogTrees of similar size are obtained. The heat of these two new LogTrees inherits the heat information of the LogTree before dynamic expansion and is diluted by a proportional coefficient. Since the sizes of the two LogTrees obtained by splitting are half of the original LogTree, the proportional coefficient is set to 0.5 by default in this embodiment.

[0096] The key-value storage structure based on non-volatile memory provided by the present invention can ensure the persistence and correctness of data.

[0097] Since the write operation on NVM only supports atomic writes with a granularity of 8B, data consistency issues need to be considered in all places on NVM that involve writes exceeding 8B. Specifically, Fig. 9 As shown, when a leaf node inserts data, the content of the node is copied to a new node, and then the new node is inserted. Finally, the pointer in the parent node pointing to the original node is modified to point to the newly generated node. Since the pointer size is 8B, it just meets the granularity of the NVM atomic write operation, so the modification of the pointer inside the parent node can be updated in place without affecting data consistency. When a leaf node is split, an index record needs to be inserted into the parent node, which will cause the parent node to perform a copy-on-write operation to create a new node, and insert the operation into the new parent node, and finally modify the pointer of the grandparent node pointing to the parent node. In general, for data modifications within the node, if the modification is only 8B in size, it can be updated in place. If it exceeds 8B, it needs to be performed through copy-on-write.

[0098] When CacheTree is synchronized or eliminated, the dirty nodes need to be synchronized back to the NvmTree nodes. Since the NvmTree nodes are larger than 8 bytes, if they are overwritten, partial writes may occur when the system loses power, resulting in partial data loss. Therefore, during the synchronization and elimination process, copy-on-write is applied to the synchronization update of leaf nodes instead of overwriting. Fig.10 As shown, when the leaf node of CacheTree needs to be synchronized back to NvmTree, the CacheTree leaf node is read into NVM to generate a new NvmTree node, and then the parent node pointer is updated, instead of directly overwriting the write target NvmTree node. The parent node pointer is atomically modified to ensure the atomicity of leaf node synchronization. In addition, if the system loses power during the synchronization process, only a part of the dirty nodes may be synchronized back to NvmTree, and there are still some dirty nodes that are not synchronized, resulting in errors in the NvmTree structure. Since the atomic write of the leaf node is guaranteed, even if the system loses power, the leaf node of NvmTree is still in a consistent state. The entire CacheTree structure can be restored in combination with the log, and the synchronization process can be re-performed. However, when replaying the log, it should be noted that some leaf nodes have been synchronized, and repeated insertion of data needs to be avoided.

[0099] Embodiment 3,

[0100] When the system loses power or fails, the data on the DRAM will be lost, and the structure on the NVM may also be inconsistent. Therefore, when the system where the index structure is located loses power or fails, fault recovery is required to ensure that normal and service can be provided. Specifically, the power failure or fault recovery method of the index structure constructed by the construction method of the DRAM-NVM hybrid index structure described in Example 1 includes the following steps:

[0101] 1) Restoration of the middle layer: When restoring, first traverse the metadata nodes of the middle layer backed up in NVM to determine whether there is data overlap between the NvmTree root nodes of the LogTree corresponding to adjacent metadata nodes. If there is data overlap, split the NvmTree root nodes with data overlap, and correct the problem that the corresponding metadata node predecessor pointer points to the wrong node to ensure that the middle layer is restored to a consistent state; finally, rebuild the metadata node linked list of the middle layer on DRAM;

[0102] It should be noted that when the system loses power, it may happen that the newly generated metadata node has been added to the metadata node list, but the root node of the original NvmTree has not been replaced. The solution is to first traverse the metadata node list when the system loses power and performs recovery operations to check whether there is data overlap between the NvmTree root nodes of adjacent LogTrees. If there is data overlap, it means that the dynamic expansion process is not complete and the root node with overlapping data needs to be split. In addition, the metadata node list also needs to consider consistency issues. Fig.11 As shown in the figure, during the process of inserting metadata nodes into a bidirectional linked list, if node a points its successor pointer to node c and the system loses power, node b has not yet modified its predecessor pointer, resulting in inconsistent data. When the system is restored after power failure, during the process of traversing the metadata node linked list, if it is found that the predecessor pointer of the successor node does not point to the current node, it can be corrected to point to the current node again.

[0103] 2) Recovery of LogTree: In order to ensure that the system can provide good read and write performance after fault recovery, the CacheTree in the hotspot LogTree is also rebuilt. Under normal circumstances (that is, power failure or failure does not occur during the synchronization or elimination of CacheTree), the CacheTree is constructed by backing up the NvmTree in the LogTree to DRAM, and then by scanning the log, all operations from the starting address of the log space to the current allocated address are played back to the CacheTree in order to restore it to the state before data loss; if the system loses power during the synchronization and elimination of the CacheTree, the NvmTree will be in an inconsistent state. At this time, the CacheTree is rebuilt using the consistent leaf nodes of the NvmTree, and then by scanning the logs in the LogTree, all operations from the starting address of the log space to the current allocated address are played back to the CacheTree in order;

[0104] Among them, the synchronization operation of CacheTree includes: when the log size is larger than the preset log size, updating the NvmTree in the LogTree where the CacheTree is located to make it the same as the CacheTree; the elimination operation of CacheTree includes: when the access heat of the LogTree where the CacheTree is located is less than the preset access heat threshold, after executing the synchronization operation of CacheTree, releasing all nodes in the CacheTree, deleting the log of the LogTree where the CacheTree is located, and reclaiming the log space;

[0105] 3) Recovery of the index layer: Take the index layer structure as a B+ tree as an example. The index layer B+ tree is all located in DRAM to accelerate data search. After the system loses power, all data will be lost and need to be rebuilt. When recovering, a new index layer B+ tree is recreated, and then the metadata node list is traversed to insert the key-value pairs consisting of the pointer of each metadata node and the minimum keyword of the LogTree corresponding to the metadata node into the B+ tree in sequence.

[0106] Since CacheTree is backed up in NVM and its modifications are recorded in log form, and the middle layer is also backed up on NVM, the fault recovery process will be very fast. At the same time, it is noted that after the middle layer fault recovery, there is no keyword overlap between LogTrees, and the recovery of CacheTrees in different LogTrees can be executed concurrently. Therefore, the recovery of LogTree can be performed in a multi-threaded task queue manner, and the system fault recovery time will be further reduced.

[0107] Embodiment 4,

[0108] A machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the method for constructing a DRAM-NVM hybrid index structure described in Example 1, the method for processing read and write requests for an index structure constructed by the method for constructing a DRAM-NVM hybrid index structure described in Example 2, and / or the method for recovering a fault of an index structure constructed by the method for constructing a DRAM-NVM hybrid index structure described in Example 3.

[0109] The relevant technical features are the same as those in Example 1, Example 2 and Example 3 and will not be elaborated here.

[0110] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for constructing a DRAM-NVM hybrid index structure, It is characterized in that include: Construct the index layer, middle layer and data layer to obtain the DRAM-NVM hybrid index structure; The index layer is a tree structure and is stored in DRAM; The middle layer includes one or more metadata nodes, which are stored in DRAM and backed up in NVM; When there are multiple metadata nodes, each metadata node is connected front and back to form a linked list structure; the data layer includes a log persistence tree LogTree; LogTree is a tree structure, the number of which is the same as the number of metadata nodes, and corresponds to the metadata nodes one by one; in the initial state, LogTree is stored in NVM, recorded as NvmTree; during the reading and writing process, if the access heat of LogTree is greater than the preset access heat threshold, CacheTree is created by backing up LogTree and caching it in DRAM; at this time, LogTree includes NvmTree initially stored in NVM, CacheTree cached in DRAM and log stored in NVM; wherein, the log is used to store records of write operations on CacheTree; The index layer is used to index the metadata nodes of the middle layer; The middle layer is used to address the LogTree in the data layer and record the access heat of each LogTree in the data layer; the metadata node in the middle layer includes a pointer to the CacheTree root node in the corresponding LogTree, a pointer to the root node of the NvmTree and a pointer to the log, as well as the access heat of the corresponding LogTree; The LogTree in the data layer is used to store the target keyword key and the pointer to value in the key-value pair written by the user; The method for setting the preset access heat threshold includes: The maximum capacity of the DRAM used to cache CacheTree is preset to M, the maximum storage capacity of CacheTree is preset to S, the top M / S access temperatures with the highest access temperatures of each LogTree in the data layer are obtained, and the minimum access temperature among the top M / S access temperatures is used as the preset access temperature threshold.

2. The method for constructing an index structure according to claim 1, It is characterized in that The index layer is a B+ tree; the LogTree is a B+ tree; When there are multiple metadata nodes, each metadata node is connected front and back to form a bidirectional linked list structure.

3. A method for processing read and write requests of an index structure constructed by the method for constructing a DRAM-NVM hybrid index structure according to any one of claims 1 to 2, It is characterized in that include: When a write request is received, the write operation is performed: S11, query the index layer based on the target keyword key in the request, obtain the metadata node pointer corresponding to the target keyword key, determine the metadata node of the middle layer, and accumulate the access heat of the LogTree corresponding to the metadata node; Allocate persistent space for the value in the request in NVM, persist it, and get a pointer to the value; S12, determining whether the CacheTree in the LogTree corresponding to the metadata node is in the creation or synchronization operation of the CacheTree, if so, proceeding to step S13; Otherwise, go to step S14; S13, write the target keyword key and the pointer to value into the log in the LogTree corresponding to the metadata node, and the operation ends; S14, inserting the target keyword key and the pointer pointing to value into the LogTree corresponding to the metadata node: judging whether there is a CacheTree in the LogTree corresponding to the metadata node, if so, inserting the target keyword key and the pointer pointing to value into the CacheTree, and writing the target keyword key and the pointer pointing to value into the log in the LogTree corresponding to the metadata node; Otherwise, insert the target keyword key and the pointer to value into NvmTree; When a read request is received, the read operation is performed: S21, query the index layer based on the target keyword key in the request, obtain the metadata node pointer corresponding to the target keyword key, determine the metadata node of the middle layer, and accumulate the access heat of the LogTree corresponding to the metadata node; S22, determining whether the CacheTree in the LogTree corresponding to the metadata node is in the creation or synchronization operation of the CacheTree, if so, proceeding to step S23; Otherwise, go to step S24; S23, searching the log in the LogTree corresponding to the metadata node for the operation record corresponding to the target keyword key, if it can be found, obtaining the value through the pointer pointing to value in the operation record, and the operation ends; Otherwise, go to step S24; S24, determine whether there is a CacheTree in the LogTree corresponding to the metadata node, if so, query in the CacheTree based on the target keyword key, obtain a pointer pointing to value, and obtain the value of value through the pointer pointing to value; otherwise, query in the NvmTree based on the target keyword key, obtain a pointer pointing to value, and obtain the value of value through the pointer pointing to value; The synchronization operation of CacheTree includes: when the log size is larger than the preset log size, updating the NvmTree in the LogTree where the CacheTree is located to make it the same as the CacheTree.

4. The read / write request processing method according to claim 3, It is characterized in that The accumulated access popularity of LogTree is: HotDegree t+Δt =A*HotDegree t +Operate Δt Among them, HotDegree t+Δt HotDegree is the access heat accumulated at the current time t+Δt; t is the access heat accumulated at the last moment t; Δt is the time difference between the current moment and the last moment; A is the proportional coefficient of the periodic decay of heat; Operate Δt is the number of read and write requests of LogTree within Δt time.

5. The read / write request processing method according to claim 3, It is characterized in that When the LogTree corresponding to the metadata node is a B+ tree, the write request processing method further includes: step S15 executed between step S12 and step S14; The step S15 includes: when the root node of LogTree is full and the height of LogTree exceeds a preset height threshold, dynamically expanding LogTree; specifically including: S151, determine whether CacheTree exists in LogTree, if not, go to step S152; otherwise, go to step S153; S152, dynamically expand the NvmTree in the LogTree: split the root node of the NvmTree in the LogTree into two new nodes, and record the LogTree before the split as the original LogTree; the split position m is the result of rounding down half of the number of keywords in the root node of the NvmTree; the new node composed of the first m keywords in the root node of the NvmTree is recorded as the first new node, and the new node composed of the remaining keywords is recorded as the second new node; the split keyword is the m+1th keyword in the root node of the NvmTree; create a new LogTree with the same structure as the original LogTree at the data layer, and use the second new node as the root node of the NvmTree in the new LogTree; The root node of the NvmTree in the original LogTree is replaced with the first new node, and the pointer information in the metadata node corresponding to the original LogTree is modified accordingly; a new metadata node is created in the middle layer, and the new metadata node is inserted between the metadata node corresponding to the original LogTree and its next metadata node, corresponding to the new LogTree; the key-value pair consisting of the split keyword and the pointer pointing to the new metadata node is inserted into the tree structure of the index layer to form a new node of the index layer; wherein the left pointer of the new node of the index layer points to the metadata node corresponding to the original LogTree, and the right pointer points to the new metadata node corresponding to the new LogTree; S153, synchronize the dirty data of CacheTree in LogTree back to NvmTree in LogTree, and record the write operation request to LogTree in the synchronization process in the log of LogTree; dynamically expand CacheTree and NvmTree in LogTree respectively according to the method described in step S152, and record the LogTree before dynamic expansion as the original LogTree; copy the newly added records in the log of the original LogTree to the two LogTrees after the dynamic expansion is completed.

6. The read / write request processing method according to claim 5, It is characterized in that The access heat of the two LogTrees after dynamic expansion is HotDegree, HotDegree = ηHotDegree 0 Among them, HotDegree 0 is the access popularity of LogTree before dynamic expansion; η is the proportional coefficient, 0<η<1.

7. The read / write request processing method according to any one of claims 3 to 6, It is characterized in that For write operations larger than 8B performed by NvmTree in LogTree, copy-on-write technology is used to ensure data consistency.

8. A power failure or fault recovery method for an index structure constructed by the method for constructing a DRAM-NVM hybrid index structure according to any one of claims 1 to 2, It is characterized in that The following steps are involved: 1) Restoration of the middle layer: traverse the metadata nodes of the middle layer backed up in NVM, determine whether there is data overlap in the NvmTree root nodes of the LogTree corresponding to adjacent metadata nodes, and if there is data overlap, split the NvmTree root nodes with data overlap, and correct the pointer information in the corresponding metadata nodes to ensure that the middle layer is restored to a consistent state, and then rebuild the metadata nodes of the middle layer on DRAM; 2) LogTree recovery: If the power failure or failure does not occur during the synchronization or elimination of CacheTree, the CacheTree is constructed by backing up the NvmTree in the LogTree to DRAM, and then all operations from the start address of the log space to the current allocated address are played back to the CacheTree in order by scanning the log in the LogTree, so that it can be restored to the state before the data loss; if the power failure or failure occurs during the synchronization or elimination of the CacheTree, the NvmTree in the LogTree will be in an inconsistent state, and the CacheTree will be rebuilt using the consistent leaf nodes of the NvmTree, and then the LogTree will be scanned. e, and replay all operations from the starting address of the log space to the current allocated address in order into the CacheTree; wherein, the synchronization operation of the CacheTree includes: when the log size is larger than the preset log size, updating the NvmTree in the LogTree where the CacheTree is located to make it the same as the CacheTree; the elimination operation of the CacheTree includes: when the access heat of the LogTree where the CacheTree is located is less than the preset access heat threshold, after executing the synchronization operation of the CacheTree, releasing all nodes in the CacheTree, deleting the log of the LogTree where the CacheTree is located, and reclaiming the log space; 3) Recovery of the index layer: Recreate a tree structure in DRAM, then traverse the metadata nodes of the middle layer, and insert the key-value pairs consisting of the pointer to the metadata node and the minimum keyword of the LogTree corresponding to the metadata node into the tree structure in sequence.

9. A machine-readable storage medium, It is characterized in that The machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by the processor, the machine-executable instructions prompt the processor to implement the DRAM-NVM hybrid index structure construction method described in any one of claims 1-2, the read and write request processing method described in any one of claims 3-7, and / or the power-off or fault recovery method of the index structure described in claim 8.