Key-Value Pair Storage Method, Controller and System Based on Multi-Stage Dynamic Migration

By dividing data storage into multiple stages and dynamically migrating, the problem of excessive memory usage in key-value pair storage systems is solved, and efficient key-value pair updates and queries are realized, reducing write delays and read request delays.

CN116821126BActive Publication Date: 2025-07-01HUAZHONG UNIV OF SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310703337.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-14
Publication Date
2025-07-01
Estimated Expiration
2043-06-14

AI Technical Summary

Technical Problem

While the existing key-value pair storage system uses key-value pair indexes to improve update and read efficiency, it leads to excessive memory usage and may even lead to system crashes.

Method used

The key-value pair storage method of multi-stage dynamic migration is adopted to divide data storage into fast storage stage, intermediate storage stage and stable storage stage. Through the corresponding migration mechanism, the balance of index performance and memory usage is flexibly adjusted, including migrating data and indexes between memory and persistent external memory.

Benefits of technology

While improving the efficiency of key-value pair update and query, it avoids the problem of excessive memory usage, reduces write delay, improves write request processing speed, and reduces read request processing delay.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116821126B_ABST
    Figure CN116821126B_ABST
Patent Text Reader

Abstract

The present invention discloses a key-value pair storage method, a controller and a system based on multi-stage dynamic migration, belonging to the field of key-value pair storage, including: constructing three stages for storing and indexing key-value pair data, and proposing corresponding inter-stage migration mechanisms; the fast storage stage quickly stores key-value pair data in the form of logs on persistent external storage and establishes a concurrent index in memory; the intermediate storage stage stores the key-value pair indexes and data in the fast storage stage into an index tree, and each index tree includes a key range index stored in memory, a persistent index block and a persistent data block stored in persistent external storage; the stable storage stage merges multiple index trees in the intermediate storage stage into one index tree; during the operation of the system, the intensity of data migration will be adjusted according to information such as load characteristics. The present invention can dynamically adjust the balance between the key-value pair request processing speed and memory occupancy, effectively avoid excessive memory occupancy rate in the limited memory scenario, and take into account the read and write performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of key-value pair storage, and more specifically, relates to a key-value pair storage method, a controller, and a system based on multi-stage dynamic migration. Background Art

[0002] In recent years, with the development and application of information technologies such as cloud computing, big data, Internet of Things, and artificial intelligence, the amount of data has shown explosive growth. How to effectively store data and provide efficient data access services has become an important issue for existing computer storage systems.

[0003] A key-value pair storage system is a common computer storage system, and the unit for storing data is a key-value pair composed of two segments of data, namely a key and a value. The key-value pair storage system is used to store key-value pair data in a persistent storage medium for long-term preservation and provides a function of querying key-value pairs by key, mainly providing two basic interfaces: a write request and a read request. The parameter of the write request is a key and a value, which is used to store a new key-value pair or modify the corresponding value according to the key; the parameter of the read request is a key, which is used to query whether there is a key-value pair corresponding to it according to the key data. If it exists, the value data is returned.

[0004] The storage hardware platforms deployed by modern computer storage systems often include two parts: memory and external storage. Among them, the memory refers to a high-speed volatile storage device with DRAM as the medium; the external storage refers to a persistent storage device. At present, the read and write performance of new external storage devices (such as persistent memory PM, solid-state disk SSD, etc.) is continuously improving and gradually approaching the memory performance, but there is still a certain gap. In order to adapt to the high bandwidth of such external storage, existing key-value pair storage systems often build a large-scale key-value pair index in volatile memory to achieve faster update and query efficiency (Youmin Chen, Youyou Lu, Fan Yang, Qing Wang, Yang Wang, and Jiwu Shu. FlatStore: An Efficient Log-Structured Key-Value Storage Engine for Persistent Memory. ASPLOS, 2020; Lawrence Benson, Hendrik Makait, and Tilmann Rabl. Viper: An efficient hybrid pmem-dram key-value store. VLDB, 2021). However, as the amount of data written into the key-value pair storage system increases, the memory space occupied by the key-value pair index also increases. Due to the limited capacity of the volatile memory of the current hardware platform, the key-value pair index often leads to excessive memory occupation and even causes the system to crash due to running out of memory. Summary of the Invention

[0005] In view of the defects and improvement requirements of the prior art, the present invention provides a key-value pair storage method, a controller and a system based on multi-stage dynamic migration. The purpose is to establish different storage stages and corresponding migration mechanisms, so that the storage stages cooperate with each other, while improving the update and query efficiency by using key-value pair indexing, avoiding excessive memory occupation.

[0006] To achieve the above object, according to one aspect of the present invention, a key-value pair storage method based on multi-stage dynamic migration is provided, including:

[0007] Fast storage stage: After receiving a write request submitted by a user thread, write the key-value pair data to be written together with the log sequence number representing its writing order into the key-value pair log on the persistent external storage, and write the key and storage address of the key-value pair as index data into the key-value pair index in the memory;

[0008] Intermediate storage stage: When the data volume stored in the fast storage stage reaches a preset threshold a, migrate the key-value pair data stored in the current fast storage stage to an index tree, and clear the current key-value pair log and key-value pair index in the fast storage stage; The index tree includes a key range index in the memory, as well as a persistent index block and a persistent data block on the persistent external storage; The persistent data block is used to store ordered key-value pair data, and the key ranges of the persistent data blocks do not overlap; The persistent index block is used to store the minimum key and storage address of one or more persistent data blocks in the order of the keys, and the key ranges indexed by the index blocks do not overlap; The key range index is used to store the key ranges and storage addresses of each persistent index block;

[0009] Stable storage stage: When the number of index trees in the intermediate storage stage reaches a user-set threshold b, read one or more index trees in the intermediate storage stage, merge the key-value pair data stored in these index trees into the original index tree in the stable storage stage, and clear the index trees read in the intermediate storage stage.

[0010] Further, in the intermediate storage stage, migrating the key-value pair data stored in the current fast storage stage to an index tree includes the following steps:

[0011] (S1) Traverse the key-value pair index in the fast storage stage to obtain the addresses of the key-value pairs arranged in the order of keys in the key-value pair log;

[0012] (S2) Read the corresponding log records in sequence according to the addresses of the key-value pairs in the key-value pair log to obtain the key-value pair data arranged in the order of keys;

[0013] (S3) Use the key-value pair data arranged in the order of keys obtained in step (S2) to construct a persistent data block on the persistent external storage and construct a corresponding persistent index block on the persistent external storage;

[0014] (S4) Create a key range index in memory, and record the key ranges and storage addresses of the persistent index blocks created in step (S3) into the created key range index according to the key ranges, completing the migration of the key-value pair data stored in the fast storage stage to an index tree in the intermediate storage stage.

[0015] Furthermore, in the stable storage stage, after reading one or more index trees in the intermediate storage stage, merge the key-value pair data stored in these index trees into the original index tree in the stable storage stage, including the following steps:

[0016] (T1) For one or more index trees in the intermediate storage stage read, read all the persistent data blocks therein and determine the corresponding key range R k ;

[0017] (T2) Search the original index tree in the stable storage stage to read the persistent data blocks located within the key range R k inside;

[0018] (T3) Sort the key-value pair data in the persistent data blocks read in steps (T1) and (T2) according to the key and construct a new persistent data block;

[0019] (T4) Construct persistent index blocks for the persistent data blocks constructed in step (T3), and update the key ranges and storage addresses of these persistent index blocks to the key range index of the index tree in the stable storage stage;

[0020] (T5) Clear the old persistent data blocks in the index tree in the stable storage stage, and clean the data in the persistent index blocks and key range index of this index tree used to index these old persistent data blocks.

[0021] Furthermore, in step (T3), when sorting the key-value pair data in the persistent data blocks read in steps (T1) and (T2) according to the key, for any one persistent data block, if its key range does not overlap with the key ranges of other persistent data blocks, directly use this persistent data block as the new persistent data block, and the key-value pair data therein does not participate in the sorting.

[0022] Furthermore, the key-value pair storage method based on multi-stage dynamic migration provided by the present invention further includes:

[0023] When the memory occupancy rate is higher than the first threshold, reduce the threshold a;

[0024] When the read / write request ratio is higher than the second threshold, reduce the threshold b;

[0025] When the read / write request ratio is lower than the third threshold, increase the threshold a and the threshold b;

[0026] When the number of write requests within a preset time period is lower than the fourth threshold, reduce threshold a and threshold b.

[0027] Furthermore, in the fast storage stage, if there are multiple user threads submitting write requests concurrently, create independent key-value pair logs for each user thread.

[0028] Furthermore, the key-value pair storage method based on multi-stage dynamic migration provided by the present invention further includes: maintaining n log sequence number counters; n is a positive integer greater than 1, and the n log sequence number counters are numbered from 0 to n - 1 in sequence;

[0029] And, in the fast storage stage, write the key-value pair data to be written, together with the log sequence number representing its write order, into the key-value pair log on the persistent external storage, including the following steps:

[0030] (S1) Calculate the hash value of the key of the key-value pair data, and after taking the modulo with the number n of log sequence number counters, obtain the operation result i, and obtain the log sequence number from the log sequence number counter numbered i;

[0031] (S2) Write the log sequence number, as well as the key and value of the key-value pair data, as a log record into the key-value pair log to which the key-value pair data belongs, and record the corresponding storage address.

