Key-value storage system, garbage collection method

By partitioning and storing key-value pairs in persistent memory and using B+ tree indexes, the multi-level compression operation of the LSM tree is eliminated, and combined with the garbage collection strategy, the problems of low efficiency and high write amplification rate of the key-value storage system in the existing technology are solved. A high-performance and long-life persistent memory storage system is achieved.

CN114691041BActive Publication Date: 2024-10-22HUNAN UNIV
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202210293809.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-24
Publication Date
2024-10-22
Estimated Expiration
2042-03-24

AI Technical Summary

Technical Problem

The existing key-value storage system based on persistent memory has reduced efficiency under high performance requirements, high write amplification rate, which affects the life of persistent memory, and does not fully utilize the characteristics of persistent memory.

Method used

The persistent memory is divided into two areas, one is used to store the value of the key-value pair, and the other is used to store the key and address. It combines the B+ tree and the memory table to eliminate the multi-level compression operation of the LSM tree, reduce write amplification, and pass garbage The recycling method optimizes the number of SSTables and improves space utilization.

Benefits of technology

A high-performance key-value storage system is implemented, which reduces read and write latency, improves throughput, extends persistent memory life, and improves system space utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114691041B_ABST
    Figure CN114691041B_ABST
Patent Text Reader

Abstract

The present invention discloses a key-value storage system and a garbage collection method. The key-value storage system includes: a persistent memory, which is provided with a first storage area and a second storage area; the first storage area is used to store the value of a key-value pair; the second storage area is used to store the key of the key-value pair and the address corresponding to the key; a dynamic random access memory, which is provided with a B+ tree and a memory table; the B+ tree is used to store the latest index value of the key-value pair; the memory table is used to store the key of the key-value pair and the address corresponding to the key. The present invention directly uses persistent memory to replace disk storage data, takes advantage of the large capacity and high speed of persistent memory, and constructs a high-performance key-value storage system based on persistent memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a key-value storage technology, in particular to a key-value storage system and a garbage collection method. Background Art

[0002] Key-value storage is one of the simplest types of databases. It has the advantages of fast query speed, large data storage volume, and high concurrency support. It has gradually become a basic component for data centers to effectively support various data-intensive applications. In recent years, emerging storage technologies, such as persistent memory, which has the characteristics of byte addressability and non-volatility, have brought great opportunities for the goal of building high-performance key-value storage: PCM, ReRAM, and the recently released Optane DC persistent memory can provide data persistence while achieving performance comparable to that of memory. These persistent memories have read latency comparable to that of memory, higher write latency (7-22 times), higher density (1.5-2.7), lower bandwidth (5-10), and lower durability {10^4-10^7} compared to memory. Persistent memory provides new opportunities for achieving high-performance key-value storage. There are already many key-value storage designs based on log-structured merge trees (LSM-Tree).

[0003] There are several main problems with existing research based on persistent memory:

[0004] First, since the key-value storage was originally designed to be optimized for memory, when it is used in persistent memory, the efficiency begins to decrease and a lot of space and bandwidth are wasted.

[0005] Secondly, some studies have coexisted persistent memory with disks such as solid-state drives and mechanical hard disks. Data is still stored on the disks, and the new persistent memory is used as an intermediate layer or smoothing layer as a large memory write buffer or read cache to improve system performance. This cannot fully utilize persistent memory to obtain high performance.

[0006] Existing key-value storage has an inherent read-write amplification structure. In LSM-Tree, an inserted key-value pair needs to be continuously merged, sorted, and written to disk, and moved to the highest level through background compression. For an n-level LSM-Tree, its write amplification ratio (the ratio between the total amount of data written to disk and the amount of data required by users) can be as high as 10n, which greatly affects the life of persistent memory devices because the number of erases and writes of persistent memory devices is several orders of magnitude lower than other hard disks. For read operations, in general, LSM-Tree also needs to search multiple files, which also greatly affects the performance of the system. Summary of the invention

[0007] The technical problem to be solved by the present invention is to provide a key-value storage system and a garbage collection method to improve system performance by using persistent memory in view of the deficiencies in the prior art.

[0008] In order to solve the above technical problems, the technical solution adopted by the present invention is: a key-value storage system, comprising:

[0009] A persistent memory, comprising a first storage area and a second storage area; the first storage area is used to store the value of a key-value pair; the second storage area is used to store the key of the key-value pair and the address corresponding to the key;

