Cache refresh method, device, equipment, computer program product and storage medium
Through real-time database read and write operation log processing, key-value pairs are generated and refresh operations are performed, which solves the problem of difficulty in achieving consistency between database and cache data, improves cache refresh efficiency, and avoids business intrusion.
Patent Information
- Application Number
- CN202411035782.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-07-31
AI Technical Summary
The existing technology is difficult to efficiently achieve data consistency between the database and cache, and may intrude into user services.
Through the database's real-time read and write operation logs, determine the characteristic information of the read and write operation events and convert it into a serialized array, generate a set of key-value pairs based on the table structure information of the target database table, and perform corresponding refresh operations to maintain the cached data. consistency.
It improves cache refresh efficiency, avoids intrusion into user business, and ensures efficient data consistency between the database and cache.
Smart Images

Figure CN118568114B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cache technology, and in particular to a cache refresh method, device, equipment, computer program product and storage medium. Background Art
[0002] As the business scale expands, the access pressure on the database continues to increase. Simply relying on the database cannot meet the business needs of high concurrency and low latency. For this reason, cache technology came into being. The cache can store commonly used data to improve read and write performance. In order to ensure the normal operation of related businesses, it is necessary to ensure data consistency between the database and the cache. However, there is a lack of a mature method in the relevant technology, which makes it difficult to efficiently achieve data consistency between the database and the cache, and may require intrusion into user business.
[0003] Therefore, how to provide a solution to the above technical problems is a problem that those skilled in the art need to solve at present. Summary of the invention
[0004] The purpose of the present invention is to provide a cache refresh method, device, equipment, computer program product and storage medium. Since the cache data can be refreshed through the real-time read and write operation log of the database, it not only improves the cache refresh efficiency but also avoids intrusion into user business.
[0005] In order to solve the above technical problems, the present invention provides a cache refresh method, which is applied to a computer system, comprising:
[0006] For the read-write operation events in the real-time read-write operation log of the database, determine the characteristic information of the read-write operation events, and convert the data of the read-write operation events into a serialized array, wherein the characteristic information includes the table name of the database table to which it belongs and the event type;
[0007] If the database table to which the read / write operation event belongs belongs to a pre-specified target database table, a key-value pair set corresponding to the read / write operation event is generated according to the serialized array of the read / write operation event and the table structure information of the target database table, wherein the key-value pair set includes a plurality of key-value pairs, and any of the key-value pairs includes: a single field value in the read / write operation event and its corresponding field name;
[0008] Determine cache data corresponding to the read / write operation event in the cache according to primary key information of the read / write operation event in the corresponding database table;
[0009] Based on the key-value pair set of the read-write operation event, a refresh operation corresponding to the event type of the read-write operation event is performed on the cache data corresponding to the read-write operation event.
[0010] On the other hand, the cache refresh method further includes:
[0011] In response to the cache reset instruction, blocking a refresh operation of the first thread;
[0012] After the cache is cleared, the data of each target database table in the database is written into the cache;
[0013] Unblocking the refresh operation of the first thread;
[0014] Among them, the first thread is a thread that executes a cache refresh operation, and the cache refresh operation refers to: based on the key-value pair set of the read and write operation events, performing a refresh operation corresponding to the event type of the read and write operation event on the cache data corresponding to the read and write operation event.
[0015] On the other hand, in response to the cache reset instruction, blocking the refresh operation of the first thread includes:
[0016] In response to the cache reset instruction, a semaphore of a first value is sent to the cache, so that the cache blocks a refresh operation of the first thread after recognizing the semaphore of the first value;
[0017] Unblocking the refresh operation of the first thread includes:
[0018] A semaphore with a second value is sent to the cache, so that the cache unblocks the refresh operation of the first thread after recognizing the semaphore with the second value.
[0019] On the other hand, the cache reset instruction includes a first reset instruction and / or a second reset instruction;
[0020] The first reset instruction is: a reset instruction automatically generated at a preset time of the day;
[0021] The second reset instruction is: a reset instruction received through a human-machine interface.
[0022] On the other hand, the cache and the database are both connected to the preset interface software, so that each application service can retrieve data from the cache or the database through the preset interface software;
[0023] Wherein, the preset interface software includes a software development kit.
[0024] On the other hand, the cache refresh method further includes:
[0025] When the read request sent by the application service through the preset interface software hits the cache, the hit target cache data is written into the second message queue;
[0026] Determine whether there is database data corresponding to the target cache data in the database;
[0027] If not, deleting the target cache data from the cache;
[0028] If so, determining whether the target cache data is consistent with the database data in the database corresponding to the target cache data;
[0029] If they are inconsistent, the target cache data in the cache is updated based on the database data.
[0030] On the other hand, it is applied to any node in a computer system;
[0031] The cache refresh method further includes:
[0032] In response to a heartbeat signal generated at every preset period, a preset time is added to the expiration time of a service identifier corresponding to itself in a service identifier sequence, wherein the service identifier sequence includes service identifiers of a plurality of nodes arranged in order, and the service identifier whose expiration time is not greater than zero is in an invalid state;
[0033] For a read / write operation event in a real-time read / write operation log of a database, determining characteristic information of the read / write operation event, and converting data of the read / write operation event into a serialized array includes:
[0034] Determine whether the service identifier corresponding to itself is at the first position in the service identifier sequence;
[0035] If it is in the first place, it determines itself as the primary copy, determines the characteristic information of the read and write operation events in the real-time read and write operation log of the database, and converts the data of the read and write operation events into a serialized array.
[0036] On the other hand, for the read-write operation events in the real-time read-write operation log of the database, determining the characteristic information of the read-write operation events, and converting the data of the read-write operation events into a serialized array includes:
[0037] As a slave node of the database, request the real-time read and write operation logs in the database;
[0038] Determining the event type of the read-write operation event through the data of the read-write operation event in the read-write operation log;
[0039] Determine the table name of the database table to which the read / write operation event belongs through a table mapping event located before the read / write operation event in the read / write operation log;
[0040] Convert the data of the read and write operation events into a serialized array;
[0041] The event types of the read and write operation events include delete events, insert events and update events.
[0042] On the other hand, based on the key-value pair set of the read-write operation event, performing a refresh operation corresponding to the event type of the read-write operation event on the cache data corresponding to the read-write operation event includes:
[0043] If the event type of the read / write operation event is a delete event, deleting the cache data corresponding to the read / write operation event;
[0044] If the event type of the read / write operation event is an insert event, the key-value pair set of the read / write operation event and the primary key information are written into the cache as cache data;
[0045] If the event type of the read / write operation event is an update event, overwriting the key-value pair set of the read / write operation event and the primary key information to the cache data corresponding to the read / write operation event in the cache;
[0046] When the write cache operation corresponding to a write event fails, the primary key information of the write event that failed to write cache is added to the first message queue so that the asynchronous thread deletes the cache data corresponding to the primary key information in the first message queue in the cache, wherein the write event includes an insert event and an update event.
[0047] On the other hand, if the database table to which the read / write operation event belongs belongs to a pre-specified target database table, generating a key-value pair set corresponding to the read / write operation event according to the serialized array of the read / write operation event and the table structure information of the target database table includes:
[0048] If the database table to which the read / write operation event belongs belongs to a pre-specified target database table, a field name sequence is determined from the table structure information of the target database table to which the read / write operation event belongs, wherein the field name sequence includes a plurality of field names arranged in order, the field names are field names in the target database table to which the read / write operation event belongs, and the order of the field names in the field name sequence is equal to the order of the field names in the respective field names of the target database table to which the read / write operation event belongs;
[0049] If the read-write operation event is a delete event, a first key-value pair set corresponding to the delete event is generated according to the serialized data corresponding to the delete event and the field name sequence, wherein the serialized data corresponding to the delete event is a row of data in the database table deleted by the delete event, and the first key-value pair set includes multiple key-value pairs, each key-value pair includes a single field value deleted by the delete event and its corresponding field name;
[0050] If the read / write operation event is an insert event, a second key-value pair set corresponding to the insert event is generated according to the serialized data corresponding to the insert event and the field name sequence, wherein the serialized data corresponding to the insert event is a row of data inserted into the database table by the insert event, and the second key-value pair set includes multiple key-value pairs, each key-value pair includes a single field value inserted by the insert event and its corresponding field name;
[0051] If the read-write operation event is an update event, a third key-value pair set and a fourth key-value pair set corresponding to the update event are generated according to the serialized data corresponding to the update event and the field name sequence, wherein the serialized data corresponding to the update event is the target row data updated by the update event in the database table, and the third key-value pair set and the fourth key-value pair set both include multiple key-value pairs, and any key-value pair in the third key-value pair set includes: a single field value and its corresponding field name before the target row data is updated, and any key-value pair in the fourth key-value pair set includes: a single field value and its corresponding field name after the target row data is updated.
[0052] On the other hand, if the database table to which the read / write operation event belongs belongs to a pre-specified target database table, after generating a key-value pair set corresponding to the read / write operation event according to the serialized array of the read / write operation event and the table structure information of the target database table, the cache refresh method further includes:
[0053] Based on the characteristic information of the read / write operation event and the key-value pair set corresponding to the read / write operation event, construct a storage object with a preset structure;
[0054] The storage object includes a first storage location and a second storage location, the first storage location is used to store the feature information, the second storage location includes a pre-storage data storage location and a post-storage data storage location, the pre-storage data storage location is used to store a key-value pair set corresponding to data before a read / write operation event occurs, and the post-storage data storage location is used to store a key-value pair set corresponding to data after a read / write operation event occurs;
[0055] Determining cache data corresponding to the read / write operation event in the cache according to primary key information of the read / write operation event in the corresponding database table includes:
[0056] The cache data corresponding to the read / write operation event and located in the cache is determined according to the primary key information in the database table corresponding to the table name in the first storage position in the storage object.
[0057] In order to solve the above technical problems, the present invention further provides a cache refresh device, comprising:
[0058] A first determination module is used to determine characteristic information of the read / write operation event in the real-time read / write operation log of the database, and convert the data of the read / write operation event into a serialized array, wherein the characteristic information includes the table name of the database table and the event type;
[0059] A first generating module is used to generate a key-value pair set corresponding to the read-write operation event according to the serialized array of the read-write operation event and the table structure information of the target database table if the database table to which the read-write operation event belongs belongs to a pre-specified target database table, wherein the key-value pair set includes a plurality of key-value pairs, and any of the key-value pairs includes: a single field value in the read-write operation event and its corresponding field name;
[0060] A second determination module, configured to determine cache data corresponding to the read / write operation event in the cache according to primary key information of the read / write operation event in the corresponding database table;
[0061] The first refresh module is used to perform a refresh operation corresponding to the event type of the read / write operation event on the cache data corresponding to the read / write operation event based on the key-value pair set of the read / write operation event.
[0062] In order to solve the above technical problems, the present invention further provides a cache refresh device, comprising:
[0063] Memory for storing computer programs;
[0064] A processor is used to implement the steps of the cache refresh method described above when executing the computer program.
[0065] In order to solve the above technical problem, the present invention further provides a computer program product, including a computer program / instruction, which implements the steps of the cache refresh method described above when executed by a processor.
[0066] In order to solve the above technical problem, the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the cache refresh method described above are implemented.
[0067] Beneficial effect: The present invention provides a cache refresh method. Considering that the real-time read and write operation log of the database reflects the latest status of the database data, and the access to the read and write operation log avoids intrusion into user business, the present invention can first determine the characteristic information of the read and write operation event based on the real-time read and write operation log of the database, and convert the data of the read and write operation event into a serialized array, and then generate a key-value pair set corresponding to the read and write operation event according to the table structure information of the target database table to which the read and write operation event belongs and the serialized array of the read and write operation event. Then, based on the key-value pair set of the read and write operation event, a refresh operation corresponding to the event type of the read and write operation event can be performed on the cache data corresponding to the read and write operation event. Since the cache data can be refreshed through the real-time read and write operation log of the database, not only the cache refresh efficiency is improved, but also intrusion into user business is avoided.
[0068] The present invention also provides a cache refresh device, equipment, computer program product and computer readable storage medium, which have the same beneficial effects as the above cache refresh method. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the relevant technologies and the drawings required for use in the embodiments are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0070] Figure 1 A schematic diagram of a flow chart of a cache refresh method provided by the present invention;
[0071] Figure 2 A schematic diagram of the principle of a data query method provided by the present invention;
[0072] Figure 3 A schematic diagram of the principle of a cache error correction method provided by the present invention;
[0073] Figure 4 A schematic diagram of the principle of a method for determining a master copy provided by the present invention;
[0074] Figure 5 A schematic flow chart of another cache refresh method provided by the present invention;
[0075] Figure 6 A schematic diagram of a flow chart of another cache refresh method provided by the present invention;
[0076] Figure 7 A schematic diagram of the structure of a cache refresh device provided by the present invention;
[0077] Figure 8 A schematic diagram of the structure of a cache refresh device provided by the present invention;
[0078] Fig. 9 A schematic diagram of the structure of a computer-readable storage medium provided by the present invention. DETAILED DESCRIPTION
[0079] The core of the present invention is to provide a cache refresh method, device, equipment, computer program product and storage medium. Since the cache data can be refreshed through the real-time read and write operation log of the database, it not only improves the cache refresh efficiency but also avoids intrusion into user business.
[0080] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0081] Please refer to Figure 1 , Figure 1 A schematic flow chart of a cache refresh method provided by the present invention, wherein the cache refresh method is applied to a computer system, comprising:
[0082] S101: for a read / write operation event in a real-time read / write operation log of a database, determining characteristic information of the read / write operation event, and converting data of the read / write operation event into a serialized array, wherein the characteristic information includes a table name of a corresponding database table and an event type;
[0083] Specifically, considering the technical problems in the above background technology, and considering that (1) the real-time read and write operation log of the database reflects the latest status of the database data, and (2) access to the read and write operation log avoids intrusion into user services, the embodiments of the present invention intend to update the real-time data in the database based on the real-time read and write operation log of the database and synchronize it to the cache, so as to efficiently achieve consistency between the database and the cache, and access to the read and write operation log of the database avoids intrusion into user services, thereby improving user experience.
[0084] Among them, the read and write operation log refers to the log generated by the database based on the read and write operation events, and the read and write operation events refer to the events of performing read and write operations on the data in the database. The event types of read and write operation events can include multiple types, such as deletion events, insertion events, and update events, etc., which are not limited in the embodiments of the present invention.
[0085] Specifically, in order to smoothly refresh the cached data in the cache based on the read-write operation event, it is necessary to know the database table and event type to which the read-write operation event belongs, and it is necessary to obtain the data of the read-write operation event. The data here may refer to the data of the database before the read-write operation event occurs and the data after the read-write operation event occurs. Considering that the read-write operation event may include the field values of a row of data to be operated in the database table, but does not include the field names corresponding to the field values, and the field values in the data of the read-write operation event have an order, which can play an important role in determining the field name corresponding to the field value. Therefore, in an embodiment of the present invention, the data of the read-write operation event can be converted into a serialized array, and the serialized data and feature information can be used as the data basis for subsequent steps.
[0086] To better illustrate the embodiment of the present invention, please refer to the following Table 1:
[0087] Table 1: A database table
[0088] Logo A B C D 1 2 3 4 5
[0089] Specifically, in Table 1, the items in the first row of Table 1 are field names, and the items in the second row are field values corresponding to the field names. For example, the field value corresponding to the identifier is 1, where the identifier can also be called ID, which is usually regarded as the primary key of the database table. In the database table, in addition to the row where the field name is located, multiple rows of field values can be included, and the object usually processed by a single read and write operation event is a single row of field values in the database table.
[0090] S102: If the database table to which the read / write operation event belongs belongs to a pre-specified target database table, a key-value pair set corresponding to the read / write operation event is generated according to the serialized array of the read / write operation event and the table structure information of the target database table, wherein the key-value pair set includes multiple key-value pairs, and any key-value pair includes: a single field value in the read / write operation event and its corresponding field name;
[0091] Specifically, considering that the read and write operation events in the read and write operation log may involve any database table, and not all database tables need to be updated into the cache, the target database table can be set in advance in the embodiment of the present invention. Therefore, in the embodiment of the present invention, subsequent operations can be performed when the database table to which the read and write operation event belongs belongs to the pre-specified target database table.
[0092] Specifically, as stated above, since the serialized array obtained by converting the data in the read and write operation events includes each field value but not each field name, this hinders the refresh of the cached data. Therefore, in an embodiment of the present invention, a key-value pair set corresponding to the read and write operation event can be generated based on the serialized array of the read and write operation event and the table structure information of the target database table, that is, a correspondence between the field value in the serialized array and the field name to which it belongs is established, and a key-value pair set composed of each key-value pair is obtained, and it is used as the data basis for subsequent steps.
[0093] Among them, organizing data in the form of key-value pairs can improve data processing efficiency.
[0094] In addition, it is worth mentioning that in the embodiment of the present invention, the table structure information of each target database table can be stored in advance in a specific column of a specific database table in the database. Then, after the computer system is running, the table structure information of each target database table can be obtained from the specific column of the specific database table in the database through a read operation for subsequent backup. The core content of the table structure information of the target database table is: table name, field name of each column of the target database table and the position of the column to which it belongs in the table. Of course, other information can also be included, such as the mode of the table and the data type of each column, etc., which is not limited in the embodiment of the present invention.
[0095] S103: determining cache data corresponding to the read / write operation event in the cache according to primary key information of the read / write operation event in the corresponding database table;
[0096] Specifically, in order to determine which row in which database table the database data involved in the read and write operation event belongs to, and this information can be reflected in the primary key information in the database table to which the read and write operation event belongs, the embodiment of the present invention can determine the cache data corresponding to the read and write operation event in the cache based on the primary key information in the database table to which the read and write operation event belongs, so as to perform a cache refresh operation in subsequent steps.
[0097] S104: Based on the key-value pair set of the read-write operation event, a refresh operation corresponding to the event type of the read-write operation event is performed on the cache data corresponding to the read-write operation event.
[0098] Specifically, since the key-value pair set corresponding to the read-write operation event and the corresponding cache data in the cache have been determined in the aforementioned steps, and considering that the specific cache refresh operation is related to the event type of the read-write operation event, the embodiment of the present invention can be based on the key-value pair set of the read-write operation event. The refresh operation corresponding to the event type of the read-write operation event can be performed on the cache data corresponding to the read-write operation event.
[0099] The present invention provides a cache refresh method. Considering that the real-time read-write operation log of a database reflects the latest status of database data, and access to the read-write operation log avoids intrusion into user services, the present invention can first determine characteristic information of a read-write operation event based on the real-time read-write operation log of the database, and convert the data of the read-write operation event into a serialized array. Then, according to the table structure information of a target database table to which the read-write operation event belongs and the serialized array of the read-write operation event, a key-value pair set corresponding to the read-write operation event is generated. Then, based on the key-value pair set of the read-write operation event, a refresh operation corresponding to the event type of the read-write operation event can be performed on the cache data corresponding to the read-write operation event. Since the cache data can be refreshed through the real-time read-write operation log of the database, not only the cache refresh efficiency is improved, but also intrusion into user services is avoided.
[0100] Based on the above embodiments:
[0101] As an optional embodiment, the cache refresh method further includes:
[0102] In response to the cache reset instruction, blocking a refresh operation of the first thread;
[0103] After the cache is cleared, the data of each target database table in the database is written into the cache;
[0104] Unblocking the refresh operation of the first thread;
[0105] The first thread is a thread for executing a cache refresh operation, and the cache refresh operation refers to: based on the key-value pair set of the read / write operation event, executing a refresh operation corresponding to the event type of the read / write operation event on the cache data corresponding to the read / write operation event.
[0106] Specifically, considering that due to reasons such as a failure of the cache refresh mechanism, there may be a long-term data inconsistency problem between the database and the cache in the computer system, or before the cache refresh method in the previous embodiment is started, each target database table in the database itself has historical data, and these historical data cannot be written into the cache based on the cache refresh method in the previous embodiment. Therefore, in order to further improve the data consistency between the database and the cache, in an embodiment of the present invention, the refresh operation of the first thread can be blocked in response to a cache reset instruction. The blocking action can avoid a cache update timing conflict with the action of the first thread, resulting in inconsistency between the database and the cache data; and when blocking, the cache can be cleared, and the data of each target database table in the database can be written into the cache. The action of writing to the cache can write all the required field values of the target database table at that time into the cache, including the historical data mentioned above.
[0107] It is worth mentioning that, in the embodiment of the present invention, the required field names in the target database table can be determined for each target database table, so as to avoid writing unnecessary field names and field values in the target database table into the cache.
[0108] Specifically, after the cache is cleared and the data of each target database table in the database is written into the cache, the refresh operation of the first thread can be unblocked. After unblocking, the read and write operation logs in the database "during the period when the first thread was blocked" can be revisited so that the first thread can refresh the cache based on the read and write operation logs in the database "during the period when the first thread was blocked", thereby further improving the data consistency between the database and the cache.
[0109] As an optional embodiment, in response to the cache reset instruction, blocking the refresh operation of the first thread includes:
[0110] In response to the cache reset instruction, a semaphore of a first value is sent to the cache, so that the cache blocks a refresh operation of the first thread after recognizing the semaphore of the first value;
[0111] Unblocking the refresh operation of the first thread includes:
[0112] A semaphore with a second value is sent to the cache, so that the cache unblocks the refresh operation of the first thread after recognizing the semaphore with the second value.
[0113] Specifically, considering that the semaphore represented by a numerical value can reduce thread perception compared to distributed locks or other forms of thread blocking methods, thereby further improving the efficiency of cache refresh work, the embodiment of the present invention can perform blocking and unblocking operations on the first thread in the form of a semaphore represented by a numerical value.
[0114] The first value and the second value may be set independently, for example, the first value may be one of 1 and 0, and the second value may be the other of 1 and 0, etc., and the embodiment of the present invention is not limited here.
[0115] Of course, in addition to this blocking method, the first thread may be blocked and contact-blocked in other ways, which are not limited in the embodiment of the present invention.
[0116] As an optional embodiment, the cache reset instruction includes a first reset instruction and / or a second reset instruction;
[0117] The first reset instruction is: a reset instruction automatically generated at a preset time of the day;
[0118] The second reset instruction is: a reset instruction received through the human-machine interface.
[0119] Specifically, by triggering a reset through a reset instruction that is automatically generated at a preset time of the day, forced consistency operations between the database and the cache can be performed every day, so that the inconsistency problem between the database and the cache will not last for more than one day, and the reset instruction received through the human-computer interface can make the cache reset operation autonomous and flexible.
[0120] Of course, in addition to the above two generating methods, the cache reset instruction may also be generated in many other ways, which are not limited in the embodiment of the present invention.
[0121] As an optional embodiment, the cache and the database are both connected to the preset interface software, so that each application service retrieves data from the cache or the database through the preset interface software;
[0122] Among them, the preset interface software includes a software development kit.
[0123] Specifically, by providing a unified preset interface software for each application service, and the preset interface software can be connected to the database and cache, in this case, no matter which application service can use the preset interface software to search for target data from the database and cache. If no result is found, it means that the target data does not exist in the computer system, which can reduce the development burden of each application service.
[0124] Among them, the software development kit tool (SDK, Software Development Kit) has the advantage of being simple and easy to use. Of course, in addition to the SDK, the preset interface software can also be of other types, which is not limited in the embodiment of the present invention.
[0125] Specifically, the query logic can be set based on the preset interface software. For example, it can be set to first query the target data from the cache. If the target data cannot be found, the cache can be penetrated to query the target data from the database.
[0126] To better illustrate the embodiments of the present invention, please refer to Figure 2 , Figure 2 This is a schematic diagram of the principle of a data query method provided by the present invention. Each application service can access the cache and the database through a preset interface software, and can read the cache or penetrate the cache to read the database.
[0127] As an optional embodiment, the cache refresh method further includes:
[0128] When the read request sent by the application service through the preset interface software hits the cache, the hit target cache data is written into the second message queue;
[0129] Determine whether there is database data corresponding to the target cache data in the database;
[0130] If it does not exist, delete the target cache data from the cache;
[0131] If so, determine whether the target cache data is consistent with the database data corresponding to the target cache data in the database;
[0132] If there is any inconsistency, the target cache data in the cache is updated based on the database data.
[0133] Specifically, in order to further ensure the consistency between the database and the cache data, considering that when the application service hits the cache through the preset interface software, it can perform a consistency check on the hit cache data, so as to refresh the cache in time, therefore, in an embodiment of the present invention, when the read request sent by the application service through the preset interface software hits the cache, the hit target cache data can be written into the second message queue, and then it is determined whether there is database data corresponding to the target cache data in the database. If not, the target cache data can be deleted from the cache. If so, it can be determined whether the target cache data is consistent with the database data corresponding to the target cache data in the database. If it is inconsistent, the target cache data in the cache can be updated based on the database data.
[0134] To better illustrate the embodiments of the present invention, please refer to Figure 3 , Figure 3 A schematic diagram of the principle of a cache error correction method provided by the present invention can write the hit target cache data into a second message queue after the application service hits the cache, and the cache error corrector (virtual module) can monitor the messages in the second message queue, read the database data corresponding to the target cache data in the database by reading the database, and then compare the cache data with the data in the database. In the case of inconsistency, the target cache data in the cache can be updated based on the database data.
[0135] As an optional embodiment, it is applied to any node in a computer system;
[0136] The cache refresh method also includes:
[0137] In response to a heartbeat signal generated at every preset period, a preset time is added to the expiration time of a service identifier corresponding to itself in a service identifier sequence, wherein the service identifier sequence includes service identifiers of a plurality of nodes arranged in order, and a service identifier whose expiration time is not greater than zero is in an invalid state;
[0138] For the read-write operation events in the real-time read-write operation log of the database, the characteristic information of the read-write operation events is determined, and the data of the read-write operation events is converted into a serialized array including:
[0139] Determine whether the service ID corresponding to itself is at the first place in the service ID sequence;
[0140] If it is in the first place, it determines itself as the primary copy, determines the characteristic information of the read and write operation events in the real-time read and write operation log of the database, and converts the data of the read and write operation events into a serialized array.
[0141] Specifically, in order to improve the high availability of the cache refresh mechanism, the cache refresh method in the embodiment of the present invention can be applied to any node in the computer system, and each node is provided with a program of the cache refresh method (that is, a copy), and then the master copy in each copy executes each step of the cache refresh method.
[0142] Specifically, each node can determine whether it belongs to the primary copy through a service identification sequence. The service identification sequence includes the service identifications of multiple nodes arranged in order. The service identification with an expiration time not greater than zero is in an invalid state. Each node can respond to the heartbeat signal generated at every preset period and increase the expiration time of the service identification corresponding to itself in the service identification sequence by a preset duration. In this case, when a node is unable to generate a heartbeat signal or respond to a heartbeat signal due to a fault, the service identification belonging to the faulty node in the service identification sequence will expire. As the service identification of the faulty node becomes invalid, the service identification after the service identification of the faulty node will advance one position, and the copy corresponding to the first service identification in the service identification sequence is identified as the primary copy. In this way, the primary copy in a healthy state can be determined simply and accurately.
[0143] Of course, in addition to the above methods, there are many other ways to determine the primary replica in a healthy state, which is not limited in the embodiment of the present invention.
[0144] To better illustrate the embodiments of the present invention, please refer to Figure 4 , Figure 4 A schematic diagram of the principle of a method for determining a primary copy provided by the present invention, wherein the first to third copies are all connected to a service identification sequence, and their own service identification can be extended according to a heartbeat signal.
[0145] As an optional embodiment, for a read / write operation event in a real-time read / write operation log of a database, determining characteristic information of the read / write operation event and converting data of the read / write operation event into a serialized array includes:
[0146] As a slave node of the database, request the real-time read and write operation logs of the database;
[0147] Determine the event type of the read / write operation event through the data of the read / write operation event in the read / write operation log;
[0148] Determine the table name of the database table to which the read / write operation event belongs through the table mapping event located before the read / write operation event in the read / write operation log;
[0149] Convert the data of read and write operation events into serialized arrays;
[0150] Among them, the event types of read and write operation events include delete events, insert events, and update events.
[0151] Specifically, considering that the slave node of the database can smoothly query the read-write operation log from the database, the computer system in the embodiment of the present invention can request the real-time read-write operation log in the database as the slave node of the database, and then determine the event type of the read-write operation event through the data of the read-write operation event in the read-write operation log, and determine the table name of the database table to which the read-write operation event belongs through the table mapping event located before the read-write operation event in the read-write operation log, and finally convert the data of the read-write operation event into a serialized array.
[0152] Specifically, taking the computer system as a cloud computing platform, the database as a MySQL (relational database management system) database, and the cache as a Redis (Remote Dictionary Server) cache as an example, the thread in the computer system can disguise itself as a slave node of the MySQL database, start the I / O (Input / Output) thread, and initiate a dump request to the MySQL master node. The master node starts the binlog dump (logical log dump) thread and pushes the Binlog (logical log) log (which contains read and write operation logs) to the above I / O thread. In this way, based on the MySQL master-slave protocol, the changes in the master node's Binlog log can be monitored in real time.
[0153] Of course, in addition to the above specific forms, the computer system, database and cache may also be of other types, which are not limited in the embodiments of the present invention.
[0154] As an optional embodiment, based on the key-value pair set of the read-write operation event, performing a refresh operation corresponding to the event type of the read-write operation event on the cache data corresponding to the read-write operation event includes:
[0155] If the event type of the read / write operation event is a delete event, the cache data corresponding to the read / write operation event is deleted;
[0156] If the event type of the read / write operation event is an insert event, the key-value pair set and primary key information of the read / write operation event are written into the cache as cache data;
[0157] If the event type of the read / write operation event is an update event, the key-value pair set and primary key information of the read / write operation event are overwritten to the cache data corresponding to the read / write operation event in the cache;
[0158] When the write cache operation corresponding to the write event fails, the primary key information of the write event that failed to write cache is added to the first message queue so that the asynchronous thread deletes the cache data corresponding to the primary key information in the first message queue in the cache, where the write event includes an insert event and an update event.
[0159] Specifically, the first half of the embodiment of the present invention introduces the specific process of "based on the key-value pair set of read and write operation events, performing a refresh operation corresponding to the event type of the read and write operation events on the cache data corresponding to the read and write operation events". The last paragraph introduces the processing method for "write cache operation failure": in order to avoid the cache data associated with the write event in the first message queue being overwritten during the retry period, thereby causing cache data errors, in the embodiment of the present invention, the "primary key information of the cache failed write event" can be added to the first message queue, and the cache data corresponding to the primary key information in the first message queue in the cache can be deleted through an asynchronous thread, thereby further improving the data consistency between the database and the cache.
[0160] To better illustrate the embodiments of the present invention, please refer to Figure 5 , Figure 5 A flow chart of another cache refresh method provided by the present invention, wherein the monitoring parser can monitor and parse the read and write operation logs in the database (that is, the process of obtaining feature information and serialized arrays), the master copy can refresh the cache through a single thread, and write the write cache failure event into the second message queue, and for the write cache failure event in the second message queue, the cache data corresponding to the write cache failure event can be deleted.
[0161] As an optional embodiment, if the database table to which the read / write operation event belongs belongs to a pre-specified target database table, generating a key-value pair set corresponding to the read / write operation event according to the serialized array of the read / write operation event and the table structure information of the target database table includes:
[0162] If the database table to which the read / write operation event belongs belongs to a pre-specified target database table, a field name sequence is determined from the table structure information of the target database table to which the read / write operation event belongs, wherein the field name sequence includes a plurality of field names arranged in order, the field names are field names in the target database table to which the read / write operation event belongs, and the order of the field names in the field name sequence is equal to the order of the field names in the respective field names of the target database table to which the read / write operation event belongs;
[0163] If the read / write operation event is a delete event, a first key-value pair set corresponding to the delete event is generated according to the serialized data and field name sequence corresponding to the delete event, wherein the serialized data corresponding to the delete event is a row of data in the database table deleted by the delete event, and the first key-value pair set includes multiple key-value pairs, each of which includes a single field value deleted by the delete event and its corresponding field name;
[0164] If the read / write operation event is an insert event, a second key-value pair set corresponding to the insert event is generated according to the serialized data and field name sequence corresponding to the insert event, wherein the serialized data corresponding to the insert event is a row of data inserted into the database table by the insert event, and the second key-value pair set includes multiple key-value pairs, each key-value pair includes a single field value inserted by the insert event and its corresponding field name;
[0165] If the read-write operation event is an update event, a third key-value pair set and a fourth key-value pair set corresponding to the update event are generated according to the serialized data and field name sequence corresponding to the update event, wherein the serialized data corresponding to the update event is the target row data updated by the update event in the database table, and the third key-value pair set and the fourth key-value pair set both include multiple key-value pairs, and any key-value pair in the third key-value pair set includes: a single field value and its corresponding field name before the target row data is updated, and any key-value pair in the fourth key-value pair set includes: a single field value and its corresponding field name after the target row data is updated.
[0166] Specifically, taking into account the differences in data of different types of read and write operation events, an embodiment of the present invention introduces a process for generating key-value pair sets of several different read and write operation events. The main difference is that the data of a deletion event includes the field values of the row data before the deletion event, the data of an insert event includes the field values of the row data after the insert event, and the data of an update event includes two sets of field values of the row data before and after the update event. Therefore, after determining the field name sequence of the database table to which the event belongs, the embodiment of the present invention can construct different key-value pair sets for the event data based on the field name sequence according to different event types.
[0167] As an optional embodiment, if the database table to which the read / write operation event belongs belongs to a pre-specified target database table, after generating a key-value pair set corresponding to the read / write operation event according to the serialized array of the read / write operation event and the table structure information of the target database table, the cache refresh method further includes:
[0168] Based on the characteristic information of the read and write operation events and the key-value pair set corresponding to the read and write operation events, a storage object with a preset structure is constructed;
[0169] The storage object includes a first storage location and a second storage location, the first storage location is used to store feature information, the second storage location includes a pre-storage data storage location and a post-storage data storage location, the pre-storage data storage location is used to store a key-value pair set corresponding to data before a read / write operation event occurs, and the post-storage data storage location is used to store a key-value pair set corresponding to data after a read / write operation event occurs;
[0170] According to the primary key information of the read / write operation event in the corresponding database table, the cache data corresponding to the read / write operation event in the cache is determined to include:
[0171] The cache data corresponding to the read / write operation event and located in the cache is determined according to the primary key information in the database table corresponding to the table name in the first storage position in the storage object.
[0172] Specifically, in order to make the key-value pair sequence of read and write operation events of each event type have a unified storage architecture, in an embodiment of the present invention, a storage object with a preset structure can be constructed based on the characteristic information of the read and write operation events and the key-value pair set corresponding to the read and write operation events. The storage object includes a first storage location and a second storage location. The first storage location is used to store the characteristic information. The second storage location includes a front data storage location and a rear data storage location. The front data storage location is used to store the key-value pair set corresponding to the data before the read and write operation event occurs, and the rear data storage location is used to store the key-value pair set corresponding to the data after the read and write operation event occurs. That is to say, for deletion events, the key-value pair sequence is stored in the front data storage location, for insertion events, the key-value pair sequence is stored in the rear data storage location, and for update events, the front data storage location is used to store the key-value pair set corresponding to the data before the read and write operation event occurs, and the rear data storage location is used to store the key-value pair set corresponding to the data after the read and write operation event occurs.
[0173] In addition, according to the primary key information of the read / write operation event in the corresponding database table, determining the cache data corresponding to the read / write operation event in the cache may include:
[0174] Get the characteristic information and serialized data in the storage object, then determine the database table corresponding to the table name, and then determine the field name of the primary key in the database table corresponding to the table name, and use the first field value in the serialized data of the storage object as the field value of the primary key, so as to obtain the primary key information, thereby determining which row of which database table the read and write operation event belongs to, so that the cached data in the cache can be determined through the primary key information.
[0175] To better illustrate the embodiments of the present invention, please refer to Figure 6 , Figure 6A schematic diagram of a flow chart of another cache refresh method provided by the present invention, Figure 6 Reason Figures 2 to 5 A global diagram of the combined cache refresh method, so you can refer to Figures 2 to 5 The embodiments of the present invention will not be described in detail here.
[0176] Please refer to Figure 7 , Figure 7 A schematic diagram of the structure of a cache refresh device provided by the present invention, the cache refresh device comprises:
[0177] The first determination module 71 is used to determine characteristic information of the read / write operation event in the real-time read / write operation log of the database, and convert the data of the read / write operation event into a serialized array, wherein the characteristic information includes the table name of the corresponding database table and the event type;
[0178] The first generating module 72 is used to generate a key-value pair set corresponding to the read-write operation event according to the serialized array of the read-write operation event and the table structure information of the target database table if the database table to which the read-write operation event belongs belongs to a pre-specified target database table, wherein the key-value pair set includes multiple key-value pairs, and any key-value pair includes: a single field value in the read-write operation event and its corresponding field name;
[0179] A second determination module 73, configured to determine cache data corresponding to the read / write operation event in the cache according to primary key information of the read / write operation event in the corresponding database table;
[0180] The first refresh module 74 is used to perform a refresh operation corresponding to the event type of the read / write operation event on the cache data corresponding to the read / write operation event based on the key-value pair set of the read / write operation event.
[0181] As an optional embodiment, the cache refresh device further includes:
[0182] A first blocking module, configured to block a refresh operation of the first thread in response to a cache reset instruction;
[0183] The first action module is used to write the data of each target database table in the database into the cache after the cache is cleared;
[0184] A second blocking module, used to unblock the refresh operation of the first thread;
[0185] The first thread is a thread for executing a cache refresh operation, and the cache refresh operation refers to: based on the key-value pair set of the read / write operation event, executing a refresh operation corresponding to the event type of the read / write operation event on the cache data corresponding to the read / write operation event.
[0186] As an optional embodiment, the first blocking module is specifically used for:
[0187] In response to the cache reset instruction, a semaphore of a first value is sent to the cache, so that the cache blocks a refresh operation of the first thread after recognizing the semaphore of the first value;
[0188] The second blocking module is specifically used for:
[0189] A semaphore with a second value is sent to the cache, so that the cache unblocks the refresh operation of the first thread after recognizing the semaphore with the second value.
[0190] As an optional embodiment, the cache reset instruction includes a first reset instruction and / or a second reset instruction;
[0191] The first reset instruction is: a reset instruction automatically generated at a preset time of the day;
[0192] The second reset instruction is: a reset instruction received through the human-machine interface.
[0193] As an optional embodiment, the cache and the database are both connected to the preset interface software, so that each application service retrieves data from the cache or the database through the preset interface software;
[0194] Among them, the preset interface software includes a software development kit.
[0195] As an optional embodiment, the cache refresh device further includes:
[0196] The second action module is used to write the hit target cache data into the second message queue when the read request sent by the application service through the preset interface software hits the cache;
[0197] A first judgment module is used to judge whether there is database data corresponding to the target cache data in the database, and if not, trigger the first deletion module; if so, trigger the second judgment module;
[0198] A first deleting module, used to delete target cache data from the cache;
[0199] A second judgment module is used to judge whether the target cache data is consistent with the database data corresponding to the target cache data in the database, and if they are inconsistent, trigger a third action module;
[0200] The third action module is used to update the target cache data in the cache based on the database data.
[0201] As an optional embodiment, the cache refresh device is applied to any node in the computer system;
[0202] The cache refresh device also includes:
[0203] A fourth action module is used to respond to the heartbeat signal generated at every preset period and increase the preset time for the expiration time of the service identification corresponding to itself in the service identification sequence, wherein the service identification sequence includes the service identifications of multiple nodes arranged in order, and the service identification whose expiration time is not greater than zero is in an invalid state;
[0204] The first determination module 71 includes:
[0205] A third judgment module is used to judge whether the service identification corresponding to itself is in the first place in the service identification sequence, and if it is in the first place, triggering a fifth action module;
[0206] The fifth action module is used to determine that it is the primary copy, determine the characteristic information of the read and write operation events in the real-time read and write operation log of the database, and convert the data of the read and write operation events into a serialized array.
[0207] As an optional embodiment, the first determining module 71 includes:
[0208] The sixth action module is used to request the real-time read and write operation logs in the database as a slave node of the database;
[0209] A third determination module is used to determine the event type of the read-write operation event through the data of the read-write operation event in the read-write operation log;
[0210] A fourth determination module, configured to determine the table name of the database table to which the read / write operation event belongs through a table mapping event located before the read / write operation event in the read / write operation log;
[0211] The conversion module is used to convert the data of the read and write operation events into a serialized array;
[0212] Among them, the event types of read and write operation events include delete events, insert events, and update events.
[0213] As an optional embodiment, the first refreshing module 74 includes:
[0214] A first refresh submodule, configured to delete cache data corresponding to the read / write operation event if the event type of the read / write operation event is a delete event;
[0215] A second refresh submodule is used to write the key-value pair set and primary key information of the read-write operation event into the cache as cache data if the event type of the read-write operation event is an insert event;
[0216] A third refresh submodule is used to overwrite the cache data corresponding to the read / write operation event in the cache with the key-value pair set and primary key information of the read / write operation event if the event type of the read / write operation event is an update event;
[0217] The seventh action module is used to add the primary key information of the write event that failed to write cache to the first message queue when the write cache operation corresponding to the write event fails, so that the asynchronous thread deletes the cache data corresponding to the primary key information in the first message queue in the cache, wherein the write event includes an insert event and an update event.
[0218] As an optional embodiment, the first generating module 72 includes:
[0219] The first generating submodule is used to determine a field name sequence from the table structure information of the target database table to which the read / write operation event belongs if the database table to which the read / write operation event belongs belongs to a pre-specified target database table, wherein the field name sequence includes a plurality of field names arranged in order, the field names are field names in the target database table to which the read / write operation event belongs, and the order of the field names in the field name sequence is equal to the order of the field names in the respective field names in the target database table to which the read / write operation event belongs;
[0220] The second generating submodule is used for generating a first key-value pair set corresponding to the deletion event according to the serialized data and field name sequence corresponding to the deletion event if the read-write operation event is a deletion event, wherein the serialized data corresponding to the deletion event is a row of data in the database table deleted by the deletion event, and the first key-value pair set includes a plurality of key-value pairs, each key-value pair including a single field value deleted by the deletion event and its corresponding field name;
[0221] The third generating submodule is used to generate a second key-value pair set corresponding to the insert event according to the serialized data and field name sequence corresponding to the insert event if the read-write operation event is an insert event, wherein the serialized data corresponding to the insert event is a row of data inserted into the database table by the insert event, and the second key-value pair set includes multiple key-value pairs, each key-value pair includes a single field value inserted by the insert event and its corresponding field name;
[0222] The fourth generating submodule is used to generate a third key-value pair set and a fourth key-value pair set corresponding to the update event if the read-write operation event is an update event, according to the serialized data and field name sequence corresponding to the update event, wherein the serialized data corresponding to the update event is the target row data updated by the update event in the database table, and the third key-value pair set and the fourth key-value pair set both include multiple key-value pairs, and any key-value pair in the third key-value pair set includes: a single field value and its corresponding field name before the target row data is updated, and any key-value pair in the fourth key-value pair set includes: a single field value and its corresponding field name after the target row data is updated.
[0223] As an optional embodiment, the cache refresh device further includes:
[0224] An eighth action module, configured to construct a storage object having a preset structure based on characteristic information of the read / write operation event and a key-value pair set corresponding to the read / write operation event;
[0225] The storage object includes a first storage location and a second storage location, the first storage location is used to store feature information, the second storage location includes a pre-storage data storage location and a post-storage data storage location, the pre-storage data storage location is used to store a key-value pair set corresponding to data before a read / write operation event occurs, and the post-storage data storage location is used to store a key-value pair set corresponding to data after a read / write operation event occurs;
[0226] The second determining module 73 is specifically used for:
[0227] The cache data corresponding to the read / write operation event and located in the cache is determined according to the primary key information in the database table corresponding to the table name in the first storage position in the storage object.
[0228] For an introduction to the cache refresh device provided in the embodiment of the present invention, please refer to the aforementioned embodiment of the cache refresh method, and the embodiment of the present invention will not be described in detail here.
[0229] Please refer to Figure 8 , Figure 8 A schematic diagram of the structure of a cache refresh device provided by the present invention, the cache refresh device comprising:
[0230] A memory 81, used for storing computer programs;
[0231] The processor 82 is used to implement the steps of the cache refresh method in the above-mentioned embodiment when executing the computer program.
[0232] For an introduction to the cache refresh device provided in the embodiment of the present invention, please refer to the aforementioned embodiment of the cache refresh method, and the embodiment of the present invention will not be described in detail here.
[0233] The present invention also provides a computer program product, including a computer program / instruction, which implements the steps of the cache refresh method in the above-mentioned embodiment when executed by a processor.
[0234] For an introduction to the computer program product provided by the embodiment of the present invention, please refer to the aforementioned embodiment of the cache refresh method, and the embodiment of the present invention will not be described in detail here.
[0235] Please refer to Fig. 9 , Fig. 9 This is a schematic diagram of the structure of a computer-readable storage medium provided by the present invention. A computer program 92 is stored on the computer-readable storage medium 91. When the computer program 92 is executed by a processor, the steps of the cache refresh method in the aforementioned embodiment are implemented.
[0236] For an introduction to the computer-readable storage medium provided in an embodiment of the present invention, please refer to the aforementioned embodiment of the cache refresh method, and the embodiment of the present invention will not be described in detail here.
[0237] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same and similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should also be noted that in this specification, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the term "include", "comprise" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such process, method, article or equipment. In the absence of more restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or equipment including the element.
[0238] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A cache refresh method, characterized in that: Applied to computer systems, including: For the read / write operation events in the real-time read / write operation log of the database, characteristic information of the read / write operation events is determined, and data of the read / write operation events is converted into a serialized array, wherein the characteristic information includes the table name of the corresponding database table and the event type; If the database table to which the read / write operation event belongs belongs to a pre-specified target database table, a key-value pair set corresponding to the read / write operation event is generated according to the serialized array of the read / write operation event and the table structure information of the target database table, wherein the key-value pair set includes a plurality of key-value pairs, and any of the key-value pairs includes: a single field value in the read / write operation event and its corresponding field name; Determine cache data corresponding to the read / write operation event in the cache according to primary key information of the read / write operation event in the corresponding database table; Based on the key-value pair set of the read-write operation event, a refresh operation corresponding to the event type of the read-write operation event is performed on the cache data corresponding to the read-write operation event.
2. The cache refresh method according to claim 1, characterized in that: The cache refresh method further includes: In response to the cache reset instruction, blocking a refresh operation of the first thread; After the cache is cleared, the data of each target database table in the database is written into the cache; Unblocking the refresh operation of the first thread; Among them, the first thread is a thread that executes a cache refresh operation, and the cache refresh operation refers to: based on the key-value pair set of the read and write operation events, performing a refresh operation corresponding to the event type of the read and write operation event on the cache data corresponding to the read and write operation event.
3. The cache refresh method according to claim 2, characterized in that: In response to the cache reset instruction, blocking the refresh operation of the first thread includes: In response to the cache reset instruction, a semaphore of a first value is sent to the cache, so that the cache blocks a refresh operation of the first thread after recognizing the semaphore of the first value; Unblocking the refresh operation of the first thread includes: A semaphore with a second value is sent to the cache, so that the cache unblocks the refresh operation of the first thread after recognizing the semaphore with the second value.
4. The cache refresh method according to claim 2, characterized in that: The cache reset instruction includes a first reset instruction and / or a second reset instruction; The first reset instruction is: a reset instruction automatically generated at a preset time of the day; The second reset instruction is: a reset instruction received through a human-machine interface.
5. The cache refresh method according to claim 1, characterized in that: The cache and the database are both connected to the preset interface software, so that each application service can retrieve data from the cache or the database through the preset interface software; Wherein, the preset interface software includes a software development kit.
6. The cache refresh method according to claim 5, characterized in that: The cache refresh method further includes: When the read request sent by the application service through the preset interface software hits the cache, the hit target cache data is written into the second message queue; Determine whether there is database data corresponding to the target cache data in the database; If not, deleting the target cache data from the cache; If so, determining whether the target cache data is consistent with the database data in the database corresponding to the target cache data; If they are inconsistent, the target cache data in the cache is updated based on the database data.
7. The cache refresh method according to claim 1, characterized in that: Applied to any node in a computer system; The cache refresh method further includes: In response to a heartbeat signal generated at every preset period, a preset time is added to the expiration time of a service identifier corresponding to itself in a service identifier sequence, wherein the service identifier sequence includes service identifiers of a plurality of nodes arranged in order, and the service identifier whose expiration time is not greater than zero is in an invalid state; For a read / write operation event in a real-time read / write operation log of a database, determining characteristic information of the read / write operation event, and converting data of the read / write operation event into a serialized array includes: Determine whether the service identifier corresponding to itself is at the first position in the service identifier sequence; If it is in the first place, it determines itself as the primary copy, determines the characteristic information of the read and write operation events in the real-time read and write operation log of the database, and converts the data of the read and write operation events into a serialized array.
8. The cache refresh method according to claim 1, characterized in that: For a read / write operation event in a real-time read / write operation log of a database, determining characteristic information of the read / write operation event, and converting data of the read / write operation event into a serialized array includes: As a slave node of the database, request the real-time read and write operation logs in the database; Determining the event type of the read-write operation event through the data of the read-write operation event in the read-write operation log; Determine the table name of the database table to which the read / write operation event belongs through a table mapping event located before the read / write operation event in the read / write operation log; Convert the data of the read and write operation events into a serialized array; The event types of the read and write operation events include delete events, insert events and update events.
9. The cache refresh method according to claim 1, characterized in that: Based on the key-value pair set of the read-write operation event, performing a refresh operation corresponding to the event type of the read-write operation event on the cache data corresponding to the read-write operation event includes: If the event type of the read / write operation event is a delete event, deleting the cache data corresponding to the read / write operation event; If the event type of the read / write operation event is an insert event, the key-value pair set of the read / write operation event and the primary key information are written into the cache as cache data; If the event type of the read / write operation event is an update event, overwriting the key-value pair set of the read / write operation event and the primary key information to the cache data corresponding to the read / write operation event in the cache; When the write cache operation corresponding to a write event fails, the primary key information of the write event that failed to write cache is added to the first message queue so that the asynchronous thread deletes the cache data corresponding to the primary key information in the first message queue in the cache, wherein the write event includes an insert event and an update event.
10. The cache refresh method according to any one of claims 1 to 9, characterized in that: If the database table to which the read / write operation event belongs belongs to a pre-specified target database table, generating a key-value pair set corresponding to the read / write operation event according to the serialized array of the read / write operation event and the table structure information of the target database table includes: If the database table to which the read / write operation event belongs belongs to a pre-specified target database table, a field name sequence is determined from the table structure information of the target database table to which the read / write operation event belongs, wherein the field name sequence includes a plurality of field names arranged in order, the field names are field names in the target database table to which the read / write operation event belongs, and the order of the field names in the field name sequence is equal to the order of the field names in the respective field names of the target database table to which the read / write operation event belongs; If the read-write operation event is a delete event, a first key-value pair set corresponding to the delete event is generated according to the serialized data corresponding to the delete event and the field name sequence, wherein the serialized data corresponding to the delete event is a row of data in the database table deleted by the delete event, and the first key-value pair set includes multiple key-value pairs, each key-value pair includes a single field value deleted by the delete event and its corresponding field name; If the read / write operation event is an insert event, a second key-value pair set corresponding to the insert event is generated according to the serialized data corresponding to the insert event and the field name sequence, wherein the serialized data corresponding to the insert event is a row of data inserted into the database table by the insert event, and the second key-value pair set includes multiple key-value pairs, each key-value pair includes a single field value inserted by the insert event and its corresponding field name; If the read-write operation event is an update event, a third key-value pair set and a fourth key-value pair set corresponding to the update event are generated according to the serialized data corresponding to the update event and the field name sequence, wherein the serialized data corresponding to the update event is the target row data updated by the update event in the database table, and the third key-value pair set and the fourth key-value pair set both include multiple key-value pairs, and any key-value pair in the third key-value pair set includes: a single field value and its corresponding field name before the target row data is updated, and any key-value pair in the fourth key-value pair set includes: a single field value and its corresponding field name after the target row data is updated.
11. The cache refresh method according to claim 10, characterized in that: If the database table to which the read / write operation event belongs belongs to a pre-specified target database table, after generating a key-value pair set corresponding to the read / write operation event according to the serialized array of the read / write operation event and the table structure information of the target database table, the cache refresh method further includes: Based on the characteristic information of the read / write operation event and the key-value pair set corresponding to the read / write operation event, construct a storage object with a preset structure; The storage object includes a first storage location and a second storage location, the first storage location is used to store the feature information, the second storage location includes a pre-storage data storage location and a post-storage data storage location, the pre-storage data storage location is used to store a key-value pair set corresponding to data before a read / write operation event occurs, and the post-storage data storage location is used to store a key-value pair set corresponding to data after a read / write operation event occurs; Determining cache data corresponding to the read / write operation event in the cache according to primary key information of the read / write operation event in the corresponding database table includes: The cache data corresponding to the read / write operation event and located in the cache is determined according to the primary key information in the database table corresponding to the table name in the first storage position in the storage object.
12. A cache refresh device, characterized in that: include: A first determination module is used to determine characteristic information of the read / write operation event in the real-time read / write operation log of the database, and convert the data of the read / write operation event into a serialized array, wherein the characteristic information includes the table name of the database table and the event type; A first generating module is used to generate a key-value pair set corresponding to the read-write operation event according to the serialized array of the read-write operation event and the table structure information of the target database table if the database table to which the read-write operation event belongs belongs to a pre-specified target database table, wherein the key-value pair set includes a plurality of key-value pairs, and any of the key-value pairs includes: a single field value in the read-write operation event and its corresponding field name; A second determination module, configured to determine cache data corresponding to the read / write operation event in the cache according to primary key information of the read / write operation event in the corresponding database table; The first refresh module is used to perform a refresh operation corresponding to the event type of the read / write operation event on the cache data corresponding to the read / write operation event based on the key-value pair set of the read / write operation event.
13. A cache refresh device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the cache refresh method according to any one of claims 1 to 11 when executing the computer program.
14. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the steps of the cache refresh method according to any one of claims 1 to 11 are implemented.
15. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the cache refresh method according to any one of claims 1 to 11 are implemented.
