Data caching method, computer device, storage medium and program product

By introducing window cache and preset hash data structures in the storage system, the usage of SSDs is optimized, and the problems of SSD storage cost and service life in the prior art are solved, and more efficient data caching and storage are achieved.

CN119322593BActive Publication Date: 2025-04-29INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411866828.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-18
Publication Date
2025-04-29
Estimated Expiration
2044-12-18

AI Technical Summary

Technical Problem

In the prior art, whether the data is cold or hot data, it will be written to the SSD first, resulting in a reduction in the additional storage cost and the service life of the SSD.

Method used

By introducing window cache and preset hash data structures in the system, the data is first written to the window cache. When the window cache has used capacity reaches the threshold, non-hotspot data are eliminated and hotspot data is cached to the main cache SSD.

Benefits of technology

Reduces the number of times the SSD is erased, extends the service life of the SSD, and improves the overall performance and cache hit rate of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119322593B_ABST
    Figure CN119322593B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of distributed storage technology, and discloses a data cache method, a computer device, a storage medium and a program product. The method includes: obtaining the name of an object to be read and the data range to be read of the object to be read; judging whether there is a key value identical to the name of the object to be read in a preset hash data structure; if not, reading the corresponding data from the system main memory based on the data range to be read, returning it to the client, and updating the preset hash data structure and the window cache; judging whether the ratio of the used capacity to the total capacity of the window cache exceeds a first ratio threshold; if exceeded, obtaining the first eliminated cache object in the window cache; obtaining the number of accesses to the first eliminated cache object, and filtering out the target cache object whose access number is greater than the number of accesses to the tail cache object of the first linked list in the main cache from the first eliminated cache object; caching the target cache object to the main cache. The present invention improves the service life of a solid state drive.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of distributed storage technology, and in particular to a data caching method, a computer device, a storage medium and a program product. Background Art

[0002] In a storage system that uses a mechanical hard disk (HHD) as the main storage disk, a high-speed solid state disk (SSD) or NVME SSD is usually used as a cache. By caching hot data in the SSD, it can be directly obtained from the SSD when reading hot data, thereby reducing response time and improving throughput.

[0003] In the related art, there are two ways to manage cached hot data in SSD. One is to manage cached hot data using the least recently used algorithm (Least Recently Used, referred to as: LRU). The other is to manage cached hot data using the least frequently used algorithm (LFU).

[0004] However, these two methods of managing hot data cached in SSDs will first write the data to the SSD regardless of whether the data is cold data or hot data. Writing cold data to the SSD brings additional storage costs without obvious system performance benefits, which seriously affects the service life of the SSD. Summary of the invention

[0005] In view of this, the present invention provides a data caching method, a computer device, a storage medium and a program product to solve the problem in the related art that no matter whether the data is cold data or hot data, it will be written into the SSD first, and writing cold data into the SSD brings additional storage cost and has no obvious system performance benefit, which seriously affects the service life of the SSD.

[0006] In a first aspect, the present invention provides a data caching method, the method comprising:

[0007] In response to a data reading request from a client, obtaining a name of an object to be read and a range of data to be read of the object to be read;

[0008] Determine whether there is a key value identical to the name of the object to be read in the preset hash data structure;

[0009] If not, the corresponding data is read from the system main memory based on the data range to be read, and returned to the client, and the preset hash data structure and window cache are updated based on the name of the object to be read, the data range to be read and the read data;

[0010] At each preset time interval, determining whether the ratio of the used capacity to the total capacity of the window cache exceeds a first ratio threshold;

[0011] If the ratio of the used capacity to the total capacity of the window cache exceeds a first ratio threshold, obtaining a first eliminated cache object in the window cache;

[0012] Obtaining the access count of the first eliminated cache object from the preset hash data structure, and based on the access count of the first eliminated cache object, screening out target cache objects from the first eliminated cache object whose access count is greater than the access count of the tail cache object of the first linked list in the main cache;

[0013] The target cache object is cached in a primary cache, and other cache objects except the target cache object in the first eliminated cache object are eliminated, wherein the primary cache is a solid state drive.

[0014] The data caching method provided in this embodiment determines whether the ratio of the used capacity to the total capacity of the window cache exceeds the first ratio threshold value at each preset time interval. If the ratio of the used capacity to the total capacity of the window cache exceeds the first ratio threshold value, the first eliminated cache object in the window cache is obtained, the access count of the first eliminated cache object is obtained from the preset hash data structure, and based on the access count of the first eliminated cache object, the target cache object whose access count is greater than the access count of the tail cache object of the first linked list in the main cache is screened out from the first eliminated cache object, and the target cache object is cached to the main cache. In this embodiment, new data will not be directly written to the main cache SSD, but will be cached to the window cache first. When the ratio of the used capacity to the total capacity of the window cache exceeds the first ratio threshold value, it is also necessary to determine whether the first eliminated cache object is hot data, that is, whether the access count of the first eliminated object is greater than the access count of the tail cache object of the first linked list in the main cache. Only when the first eliminated cache object is hot data, that is, the target cache object, will it be cached to the main cache, thereby reducing the number of erasures and writes of the SSD and improving the service life of the SSD.

[0015] In an optional implementation, the window cache includes a second linked list, the elements of the second linked list are metadata information context pointers of cache objects in the window cache, and the elimination order of the corresponding cache objects is determined according to the link order of the metadata information context pointers of the cache objects in the second linked list; the updating of the preset hash data structure and the window cache based on the name of the object to be read, the range of data to be read, and the read data includes:

[0016] Generate metadata information context of the object to be read based on the name of the object to be read and the range of data to be read;

[0017] The name of the object to be read is used as a key value, and the metadata information context of the object to be read is inserted into the preset hash data structure in the form of a metadata information context pointer of the object to be read as a real value;

[0018] The read data is cached in the window cache, and the metadata information context pointer of the object to be read is inserted into the head of the second linked list.

[0019] The data caching method provided in this embodiment can ensure that hot data or recently accessed data can be easily and quickly accessed again by caching the read data into the window cache and inserting the metadata information context pointer of the object to be read into the head of the second linked list. When there is a request for the same data, it can be directly obtained from the high-speed window cache without having to be obtained from the system main memory again, thereby improving the cache hit rate and the data reading speed.

[0020] In an optional implementation, the obtaining the first eliminated cache object in the window cache includes:

[0021] Obtaining a first preset number of metadata information context pointers at the end of the second linked list of the window cache;

[0022] Based on a first preset number of metadata information context pointers at the end of the second linked list, a first elimination object in the window cache is determined.

[0023] The data caching method provided in this embodiment directly obtains the metadata information context pointer at the end of the second linked list, so that the system can quickly identify which cache objects in the window cache have not been accessed for the longest time, and eliminate multiple cache objects that have not been accessed for the longest time, thereby ensuring the novelty and practicality of the cache objects in the window cache and improving the cache hit rate.

[0024] In an optional embodiment, the method further includes:

[0025] At each preset time interval, determining whether the ratio of the used capacity to the total capacity of the primary cache exceeds a second ratio threshold;

[0026] If the ratio of the used capacity to the total capacity of the primary cache exceeds a second ratio threshold, obtaining a second preset number of metadata information context pointers at the tail of the first linked list of the primary cache;

[0027] Determining a second eliminated cache object in the primary cache based on a second preset number of metadata information context pointers at the tail of the first linked list;

[0028] Eliminate the second cache object from the primary cache;

[0029] Among them, the main cache includes a first linked list, the elements of the first linked list are metadata information context pointers of the cache objects in the main cache, and the elimination order of the corresponding cache objects is determined according to the link order of the metadata information context pointers of the cache objects in the first linked list.

[0030] The data caching method provided in this embodiment periodically checks the ratio of the used capacity of the main cache to the total capacity. When the ratio exceeds a second ratio threshold, it automatically triggers the cache cleaning mechanism to eliminate seldom accessed cache objects from the tail of the first linked list, thereby ensuring that the system can eliminate some cache objects in the main cache before the main cache resources are about to be exhausted, thereby ensuring the continuity and stability of the system operation.

[0031] In an optional implementation, caching the target cache object into the primary cache includes:

[0032] Writing the target cache object into the to-be-committed cache area of ​​the window cache, and inserting the metadata information context pointer of the target cache object into the to-be-committed linked list of the window cache;

