A caching method, apparatus, and device for a storage system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-26
- Publication Date
- 2026-08-14
AI Technical Summary
对于LSM-Tree而言,在冷启动阶段,由于数据分散在多个层级的存储结构中,热点数据的识别和缓存变得困难,可能导致较低的缓存命中率
[0033]本发明所提供的一种存储系统的缓存方法、装置及设备,构建的缓存系统包括双层的缓存架构以及缓存大小调节器;相比于现有的应用在基于LSM-Tree的存储系统上的缓存模型来说,缓存的粒度更细。传统块缓存的大小是固定的,如果一个块中只有部分数据被访问了,那么整个块都会被缓存,这样会导致缓存空间的浪费。本发明是基于多粒度的,分为块缓存和组缓存,当块缓存中的热数据小于一个阈值的时,将会退化成组缓存。一定程度上提升了缓存的利用率。与此同时,还会根据LSM-Tree的高度动态分配缓存内存;在LSM-tree存储引擎中,传统的缓存替换机制(如LRU、LFU)无法有效应对以表为粒度的统计和访问信息,因为后台的操作(如flush和compaction)会破坏原有的统计信息,导致无法预测访问信息,从而产生缓存失效问题。这个问题会导致LSM-tree存储引擎性能抖动,影响系统的稳定性和用户的访问体验。本发明通过人工只能算法预测将要访问的数据,提前将它放入缓存中,减少缓存失效率。
Smart Images