[0010] A dynamic random access memory is provided with a B+ tree and a memory table; the B+ tree is used to store the latest index value of the key-value pair; the memory table is used to store the key of the key-value pair and the address corresponding to the key.

[0011] The present invention compresses multiple levels of LSM trees into a single level, eliminates the compact operation between levels in the LSM tree (this operation has a large write amplification), uses key-value separation to reduce the amount of data written when large values ​​are present, and stores B+ trees in memory to reduce read amplification during queries.

[0012] The second storage area uses the Level 0 layer of the LSM-Tree; the keys and addresses corresponding to the keys are stored in multiple SSTables of the Level 0 layer. The present invention compresses the multi-level structure of the LSM tree into a single layer, so that the system does not need compression operations, reducing the write amplification of the entire system.

[0013] In order to ensure that the metadata will not be lost when the system loses power, a metadata management area is also provided in the persistent memory for storing metadata information of key-value pairs.

[0014] The process of searching for data in the storage system includes: searching for key k in the memory table of the dynamic random access memory, if the key does not exist, searching in the immutable memory table, if the key does not exist, searching in the B+ tree, if the key is found, obtaining the corresponding value from the first storage area according to the address corresponding to the key, and terminating the search; if the key is not found, returning a not found result to the client. The present invention reduces read amplification, the LSM tree needs to search all LEVELs on the DRAM and the disk, and the present invention only needs to search the MEMTABLE and B+ tree in the DRAM.

[0015] The process of writing data to the storage system includes:

[0016] Write the value in the key-value pair to the first storage area, and return the position information of the written value, replacing the value with the position information to form a key-position information pair, that is, (key, position information);

[0017] Write the key-position information pair into the write-ahead log;

[0018] Write the key-position information pair into the memory table and return the current operation result.

[0019] In actual work, the length of the value in the key value is greater than the length of the position information. Using position information instead of the key can reduce write amplification.

[0020] When writing data, if the memory table is full, the current memory table is set as an immutable memory table, and a new memory table is created in the dynamic random access memory to receive data writing; the data in the immutable memory table is written into the second storage area and the B+ tree at the same time. The data is first written into the faster memory, and then written into the second storage area and the B+ tree in batches, which improves the writing throughput.

[0021] As an inventive concept, the present invention also provides a garbage collection method, which is applicable to the above-mentioned key-value storage system of the present invention; comprising the following steps:

[0022] Initialize the merge candidate set;

[0023] If the ratio of the valid items in any SSTable in the second storage area (i.e., a key-value pair in the SSTable that is currently the latest value, i.e., a key-value pair that has not been updated or deleted) to the total number of key-value items in the SSTable reaches a set threshold, the SSTable is added to the merge candidate set;

[0024] When the number of SSTables in the merge candidate set reaches a preset threshold, all SSTables in the merge candidate set are merged into one SSTable.

[0025] The garbage collection method of the present invention reduces the number of SSTables and keeps the data in order. Moreover, the program can run in the background without affecting the system performance.

[0026] The specific implementation process of merging all SSTables in the merge candidate set into one SSTable includes:

[0027] 1) Traverse the SSTable list in the merge candidate set. If there is no valid key-value item in the SSTable list (when flushing the content in DRAM into PM, if the current key-value pair has an old value, the old value is marked as invalid), directly remove the SSTable list from the merge candidate set;

[0028] 2) If the list of SSTables in the merge candidate set becomes empty, the merge process is terminated directly; otherwise, the list of SSTables obtained after step 1) is sorted as a whole, and an iterator that traverses all key-value pairs in all SSTables in the merge candidate set is constructed;

[0029] 3) Scan iterator, search for each key-value pair in the B+ tree, if the value searched by the key matches the current key-value pair, write the key-value pair to the newly created SSTable and update the content in the B+ tree;

[0030] 4) After SSTable writing is completed, the SSTable in the merge candidate set is deleted, the newly created SSTable and the deleted SSTable data are incrementally updated to the metadata management area of ​​the persistent memory, and the current merge candidate set is cleared.

[0031] Garbage collection based on effective key value rate can improve garbage collection efficiency and reduce the amount of data written (if multiple SSTables are valid items, all need to be rewritten, increasing write amplification).

[0032] Compared with the prior art, the present invention has the following beneficial effects:

[0033] 1. The present invention directly uses persistent memory to replace disk storage data, taking advantage of the large capacity and high speed of persistent memory to build a high-performance key-value storage system based on persistent memory.

[0034] 2. Existing LSM-Tree-based systems have extremely high read and write amplification, which greatly affects the life of persistent memory. Based on this, the present invention combines the advantages of LSM-Tree's high write throughput and the advantages of B+ tree index fast search. Based on LSM-Tree, the present invention compresses the multi-level structure to a single level, maintaining high throughput while greatly reducing the write amplification caused by compression in the LSM-Tree architecture. The present invention establishes a B+ tree index for the data in the persistent memory, reducing its read amplification and maintaining its high read throughput, thereby extending the service life of the persistent memory while also improving the throughput of the system. The key-value separated storage structure of the present invention reduces the total amount of data written and the size of the B+ tree in the memory, further reducing the write amplification of the system.

[0035] 3. Compared with other persistent memory-based systems, the present invention greatly reduces the system's read and write latency and improves throughput.

[0036] 4. The present invention implements a garbage collection strategy and improves the space utilization of persistent memory.

[0037] 5. The present invention realizes the function of recovering after system crash. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 This is a structural diagram of a storage system according to an embodiment of the present invention;

[0039] Figure 2 This is a schematic diagram of data layout according to an embodiment of the present invention. DETAILED DESCRIPTION

[0040] The system architecture diagram of the present invention is as follows: Figure 1 , which stores all persistent data in persistent memory and includes the following parts:

[0041] 1. Compress the multi-level structure of LSM-Tree to a single level. The present invention removes the hierarchical structure of LSM-Tree, retaining only the unordered Level 0, and places all data flushed to the persistent memory in the SSTable of Level 0, which makes it unnecessary for the database to frequently perform compression operations on the higher levels, greatly reducing the write amplification of data in the storage system. Canceling the levels does not directly improve database performance, but it eliminates some redundant processes by eliminating expensive operations (compression process) in the system (there are many levels in the LSM tree architecture, and writes need to be continuously merged from the upper level to the lower level. After compressing the multi-level LSM tree to a single level, the compact operation between levels in the LSM tree is eliminated, and this operation has a large write amplification), so that the system performance benefits from this.

[0042] 2. A B+ tree is maintained in the memory. When performing a read operation, if the read in the memory fails, it is necessary to search in the entire Level 0. Since the SSTables in Level 0 are stored out of order, it is necessary to scan all SSTables for searching, which results in a huge read amplification. In order to solve this problem, the present invention maintains a B+ tree in the memory, which stores the latest values ​​of all KV items (key-value pairs) in Level 0. In this way, when performing a read operation, the present invention first searches the MemTable (memory table) and Immutable MemTable (immutable memory table) in the memory like the LSM-Tree. If not found, only the B+ tree needs to be searched without scanning the SSTables in each level, which reduces the read amplification in the system.

[0043] 3. Key-value separation design. Since the B+ tree is stored in memory, in order to save memory space, the present invention makes a key-value separation design for the key-value pairs in the system, that is, the value is written in a special value append log, and a shorter address is used to save it instead. In this way, only the key and the address of the corresponding value are saved in the B+ tree. In the experiment of the present invention, the data layout is as follows Figure 2In order to make the address length as small as possible, the address consists of a 6-byte value address and a 2-byte SSTable pool number. The 6-byte value address includes a 2-byte pool number and a 4-byte offset. The first six bytes are used to locate the value, and the last two bytes are used to count the valid values ​​in the SSTable. The value item in the value log consists of a 4-byte value size and value content. In actual scenarios, the value size is greater than 8 bytes in most cases. Therefore, the use of key-value separation not only reduces the amount of data stored in memory, but also reduces the amount of data written when the B+ tree is balanced.

[0044] 4. Garbage collection algorithm. Since all SSTables are stored in Level 0, if there is no appropriate garbage collection mechanism, there will be many invalid key-value pairs occupying persistent memory space in update-intensive workloads, resulting in reduced utilization of persistent memory. To solve this problem, the system provides an SSTable merge operation to perform garbage collection on Level 0. For the merge operation, the system maintains a merge candidate set for SSTable. When the system starts, a background process is configured to maintain this set and make judgments when the metadata in Level 0 changes (flush operation). When a single SSTable meets the conditions, it is added to the merge candidate set. In the system, the condition for adding an SSTable to the merge candidate set is that the ratio of valid items in a single SSTable to the total number reaches a set threshold (for example, 50%). When the size of the candidate set reaches a pre-set threshold (for example, the threshold is set to 2), the merge between SSTables is initiated.