[0033] Determine whether the data volume of the cache object corresponding to the metadata information context pointer in the to-be-submitted linked list reaches a data volume threshold;

[0034] If the data volume threshold is reached, the metadata information context pointer is obtained from the to-be-committed linked list in turn, the cache object corresponding to the metadata information context pointer in the to-be-committed cache area is cached to the main cache, and the metadata information context pointer is inserted into the head of the first linked list of the main cache.

[0035] The data caching method provided in this embodiment accumulates a certain amount of cache objects to the cache area to be committed, and then writes these cache objects to the main cache at one time. By utilizing the concurrent reading and writing characteristics of SSD, the number of write operations can be significantly reduced, thereby reducing the overhead of each write and improving the main cache update efficiency and the overall system performance.

[0036] In an optional embodiment, the method further includes:

[0037] If there is a key value identical to the name of the object to be read in the preset hash data structure, then determining the hotspot type corresponding to the object to be read according to the real value corresponding to the key value;

[0038] If the hotspot type corresponding to the object to be read is a window cache hotspot, the metadata information context pointer corresponding to the object to be read in the second linked list of the window cache is moved to the head of the second linked list, and based on the data range to be read, data belonging to the data range to be read is read from the window cache, and the data range to be read is updated for the first time;

[0039] Based on the to-be-read data range after the first update, reading data belonging to the to-be-read data range after the first update from the primary cache, and performing a second update on the to-be-read data range;

[0040] Based on the to-be-read data range after the second update, reading data belonging to the to-be-read data range after the second update from the system main memory;

[0041] The data read from the window cache, the data read from the main cache and the data read from the system main memory are combined and processed to obtain target data, and the target data is returned to the client.

[0042] The data caching method provided in this embodiment ensures the high efficiency of data access and improves the data reading efficiency by reading data belonging to the data range to be read from the window cache, the main cache, and the system main memory in sequence when the hotspot type of the object to be read is a window cache hotspot.

[0043] In an optional embodiment, the method further includes:

[0044] If the hotspot type corresponding to the object to be read is a main cache hotspot, the metadata information context pointer corresponding to the object to be read in the first linked list of the main cache is moved to the head of the first linked list, and based on the data range to be read, data belonging to the data range to be read is read from the window cache, the data range to be read is updated for the first time, based on the data range to be read after the first update, data belonging to the data range to be read after the first update is read from the main cache, the data range to be read is updated for the second time, based on the data range to be read after the second update, data belonging to the data range to be read after the second update is read from the system main memory, the data read from the window cache, the data read from the main cache and the data read from the system main memory are combined and processed to obtain target data, and the target data is returned to the client.

[0045] The data caching method provided in this embodiment ensures the high efficiency of data access and improves the data reading efficiency by reading data belonging to the data range to be read from the window cache, the main cache, and the system main memory in sequence when the hotspot type of the object to be read is the main cache hotspot.

[0046] In an optional embodiment, the method further includes:

[0047] If the hotspot type corresponding to the object to be read is non-hotspot, the metadata information context pointer of the object to be read is inserted into the head of the second linked list of the window cache, and the access count of the object to be read is updated. Based on the data range to be read, the corresponding data is read from the system main memory and returned to the client.

[0048] The data caching method provided in this embodiment ensures that whether it is a window cache hotspot, a main cache hotspot or a non-hotspot object, it can be quickly accessed by identifying the hotspot type of the object to be read and responding to the movement of the metadata information context pointer. This not only shortens the delay time of data reading, but also improves the access efficiency of hotspot data.

[0049] In an optional embodiment, the method further includes:

[0050] In response to a data writing request from a client, obtain a name of an object to be written, data to be written of the object to be written, and a range of data to be written;

[0051] Based on the range of data to be written, writing the data to be written of the object to be written into the system main memory;

[0052] Determine whether there is a key value identical to the name of the object to be written in the preset hash data structure;

[0053] If it exists, determine the hotspot type corresponding to the object to be written according to the real value corresponding to the key value;

[0054] If the hotspot type corresponding to the object to be written is a window cache hotspot, the data range in the metadata information context corresponding to the metadata information context pointer corresponding to the object to be written in the second linked list of the window cache is updated, and the cache object corresponding to the object to be written in the window cache is updated.

[0055] The data caching method provided in this embodiment first ensures the security and persistence of the data by writing the data to be written into the system main memory, and then updates and writes the window cache when the hotspot type corresponding to the object to be written is a window cache hotspot to ensure the consistency of the data in the system main memory and the cache.

[0056] In an optional embodiment, the method further includes:

[0057] If the hotspot type corresponding to the object to be written is a main cache hotspot, the data to be written of the object to be written is cached in the to-be-committed cache area of ​​the window cache, and the data range of the metadata information context corresponding to the metadata information context pointer corresponding to the object to be written in the first linked list of the main cache is updated.

[0058] The data caching method provided in this embodiment first ensures the security and persistence of the data by writing the data to be written into the system main memory, and then caches the object to be written to the pending cache area of ​​the window cache when the hotspot type corresponding to the object to be written is the main cache hotspot, thereby updating and writing the main cache according to the object to be written to ensure the consistency of the data in the system main memory and the cache.

[0059] In an optional embodiment, the method further includes:

[0060] If the hotspot type corresponding to the object to be written is a primary cache hotspot, determining whether the metadata information context pointer of the object to be written is in the to-be-committed linked list of the window cache;

[0061] If the metadata information context pointer of the object to be written is in the to-be-committed linked list of the window cache, determining whether the data volume of the cache object corresponding to the metadata information context pointer in the to-be-committed linked list reaches a data volume threshold;

[0062] If the data volume threshold is reached, metadata information context pointers are obtained from the to-be-committed linked list in sequence, and the cache objects corresponding to the metadata information context pointers in the to-be-committed cache area are cached into the main cache.

[0063] The data caching method provided in this embodiment determines whether the data amount of the cache object corresponding to the metadata information context pointer in the to-be-committed linked list reaches a data amount threshold. When the data amount threshold is reached, the cache object corresponding to the metadata information context pointer in the to-be-committed cache area is cached to the main cache, thereby updating and writing the main cache to ensure data consistency in the system main memory and cache.

[0064] In an optional embodiment, the method further includes:

[0065] If the metadata information context pointer of the object to be written is not in the to-be-submitted linked list of the window cache, the metadata information context pointer of the object to be written is inserted into the to-be-submitted linked list, and the step of determining whether the data amount of the cache object corresponding to the metadata information context pointer in the to-be-submitted linked list reaches the data amount threshold is returned.

[0066] The data caching method provided in this embodiment first ensures the security and persistence of the data by writing the data to be written into the system main memory, and then updates or writes the window cache or the main cache according to the hotspot type of the object to be written to ensure the consistency of the data in the system main memory and the cache.

[0067] In a second aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the data caching method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0068] In a third aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the data caching method of the first aspect or any corresponding embodiment thereof.

[0069] In a fourth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the data caching method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0070] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the related technologies, the drawings required for use in the specific embodiments or the related technical descriptions will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0071] Figure 1 is a flow chart of a data caching method according to an embodiment of the present invention;

[0072] Figure 2 is a schematic diagram of a process of determining to eliminate cache objects and updating the primary cache according to an embodiment of the present invention;

[0073] Figure 3 is a schematic diagram of determining the number of accesses to a cache object using a counting minimum sketch algorithm according to an embodiment of the present invention;

[0074] Figure 4 is a flow chart of another data caching method according to an embodiment of the present invention;

[0075] Figure 5 is a schematic diagram of managing cache objects of a window cache by using an LRU algorithm according to an embodiment of the present invention;

[0076] Figure 6is a schematic diagram of a process of reading data according to an embodiment of the present invention;

[0077] Figure 7 is a schematic diagram of a process of writing data according to an embodiment of the present invention;

[0078] Figure 8 is a schematic diagram of the structure of a data cache system according to an embodiment of the present invention;

[0079] Fig. 9 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0080] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0081] In order to improve the reading performance of data in input and output devices, high-speed SSD or NVME SSD is usually used as cache in storage systems with HDD as the main storage disk. By caching hot data in SSD, when the client reads hot data, it can hit the cache data in SSD, that is, directly obtain the data that the client needs to read from SSD without reading from the lower-performance main storage HDD, thereby reducing response time and improving throughput.