[0032] Furthermore, the key-value pair storage method based on multi-stage dynamic migration provided by the present invention further includes: processing the read requests submitted by user threads according to the following steps:

[0033] (1) Query the key-value pair index in the fast storage stage according to the key K of the key-value pair data to be read to obtain the corresponding index data. If the acquisition is successful, read the key-value pair data from the persistent external storage according to the storage address in the index data, and then transfer to step (4); otherwise, transfer to step (2);

[0034] (2) Query each index tree in the intermediate storage stage according to the key K in the order from new to old according to the generation time to obtain the corresponding key-value pair data. If the acquisition is successful, transfer to step (4); otherwise, transfer to step (3);

[0035] (3) Query the index tree in the stable storage stage according to the key K to obtain the corresponding key-value pair data. If the acquisition is successful, transfer to step (4); otherwise, determine that the read fails and the read request processing ends;

[0036] (4) Return the read key-value pair data and the read request processing ends;

[0037] For any one index tree, its query method is:

[0038] (1') Query the key range index to obtain the storage address of the persistent index block whose key range contains key K. If the acquisition is successful, read the persistent index block and proceed to step (2'); otherwise, determine that the current index tree does not contain the key-value pair data to be read, and the current index tree query ends.

[0039] (2') Obtain the storage address of the persistent data block whose key range contains key K from the persistent index block. If the acquisition is successful, read the persistent data block and proceed to step (3'); otherwise, determine that the current index tree does not contain the key-value pair data to be read, and the current index tree query ends.

[0040] (3') Query the key-value pair data in the persistent data block according to key K. If the query is successful, the current index tree query ends; otherwise, determine that the current index tree does not contain the key-value pair data to be read, and the current index tree query ends.

[0041] According to another aspect of the present invention, there is provided a key-value pair storage controller based on multi-stage dynamic migration, including: a computer-readable storage medium and a processor;

[0042] The computer-readable storage medium is used to store a computer program;

[0043] The processor is used to read the computer program stored in the computer-readable storage medium and execute the key-value pair storage method based on multi-stage dynamic migration provided by the present invention.

[0044] According to another aspect of the present invention, there is provided a storage system based on heterogeneous storage media, including: a memory, a persistent external memory, and the key-value pair storage controller based on multi-stage dynamic migration provided by the present invention.

[0045] Generally speaking, through the above technical solutions conceived by the present invention, the following beneficial effects can be achieved:

[0046] (1) The present invention divides data storage into three stages with different memory utilization rates. Each stage stores a part of the key-value pair data and the corresponding key-value pair index, and proposes a corresponding inter-stage migration mechanism to realize the migration of data in the stages, thereby flexibly adjusting the balance between index performance and memory occupancy. While making full use of the key-value pair index to improve the efficiency of key-value pair update and query, it avoids the problem of excessive memory occupancy caused by a single index structure as the data volume increases.

[0047] (2) The present invention writes all the key-value pairs written by the user into the fast storage stage. The fast storage stage stores data using the key-value pair index in memory and the key-value pair log in persistent external storage. Therefore, the latency of user writing only includes the sequential I / O time for writing log records with high efficiency and the update time for the memory index, greatly reducing the writing latency. In the preferred solution, an independent key-value pair log is allocated for each user thread, and multiple log sequence number counters are maintained, so that the writes to the external storage by different user threads are dispersed to different logs, avoiding write I / O contention, increasing parallelism, and thus achieving a significant improvement in the processing speed of write requests.

[0048] (3) When the amount of key-value pair data stored in the fast storage stage of the present invention reaches a certain threshold, the key-value pair data in the fast storage stage will be migrated to the intermediate storage stage, avoiding the decline in read and write performance caused by an overly large memory index in the fast storage stage; at the same time, by reordering the key-value pair data in the log to form an internally sorted persistent data block, the entries in the upper-level index only need to record the key range instead of individual keys, greatly reducing the scale of the index, and thus reducing the memory occupancy of the system; in addition, using the persistent index block stored in the external storage to index the persistent data block shares the task of the memory index, further reducing the memory occupancy of the system.

[0049] (4) When the number of index trees in the intermediate storage stage of the present invention reaches a certain threshold, multiple index trees in the intermediate storage stage will be merged into one index tree in the stable storage stage, reducing the number of indexes that need to be queried for read request processing, and thus reducing the processing latency of read requests. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 It is a schematic diagram of the key-value pair storage method based on multi-stage dynamic migration provided by an embodiment of the present invention;

[0051] Figure 2 It is a schematic diagram of data storage in each stage provided by an embodiment of the present invention;

[0052] Figure 3 It is a schematic diagram of the index tree structure provided by an embodiment of the present invention;

[0053] Figure 4 It is a flowchart of the key-value pair storage method based on multi-stage dynamic migration provided by an embodiment of the present invention;

[0054] Figure 5 It is a schematic diagram of the process of writing key-value pair data into the key-value pair log provided by an embodiment of the present invention;

[0055] Figure 6 It is a schematic diagram of the process of migrating from the fast storage stage to the intermediate storage stage provided by an embodiment of the present invention;

[0056] Figure 7 It is a schematic diagram of the process of migrating from the intermediate storage stage to the stable storage stage provided by the embodiment of the present invention;

[0057] Figure 8 It is a schematic diagram of the read request processing flow provided by the embodiment of the present invention. Detailed implementation manners

[0058] In order to make the objectives, technical solutions and advantages of the present invention clearer and more understandable, the present invention will be further described in detail below with reference to 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 used 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] In the present invention, the terms "first", "second", etc. (if any) in the present invention and the accompanying drawings are used to distinguish similar objects and do not necessarily need to describe a specific order or sequence.

