Rapid cache recovery method based on cold and hot characteristics
Through the cache recovery method based on hot and cold characteristics, the recovery speed of cached data is optimized, the problem of slow recovery speed in the existing technology is solved, and the rapid restart and high availability of the system are achieved.
Patent Information
- Application Number
- CN202411373430.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2024-12-27
AI Technical Summary
In the prior art, cached data recovery scheme based on nonvolatile media is slow to recover after downtime, especially for frequently used data, which leads to system access stuttering in the initial stage and cannot work normally.
Using a fast cache recovery method based on hot and cold characteristics, the hot and cold values of the data are calculated through the hot and cold management module, and data with high hot and cold values are stored first in non-volatile media, while low-frequency data are stored only in volatile media. In the meantime, quickly restore high-frequency data after downtime and obtain low-frequency data from the data source to avoid lag.
It realizes rapid recovery of cached data, improves the system's rapid restart ability after downtime, avoids the initial lag in system access, and meets the requirements of high availability and high reliability.
Smart Images

Figure CN119201000A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of cache abnormality recovery, and in particular to a fast cache recovery method based on hot and cold features. Background Art
[0002] With the development of Internet technology and BS mode (browser / server mode) applications, more flexible use and humanized interaction require an increasing amount of data to be generated at a time. Caching technology is the guarantee for the continued development of WEB systems. In Internet applications, it can significantly solve the performance access bottleneck between database servers and WEB servers. Caching technology is also becoming more and more widespread, with a variety of caching technologies flourishing.
[0003] For complex system cloud computing services and storage devices with high security requirements, they are usually run as basic equipment platforms. The faster the recovery time of a failure is required, the better, so that the upper-layer business can run stably. The industry requires that the MTBF of storage devices is 10,000 hours, and an average of 1 failure is allowed in 10,000 hours, which is less than 99.99%. In other words, the maximum interruption time in the past year is 50 minutes. Therefore, rapid recovery of equipment after downtime is very necessary.
[0004] In the prior art, a cache data recovery solution based on non-volatile media is usually adopted, which is a traditional recovery strategy for cache systems. The core logic of this solution is to use non-volatile media (such as hard disks, SSDs, etc.) as persistent storage for cache data. When the system is running normally, cache data is stored in the memory to provide fast access, and all cache data in the memory is asynchronously written to the non-volatile media regularly or based on trigger conditions to ensure data persistence. When the system crashes, the service is quickly restarted by recovering the cache data from the non-volatile media to the memory. However, the cache data recovery solution based on non-volatile media depends on the data loading process from the disk to the memory after the crash, so all data needs to be recovered. As a result, the amount of data to be recovered is large, which may lead to a slow recovery speed for frequently used data. At the same time, in the prior art, for applications with low security levels, cache data can also be gradually updated by re-querying the data source. Although data source recovery does not consume space, recovery takes a long time, causing jams in the early stage of system access, and the cache cannot work properly. Summary of the invention
[0005] Based on this, in order to solve the above technical problems, a fast cache recovery method based on hot and cold characteristics is provided to solve the problem that the prior art may cause slow recovery speed for frequently used data.
[0006] In a first aspect, a fast cache recovery method based on hot and cold features is applied to a main process, the method comprising:
[0007] In response to the start of the cache service, entering the working state; the start of the cache service is restarting the cache service after abnormal downtime or shutdown;
[0008] Control the operation of the hot and cold management module to perform hot and cold calculations on the data in the cache storage space, and add the data that needs to be updated to the common task queue QC according to the hot and cold values based on the hot and cold calculation results;
[0009] Control the Master controller and the Slave controller to read the persistent cache data from the non-volatile medium, and add the task of reading the persistent cache data to the cache write queue QW; control the Slave controller to synchronize the cache with the Master controller;
[0010] Control the execution of data in the cache write queue QW in sequence, so that when the data in the cache write queue QW is persistent cache data read from the non-volatile medium, the cache data is written to the volatile medium, and when the data in the cache write queue QW is data read from the common task queue QC, the data with a hot and cold value greater than or equal to a certain threshold is cached in the non-volatile medium and the volatile medium, and the data with a hot and cold value less than a certain threshold is cached in the volatile medium; after the execution of any data in the cache write queue QW is completed, all cache data are passed to the hot and cold management module to calculate the hot and cold values and then refresh the task order in the common task queue QC; the task in the cache write queue QW is the task of writing the cache data into the cache storage space;
[0011] When all tasks in the cache write queue QW are executed, the tasks in the event task queue QE are executed, the data source interface is called to obtain data, and the data is added to the write queue QW, waiting to be written into the cache; the tasks in the event task queue QE are tasks that obtain data corresponding to the event after the event is detected;
[0012] When all tasks in the event task queue QE are executed, the tasks in the common task queue QC are executed in sequence, the data source interface is called to obtain data, and the data is added to the write queue QW; the tasks of the common task queue QC are to calculate the hot and cold values of the cached data according to the set time or after the data in the cache write queue QW is written and re-sorted; the tasks in the common task queue QC are tasks for updating the cached data that needs to be updated beyond the set time.
[0013] In the above solution, optionally, after controlling the Slave controller to read the persistent cache data from the non-volatile medium, the method further includes: adding the cache data to the cache synchronization queue QS, so that the local data is read from the cache synchronization queue QS and transmitted to the remote end.
[0014] In the above scheme, further optionally, after controlling the Slave controller to synchronize the cache with the Master controller, the method further includes: receiving a pause signal, wherein the pause signal is when the client requests the server to obtain data, the server cannot find the corresponding data in the cache storage space and sends it to the main process;
[0015] A cancel pause signal is received; the cancel pause signal is that the server obtains data locally or through other controllers, and adds the obtained data to the cache write queue QW so that it is written to the volatile medium.
[0016] In the above solution, further optionally, after controlling the Slave controller to synchronize the cache with the Master controller, the step further includes: receiving an end signal and exiting the operation.
[0017] In the above solution, optionally, in response to the start of the cache service, after entering the working state, the method further includes: detecting whether there are other processes running, and if so, ending the work.
[0018] In the above solution, optionally, the controlling and running of the cold and hot management task module to perform cold and hot calculations on the data in the cache storage space includes:
[0019] The cold and hot management task module obtains the total number of accesses to all data and the number of accesses to each data from the inspection access records, and calculates the access frequency of each data;
[0020] Calculate the time consumption score of each data, the time consumption score of the controller transmission, and the change type score;
[0021] If the cache task of the Master controller is not the current controller, the data hot and cold values are calculated using the following formula:
[0022] Total score HCS1 = access frequency score NTS*50% + change type score CTS*30% + data consumption time score DES*20%;
[0023] If the Master controller cache task is other than the current controller, the data hot and cold values are calculated using the following formula:
[0024] Total score HCS2 = HCS1 + controller transmission time score CES * 10%.
[0025] In the above scheme, optionally, the method also includes: receiving a signal that the Slave controller is upgraded to the Master controller, recording the controller upgraded from the Slave controller to the Master controller as the upgraded Master controller, controlling other Slave controllers to synchronize cached data to the upgraded Master controller, and adding data to the cache write queue QW.
[0026] In the above solution, optionally, the volatile medium is a memory or a virtual memory, and the non-volatile medium is a file system, a database, or a hard disk.
[0027] In a second aspect, a computer device includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of a fast cache recovery method based on hot and cold features described in the first aspect are implemented.
[0028] In a third aspect, a computer program product includes a computer program / instruction, which, when executed by a processor, implements the steps of a fast cache recovery method based on hot and cold features as described in the first aspect.
[0029] This application has at least the following beneficial effects:
[0030] The present application calculates the hot and cold values of the data during normal cache updates, sorts the data according to the hot and cold values, updates the data with high hot and cold values first, and controls the data with hot and cold values greater than a certain threshold to be stored in the non-volatile medium when the updated data is placed in the write queue, while the data with hot and cold values less than a certain threshold is not stored in the non-volatile medium, and is only placed in the volatile medium, thereby ensuring that the data stored in the non-volatile medium is the data with high hot and cold values, that is, the data with high access frequency. After a crash, the data obtained from the non-volatile medium are all the data with high hot and cold values, thereby achieving the problem of fast cache recovery of data with high access frequency. For data with low access frequency, if an instruction to access the data is encountered, it is obtained from the data source, and since the access frequency of such data is low, it will not cause a large number of accesses, and thus will not cause jams. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 A flowchart of a fast cache recovery method based on hot and cold features is provided for an embodiment of the present application;
[0032] Figure 2 A flowchart of Master abnormal recovery is provided for an embodiment of the present application;
[0033] Figure 3 A Slave abnormal recovery flow chart provided for an embodiment of the present application;
[0034] Figure 4 A flowchart of a cache event listening process CEL performing event listening provided in one embodiment of the present application;
[0035] Figure 5 A queue execution flow chart provided for one embodiment of the present application;
[0036] Figure 6 A main thread execution flow chart provided for one embodiment of the present application;
[0037] Figure 7 A flowchart of a cache synchronization task process CSP providing an embodiment of the present application for synchronizing data to a remote end;
[0038] Figure 8 A flowchart of a user request to obtain data provided in one embodiment of the present application;
[0039] Fig. 9 A flow chart of heat and cold calculation provided for one embodiment of the present application;
[0040] Fig.10 A recovery flowchart for upgrading a slave to a master is provided for an embodiment of the present application. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0042] Some of the scenarios involved in this application are introduced as follows:
[0043] Cache Response:
[0044] 1. The client (browser, gateway, CURL, etc.) requests the storage WEB service. The storage system retrieves the cache service, caches the response to the WEB service, and then feeds it back to the client. If there is no record in the cache, the cache is synchronized through the data source. Of course, the data source directly returns and then synchronizes to the cache. If the requested Slave controller is cached, it is synchronized;
[0045] 2. The actions initiated by the client (non-query requests) correspond to the cache, which needs to ensure accuracy. In particular, check whether the cache needs to be refreshed. In order to prevent conflicts with event-triggered tasks, the time is recorded before the action starts. After the action is completed, check whether the refresh time of the current cache is after the action starts or the cache refresh task is already in the queue. If it is, give up refreshing the cache, otherwise you need to add a cache refresh task.
[0046] Hot and cold statistics:
[0047] 1. The cached responses will be recorded, the response time of the data source during cache synchronization will be recorded, and the data transmission between controllers will also be recorded; the cache response frequency and data time will be predefined by default, and the transmission time between controllers is 0 by default. The predefined time is for calculation during downtime recovery; the default update interval of cached data will also be defined to determine whether the task should be executed during normal task traversal;
[0048] 2. The change type of cache data. The change type can only be predefined before leaving the factory or manually changed by the configuration file. The change type is the initial hot and cold priority division. The change type not only affects the weight of the hot and cold priority calculation, but also directly determines the synchronization method of the cache.
[0049] (1) Immutable: cannot be changed unless the system is completely restored; for example, system type, major version, and factory predefined configuration;
[0050] (2) Extremely difficult to change: They will not change during normal operation, but may change when the system crashes or restarts; for example, device hardware and system version;
[0051] (3) Ordinary changes: changes that occur after the system is manually configured, usually accompanied by event triggers; must be the creation, modification, and deletion of virtual resources;
[0052] (4) Changeable: Resources that are predicted to be frequently operated by humans, usually triggered by events; for example, main functions;
[0053] (5) Extremely changeable: Resources that change without human intervention and with changes in the environment or time, usually without events, such as the device's monitoring information such as temperature, humidity, and voltage. These caches usually need to be refreshed regularly and cannot wait until an event occurs.
[0054] 3. Hot and cold statistics will be calculated based on the cache response frequency, data source time, inter-controller transmission time (the transmission of this controller will be considered as 0), and the variable type of cache data using the weighted average method to calculate the hot and cold values, and the data will be divided into cold data or hot data according to the set hot and cold thresholds.
[0055] 4. Overall, the hot and cold division is to distinguish the priority of cache updates. Ordinary cache update tasks can be synchronized in sequence. High response frequency should be synchronized first, low data source time and low controller time should be synchronized first, and the easier the change, the higher the priority. The score of high priority should be higher than the score of low priority with the same indicator; the weight ratio should be response frequency greater than change type greater than response time greater than transmission time.
[0056] 5. Hot data or newly generated hot data during the operation of the storage system is persistently stored.
[0057] Cache synchronization:
[0058] 1. Cache synchronization operation logic: There are two queues, the ordinary queue for timed synchronization and the event synchronization queue.
[0059] 2. When an action occurs in a single controller storage system, IO requests, monitoring events, scheduled tasks trigger cache synchronization, including actions from the client, which are added to the event synchronization task queue.
[0060] 3. The cache synchronization process cyclically reads the ordinary task queue, requests the actual data source, and cyclically synchronizes and refreshes the local cache data; the ordinary task queue will be executed only when there is no task in the event synchronization queue.
[0061] 4. In a multi-controller system, the Master controller will always respond to client requests. When responding to Slave data, the Master will check the validity of the local corresponding Slave cache. If it expires, it will actively request the Slave cache data. The Slave response process here is consistent with that of a single controller, but it will feedback whether the data comes from the cache or the actual data source.
[0062] 5. When a single controller refreshes the local cache, if it is a Slave controller, it will actively synchronize the cache data to the Master and record the time consumed by synchronizing only the cache data between the controllers.
[0063] Abnormal recovery:
[0064] 1. Hot and cold initialization: Load persistent hot data, merge it with the predefined default configuration, and calculate the hot and cold data division.
[0065] 2. Local direct recovery: When the storage system is restored after a crash, the integrity of the locally persisted cached data is verified and the cached data is restored. To prevent data loss due to a crash, the cached data should be split and stored separately when it is persisted to ensure its consistency and integrity.
[0066] 3. Controller synchronization recovery: At this time, the current controller has been restarted after crashing. It must be in the Slave role. Refresh the local cache and synchronize it to the Master controller. There is no need to synchronize the cache from the Master to the local end. Wait until the local cache is ready to synchronize to the Master.
[0067] 4. Controller failover: The Master controller suddenly crashes and the Slave becomes the Master. At this time, all remaining available controller caches need to be synchronized to the local end.
[0068] 5. Data source synchronization: When persistent data or other controllers have no cached data, choose to synchronize cached data from the data source.
[0069] The following terms are used in this application:
[0070] 1. Entity or service: a separate entity or an independently running service process.
[0071] Web client WC (web client): An application client that can make HTTP requests and responses and render returned data, such as browsers, gateways, mail clients, CURL, etc.
[0072] Web server WS (web services): A WEB server that can receive HTTP requests, process and return them. It also interacts with cache services, such as Nginx, Apache, IIS, etc.
[0073] Cache main process (CMP): The main process of the storage system cache service. In order to save system resource consumption and prevent concurrency errors, all interactive tasks must be controlled by the main process and completed in collaboration with other processes. It is responsible for waiting for cache instructions from the cache interface and cache event listeners, parsing event task queues and circulating ordinary task queues, and distributing tasks to cache update or synchronization processes.
[0074] Cache synchronization process CSP (cache synchronize process): receives cache synchronization instructions from the main process, loops through the cache synchronization task queue, requests the cache interface of the specified controller, and synchronizes the cache data to the specified controller.
[0075] Cache event listen process CEL (cache event listen process): subscribes to and listens to events from the storage system, adds cache update tasks corresponding to event conversions to the event task queue, and reports to the cache master process CMP.
[0076] 2. Interface: It does not run independently, can be called directly locally or remotely (RPC) via an interface that uses synchronous calling and can complete and return quickly.
[0077] Cache external interface (CEI): Cache external interface, which accepts data requests from the web server WS and reports to the cache master process, and returns data to WS; it also accepts cache acquisition requests from other controllers.
[0078] Cache data source interface CSI (cache source interface): actual data source interface.
[0079] Cache read interface CRI (cache read interface): Get local cache data and check whether the local cache exists. If it exists, the data is returned directly. If it does not exist, the cache is not updated here.
[0080] Cache write interface CWI (cache write interface): writes cache data into the cache space interface.
[0081] Cache hot and cold interface (CHC): counts and calculates the hot and cold priorities of cache items based on indicator weights.
[0082] 3. Data or configuration:
[0083] Cache data CD (cache data): cache data, recorded in volatile storage media, with fast storage and reading speed, recording data hot and cold characteristic values, update time, and update interval.
[0084] Persistent cache data CNV (cache nonvalatile): cache data, recorded in non-volatile storage media, only saves hot data cache, cannot be directly read by the cache service, and is only used for exception recovery.
[0085] Cache access record RCR (record of cache request): Cache access record, used for cache hotspot calculation features. Each cache access will be recorded, including cache record time, acquisition time, and controller transmission time. If the cache data exists, the acquisition time and controller transmission time are 0, and it does not participate in hotspot calculation.
[0086] Event task queue QE (event queue): After the event listener CEL detects an event, it will add the cache update task to the event task queue. The main process is responsible for reading the task and executing it.
[0087] Common task queue QC (common queue): The common task queue is the update task and the output of hot and cold management. The hot and cold statistics management will update the task order according to the calculation. The common task is the full data cache task.
[0088] Cache synchronization task queue QS (synchronize queue): The cache data that needs to be synchronized to other controllers is added to the cache synchronization task queue. The cache synchronization process loops through the synchronization task queue to synchronize the data to other controllers.
[0089] Cache write queue QW (write queue): When cache data needs to be written to the cache storage space, it is first added to the write queue. The main process loops through the write queue to save the cache. The cache storage method here can be volatile media such as memory and virtual memory, or non-volatile media such as file systems, databases, and hard disks.
[0090] In one embodiment, Figure 1 As shown, a fast cache recovery method based on hot and cold features is provided, which is applied to the main process, and the method includes:
[0091] Step S1: In response to the start of the cache service, the system enters a working state; the start of the cache service is to restart the cache service after an abnormal downtime or shutdown.
[0092] Step S2: Control the operation of the cold and hot management module to perform cold and hot calculations on the data in the cache storage space, and add the data to be updated to the common task queue QC according to the cold and hot values based on the cold and hot calculation results.
[0093] Step S3: Control the Master controller and the Slave controller to read the persistent cache data from the non-volatile medium, and add the task of reading the persistent cache data to the cache write queue QW; control the Slave controller to synchronize the cache with the Master controller.
[0094] In step S3, the abnormal recovery process is executed by the master process, and the existing cache data that can be quickly restored is immediately restored; for Master abnormal recovery: Figure 2 , the controller directly acts as the Master when it starts. Exception recovery requires loading the persistent cache and notifying the Slave controller to synchronize the cache with the Master, which usually includes the following steps:
[0095] Recm1: Starts recovery as the Master controller;
[0096] Recm2: Read the persistent cache data CNV and load the cache;
[0097] Recm3: Add cache tasks to the cache write queue;
[0098] Recm4: Send a signal to the Slave to notify the Slave to synchronize the cache with the Master. Only the Slave's persistent cache needs to be synchronized. The Slave cache is not directly obtained here. The Slave may not be ready for the cache.
[0099] Recm5: Recovery completed, return to the main process CMP.
[0100] For Slave abnormal recovery, such as Figure 3 Said, comprising the following steps:
[0101] Recs1: Starts recovery as a slave controller;
[0102] Recs2: Read the persistent cache data CNV and load the cache;
[0103] Recs3: Add the loaded cache data to the cache write queue QW;
[0104] Recs4: Add cache data to the cache synchronization queue QS, and synchronize the cache to the Master;
[0105] Recs5: Recovery completed, return to the main process CMP.
[0106] Step S4: Control the execution of the data in the cache write queue QW in sequence, so that when the data in the cache write queue QW is the persistent cache data read from the non-volatile medium, the cache data is written to the volatile medium, and when the data in the cache write queue QW is the data read from the ordinary task queue QC, the data with a hot and cold value greater than or equal to a certain threshold is cached in the non-volatile medium and the volatile medium, and the data with a hot and cold value less than a certain threshold is cached in the volatile medium; after the execution of any data in the cache write queue QW is completed, all the cache data are passed to the hot and cold management module to calculate the hot and cold values and then refresh the task order in the ordinary task queue QC; the task in the cache write queue QW is the task of writing the cache data to the cache storage space.
[0107] Step S5: When all tasks in the cache write queue QW are executed, execute the tasks in the event task queue QE, call the data source interface to obtain data, and add the data to the write queue QW, waiting to be written to the cache; the tasks in the event task queue QE are tasks that obtain the data corresponding to the event after detecting the event.
[0108] In step S5, event listening is usually performed through the cache event listening process CEL, such as Figure 4 The event listening task process will be connected to the event server through the socket. When a new event is generated in the system, the event information will be sent to the socket client CEL that subscribes to it through the event server. The specific steps include:
[0109] Step 1: The CEL process starts with the boot or with the main process;
[0110] Step 2: Determine whether the cache event listening process CEL task has been started. If it has been started, exit directly;
[0111] Step 3: Connect to the event server and subscribe to events;
[0112] Step 4: Start the main loop to determine whether the process end signal is received. If the end signal is received, exit the subscription Step 6 and exit the process Step 7;
[0113] Step 5: Receive event information from the event server, parse the information, find the corresponding cache task and add it to the event task queue QE, then continue to execute Step 4 in a loop after sleeping;
[0114] Step 6: Unsubscribe from the event server;
[0115] Step 7: Clear the process ID and exit the process.
[0116] Step S6: When all tasks in the event task queue QE are executed, the tasks in the common task queue QC are executed in sequence, the data source interface is called to obtain data, and the data is added to the write queue QW; the tasks of the common task queue QC are to calculate the hot and cold values of the cached data according to the set time or after the data in the cache write queue QW is written and re-sorted; the tasks in the common task queue QC are tasks for updating the cached data that needs to be updated beyond the set time.
[0117] Specifically, Figure 5 As shown, check the write queue QW. If there is a write queue, read the write task and call the cache write interface CWI to update the cache data CD. Then, pass the cache data to the hot and cold management interface CHC to calculate the hot and cold values and refresh the common task QC, and start again. Here, refreshing the hot and cold values only refreshes the hot and cold values of a single cache task. If there is no write queue, execute the event task queue QE.
[0118] Continue to detect the event task queue QE. If there is an event task queue, read the task queue and call the data source interface to obtain data, add the data to the cache write queue. If it is currently a standby control, synchronize the data to the cache synchronization task QS and start again. If there is no event task queue, execute the normal task queue QC;
[0119] Continue to detect the ordinary task queue QC. The ordinary task queue will compare the update interval. If the current elapsed time is greater than the update interval, the ordinary task will be updated. The call data source and synchronization are consistent with the event task queue QE.
[0120] Special note: Updates to the cache by ordinary tasks, event tasks, or external calls will be considered normal updates. The update interval will be refreshed, and the cache refresh time will also be refreshed. In the ordinary task queue, data with higher popularity can always be executed faster.
[0121] Check whether the last hot and cold calculation refresh time has timed out and has not been refreshed for a long time. If a refresh is required, recalculate all task refresh hot and cold values and update them to the normal task QC.
[0122] For the cache master process, Figure 6 Describe the main process of the cache service. The cache service will be restarted after an abnormal downtime or shutdown. The cache service needs to be restarted automatically, including the following processes:
[0123] Step 1: The main process is called up, and the device should have just started up;
[0124] Step 2: Process mark. The main process can only run uniquely. If there is an existing process, the current task will exit directly.
[0125] Step 3: Run the cold and hot management task CHC in synchronous mode to load cold and hot data;
[0126] Step 4: Restore the persistent cache;
[0127] Step 5: Signal registration, detection signal input;
[0128] Step 6: Queue execution, loop each queue, determine the end signal and pause signal, and terminate the cached data when the pause signal is detected;
[0129] Step 7: The process exits after detecting the end signal.
[0130] In the above-mentioned fast cache recovery method based on hot and cold characteristics, when updating the cache at ordinary times, the hot and cold values of the data are calculated, and the data is sorted according to the hot and cold values. The data with high hot and cold values are updated first. At the same time, when the updated data is placed in the write queue, the data with hot and cold values greater than a certain threshold is controlled to be stored in the non-volatile medium, and the data with hot and cold values less than a certain threshold is not stored in the non-volatile medium, but only placed in the volatile medium, thereby ensuring that the data stored in the non-volatile medium is the data with higher hot and cold values, that is, the data with higher access frequency. After the downtime, the data obtained from the non-volatile medium are all the data with higher hot and cold values, thereby realizing the problem of fast cache recovery of data with higher access frequency. For data with lower access frequency, if an instruction to access the data is encountered, it is obtained from the data source. Since the access frequency of such data is low, it will not cause a large number of accesses, and thus will not cause jams.
[0131] In one embodiment, after controlling the Slave controller to read the persistent cache data from the non-volatile medium, the method further includes: adding the cache data to the cache synchronization queue QS, so that the local data is read from the cache synchronization queue QS and transmitted to the remote end.
[0132] Specifically, Figure 7 As shown, the cache synchronization task process CSP is a cache synchronization process that runs independently or a task thread of the main process. Different from the synchronization call that actively obtains the cache database of other controllers, cache synchronization only synchronizes the local data to the remote end, and specifically includes the following steps:
[0133] Step 1: The process starts with the boot or with the main process;
[0134] Step 2: Determine whether the cache synchronization CSP task has been started. If it has been started, exit directly;
[0135] Step 3: Start the main loop to determine whether the process end signal is received. If the end signal is received, exit the process directly;
[0136] Step 4: Read the synchronous task queue QS. If there is a task to be executed, continue to execute Step 5. If there is no task to be executed, go back to the main loop and start Step 3 after sleeping.
[0137] Step 5: Call the remote interface CEI to obtain cache data;
[0138] Step 6: Execute cache synchronization and update the time taken to synchronize the cache to the controller transmission time taken to access the record CRC; after sleeping, return to Step 3;
[0139] Step 7: Exit the cache synchronization task process, regardless of whether there are cache tasks QS to be synchronized, usually because a task end signal is received.
[0140] In one embodiment, after controlling the slave controller to synchronize the cache with the master controller, the method further includes: receiving a pause signal, wherein the pause signal is when the client requests the server to obtain data, the server cannot find the corresponding data in the cache storage space and sends it to the main process;
[0141] A cancel pause signal is received; the cancel pause signal is that the server obtains data locally or through other controllers, and adds the obtained data to the cache write queue QW so that it is written to the volatile medium.
[0142] Specifically, Figure 8As shown in the figure, the client requests to obtain cache data. The client WC requests the server WS. WS calls the cache external interface CEI. CEI retrieves whether the cache exists through the acquisition interface CRI. If it exists, it directly returns the cache data to the server WS. If it does not exist, it continues to execute the action that needs to update the cache, and immediately sends a pause signal to the cache main process CMP. The cache acquisition should be executed immediately, and then it is determined whether the cache data should be obtained locally or by other controllers. The local acquisition calls the data source to update CSI, and other controllers call the remote cache external interface CEI. After getting the cache data, CRI returns to the server WS and adds the cache data to the cache write queue. The cache access, data source time, and controller transmission time are recorded in the access record CRC, a write signal is sent to the cache write process, and finally a cancel pause signal is sent to the main process CMP.
[0143] In one embodiment, after controlling the Slave controller to synchronize the cache with the Master controller, the process further includes: receiving an end signal and exiting the operation.
[0144] In one embodiment, in response to the start of the cache service, after entering the working state, the method further includes: detecting whether other processes are running, and if so, ending the work.
[0145] In one embodiment, the controlling and running of the cold and hot management task module to perform cold and hot calculations on the data in the cache storage space includes:
[0146] The cold and hot management task module obtains the total number of accesses to all data and the number of accesses to each data from the inspection access records, and calculates the access frequency of each data;
[0147] Calculate the time consumption score of each data, the time consumption score of the controller transmission, and the change type score;
[0148] If the cache task of the Master controller is not the current controller, the data hot and cold values are calculated using the following formula:
[0149] Total score HCS1 = access frequency score NTS*50% + change type score CTS*30% + data consumption time score DES*20%;
[0150] If the Master controller cache task is other than the current controller, the data hot and cold values are calculated using the following formula:
[0151] Total score HCS2 = HCS1 + controller transmission time score CES * 10%.
[0152] Specifically, Fig. 9, hot and cold management will be executed when there is cache writing, or it will be executed regularly. The difference is that the scheduled execution is executed when the cache is not updated for a long time, and it will be checked during the main process queue cycle. When there is cache writing, the hot and cold calculation of the written cache will be performed separately; hot and cold management will eventually get the score of the cache task from 0 to 100. It includes the following steps:
[0153] Hc-step1: The hot and cold management interface starts to execute and check the access record RCR and common task QC.
[0154] Hc-Step2: Calculate the access frequency 0-100, count the number of accesses NT (number of times) of a certain cache or all caches, count the total number SUM, and calculate the cache access frequency score NTS (number of times score), NTS = NT / SUM, if the number of accesses is 0, the score is also 0.
[0155] Hc-Step3: Calculate the data elapse score DES (data elapse score), with a score of 0-100. The data source response time is usually expressed in milliseconds. Here, the average score estimation method is used, that is, the response time of a cache that reaches the average score level Avg is considered to be 60 points, the maximum time Max is 0 points, and the minimum time Min is 100 points. Determine the three coordinates (Min, 100) (Avg, 60) (Max, 0), and substitute the coordinates into the quadratic standard function f(x) = ax 2 +bx+c, get the clear quadratic function coefficient abc, and use the quadratic function f(x) to convert the time consumption into DES score.
[0156] Hc-Step4: Calculate the controller elapse score (CES). The controller elapse score is also estimated using the average score. The difference is that only the controller elapse score is calculated, and the cache task is not calculated separately. The calculation method is the same as the data source elapse score. The controller elapse score is applicable to all common tasks QC. The cold and hot data scores do not calculate CES by default. Only when obtaining a non-current controller, CES will be accumulated for judgment.
[0157] Hc-Step5: Calculate the change type score CTS (change type score). The change type will be directly scored:
[0158] (1) immutable = 10;
[0159] (2) Extremely difficult to change = 20;
[0160] (3) Normal change = 40;
[0161] (4) Changeability = 60;
[0162] (5) Extremely changeable = 100.
[0163] Hc-Step 6: Calculate the total score HCS (hot cold sum), HCS = NTS*50% + CTS*30% + DES*20%; if the current controller is the Master controller and the cache task is not the current controller, then HCS is added to CES, HCS = HCS + CES*10%.
[0164] Hc-Step7: Update the common task QC according to the score. If it is a single cache, take out this cache and find the score in QC between greater than or equal to and less than or equal to. If it is all tasks, reorder the entire QC queue.
[0165] In one embodiment, the method further includes: receiving a signal that a Slave controller is upgraded to a Master controller, recording the controller upgraded from a Slave controller to a Master controller as an upgraded Master controller, controlling other Slave controllers to synchronize cache data to the upgraded Master controller, and adding data to a cache write queue QW.
[0166] Specifically, Fig.10 As shown in the figure, the recovery from Slave to Master includes the following steps:
[0167] Recsm1: The slave controller is promoted to the master controller and will serve as the primary access cache service point, usually in failover or switchback scenarios;
[0168] Recsm2: The main process receives the signal to become the Master process;
[0169] Recsm3: directly obtains cache data from other slave controllers and adds it to the cache write queue QW;
[0170] Recsm4: Transfer completed, return to the main process CMP.
[0171] In one embodiment, a computer device is provided, which may be a server. The computer device includes a processor, a memory, and a network interface connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, the above-mentioned fast cache recovery method based on hot and cold features is implemented.
[0172] In one embodiment, a computer program product is also provided, including a computer program / instruction, which involves all or part of the process in the above-mentioned embodiment method.
[0173] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0174] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0175] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A fast cache recovery method based on hot and cold characteristics, characterized in that: Applied to the main process, the method includes: In response to the start of the cache service, entering the working state; the start of the cache service is restarting the cache service after abnormal downtime or shutdown; Control the operation of the hot and cold management module to perform hot and cold calculations on the data in the cache storage space, and add the data that needs to be updated to the common task queue QC according to the hot and cold values based on the hot and cold calculation results; Control the Master controller and the Slave controller to read the persistent cache data from the non-volatile medium, and add the task of reading the persistent cache data to the cache write queue QW; control the Slave controller to synchronize the cache with the Master controller; Control the execution of data in the cache write queue QW in sequence, so that when the data in the cache write queue QW is persistent cache data read from the non-volatile medium, the cache data is written to the volatile medium, and when the data in the cache write queue QW is data read from the common task queue QC, the data with a hot and cold value greater than or equal to a certain threshold is cached in the non-volatile medium and the volatile medium, and the data with a hot and cold value less than a certain threshold is cached in the volatile medium; after the execution of any data in the cache write queue QW is completed, all cache data are passed to the hot and cold management module to calculate the hot and cold values and then refresh the task order in the common task queue QC; the task in the cache write queue QW is the task of writing the cache data into the cache storage space; When all tasks in the cache write queue QW are executed, the tasks in the event task queue QE are executed, the data source interface is called to obtain data, and the data is added to the write queue QW, waiting to be written into the cache; the tasks in the event task queue QE are tasks that obtain data corresponding to the event after the event is detected; When all tasks in the event task queue QE are executed, the tasks in the common task queue QC are executed in sequence, the data source interface is called to obtain data, and the data is added to the write queue QW; the tasks of the common task queue QC are to calculate the hot and cold values of the cached data according to the set time or after the data in the cache write queue QW is written and re-sorted; the tasks in the common task queue QC are tasks for updating the cached data that needs to be updated beyond the set time.
2. The fast cache recovery method based on hot and cold characteristics according to claim 1, characterized in that: After controlling the slave controller to read the persistent cache data from the non-volatile medium, the method further includes: adding the cache data to the cache synchronization queue QS, so that the local data is read from the cache synchronization queue QS and transmitted to the remote end.
3. The fast cache recovery method based on hot and cold characteristics according to claim 2 is characterized in that: After controlling the slave controller to synchronize the cache with the master controller, the method further includes: receiving a pause signal, wherein the pause signal is when the client requests the server to obtain data, the server cannot find the corresponding data in the cache storage space and sends it to the main process; A cancel pause signal is received; the cancel pause signal is that the server obtains data locally or through other controllers, and adds the obtained data to the cache write queue QW so that it is written to the volatile medium.
4. The fast cache recovery method based on hot and cold characteristics according to claim 3 is characterized in that: After controlling the Slave controller to synchronize the cache with the Master controller, the method further includes: receiving an end signal and exiting the operation.
5. The fast cache recovery method based on hot and cold characteristics according to claim 1, characterized in that: In response to the start of the cache service, after entering the working state, the method further includes: detecting whether other processes are running, and if so, ending the work.
6. The fast cache recovery method based on hot and cold characteristics according to claim 2, characterized in that: The controlling and running of the cold and hot management task module to perform cold and hot calculations on the data in the cache storage space comprises: The cold and hot management task module obtains the total number of accesses to all data and the number of accesses to each data from the inspection access records, and calculates the access frequency of each data; Calculate the time consumption score of each data, the time consumption score of the controller transmission, and the change type score; If the cache task of the Master controller is not the current controller, the data hot and cold values are calculated using the following formula: Total score HCS1 = access frequency score NTS*50% + change type score CTS*30% + data consumption time score DES*20%; If the Master controller cache task is other than the current controller, the data hot and cold values are calculated using the following formula: Total score HCS2 = HCS1 + controller transmission time score CES * 10%.
7. The fast cache recovery method based on hot and cold characteristics according to claim 1, characterized in that: The method further includes: receiving a signal that a slave controller is upgraded to a master controller, recording the controller upgraded from a slave controller to a master controller as an upgraded master controller, controlling other slave controllers to synchronize cache data to the upgraded master controller, and adding data to a cache write queue QW.
8. The fast cache recovery method based on hot and cold characteristics according to claim 1, characterized in that: The volatile medium is a memory or a virtual memory, and the non-volatile medium is a file system, a database, or a hard disk.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of implementing the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Graph calculation method and device, electronic equipment and storage medium
CN120578668A
Fault recovery method and electronic equipment
CN122111742A
A fault recovery method and electronic device
CN122111742B