[0082] In the related art, hot data cached in SSD is mostly managed in the following two ways. The first is to use LRU or its improved algorithm to manage data objects (or data blocks). The algorithm maintains a linked list. When the client accesses the data in the main memory, the data is written to the cache device SSD at the same time, and the data object is inserted into the head of the LRU linked list according to the rules. When the cache used space of the cache device SSD reaches the set upper limit, the data object is taken out from the tail of the LRU linked list for elimination and deletion. In this way, if it is hot data, it will always be at the head of the LRU linked list and will not be eliminated.

[0083] The other is to use LFU or its improved algorithm to manage data objects (or data blocks). The algorithm uses the access frequency of data objects in a certain period as the basis for judging whether the data object is to be eliminated. When the cache space of the cache device SSD reaches the set upper limit, the data objects with the lowest access frequency and the longest access time will be selected for elimination. In actual use, in order to reduce the computational complexity, the Bloom filter method is often introduced.

[0084] However, these two methods of managing hot data cached in SSDs will write the data to the SSD first regardless of whether the data is cold data or hot data. Writing cold data to the SSD brings additional storage costs (including SSD life and write resource consumption) without bringing obvious system performance benefits, which seriously affects the service life of the SSD.

[0085] Moreover, the SSD cache needs to be updated every time data is written, which is equivalent to an additional operation of writing to the SSD cache in addition to writing the original data to the storage system. Frequent additional writes to the SSD cache under high business pressure will lead to a decrease in system write performance.

[0086] Furthermore, the LRU algorithm is used to manage cached hot data, which performs well for sudden sparse traffic, but it will also pollute the cache. For example, if the full data is traversed occasionally, the historical hot data will be flushed away, causing pollution and a low cache hit rate. The LFU algorithm is used to manage cached hot data, which is ineffective for sudden sparse traffic, because the data that was frequently accessed in the early stage occupies the cache, and it is difficult to replace it with occasional traffic. Some of the data that was accessed in large quantities in the past may not be accessed in the future, and it will occupy the cache all the time, resulting in a low cache hit rate.

[0087] It can be seen that the two methods of managing hot data cached in SSDs in the related art are difficult to provide a high cache hit rate in some application scenarios.

[0088] An embodiment of the present invention provides a data caching method, which determines whether the ratio of the used capacity to the total capacity of a window cache exceeds a first ratio threshold value at each preset time interval. If the ratio of the used capacity to the total capacity of the window cache exceeds the first ratio threshold value, a first eliminated cache object in the window cache is obtained, the number of accesses to the first eliminated cache object is obtained from a preset hash data structure, and based on the number of accesses to the first eliminated cache object, a target cache object whose number of accesses is greater than the number of accesses to the tail cache object of a first linked list in a main cache is screened out from the first eliminated cache object, and the target cache object is cached in the main cache so that new data will not be directly written to the main cache SSD, but will be cached in the window cache first. When the ratio of the used capacity to the total capacity of the window cache exceeds the first ratio threshold value, it is also necessary to determine whether the first eliminated cache object is hot data, that is, whether the number of accesses to the first eliminated object is greater than the number of accesses to the tail cache object of the first linked list in the main cache. Only when the first eliminated cache object is hot data, that is, the target cache object, will it be cached in the main cache, thereby reducing the number of erasures and writes of the SSD and improving the service life of the SSD.

[0089] According to an embodiment of the present invention, a data caching method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0090] In this embodiment, a data caching method is provided, which can be used in a distributed storage system. Figure 1 is a flow chart of a data caching method according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:

[0091] Step S101 , in response to a data reading request from a client, obtaining a name of an object to be read and a range of data to be read of the object to be read.

[0092] The distributed storage system receives a data read request from a client, and obtains a name of an object to be read and a range of data to be read of the object to be read in the data read request.

[0093] Step S102, determining whether there is a key value identical to the name of the object to be read in the preset hash data structure.

[0094] Among them, the preset hash data structure is a hash map. The query efficiency of the hash map is high. The map is a data structure that has both real values ​​and key values. Hash is to transform an input of any length into an output of a fixed length through a hash algorithm.

[0095] The key value of the hash map is the cache object name, and the actual value is the metadata information context (ctx) pointer of the cache object. It can be understood that the metadata information context pointer of the cache object points to the metadata information context of the cache object.

[0096] It should be noted that the cache object management module in the distributed storage system is used to manage the metadata information ctx of all cache objects, and is also used to query the data range cached in the window cache or the main cache when a business accesses a cache object. All cache objects include cache objects included in the window cache and cache objects included in the main cache.

[0097] The metadata information context of the cache object includes:

[0098] 1. Cache object name, used to record and query cache objects.

[0099] 2. Memory cache data is used to use map to record the off-len (data range) data of the cache object cache when the cache object is located in the window cache.

[0100] 3. The main cache data range is used to use the map to record the cache off-len (data range) of the cache object when the cache object is in the main cache.

[0101] 4. Hotspot type, used to use enumeration type to record whether the cache object is a window cache hotspot, a main cache hotspot, or non-hotspot data.

[0102] Determining whether there is a key value with the same name as the object to be read in the preset hash data structure is essentially determining whether there is a cache object with the same name as the object to be read cached in the main cache or the window cache.

[0103] Step S103, if it does not exist, read the corresponding data from the system main memory based on the data range to be read, return it to the client, and update the preset hash data structure and window cache based on the name of the object to be read, the data range to be read and the read data.

[0104] Among them, if there is no key value with the same name as the object to be read in the preset hash data structure, it means that no data of the object to be read is cached in the main cache or window cache, and the corresponding data needs to be read from the system main memory based on the data range to be read, and the read data is returned to the client.

[0105] By updating the preset hash data structure and window cache based on the name of the object to be read, the range of data to be read and the read data, it is ensured that the preset hash data structure always manages the metadata information context of all cached objects and the window cache stores hotspot data.

[0106] It should be noted that the window cache in this embodiment is a memory medium on a storage system node, and the main cache is an SSD, that is, an SSD medium cache.

[0107] Step S104: determining whether the ratio of the used capacity to the total capacity of the window cache exceeds a first ratio threshold at intervals of a preset time period.

[0108] The preset time period is set by the technical staff and is not limited here. Figure 2 FIG. 1 is a flow chart of determining to eliminate cache objects and update the main cache according to an embodiment of the present invention. Figure 2 As shown, it is determined at every preset time interval, that is, regularly, whether the ratio of the used capacity of the window buffer to the total capacity of the window buffer exceeds a first ratio threshold value. The first ratio threshold value is set by a technician.

[0109] Determining whether the ratio of the used capacity of the window cache to the total capacity of the window cache exceeds the first ratio threshold is to determine whether the water level of the window cache reaches the first water level threshold, which is set by a technician.

[0110] Step S105: If the ratio of the used capacity to the total capacity of the window cache exceeds a first ratio threshold, a first eliminated cache object in the window cache is obtained.

[0111] Among them, the ratio of the used capacity of the window cache to the total capacity exceeds the first ratio threshold, indicating that the cacheable space of the window cache is about to reach the threshold, and the cache objects in the window cache need to be eliminated to ensure that the window cache is not filled up, thereby ensuring the stability of the window cache.

[0112] It should be noted that the window cache uses the LRU algorithm to manage the cache objects therein, and is mainly used to meet the access requirements for sudden hot data.

[0113] Step S106, obtaining the access count of the first eliminated cache object from the preset hash data structure, and based on the access count of the first eliminated cache object, filtering out the target cache object whose access count is greater than the access count of the tail cache object of the first linked list in the main cache from the first eliminated cache object.

[0114] The metadata information context in the preset hash data structure also includes the access count information of the cache object. After obtaining the first eliminated cache object, the access count of the first eliminated cache object is obtained from the metadata information context corresponding to the first eliminated cache object in the preset hash data structure, so as to screen the first eliminated cache object and obtain the target cache object. In other words, whether the first eliminated cache object can enter the main cache is determined by judging the size of the access count of the first eliminated cache object and the access count of the tail cache object of the first linked list in the main cache.

[0115] It should be noted that the main cache uses the LFU algorithm to manage the cache objects in it, which is used to cache data with a high overall access frequency. For the data eliminated from the window cache, i.e., the cache objects, it is necessary to determine whether its access frequency is hot enough to determine whether it can replace the cold data in the main cache. Only data with a high access frequency over a long period of time can enter the main cache to avoid cold data replacing hot data.