[0060] In order to solve the technical problem that the existing key-value pair storage system will cause too high memory occupancy while improving the update and read efficiency by using key-value pair indexes, the present invention provides a key-value pair storage method, controller and system based on multi-stage dynamic migration. The overall idea is as follows: the data storage is divided into three stages with different memory utilization rates. Each stage stores a part of the key-value pair data and the corresponding key-value pair indexes, and a corresponding inter-stage migration mechanism is proposed to realize the migration of data in the stages, so as to flexibly adjust the balance between index performance and memory occupancy. While making full use of key-value pair indexes to improve the key-value pair update and query efficiency, it avoids the problem of too high memory occupancy caused by a single index structure as the data volume increases.

[0061] Generally speaking, in the following embodiments, a hardware platform with DRAM as the memory and SSD or NVM as the external memory is taken as an example for description.

[0062] Refer to Figure 1 and Figure 2 In this embodiment, the specifically divided data storage stages are: the fast storage stage, the intermediate storage stage and the stable storage stage; where:

[0063] The fast storage stage stores data through the key-value pair index in the memory and the key-value pair log in the persistent external memory. The key-value pair log is used to store the key-value pair data, and the key and storage address of the key-value pair data constitute the index data and are stored in the key-value pair index; optionally, in this embodiment, Masstree is selected as the data structure of the key-value pair index in the memory. It is a B+ tree that supports concurrent reading and writing, and supports variable-length byte keys and 8-byte values for storing address information;

[0064] In the intermediate storage stage, data is stored through one or more index trees. Refer to Figure 3 , where the index tree stores data with a key range index in memory and persistent index blocks and persistent data blocks in persistent external storage. The persistent data blocks are used to store a specified number of key-value pairs in the order of keys, and the key ranges of the persistent data blocks do not overlap; the persistent index blocks are used to store the index information of a specified number of persistent data blocks in the order of keys, and the index information of the persistent data blocks includes the minimum key and storage address of the persistent data block, and the key ranges of the persistent index blocks do not overlap; the key range index is used to store the index information of the persistent index blocks, and the index information of the persistent index blocks includes the key range and storage address of the persistent index block;

[0065] In the stable storage stage, data is stored through an index tree, and the structure of this index tree is the same as that in the intermediate storage stage, as Figure 3 shown.

[0066] As Figure 1 and Figure 2 shown, when a user thread submits a write request, the key-value pair data to be written will be written to the fast storage stage. As the number of written key-value pairs increases, the key-value pair index in memory will increase, and correspondingly, the memory occupancy rate will also increase. When the amount of key-value pair data stored in the fast storage stage exceeds the threshold a, the key-value pair data stored in the fast storage stage will be migrated as a whole to an index data in the intermediate storage stage. At the same time, the key-value pair log and key-value pair index in the fast storage stage will be cleared, avoiding the decline in read and write performance caused by the excessive memory index in the fast storage stage; since in the index tree, the key range index value in memory needs to record the key range instead of a single key, large-scale indexes are greatly reduced, thus reducing the memory occupancy rate of the system. In addition, the index tree indexes the persistent data blocks with persistent index blocks stored in external storage, sharing the task of memory indexing and further reducing the memory occupancy of the system. As the fast storage stage migrates to the intermediate storage stage, the number of index trees in the intermediate storage stage will increase accordingly. When the number of index trees in the intermediate storage stage exceeds the threshold b, all or part of the index trees in the intermediate index stage will be merged into an index tree in the stable storage stage, reducing the number of index trees in the system. Under the condition of reducing the memory occupancy rate of the key range index, the number of indexes that need to be queried for read requests is reduced, greatly reducing the processing delay of read requests.

