Cache processing method, device, computer equipment and storage medium
By listening to database instructions and determining the cache processing method, using the thread group surrounding the database service to update data in the cache server, the problems of cached data update delay and poor code readability in the existing technology are solved, and the timely and timely cached data is achieved. Efficient update.
Patent Information
- Application Number
- CN202110950495.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-18
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2041-08-18
AI Technical Summary
The prior art has problems with poor code readability and data update delays when cached data is updated, especially when database exceptions or log synchronization exceptions, cached data cannot be updated in time.
By listening to the data update instructions sent by the database, analyzing the instructions and determining the cache processing method, data update processing is carried out in the cache server in an asynchronous or synchronous manner, ensuring the timeliness and reliability of data updates, avoiding code intrusion into the business layer, and using surrounding The thread group of the database service performs data monitoring and processing.
It realizes timely update of cached data, avoids the problems of poor code readability and update delay, ensures the efficiency and reliability of data updates, and reduces the impact of database crashes on cache updates.
Smart Images

Figure CN113672649B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a cache processing method, apparatus, computer equipment and storage medium. Background Art
[0002] With the development of computer technology, in order to obtain the latest data faster, it is particularly important for the cache to be able to update the data in time. At present, one method is to write the corresponding cache code directly in the business code, that is, write the corresponding code wherever the cache is needed in the business layer. Although this method can update the cached data in time, the code readability is poor, which is not conducive to later code maintenance. Another method is the log synchronization method, that is, the data update operation is recorded in the log in the form of events. This method can solve the problem of poor code readability, but when an exception occurs in the log or the database, the cached data cannot be updated in time.
[0003] Therefore, the current methods either have the problem of poor code readability or the problem that the data in the cache cannot be updated in time. Therefore, the current methods have certain limitations. Summary of the invention
[0004] Based on this, it is necessary to provide a cache processing method, device, computer equipment and storage medium that can avoid limitations in response to the above technical problems.
[0005] A cache processing method, the method comprising:
[0006] Monitor data update instructions sent to the database;
[0007] Analyze the data update instruction and determine a cache processing method corresponding to the data update instruction;
[0008] If the cache processing mode is asynchronous cache processing, the data update instruction is executed by the first processing thread to perform data update processing on the cache server;
[0009] If the cache processing mode is synchronous cache processing, after the database executes the data update instruction to complete the data update processing, the data update instruction is executed in the cache server through the second processing thread to perform data update processing on the cache server.
[0010] In one embodiment, analyzing the data update instruction to determine the cache processing method corresponding to the data update instruction includes:
[0011] Analyze the data update instruction to determine the target business corresponding to the data updated by the data update instruction;
[0012] Determine a cache processing mode corresponding to the target service.
[0013] In one embodiment, if the cache processing mode is asynchronous cache processing, executing the data update instruction through the first processing thread to perform data update processing on the cache server includes:
[0014] If the cache processing mode is asynchronous cache processing, then
[0015] Performing data update processing on the cache server by executing the data update instruction through a first processing thread surrounding the database service;
[0016] The database surround service is a service program that provides a processing thread group; the threads in the processing thread group include an operation monitoring thread and a processing thread for cache processing; and the processing threads include the first processing thread.
[0017] In one embodiment, the processing thread includes the second processing thread;
[0018] If the cache processing mode is synchronous cache processing, after the database executes the data update instruction to complete the data update processing, the data update instruction is executed in the cache server through the second processing thread to perform data update processing on the cache server, including:
[0019] If the cache processing mode is synchronous cache processing, then
[0020] After the database executes the data update instruction to complete the data update process, the data update instruction is executed in the cache server by the second processing thread surrounding the database service to perform data update process on the cache server.
[0021] In one embodiment, executing the data update instruction in the cache server by the second processing thread surrounding the database service to perform data update processing on the cache server includes:
[0022] Reading the operation log information corresponding to the data update instruction from the log;
[0023] The operation corresponding to the operation log information is executed in the cache server by the second processing thread surrounding the database service, so as to perform data update processing on the cache server.
[0024] In one embodiment, the method further comprises:
[0025] Monitoring the operations occurring in the database and the cache server by using a plurality of the operation monitoring threads surrounding the database service;
[0026] If the operation monitoring thread monitors that the processing thread executing the operation has an exception, the operation monitoring thread will replace the abnormal processing thread to perform the corresponding operation.
[0027] In one of the embodiments, the second processing thread executes the data update instruction in the cache server according to the operation log information corresponding to the data update instruction recorded in the log;
[0028] The method further comprises:
[0029] After the operation corresponding to the operation log information is executed in the cache server, deleting the operation log information from the log;
[0030] If the operation monitoring thread monitors that the operation log information corresponding to the data update instruction has not been deleted, it is determined that the second processing thread is abnormal;
[0031] The operation monitoring thread replaces the abnormal processing thread to perform corresponding operations, including:
[0032] The second processing thread is replaced by the operation monitoring thread, and the operation corresponding to the operation log information is executed in the cache server to perform data update processing on the cache server.
[0033] A cache processing device, the device comprising:
[0034] A monitoring module, used to monitor data update instructions sent to the database;
[0035] A determination module, used for analyzing the data update instruction and determining a cache processing mode corresponding to the data update instruction;
[0036] An execution module, configured to execute the data update instruction through a first processing thread to perform data update processing on the cache server if the cache processing mode is asynchronous cache processing;
[0037] The execution module is also used to execute the data update instruction in the cache server through a second processing thread to perform data update processing on the cache server after the database executes the data update instruction to complete the data update processing if the cache processing mode is synchronous cache processing.
[0038] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0039] Monitor data update instructions sent to the database;
[0040] Analyze the data update instruction and determine a cache processing method corresponding to the data update instruction;
[0041] If the cache processing mode is asynchronous cache processing, the data update instruction is executed by the first processing thread to perform data update processing on the cache server;
[0042] If the cache processing mode is synchronous cache processing, after the database executes the data update instruction to complete the data update processing, the data update instruction is executed in the cache server through the second processing thread to perform data update processing on the cache server.
[0043] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0044] Monitor data update instructions sent to the database;
[0045] Analyze the data update instruction and determine a cache processing method corresponding to the data update instruction;
[0046] If the cache processing mode is asynchronous cache processing, the data update instruction is executed by the first processing thread to perform data update processing on the cache server;
[0047] If the cache processing mode is synchronous cache processing, after the database executes the data update instruction to complete the data update processing, the data update instruction is executed in the cache server through the second processing thread to perform data update processing on the cache server.
[0048] The above-mentioned cache processing method, device, computer equipment and storage medium directly monitor the data update instructions sent to the database to quickly learn the relevant operations that the database will perform on the data. The monitored data update instructions are analyzed to determine the cache processing method corresponding to the data update instruction. Different cache processing methods are used for different data update instructions. For data that is subject to database updates and has low timeliness requirements, synchronous cache processing can be used. For data that needs to be updated urgently, asynchronous cache processing is used. There is no need to wait for the database to complete the data update operation. The data is directly processed asynchronously, which can avoid situations such as database crashes that affect the cache data update efficiency. There is no need to invade the cache-related code into the business layer to avoid the hidden dangers of later maintenance caused by poor code readability, and it can also avoid the situation where data with high timeliness requirements have update delays, thereby effectively avoiding the limitations of the current method of timely updating data in the cache. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 A schematic diagram of a flow chart of a cache processing method in an embodiment;
[0050] Figure 2 A schematic diagram of a cache processing method in an embodiment;
[0051] Figure 3 is a timing diagram of a cache processing method in an embodiment;
[0052] Figure 4 is a flow chart of a cache processing method in another embodiment;
[0053] Figure 5 is a structural block diagram of a cache processing device in one embodiment;
[0054] Figure 6 is a structural block diagram of a cache processing device in one embodiment;
[0055] Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0056] 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.
[0057] In one embodiment, Figure 1As shown, a cache processing method is provided. This embodiment uses the method applied to a cache server as an example for illustration. It can be understood that the method can also be applied to a terminal, and can also be applied to a system including a terminal and a cache server, and is implemented through the interaction between the terminal and the cache server. In this embodiment, the method includes the following steps:
[0058] Step 102: monitor the data update instruction sent to the database.
[0059] The data update instruction is an instruction to update data, and is used to instruct the database to perform one or more operations such as modifying, writing, and deleting data.
[0060] Specifically, the cache server may obtain the data update instruction when monitoring a data update instruction sent to the database.
[0061] In one embodiment, the cache server can monitor all instructions sent to the database within a preset interval, determine whether the instructions sent to the database are data update instructions, and if they are data update instructions, the cache server can intercept the data update instructions, or record the data operation corresponding to the data update instructions in a log. It can be understood that the "interception" in each embodiment of the present application is not a complete truncation. After the cache server intercepts the data update instruction, the data update instruction can still be sent to the database, but the cache server can execute steps 104 to 108 in the embodiment of the present application after identifying the data update instruction.
[0062] In one embodiment, the cache server can process the data by calling the corresponding thread after intercepting the data update instruction. The cache server can also read the operation corresponding to the data update instruction recorded in the log before, after or synchronously after the database completes the data update corresponding to the data update instruction, and execute the operation corresponding to the data update instruction by calling the corresponding thread to process the data.
[0063] Step 104: Analyze the data update instruction and determine the cache processing method corresponding to the data update instruction.
[0064] Among them, the cache processing method is the data processing method for the cache server.
[0065] Specifically, the cache server may analyze the monitored data update instruction sent to the database to obtain an analysis result, and determine the cache processing mode corresponding to the data update instruction according to the analysis result.
[0066] In one embodiment, the cache server may analyze the business corresponding to the data update instruction to obtain analysis results related to the business update requirements, and determine the cache processing method corresponding to the data update instruction based on the analysis results related to the business update requirements.
[0067] In one embodiment, the cache server can analyze the data update requirements of the cache of the data corresponding to the data update instruction, obtain the analysis results corresponding to the data update requirements, and determine the cache processing method corresponding to the data update instruction according to the analysis results corresponding to the data update requirements. In an example, assuming that the COVID-19 test results of the health code need to be updated, there are two data update requirements, one requiring the latest COVID-19 test data to be updated within 24 hours, and the other requiring the latest COVID-19 test results to be updated within 2 hours. Therefore, the cache server can determine the cache processing method corresponding to the data update instruction according to the analysis results corresponding to the cache data update requirements. For example, if the data update requirements corresponding to the latest COVID-19 test data to be updated within 24 hours are not so high in terms of timeliness, the corresponding cache processing method can be synchronous cache processing, that is, after the data is updated in the database, the data update processing is synchronized in the cache server. If the data update requirements corresponding to the latest COVID-19 test results to be updated within 2 hours have relatively high timeliness requirements, then the corresponding cache processing method can be asynchronous cache processing, that is, the update processing is directly performed in the cache server, and the data is updated to the cache server in a timely manner, regardless of whether the data in the database has been updated.
[0068] Step 106: If the cache processing mode is asynchronous cache processing, the data update instruction is executed by the first processing thread to perform data update processing on the cache server.
[0069] Asynchronous cache processing refers to asynchronous processing of data processing in the cache server and data processing in the database. That is, during asynchronous cache processing, data processing in the cache server is independent of data processing in the database. For example, cache processing can be performed before the database updates data, after the database updates data, or simultaneously with the database updating data. The first processing thread is a thread that performs asynchronous cache processing.
[0070] Specifically, if the cache processing mode is asynchronous cache processing, the cache server can call the first processing thread from multiple threads to execute the data update instruction, and no longer monitor whether the database has completed the data update through the corresponding operation monitoring thread, and directly perform data update processing on the cache server.
[0071] In one embodiment, before updating data in the database, the cache server may call the first processing thread to execute a data update instruction to perform data update processing on the cache server.
[0072] In one embodiment, after the database updates the data, the cache server may call the first processing thread to execute the data update instruction to perform data update processing on the cache server.
[0073] In one embodiment, the cache server calls the first processing thread to execute the data update instruction, and performs data update processing on the cache server at the same time as the database updates the data.
[0074] Step 108, if the cache processing mode is synchronous cache processing, after the database executes the data update instruction to complete the data update processing, the data update instruction is executed in the cache server through the second processing thread to perform data update processing on the cache server.
[0075] Among them, synchronous cache processing refers to the processing method of synchronizing the data update processing of the database to the cache server. That is, the data update order in the cache server must be after the data update in the database, which is equivalent to updating the data in the cache server synchronously after the data in the database is updated, so that the data processing in the cache server is consistent with the data processing in the database.
[0076] Specifically, if the cache processing mode is synchronous cache processing, after the database executes the data update instruction to complete the data update processing, the cache server can execute the data update instruction in the cache server through the second processing thread to perform data update processing on the cache server.
[0077] In one embodiment, if the cache processing method is synchronous cache processing, the cache server can record the operation corresponding to the data update instruction in its own log. After the corresponding operation listening thread monitors that the database has completed the data update, the data update instruction is executed in the cache server through the second processing thread to perform data update processing on the cache server.
[0078] In one embodiment, if the cache processing method is synchronous cache processing, the cache server can also read the database log after listening to the database through the corresponding operation listening thread to complete the data update, obtain the operations corresponding to all data update instructions related to the database data update recorded in the log, and execute the corresponding operations in the cache server through the second processing thread to perform data update processing on the cache server.
[0079] In the above-mentioned cache processing method, the data update instructions sent to the database are directly monitored to quickly learn the relevant operations that the database will perform on the data. The monitored data update instructions are analyzed to determine the cache processing method corresponding to the data update instructions. Different cache processing methods are used for different data update instructions. For data that is subject to database updates and has low timeliness requirements, synchronous cache processing can be used. For data that needs to be updated urgently, asynchronous cache processing is used. There is no need to wait for the database to complete the data update operation. The data can be processed asynchronously directly, which can avoid situations such as database crashes that affect the cache data update efficiency. There is no need to invade the cache-related code into the business layer to avoid the hidden dangers of later maintenance caused by poor code readability, and it can also avoid the update delay of urgent data with high timeliness requirements, thereby effectively avoiding the limitations of the current method of timely updating data in the cache.
[0080] In one embodiment, analyzing the data update instruction and determining the cache processing mode corresponding to the data update instruction includes: analyzing the data update instruction and determining the target business corresponding to the data updated by the data update instruction; and determining the cache processing mode corresponding to the target business.
[0081] The target business is the business corresponding to the updated target data. It is understandable that different data can correspond to different businesses, for example, the COVID-19 test data corresponds to the COVID-19 test business, and the vaccination data corresponds to the vaccination business.
[0082] Specifically, the cache server may analyze the monitored data update instructions sent to the database, determine the target business corresponding to the data updated by the data update instructions based on the data update instruction analysis results, and further determine the cache processing method corresponding to the target business.
[0083] In one embodiment, the cache server may analyze the monitored data update instruction sent to the database, and determine the target business corresponding to the updated data by analyzing the business cache server corresponding to the data to be updated by the data update instruction.
[0084] In one embodiment, the cache server may analyze the monitored data update instruction sent to the database, and determine the target business corresponding to the updated data by analyzing the keywords carried in the data update instruction.
[0085] In this embodiment, different businesses are first analyzed, and then different cache processing methods are flexibly determined according to the different businesses. Compared with a single log synchronization method, the cache data update delay problem caused by log synchronization can be avoided.
[0086] In one embodiment, if the cache processing method is asynchronous cache processing, the data update instruction is executed by the first processing thread to perform data update processing on the cache server, including: if the cache processing method is asynchronous cache processing, the data update instruction is executed by the first processing thread surrounding the database service to perform data update processing on the cache server; wherein the processing thread includes the first processing thread.
[0087] The database-surrounding service is a service program that provides a processing thread group, and the threads in the processing thread group include an operation monitoring thread and a processing thread for cache processing. It can be understood that the operation monitoring thread in the database-surrounding service can monitor the operations related to the data update of the cache server and the database. If a processing thread is needed during the monitoring process, a corresponding processing thread can be provided to update the data in the cache server.
[0088] Specifically, after determining that the cache processing mode corresponding to the target service is asynchronous cache processing, the cache server may execute a data update instruction through a first processing thread surrounding the database service to perform data update processing on the cache server.
[0089] In one embodiment, the cache server may search for a processing thread in the surrounding database service, and after finding a first processing thread corresponding to the asynchronous cache processing, execute a data update instruction through the first processing thread to perform data update processing on the cache server.
[0090] In one embodiment, after determining that the cache processing method corresponding to the target business is asynchronous cache processing, the cache server generates a processing thread call instruction corresponding to the asynchronous cache processing to the surrounding database service, and executes the data update instruction through the first processing thread returned by the surrounding database service to perform data update processing on the cache server.
[0091] In one embodiment, after the cache server determines that the cache processing mode corresponding to the target business is asynchronous cache processing, the operation listening thread in the surrounding database service can execute the data update instruction through the corresponding first processing thread after listening to the need for asynchronous cache processing of the data, and perform data update processing on the cache server.
[0092] In one embodiment, Figure 2As shown, a schematic diagram of a cache processing method is provided. The database has a corresponding log synchronizer that specifically records data operations that occur in the database. The database's slave server, that is, the sub-server, can read the operations of the log synchronizer and execute them so that the same operations occur on its own data and the database. The cache server includes a surrounding database service and a cache space. The surrounding database service includes multiple processing threads, including a first processing thread, a second processing thread, an operation listening thread, and a cache thread. Among them, the cache thread is used to receive the processing results of the first processing thread, the second processing thread, and the operation listening thread, and update them into the cache space. Figure 2 Only one cache space is used for illustration, and it can be understood that there may be one or more cache spaces in the cache server.
[0093] The cache server can monitor the data update instructions sent to the database through the operation listening thread of the surrounding database service. The cache server analyzes the data update instructions through the surrounding database service and determines asynchronous cache processing or synchronous cache processing. If it is asynchronous cache processing, the cache server executes the data update instruction through the first processing thread provided by the surrounding database service, and stores the processing result of the first processing thread to the cache space through the cache thread. If it is synchronous cache processing, after the cache server monitors the database through the operation listening thread of the surrounding database service to complete the data update, it reads the operation log information corresponding to the data update instruction from the log synchronizer of the database, executes the operation corresponding to the operation log information in the cache server through the second processing thread of the surrounding database service, and stores the processing result of the second processing thread to the cache space through the cache thread. It can be understood that through the operation listening thread of the surrounding database service, the operations related to the data update processing can be monitored, and when there are exceptions in the operation process, the exceptions can be handled.
[0094] In this embodiment, the surrounding database service can monitor the processing process through the monitoring thread, so as to provide a first processing thread for asynchronous cache processing when there is a demand for a processing thread. The surrounding database service can also provide a replacement processing thread for the monitored exception to ensure the data update efficiency. For cache servers with high update speed requirements, the surrounding database service ensures real-time update of cache server data and avoids delays in data updates.
[0095] In one embodiment, the processing thread includes a second processing thread; if the cache processing method is synchronous cache processing, then after the database executes the data update instruction to complete the data update processing, the data update instruction is executed in the cache server through the second processing thread to perform data update processing on the cache server, including: if the cache processing method is synchronous cache processing, then after the database executes the data update instruction to complete the data update processing, the data update instruction is executed in the cache server through the second processing thread surrounding the database service to perform data update processing on the cache server.
[0096] Specifically, after the cache server determines that the cache processing mode corresponding to the target service is synchronous cache processing, it waits for the database to execute the data update instruction to complete the data update processing, and then executes the data update instruction through the second processing thread surrounding the database service to perform data update processing on the cache server.
[0097] In one embodiment, after the cache server determines that the cache processing method corresponding to the target business is synchronous cache processing, it monitors the data update processing of the database through the operation monitoring thread of the surrounding database service. After monitoring that the database has completed the data update processing, the data update instruction is executed in the cache server through the second processing thread of the surrounding database service to perform data update processing on the cache server.
[0098] In one embodiment, after the cache server determines that the cache processing method corresponding to the target business is synchronous cache processing, it monitors the data update processing of the database through the operation monitoring thread of the surrounding database service. If it is monitored that the database is abnormal and the data update processing is not completed, the data update instruction can be executed in the cache server through the second processing thread of the surrounding database service to perform data update processing on the cache server.
[0099] In one embodiment, after the cache server determines that the cache processing mode corresponding to the target service is synchronous cache processing, it monitors the data update processing of the database through the operation monitoring thread surrounding the database service. After monitoring that the database completes the data update processing, the data update instruction can be executed in the cache server through the second processing thread surrounding the database service. If it is monitored that there is an abnormality in the execution of the data update instruction by the second processing thread, the data update instruction is replaced by the second processing thread to perform data update processing on the cache server.
[0100] In this embodiment, for the data of the cache server that needs to adopt synchronous cache processing, the data update processing of the database can be monitored by the operation monitoring thread surrounding the database service. Once the database completes the data update processing, the second processing thread is directly called to execute the data update instruction to perform data update processing on the cache server. Moreover, when an abnormality is monitored, a decision can be made to ensure that the cache server data is updated and the delay of data update is avoided.
[0101] In one embodiment, a data update instruction is executed in a cache server by a second processing thread surrounding a database service to perform data update processing on the cache server, including: reading operation log information corresponding to the data update instruction from a log; and executing an operation corresponding to the operation log information in the cache server by a second processing thread surrounding the database service to perform data update processing on the cache server.
[0102] The log is used to record the operation log information corresponding to the data update instruction for the synchronous cache mode. It is understandable that when the synchronous cache mode is adopted, the operation log information corresponding to the data update instruction can be recorded in the log, and the operation log information can be read again when the step of executing the data update instruction is reached.
[0103] Specifically, for the synchronous caching method, the cache server can monitor whether the time to execute the data update instruction has arrived through the operation monitoring thread. If so, it reads the operation log information corresponding to the data update instruction from the log, and executes the operation corresponding to the operation log information in the cache server through the second processing thread surrounding the database service to perform data update processing on the cache server.
[0104] In one embodiment, the cache server may record the operation log information corresponding to the data update instruction in a log of the cache server, or in a non-database log.
[0105] In one embodiment, if the operation log information corresponding to the data update instruction is recorded in the log of the cache server, the cache server reads the operation log information corresponding to the data update instruction from its own log after monitoring that the database has completed the data update process. After the cache server has updated the data, it can delete the corresponding operation log information from its own log, or keep it for a period of time, or keep it permanently.
[0106] In one embodiment, Figure 3 As shown, a timing diagram of a cache processing method is provided, which specifically includes the following steps:
[0107] (1) The application service can send data update instructions to the database.
[0108] (2) The cache server can monitor the data update processing of the database through the operation monitoring thread surrounding the database service. After monitoring the data update instruction of the database, the cache server analyzes the data update instruction and determines the cache processing method corresponding to the data update instruction. If the cache processing method is asynchronous cache processing, step (3-1) is executed; if it is synchronous cache processing, steps (3-2-1) to (3-2-3) are executed.
[0109] (3-1) The cache server executes the data update instruction through the first processing thread.
[0110] (3-2-1) After the database executes the data update instruction and completes the data update process, the operation log information corresponding to the data update instruction can be recorded in the log synchronizer.
[0111] (3-2-2) The cache server obtains the operation log information returned by the database.
[0112] (3-2-3) The cache server executes the operation corresponding to the operation log information in the cache server through the second processing thread surrounding the database service.
[0113] (4) The application service can read the written data from the cache server.
[0114] It can be understood that the cache server can monitor the various operations in steps (1) and (3) through the operation monitoring program surrounding the database service. If there is an exception in the processing thread, the first or second processing thread where the exception occurs can be replaced to handle the data update process, wherein (3) includes (3-1) and (3-2-1) to (3-2-3).
[0115] In this embodiment, for the data of the cache server that needs to adopt synchronous cache processing, by reading the operation log information corresponding to the data update instruction recorded in the log, and executing the operation corresponding to the operation log information through the second processing thread, when the database crashes or the database log fails to record the data processing operation occurring in the database, the cache server can still successfully obtain the operation log information and execute the operation corresponding to the operation log information to perform data update processing on the cache server, thereby avoiding the data update delay caused by synchronous cache processing.
[0116] In one embodiment, the method further includes: monitoring operations occurring in the database and cache server through multiple operation monitoring threads surrounding the database service; if the operation monitoring thread detects that there is an exception in the processing thread executing the operation, the operation monitoring thread replaces the abnormal processing thread to perform the corresponding operation.
[0117] Specifically, the cache server can monitor the operations occurring in the database and the cache server through multiple operation monitoring threads surrounding the database service. If one of the operation monitoring threads monitors that the processing thread executing the operation is abnormal, the cache server can call the operation monitoring thread to replace the abnormal processing thread to perform the corresponding operation through the surrounding database service.
[0118] In one embodiment, the processing thread in which the exception occurs includes a first processing thread and a second processing thread. For example, if the operation monitoring thread monitors that the first processing thread executing the operation that occurs has an exception, that is, there is a problem with the asynchronous cache processing, the cache server can replace the first processing thread with the operation monitoring thread to perform asynchronous cache processing to update the data. If the operation monitoring thread monitors that the second processing thread executing the operation that occurs has an exception, that is, there is a problem with the synchronous cache processing, the cache server can replace the second processing thread with the operation monitoring thread to perform asynchronous cache processing to update the data.
[0119] In this embodiment, by surrounding multiple operation monitoring threads of the database service, during the data update process of the cache server, the operations involved in the data update of the cache server are always monitored. Once an exception is found, the monitoring thread can replace the processing thread where the exception occurs to perform corresponding operations to ensure that the exception can be processed in time, thereby ensuring that the cache server data is updated and processing, avoiding delays in data updating.
[0120] In one embodiment, the second processing thread executes the data update instruction in the cache server according to the operation log information corresponding to the data update instruction recorded in the log; the method also includes: after executing the operation corresponding to the operation log information in the cache server, deleting the operation log information from the log; if the operation listening thread detects that the operation log information corresponding to the data update instruction has not been deleted, it is determined that there is an abnormality in the second processing thread; the operation listening thread replaces the abnormal processing thread to perform corresponding operations, including: the operation listening thread replaces the second processing thread, and executes the operation corresponding to the operation log information in the cache server to perform data update processing on the cache server.
[0121] The second processing thread is used to execute the data update instruction in the cache server according to the operation log information corresponding to the data update instruction recorded in the log.
[0122] Specifically, after the operation corresponding to the operation log information is executed in the cache server, if the log is the log of the cache server itself, the cache server can delete the operation log information from the log. The operation monitoring thread can monitor that the operation log information corresponding to the data update instruction has not been deleted, and determine that there is an abnormality in the second processing thread. The cache server can replace the second processing thread with the operation monitoring thread to execute the operation corresponding to the operation log information in the cache server to perform data update processing on the cache server.
[0123] In one embodiment, if the log is not a log of a database or a cache server itself, after the operation corresponding to the operation log information is executed in the cache server, the corresponding log deletion instruction can be sent to the object where the log is located through the operation monitoring thread to delete the operation log information corresponding to the data update instruction.
[0124] In one embodiment, the cache server can operate the monitoring thread to check whether the operation log information corresponding to the data update instruction has not been deleted when a preset time period is reached. If the operation log information has not been deleted when the preset time period is reached, it is determined that the exception of the second processing thread is a timeout and the data update processing is not completed.
[0125] In one embodiment, the cache server can use an operation monitoring thread to check whether the operation log information corresponding to the data update instruction has not been deleted when a preset time period is reached. If the operation log information has not been deleted when the preset time period is reached, it can be checked whether the cache server has completed the data update processing. If so, the operation monitoring thread completes the operation log information deletion operation corresponding to the data update instruction.
[0126] like Figure 4 As shown, it is a flow chart of the cache processing method in another embodiment. The cache server listens to the data update instruction through the surrounding database service, or obtains the operation log information corresponding to the data update instruction from the log synchronizer. After listening to the data update instruction, the data update instruction can be analyzed, and the analysis shows that the data update instruction is a cache deletion instruction. The cache server determines that the cache processing method is asynchronous cache processing through the surrounding database service, and determines through the processing thread group that the cache is deleted through the first processing thread. After listening to the data update instruction, the data update instruction can be analyzed, and the analysis result is a write data instruction (i.e., set cache). The cache server determines that the cache processing method is synchronous cache processing through the surrounding database service. After writing data to the database, it can be read from the database log, and the operation log information corresponding to the write data can be read, and the write data is executed in the cache server through the second processing thread of the surrounding database service.
[0127] In this embodiment, for the data of the cache server that needs to adopt synchronous cache processing, the operation monitoring thread reaches a preset time length, checks whether the operation log information corresponding to the data update instruction has not been deleted, and can further check whether the cache server has completed the data update processing, and replace any second processing thread to execute the operation corresponding to the operation log information to perform data update processing on the cache server. It can also handle exceptions related to the log of the data update processing other than the second processing thread, so that the operations involved in the entire synchronous cache processing can be successfully completed, thereby ensuring that the cache server data is updated and avoiding delays in data updates.
[0128] It should be understood that, although the various steps in the flowcharts of the above-mentioned various embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts of the above-mentioned various embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0129] In one embodiment, Figure 5 As shown, a cache processing device 500 is provided, including: a monitoring module 502, a determining module 504, and an executing module 506, wherein:
[0130] A monitoring module 502 is used to monitor data update instructions sent to the database;
[0131] A determination module 504, configured to analyze the data update instruction and determine a cache processing method corresponding to the data update instruction;
[0132] An execution module 506 is configured to execute the data update instruction through a first processing thread to perform data update processing on the cache server if the cache processing mode is asynchronous cache processing;
[0133] The execution module 506 is also used to execute the data update instruction in the cache server through a second processing thread to perform data update processing on the cache server after the database executes the data update instruction to complete the data update processing if the cache processing mode is synchronous cache processing.
[0134] In one embodiment, the determination module 504 is further used to analyze the data update instruction, determine the target business corresponding to the data updated by the data update instruction, and determine the cache processing method corresponding to the target business.
[0135] In one embodiment, the execution module 506 is also used to execute the data update instruction through the first processing thread of the surround database service to perform data update processing on the cache server if the cache processing method is asynchronous cache processing; wherein the surround database service is a service program that provides a processing thread group; the threads in the processing thread group include an operation listening thread and a processing thread for cache processing; the processing threads include the first processing thread.
[0136] In one embodiment, the processing thread includes the second processing thread; the execution module 506 is also used to, if the cache processing method is synchronous cache processing, execute the data update instruction in the cache server through the second processing thread surrounding the database service to perform data update processing on the cache server after the data update instruction is executed in the database to complete the data update processing.
[0137] In one embodiment, the execution module 506 is also used to read operation log information corresponding to the data update instruction from the log; and execute the operation corresponding to the operation log information in the cache server through the second processing thread surrounding the database service to perform data update processing on the cache server.
[0138] In one embodiment, Figure 6 As shown, the device also includes:
[0139] The exception handling module 508 is used to monitor the operations occurring in the database and the cache server through the multiple operation monitoring threads surrounding the database service; if the operation monitoring thread detects that the processing thread executing the operation is abnormal, the operation monitoring thread will replace the abnormal processing thread to perform the corresponding operation.
[0140] In one embodiment, the second processing thread executes the data update instruction in the cache server according to the operation log information corresponding to the data update instruction recorded in the log; the exception handling module 508 is used to delete the operation log information from the log after executing the operation corresponding to the operation log information in the cache server; if the operation monitoring thread monitors that the operation log information corresponding to the data update instruction has not been deleted, it is determined that there is an exception in the second processing thread; the operation monitoring thread replaces the second processing thread, and executes the operation corresponding to the operation log information in the cache server to perform data update processing on the cache server.
[0141] For the specific definition of the cache processing device, please refer to the definition of the cache processing method above, which will not be repeated here. Each module in the above cache processing device can be implemented in whole or in part by software, hardware and a combination thereof. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0142] In one embodiment, a computer device is provided. The computer device may be a cache server, and its internal structure diagram may be as follows: Figure 7 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, 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 database of the computer device is used to store cache processing data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a cache processing method is implemented.
[0143] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0144] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0145] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0146] 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 the present 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).
[0147] 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.
[0148] 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 cache processing method, It is characterized in that The method comprises: Monitor data update instructions sent to the database; Analyze the data update instruction to determine the target business corresponding to the data updated by the data update instruction; determine the cache processing method corresponding to the target business; If the cache processing mode is asynchronous cache processing, the data update instruction is executed by the first processing thread of the surrounding database service to perform data update processing on the cache server; wherein the surrounding database service is a service program that provides a processing thread group; the threads in the processing thread group include an operation listening thread and a processing thread for performing cache processing; the processing threads include the first processing thread; If the cache processing mode is synchronous cache processing, after the database executes the data update instruction to complete the data update processing, the operation log information corresponding to the data update instruction is read from the log; the operation corresponding to the operation log information is executed in the cache server through the second processing thread of the surrounding database service to perform data update processing on the cache server; The operations occurring in the database and the cache server are monitored through the multiple operation monitoring threads surrounding the database service; if the operation monitoring thread detects that the processing thread executing the occurring operation is abnormal, the operation monitoring thread replaces the abnormal processing thread to perform the corresponding operation.
2. The method according to claim 1, It is characterized in that The analyzing the data update instruction to determine the target business corresponding to the data updated by the data update instruction includes: Analyze the data update instruction to obtain the business cache server corresponding to the data updated by the data update instruction; Based on the service cache server, a target service corresponding to the data updated by the data update instruction is determined.
3. The method according to claim 1, It is characterized in that The monitoring of the data update instruction sent to the database includes: Listen to all commands sent to the database within a preset interval; Determining whether the instruction sent to the database is a data update instruction; If it is a data update instruction, intercept the data update instruction.
4. The method according to claim 1, It is characterized in that The determining of a cache processing mode corresponding to the target service includes: Analyze the business corresponding to the data update instruction to obtain analysis results related to the business update requirements; According to the analysis result related to the service update requirement, a cache processing mode corresponding to the data update instruction is determined.
5. The method according to claim 1, It is characterized in that During the asynchronous cache processing, the data processing in the cache server is independent of the data processing in the database.
6. The method according to claim 1, It is characterized in that During the synchronous cache processing, the data update order in the cache server must be after the data update order in the database.
7. The method according to claim 1, It is characterized in that The second processing thread executes the data update instruction in the cache server according to the operation log information corresponding to the data update instruction recorded in the log; The method further comprises: After the operation corresponding to the operation log information is executed in the cache server, deleting the operation log information from the log; If the operation monitoring thread monitors that the operation log information corresponding to the data update instruction has not been deleted, it is determined that the second processing thread is abnormal; The operation monitoring thread replaces the abnormal processing thread to perform corresponding operations, including: The second processing thread is replaced by the operation monitoring thread, and the operation corresponding to the operation log information is executed in the cache server to perform data update processing on the cache server.
8. A cache processing device, It is characterized in that The device comprises: A monitoring module, used to monitor data update instructions sent to the database; A determination module, configured to analyze the data update instruction, determine a target service corresponding to the data updated by the data update instruction, and determine a cache processing method corresponding to the target service; an execution module, configured to execute the data update instruction through a first processing thread of a surrounding database service to perform data update processing on the cache server if the cache processing mode is asynchronous cache processing; wherein the surrounding database service is a service program that provides a processing thread group; the threads in the processing thread group include an operation listening thread and a processing thread for performing cache processing; and the processing threads include the first processing thread; The execution module is further configured to, if the cache processing mode is synchronous cache processing, read operation log information corresponding to the data update instruction from a log after the database executes the data update instruction to complete the data update processing; and execute the operation corresponding to the operation log information in the cache server through the second processing thread of the surrounding database service to perform data update processing on the cache server; The exception handling module is used to monitor the operations occurring in the database and the cache server through the multiple operation monitoring threads surrounding the database service; if the operation monitoring thread detects that the processing thread executing the operation is abnormal, the operation monitoring thread will replace the abnormal processing thread to perform the corresponding operation.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that 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-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Cached data synchronization method, equipment, service centers and multi-center service system
CN107547632A
Database and cache consistency synchronization method and device, computer equipment and storage medium
CN111078717A
Database operation method and device
CN112612780A
Data processing method and device, electronic equipment and storage medium
CN113031864A
System and method for asynchronous update of indexes in a distributed database
US20090210429A1