[0116] Specifically, the target cache object is screened by comparing the access count of the first eliminated cache object with the access count of the tail cache object of the first linked list in the main cache, thereby ensuring that the cache object cached in the main cache is hot data.

[0117] It should be further explained that, in order to save system resources, this embodiment introduces a count-min sketch algorithm to record the number of accesses to all cache objects. The algorithm is implemented based on a hash function and a count array. It hashes the cache object to multiple positions in the count array. When a cache object is accessed, the counts at multiple positions on the count array of its hash map are increased by 1. When obtaining the access count of a cache object, that is, the number of accesses, the combination of the counts at multiple positions on the count array of the hash map of the cache object is obtained, and the lowest value is taken as the estimated value of the number of accesses to the cache object.

[0118] Although this algorithm will sacrifice a certain degree of accuracy, by selecting appropriate parameters, the calculation errors can be greatly reduced, and a small calculation error will not have a significant impact on the cache hit rate, and its efficiency improvement is very obvious.

[0119] Figure 3 FIG. 1 is a schematic diagram of determining the number of accesses to a cache object using a counting minimum sketch algorithm according to an embodiment of the present invention. Figure 3 As shown, when accessing cache object A, the counts of multiple positions on the count array of the hash map of cache object A, namely C1, C3, and C12, are all increased by 1. When calculating the number of accesses to cache object B, the counts of multiple positions on the count array of the hash map of cache object B, namely C2, C7, and C11, are obtained, and the minimum value is taken as the estimated value of the number of accesses to cache object B.

[0120] It should be noted that in order to prevent the cache objects in the main cache from being difficult to replace due to too high a historical access count, a decay mechanism is introduced. If the total access count of the cache objects in the main cache reaches the access count threshold, the access count of the cache objects in the main cache is decayed, that is, the access count of the cache objects in the main cache is divided by 2, that is, the multiple positions of the corresponding count array are divided by 2. Or, the access count of the cache objects in the main cache is decayed every decay time period.

[0121] Step S107: Cache the target cache object into the main cache, and eliminate other cache objects except the target cache object in the first eliminated cache object.

[0122] After the target cache object is screened out, the target cache object is cached in the main cache, and other cache objects in the first elimination object are eliminated.

[0123] The data caching method provided in the present embodiment determines whether the ratio of the used capacity to the total capacity of the window cache exceeds a first ratio threshold value at each preset time period. If the ratio of the used capacity to the total capacity of the window cache exceeds the first ratio threshold value, a first eliminated cache object in the window cache is obtained, the number of accesses to the first eliminated cache object is obtained from a preset hash data structure, and based on the number of accesses to the first eliminated cache object, a target cache object whose number of accesses is greater than the number of accesses to the tail cache object of the first linked list in the main cache is screened out from the first eliminated cache object, and the target cache object is cached in the main cache. In this embodiment, new data will not be written directly to the main cache SSD, but will be cached to the window cache first. When the ratio of the used capacity to the total capacity of the window cache exceeds the first ratio threshold, it is also necessary to determine whether the first eliminated cache object is hot data, that is, whether the access count of the first eliminated object is greater than the access count of the tail cache object of the first linked list in the main cache. Only when the first eliminated cache object is hot data, that is, the target cache object, will it be cached to the main cache, which reduces the number of erase and write times of the SSD and increases the service life of the SSD, solving the problems in the related technology of large waste of cache disk life, large impact on write performance, and low cache hit rate in some scenarios.

[0124] The data caching method provided in this embodiment uses a memory medium as a burst hotspot cache to improve the access speed of the burst hotspot.

[0125] In this embodiment, a data caching method is provided, which can be used in a distributed storage system. Figure 4 is a flow chart of a data caching method according to an embodiment of the present invention. Figure 4 As shown, the process includes the following steps:

[0126] Step S401, in response to a data read request from a client, obtain the name of the object to be read and the data range to be read of the object to be read. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.

[0127] Step S402: Determine whether there is a key value in the preset hash data structure that is the same as the name of the object to be read. Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.

[0128] Step S403, if it does not exist, read the corresponding data from the system main memory based on the data range to be read, return it to the client, and update the preset hash data structure and window cache based on the name of the object to be read, the data range to be read and the read data.

[0129] Specifically, the above step S403 includes:

[0130] Step S4031: Generate metadata information context of the object to be read based on the name of the object to be read and the data range to be read.

[0131] The window cache includes a second linked list, the elements of which are metadata information context pointers of cache objects in the window cache, and the elimination order of corresponding cache objects is determined according to the link order of the metadata information context pointers of the cache objects in the second linked list.

[0132] It can be understood that, the earlier the link order of the metadata information context pointer of the cache object in the second linked list, the later the elimination order of the corresponding cache object.

[0133] Based on the name of the object to be read and the range of data to be read, a metadata information context of the object to be read is generated, that is, based on the object to be read and the range of data to be read, a metadata information context corresponding to the service to be provided is created.

[0134] Step S4032: Using the name of the object to be read as a key value, the metadata information context of the object to be read is inserted into a preset hash data structure in the form of a metadata information context pointer of the object to be read as a real value.

[0135] The updating of the preset hash data structure is completed through the above steps S4031 and S4032.

[0136] Step S4033, cache the read data into the window cache, and insert the metadata information context pointer of the object to be read into the head of the second linked list.

[0137] Figure 5 FIG. 1 is a schematic diagram of managing cache objects of a window cache using an LRU algorithm according to an embodiment of the present invention. Figure 5 As shown, when the object to be read is a new access object, the metadata information context pointer of the object to be read is inserted into the head of the second linked list. If there is no key value with the same name as the object to be read in the preset hash data structure, it is determined that the object to be read is a new access object.

[0138] It should be noted that the second linked list is the LRU linked list.

[0139] It is understandable that, in the case where the object to be read is a re-read object, the metadata information context pointer of the object to be read is moved to the head of the second linked list. Wherein, if there is a key value identical to the name of the object to be read in the preset hash data structure, and the hotspot type of the object to be read is a window cache hotspot, then the object to be read is determined to be a re-read object.

[0140] Step S404: at every preset time interval, determine whether the ratio of the used capacity to the total capacity of the window cache exceeds a first ratio threshold. Figure 1 Step S104 of the illustrated embodiment will not be described in detail here.

[0141] Step S405: If the ratio of the used capacity to the total capacity of the window cache exceeds a first ratio threshold, the first eliminated cache object in the window cache is obtained. Figure 1 Step S105 of the illustrated embodiment will not be described in detail here.

[0142] Step S406, obtaining the access count of the first eliminated cache object from the preset hash data structure, and based on the access count of the first eliminated cache object, filtering out the target cache object whose access count is greater than the access count of the tail cache object of the first linked list in the main cache from the first eliminated cache object. Figure 1 Step S106 of the illustrated embodiment will not be described in detail here.

[0143] Step S407: Cache the target cache object to the main cache, and eliminate other cache objects except the target cache object in the first eliminated cache object. Figure 1 Step S107 of the illustrated embodiment will not be described in detail here.

[0144] The data caching method provided in this embodiment can ensure that hot data or recently accessed data can be easily and quickly accessed again by caching the read data into the window cache and inserting the metadata information context pointer of the object to be read into the head of the second linked list. When there is a request for the same data, it can be directly obtained from the high-speed window cache without having to be obtained from the system main memory again, thereby improving the cache hit rate and the data reading speed.

[0145] In some optional implementations, the above step S405 includes:

[0146] Step a1, obtaining a first preset number of metadata information context pointers at the end of the second linked list of the window cache.

[0147] The first preset number is set by a technician. The value of the first preset number is determined based on the data volume of the metadata information context pointer included in the second linked list.

[0148] Step a2: determining the first eliminated cache object in the window cache based on a first preset number of metadata information context pointers at the end of the second linked list.

[0149] After obtaining the first preset number of metadata information context pointers at the end of the second linked list, the corresponding metadata information context is determined according to these metadata information context pointers, and then the corresponding cache object in the window cache is determined, that is, the first eliminated cache object.

[0150] like Figure 5 As shown, a first preset number of metadata information context pointers are eliminated from the tail of the second linked list of the window cache, and correspondingly, the corresponding first eliminated cache objects are eliminated from the cache objects of the window cache.