[0067] It is easy to understand that in order to implement the above three-stage data storage and the corresponding migration between stages, in practical applications, some initialization work needs to be completed, including: creating corresponding data structures for the volatile structures (key-value pair index, key range index, etc.) and persistent structures (key-value pair log, persistent data block, persistent index block, etc.) of the three stages in volatile memory and persistent external storage; initializing the key-value pair index in the fast storage stage and recording the entry address of the key-value pair index; recording the number and entry address of the index trees in the intermediate storage stage, and initializing the number of index trees to 0; initializing the memory index of the index trees in the stable storage stage to be empty and recording its entry address, etc. To complete the migration between stages, the initialization work also includes: initializing a dedicated migration thread and a dedicated merge thread. The migration thread determines the timing of migrating from the fast storage to the intermediate storage stage in a polling manner in the background and executes the migration from the fast storage to the intermediate storage stage; the merge thread determines the actual situation of migrating from the intermediate storage stage to the stable storage stage in a polling manner in the background and executes the migration from the intermediate storage stage to the stable storage stage.

[0068] During subsequent use, the total amount of key-value pair data in the fast storage stage and the number of index trees in the intermediate storage stage will be recorded in real time.

[0069] The following are examples.

[0070] Example 1:

[0071] A key-value pair storage method based on multi-stage dynamic migration, refer to Figures 1 to 4 , including:

[0072] Fast storage stage: After receiving a write request submitted by a user thread, write the key-value pair data to be written together with the log sequence number indicating its write order to the key-value pair log on the persistent external storage, and write the key and storage address of the key-value pair as index data to the key-value pair index in memory;

[0073] Intermediate storage stage: When the amount of data stored in the fast storage stage reaches a preset threshold a, migrate the key-value pair data stored in the current fast storage stage to an index tree, and clear the current key-value pair log and key-value pair index in the fast storage stage; The index tree includes a key range index in memory, as well as a persistent index block and a persistent data block on the persistent external storage; The persistent data block is used to store ordered key-value pair data, and the key ranges of the persistent data blocks do not overlap; The persistent index block is used to store the minimum key and storage address of one or more persistent data blocks in the order of the keys, and the key ranges indexed by the index blocks do not overlap; The key range index is used to store the key ranges and storage addresses of each persistent index block;

[0074] Stable storage phase: When the number of index trees in the intermediate storage phase reaches the user-set threshold b, one or more index trees in the intermediate storage phase are read, and the key-value pair data stored in these index trees is merged into the original index tree in the stable storage phase, and the read index trees in the intermediate storage phase are cleared.

[0075] To avoid write I / O contention and increase parallelism, as a preferred implementation, in the fast storage phase of this embodiment, if multiple user threads concurrently submit write requests, independent key-value pair logs are created for each user thread, so that the writes to the external storage by different user threads are dispersed to different logs. In this embodiment, before a user thread starts to call the read / write interface, it must first call the GetClient interface once to indicate that it is a new user thread. At this time, the system will allocate independent external storage space to store the key-value pair data log of this thread; when the user thread has completed all the read / write requests it needs to issue, it needs to call the CloseClient interface. At this time, the system will recycle the allocated extra space.

[0076] To further improve the parallelism and thus improve the write request performance, on the basis of creating independent key-value pair logs for each user thread in this embodiment, multiple log sequence number counters are maintained to avoid the contention of the log sequence number counters. Let n (n>1) represent the number of log sequence number counters, and the n log sequence number counters are numbered from 0 to n-1 in sequence;

[0077] As Figure 5 shown, based on multiple logs and multiple log sequence number counters, in the fast storage phase of this embodiment, writing the key-value pair data to be written, together with the log sequence number representing its writing order, into the key-value pair log on the persistent external storage includes the following steps:

[0078] (S1) Calculate the hash value of the key of the key-value pair data, and after taking the modulo with the number n of log sequence number counters, obtain the operation result i, and obtain the log sequence number from the log sequence number counter numbered i;

[0079] (S2) Write the log sequence number, as well as the key and value of the key-value pair data, as a log record into the key-value pair log to which the key-value pair data belongs, and record the corresponding storage address.

[0080] Based on the data structure designed in this embodiment, as Figure 6 shown, in the intermediate storage phase, migrating the key-value pair data stored in the current fast storage phase to an index tree includes the following steps:

[0081] (S1) Traverse the key-value pair index in the fast storage phase to obtain the addresses of the key-value pairs arranged in key order in the key-value pair log;

[0082] (S2) Read the corresponding log records in sequence according to the addresses of the key-value pairs in the key-value pair log, and obtain the key-value pair data arranged in the order of key presses;

[0083] (S3) Use the key-value pair data arranged in the order of key presses obtained in step (S2) to construct persistent data blocks on persistent external storage, and construct corresponding persistent index blocks on persistent external storage, thereby writing the key-value pair data obtained in step (S2) to persistent external storage;

