Cache data management method and electronic equipment
By setting up hash tables and version linked lists in the caching system, and combining the popularity and location of version nodes, the problem of caching components being unable to perceive version information is solved. This enables the reasonable retention of hot data and the reasonable elimination of old versions, improving the accuracy of cache data management and system efficiency.
Patent Information
- Application Number
- CN202511527981.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-24
- Publication Date
- 2025-11-21
AI Technical Summary
The caching component is unable to perceive version information, resulting in an inability to accurately count data popularity and correctly handle hot data from older versions, thus affecting the accuracy and consistency of the data eviction strategy.
In the caching system, a hash table is set up to organize multiple version nodes corresponding to the same data identifier into a version linked list. When new data is written, the new version node is added to the linked list instead of overwriting the old version. The popularity information and position of the version node are combined to make a comprehensive judgment and selectively eliminate the oldest version node with low popularity.
It improves the accuracy of cached data eviction, avoids the accidental deletion of hot data, and ensures data access consistency and efficient system operation.
Smart Images

Figure CN120994576A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a cached data management method and electronic device. Background Technology
[0002] In current storage systems, Multi-Version Concurrency Control (MVCC) is used to ensure data concurrency performance and consistency. Data in the storage system is controlled using different versions. That is, when data is written, a new version is created and written to a new node, rather than overwriting old data nodes. Caching components do not incorporate version control technology. Data in the cache is organized at the physical data block level, and the caching component cannot perceive version information, making it impossible to accurately calculate the true popularity of data. Furthermore, technologies that incorporate version control into caching components only consider the newness of the version when measuring data popularity. During data eviction, the oldest version is uniformly evicted, lacking statistical analysis of data popularity and failing to properly handle frequently accessed data in older versions. Summary of the Invention
[0003] This application provides a cached data management method and electronic device to at least solve the problem in related technologies that the cache component cannot perceive version information and cannot accurately count the true popularity of data, resulting in the inability to manage data and eliminate old version data based on the popularity and version of the data. It can retain hot data to the maximum extent while ensuring data consistency.
[0004] This application provides a method for managing cached data, including: In the caching system, a hash table is set to manage cached data. Data nodes of the cached data are assigned data identifiers (Keys) and version nodes for identifying version information. Multiple version nodes corresponding to the same data identifier are linked to the same version list. When the caching system receives the target data to be written, it determines the corresponding target hash bucket based on the target data identifier of the target data using a hash function, and searches for the existence of a head node in the hash chain of the target hash bucket. In response to the absence of a head node, a new head node is created in the hash chain of the target hash bucket, and the head node is pointed to the first row of the version chain corresponding to the target data identifier. A new version node is created in the first row of the version chain to store the target data. In response to the existence of a head node, a new version node is created to store the target data, and the new version node is inserted at the end of the version list; When the remaining cache space of the caching system is less than a first threshold, the corresponding popularity information is determined according to the number of multiple version nodes in the version chain, and candidate data nodes to be eliminated are determined according to the popularity information of the version nodes and their positions in the version chain. Data nodes to be deleted are selected from the candidate data nodes to be eliminated and deleted.
[0005] This application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any of the above-described cache data management methods when executing the computer program. In the caching system, a hash table is set to manage cached data. Data nodes of the cached data are assigned data identifiers (Keys) and version nodes for identifying version information. Multiple version nodes corresponding to the same data identifier are linked to the same version list. When the caching system receives the target data to be written, it determines the corresponding target hash bucket based on the target data identifier of the target data using a hash function, and searches for the existence of a head node in the hash chain of the target hash bucket. In response to the absence of a head node, a new head node is created in the hash chain of the target hash bucket, and the head node is pointed to the first row of the version chain corresponding to the target data identifier. A new version node is created in the first row of the version chain to store the target data. In response to the existence of a head node, a new version node is created to store the target data, and the new version node is inserted at the end of the version list; When the remaining cache space of the caching system is less than a first threshold, the corresponding popularity information is determined according to the number of multiple version nodes in the version chain, and candidate data nodes to be eliminated are determined according to the popularity information of the version nodes and their positions in the version chain. Data nodes to be deleted are selected from the candidate data nodes to be eliminated and deleted.
[0006] This application utilizes a hash table within the caching system to organize multiple version nodes corresponding to the same data identifier into a version linked list. When new data is written, a new version node is appended to the linked list instead of overwriting the old version, enabling the system to perceive and manage multiple versions of data. Simultaneously, by combining the popularity information of version nodes with their position in the version linked list, a comprehensive judgment is made to selectively evict the oldest version node with low popularity when cache space is insufficient. Through this method, the caching system can maximize the retention of frequently accessed data while ensuring the reasonable eviction of older versions, improving the accuracy of cache data eviction and preventing the accidental deletion of popular data, thereby guaranteeing data access consistency and the overall efficient operation of the system. Attached Figure Description
[0007] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0008] Figure 1 This is a diagram illustrating the application environment of a cache data management method in one embodiment of this application. Figure 2 This is a flowchart illustrating a cache data management method in one embodiment of this application; Figure 3 This is a schematic diagram illustrating the principle of setting up a hash table in the cache system to manage cache data in one embodiment of the present application. Figure 4 This is a structural block diagram of a cache data management device in one embodiment of this application; Figure 5 This is an internal structural diagram of a computer device in one embodiment of this application. Detailed Implementation
[0009] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.
[0010] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.
[0011] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0012] In current storage systems, Multi-Version Concurrency Control (MVCC) is used to ensure data concurrency performance and consistency. This technology primarily achieves conflict-free read and write operations by creating different versions of data. That is, when data is written, a new version is created and written to a new node, rather than overwriting the old data node. Data write operations can be executed concurrently without locks. Data read operations, on the other hand, find the corresponding version node based on the version information needed, and write new data without blocking.
[0013] As a core component of a storage system, DRAM (Device Cache) is written to the cache first during data writing. Through data persistence technology, data can be returned to the user without being written to disk. Frequently accessed data is retained in the cache; when data is read, a cache hit allows the cached data to be used and returned to the user, avoiding disk read time. Therefore, the performance of the cache component has a significant impact on the storage system. Applying MVCC (Multi-Version Concurrency Control) technology to the cache, and organizing the data in the cache through version control, can further improve the read and write performance of cached data.
[0014] The caching component does not incorporate version control; the data in the cache is organized at the physical data block level, not at the upper-level logical data block level. In contrast, data in the storage system is controlled using different versions. When writing data of different versions, new physical space is allocated, rather than using the physical space of the old version. The caching component is unaware of version information and cannot accurately determine the true popularity of the data.
[0015] Existing technologies that introduce version control into caching components only consider the age of the version when measuring data popularity. During the elimination process, the oldest version is eliminated uniformly, lacking statistical analysis of data popularity and failing to properly handle popular data from older versions.
[0016] The cache data management method provided in this application can be applied to, for example... Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network. Terminal 102 sends write data requests, access data requests, or update operation requests to server 104. Server 104's caching system manages the data. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices, and server 104 can be a standalone server or a server cluster consisting of multiple servers.
[0017] like Figure 2 As shown, an embodiment of this application provides a cached data management method, including the following steps: Step S1: Set up a hash table in the caching system to manage cached data, set data identifiers for data nodes of cached data and version nodes for identifying version information, and attach multiple version nodes corresponding to the same data identifier to the same version linked list. Step S2: When the caching system receives the target data to be written, it determines the corresponding target hash bucket based on the target data identifier of the target data using a hash function, and searches for the existence of a head node in the hash chain of the target hash bucket. Step S3: In response to the absence of a head node, a new head node is created in the hash chain of the target hash bucket, the head node is pointed to the first row of the version chain corresponding to the target data identifier, and a new version node is created in the first row of the version chain to store the target data. Step S4: In response to the existence of a head node, a new version node is created to store the target data, and the new version node is inserted at the end of the version linked list; Step S5: In response to the remaining cache space of the caching system being less than the first threshold, determine the corresponding popularity information based on the number of multiple version nodes in the version chain, determine the candidate data nodes to be eliminated based on the popularity information of the version nodes and their positions in the version chain, and select the data nodes to be deleted from the candidate data nodes to be eliminated and delete them.
[0018] Specifically, by setting up a hash table in the caching system, multiple version nodes corresponding to the same data identifier are organized into a version linked list. When new data is written, the new version node is appended to the linked list instead of overwriting the old version, enabling the system to detect and manage multiple versions of data. Simultaneously, by combining the popularity information of version nodes with their position in the version linked list, a comprehensive judgment is made to selectively evict the oldest version node with low popularity when cache space is insufficient. In this way, the caching system can maximize the retention of frequently accessed data while ensuring that older versions of data are properly evicted. This improves the accuracy of cache data eviction and avoids the accidental deletion of popular data, thereby guaranteeing data access consistency and the overall efficient operation of the system.
[0019] The process of forming the version list is as follows: When data is written to the storage system, the data is identified as a key. The corresponding hash bucket is found using a hash function. In the hash list corresponding to the hash bucket, the head node of the version list is found. If it does not exist, a new head node of the version list is created. If it exists, a new version node is created, its relevant information is initialized, and it is inserted at the end of the version list.
[0020] The data node is a sub-data segment into which the written data is divided. Each sub-data segment corresponds to multiple versions. Each version is a version node. Each data node is stored in a hash bucket. There is at least one version node in the version linked list corresponding to each data node. Each version node represents the version of its corresponding data node. The corresponding version of the data node can be obtained through the version node.
[0021] The data insertion process is as follows: In the storage system, data with identifier K1 and version V1 is written. The hash bucket corresponding to K1 is calculated using a hash function. The hash list is found; if no node exists in the hash list, a version list head node is created and inserted into the hash list. A version node is created, and its parameters are initialized. The version node's metadata information is updated with the updated data identifier information, and the version number is updated in the version information. Finally, the node pointer of the version head node is updated to the newly created version node. A cache resource is requested to store the data, the user data is written to the cache, and the version node's data block pointer Data_Ptr is updated. Data with identifier K1 and version V2 is written. The hash table search follows the same process as above, finding the version list head node, creating a new version node, and initializing its information. The version node is added to the tail of the version list.
[0022] like Figure 3 As shown, in this embodiment, setting a hash table in the caching system to manage cached data further includes: The hash table is set up by multiple hash buckets, each containing a hash list. Each node in the hash list is associated with a corresponding data identifier (key) and points to the version list corresponding to the data identifier. Multiple version data nodes in the version linked list are connected sequentially in order of version age. The head node of the hash linked list points to the first row of the version linked list, and the first row corresponds to the storage of the oldest version node.
[0023] The combination of hash buckets and linked lists enables cached data to be quickly partitioned and organized in chronological order. This structure reduces lookup overhead and supports multi-version management under different data identifiers, improving the retrieval and maintenance efficiency of the caching system in large-scale data scenarios.
[0024] In this embodiment, the head node of the hash chain points to the first row of the version chain, and the first row corresponds to the node storing the oldest version, including: Set the head node of the hash list to contain a pointer to the version node (Node_Ptr). The information included in the version node settings includes: Version identifier (Version_Info) is used to identify the version information of the data. The version identifier is a timestamp or an incrementing identifier number. Metadata information (Data_Info) is used to describe the logical address and volume information of the data. A data pointer (Data_Ptr) is used to point to the memory address where the data is stored. A pointer to the next version node (Next_Version); The popularity statistics (Version_Heat_Metric) are used to characterize the access popularity of version nodes.
[0025] By storing the data itself and its related metadata in the version node, the system can quickly achieve data access, data location, and popularity assessment. This solution avoids secondary lookups during the access process, improves access efficiency, and provides a precise decision-making basis for cache eviction strategies.
[0026] In this embodiment, when the caching system receives the target data to be written, determining the corresponding target hash bucket based on the data identifier of the target data using a hash function includes: Obtain the data identifier key of the target data; The corresponding hash bucket is determined by Hash_Index = Hash(Key) mod Hash_Size, where Hash_Index is the index of the hash bucket, Hash() is the hash function, Hash_Size is the size of the hash table, and mod is the modulo operation.
[0027] This scheme utilizes hash functions to map data identifiers to specific hash buckets, effectively distributing data storage locations, avoiding excessive concentration of conflicts, shortening retrieval paths, thereby enabling fast lookup and writing of cached data and improving the overall system response speed.
[0028] In this embodiment, the method further includes: When the caching system receives a request to access target data, it determines the target hash bucket and the corresponding version list based on the target data identifier and target version identifier, and then traverses the version list: If a version node matching the target version identifier is found, the content of the data node corresponding to the version node is returned. If no version node that exactly matches the target version identifier is found, the data node content corresponding to the old version node in the version list that is closest to and no later than the target version identifier is returned. If the target version identifier is earlier than the oldest version node in the version chain, it is determined as a cache miss.
[0029] This solution ensures that even when the target version cannot be accurately matched in the cache, it can still provide the closest old version data, thereby reducing the cache miss rate and improving the response success rate of user requests. It is especially suitable for application scenarios where data consistency requirements can tolerate a certain amount of latency.
[0030] The version list access method is as follows: Based on the data identifier Key, find the corresponding hash bucket and check if the hash list contains the data. If no data is found, it's a cache miss. If data is found, continue searching for the head node of the version list. If not found, it's a cache miss. If the head node is found, the version list needs to be traversed. The version information (Version_Info), i.e., the target version information, is compared against the version list. If the target version is older than the oldest version in the current version list, it means the target version is not in the cache, resulting in a cache miss, and it needs to be read from the underlying disk space. If the target version and the oldest version are the same, the data content of the oldest version node is returned. If the target version is newer than the oldest version, the next version node in the version list is compared. If the next node is newer than the target version, the data content of the previous node can be returned. If they are the same, the data content of the next node is returned. If the next node version is older, the version list is accessed again, and so on.
[0031] In this embodiment, the method further includes: When a cache miss is detected, a back-to-origin operation is triggered to retrieve the target data from the backend storage system and rewrite the target data into the cache system.
[0032] This solution ensures the integrity of the caching system, providing correct data even if a cache miss occurs through a write-back operation. Furthermore, writing back to the cache increases the hit rate of subsequent accesses, reduces the access pressure on the backend storage, and improves overall system performance.
[0033] In this embodiment, in response to the remaining cache space of the caching system being less than a first threshold, the corresponding popularity information is determined based on the number of multiple version nodes in the version chain, and candidate eviction data nodes are determined based on the popularity information of the version nodes and their positions in the version chain. Selecting and deleting the data node to be deleted from the candidate eviction data nodes includes: When the remaining cache space of the caching system is less than the first threshold, cached data is evicted, and the popularity of each version node and its position in the corresponding version list are obtained. Select the version node with the lowest popularity that is located at the top of the list as the elimination target; Delete the version node and data node corresponding to the target to be phased out; Among these, when selecting the version node with the lowest popularity and located at the top of the list as the elimination target, the following are also included: The oldest version node is selected as the final elimination target based on the time sequence of the version identifier.
[0034] In this embodiment, when deleting the version node and data node corresponding to the elimination target, the method further includes: Determine whether the data node to be deleted corresponding to the elimination target is marked as locked. If it is marked as locked, skip the current data node and continue to select the next candidate data node.
[0035] By incorporating a comprehensive judgment based on popularity and time location, the system can more intelligently select objects to be eliminated, avoiding the accidental deletion of frequently used data; at the same time, the addition of a locking mechanism can protect critical data from being cleared, improving the controllability and reliability of the caching strategy.
[0036] In this embodiment, obtaining the popularity of each version node includes: Get the access count of the i-th version node in the version list. i ; Get the weight of the i-th version node. i ; Based on the Access_Count of the i-th version node i Weight of the i-th version node i The product of these factors determines the heat value of the i-th version node. i .
[0037] This scheme combines access frequency and weight information to upgrade simple access statistics into a weighted popularity value, which can more reasonably reflect the actual use value of the data, thereby improving the accuracy and flexibility of cache eviction decisions.
[0038] In this embodiment, the weight of the i-th version node is obtained. i include: Get the base weight (Weight_Base) of the version node in the version list; Obtain the baseline growth coefficient ρ, and determine the growth coefficient ρ of the i-th version node based on the baseline growth coefficient ρ. i ; Based on the base weight Weight_Base of the version nodes in the version linked list and the growth coefficient ρ of the i-th version node. i The product of these factors determines the weight of the i-th version node. i .
[0039] The proposed scheme dynamically adjusts the weights by introducing a baseline growth coefficient ρ. The growth coefficient ρi of the i-th version node indicates that the more version nodes there are, the higher the popularity value. The baseline growth coefficient increases exponentially, which can significantly improve the influence of the popularity value. This allows the time a version node spends in the cache or its access characteristics to affect its priority, thereby achieving more flexible popularity control and ensuring that hot data is preferentially retained in the cache.
[0040] The data popularity statistics process is as follows: Read data with identifier K1 and version V2. Search the hash table to find the head node of the version linked list. At this point, there are two nodes in the version linked list. Compare them sequentially. If the version information matches the second node in the version linked list, return the data content of the second version node. Simultaneously, update the popularity information of the corresponding version node. For example, if the base weight (Weight_Base) of a version node is 1, the growth coefficient (ρ) is 1.1, and Access_Count2 is 1, then the weight (Weight2) of the second version node is 1.1, and the popularity value (Heat_Value2) is 1.1.
[0041] Read data with identifier K1 and version V1, find the first node in the version linked list, match the version information, and return the data content corresponding to the version node. Set Weight1 to 1, Access_Count1 to 1, and update the version node's heat_Value1 to 1.
[0042] Read the data identified as K1, version V3. Similarly, traverse the version list, find the last version node (which is the latest node in the list and older than the target version), and return its data content. Update its heat information. At this point, Access_Count2 is 2, and Heat_Value2 is 2.2.
[0043] During data eviction, nodes with lower usage frequency are prioritized for eviction. However, to maintain the integrity of the version list, nodes in the middle of the list cannot be evicted, as this would lead to data inconsistency. For example, if versions V3, V4, and V5 are added to the cache simultaneously, and version V4 is evicted, but V4 data is needed later, the version list is searched, finding a matching V3 node, while the required V4 data is already on disk. This results in data inconsistency. Therefore, eviction must consider both usage frequency and the integrity of the version list. The optimal eviction method is to select nodes with low usage frequency that are also the oldest nodes in the version list.
[0044] In this embodiment, the method further includes: When the caching system receives an update request, if the version list corresponding to the target data identifier already exists, it creates a new version node and inserts it at the end of the version list, while keeping the old version node from being overwritten, so as to support the coexistence of multiple versions.
[0045] This solution supports multi-version storage of data, which can retain historical data to meet backtracking needs, while also providing the latest version for quick access, thus balancing data consistency and historical traceability capabilities and improving the applicability of the system.
[0046] In this embodiment, the method further includes: Set a maximum version number threshold for each version list. If the number of version nodes in the version list exceeds the threshold, the oldest version node located at the first row of the list is deleted first to limit the cache usage of a single data identifier.
[0047] By limiting the number of versions corresponding to each data identifier, the mechanism avoids situations where a single data identifier occupies too many cache resources. This mechanism ensures a balanced allocation of cache space, improves overall cache utilization efficiency, and prevents cache pollution.
[0048] In the aforementioned cached data management method, a hash table is set up in the cache system to organize multiple version nodes corresponding to the same data identifier into a version linked list. When new data is written, the new version node is appended to the linked list instead of overwriting the old version, enabling the system to perceive and manage multiple versions of data. Simultaneously, by combining the popularity information of the version node with its position in the version linked list, a comprehensive judgment is made, selectively evicting the oldest version node with low popularity when cache space is insufficient. Through this approach, the cache system can maximize the retention of hot data while ensuring the reasonable eviction of old version data. This improves the accuracy of cached data eviction and avoids the accidental deletion of hot data, thereby guaranteeing data access consistency and the overall efficient operation of the system.
[0049] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.
[0050] In one embodiment, such as Figure 4 As shown, a cache data management device 10 is provided, including: a cache data management module 1, a hash bucket positioning module 2, a new version linked list module 3, a version appending module 4, and an expiration management module 5.
[0051] The cache data management module 1 is used to set up a hash table in the cache system to manage cache data, set a data identifier (Key) for the data nodes of the cache data and a version node for identifying version information, and attach multiple version nodes corresponding to the same data identifier to the same version linked list.
[0052] The hash bucket location module 2 is used to determine the corresponding target hash bucket based on the target data identifier of the target data using a hash function when the cache system receives the target data to be written, and to search for the existence of a head node in the hash chain of the target hash bucket.
[0053] The new version linked list module 3 is used to create a new head node in the hash linked list of the target hash bucket in response to the absence of a head node. The head node is set to point to the first row of the version linked list corresponding to the target data identifier, and a new version node is created in the first row of the version linked list to store the target data.
[0054] The version append module 4 is used to create a new version node to store the target data in response to the existence of a head node, and insert the new version node at the end of the version linked list.
[0055] The eviction management module 5 is used to respond to the situation where the remaining cache space of the caching system is less than the first threshold. It determines the corresponding popularity information based on the number of multiple version nodes in the version chain, determines the candidate eviction data nodes based on the popularity information of the version nodes and their positions in the version chain, selects the data nodes to be deleted from the candidate eviction data nodes, and deletes them.
[0056] In this embodiment, setting up a hash table in the caching system to manage cached data further includes: The hash table is set up by multiple hash buckets, each containing a hash list. Each node in the hash list is associated with a corresponding data identifier (key) and points to the version list corresponding to the data identifier. Multiple version data nodes in the version linked list are connected sequentially in order of version age. The head node of the hash linked list points to the first row of the version linked list, and the first row corresponds to the storage of the oldest version node.
[0057] In this embodiment, the head node of the hash chain points to the first row of the version chain, and the first row corresponds to the node storing the oldest version, including: Set the head node of the hash list to contain a pointer to the version node (Node_Ptr). The information included in the version node settings includes: Version identifier (Version_Info) is used to identify the version information of the data. The version identifier is a timestamp or an incrementing identifier number. Metadata information (Data_Info) is used to describe the logical address and volume information of the data. A data pointer (Data_Ptr) is used to point to the memory address where the data is stored. A pointer to the next version node (Next_Version); The popularity statistics (Version_Heat_Metric) are used to characterize the access popularity of version nodes.
[0058] In this embodiment, when the caching system receives the target data to be written, determining the corresponding target hash bucket based on the data identifier of the target data using a hash function includes: Obtain the data identifier key of the target data; The corresponding hash bucket is determined by Hash_Index = Hash(Key) mod Hash_Size, where Hash_Index is the index of the hash bucket, Hash() is the hash function, Hash_Size is the size of the hash table, and mod is the modulo operation.
[0059] In this embodiment, as Figure 4 As shown, the cache data management device 10 also includes a data access processing module 6, which is used for: When the caching system receives a request to access target data, it determines the target hash bucket and the corresponding version list based on the target data identifier and target version identifier, and then traverses the version list: If a version node matching the target version identifier is found, the content of the data node corresponding to the version node is returned. If no version node that exactly matches the target version identifier is found, the data node content corresponding to the old version node in the version list that is closest to and no later than the target version identifier is returned. If the target version identifier is earlier than the oldest version node in the version chain, it is determined as a cache miss.
[0060] In this embodiment, as Figure 4 As shown, the cache data management device 10 also includes a back-to-source write module 7, which is used for: When a cache miss is detected, a back-to-origin operation is triggered to retrieve the target data from the backend storage system and rewrite the target data into the cache system.
[0061] In this embodiment, in response to the remaining cache space of the caching system being less than a first threshold, the corresponding popularity information is determined based on the number of multiple version nodes in the version chain, and candidate eviction data nodes are determined based on the popularity information of the version nodes and their positions in the version chain. Selecting and deleting the data node to be deleted from the candidate eviction data nodes includes: When the remaining cache space of the caching system is less than the first threshold, cached data is evicted, and the popularity of each version node and its position in the corresponding version list are obtained. Select the version node with the lowest popularity that is located at the top of the list as the elimination target; Delete the version node and data node corresponding to the target to be phased out; Among these, when selecting the version node with the lowest popularity and located at the top of the list as the elimination target, the following are also included: The oldest version node is selected as the final elimination target based on the time sequence of the version identifier; When deleting the version node and data node corresponding to the elimination target, the following is also included: Determine whether the data node to be deleted corresponding to the elimination target is marked as locked. If it is marked as locked, skip the current data node and continue to select the next candidate data node.
[0062] In this embodiment, obtaining the popularity of each version node includes: Get the access count of the i-th version node in the version list. i ; Get the weight of the i-th version node. i ; Based on the Access_Count of the i-th version node i Weight of the i-th version node i The product of these factors determines the heat value of the i-th version node. i .
[0063] In this embodiment, the weight of the i-th version node is obtained. i include: Get the base weight (Weight_Base) of the version node in the version list; Obtain the baseline growth coefficient ρ, and determine the growth coefficient ρ of the i-th version node based on the baseline growth coefficient ρ. i ; Based on the base weight Weight_Base of the version nodes in the version linked list and the growth coefficient ρ of the i-th version node. i The product of these factors determines the weight of the i-th version node.i .
[0064] In this embodiment, as Figure 4 As shown, the cache data management device 10 also includes a multi-version update module 8, which is used for: When the caching system receives an update request, if the version list corresponding to the target data identifier already exists, it creates a new version node and inserts it at the end of the version list, while keeping the old version node from being overwritten, so as to support the coexistence of multiple versions.
[0065] In this embodiment, as Figure 4 As shown, the cache data management device 10 also includes a version quantity limit module 9, which is used for: Set a maximum version number threshold for each version list. If the number of version nodes in the version list exceeds the threshold, the oldest version node located at the first row of the list is deleted first to limit the cache usage of a single data identifier.
[0066] In the aforementioned cache data management device, a hash table is set up in the cache system to organize multiple version nodes corresponding to the same data identifier into a version linked list. When new data is written, the new version node is appended to the linked list instead of overwriting the old version, enabling the system to perceive and manage multiple versions of data. Simultaneously, by combining the popularity information of the version node with its position in the version linked list, a comprehensive judgment is made, selectively evicting the oldest version node with low popularity when cache space is insufficient. In this way, the cache system can maximize the retention of hot data while ensuring that old version data is reasonably evicted. This improves the accuracy of cache data eviction and avoids the accidental deletion of hot data, thereby guaranteeing data access consistency and the overall efficient operation of the system.
[0067] For a description of the features in the embodiment corresponding to the cache data management device, please refer to the relevant description in the embodiment corresponding to the cache data management method, which will not be repeated here.
[0068] Embodiments of this application also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above-described embodiments of the cache data management method.
[0069] In one embodiment, the electronic device may be a server, and its internal structure diagram may be as follows: Figure 5As shown, this electronic device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system, computer programs, and the database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage medium. The database stores cached data management data. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements a cached data management method.
[0070] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above-described embodiments of the cache data management method when running: In the caching system, a hash table is set to manage cached data. Data nodes of cached data are assigned data identifiers (Keys) and version nodes for identifying version information. Multiple version nodes corresponding to the same data identifier are linked to the same version list. When the caching system receives the target data to be written, it determines the corresponding target hash bucket based on the target data identifier using a hash function, and then searches the hash chain of the target hash bucket to see if a head node exists. If no head node exists, a new head node is created in the hash chain of the target hash bucket, and the head node is pointed to the first row of the version chain corresponding to the target data identifier. A new version node is created in the first row of the version chain to store the target data. In response to the existence of a head node, a new version node is created to store the target data, and the new version node is inserted at the end of the version list; When the remaining cache space of the caching system is less than the first threshold, the corresponding popularity information is determined based on the number of multiple version nodes in the version chain. Candidate data nodes to be eliminated are determined based on the popularity information of the version nodes and their positions in the version chain. Data nodes to be deleted are selected from the candidate data nodes to be eliminated and deleted.
[0071] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0072] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above-described cache data management method embodiments: In the caching system, a hash table is set to manage cached data. Data nodes of cached data are assigned data identifiers (Keys) and version nodes for identifying version information. Multiple version nodes corresponding to the same data identifier are linked to the same version list. When the caching system receives the target data to be written, it determines the corresponding target hash bucket based on the target data identifier using a hash function, and then searches the hash chain of the target hash bucket to see if a head node exists. If no head node exists, a new head node is created in the hash chain of the target hash bucket, and the head node is pointed to the first row of the version chain corresponding to the target data identifier. A new version node is created in the first row of the version chain to store the target data. In response to the existence of a head node, a new version node is created to store the target data, and the new version node is inserted at the end of the version list; When the remaining cache space of the caching system is less than the first threshold, the corresponding popularity information is determined based on the number of multiple version nodes in the version chain. Candidate data nodes to be eliminated are determined based on the popularity information of the version nodes and their positions in the version chain. Data nodes to be deleted are selected from the candidate data nodes to be eliminated and deleted.
[0073] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in any of the above-described cache data management method embodiments: In the caching system, a hash table is set to manage cached data. Data nodes of cached data are assigned data identifiers (Keys) and version nodes for identifying version information. Multiple version nodes corresponding to the same data identifier are linked to the same version list. When the caching system receives the target data to be written, it determines the corresponding target hash bucket based on the target data identifier using a hash function, and then searches the hash chain of the target hash bucket to see if a head node exists. If no head node exists, a new head node is created in the hash chain of the target hash bucket, and the head node is pointed to the first row of the version chain corresponding to the target data identifier. A new version node is created in the first row of the version chain to store the target data. In response to the existence of a head node, a new version node is created to store the target data, and the new version node is inserted at the end of the version list; When the remaining cache space of the caching system is less than the first threshold, the corresponding popularity information is determined based on the number of multiple version nodes in the version chain. Candidate data nodes to be eliminated are determined based on the popularity information of the version nodes and their positions in the version chain. Data nodes to be deleted are selected from the candidate data nodes to be eliminated and deleted.
[0074] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0075] The cached data management method and electronic device provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only intended to help understand the method and core ideas of this application. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of this application.
Claims
1. A method for managing cached data, characterized in that, include: A hash table is set up in the caching system to manage cached data. Data identifiers and version nodes for identifying version information are set for the data nodes of the cached data. Multiple version nodes corresponding to the same data identifier are linked to the same version list. When the caching system receives the target data to be written, it determines the corresponding target hash bucket based on the target data identifier of the target data using a hash function, and searches for the existence of a head node in the hash chain of the target hash bucket. In response to the absence of a head node, a new head node is created in the hash chain of the target hash bucket, and the head node is pointed to the first row of the version chain corresponding to the target data identifier. A new version node is created in the first row of the version chain to store the target data. In response to the existence of a head node, a new version node is created to store the target data, and the new version node is inserted at the end of the version list; When the remaining cache space of the caching system is less than a first threshold, the corresponding popularity information is determined according to the number of multiple version nodes in the version chain, and candidate data nodes to be eliminated are determined according to the popularity information of the version nodes and their positions in the version chain. Data nodes to be deleted are selected from the candidate data nodes to be eliminated and deleted.
2. The cache data management method according to claim 1, characterized in that, The method of setting up a hash table in the caching system to manage cached data also includes: The hash table is configured to include multiple hash buckets, each of which contains a hash chain, wherein the nodes of the hash chain are associated with corresponding data identifiers and point to the version chain corresponding to the data identifier; The multiple version data nodes in the version linked list are connected sequentially in the order of newest and oldest versions. The head node of the hash linked list points to the first row of the version linked list, and the first row corresponds to the storage of the oldest version node.
3. The cache data management method according to claim 2, characterized in that, The head node of the hash chain points to the first row of the version chain, and the first row corresponds to the node storing the oldest version, including: The head node of the hash chain is configured to contain a pointer to the version node; The information included in the version node setting includes: Version identifier, used to identify the version information of the data, wherein the version identifier is a timestamp or an incrementing identifier number; Metadata information is used to describe the logical address and volume information of the data access. A data pointer is used to point to the memory address where data is stored. A pointer to the next version node; Popularity statistics are used to characterize the access popularity of the version node.
4. The cache data management method according to claim 1, characterized in that, The method further includes: When the caching system receives a request to access target data, it determines the target hash bucket and the corresponding version list based on the target data identifier and target version identifier, and then traverses the version list: If a version node matching the target version identifier is found, the data node content corresponding to the version node is returned; If no version node that exactly matches the target version identifier is found, the data node content corresponding to the old version node in the version list that is closest to the target version identifier and no later than the target version identifier is returned. If the target version identifier is earlier than the oldest version node in the version list, it is determined as a cache miss.
5. The cache data management method according to claim 4, characterized in that, The method further includes: When a cache miss is detected, a back-to-origin operation is triggered to retrieve the target data from the backend storage system and rewrite the target data in the cache system.
6. The cache data management method according to claim 1, characterized in that, When the remaining cache space of the caching system is less than a first threshold, the following steps are taken: determining the corresponding popularity information based on the number of multiple version nodes in the version chain; determining candidate eviction data nodes based on the popularity information of the version nodes and their positions in the version chain; and selecting and deleting data nodes from the candidate eviction data nodes. When the remaining cache space of the caching system is less than a first threshold, cached data is evicted, and the popularity of each version node and its position in the corresponding version list are obtained. Select the version node with the lowest popularity that is located at the top of the list as the elimination target; Delete the version node and data node corresponding to the elimination target; Among these, when selecting the version node with the lowest popularity and located at the top of the list as the elimination target, the following are also included: The oldest version node is selected as the final elimination target based on the time sequence of the version identifier.
7. The cache data management method according to claim 6, characterized in that, The process of deleting the version node and data node corresponding to the elimination target also includes: Determine whether the data node to be deleted corresponding to the elimination target is marked as locked. If it is marked as locked, skip the current data node and continue to select the next candidate data node.
8. The cache data management method according to claim 6, characterized in that, The process of obtaining the popularity of each version node includes: Get the number of visits to the i-th version node in the version list; Obtain the weight of the i-th version node; The popularity value of the i-th version node is determined by multiplying the number of visits to the i-th version node by the weight of the i-th version node.
9. The cache data management method according to claim 8, characterized in that, The process of obtaining the weight of the i-th version node includes: Obtain the basic weight of the version nodes in the version linked list; Obtain the baseline growth coefficient ρ, and determine the growth coefficient ρi of the i-th version node based on the baseline growth coefficient ρ; The weight of the i-th version node is determined by multiplying the basic weight of the version node in the version list with the growth coefficient ρi of the i-th version node.
10. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the cache data management method as described in any one of claims 1 to 9 when executing the computer program.
Citation Information
Patent Citations
Distributed cache management method based on version control and manager
CN111858556A
Asynchronous cache coherency for mvcc based database systems
CN112384906A
Cache management method and device, equipment and storage medium
CN115964391A
Graph data security caching method, terminal equipment and storage medium
CN118350025A
Data caching method, computer equipment, storage medium and program product
CN119322593A
Cited By
Cache management method and electronic equipment
CN122195883A