[0151] The data caching method provided in this embodiment directly obtains the metadata information context pointer at the end of the second linked list, so that the system can quickly identify which cache objects in the window cache have not been accessed for the longest time, and eliminate multiple cache objects that have not been accessed for the longest time, thereby ensuring the novelty and practicality of the cache objects in the window cache and improving the cache hit rate.

[0152] In some optional implementations, the data caching method further includes:

[0153] Step b1: determining whether the ratio of the used capacity to the total capacity of the primary cache exceeds a second ratio threshold at intervals of a preset time period.

[0154] Among them, Figure 2 As shown, at every preset time interval, that is, at regular intervals, it is determined whether the ratio of the used capacity of the primary cache to the total capacity of the primary cache exceeds the second ratio threshold. The second ratio threshold is set by a technician.

[0155] Determining whether the ratio of the used capacity of the primary cache to the total capacity of the primary cache exceeds the second ratio threshold is to determine whether the water level of the primary cache reaches the second water level threshold, which is set by a technician.

[0156] Step b2: if the ratio of the used capacity to the total capacity of the primary cache exceeds a second ratio threshold, a second preset number of metadata information context pointers at the tail of the first linked list of the primary cache are obtained.

[0157] Among them, the ratio of the used capacity of the main cache to the total capacity exceeds the second ratio threshold, indicating that the cacheable space of the main cache is about to reach the threshold, and the cache objects in the main cache need to be eliminated to ensure that the main cache is not full, thereby ensuring the stability of the main cache.

[0158] The main cache includes a first linked list, namely, the SLRU linked list, the elements of which are metadata information context pointers of cache objects in the main cache, and the elimination order of the corresponding cache objects is determined according to the link order of the metadata information context pointers of the cache objects in the first linked list. It can be understood that the earlier the metadata information context pointer is linked, the later the elimination order of the corresponding cache object is.

[0159] Similar to the window cache, the metadata information context pointer corresponding to the cache object newly written into the main cache needs to be inserted into the head of the first linked list. When the object to be read is a cache object already in the main cache, the metadata information context pointer corresponding to the object to be read is moved to the head of the first linked list.

[0160] The second preset number is set by a technician. The value of the second preset number is determined based on the data volume of the metadata information context pointer included in the first linked list.

[0161] Step b3: determining a second eliminated cache object in the primary cache based on a second preset number of metadata information context pointers at the end of the first linked list.

[0162] Among them, after obtaining the second preset number of metadata information context pointers at the end of the first linked list, the corresponding metadata information context is determined according to these metadata information context pointers, and then the corresponding cache object in the main cache is determined, that is, the second eliminated cache object.

[0163] Step b4: Eliminate the second cache object from the primary cache.

[0164] like Figure 2 As shown, if the ratio of the used capacity of the main cache to the total capacity exceeds the second ratio threshold, that is, the main cache water level reaches the second water level threshold, the object is taken out from the tail of the main cache SLRU, corresponding to the description of the aforementioned steps b2 and b3, which will not be repeated here.

[0165] By adding the operation of deleting the second eliminated cache object to the SSD update transaction, that is, by adding the operation of deleting the second eliminated cache object to the SSD update transaction, the second eliminated cache object is eliminated from the main cache.

[0166] The data caching method provided in this embodiment periodically checks the ratio of the used capacity of the main cache to the total capacity. When the ratio exceeds a second ratio threshold, it automatically triggers the cache cleaning mechanism to eliminate seldom accessed cache objects from the tail of the first linked list, thereby ensuring that the system can eliminate some cache objects in the main cache before the main cache resources are about to be exhausted, thereby ensuring the continuity and stability of the system operation.

[0167] In some optional implementations, the above step S407 includes:

[0168] Step c1, writing the target cache object into the to-be-committed cache area of ​​the window cache, and inserting the metadata information context pointer of the target cache object into the to-be-committed linked list of the window cache.

[0169] After the target cache object that can be cached to the main cache is screened out, the target cache object is written into the to-be-committed cache area of ​​the window cache, and the metadata information context pointer of the target cache object is inserted into the to-be-committed linked list of the window cache.

[0170] It should be noted that, when the ratio of the used capacity to the total capacity of the main cache does not exceed the third ratio threshold, the first eliminated cache objects in the window cache are all considered hot spots, that is, all the first eliminated cache objects are used as target cache objects, and the target cache objects are written into the to-be-committed cache area of ​​the window cache. The third ratio threshold is set by a technician and is smaller than the second ratio threshold.

[0171] When the ratio of the used capacity to the total capacity of the main cache exceeds a third ratio threshold, the access count of the first eliminated cache object is obtained from a preset hash data structure, and based on the access count of the first eliminated cache object, a target cache object whose access count is greater than the access count of the tail cache object of the first linked list in the main cache is screened out from the first eliminated cache object, and the target cache object is written into the to-be-committed cache area of ​​the window cache.

[0172] Step c2, determining whether the data volume of the cache object corresponding to the metadata information context pointer in the to-be-submitted linked list reaches a data volume threshold.

[0173] like Figure 2 As shown, it is determined whether the data volume of the cache object corresponding to the metadata information context pointer in the to-be-submitted linked list has reached the data volume threshold, that is, whether the data volume of the to-be-submitted cache area has reached the data volume threshold. That is, whether the data volume to be asynchronously submitted has reached the threshold.

[0174] Step c3, if the data volume threshold is reached, the metadata information context pointer is obtained from the linked list to be submitted in turn, the cache object corresponding to the metadata information context pointer is cached to the main cache, and the metadata information context pointer is inserted into the head of the first linked list of the main cache.

[0175] Among them, when the data amount of the cache object corresponding to the metadata information context pointer in the to-be-submitted linked list reaches the data amount threshold, the metadata information context pointer is obtained from the to-be-submitted linked list in the order from the tail to the head of the to-be-submitted linked list, and according to the obtained metadata information context pointer, the corresponding cache object is cached to the main cache, and the metadata information context pointer is inserted into the head of the first linked list of the main cache.

[0176] A storage backend engine instance based on SSD cache medium is created in the main cache. The cache object data is written to and read from the SSD by calling the read and write interfaces of the storage backend. The update of the main cache is placed in the background to avoid affecting the front-end business.

[0177] The writing of the main cache adopts the asynchronous submission method. When the data of the main cache needs to be updated, that is, the data amount of the cache object corresponding to the metadata information context pointer in the to-be-submitted linked list reaches the data amount threshold, that is, the amount of data to be asynchronously submitted reaches the threshold, the metadata information context pointer is taken out from the to-be-submitted linked list, that is, the to-be-submitted linked list in sequence, which is essentially to take out the metadata information context, and construct a write operation request (OP) to add it to the SSD update transaction, and submit the SSD update transaction to achieve caching the cache object corresponding to the metadata information context pointer to the main cache.

[0178] It can be understood that after the cache object corresponding to the metadata information context pointer is cached to the main cache, the cache object data in the cache area to be submitted and the metadata information context pointer of the cache object in the linked list to be submitted are cleared, that is, the memory cache data in ctx is cleared.

[0179] The data caching method provided in this embodiment accumulates a certain amount of cache objects to the cache area to be committed, and then writes these cache objects to the main cache at one time. By utilizing the concurrent reading and writing characteristics of SSD, the number of write operations can be significantly reduced, thereby reducing the overhead of each write, improving the main cache update efficiency and the overall system performance, and reducing the maintenance cost of the storage device.

[0180] In some optional implementations, the data caching method further includes:

[0181] Step d1: If there is a key value identical to the name of the object to be read in the preset hash data structure, the hotspot type corresponding to the object to be read is determined according to the real value corresponding to the key value.

[0182] Figure 6 FIG. 1 is a schematic diagram of a process for reading data according to an embodiment of the present invention. Figure 6 As shown, in response to a data reading request from a client, that is, in response to a request from a client to read a data segment of a certain object, the name of the object to be read and the data range to be read of the object to be read are obtained.

[0183] Determine whether the preset hash data structure has a key value with the same name as the object to be read, that is, determine whether the object is in the preset hash data structure (object_map).

[0184] If there is a key value identical to the name of the object to be read in the preset hash data structure, the hotspot type corresponding to the object to be read is determined according to the real value corresponding to the key value, that is, the object hotspot type is determined.