[0045] The merging process is completed by the background program. Algorithm 1 describes the merging process. The first to sixth lines first check whether the SSTable in the merge candidate set contains valid key-value items. If the SSTable contains only invalid items, the pool to which the SSTable belongs can be directly recycled without any other changes. Since the key-value pairs in a single SSTable are ordered, in lines 10 and 11, the present invention uses a merge sort method to sort multiple SSTABLEs and create an iterator that can traverse all key-value items. Lines 13 to 20 are the processing of each key-value item. From the pseudocode, it can be seen that for the current key-value pair, the present invention first searches in the B+ tree. If the current item exists and the latest address is the same as the address of the currently processed item, it proves that the item is a valid item, and then writes it to a new SSTable. When the key-value item is written to a new SSTable, the SSTable number where the corresponding item is stored in the B+ tree changes, which will cause data errors in the system. Therefore, the present invention updates the item while writing it to the new SSTable. Figure 2The loc part of the address shown in the table is used to keep the data in the tree correct. The present invention performs the same operation on all items in the iterator. Lines 21 and 22 are updates of some metadata, including the addition and deletion of SSTables, the preservation of metadata, the update of the merge candidate set, and the recycling of old space. Since the algorithm of the present invention updates the data in the B+ tree when merging SSTables, if there are modifications to the valid items of the new SSTable during the merging process, the metadata will also be incorrect. In order to solve this problem, the present invention adds a check operation when updating the metadata, that is, if a new SSTable is written during the merging process, the present invention will record these operations and calculate the corresponding metadata in the InstallMergeResult() function in line 21 (the function input is the deleted and newly added SSTables after the merge, and the output is whether it is successful. Success means that the metadata update is completed, and failure is retried).

[0046]

[0047] Algorithm 1: Input: Candidate SSTable (SSTable that meets the merge conditions)

[0048] Step 1: First traverse the candidate SSTable list. If there is no valid key value item in the list, remove it directly from the candidate list.

[0049] Step 2: If the SSTable in the candidate list becomes empty, the merge process ends directly.

[0050] Step 3: Since the key-value items in the SSTable are arranged in order, use merge sort to sort the candidate SSTable list as a whole, and build an iterator that can traverse these items.

[0051] Step 4: Scan the iterator and search the global B+ tree for each key-value pair. If the value searched by the key is equal to the current key-value pair, write the key-value pair to the new SSTable and update the content in the B+ tree.

[0052] Step 5: After SSTable writing is completed, delete the SSTable in the candidate set, incrementally update the newly created SSTable and deleted SSTable data to metadata management, and clear the current merge candidate set.

[0053] The operation process of the storage system of the present invention is as follows: Figure 1 The directed arrows in the figure include the following operations:

[0054] GET(k) is to obtain the value of the key k in the database. When a GET operation with a given key k is passed in, the system PMDB of the present invention executes GET①, GET② and GET③ in sequence. GET① searches in the current MemTable. If the key does not exist, GET② is executed. GET② searches the IMMTABLE. If the key does not exist, GET③ is executed. GET③ searches in the B+ tree. If any of the above three processes successfully finds k, the corresponding value is obtained from the value area according to the read address and the result is returned to the client and the subsequent search process is terminated. If none of the three processes finds K, it returns to the client that it is not found. During the execution of the entire GET operation, PMDB returns the result to the client without reading any SSTable.

[0055] PUT(k,v) represents a write operation on a key-value pair (k,v). When inserting a key-value pair, if the key k does not exist in the system, insert is executed, otherwise update is executed. When a PUT operation of a given key-value pair (k,v) is passed in, the data flow inside PMDB is represented as ①-⑤ in the figure. ① means that when the system receives a PUT operation of a given key-value pair (k,v), ② and ③ write v in the key-value pair to the value area and return the location information address of the written value, and address is used instead of v for subsequent operations. ④ is to write (k,address) to the write-before log to perform fault recovery when the system crashes suddenly. ⑤ Write (k,address) to the MEMTABLE in memory and return the current operation result.