[0084] (S4) Create a key range index in memory, and record the key ranges and storage addresses of the persistent index blocks created in step (S3) according to the key ranges into the created key range index, completing the migration of the key-value pair data stored in the fast storage stage to an index tree in the intermediate storage stage.

[0085] As Figure 7 shown, in the stable storage stage, after reading one or more index trees in the intermediate storage stage, merge the key-value pair data stored in these index trees into the original index tree in the stable storage stage, including the following steps:

[0086] (T1) For one or more index trees read in the intermediate storage stage, read all the persistent data blocks therein and determine the corresponding key range R k ;

[0087] (T2) Search the original index tree in the stable storage stage to read the persistent data blocks located within the key range R k ;

[0088] (T3) Sort the key-value pair data in the persistent data blocks read in steps (T1) and (T2) according to the key, and then construct new persistent data blocks;

[0089] As a preferred implementation manner, in this embodiment, in step (T3), when sorting the key-value pair data in the persistent data blocks read in steps (T1) and (T2) according to the key, for any persistent data block, if its key range does not overlap with the key ranges of other persistent data blocks, directly use this persistent data block as the new persistent data block, and the key-value pair data therein does not participate in the sorting, thereby avoiding repeated write operations on this persistent data block and improving the merging efficiency;

[0090] (T4) Construct persistent index blocks for the persistent data blocks constructed in step (T3), and update the key ranges and storage addresses of these persistent index blocks to the key range index of the index tree in the stable storage stage;

[0091] (T5) Clear the old persistent data blocks in the index tree in the stable storage stage, and clean the data in the persistent index blocks and key range index of this index tree used to index these old persistent data blocks;

[0092] In step (T5), the specific ways to clean the persistent index blocks of the index tree in the stable storage stage and the data used to index these old persistent data blocks within the key range index include: cleaning the corresponding data in the persistent index block storing the minimum key and address information of these old persistent data blocks; if the data in a certain persistent index block is completely cleared due to this step, deleting the key range and storage address of this persistent index block stored in the key range index.

[0093] As Figure 1 、 Figure 2 、 Figure 4 and Figure 8 shown, this embodiment further includes: processing the read requests submitted by user threads according to the following steps:

[0094] (1) Query the key-value pair index in the fast storage stage according to the key K of the key-value pair data to be read to obtain the corresponding index data. If the acquisition is successful, read the key-value pair data from the persistent external storage according to the storage address in the index data, and then transfer to step (4); otherwise, transfer to step (2);

[0095] (2) Query each index tree in the intermediate storage stage according to the key K in the order from new to old according to the generation time to obtain the corresponding key-value pair data. If the acquisition is successful, transfer to step (4); otherwise, transfer to step (3);

[0096] (3) Query the index tree in the stable storage stage according to the key K to obtain the corresponding key-value pair data. If the acquisition is successful, transfer to step (4); otherwise, determine that the read fails and the read request processing ends;

[0097] (4) Return the read key-value pair data and the read request processing ends;

[0098] For any index tree, its query method is:

[0099] (1') Query the key range index to obtain the persistent index block whose key range contains the key K. If the acquisition is successful, read this persistent index block and transfer to step (2'); otherwise, determine that the current index tree does not contain the key-value pair data to be read and the current index tree query ends;

[0100] (2') Obtain the storage address of the persistent data block whose key range contains the key K from the persistent index block. If the acquisition is successful, read this persistent data block and transfer to step (3'); otherwise, determine that the current index tree does not contain the key-value pair data to be read and the current index tree query ends;