[0185] Step d2, if the hotspot type corresponding to the object to be read is a window cache hotspot, the metadata information context pointer corresponding to the object to be read in the second linked list of the window cache is moved to the head of the second linked list, and based on the data range to be read, the data belonging to the data range to be read is read from the window cache, and the data range to be read is updated for the first time.

[0186] Among them, the hotspot type corresponding to the object to be read is a window cache hotspot, indicating that the object to be read is in the window cache, and the metadata information context pointer corresponding to the object to be read in the second linked list of the window cache is moved to the head of the second linked list, that is, the object ctx is moved to the LRU head.

[0187] Based on the data range to be read, the data belonging to the data range to be read is read from the window cache, that is, the memory cache data in ctx is read.

[0188] It should be noted that the data belonging to the to-be-read data range is data corresponding to a data range in which a data range in the metadata information context of the to-be-read object in the window cache overlaps with the to-be-read data range.

[0189] The data range to be read is subtracted from the overlapping data range to obtain the data range to be read after the first update.

[0190] Step d3, based on the to-be-read data range after the first update, read the data belonging to the to-be-read data range after the first update from the main cache, and perform a second update on the to-be-read data range.

[0191] After obtaining the to-be-read data range after the first update, data belonging to the to-be-read data range after the first update is read from the main cache, that is, the data cached in the SSD is read, and the to-be-read data range is updated for the second time.

[0192] The data belonging to the to-be-read data range after the first update is data corresponding to a data range where a data range in the metadata information context of the to-be-read object in the main cache overlaps with the to-be-read data range after the first update.

[0193] The data range to be read after the first update is subtracted from the overlapping data range to obtain the data range to be read after the second update.

[0194] Step d4, based on the to-be-read data range after the second update, read the data belonging to the to-be-read data range after the second update from the system main memory.

[0195] After obtaining the to-be-read data range after the first update, the data belonging to the to-be-read data range after the second update is directly read from the system main memory, that is, the unread data is read from the system main memory.

[0196] It should be noted that each time the object to be read is read, the corresponding access count needs to be increased by 1.

[0197] In step d5, the data read from the window cache, the data read from the main cache, and the data read from the system main memory are combined and processed to obtain target data, and the target data is returned to the client.

[0198] The data caching method provided in this embodiment ensures the high efficiency of data access and improves the data reading efficiency by reading data belonging to the data range to be read from the window cache, the main cache, and the system main memory in sequence when the hotspot type of the object to be read is a window cache hotspot.

[0199] In some optional implementations, the data caching method further includes:

[0200] Step e1, if the hotspot type corresponding to the object to be read is a main cache hotspot, the metadata information context pointer corresponding to the object to be read in the first linked list of the main cache is moved to the head of the first linked list, and based on the data range to be read, data belonging to the data range to be read is read from the window cache, the data range to be read is updated for the first time, based on the data range to be read after the first update, data belonging to the data range to be read after the first update is read from the main cache, and the data range to be read is updated for the second time, based on the data range to be read after the second update, data belonging to the data range to be read after the second update is read from the system main memory, the data read from the window cache, the data read from the main cache and the data read from the system main memory are combined and processed to obtain the target data, and the target data is returned to the client.

[0201] Among them, if the hotspot type corresponding to the object to be read is the main cache hotspot, the metadata information context pointer corresponding to the object to be read in the first linked list of the main cache is moved to the head of the first linked list, that is, the object ctx is moved to the SLRU head.

[0202] It should be noted that even if the hotspot type corresponding to the object to be read is the main cache hotspot, the data needs to be read from the window cache first and then from the main cache, because the to-be-committed cache area in the window cache may contain write update data to be submitted to the main cache.

[0203] The data caching method provided in this embodiment ensures the high efficiency of data access and improves the data reading efficiency by reading data belonging to the data range to be read from the window cache, the main cache, and the system main memory in sequence when the hotspot type of the object to be read is the main cache hotspot.

[0204] In some optional implementations, the data caching method further includes:

[0205] Step f1, if the hotspot type corresponding to the object to be read is non-hotspot, the metadata information context pointer of the object to be read is inserted into the head of the second linked list of the window cache, and the access count of the object to be read is updated. Based on the data range to be read, the corresponding data is read from the system main memory and returned to the client.

[0206] If the hotspot type corresponding to the object to be read is non-hotspot, the metadata information context pointer of the object to be read is inserted into the head of the second linked list of the window cache, that is, the object ctx is inserted into the LRU head.

[0207] It is understandable that if the hotspot type corresponding to the object to be read is non-hotspot, that is, there is no cache of the object to be read in the window cache and the main cache, the corresponding data is directly read from the system main memory and the read data is returned to the client.

[0208] In summary, when reading data, read the read cache first. The read cache includes the memory cache and the main cache. If the read cache can be hit, the read latency can be reduced. In the case of partial hits in the read cache, the cached part can be read in the cache, and the remaining part is read from the main memory of the storage system. After the reading is completed, the complete data is returned. Among them, when reading the data in the read cache, follow the principle of reading the memory cache first and then reading the main cache.

[0209] The data caching method provided in this embodiment ensures that whether it is a window cache hotspot, a main cache hotspot or a non-hotspot object, it can be quickly accessed by identifying the hotspot type of the object to be read and responding to the movement of the metadata information context pointer. This not only shortens the delay time of data reading, but also improves the access efficiency of hotspot data.

[0210] In some optional implementations, the data caching method further includes:

[0211] Step g1, in response to a data writing request from a client, obtaining a name of an object to be written, data to be written of the object to be written, and a range of data to be written.

[0212] The distributed storage system receives a data writing request from a client, and obtains the name of the object to be written, the data to be written of the object to be written, and the range of the data to be written in the data writing request.

[0213] Step g2, based on the range of data to be written, write the data to be written of the object to be written into the system main memory.

[0214] Step g3, determining whether there is a key value identical to the name of the object to be written in the preset hash data structure.

[0215] To ensure data consistency between the system main memory and the cache, when data written to the system main memory is updated, the corresponding data in the cache also needs to be updated at the same time.

[0216] Figure 7 1 is a flow chart of writing data according to an embodiment of the present invention. Figure 7 As shown, after the client writes an object data segment into the system main memory, that is, after the data to be written of the object to be written is written into the system main memory, it is determined whether there is a key value with the same name as the object to be written in the preset hash data structure, that is, whether the object is in the object_map.

[0217] Step g4: If it exists, determine the hotspot type corresponding to the object to be written according to the real value corresponding to the key value.

[0218] If there is a key value identical to the name of the object to be written in the preset hash data structure, the hotspot type corresponding to the object to be written is determined according to the real value corresponding to the key value, that is, the metadata information context of the object to be written.

[0219] It should be noted that, when the ratio of the used capacity of the window cache to the total capacity does not exceed the fourth ratio threshold, and there is no key value identical to the name of the object to be written in the preset hash data structure, the data newly written by the client, i.e., the object to be written, is considered a hotspot, and the metadata information context of the object to be written is generated according to the name of the object to be written, the data to be written of the object to be written, and the range of the data to be written, and the name of the object to be written is used as the key value, and the metadata information context of the object to be written is inserted into the preset hash data structure as a real value in the form of a metadata information context pointer, and the data to be written is cached to the window cache, and the metadata information context pointer of the object to be written is inserted into the head of the second linked list, so as to maximize the use of the cache. Among them, the fourth ratio threshold is set by a technician and is less than the first ratio threshold.

[0220] Step g5, if the hotspot type corresponding to the object to be written is a window cache hotspot, the data range in the metadata information context corresponding to the metadata information context pointer corresponding to the object to be written in the second linked list of the window cache is updated, and the object to be written in the window cache is updated.

[0221] Among them, if the hotspot type corresponding to the object to be written is a window cache hotspot, the data range in the metadata information context corresponding to the metadata information context pointer corresponding to the object to be written in the second linked list of the window cache is updated to the data range summed up by the original data range and the data range to be written, and the data to be written of the object to be written is cached in the window cache, that is, the memory cache data in ctx is updated.

[0222] The data caching method provided in this embodiment first ensures the security and persistence of the data by writing the data to be written into the system main memory, and then updates and writes the window cache when the hotspot type corresponding to the object to be written is a window cache hotspot to ensure the consistency of the data in the system main memory and the cache.

[0223] In some optional implementations, the data caching method further includes:

[0224] Step h1, if the hotspot type corresponding to the object to be written is the main cache hotspot, the data to be written of the object to be written is cached in the pending cache area of ​​the window cache, and the data range of the metadata information context corresponding to the metadata information context pointer corresponding to the object to be written in the first linked list of the main cache is updated.

[0225] Among them, if the hotspot type corresponding to the object to be written is the main cache hotspot, the data to be written of the object to be written is cached in the pending cache area of ​​the window cache, that is, the memory cache data in ctx is updated, and the data range of the metadata information context corresponding to the metadata information context pointer corresponding to the object to be written in the first linked list of the main cache is updated to the original data range minus the updated data range, to prevent reading the data before the update. Among them, the updated data range is the overlapping data range of the data range to be written and the original data range.

[0226] The data caching method provided in this embodiment first ensures the security and persistence of the data by writing the data to be written into the system main memory, and then caches the object to be written to the pending cache area of ​​the window cache when the hotspot type corresponding to the object to be written is the main cache hotspot, thereby updating and writing the main cache according to the object to be written to ensure the consistency of the data in the system main memory and the cache.

[0227] In some optional implementations, the data caching method further includes:

[0228] Step i1: if the hotspot type corresponding to the object to be written is a primary cache hotspot, it is determined whether the metadata information context pointer of the object to be written is in the to-be-committed linked list of the window cache.

[0229] Here, it is determined whether the metadata information context pointer of the object to be written is in the pending submission linked list of the window cache, that is, it is determined whether the metadata information context pointer of the object to be written is already in the pending asynchronous submission linked list.

[0230] Step i2: if the metadata information context pointer of the object to be written is in the to-be-committed linked list of the window cache, determine whether the data volume of the cache object corresponding to the metadata information context pointer in the to-be-committed linked list reaches the data volume threshold.

[0231] It is determined whether the data volume of the cache object corresponding to the metadata information context pointer in the to-be-committed linked list reaches the data volume threshold, that is, it is determined whether the data volume to be asynchronously committed reaches the threshold.

[0232] Step i3: If the data volume threshold is reached, the metadata information context pointer is obtained from the to-be-submitted linked list in turn, and the cache object corresponding to the metadata information context pointer is cached into the main cache.

[0233] Please refer to the above step c3 for details, which will not be repeated here.

[0234] The data caching method provided in this embodiment determines whether the data amount of the cache object corresponding to the metadata information context pointer in the to-be-committed linked list reaches a data amount threshold. When the data amount threshold is reached, the cache object corresponding to the metadata information context pointer in the to-be-committed cache area is cached to the main cache, thereby updating and writing the main cache to ensure data consistency in the system main memory and cache.

[0235] In some optional implementations, the data caching method further includes:

[0236] Step j1, if the metadata information context pointer of the object to be written is not in the pending list of the window cache, then the metadata information context pointer of the object to be written is inserted into the pending list, and the step of returning to determine whether the data amount of the cache object corresponding to the metadata information context pointer in the pending list reaches the data amount threshold is executed.

[0237] If the metadata information context pointer of the object to be written is not in the pending submission linked list of the window cache, the metadata information context pointer of the object to be written is inserted into the pending submission linked list, that is, the object ctx is inserted into the pending asynchronous submission linked list.

[0238] The data caching method provided in this embodiment first ensures the security and persistence of the data by writing the data to be written into the system main memory, and then updates or writes the window cache or the main cache according to the hotspot type of the object to be written to ensure the consistency of the data in the system main memory and the cache.

[0239] By using the window cache as a write buffer to update the main cache, data to be cached in the main cache is temporarily cached and written to the SSD through asynchronous submission, which reduces the number of SSD erase and write times and increases the service life of the SSD.

[0240] In some optional implementations, the data caching method further includes:

[0241] Step k1, when there is a key value identical to the name of the object to be read in the preset hash data structure, and data corresponding to the data range to be read needs to be read from the system main memory, the data corresponding to the data range to be read read from the system main memory is updated to the corresponding cache according to the hotspot type of the object to be read, and the data range in the metadata information context of the object to be read is updated.

[0242] Among them, if the hotspot type of the object to be read is a window cache hotspot, the data corresponding to the data range to be read from the system main memory is updated to the window cache, and the data range in the metadata information context of the object to be read is updated to the sum of the original data range and the data range corresponding to the data read from the system main memory.

[0243] If the hotspot type of the object to be read is a main cache hotspot, the data corresponding to the data range to be read from the system main memory is updated to the to-be-committed buffer area of ​​the window cache, and the metadata information context pointer of the object to be read is inserted into the to-be-committed linked list.

[0244] When the cache object corresponding to the metadata information context pointer in the to-be-committed linked list in the to-be-committed cache area is cached to the main cache, the data range in the metadata information context corresponding to the to-be-read object in the main cache is updated to the sum of the original data range and the data range corresponding to the data read from the system main memory.

[0245] That is to say, for cache objects that have been identified as hot spots in the window cache or main cache, the data pull-up function needs to be implemented, that is, the data that is not in the cache will be updated to the cache when the data is read from the system main memory. For the pull-up writing of data, the data writing process can be reused. After completing the reading of the main memory data, the data writing function can be called with the read data.

[0246] The data caching method provided in this embodiment can improve the cache hit rate, reduce the subsequent access delay to the object to be read, and improve the access speed by caching the data read from the system main memory into the cache when there is a key value identical to the name of the object to be read in the preset hash data structure and the data corresponding to the data range to be read needs to be read from the system main memory.

[0247] In some optional implementations, the data caching method further includes:

[0248] Step L1, in the event of a failure in the main cache or the window cache, perform fault recovery and clear the cache objects of the main cache and the window cache after fault recovery, or verify the cache objects of the main cache and the window cache after fault recovery, and rebuild the cache objects of the main cache and the window cache based on the verification results.

[0249] Specifically, the cache objects of the main cache and the window cache are verified, and the cache objects of the main cache and the window cache are rebuilt according to the verification results, including:

[0250] The cache objects of the main cache and the window cache are verified by the data verification method in the related technology to obtain the verification result of a damaged cache object or an erroneous cache object, and the damaged cache object or the erroneous cache object is marked as invalid.

[0251] Reload the cache objects marked as invalid and retain other cache objects in the main cache and window cache except the invalid cache objects.

[0252] The data caching method provided in this embodiment avoids the use of unreliable data and ensures data security by clearing the cache objects of the main cache and the window cache after fault recovery.

[0253] After failure recovery, damaged or erroneous cache objects can be found through verification and marked as invalid. Only invalid cache objects are reloaded, reducing the time and resource consumption of reloading data, improving system performance, and retaining valid cache objects to ensure the probability of cache usage.

[0254] In this embodiment, a data cache system is also provided. Figure 8 is a schematic diagram of the structure of a data cache system according to an embodiment of the present invention. Figure 8 As shown, the data cache system includes a cache object management module, a window cache module, a main cache module, a cache elimination module and a capacity statistics module.

[0255] The cache object management module is used to manage the metadata information context of all cache objects, including a preset hash data structure, and is also used to query the data range cached in the window cache or main cache when a business accesses a cache object.

[0256] The window cache module is used to manage the cache objects in the window cache through the LRU algorithm when performing business read and write operations on the cache objects in the window cache.

[0257] The primary cache module is used to manage cache objects in the primary cache through the LFU algorithm when performing business read and write operations on cache objects in the primary cache.

[0258] The cache elimination module is used to execute the above steps S404 to S407 and the above steps b1 to b4. Please refer to the description of the above steps for details, which will not be repeated here.

[0259] The capacity statistics module is used to count the used capacity of the window cache and the main cache in real time when performing data read and write operations, and provide the water level of the current window cache and the main cache, that is, the ratio of the used capacity of the above-mentioned window cache to the total capacity and the ratio of the used capacity of the main cache to the total capacity.

[0260] In the storage system initialization process, the read cache instance is initialized, including initializing the corresponding modules and devices of the read cache, and in the storage system shutdown process, the read cache instance is closed and the corresponding threads and resources are released.

[0261] The data cache system provided in this embodiment combines the advantages of the LRU algorithm and the LFU algorithm, so that the cache of the storage system has a higher hit rate when facing sudden hot spots or global hot spots.