[0056] Figure 1 ⑥-⑧ are background processes. When MEMTABLE is full, ⑥ sets MEMTABLE to IMMUTABLE and creates a new MEMTABLE to continue to accept writes. When IMMTABLE exists in the system, the persistence operation of IMMTABLE will be triggered, that is, ⑦ flushes it to LEVEL0 in persistent memory in the form of SSTABLE and writes it to the B+ tree in memory at the same time. When there are too many invalid items in SSTABLE in LEVEL0, the merging process of ⑧ SSTABLE is triggered, and multiple SSTABLEs with invalid items exceeding the preset threshold are merged into one, so as to improve the space utilization of persistent memory.

[0057] DELETE(k) is implemented by setting v to the delete flag in PUT.

[0058] The present invention implements PMDB on a real persistent storage. Experimental results show that PMDB improves read and write throughput compared to LevelDB. When the value size is 100 bytes, 1KB, 4KB and 16KB, the read throughput is 0.11, 0.84, 3.17 and 9.69 times faster than LevelDB respectively, and the write throughput is 0.06, 9.96, 44 and 83 times faster than LevelDB respectively. Compared with LevelDB, PMDB also has lower write amplification and less data writing.

Claims

1. A key-value storage system, It is characterized in that include: A persistent memory having a first storage area and a second storage area; The first storage area is used to store the value of the key-value pair; The second storage area is used to store the key of the key-value pair and the address corresponding to the key; A dynamic random access memory is provided with a B+ tree and a memory table; the B+ tree is used to store the latest index value of the key-value pair; The memory table is used to store the key of the key-value pair and the address corresponding to the key; The second storage area uses Level 0 of LSM-Tree; The keys and addresses corresponding to the keys are stored in multiple SSTables of Level 0 layer; The process of searching for data in the storage system includes: Search for key k in the memory table of the dynamic random access memory. If the key does not exist, search in the immutable memory table. If the key does not exist, search in the B+ tree. If the key is found, obtain the corresponding value from the first storage area according to the address corresponding to the key, and terminate the search. If the key is not found, return a not found result to the client. When writing data, if the memory table is full, the current memory table is set as an immutable memory table, and a new memory table is created in the dynamic random access memory to accept data writing; the data in the immutable memory table is simultaneously written into the second storage area and the B+ tree.

2. The key-value storage system according to claim 1, It is characterized in that The persistent memory is also provided with a metadata management area for storing metadata information of key-value pairs.

3. The key-value storage system according to claim 1, It is characterized in that The process of writing data to the storage system includes: Write the value in the key-value pair to the first storage area, and return the position information of the written value, replacing the value with the position information to form a key-position information pair; Write the key-position information pair into the write-ahead log; Write the key-position information pair into the memory table and return the current operation result.

4. A garbage collection method, applicable to the key-value storage system according to any one of claims 1 to 3; It is characterized in that The following steps are involved: Initialize the merge candidate set; If the ratio of the valid items in any SSTable in the second storage area to the total number of key-value items in the SSTable reaches a set threshold, the SSTable is added to the merge candidate set; When the number of SSTables in the merge candidate set reaches a preset threshold, all SSTables in the merge candidate set are merged into one SSTable.

5. The garbage collection method according to claim 4, It is characterized in that The specific implementation process of merging all SSTables in the merge candidate set into one SSTable includes: 1) Traverse the SSTable list in the merge candidate set. If there is no valid key value item in the SSTable list, directly remove the SSTable list from the merge candidate set; 2) If the list of SSTables in the merge candidate set becomes empty, the merge process ends directly; otherwise, the list of SSTables obtained after step 1) is sorted as a whole, and an iterator that traverses all key-value pairs in all SSTables in the merge candidate set is constructed; 3) Scan iterator, search for each key-value pair in the B+ tree, if the value searched by the key matches the current key-value pair, write the key-value pair to the newly created SSTable and update the content in the B+ tree; 4) After SSTable writing is completed, the SSTable in the merge candidate set is deleted, the newly created SSTable and the deleted SSTable data are incrementally updated to the metadata management area of ​​the persistent memory, and the current merge candidate set is cleared.

Citation Information

Cited By

  • FPGA acceleration parallel computing method oriented to Key-Value storage system

    CN119806396A

  • A parallel computing method for FPGA acceleration of a Key-Value storage system

    CN119806396B