Key-value storage method and system based on non-volatile memory and solid-state hard disk
By distinguishing the storage of large key-value pairs and small key-value pairs in non-volatile memory and using data structures such as B+ trees, the problem of performance deterioration of NVM and SSD hybrid storage devices in the existing technology is solved, and more efficient key-value storage performance is achieved.
Patent Information
- Application Number
- CN202411659980.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2044-11-20
AI Technical Summary
When deployed on hybrid storage devices consisting of NVM and SSD, existing key-value storage systems cannot fully utilize the characteristics of NVM and SSD, resulting in performance degradation, especially problems in search performance and write amplification.
Key-value pairs are divided into large and small key-value pairs based on the amount of storage space they occupy. They are stored separately in non-volatile memory and their storage locations are recorded using a location record structure. Data structures such as B+ trees are used to improve query performance, and memory blocks are allocated rationally to reduce the number of compaction operations.
It effectively improves the range query performance and write performance of the key-value storage system, reduces write amplification, and fully utilizes the characteristics of NVM and SSD.
Smart Images

Figure CN119536654B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of key-value storage, and more specifically, relates to a key-value storage method and system based on non-volatile memory and solid-state hard disk. Background Art
[0002] Key-value stores are essential components of databases and various data-intensive applications. They are widely used in fields such as web search, e-commerce, cloud storage, and social networking, and have garnered extensive attention and research from both academia and industry. Existing key-value stores, such as LevelDB and RocksDB, are primarily optimized for disks and solid-state drives (SSDs). Specifically, because disks offer better sequential read and write performance than random read and write performance, LevelDB and RocksDB first write key-value pairs to memory and then sequentially write these in-memory key-value pairs to disk in batches to fully utilize the disk's characteristics. Furthermore, traditional storage solutions store key-value pairs in a tiered manner, with the key values in the upper tier being newer than the key-value pairs in the lower tiers. When searching for a key-value pair, the system first searches the upper tier. If the key-value pair is not found, the system searches the lower tiers, continuing until the last tier is reached. Furthermore, with usage, invalid key-value pairs are generated in the key-value store. When the number of invalid key values exceeds a certain threshold, a compaction operation is required. During this compaction operation, the key-value pairs from disk are read into memory, deleted, sorted, and then written to disk again. This process can result in significant write amplification. Therefore, traditional key-value storage solutions have poor search performance.
[0003] DRAM technology faces significant challenges in storage density and energy consumption. To overcome DRAM's shortcomings, researchers have begun researching non-volatile memory (NVM) technologies, such as phase-change memory (PCM) and resistive random access memory (RRAM). NVM offers high storage density, low static power consumption, data integrity during power failures, byte-by-byte addressing, and low read and write latency, making it a promising candidate to replace DRAM in the near future. With the continued development and maturity of solid-state drives (SSDs), SSDs have been widely deployed in computer systems. Similar to disks, SSDs offer better sequential write performance than random write performance. However, unlike disks, SSDs offer similar random read (multi-threaded) and sequential read performance. Therefore, hybrid storage devices composed of NVM and SSDs can significantly improve storage system performance.
[0004] However, existing key-value storage solutions are mainly designed for disks and solid-state drives. When deployed on hybrid storage devices consisting of NVM and SSDs, they cannot fully utilize the characteristics of NVM and SSDs and may even lead to performance degradation. Summary of the Invention
[0005] In response to the defects and improvement needs of the existing technology, the present invention provides a key-value storage method and system based on non-volatile memory and solid-state drive, the purpose of which is to fully utilize the characteristics of NVM and SSD to improve the key-value storage performance.
[0006] To achieve the above objectives, according to one aspect of the present invention, a key-value storage method based on a non-volatile memory and a solid-state drive is provided, comprising:
[0007] Pre-allocate a memory block S_mem and a storage block B_mem in the non-volatile memory for storing small key-value pairs and large key-value pairs, respectively, and create a location record structure for recording the storage location of each key-value pair in the non-volatile memory or solid-state drive; the storage space occupied by the small key-value pair is less than a preset threshold, and the storage space occupied by the large key-value pair is not less than the preset threshold;
[0008] When an insert operation is received from the upper layer, the operation is performed in the following ways:
[0009] (I1) For the key-value pair kv to be inserted i , determine its type, if it is a small key-value pair data, then go to (I2); otherwise, go to (I4);
[0010] (I2) Determine whether the current memory block S_mem is full. If so, convert the memory block S_mem into a memory block S_imm, flush it to the solid-state drive, and reallocate the memory block S_mem in the non-volatile memory, and proceed to (I3); if not, proceed directly to (I3);
[0011] (I3) The key-value pair kv i Insert the current memory block S_mem in order and go to (I6);
[0012] (I4) Determine whether the current memory block B_mem is full. If so, convert the memory block B_mem to the memory block B_imm, flush it to the solid-state drive, and fully allocate the memory block B_mem in the non-volatile memory, and then proceed to (I5); if not, directly proceed to (I5);
[0013] (I5) The key-value pair kv i Insert the current memory block B_mem and go to (I6);
[0014] (I6) Record the key-value pair kv in the location record structure i The storage location of the insert operation is completed.
[0015] Furthermore, when a range query operation is received from an upper layer, the operation execution method includes:
[0016] For the key range to be queried, the location record structure is searched to obtain the storage location of each key-value pair data within the key range, and the corresponding key-value pairs are read in parallel according to the storage location, and then merged and sorted.
[0017] Furthermore, the location record structure is a B+ tree, a skip list or a red-black tree.
[0018] Furthermore, when a delete operation is received from an upper layer, the operation execution method includes:
[0019] For the key-value pair kv to be deleted d , delete its storage location from the location record structure and set the key-value pair kv d Mark as invalid.
[0020] Furthermore, the key-value pairs in each memory block S_imm are flushed to a data block S_kv in the solid-state drive, and the key-value pairs in each memory block B_imm are flushed to a data block B_kv in the solid-state drive;
[0021] When a compaction operation is received from the upper layer, the operation is performed in the following ways:
[0022] For the data block S_kv to be operated, perform the following steps:
[0023] (C1) Reading all key-value pairs in the data block S_kv to be operated into the volatile memory and deleting invalid key-value pairs therein;
[0024] (C2) After sorting the remaining key-value pairs according to the size of the key, the key-value pairs are divided into data blocks according to the size of the data block S_kv;
[0025] (C3) writing the divided data blocks into the data block S_kv in parallel in the solid state drive, and deleting the original data block S_kv;
[0026] For the data block B_kv to be operated, perform the following steps:
[0027] (C1′) reading all key-value pairs in the data block B_kv to be operated into the volatile memory and deleting invalid key-value pairs therein;
[0028] (C2′) dividing the remaining key-value pairs into data blocks according to the size of the data block B_kv;
[0029] (C3′) The divided data blocks are written in parallel to the data blocks B_kv in the solid state drive, and the original data blocks B_kv are deleted.
[0030] Furthermore, when an update operation is received from an upper layer, the operation execution method includes:
[0031] The original key-value pair is deleted through the delete operation, and then the new key-value pair is inserted through the insert operation.
[0032] Furthermore, when a single-point query operation is received from an upper layer, the operation execution method includes:
[0033] For the key-value pair kv to be queried s , query its storage location from the location record structure;
[0034] Read the key-value pair kv according to the storage location s .
[0035] According to yet another aspect of the present invention, there is provided a key-value storage controller based on a non-volatile memory and a solid-state drive, comprising: a computer-readable storage medium and a processor;
[0036] Computer-readable storage medium for storing computer programs;
[0037] The processor is used to read the computer program stored in the computer-readable storage medium and execute the above-mentioned key-value storage method based on non-volatile memory and solid-state hard disk provided by the present invention.
[0038] According to another aspect of the present invention, a key-value storage system is provided, comprising: a non-volatile memory, a solid-state drive, and the key-value storage controller based on the non-volatile memory and solid-state drive provided by the present invention.
[0039] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects:
[0040] The present invention can make full use of the performance of NVM and SSD, and effectively improve the key-value storage performance. Specifically, the present invention divides key-value pairs into large key-value pairs and small key-value pairs according to the size of the occupied storage space. For small key-value pairs, ordered storage is performed, and for large key-value pairs, ordered storage is not required; when performing a range query operation, it is necessary to randomly read multiple key-value pairs. For large key-value pairs, since they occupy a large storage space and are read in parallel, the corresponding reading is close to sequential reading. For small key-value pairs, since they are stored in an orderly manner, multiple key-value pairs to be read are stored in adjacent storage spaces, so that performance close to sequential reading can also be obtained. Therefore, the present invention can make full use of the characteristics of SSD's multi-threaded random read performance and sequential read performance that are not much different, and effectively improve range query performance. In addition, the present invention does not require large key-value pairs to be stored in an orderly manner, so the number of compaction operations can be effectively reduced, thereby effectively reducing write amplification and improving write performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1The overall architecture diagram of the key-value storage method provided by an embodiment of the present invention;
[0042] Figure 2 A flowchart of a write operation provided by an embodiment of the present invention;
[0043] Figure 3 A flowchart of a read operation provided by an embodiment of the present invention;
[0044] Figure 4 This is a flowchart of the compaction operation provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0045] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely for the purpose of explaining 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 may be combined with each other as long as they do not conflict with each other.
[0046] In the present invention, the terms "first", "second", etc. (if any) in the present invention and the drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0047] The overall performance of a key-value storage system is determined by the performance of key-value operations. In a key-value storage system, key-value operations include write operations, read operations, and compaction operations. Read operations include insert operations, update operations, and delete operations. Insert operations insert a key-value pair, update operations update a key-value pair, and delete operations delete a key-value pair. Read operations primarily include single-point queries and range queries. Single-point queries only search for a single key-value pair, while range queries search for key-value pairs within a specified range. Compaction operations primarily include garbage collection and sorting key-value pairs.
[0048] In order to fully utilize the performance of NVM and SSD and effectively improve the key-value storage performance when deploying the key-value storage system on a hybrid storage device composed of NVM and SSD, the present invention provides a key-value storage method and system based on non-volatile memory and solid-state drive, such as Figure 1As shown, in the present invention, the key-value pairs are first stored in the non-volatile memory and then flushed to the solid-state drive with larger capacity; small key-value pairs and large key-value pairs are stored separately, small key-value pairs are stored in S_mem, S_imm in NVM and S_kv in SSD, and large key-value pairs are stored in B_mem, B_imm in NVM and B_kv in SSD; small key-value pairs are stored in each structure in order, while large key-value pairs do not need to be stored in order; at the same time, the present invention maintains a corresponding data structure in NVM for recording the storage location of key-value pairs in NVM or SSD.
[0049] In the present invention, large key-value pairs and small key-value pairs are distinguished based on the amount of storage space occupied by the key-value pairs. Key-value pairs that occupy less than a preset threshold are classified as small key-value pairs, while key-value pairs that occupy at least the preset threshold are classified as large key-value pairs. In practical applications, the threshold for distinguishing between large and small key-value pairs should be set based on the read and write performance of the SSD in the hybrid storage device to ensure that random reads of large key-value pairs in the SSD achieve performance close to that of sequential reads.
[0050] The location record structure used to record the storage location of key-value pairs can be any data structure. To improve query performance, especially range query performance, B+ trees, skip lists, red-black trees, etc. that support range queries are preferred. Without loss of generality, the following embodiments are described using B+ trees as an example.
[0051] Based on the above concept, in the present invention, the execution process of the write operation is as follows Figure 2 As shown, the insert operation first determines the size of the key-value pair. If the key-value pair is a small key-value pair, the key-value pair is inserted into S_mem, otherwise the key-value pair is inserted into B_mem, and finally the storage location of the key-value pair is inserted into the B+ tree. If S_mem (B_mem) is full, S_mem (B_mem) is converted to S_imm (B_imm), and then S_imm (B_imm) is flushed to the solid-state drive. The delete operation will The location of the key-value pair stored in the B+ tree is directly deleted. The update operation first performs the delete operation and then the insert operation.
[0052] The execution flow of the read operation is as follows Figure 3 As shown in the figure, a single-point query finds the location of the key-value pair in the B+ tree and then reads the key-value pair at the specified location. A range query first finds the location of the key-value pair in a given range in the B+ tree, then reads the key-value pairs in parallel based on the found locations, and finally merges and sorts the read results.
[0053] The execution process of the compaction operation is as follows Figure 4As shown in the figure, after the compaction operation clears invalid key-value pairs in S_kv, it still needs to ensure that the key-value pairs in S_kv are in order. After the compaction operation clears invalid key-value pairs in B_kv, it does not need to ensure that the key-value pairs in B_kv are in order.
[0054] The following are examples.
[0055] Example 1:
[0056] A key-value storage method based on non-volatile memory and solid-state drive, such as Figure 1 Shown, including:
[0057] Pre-allocate a memory block S_mem and a storage block B_mem in the non-volatile memory for storing small key-value pairs and large key-value pairs, respectively, and create a location record structure for recording the storage location of each key-value pair in the non-volatile memory or solid-state drive; the storage space occupied by the small key-value pair is less than a preset threshold, and the storage space occupied by the large key-value pair is not less than the preset threshold;
[0058] like Figure 2 As shown, when an insert operation is received from the upper layer, the operation execution method includes:
[0059] (I1) For the key-value pair kv to be inserted i , determine its type, if it is a small key-value pair data, then go to (I2); otherwise, go to (I4);
[0060] (I2) Determine whether the current memory block S_mem is full. If so, convert the memory block S_mem into a memory block S_imm, flush it to the solid-state drive, and reallocate the memory block S_mem in the non-volatile memory, and proceed to (I3); if not, proceed directly to (I3);
[0061] In this embodiment, after the memory block S_mem is converted into the memory block S_imm, the memory block S_imm no longer receives key-value pair data;
[0062] (I3) The key-value pair kv i Insert the current memory block S_mem in order and go to (I6);
[0063] (I4) Determine whether the current memory block B_mem is full. If so, convert the memory block B_mem to the memory block B_imm, flush it to the solid-state drive, and fully allocate the memory block B_mem in the non-volatile memory, and then proceed to (I5); if not, directly proceed to (I5);
[0064] In this embodiment, after the memory block B_mem is converted into the memory block B_imm, the memory block B_imm no longer receives key-value pair data;
[0065] (I5) The key-value pair kv i Insert the current memory block B_mem and go to (I6);
[0066] (I6) Record the key-value pair kv in the location record structure i The storage location of the insert operation is completed.
[0067] It is easy to understand that after the memory block S_imm or B_imm is flushed to the solid-state drive, the storage location of each key-value pair in the B+ tree will be updated accordingly.
[0068] like Figure 2 As shown, when a delete operation is received from the upper layer, the operation execution method includes:
[0069] For the key-value pair kv to be deleted d , delete its storage location from the B+ tree and set the key-value pair kv d Mark as invalid.
[0070] In actual applications, for each newly inserted key-value pair, the corresponding version number can be written at the same time. In subsequent operations, whether the key-value pair is valid can be determined based on the version number.
[0071] like Figure 2 As shown, when an update operation is received from the upper layer, the operation execution method includes:
[0072] The original key-value pair is deleted through the delete operation, and then the new key-value pair is inserted through the insert operation.
[0073] like Figure 3 As shown, when a single-point query operation is received from the upper layer, the operation execution method includes:
[0074] For the key-value pair kv to be queried s , query its storage location from the location record structure;
[0075] Read the key-value pair kv according to the storage location s .
[0076] like Figure 3 As shown, when a range query operation is received from the upper layer, the operation execution method includes:
[0077] For the key range to be queried, the location record structure is searched to obtain the storage location of each key-value pair data within the key range, and the corresponding key-value pairs are read in parallel according to the storage location, and then merged and sorted.
[0078] like Figure 4As shown in the figure, when a compaction operation is received from the upper layer, the operation is executed in the following ways:
[0079] For the data block S_kv to be operated, perform the following steps:
[0080] (C1) Reading all key-value pairs in the data block S_kv to be operated into the volatile memory and deleting invalid key-value pairs therein;
[0081] (C2) After sorting the remaining key-value pairs according to the size of the key, the key-value pairs are divided into data blocks according to the size of the data block S_kv;
[0082] (C3) writing the divided data blocks into the data block S_kv in parallel in the solid state drive, and deleting the original data block S_kv;
[0083] For the data block B_kv to be operated, perform the following steps:
[0084] (C1′) reading all key-value pairs in the data block B_kv to be operated into the volatile memory and deleting invalid key-value pairs therein;
[0085] (C2′) dividing the remaining key-value pairs into data blocks according to the size of the data block B_kv;
[0086] (C3′) The divided data blocks are written in parallel to the data blocks B_kv in the solid state drive, and the original data blocks B_kv are deleted.
[0087] In general, since this embodiment stores large key-value pairs and small key-value pairs separately, and small key-value pairs are stored in order, while large key-value pairs do not require ordered storage, the range query operation performance and write operation performance of the key-value query system are effectively improved, thereby improving the overall performance of the key-value storage system.
[0088] Example 2:
[0089] A key-value storage controller based on non-volatile memory and solid-state drive, comprising: a computer-readable storage medium and a processor;
[0090] Computer-readable storage medium for storing computer programs;
[0091] The processor is used to read the computer program stored in the computer-readable storage medium and execute the key-value storage method based on the non-volatile memory and solid-state hard disk provided in the above embodiment 1.
[0092] Example 3:
[0093] A key-value storage system includes: a non-volatile memory, a solid-state drive, and a key-value storage controller based on the non-volatile memory and the solid-state drive provided in the above-mentioned embodiment 2.
[0094] It will be easily understood by those skilled in the art that the above description is merely 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 scope of protection of the present invention.
Claims
1. A key-value storage method based on non-volatile memory and solid-state hard disk, characterized in that: include: Pre-allocating a memory block S_mem and a storage block B_mem in the non-volatile memory for storing small key-value pairs and large key-value pairs, respectively, and creating a location record structure for recording the storage location of each key-value pair in the non-volatile memory or solid-state drive; the storage space occupied by the small key-value pairs is less than a preset threshold, and the storage space occupied by the large key-value pairs is not less than the preset threshold; When an insert operation is received from the upper layer, the operation is performed in the following ways: (I1) For the key-value pair kv to be inserted i , determine its type, if it is a small key-value pair data, then go to (I2); otherwise, go to (I4); (I2) determining whether the current memory block S_mem is full; if so, converting the memory block S_mem into a memory block S_imm, flushing it to the solid-state drive, and reallocating the memory block S_mem in the non-volatile memory, and transferring to (I3); if not, directly transferring to (I3); (I3) The key-value pair kv i Insert the current memory block S_mem in order and go to (I6); (I4) determining whether the current memory block B_mem is full; if so, converting the memory block B_mem into a memory block B_imm, flushing it to the solid-state drive, and fully allocating the memory block B_mem in the non-volatile memory, and proceeding to (I5); if not, directly proceeding to (I5); (I5) The key-value pair kv i Insert the current memory block B_mem and go to (I6); (I6) Record the key-value pair kv in the location record structure i The storage location of the insert operation is completed.
2. The key-value storage method based on non-volatile memory and solid-state drive according to claim 1, wherein: When a range query operation is received from the upper layer, the operation is executed in the following ways: For the key range to be queried, the position record structure is searched to obtain the storage location of each key-value pair data within the key range, and the corresponding key-value pairs are read in parallel according to the storage locations, and then merged and sorted.
3. The key-value storage method based on non-volatile memory and solid-state drive according to claim 2, characterized in that: The location record structure is a B+ tree, a skip list or a red-black tree.
4. The key-value storage method based on non-volatile memory and solid-state drive according to any one of claims 1 to 3, characterized in that: When a delete operation is received from the upper layer, the operation is performed in the following ways: For the key-value pair kv to be deleted d , delete its storage location from the location record structure, and the key-value pair kv d Mark as invalid.
5. The key-value storage method based on non-volatile memory and solid-state hard disk according to claim 4, characterized in that: The key-value pairs in each memory block S_imm are flushed to a data block S_kv in the solid state drive, and the key-value pairs in each memory block B_imm are flushed to a data block B_kv in the solid state drive; When a compaction operation is received from the upper layer, the operation is performed in the following ways: For the data block S_kv to be operated, perform the following steps: (C1) Reading all key-value pairs in the data block S_kv to be operated into the volatile memory and deleting invalid key-value pairs therein; (C2) After sorting the remaining key-value pairs according to the size of the key, the key-value pairs are divided into data blocks according to the size of the data block S_kv; (C3) writing the divided data blocks into the data block S_kv in parallel in the solid state drive, and deleting the original data block S_kv; For the data block B_kv to be operated, perform the following steps: (C1′) reading all key-value pairs in the data block B_kv to be operated into the volatile memory and deleting invalid key-value pairs therein; (C2′) dividing the remaining key-value pairs into data blocks according to the size of the data block B_kv; (C3′) Writing the divided data blocks into the data blocks B_kv in the solid state drive in parallel, and deleting the original data blocks B_kv.
6. The key-value storage method based on non-volatile memory and solid-state hard disk according to claim 4, characterized in that: When an update operation is received from the upper layer, the operation execution methods include: The original key-value pair is deleted through the delete operation, and then a new key-value pair is inserted through the insert operation.
7. The key-value storage method based on non-volatile memory and solid-state drive according to any one of claims 1 to 3, characterized in that: When a single-point query operation is received from the upper layer, the operation execution methods include: For the key-value pair kv to be queried s , querying its storage location from the location record structure; Read the key-value pair kv according to the storage location s .
8. A key-value storage controller based on non-volatile memory and solid-state drive, characterized in that: include: Computer-readable storage media and processor; The computer-readable storage medium is used to store a computer program; The processor is used to read the computer program stored in the computer-readable storage medium and execute the key-value storage method based on non-volatile memory and solid-state hard disk according to any one of claims 1 to 7.
9. A key-value storage system, characterized in that: include: A non-volatile memory, a solid-state drive, and a key-value storage controller based on the non-volatile memory and the solid-state drive as described in claim 8.
Citation Information
Patent Citations
Key value storage system based on NVM and SSD hybrid storage structure
CN110347336A
Method and system for reducing garbage collection and write amplification of key-value separation storage system
CN112395212A