[0262] The embodiment of the present invention also provides a computer device, see Fig. 9 , Fig. 9 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Fig. 9 As shown, the computer device includes: one or more processors 901, memory 902, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Each component utilizes different buses to communicate with each other, and can be installed on a common mainboard or installed in other ways as required. The processor can process the instructions executed in the computer device, including instructions stored in the memory or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides part of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Fig. 9 A processor 901 is taken as an example.

[0263] The processor 901 may be a central processing unit, a network processor or a combination thereof. The processor 901 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable logic gate array, a general purpose array logic or any combination thereof.

[0264] The memory 902 stores instructions executable by at least one processor 901 so as to enable at least one processor 901 to implement the method shown in the above embodiment.

[0265] The memory 902 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 902 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 902 may optionally include a memory remotely arranged relative to the processor 901, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0266] The memory 902 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 902 may also include a combination of the above types of memory.

[0267] The computer device also includes a communication interface 903, which is used for the computer device to communicate with other devices or a communication network.

[0268] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0269] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.

[0270] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A data caching method, characterized in that: The method comprises: In response to a data reading request from a client, obtaining a name of an object to be read and a range of data to be read of the object to be read; Determine whether there is a key value identical to the name of the object to be read in the preset hash data structure; If not, the corresponding data is read from the system main memory based on the data range to be read, and returned to the client, and the preset hash data structure and window cache are updated based on the name of the object to be read, the data range to be read and the read data; At each preset time interval, determining whether the ratio of the used capacity to the total capacity of the window cache exceeds a first ratio threshold; If the ratio of the used capacity to the total capacity of the window cache exceeds a first ratio threshold, obtaining a first eliminated cache object in the window cache; Obtaining the access count of the first eliminated cache object from the preset hash data structure, and based on the access count of the first eliminated cache object, screening out target cache objects from the first eliminated cache object whose access count is greater than the access count of the tail cache object of the first linked list in the main cache; caching the target cache object to a primary cache, and eliminating other cache objects except the target cache object in the first eliminated cache object, wherein the primary cache is a solid state drive; The window cache includes a second linked list, the elements of which are metadata information context pointers of cache objects in the window cache, and the elimination order of corresponding cache objects is determined according to the link order of the metadata information context pointers of the cache objects in the second linked list; the updating of the preset hash data structure and the window cache based on the name of the object to be read, the range of data to be read and the read data includes: Generate metadata information context of the object to be read based on the name of the object to be read and the range of data to be read; The name of the object to be read is used as a key value, and the metadata information context of the object to be read is inserted into the preset hash data structure in the form of a metadata information context pointer of the object to be read as a real value; Cache the read data into the window cache, and insert the metadata information context pointer of the object to be read into the head of the second linked list; The method further comprises: At each preset time interval, determining whether the ratio of the used capacity to the total capacity of the primary cache exceeds a second ratio threshold; If the ratio of the used capacity to the total capacity of the primary cache exceeds a second ratio threshold, obtaining a second preset number of metadata information context pointers at the tail of the first linked list of the primary cache; Determining a second eliminated cache object in the primary cache based on a second preset number of metadata information context pointers at the tail of the first linked list; Eliminate the second cache object from the primary cache; The main cache includes a first linked list, the elements of which are metadata information context pointers of cache objects in the main cache, and the elimination order of corresponding cache objects is determined according to the link order of the metadata information context pointers of the cache objects in the first linked list; The step of caching the target cache object into the primary cache comprises: Writing the target cache object into the to-be-committed cache area of ​​the window cache, and inserting the metadata information context pointer of the target cache object into the to-be-committed linked list of the window cache; Determine whether the data volume of the cache object corresponding to the metadata information context pointer in the to-be-submitted linked list reaches a data volume threshold; If the data volume threshold is reached, the metadata information context pointer is obtained from the to-be-committed linked list in turn, the cache object corresponding to the metadata information context pointer in the to-be-committed cache area is cached to the main cache, and the metadata information context pointer is inserted into the head of the first linked list of the main cache.

2. The method according to claim 1, characterized in that The obtaining of the first eliminated cache object in the window cache comprises: Obtaining a first preset number of metadata information context pointers at the end of the second linked list of the window cache; Based on a first preset number of metadata information context pointers at the end of the second linked list, a first elimination object in the window cache is determined.

3. The method according to claim 1, characterized in that The method further comprises: If there is a key value identical to the name of the object to be read in the preset hash data structure, then determining the hotspot type corresponding to the object to be read according to the real value corresponding to the key value; If the hotspot type corresponding to the object to be read is a window cache hotspot, the metadata information context pointer corresponding to the object to be read in the second linked list of the window cache is moved to the head of the second linked list, and based on the data range to be read, data belonging to the data range to be read is read from the window cache, and the data range to be read is updated for the first time; Based on the to-be-read data range after the first update, reading data belonging to the to-be-read data range after the first update from the primary cache, and performing a second update on the to-be-read data range; Based on the to-be-read data range after the second update, reading data belonging to the to-be-read data range after the second update from the system main memory; The data read from the window cache, the data read from the main cache and the data read from the system main memory are combined and processed to obtain target data, and the target data is returned to the client.

4. The method according to claim 3, characterized in that The method further comprises: If the hotspot type corresponding to the object to be read is a main cache hotspot, the metadata information context pointer corresponding to the object to be read in the first linked list of the main cache is moved to the head of the first linked list, and based on the data range to be read, data belonging to the data range to be read is read from the window cache, the data range to be read is updated for the first time, based on the data range to be read after the first update, data belonging to the data range to be read after the first update is read from the main cache, the data range to be read is updated for the second time, based on the data range to be read after the second update, data belonging to the data range to be read after the second update is read from the system main memory, the data read from the window cache, the data read from the main cache and the data read from the system main memory are combined and processed to obtain target data, and the target data is returned to the client.

5. The method according to claim 3, characterized in that: The method further comprises: If the hotspot type corresponding to the object to be read is non-hotspot, the metadata information context pointer of the object to be read is inserted into the head of the second linked list of the window cache, and the access count of the object to be read is updated. Based on the data range to be read, the corresponding data is read from the system main memory and returned to the client.

6. The method according to claim 1, characterized in that The method further comprises: In response to a data writing request from a client, obtain a name of an object to be written, data to be written of the object to be written, and a range of data to be written; Based on the range of data to be written, writing the data to be written of the object to be written into the system main memory; Determine whether there is a key value identical to the name of the object to be written in the preset hash data structure; If it exists, determine the hotspot type corresponding to the object to be written according to the real value corresponding to the key value; If the hotspot type corresponding to the object to be written is a window cache hotspot, the data range in the metadata information context corresponding to the metadata information context pointer corresponding to the object to be written in the second linked list of the window cache is updated, and the cache object corresponding to the object to be written in the window cache is updated.

7. The method according to claim 6, characterized in that The method further comprises: If the hotspot type corresponding to the object to be written is a main cache hotspot, the data to be written of the object to be written is cached in the to-be-committed cache area of ​​the window cache, and the data range of the metadata information context corresponding to the metadata information context pointer corresponding to the object to be written in the first linked list of the main cache is updated.

8. The method according to claim 7, characterized in that The method further comprises: If the hotspot type corresponding to the object to be written is a primary cache hotspot, determining whether the metadata information context pointer of the object to be written is in the to-be-committed linked list of the window cache; If the metadata information context pointer of the object to be written is in the to-be-committed linked list of the window cache, determining whether the data volume of the cache object corresponding to the metadata information context pointer in the to-be-committed linked list reaches a data volume threshold; If the data volume threshold is reached, metadata information context pointers are obtained from the to-be-committed linked list in sequence, and the cache objects corresponding to the metadata information context pointers in the to-be-committed cache area are cached into the main cache.

9. The method according to claim 8, characterized in that The method further comprises: If the metadata information context pointer of the object to be written is not in the to-be-submitted linked list of the window cache, the metadata information context pointer of the object to be written is inserted into the to-be-submitted linked list, and the step of determining whether the data amount of the cache object corresponding to the metadata information context pointer in the to-be-submitted linked list reaches the data amount threshold is returned.

10. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the data caching method according to any one of claims 1 to 9 by executing the computer instructions.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the data caching method according to any one of claims 1 to 9.

12. A computer program product, characterized in that The method comprises computer instructions, wherein the computer instructions are used to cause a computer to execute the data caching method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Caching method and device based on two-layer cache structure

    CN115563029A