[0101] (3') Query the storage address of the key-value pair data in the persistent data block according to the key K. If the query is successful, the current index tree query ends; otherwise, it is determined that the current index tree does not contain the key-value pair data to be read, and the current index tree query ends.

[0102] The migration between data storage phases will consume system resources, and the number of index trees will affect the processing performance of read requests. In practical applications, the threshold for triggering the migration between data storage phases can be set accordingly according to the characteristics of the load. Therefore, in the default configuration of this embodiment, a = 10000000 and b = 2, that is, when the number of key-value pair data stored in the fast storage phase reaches 10000000, the migration from the fast storage phase to the intermediate storage phase will be triggered, and when the number of index trees in the intermediate storage phase reaches 2, the migration from the intermediate storage phase to the stable storage phase will be triggered.

[0103] Considering that in practical applications, the load may change dynamically. To adapt to the load change and ensure high read and write request processing performance, this embodiment will dynamically adjust the threshold according to the load characteristics, as follows:

[0104] When the memory occupancy rate is higher than the first threshold, reduce the threshold a; when the memory occupancy rate is high, it means that the memory required by other user requests is high. At this time, reducing the threshold a can reduce the memory occupancy in the fast storage phase to meet the needs of normal user requests. Optionally, in this embodiment, the first threshold is 50%, and when the memory occupancy rate is higher than 50%, the threshold a will be halved;

[0105] When the read / write request ratio is higher than the second threshold, reduce the threshold b; when the read / write request ratio is high, it means that the current load is mainly read requests. Since the fewer the number of index trees in the system, the better the read request processing performance. At this time, reducing the threshold b can reduce the number of index trees and ensure high read request processing performance. Optionally, in this embodiment, the second threshold is 4:1, and when the read / write request ratio exceeds 4:1, the threshold b will be set to 1;

[0106] When the read / write request ratio is lower than the third threshold, increase the threshold a and the threshold b; when the read / write request ratio is low, it means that the current load is mainly write requests. Since write requests require more system resources, at this time, increasing the threshold a and b can reduce the frequency of migration between storage phases, thereby reducing the system resources occupied by data migration, reserving resources for user write requests, and reducing the write amplification of data migration from the intermediate storage phase to the stable storage phase to ensure high write request performance. Optionally, in this embodiment, the third threshold is 1:4. When the read / write request ratio is lower than 1:4, the threshold a will be continuously increased until it reaches the default value of 20000000, and the threshold b will be set to 4;

[0107] When the number of write requests within a preset time period is lower than the fourth threshold, reduce threshold a and threshold b; when the number of write requests is very small within the preset time period, there will be a large amount of idle system resources. At this time, reducing threshold a and b can quickly complete the data migration in the first two stages to the stable storage stage without affecting normal user requests.

[0108] It is easy to understand that the above thresholds and the specific adjustment degree are only for illustrative purposes and should not be construed as the sole limitation of the present invention. In actual applications, they can be adjusted in real time according to specific load characteristics.

[0109] Embodiment 2:

[0110] A key-value pair storage controller based on multi-stage dynamic migration includes: a computer-readable storage medium and a processor;

[0111] The computer-readable storage medium is used to store a computer program;

[0112] The processor is used to read the computer program stored in the computer-readable storage medium and execute the key-value pair storage method based on multi-stage dynamic migration provided in the above Embodiment 1.

[0113] Embodiment 3:

[0114] A storage system based on heterogeneous storage media includes: a memory, a persistent external memory, and the key-value pair storage controller based on multi-stage dynamic migration provided in the above Embodiment 2.

[0115] Those skilled in the art can easily understand that the above are only the preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, and improvements made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A key-value pair storage method based on multi-stage dynamic migration, characterized in that, Including: Fast storage stage: After receiving a write request submitted by a user thread, write the key-value pair data to be written, along with the log sequence number representing its write order, to the key-value pair log on persistent external storage, and write the key and storage address of the key-value pair as index data to the key-value pair index in memory; Intermediate storage stage: When the amount of data stored in the fast storage stage reaches the preset threshold a, migrate the key-value pair data stored in the current fast storage stage to an index tree, and clear the current key-value pair log and key-value pair index in the fast storage stage; the index tree includes a key range index in memory, as well as persistent index blocks and persistent data blocks on persistent external storage; the persistent data blocks are used to store ordered key-value pair data, and the key ranges of the persistent data blocks do not overlap; the persistent index blocks are used to store the minimum key and storage address of one or more persistent data blocks in the order of the keys, and the key ranges indexed by the index blocks do not overlap; the key range index is used to store the key ranges and storage addresses of each persistent index block; Stable storage stage: When the number of index trees in the intermediate storage stage reaches the user-set threshold b, read one or more index trees in the intermediate storage stage, merge the key-value pair data stored in these index trees into the original index tree in the stable storage stage, and clear the index trees read in the intermediate storage stage.

2. The key-value pair storage method based on multi-stage dynamic migration according to claim 1, wherein In the intermediate storage stage, migrating the key-value pair data stored in the current fast storage stage to an index tree includes the following steps: (S1) Traverse the key-value pair index in the fast storage stage to obtain the addresses of the key-value pairs arranged in key order in the key-value pair log; (S2) Read the corresponding log records in sequence according to the addresses of the key-value pairs in the key-value pair log to obtain the key-value pair data arranged in key order; (S3) Use the key-value pair data arranged in key order obtained in step (S2) to construct a persistent data block on persistent external storage, and construct a corresponding persistent index on persistent external storage; (S4) Create a key range index in memory, and record the key ranges and storage addresses of the persistent index blocks created in step (S3) in the created key range index according to the key ranges, completing the migration of the key-value pair data stored in the fast storage stage to an index tree in the intermediate storage stage.

3. The key-value pair storage method based on multi-stage dynamic migration according to claim 2, characterized in that, In the stable storage stage, after reading one or more index trees in the intermediate storage stage, merging the key-value pair data stored in these index trees into the original index tree in the stable storage stage includes the following steps: (T1) For one or more index trees in the read intermediate storage stage, read all persistent data blocks therein and determine the corresponding key range R k ; (T2) Search the original index tree in the stable storage phase to read the persistent data blocks within the key range R k ; (T3) Sort the key-value pair data in the persistent data blocks read in steps (T1) and (T2) according to the keys, and construct a new persistent data block; (T4) Construct persistent index blocks for the persistent data blocks constructed in step (T3), and update the key ranges and storage addresses of these persistent index blocks to the key range index of the index tree in the stable storage stage; (T5) Clear the old persistent data blocks in the index tree in the stable storage stage, and clean the data in the persistent index blocks and key range index of the index tree used to index these old persistent data blocks.

4. The key-value pair storage method based on multi-stage dynamic migration according to claim 3, wherein, In the step (T3), when sorting the key-value pair data in the persistent data blocks read in steps (T1) and (T2) according to the keys, for any persistent data block, if its key range does not overlap with the key ranges of other persistent data blocks, then directly use this persistent data block as a new persistent data block, and the key-value pair data therein does not participate in the sorting.

5. The key-value pair storage method based on multi-stage dynamic migration according to any one of claims 1 to 4, characterized in that, It further includes: When the memory occupancy rate is higher than the first threshold, reduce the threshold a; When the read / write request ratio is higher than the second threshold, reduce the threshold b; When the read / write request ratio is lower than the third threshold, increase the threshold a and the threshold b; When the number of write requests within a preset time period is lower than the fourth threshold, reduce the threshold a and the threshold b.

6. The key-value pair storage method based on multi-stage dynamic migration according to any one of claims 1 to 4, characterized in that, In the fast storage stage, if there are multiple user threads concurrently submitting write requests, create independent key-value pair logs for each user thread.

7. The key-value pair storage method based on multi-stage dynamic migration according to claim 6, wherein, It further includes: Maintain n log sequence number counters; n is a positive integer greater than 1, and the n log sequence number counters are numbered from 0 to n - 1 in sequence; Moreover, in the fast storage stage, writing the key-value pair data to be written together with the log sequence number representing its writing order into the key-value pair log on the persistent external storage includes the following steps: (S1) Calculate the hash value of the key of the key-value pair data, and after taking the modulus with the number n of log sequence number counters, obtain the operation result i, and obtain the log sequence number from the log sequence number counter numbered i; (S2) Write the log sequence number, as well as the key and value of the key-value pair data, as a log record into the key-value pair log to which the key-value pair data belongs, and record the corresponding storage address.

8. The key-value pair storage method based on multi-stage dynamic migration according to any one of claims 1 to 4, characterized in that It further includes: Processing the read requests submitted by user threads according to the following steps: (1) Query the key-value pair index in the fast storage stage according to the key K of the key-value pair data to be read to obtain the corresponding index data. If the acquisition is successful, then read the key-value pair data from the persistent external storage according to the storage address in the index data, and then go to step (4); otherwise, go to step (2); (2) Query each index tree in the intermediate storage stage according to the key K in the order from new to old according to the generation time to obtain the corresponding key-value pair data. If the acquisition is successful, then go to step (4); otherwise, go to step (3); (3) Query the index tree in the stable storage stage according to the key K to obtain the corresponding key-value pair data. If the acquisition is successful, then go to step (4); otherwise, determine that the read fails and the read request processing ends; (4) Return the read key-value pair data and the read request processing ends; For any index tree, its query method is: (1') Query the key range index to obtain the storage address of the persistent index block whose key range contains the key K. If the acquisition is successful, then read this persistent index block and go to step (2'); otherwise, determine that the current index tree does not contain the key-value pair data to be read and the current index tree query ends; (2') Obtain the storage address of the persistent data block whose key range contains the key K from the persistent index block. If the acquisition is successful, then read this persistent data block and go to step (3'); otherwise, determine that the current index tree does not contain the key-value pair data to be read and the current index tree query ends; (3') Query the key-value pair data in the persistent data block according to the key K. If the query is successful, the current index tree query ends; otherwise, it is determined that the current index tree does not contain the key-value pair data to be read, and the current index tree query ends.

9. A key-value pair storage controller based on multi-stage dynamic migration, characterized in that, Comprising: A computer-readable storage medium and a 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 pair storage method based on multi-stage dynamic migration according to any one of claims 1 to 8.

10. A storage system based on heterogeneous storage media, characterized in that, Comprising: A memory, a persistent external memory, and the key-value pair storage controller based on multi-stage dynamic migration according to claim 9.

Citation Information

Patent Citations

  • Storage engine caching method and system based on ART tree

    CN114218272A

  • Data processing method and device, equipment and storage medium

    CN115544003A