Data updating method and device, equipment, storage medium and program product
By obtaining database update result information and updating cached data, the problem of inconsistency in data updates is solved, the timely consistency between cache and database data is achieved, and the server performance loss is reduced.
Patent Information
- Application Number
- CN202411646148.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-03-07
AI Technical Summary
When processing data query requests while updating the database, it may cause the data query request to obtain old data that has not been updated yet, resulting in inconsistency between the cache and the business data in the database.
By obtaining the update result information of the database, it detects whether there is service process data related to the update result information in the cache, and when it is determined that the data has not been updated, the service process data in the cache is updated based on the update result information.
Ensure that after the database update is completed, the data in the cache can be updated in a timely manner, thereby maintaining the consistency of the cache and database data, avoiding unnecessary cache updates, and reducing server performance losses.
Smart Images

Figure CN119576954A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of data processing technology, and in particular, relates to a data updating method, device, equipment, storage medium and program product. Background Art
[0002] The service process running on the server is used to receive business-related requests sent by electronic devices and perform corresponding business processing based on the received requests. During the business processing, the service process will store the business data generated during the business processing in the database of the server. During the business processing, the service process will store some data that may be frequently used in the future into the cache so that it can be quickly called from the cache when used again.
[0003] In the related art, when a service process needs to obtain business data, it will first search and try to obtain it from the cache. If the business data required by the service process does not exist in the cache, the service process will directly turn to the database to search and obtain it, and then store the obtained business data in the cache, so as to achieve subsequent rapid acquisition of the business data. However, while the database is being updated, if a data query request is being processed, the data query request may obtain old data that has not been updated yet, which will lead to inconsistencies between the data in the cache and the business data in the database. Summary of the invention
[0004] The embodiments of the present application provide a data update method, apparatus, device, storage medium and program product, which can effectively solve the problem of inconsistent business data in the cache and database caused by data query requests obtaining old data when updating the database and processing data query requests at the same time.
[0005] In a first aspect, an embodiment of the present application provides a data updating method, the data updating method comprising:
[0006] Get the update result information of the database;
[0007] Check whether there is service process data related to the update result information in the cache;
[0008] In the case where there is service process data in the cache, determining whether the service process data in the cache is updated according to the update result information;
[0009] When it is determined that the service process data has not been updated, the service process data in the cache is updated according to the update result information.
[0010] In some possible implementations of the embodiments of the present application, obtaining update result information of the database includes:
[0011] When it is determined that the database update is successful, the update information of the database is written into the log of the database through the row mode to obtain the updated log of the database;
[0012] Get the update result information of the database from the updated log.
[0013] In some possible implementations of the embodiments of the present application, before executing the step of detecting whether there is service process data related to the update result information in the cache, the data update method further includes:
[0014] When it is determined that the database update is successful, delete the data in the cache;
[0015] Check whether there is service process data related to the update result information in the cache, including:
[0016] Taking the time when the database is successfully updated as the starting time, after a preset period of time, check whether there is service process data related to the update result information in the cache;
[0017] The preset duration is greater than a maximum of a preset cache deletion instruction processing duration and a preset data query request processing duration.
[0018] In some possible implementations of the embodiments of the present application, after a preset time period has elapsed and the time when the database is successfully updated is taken as the starting time, before detecting whether there is service process data related to the update result information in the cache, the data update method further includes:
[0019] Monitor database logs in real time;
[0020] The time when the update information of the database is written into the log of the database is determined as the time when the database update is successful.
[0021] In some possible implementations of the embodiments of the present application, when there is service process data in the cache, determining whether the service process data in the cache is updated according to the update result information includes:
[0022] When there is service process data in the cache, the data related to the service process data in the cache is compared with the data related to the service process data in the update result information to obtain a comparison result;
[0023] According to the comparison result, it is determined whether the data related to the service process data is updated.
[0024] In some possible implementations of the embodiments of the present application, the update result information includes an update row index and an update data value corresponding to the update row index, the service process data includes a first target row index in the update row index, the data related to the service process data in the cache includes a cache data value corresponding to the first target row index in the cache, and the comparison result includes a first comparison result or a second comparison result; when there is service process data in the cache, the data related to the service process data in the cache is compared with the data related to the service process data in the update result information to obtain a comparison result, including:
[0025] When there is a first target row index in the update row index in the cache, obtaining a first update data value corresponding to the first target row index according to the update result information;
[0026] Comparing the first updated data value with the cached data value, and obtaining a first comparison result when the first updated data value and the cached data value are the same;
[0027] The first updated data value is compared with the cached data value, and when the first updated data value is different from the cached data value, a second comparison result is obtained.
[0028] In some possible implementations of the embodiments of the present application, determining whether data related to the service process data is updated according to the comparison result includes:
[0029] According to the first comparison result, determining that the data related to the service process data has been updated;
[0030] According to the second comparison result, it is determined that the data related to the service process data has not been updated.
[0031] In some possible implementations of the embodiments of the present application, the update result information includes an update row index and an update data value corresponding to the update row index; after executing the step of updating the service process data in the cache according to the update result information when it is determined that the service process data has not been updated, the data update method further includes:
[0032] Get the cached deletion records, which include the deletion row index related to deleting data based on the update result information;
[0033] Check whether there is a data value corresponding to the deleted row index in the cache;
[0034] When there is no data value corresponding to the second target row index in the deleted row index in the cache, obtaining a second updated data value corresponding to the second target row index according to the update result information;
[0035] The second update data value is written into a corresponding position in the cache according to the second target row index.
[0036] In some possible implementations of the embodiments of the present application, the deletion record also includes a deletion row index that is independent of the update result information and an initial data value corresponding to the deletion row index; the data update method also includes writing the initial data value to the corresponding position in the cache based on the deletion row index.
[0037] In a second aspect, an embodiment of the present application provides a data updating device, the data updating device comprising:
[0038] A first acquisition module is used to acquire update result information of the database;
[0039] A first detection module is used to detect whether there is service process data related to the update result information in the cache;
[0040] A first determination module, configured to determine whether the service process data in the cache is updated according to the update result information when there is service process data in the cache;
[0041] The update module is used to update the service process data in the cache according to the update result information when it is determined that the service process data has not been updated.
[0042] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the data updating method as described in any one of the first aspects is implemented.
[0043] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having computer program instructions stored thereon, and when the computer program instructions are executed by a processor, a data updating method as described in any one of the first aspects is implemented.
[0044] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program or instructions, and when the computer program or instructions are executed by a processor, they implement the data updating method as described in any one of the first aspects.
[0045] The data updating method, device, equipment, storage medium and program product of the embodiment of the present application can detect whether the service process data in the cache has been updated through the update result information when there is service process data related to the update result information in the cache, and when it is determined that the service process data in the cache has not been updated, the service process data in the cache is updated according to the update result information. In this way, it is ensured that after the database update is completed, if there is old service process data in the cache, it can be updated in time so that the data in the cache and the database remain consistent. In addition, the update mechanism that performs the update operation only when it is determined that the service process data in the cache has not been updated can effectively avoid unnecessary updates to the cache, and while ensuring that the data in the cache is consistent with the data in the database, it minimizes the performance loss caused to the server due to frequent cache updates. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0047] Figure 1 A schematic diagram showing a flow chart of a data updating method provided by some embodiments of the present application;
[0048] Figure 2 A flowchart showing a specific implementation of step 110 provided in some embodiments of the present application is shown;
[0049] Figure 3 A schematic diagram showing a flow chart of determining the time of successful database update in a data update method provided in some embodiments of the present application;
[0050] Figure 4 A flowchart showing a specific implementation of step 130 provided in some embodiments of the present application is shown;
[0051] Figure 5 A flowchart showing a specific implementation of step 1301 provided in some embodiments of the present application is shown;
[0052] Figure 6 A flowchart showing a specific implementation of step 1302 provided in some embodiments of the present application is shown;
[0053] Figure 7 A schematic diagram of a process of writing data into a cache in a data updating method provided in some embodiments of the present application is shown;
[0054] Figure 8A schematic diagram showing the structure of a data updating device provided in some embodiments of the present application is shown;
[0055] Fig. 9 A schematic diagram of the structure of an electronic device provided in some embodiments of the present application is shown. DETAILED DESCRIPTION
[0056] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0057] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0058] It should be noted that the acquisition, storage, use and processing of data in the embodiments of the present application are in compliance with the relevant provisions of national laws and regulations.
[0059] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0060] Before describing the technical solutions provided by the embodiments of the present application, in order to facilitate the understanding of the embodiments of the present application, the present application first specifically describes the related technologies involved:
[0061] When updating a database, you usually need to update two data stores. There are generally two ways to do this: the first way is to update the database first, then update the cache; the second way is to update the cache first, then update the database.
[0062] When the first method is used to update the database, if a data query request and a data update request occur at the same time. The data query request attempts to obtain data from the cache. If it finds that there is no data to be queried in the cache, it will turn to read the database and obtain the old data from it. However, before the data query request puts the old data into the cache, the data update request arrives. The data update request first updates the data in the database to make it new data, and then invalidates the cache. At this time, the data query request does not know that the data has been updated and the cache has expired, and it will continue to put the old data previously read from the database into the cache. This directly leads to inconsistency between the data in the cache and the database. If the subsequent data query request first obtains data from the cache, it will obtain wrong old data instead of the latest database data.
[0063] When the second method is used to update the database, there is also a concurrent data query request and a data update request. The data update request first invalidates the cache and then prepares to update the database. But before the data update request is written to the database, the data query request arrives. Because the cache has expired, the data query request can only read data from the database, and the data in the database is still old data at this time. The data query request writes this old data back to the cache. Then, the data update request completes the update of the database and writes the new data. At this time, the data in the cache is old data, and the data in the database is new data, and the cache and database data are inconsistent. If subsequent data query requests obtain data from the cache, they will get wrong old data instead of the latest database data.
[0064] Therefore, if a data query request is being processed while the database is being updated, the data query request may obtain old data that has not been updated yet, which may lead to inconsistencies between the data in the cache and the business data in the database.
[0065] In order to solve the above problems in the related art, the present application provides a data updating method, device, equipment, storage medium and program product. Figure 1 To Attachment Figure 6 , the data updating method provided in the embodiment of the present application is described in detail through specific embodiments and their application scenarios.
[0066] Figure 1 FIG. 1 is a flow chart showing a data updating method provided by some embodiments of the present application. Figure 1 As shown, the data updating method is applied to a server, and the data updating method may include steps 110 to 140.
[0067] Step 110, obtaining update result information of the database.
[0068] Step 120: Check whether there is service process data related to the update result information in the cache.
[0069] Step 130: If there is service process data in the cache, determine whether the service process data in the cache is updated according to the update result information.
[0070] Step 140: When it is determined that the service process data has not been updated, the service process data in the cache is updated according to the update result information.
[0071] Therefore, if there is service process data related to the update result information in the cache, the update result information can be used to detect whether the service process data in the cache has been updated, and if it is determined that the service process data in the cache has not been updated, the service process data in the cache is updated according to the update result information. In this way, it is ensured that after the database update is completed, if there is old service process data in the cache, it can be updated in time to keep the data in the cache and the database consistent. In addition, the update mechanism that performs the update operation only when it is determined that the service process data in the cache has not been updated can effectively avoid unnecessary updates to the cache, while ensuring that the data in the cache is consistent with the data in the database, and minimizes the performance loss caused to the server due to frequent cache updates.
[0072] The above steps are described in detail below, as shown below.
[0073] First, with respect to S110, the database involved in the embodiments of the present application refers to a system for storing data in a server, which can perform operations such as inserting, querying, updating, and deleting data. The update result information refers to information about the update content generated by the database after executing the update operation, such as which data is updated, how to update, and other information.
[0074] In some embodiments of the present application, Figure 2 As shown, the above step 110 may specifically include step 1101 to step 1102.
[0075] Step 1101, when it is determined that the database update is successful, the update information of the database is written into the log of the database through the row mode to obtain the updated log of the database.
[0076] The database log refers to a file or data structure used to record database operations, which may include information about various operations in the database, such as records of update, insert, delete, and other operations. The row mode refers to a recording mode of the database log. The row mode records in detail the changes that occur to each row of data in the database during the update operation, including the value before and after the modification, so as to accurately present the details of the data changes in the database. Update information refers to the details of the data changes, including which rows of data should be modified, the values before and after the modification, and other information.
[0077] Exemplarily, the server may include a database management system and a database log recording module. The database management system may set an update success judgment mechanism inside the server, and start the log recording module once it detects that the database update operation is successful; then, the log recording module writes the changes in each row of data involved in the update operation, such as which specific row, the content before the update, the content after the update, and other information, into the database log file or the corresponding log storage area in sequence according to the rules of the row mode.
[0078] Step 1102, obtaining update result information of the database from the updated log.
[0079] Exemplarily, the server searches and parses the update result information in the updated log according to a preset information extraction rule through an interactive interface with the log of the database. The preset information extraction rule may be based on a preset tag, data format or field to identify the location and content of the update result information in the updated log.
[0080] Therefore, the update information is recorded in the log in row mode, so that every update operation of the database has a detailed record. In addition, the update result information is obtained from the updated log, which provides an accurate and reliable basis for the update judgment of the service process data in the cache, so as to ensure the consistency of the cache and database data.
[0081] For example, when a service process running on a server performs business processing, if it encounters a situation where data in a database needs to be updated, the service process organizes the relevant information of the data to be updated into a data update request. Then, through the communication mechanism between the server and the database, such as a network connection and a specific database access protocol, the data update request is sent to the database. After the database receives the data update request sent by the service process, it updates the corresponding data according to the information in the data update request. After the update operation is completed, the log recording module of the database generates update result information according to the actual situation of the update.
[0082] In some embodiments of the present application, after the service process completes the update operation on the update database, the data in the cache will be invalidated to ensure that when there is a subsequent data query request, the cache can obtain the latest data from the database, thereby ensuring the timeliness and accuracy of the data. Based on this, before the above step 120, the data update method can also include deleting the data in the cache when it is determined that the database update is successful. In this way, data inconsistency problems caused by obsolete data in the cache can be effectively avoided, the accuracy and reliability of data processing and query links can be improved, and the normal operation of the service process can be guaranteed.
[0083] The cache refers to the area that temporarily stores the data of the service process in order to increase the speed at which the service process accesses data.
[0084] For example, the service process sends an invalidation instruction or a deletion instruction to the cache, and when the cache receives the invalidation instruction or the deletion instruction, it sets an automatic expiration time for the data in the cache. Once the preset expiration time is reached, the cache will automatically delete the data corresponding to the service process.
[0085] Secondly, involving step 120, the server can traverse the data in the cache corresponding to the service process, and determine whether there is service process data related to the update result information in the cache based on the characteristics in the update result information, such as specific data identifiers, data types, etc. If there is no relevant service process data, there is no need to perform subsequent steps, thereby saving server resource waste.
[0086] In some embodiments of the present application, the above-mentioned step 120 may specifically include, taking the time when the database is successfully updated as the starting time, and after a preset time has passed, detecting whether there is service process data related to the update result information in the cache; wherein the preset time is greater than the maximum value of the preset cache deletion instruction processing time and the preset data query request processing time.
[0087] The preset cache deletion instruction processing time refers to the time required to process the cache deletion instruction. The preset data query request processing time refers to the time required to process the data query request.
[0088] Therefore, within the specific time range of the preset duration, all concurrent data query requests before the data update request is initiated have been successfully completed. At the same time, all processing work related to the data update request, such as cache invalidation, has also been completed. In this way, when testing the data in the cache, it is only necessary to test a small amount of data in the cache that may not have been updated after the cache invalidation, avoiding the testing of all the data originally in the cache, greatly reducing the detection workload, improving the detection efficiency, and being able to more accurately focus on the key parts that may be affected by the data update, effectively reducing the resource consumption that may be caused by comprehensive testing.
[0089] In some embodiments of the present application, after a preset time period has passed and the time when the database is successfully updated is taken as the starting time, before checking whether there is service process data related to the update result information in the cache, such as Figure 3 As shown, the data updating method may further include steps 210 to 220.
[0090] Step 210: monitor the database logs in real time.
[0091] The database log may include timestamp, database name, table name, change details, etc. Monitoring means to continuously monitor the database log through a service process to obtain new content or changes in the database log.
[0092] Next, the specific functions of timestamp, database name, table name, and change details are explained.
[0093] Timestamps are used to identify a sequence of characters at a certain moment. In database logs, they are used to record the time when events such as data updates occur.
[0094] The database name is used to uniquely identify the database name to distinguish different databases.
[0095] The table name refers to the identifier of the table that stores data in the database. A database usually consists of multiple tables, each of which is used to store a specific type of data.
[0096] Change details refer to detailed information about data modifications in the database, including which data was modified, how the modification was made (e.g., whether it was added, deleted, or modified), and the data content before and after the modification.
[0097] Step 220: The time when the update information of the database is written into the log of the database is determined as the time when the database update is successful.
[0098] Exemplarily, the time point at which the database update information is recorded in the database log may be confirmed as the time when the database update is successful.
[0099] Therefore, real-time monitoring of database logs ensures real-time grasp of data updates, helps to clearly define the time point when the database update is successful, and by accurately defining the time of successful update, it can improve the accuracy of the preset time, making the entire data processing process more accurate in time control and avoiding data inconsistency problems caused by time errors.
[0100] Exemplarily, a specific listening program such as a consistency guarantee program can be run on the server, the consistency guarantee program can be connected to the database log, and the database log can be checked at a certain frequency such as once per second or a shorter time interval to see if there is new content generated. When the data in the database changes, the consistency guarantee program can obtain the specific content of the data change in the database in a timely manner. However, after listening to the data change, the consistency guarantee program will not process the cache immediately, but will set a delay time, and this delay time, that is, the preset time, must be greater than the timeout time requested by the service process to ensure that all successful update operations can be completed smoothly. For operations that have not been completed after the delay time, it is a request that has timed out and failed. For these requests that have timed out and failed, no subsequent processing is required. After the delay time ends, the consistency guarantee program will query the corresponding data in the cache and compare it with the changed value listened to.
[0101] Next, step 130 is involved, and the update result information includes the data changes after the database update operation is completed. By comparing the data in the cache and the update result information, it can be found whether the data in the cache is consistent with the updated data in the database, that is, whether the service process data in the cache needs to be updated.
[0102] Then, in step 140, when it is confirmed that the service process data has not been updated, the service process data in the cache is updated according to the update result information, so that the cache data is consistent with the latest state of the database.
[0103] It is worth noting here that during the operation of the server, the consumption of server performance by update operations is much greater than that by query operations. Therefore, the embodiment of the present application adopts a conditional update mechanism that first confirms whether the service process data in the cache has been updated, and only when it is confirmed that it has not been updated, performs an update operation on the service process data in the cache according to the update result information. This mechanism can effectively avoid unnecessary cache updates, ensure that the cache data is consistent with the latest status of the database, and minimize the performance loss caused by frequent cache updates, thereby improving the overall operating efficiency and stability of the server.
[0104] In some embodiments of the present application, Figure 4 As shown, the above step 130 may specifically include step 1301 to step 1302.
[0105] Step 1301, when there is service process data in the cache, compare the data related to the service process data in the cache with the data related to the service process data in the update result information to obtain a comparison result.
[0106] For example, data related to the service process data can be extracted from the cache, and data related to the service process data can be screened out from the update result information. Then, these data are compared one by one, and through this detailed comparison, the difference between the data in the cache and the data in the update result information can be accurately found.
[0107] Step 1302: Determine whether data related to the service process data is updated based on the comparison result.
[0108] Therefore, by comparing the service process data in the cache with the relevant data in the update result information, it is possible to accurately determine whether the service process data in the cache is updated, so that the cache data can be adjusted in time to ensure that the data in the cache is consistent with the updated data in the database.
[0109] In some embodiments of the present application, the update result information includes an update row index and an update data value corresponding to the update row index, the service process data includes a first target row index in the update row index, the data related to the service process data in the cache includes a cache data value in the cache corresponding to the first target row index, and the comparison result includes a first comparison result or a second comparison result.
[0110] Among them, the update row index refers to the index information used to identify the updated row in the database. Through this index, you can quickly locate which rows of data are affected by the update operation. The update data value refers to the new data value of the row pointed to by the update row index after the update operation in the database. The service process data refers to the data related to the service process running on the server, which includes the first target row index in the update row index, which indicates that the service process data is associated with the database update operation. The first target row index refers to a part of the update row index, which is a specific row index related to the current service process data. The cache data value refers to the data value stored in the cache that corresponds to the first target row index. The cache is a place where data is temporarily stored to improve data access speed. The cache data value is the data content related to a specific index obtained from the cache.
[0111] Based on this, Figure 5 As shown, the above step 1301 may specifically include steps 13011 to 13013.
[0112] Step 13011: When there is a first target row index in the update row index in the cache, obtain a first update data value corresponding to the first target row index according to the update result information.
[0113] Exemplarily, the storage location of the first target row index is searched in the cache, and after confirming its existence, the update data value corresponding to the first target row index is found from the update result information in an index matching manner.
[0114] Step 13012: compare the first updated data value with the cached data value, and obtain a first comparison result when the first updated data value is the same as the cached data value.
[0115] Exemplarily, a data comparison operation is used to compare the first updated data value and the cached data value bit by bit or element by element. If the two are the same, it is determined that a first comparison result is obtained.
[0116] Step 13013, compare the first updated data value with the cached data value, and obtain a second comparison result when the first updated data value is different from the cached data value.
[0117] Exemplarily, a data comparison operation is used to compare the first updated data value and the cached data value bit by bit or element by element. If any part of the two is not equal, it is determined that the second comparison result is obtained.
[0118] Therefore, by comparing the cached data value and the updated data value, it is possible to accurately determine whether the two are consistent, effectively avoiding the problem of incorrect updating or untimely updating of cached data due to inaccurate data comparison.
[0119] In some embodiments of the present application, corresponding measures can be taken according to the comparison results to ensure the consistency of cache and database data. Figure 6 As shown, the above step 1302 may specifically include step 13021 to step 13022.
[0120] Step 13021: Determine, based on the first comparison result, whether the data related to the service process data has been updated.
[0121] Step 13022: According to the second comparison result, determine that the data related to the service process data has not been updated.
[0122] Therefore, when data is updated, it can be discovered and responded to in time to maintain the consistency of cache and database data. When data is not updated, no unnecessary operations will be performed, thereby improving the overall processing efficiency of the server.
[0123] In some embodiments of the present application, when there is service process data in the cache, determining whether the service process data in the cache is updated based on the update result information may include finding the actual data value corresponding to the same index in the update result information of the database through the index of the service process data in the cache, and after finding the data value corresponding to the same index in the database and the cache, comparing the two data values to determine whether the data in the cache is consistent with the latest data in the database. If the two are the same, it means that the data in the cache is still the latest and does not need to be updated; if they are different, it means that the data in the cache is outdated and needs to be updated according to the latest data in the database.
[0124] In some embodiments of the present application, based on this, after the aforementioned step 140, as Figure 7 As shown, the data updating method may further include steps 310 to 340.
[0125] Step 310, obtaining a cached deletion record, where the deletion record includes a deletion row index related to deleting data based on the update result information.
[0126] The cache deletion record refers to a collection of information related to data deletion operations in the cache, including the deletion row index involved in deleting data based on update result information. The deletion row index is used to determine the index information of the row where the deleted data is located in the cache.
[0127] Exemplarily, the acquisition of cached deletion record information focuses on the deletion row index content related to the data deletion operation based on the update result information in the cache. These deletion row indexes can indicate which cached data rows may be affected during the database update process.
[0128] Step 320: Check whether there is a data value corresponding to the deleted row index in the cache.
[0129] Exemplarily, the cache data structure is traversed, and the deleted row index is used as a search basis to check whether the data value at the corresponding position can be found in the cache.
[0130] Step 330: If there is no data value corresponding to the second target row index in the deleted row index in the cache, obtain a second updated data value corresponding to the second target row index according to the update result information.
[0131] Exemplarily, in the update result information, the corresponding second update data value is searched through the second target row index to obtain accurate data of the user update cache, so as to ensure that correct data can be supplemented when cache data is missing.
[0132] Step 340 , writing the second updated data value into a corresponding position in the cache according to the second target row index.
[0133] Exemplarily, the second target row index can be used to determine the write position in the cache, and then the second updated data value can be stored in the position, thereby updating the missing data in the cache, making the cache data more complete and accurate, and further ensuring the consistency of the cache and database data.
[0134] Therefore, in the update result information, by performing parsing and matching operations on it, the corresponding second update data value is found according to the second target row index, ensuring that accurate data can be obtained for updating the cache in the event of cache data missing.
[0135] In some embodiments of the present application, the deletion record also includes a deletion row index that is unrelated to the update result information and an initial data value corresponding to the deletion row index. Based on this, the aforementioned data update method may also include, according to the deletion row index, writing the initial data value to a corresponding position in the cache.
[0136] For example, in the deletion record, in addition to the information related to the update, there are also deletion row indexes and corresponding initial data values that are not related to the update result information. At this time, the initial data values can be rewritten back to the cache based on these deletion row indexes to restore some data in the cache that was mistakenly deleted or needs to be reused.
[0137] Therefore, the deleted row index and initial data value that are not related to the update are extracted from the deleted record, and then the initial data value is written back to the cache according to the index, which helps to recover the data in the cache that may have been deleted by mistake or needs to be reused, ensure the integrity and correctness of the cache data, and maintain the normal function of the cache.
[0138] Next, the above data updating method of the present application will be further explained with reference to specific examples.
[0139] During the operation of the service process, data query requests and data update requests may be concurrent. When a data query request occurs, data will first be obtained from the cache. If the cache is missing, that is, the data query request fails to obtain data from the cache, then the data query request turns to the database to read data. However, before the data read from the database is put into the cache, a data update request arrives. This data update request not only updates the database, but also deletes the data related to the service process in the cache. In this case, the previous query request will put the old data read from the database into the cache, so that the data in the cache and the database will be inconsistent. At this time, when the delay set by the consistency guarantee program in the server ends, the change records of the cache and the database will be compared. Once the two are found to be inconsistent, the cache will be invalidated. After that, the data query operation is performed again, and then the cache is updated according to the new query results, so that the data in the cache and the database are restored to be consistent. In this way, the problem caused by processing data query requests while updating the database can be effectively solved, that is, the data query request is prevented from obtaining old data, thereby preventing the inconsistency of business data in the cache and the database.
[0140] Based on the data updating method provided in the above embodiment, the present application also provides a specific implementation of the data updating device. Please refer to the following embodiment.
[0141] See also Figure 8 , the data updating device 400 provided in the embodiment of the present application includes:
[0142] A first acquisition module 410 is used to acquire update result information of a database;
[0143] A first detection module 420, used to detect whether there is service process data related to the update result information in the cache;
[0144] A first determination module 430 is used to determine whether the service process data in the cache is updated according to the update result information when there is service process data in the cache;
[0145] The updating module 440 is configured to update the service process data in the cache according to the update result information when it is determined that the service process data has not been updated.
[0146] Therefore, the first acquisition module 410 is used to obtain the update result information of the database, and then the detection module 420 and the first determination module 430 are used to determine whether the service process data related to the update result information in the cache has been updated. Then, when the update module 440 is used to determine that the service process data in the cache has not been updated, the service process data in the cache is updated according to the update result information. In this way, it is ensured that after the database update is completed, if there is old service process data in the cache, it can be updated in time to keep the business data in the cache and the database consistent.
[0147] In some embodiments of the present application, the first acquisition module 410 may include:
[0148] The writing submodule is used to write the update information of the database into the log of the database through the row mode when it is determined that the database update is successful, so as to obtain the updated log of the database;
[0149] The acquisition submodule is used to obtain the update result information of the database from the updated log.
[0150] In some embodiments of the present application, the data updating device 400 may further include:
[0151] A deletion module is used to delete the data in the cache before detecting whether there is service process data related to the update result information in the cache and when it is determined that the database update is successful;
[0152] In some embodiments of the present application, the above-mentioned first detection module 420 is specifically used to detect whether there is service process data related to the update result information in the cache after a preset time period, with the time when the database is successfully updated as the starting time; wherein the preset time period is greater than the maximum value of the preset cache deletion instruction processing time and the preset data query request processing time.
[0153] In some embodiments of the present application, the data updating device 400 may further include:
[0154] The monitoring module is used to monitor the database log in real time before detecting whether there is service process data related to the update result information in the cache after a preset time period starting from the time when the database is successfully updated;
[0155] The second determining module is used to determine the time when the update information of the database is written into the log of the database as the time when the database is successfully updated.
[0156] In some embodiments of the present application, the first determining module may specifically include:
[0157] A comparison submodule, for comparing data related to the service process data in the cache with data related to the service process data in the update result information to obtain a comparison result when there is service process data in the cache;
[0158] The determination submodule is used to determine whether the data related to the service process data is updated according to the comparison result.
[0159] In some embodiments of the present application, the above-mentioned comparison submodule may specifically include:
[0160] an acquiring unit, configured to acquire, according to the update result information, a first updated data value corresponding to the first target row index, when the update result information includes an update row index and an update data value corresponding to the update row index, the service process data includes a first target row index in the update row index, the data related to the service process data in the cache includes a cache data value in the cache corresponding to the first target row index, the comparison result includes a first comparison result or a second comparison result, and the cache has the first target row index in the update row index;
[0161] A first comparison unit, used to compare the first update data value with the cache data value, and obtain a first comparison result when the first update data value is the same as the cache data value;
[0162] The second comparison unit is used to compare the first update data value with the cache data value, and obtain a second comparison result when the first update data value is different from the cache data value.
[0163] In some embodiments of the present application, the above-mentioned determination submodule may include:
[0164] A first determining unit, configured to determine, based on the first comparison result, that data related to the service process data has been updated;
[0165] The second determining unit is used to determine, according to the second comparison result, that the data related to the service process data has not been updated.
[0166] In some embodiments of the present application, the data updating device 400 may further include:
[0167] A second acquisition module is used to acquire a cache deletion record after the update result information includes an update row index and an update data value corresponding to the update row index, it is determined that the service process data is not updated, and the service process data in the cache is updated according to the update result information, wherein the deletion record includes a deletion row index related to the deletion of data based on the update result information;
[0168] A second detection module is used to detect whether there is a data value corresponding to the deleted row index in the cache;
[0169] A third acquisition module, configured to acquire, when there is no data value corresponding to the second target row index in the deleted row index in the cache, a second updated data value corresponding to the second target row index according to the update result information;
[0170] The first writing module is used to write the second updated data value into a corresponding position in the cache according to the second target row index.
[0171] In some embodiments of the present application, the data updating device 400 may further include:
[0172] The first writing module is used to write the initial data value into a corresponding position in the cache according to the deleted row index when the deleted record also includes a deleted row index unrelated to the update result information and an initial data value corresponding to the deleted row index.
[0173] Each module of the data updating device 400 provided in the embodiment of the present application can realize Figure 1 The functions of the various steps of the data updating method provided in Figures 1 and 2 can achieve the corresponding technical effects. For the sake of brevity, they will not be repeated here.
[0174] Fig. 9 A schematic diagram of the hardware structure of an electronic device provided in some embodiments of the present application is shown.
[0175] The electronic device 500 may include a processor 501 and a memory 502 storing computer program instructions.
[0176] Specifically, the processor 501 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0177] The memory 502 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 502 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 502 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 502 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 502 is a non-volatile solid-state memory.
[0178] In a particular embodiment, the memory 502 may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Therefore, generally, the memory 502 includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the data processing method according to the first aspect of the present application.
[0179] The processor 501 implements any one of the data updating methods in the above embodiments by reading and executing the computer program instructions stored in the memory 502 .
[0180] In one example, the electronic device may further include a communication interface 503 and a bus 510. Figure 5 As shown, the processor 501, the memory 502, and the communication interface 503 are connected via a bus 510 and communicate with each other.
[0181] The communication interface 503 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0182] Bus 510 includes hardware, software or both, and the parts of electronic equipment are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 510 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the application considers any suitable bus or interconnection.
[0183] The electronic device can execute the data updating method in the embodiment of the present application, thereby realizing the combination Figures 1 to 8 The data updating method and device described.
[0184] In addition, in combination with the data updating method in the above embodiment, the embodiment of the present application may provide a computer-readable storage medium for implementation. The computer-readable storage medium stores computer program instructions; when the computer program instructions are executed by the processor, any one of the data updating methods in the above embodiment is implemented. Examples of computer-readable storage media include non-transitory computer-readable storage media, such as portable disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, etc.
[0185] In addition, in combination with the data updating method in the above embodiment, the embodiment of the present application may provide a computer program product for implementation. The program product is stored in a storage medium, and may specifically include a computer program or instruction, which implements any one of the data updating methods in the above embodiment when executed by a processor. The program product is executed by at least one processor to implement the various processes of the above data processing method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0186] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0187] The functional blocks shown in the above block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0188] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0189] Aspects of the present disclosure are described above with reference to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0190] The above are only specific implementation methods of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.
Claims
1. A data updating method, characterized in that: include: Get the update result information of the database; Detecting whether there is service process data related to the update result information in the cache; In a case where the service process data is present in the cache, determining whether the service process data in the cache is updated according to the update result information; When it is determined that the service process data has not been updated, the service process data in the cache is updated according to the update result information.
2. The data updating method according to claim 1, characterized in that: The obtaining of update result information of the database includes: When it is determined that the database update is successful, writing the update information of the database into the log of the database in row mode to obtain the updated log of the database; The update result information of the database is obtained from the updated log.
3. The data updating method according to claim 2, characterized in that: Before detecting whether there is service process data related to the update result information in the cache, the method further includes: If it is determined that the database update is successful, deleting the data in the cache; The detecting whether there is service process data related to the update result information in the cache includes: Taking the time when the database is successfully updated as the starting time, after a preset time has passed, detecting whether there is service process data related to the update result information in the cache; The preset duration is greater than a maximum of a preset cache deletion instruction processing duration and a preset data query request processing duration.
4. The data updating method according to claim 3, characterized in that: The method further includes: starting from the time when the database is successfully updated and, after a preset time period, detecting whether there is service process data related to the update result information in the cache: Monitor the logs of the database in real time; The time when the update information of the database is written into the log of the database is determined as the time when the database is successfully updated.
5. The data updating method according to claim 1, characterized in that: In the case where the service process data is in the cache, determining whether the service process data in the cache is updated according to the update result information includes: When the service process data is present in the cache, comparing the data related to the service process data in the cache with the data related to the service process data in the update result information to obtain a comparison result; According to the comparison result, it is determined whether the data related to the service process data is updated.
6. The data updating method according to claim 5, characterized in that: The update result information includes an update row index and an update data value corresponding to the update row index, the service process data includes a first target row index in the update row index, the data in the cache related to the service process data includes a cache data value in the cache corresponding to the first target row index, and the comparison result includes a first comparison result or a second comparison result; In the case where the service process data is present in the cache, comparing the data related to the service process data in the cache with the data related to the service process data in the update result information to obtain a comparison result, including: When there is a first target row index in the update row index in the cache, obtaining a first update data value corresponding to the first target row index according to the update result information; Comparing the first updated data value with the cached data value, and obtaining the first comparison result when the first updated data value is the same as the cached data value; The first updated data value is compared with the cached data value, and when the first updated data value is different from the cached data value, the second comparison result is obtained.
7. The data updating method according to claim 6, characterized in that: The step of determining, according to the comparison result, whether data related to the service process data is updated includes: According to the first comparison result, determining that data related to the service process data has been updated; According to the second comparison result, it is determined that the data related to the service process data has not been updated.
8. The data updating method according to claim 1 or 3, characterized in that: The update result information includes an update row index and an update data value corresponding to the update row index; In the case where it is determined that the service process data has not been updated, after updating the service process data in the cache according to the update result information, the method further includes: Acquire the deletion record of the cache, wherein the deletion record includes a deletion row index related to deleting data based on the update result information; Detecting whether there is a data value corresponding to the deleted row index in the cache; When there is no data value corresponding to the second target row index in the deleted row index in the cache, acquiring a second updated data value corresponding to the second target row index according to the update result information; The second updated data value is written into a corresponding position in the cache according to the second target row index.
9. The data updating method according to claim 1, characterized in that: The deletion record also includes a deletion row index that is unrelated to the update result information and an initial data value corresponding to the deletion row index; the method further includes: The initial data value is written into a corresponding position in the cache according to the delete row index.
10. A data updating device, characterized in that: The device comprises: A first acquisition module is used to acquire update result information of the database; A first detection module, used to detect whether there is service process data related to the update result information in the cache; A first determining module, configured to determine whether the service process data in the cache is updated according to the update result information when the service process data is present in the cache; An updating module is used to update the service process data in the cache according to the update result information when it is determined that the service process data has not been updated.
11. An electronic device, characterized in that: The device comprises: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the data updating method according to any one of claims 1 to 9 is implemented.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the data updating method according to any one of claims 1 to 9 is implemented.
13. A computer program product, characterized in that It comprises a computer program, which, when executed, implements the data updating method according to any one of claims 1 to 9.