Figure CN117270778B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data caching, and in particular to a caching method, apparatus, and device for a storage system. Background Technology
[0002] LSM-tree-based storage systems currently use traditional caching algorithms, such as LevelDB and RocksDB, which use the LRU algorithm. However, traditional caching methods (such as LRU, LFU, FIFO, etc.) have some drawbacks and challenges. Traditional caching methods struggle to accurately capture data access patterns and hot data within an LSM-tree. Due to the multi-level storage structure of LSM-trees and the impact of write and merge operations, data access frequency and popularity can change drastically at different times. Traditional caching methods, primarily based on the Least Recently Used (LRU) principle, cannot flexibly adapt to such changes, potentially leading to cache inconsistency and impacting query performance. Traditional caching methods require pre-specifying the cache size. However, the data size at each level of an LSM-tree can change dynamically, and the access frequency and characteristics of data at different levels differ. Therefore, choosing an appropriate cache size becomes difficult; setting it too small may result in cache misses and decreased query performance, while setting it too large may lead to memory waste and cache inconsistency. Caching methods typically rely on the presence of hot data to improve the hit rate. For LSM-Tree, during the cold start phase, the identification and caching of hot data becomes difficult because the data is scattered across multiple levels of storage structure, which may result in a low cache hit rate.
[0003] Based on the above problems, there is an urgent need to provide a method or system to solve the problem of low cache utilization in LSM-Tree-based storage systems. Summary of the Invention
[0004] The purpose of this invention is to provide a caching method, apparatus, and device for a storage system, which can improve the cache utilization of an LSM-Tree-based storage system.
[0005] To achieve the above objectives, the present invention provides the following solution:
[0006] A caching method for a storage system, comprising:
[0007] A caching system is constructed, comprising a two-layer caching architecture and a cache size adjuster. The two-layer caching architecture includes a block cache and a group cache. The block cache uses a hash table as its data structure, with the unique identifier of the data block as the key and the data block itself as the value stored in the hash table. The group cache uses a hash table and a doubly linked list as its data structures. The hash table is used for fast data lookup, and the linked list is used for data storage and access. The cache size adjuster dynamically adjusts the cache space of the block cache and the group cache based on the memory usage collected by the collector and the system I / O load.
[0008] A prefetcher is constructed using the XGBOOST algorithm; the prefetcher takes the user's access data, time, and system load as inputs, and the predicted range of data keys to be accessed as output.
[0009] Users interact with the storage engine through the interfaces exposed by the storage engine;
[0010] When the read process first looks up data in the cache system, the cache system uses the collector and cache size adjuster to dynamically adjust the cache space of the block cache and group cache; at the same time, the prefetcher fetches data from the storage engine according to the predicted range of data keys to be accessed and puts it into the cache system.
[0011] If data is found in the cache from the caching system, then the data is returned directly from the cache.
[0012] If the cache is not hit in the caching system, the data is retrieved directly from the storage engine.
[0013] A cache device for a storage system, comprising:
[0014] A caching system building unit is used to construct a caching system. The caching system includes a two-layer caching architecture and a cache size adjuster. The two-layer caching architecture includes a block cache and a group cache. The block cache uses a hash table as its data structure, with the unique identifier of the data block as the key and the data block itself as the value stored in the hash table. The group cache uses a hash table and a doubly linked list as its data structures. The hash table is used for fast data lookup, and the linked list is used for data storage and access. The cache size adjuster dynamically adjusts the cache space of the block cache and the group cache based on the memory usage rate collected by the collector and the system I / O load.
[0015] A prefetcher construction unit is used to construct a prefetcher using the XGBOOST algorithm; the prefetcher takes the user-accessed data, time, and system load as inputs, and the predicted range of data keys to be accessed as outputs;
[0016] The interaction unit is used for users to interact with the storage engine through the interfaces exposed by the storage engine;
[0017] The read unit is used when the read process first looks up data in the cache system. The cache system uses the collector and cache size adjuster to dynamically adjust the cache space of the block cache and group cache. At the same time, the prefetcher fetches data from the storage engine according to the predicted range of data keys to be accessed and puts it into the cache system.
[0018] Returns a data unit, used to return data directly from the cache if data is hit in the cache system;
[0019] The data retrieval unit is used to retrieve data directly from the storage engine if the cache is not hit in the caching system.
[0020] A caching device for a storage system, applied to a caching method for the aforementioned storage system, includes: a collector, a caching system, a model trainer, and a prefetcher module;
[0021] The collector is connected to both the cache system and the prefetcher module; the model trainer is connected to the prefetcher module; the prefetcher module is connected to the cache system; and the cache system is connected to the marine storage engine.
[0022] Optionally, the caching system includes: a block cache, a set cache, and a cache size adjuster;
[0023] Block cache is used to store block cache hash tables and linked lists, and to store and locate block caches. When the hot data in the block cache is less than a threshold, it degenerates into group cache. At the same time, it accepts instructions from the cache size adjuster to dynamically adjust the size of the cache.
[0024] The group cache is used to store the block cache hash table and linked list, and to store and locate the block cache; at the same time, it accepts instructions from the cache size adjuster to dynamically adjust the size of the cache.
[0025] The cache size adjuster is used to receive data from the collector, send adjustment parameters to the block cache and group cache, and dynamically adjust the cache size.
[0026] Optionally, the prefetcher module includes: a prefetcher and a prefetch notification;
[0027] The prefetch notification is used to sense whether the storage engine has undergone flush and compaction operations, and then notify the prefetcher to perform a prefetch operation based on the sensing result.
[0028] The prefetcher is used to receive prefetch information and retrieve data from the storage engine to write to the cache. It also receives information from the collector to dynamically adjust the size of the prefetch cache.
[0029] Optionally, the model trainer uses the XGBOOST algorithm to train the model based on the host load data collected by the collector and the IO data of the storage system.
[0030] An electronic device includes a memory and a processor, the memory being used to store a computer program, and the processor running the computer program to cause the electronic device to perform a caching method of a storage system.
[0031] Optionally, the memory is a computer-readable storage medium.
[0032] According to specific embodiments provided by the present invention, the present invention discloses the following technical effects:
[0033] This invention provides a caching method, apparatus, and device for a storage system. The constructed caching system includes a two-layer caching architecture and a cache size adjuster. Compared to existing caching models applied to LSM-Tree-based storage systems, the caching granularity is finer. Traditional block caches have a fixed size; if only part of the data in a block is accessed, the entire block is cached, leading to wasted cache space. This invention is multi-granular, divided into block cache and group cache. When the amount of hot data in the block cache is less than a certain threshold, it will degenerate into a group cache, improving cache utilization to some extent. Simultaneously, cache memory is dynamically allocated based on the LSM-Tree height. In LSM-tree storage engines, traditional cache replacement mechanisms (such as LRU and LFU) cannot effectively handle table-level statistics and access information because background operations (such as flush and compaction) can destroy existing statistics, leading to unpredictable access information and cache invalidation. This problem causes performance fluctuations in the LSM-tree storage engine, affecting system stability and user experience. This invention uses artificial intelligence algorithms to predict the data to be accessed and puts it into the cache in advance, reducing cache miss rate. Attached Figure Description
[0034] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0035] Figure 1 This is a schematic diagram of a caching method for a storage system provided by the present invention;
[0036] Figure 2 This is a schematic diagram of the cache device structure of a storage system provided by the present invention;
[0037] Figure 3 This is a schematic diagram of the cache system architecture;
[0038] Figure 4 This is a schematic diagram of the prefetcher module. Detailed Implementation
[0039] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0040] The purpose of this invention is to provide a caching method, apparatus, and device for a storage system, which can improve the cache utilization of LSM-Tree-based storage systems.
[0041] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0042] like Figure 1 As shown, the caching method for a storage system provided by the present invention includes:
[0043] S101, Construct a caching system; the caching system includes a two-layer caching architecture and a cache size adjuster; the two-layer caching architecture includes a block cache and a group cache; the block cache uses a hash table as a data structure, with the unique identifier of the data block as the key and the data block itself as the value stored in the hash table; the group cache uses a hash table and a doubly linked list as data structures; the hash table is used for fast data lookup, and the linked list is used for storing and accessing data; the cache size adjuster is used to dynamically adjust the cache space of the block cache and the group cache according to the memory usage rate collected by the collector and the system I / O load.
[0044] The caching system designed in this invention is a two-layer caching architecture: the first layer is a block cache, and the second layer is a group cache. When data needs to be retrieved, it is first retrieved from the group cache. Data that is not found (does not exist) is then retrieved from the block cache, and the entire block of data is loaded.
[0045] Block caching: Block caching uses a hash table as its data structure, with the unique identifier of each data block as the key and the data block itself as the value. The block header records the number of frequently accessed data entries and the total number of entries, allowing for the assessment of the block's popularity. Based on the popularity of data in the block cache, if the ratio of frequently accessed data falls below a certain threshold, the block cache will automatically degrade to a set cache, saving significant memory resources.
[0046] Group Cache Construction: The group cache uses a hash table and a doubly linked list as its data structures. The hash table is used for fast data lookup, and the linked list is used for data storage and access. Each group's header information stores the range of keys, allowing for quick and rough location of data. The group cache can be viewed as a block cache that has removed useless data, saving memory and simplifying management.
[0047] An adaptive cache size adjustment mechanism is used. The maximum capacity of the block cache and set data cache is determined based on system resources and performance requirements. By monitoring cache hit rates and system I / O metrics, the maximum capacity of these two cache types is dynamically adjusted to optimize performance.
[0048] S102, a prefetcher is constructed using the XGBOOST algorithm. The prefetcher takes the user's access data, time, and system load as input, and the predicted range of data keys to be accessed as output. Model training is performed based on the host load data collected by the collector and the IO data of the storage system. Each time a data update or merge operation occurs, the data that may be used is pre-loaded into the cache, which greatly improves the cache hit rate.
[0049] S103, users interact with the storage engine through the interfaces exposed by the storage engine;
[0050] S104, when the read process first looks up data in the cache system, the cache system uses the collector and cache size adjuster to dynamically adjust the cache space of the block cache and group cache; at the same time, the prefetcher fetches data from the storage engine according to the predicted range of data keys to be accessed and puts it into the cache system.
[0051] S105, if data is found in the cache from the caching system, then the data is returned directly from the cache;
[0052] S106 If the cache is not hit in the caching system, the data is retrieved directly from the storage engine.
[0053] As another specific embodiment, the present invention provides a cache device for a storage system, comprising:
[0054] A caching system building unit is used to construct a caching system. The caching system includes a two-layer caching architecture and a cache size adjuster. The two-layer caching architecture includes a block cache and a group cache. The block cache uses a hash table as its data structure, with the unique identifier of the data block as the key and the data block itself as the value stored in the hash table. The group cache uses a hash table and a doubly linked list as its data structures. The hash table is used for fast data lookup, and the linked list is used for data storage and access. The cache size adjuster dynamically adjusts the cache space of the block cache and the group cache based on the memory usage rate collected by the collector and the system I / O load.
[0055] A prefetcher construction unit is used to construct a prefetcher using the XGBOOST algorithm; the prefetcher takes the user-accessed data, time, and system load as inputs, and the predicted range of data keys to be accessed as outputs;
[0056] The interaction unit is used for users to interact with the storage engine through the interfaces exposed by the storage engine;
[0057] The read unit is used when the read process first looks up data in the cache system. The cache system uses the collector and cache size adjuster to dynamically adjust the cache space of the block cache and group cache. At the same time, the prefetcher fetches data from the storage engine according to the predicted range of data keys to be accessed and puts it into the cache system.
[0058] Returns a data unit, used to return data directly from the cache if data is hit in the cache system;
[0059] The data retrieval unit is used to retrieve data directly from the storage engine if the cache is not hit in the caching system.
[0060] like Figure 2 As shown, the present invention also provides a caching device for a storage system, applied to the caching method of the aforementioned storage system, comprising: a collector, a caching system, a model trainer, and a prefetcher module;
[0061] The collector is connected to both the cache system and the prefetcher module; the model trainer is connected to the prefetcher module; the prefetcher module is connected to the cache system; and the cache system is connected to the marine storage engine.
[0062] like Figure 3 As shown, the caching system includes: block cache, set cache, and cache size adjuster;
[0063] Block cache is used to store block cache hash tables and linked lists, and to store and locate block caches. When the hot data in the block cache is less than a threshold, it degenerates into group cache. At the same time, it accepts instructions from the cache size adjuster to dynamically adjust the size of the cache.
[0064] The group cache is used to store the block cache hash table and linked list, and to store and locate the block cache; at the same time, it accepts instructions from the cache size adjuster to dynamically adjust the size of the cache.
[0065] The cache size adjuster is used to receive data from the collector, send adjustment parameters to the block cache and group cache, and dynamically adjust the cache size.
[0066] like Figure 4 As shown, the prefetcher module includes: a prefetcher and a prefetch notification;
[0067] The prefetch notification is used to sense whether the storage engine has undergone flush and compaction operations, and then notify the prefetcher to perform a prefetch operation based on the sensing result.
[0068] The prefetcher is used to receive prefetch information and retrieve data from the storage engine to write to the cache. It also receives information from the collector to dynamically adjust the size of the prefetch cache.
[0069] The model trainer uses the XGBOOST algorithm to train the model based on the host load data collected by the data acquisition unit and the IO data of the storage system. The model trainer is mainly responsible for training the model and consists of several modules, including data cleaning, feature extraction, and model training. The data cleaning module filters out some dirty data from the training data, and then performs feature extraction. We used common read / write features and timestamp features, and trained the model using the XGBOOST algorithm.
[0070] In order to execute the methods corresponding to the above embodiments and achieve the corresponding functions and technical effects, the present invention also provides an electronic device, including a memory and a processor, wherein the memory is used to store a computer program, and the processor runs the computer program to enable the electronic device to execute the caching method of the storage system described above.
[0071] The memory is a computer-readable storage medium.
[0072] Based on the above description, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned computer storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory, random access memory, magnetic disks, or optical disks.
[0073] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the systems disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant parts can be referred to the method section.
[0074] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. Furthermore, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A caching method for a storage system, characterized in that, include: Construct a caching system; the caching system includes a two-layer caching architecture and a cache size adjuster; the two-layer caching architecture includes block cache and group cache; The block cache uses a hash table as its data structure, with the unique identifier of the data block as the key and the data block itself as the value stored in the hash table; the group cache uses a hash table and a doubly linked list as its data structure; the hash table is used for fast data lookup, and the linked list is used for data storage and access; the cache size adjuster is used to dynamically adjust the cache space of the block cache and the group cache according to the memory usage rate collected by the collector and the system I / O load. A prefetcher is constructed using the XGBOOST algorithm; the prefetcher takes the user's access data, time, and system load as inputs, and the predicted range of data keys to be accessed as output. Users interact with the storage engine through the interfaces exposed by the storage engine; When the read process first looks up data in the cache system, the cache system uses the collector and cache size adjuster to dynamically adjust the cache space of the block cache and group cache; at the same time, the prefetcher fetches data from the storage engine according to the predicted range of data keys to be accessed and puts it into the cache system. If data is found in the cache from the caching system, then the data is returned directly from the cache. If the cache is not hit in the caching system, the data is retrieved directly from the storage engine.
2. A cache device for a storage system, characterized in that, include: A caching system building unit is used to construct a caching system. The caching system includes a two-layer caching architecture and a cache size adjuster. The two-layer caching architecture includes a block cache and a group cache. The block cache uses a hash table as its data structure, with the unique identifier of the data block as the key and the data block itself as the value stored in the hash table. The group cache uses a hash table and a doubly linked list as its data structures. The hash table is used for fast data lookup, and the linked list is used for data storage and access. The cache size adjuster dynamically adjusts the cache space of the block cache and the group cache based on the memory usage rate collected by the collector and the system I / O load. A prefetcher construction unit is used to construct a prefetcher using the XGBOOST algorithm; the prefetcher takes the user-accessed data, time, and system load as inputs, and the predicted range of data keys to be accessed as outputs; The interaction unit is used for users to interact with the storage engine through the interfaces exposed by the storage engine; The read unit is used when the read process first looks up data in the cache system. The cache system uses the collector and cache size adjuster to dynamically adjust the cache space of the block cache and group cache. At the same time, the prefetcher fetches data from the storage engine according to the predicted range of data keys to be accessed and puts it into the cache system. Returns a data unit, used to return data directly from the cache if data is hit in the cache system; The data retrieval unit is used to retrieve data directly from the storage engine if the cache is not hit in the caching system.
3. A caching device for a storage system, applied to the caching method of the storage system as described in claim 1, characterized in that, include: Acquisition module, caching system, model trainer, and prefetcher module; The collector is connected to both the cache system and the prefetcher module; the model trainer is connected to the prefetcher module; the prefetcher module is connected to the cache system; and the cache system is connected to the marine storage engine.
4. A cache device for a storage system according to claim 3, characterized in that, The caching system includes: block cache, set cache, and cache size adjuster; Block cache is used to store block cache hash tables and linked lists, and to store and locate block caches. When the hot data in the block cache is less than a threshold, it degenerates into group cache. At the same time, it accepts instructions from the cache size adjuster to dynamically adjust the size of the cache. The group cache is used to store the block cache hash table and linked list, and to store and locate the block cache; at the same time, it accepts instructions from the cache size adjuster to dynamically adjust the size of the cache. The cache size adjuster is used to receive data from the collector, send adjustment parameters to the block cache and group cache, and dynamically adjust the cache size.
5. A cache device for a storage system according to claim 3, characterized in that, The prefetcher module includes: a prefetcher and a prefetch notification; The prefetch notification is used to sense whether the storage engine has undergone flush and compaction operations, and then notify the prefetcher to perform a prefetch operation based on the sensing result. The prefetcher is used to receive prefetch information and retrieve data from the storage engine to write to the cache. It also receives information from the collector to dynamically adjust the size of the prefetch cache.
6. A cache device for a storage system according to claim 3, characterized in that, The model trainer uses the XGBOOST algorithm to train the model based on the host load data collected by the collector and the IO data of the storage system.
7. An electronic device, characterized in that, The device includes a memory and a processor, the memory being used to store a computer program, and the processor running the computer program to cause the electronic device to perform a caching method for a storage system according to any one of claims 1.
8. An electronic device according to claim 7, characterized in that, The memory is a computer-readable storage medium.
Citation Information
Patent Citations
Distributed storage cache management method and system, storage medium and equipment
CN114817195A
Optimized self-designing key-value storage engine
US11563803B1