Cache updating method and system, electronic equipment and computer readable medium
By using messages middleware and distributed locking technologies in the SaaS platform, data consistency updates of source databases, intermediate layer caches and application servers are achieved, solving the problems of database performance pressure and inconsistency, and improving service stability and quality .
Patent Information
- Application Number
- CN202411029235.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-11-15
AI Technical Summary
In the SaaS platform, when multiple customers request services, the database performance pressure is high, resulting in service stability being affected, and the intermediate layer cache update is not timely, resulting in inconsistent customer information, affecting service quality.
By publishing update event messages on the message middleware, the local cache and intermediate layer cache are driven to update data, ensuring data consistency between the source database, intermediate layer cache and application server, and using distributed locking and timing task mechanisms to achieve data timely updates.
It effectively avoids business support errors caused by inconsistent customer information and untimely updates, improves service stability and quality, and reduces database load.
Smart Images

Figure CN118964423A_ABST
Abstract
Description
Background Art
[0002] SaaS (Software as a Service) can include software product services for individuals and enterprises, in which case the software product is the carrier for providing software functional services. The SaaS platform can provide software services to clients through API (Application Programming Interface), browser web pages, service subscriptions, etc., while the SaaS platform needs to support business access from a large number of different customers, thus requiring the deployment of a large service cluster. Due to differences in the access scenarios, call volumes, service content, response time requirements, etc. of different customers, different customers can be routed to the corresponding server cluster in a hierarchical manner to provide services. When providing software services to customers, it is usually necessary to load the corresponding customer information from the database to the local application server. When multiple customers request services and a large-scale server cluster is started or restarted, if the loading speed is fast, it will cause great performance pressure on the database, and even a chain reaction may occur due to the sharing of database resources, affecting the stability of the overall service provided to customers; if the loading speed is slow, it will seriously slow down the business support speed, thereby increasing the labor cost of publishing.
[0003] At present, in order to ensure business stability while improving startup speed, you can create a middle-tier cache and write the required customer information into the middle-tier cache in one load, so that subsequent loads can be directly retrieved from the middle-tier cache without accessing the back-end database, thereby reducing the performance pressure of the database. However, this solution is only applicable to scenarios where data consistency requirements are not high. In actual applications, inconsistent customer information may occur, and untimely updates may cause business support errors or failures, affecting service quality. Summary of the invention
[0004] The purpose of the present disclosure is to provide a cache update method, a cache update system, an electronic device and a computer-readable medium. The method can cache the source data in the middle-layer cache and provide source data query services to multiple application servers before the source database, thereby maintaining the data consistency of the source database, the middle-layer cache and the application server, avoiding inconsistent customer information and untimely updates that cause business support errors or failures, maintaining service stability and improving service quality.
[0005] According to a first aspect of the present disclosure, a cache update method is provided, which can be applied to multiple application servers, and the method includes: pulling an update event message published by a source database to a message middleware, the update event message indicating an update operation on at least one source data in the source database; performing an update operation on the corresponding source data in a local cache based on the update event message, and performing an update operation on the corresponding source data in an intermediate-layer cache; the intermediate-layer cache is used to cache the source data of the source database, and provide the source data to multiple application servers before the source database.
[0006] Optionally, any one of the multiple application servers is the first application server, and the others are second application servers, and the steps for creating the middle-tier cache are as follows: the first application server starts to start up and requests source data from the middle-tier cache; if the first application server fails to request source data from the middle-tier cache, the first application server obtains source data from the source database; the first application server writes the source data to the local cache to complete the startup, and writes the source data to the middle-tier cache; the second application server obtains the source data from the middle-tier cache, and writes the source data to the local cache to complete the startup.
[0007] Optionally, the steps for creating the middle-tier cache are as follows: multiple application servers start to start up and request source data from the middle-tier cache; when multiple application servers fail to request source data from the middle-tier cache, they compete for distributed locks; the third application server that successfully competes for the distributed lock obtains source data from the source database; the third application server writes the source data to the local cache to complete the startup, writes the source data to the middle-tier cache, and releases the distributed lock; the fourth application server that fails to compete for the distributed lock waits for a first time period before obtaining the source data from the middle-tier cache, and writes the source data to the local cache to complete the startup; the first preset time period is greater than the startup time of the application server.
[0008] Optionally, pulling the update event message published by the origin database to the message middleware includes: after each application server completes startup, executing a message timing processing task, and when each cycle of the message timing task processing task expires, pulling at least one update event message published by the origin database to the message middleware within a second preset time period.
[0009] Optionally, an update operation is performed on the corresponding source data in the middle-layer cache, including: multiple application servers compete for the distributed lock; the fifth application server that successfully competes for the distributed lock performs an update operation on the corresponding source data in the middle-layer cache and releases the distributed lock to determine that the processing of the update event message is completed; the sixth application server that fails to compete for the distributed lock determines that the processing of the update event message is completed.
[0010] Optionally, the second preset time period is greater than the duration of each cycle of the message timing processing task.
[0011] Optionally, the middle-tier cache is built on a Redis database.
[0012] According to a second aspect of the present disclosure, a cache update system is provided, which may include multiple application servers, source databases, middle-tier caches and message middleware, each application server including: a message pulling module, used to pull update event messages published by the source database to the message middleware, the update event message indicating an update operation on at least one source data in the source database; a message processing module, used to perform an update operation on the corresponding source data in the local cache based on the update event message, and to perform an update operation on the corresponding source data in the middle-tier cache; the middle-tier cache is used to cache the source data of the source database, and provide the source data to the application server before the source database.
[0013] Optionally, the application server further includes a data request module and a data writing module, any one of the multiple application servers is a first application server, and the others are second application servers;
[0014] The data request module of the first application server is used to request source data from the middle-tier cache when the first application server starts to start; the data request module of the first application server is also used to obtain source data from the source database when the source data request from the middle-tier cache fails; the data writing module of the first application server is used to write the source data into the local cache to complete the startup, and write the source data into the middle-tier cache;
[0015] The data request module of the second application server is used to obtain source data from the middle-tier cache, and the data writing module is used to write the source data into the local cache to complete the startup.
[0016] Optionally, the application server further includes a data request module and a data writing module, wherein the data request modules of the multiple application servers are used to request source data from the middle-layer cache when the application server starts; the data request modules of the multiple application servers are used to compete for distributed locks when the source data request from the middle-layer cache fails;
[0017] The data request module of the third application server is also used to obtain source data from the source data when the competition for the distributed lock is successful; the data writing module of the third application server is used to write the source data into the local cache to complete the startup, write the source data into the middle-layer cache, and release the distributed lock;
[0018] The data request module of the fourth application server is also used to obtain source data from the middle layer cache after waiting for a first time period in the event of a failure in competing for a distributed lock, and the data writing module is used to write the source data to the local cache to complete the startup; the first preset time period is greater than the startup time of the application server.
[0019] Optionally, the message pulling module of multiple application servers is specifically used to execute the message timing processing task after each application server completes the startup, and when each cycle of the message timing task processing task expires, pull at least one update event message published by the source database to the message middleware within a second preset time period.
[0020] Optionally, the message processing modules of the multiple application servers are also used for the multiple application servers to compete for the distributed lock;
[0021] A message processing module of the fifth application server is used to perform an update operation on the corresponding source data in the middle-layer cache and release the distributed lock when the competition for the distributed lock succeeds, so as to determine that the processing of the update event message is completed;
[0022] The message processing module of the sixth application server is used to determine that the processing of the update event message is completed when the competition for the distributed lock fails.
[0023] Optionally, the second preset time period is greater than the duration of each cycle of the message timing processing task.
[0024] Optionally, the middle-tier cache is built on a Redis database.
[0025] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0026] Processor; and
[0027] a memory for storing a computer program for the processor;
[0028] The processor is configured to implement the cache update method of the first aspect by executing a computer program.
[0029] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the cache update method of the first aspect is implemented.
[0030] According to a fifth aspect of the present disclosure, a computer program product is provided. When the computer program product is run on an electronic device, the electronic device implements the cache update method of the first aspect when executing the computer program product.
[0031] The cache update method provided by the present disclosure is applied to multiple application servers, each application server can pull the update event message published by the source data to the message middleware, and the update event message can indicate the update operation of at least one source data in the source data; based on the obtained update event message, the application server can perform an update operation on the corresponding source data in the local cache, and also perform an update operation on the source data corresponding to the middle-layer cache, so as to maintain consistency between the source database, the middle-layer cache and multiple application servers; wherein the middle-layer cache can cache the source data of the source database, and can provide the source data to multiple application servers before the source database, so as to share and reduce the business pressure of the source database. The method is based on event message drive, and can timely update the data of the source database, the middle-layer cache and the application server, avoid inconsistent customer information, untimely updates causing business support errors or failures, maintain service stability, and improve service quality.
[0032] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0034] Figure 1 This is one of the step flow charts of the cache update method provided in the embodiment of the present disclosure.
[0035] Figure 2 One of the flow charts for creating the middle-tier cache provided in the embodiments of the present disclosure.
[0036] Figure 3 The second flowchart of creating the middle-layer cache provided in the embodiment of the present disclosure.
[0037] Figure 4 This is the second step flow chart of the cache update method improved in the embodiment of the present disclosure.
[0038] Figure 5 A structural block diagram of a cache update system provided in an embodiment of the present disclosure.
[0039] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0040] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.
[0041] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the figures represent the same or similar parts, and their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0042] It should be noted that the data obtained in this disclosure are accessed, collected, stored and used for subsequent analysis and processing with the consent and authorization of the users or the parties to whom the relevant data belong, after the users or the parties to whom the relevant data belong are clearly informed of the data collection content, data purpose, processing method and other information. The users or the parties to whom the relevant data belong may be sent the ways to access, correct and delete the data, as well as the methods to revoke consent and authorization.
[0043] Figure 1 This is one of the step flow charts of the cache update method provided in the embodiment of the present disclosure. The method can be applied to multiple application servers. The step flow of the method can be shown as follows: Step 101 to Step 102:
[0044] Step 101: Pull the update event message published by the source database to the message middleware, where the update event message indicates an update operation on at least one source data in the source database.
[0045] Step 102: based on the update event message, perform an update operation on the corresponding source data in the local cache, and perform an update operation on the corresponding source data in the middle-tier cache; the middle-tier cache is used to cache the source data of the source database, and provide the source data to multiple application servers before the source database.
[0046] In the disclosed embodiment, the application server can start in response to a business request, load the source data required for the business from the middle-tier cache, and provide services based on the source data. Due to the scenarios, call volumes, service contents, response time requirements, etc. of different business requests, the source data obtained is different, and the application servers responding to different business requests are also different in quantity, scale, and resource configuration. The middle-tier cache can cache the source data in the source database so that the application server can directly obtain the required source data from the middle-tier cache without accessing the source database. In this architecture, by introducing the middle-tier cache, the source data stored in the source database can be transferred to the middle-tier cache for query. The source database is usually a relational database with limited performance and cannot support the deployment and startup of large-scale application servers. Therefore, setting up the middle-tier cache solves the problem that when multiple application servers are started at the same time, the pressure is too high, which may cause the source database to be overwhelmed, or starting the application server in batches may slow down the business support speed, and cannot take into account the current situation of startup speed and business stability.
[0047] For example, taking the decision-making business in the field of risk control as an example, business A in the game neighborhood includes risk control strategies in login, redemption, and chat scenarios. The application server started in response to the request of business A can load the source data of risk control strategies in login, redemption, and chat scenarios from the middle-tier cache to the local cache to support business A;
[0048] Alternatively, if business B in the e-commerce field includes risk control strategies for scenarios such as registration, login, coupon collection, ordering, payment, delivery, receipt, and refund, the application server started in response to the request of business B can load the source data of risk control strategies for scenarios such as registration, login, coupon collection, ordering, payment, delivery, receipt, and refund from the middle-tier cache to the local cache to support business B.
[0049] Furthermore, business A is routed to cluster 1 containing 4 application servers, and business B is routed to cluster 2 containing 100 application servers. Multiple application servers in each cluster can obtain the source data required by the business from the middle-tier cache.
[0050] On this basis, the embodiment of the present disclosure provides a cache update method to maintain the consistency of the source database, the middle-tier cache, and the application server. By configuring the message middleware, when an update operation occurs on the stored source data, the source database can publish a corresponding update event message to the message middleware for the update operation, so that the update event message can indicate an update operation on at least one source data in the source database. The message middleware can carry the update event message published by the database for the application server to pull.
[0051] Furthermore, the update operation can be directly updated from the page to the corresponding source data in the source database, and the update operation can include operations such as adding, deleting, and modifying. The source data to which the update operation occurs may correspond to multiple application servers. The source database can publish multiple update event messages to the message middleware for the update operation of the source data point-to-point, and each application server corresponding to the business consumes the corresponding update event message one-to-one; or, the source database can also adopt a publish-subscribe mode for the update operation of the source data, publish the update event message to the topic corresponding to the business of the message middleware, and multiple application servers corresponding to the business subscribe to the topic to consume the update event message published to the topic in a many-to-one manner. The application server processes the update event message, which can be immediate processing, directly obtaining the processing when the update event message is published to the message middleware; or it can be asynchronous processing, which does not process the update event message immediately when it is published to the message middleware, but obtains the processing when the agreed time arrives. The embodiments of the present disclosure do not impose specific restrictions on this.
[0052] In the disclosed embodiment, when the application server processes an update event message, since the application server corresponding to the business has the source data in the local cache to support the business, a consistent update operation in the source database can be performed on the corresponding source data in the local cache based on the update event message, and a consistent update operation in the source database can be performed on the corresponding source data in the middle-tier cache, thereby achieving a three-party consistent update of the source database, the middle-tier cache and the application server driven by an event message.
[0053] In the disclosed embodiment, when multiple application servers are started, in order to avoid the business stability risks that may be caused by accessing the source database at the same time and the problem of slow startup caused by multiple batch startups, the source data in the source database can be pre-cached with the middle-tier cache for direct access by the application server. During the process of multiple application server startups, it may happen that the middle-tier cache has not cached the required source data, so it is necessary to create a middle-tier cache corresponding to the required source data. In actual applications, the middle-tier cache can obtain the required source data from the source database based on the query information of the application server and then provide it to the application server; it can also be as follows:
[0054] In an optional method embodiment of the present disclosure, when multiple application servers are started, one of the creation processes of the intermediate layer cache can be as follows: Figure 2 As shown, any one of the multiple application servers is a first application server, and the others are second application servers, as shown in the following steps 201 to 204:
[0055] Step 201: The first application server starts to start and requests source data from the middle-tier cache.
[0056] Step 202: When the first application server fails to request the source data from the middle-tier cache, the first application server obtains the source data from the source database.
[0057] Step 203: The first application server writes the source data into the local cache to complete the startup, and writes the source data into the middle-tier cache.
[0058] Step 204: The second application server obtains source data from the middle-tier cache, and writes the source data into the local cache to complete the startup.
[0059] In the disclosed embodiment, one application server may first query and obtain the required source data from the middle-tier cache. If the required source data exists in the middle-tier cache, other application servers may directly obtain the required source data. If the required source data does not exist in the middle-tier cache, other application servers wait for the one application server to obtain the required source data from the source database and write it into the middle-tier cache before obtaining the required source data from the middle-tier cache. For example, any first application server may be determined among multiple application servers that respond to the same business request, and the others are second application servers, where the first application server is started first and the second application server is started later. The second application server may be started later after the first application server is started, or it may be started after waiting for a period of time after the first application server starts. The waiting time may be set according to actual needs.
[0060] When the first application server starts to start, it can request source data from the middle-tier cache. If the required source data exists in the middle-tier cache, it can be directly provided to the first application server, so that the first application server successfully obtains the required source data; or, when the required source data does not exist in the middle-tier cache, the first application server fails to request source data from the middle-tier cache, and obtains the required source data from the source database. A single application server accesses it at a time, which reduces the operating burden of the source database. Then, the first application server writes the obtained source data into the local cache to complete the startup, supports the business based on the source data, and writes the required source data into the middle-tier cache. When multiple second application servers are started later, they can directly obtain the required source data from the middle-tier cache and write each into the local cache to complete the startup.
[0061] In an optional method embodiment of the present disclosure, when multiple application servers are started, the second process of creating the middle-tier cache can be as follows: Figure 3 As shown in the following steps 301 to 305:
[0062] Step 301: Multiple application servers start to start and request source data from the middle-tier cache.
[0063] Step 302: When multiple application servers fail to request source data from the middle-tier cache, they compete for the distributed lock.
[0064] Step 303: The third application server that successfully competes for the distributed lock obtains source data from the source database.
[0065] Step 304: The third application server writes the source data into the local cache to complete the startup, writes the source data into the middle-tier cache, and releases the distributed lock.
[0066] Step 305: the fourth application server that fails to compete for the distributed lock waits for a first time period before obtaining source data from the middle-layer cache and writing the source data into the local cache to complete startup; the first preset time period is greater than the startup time of the application server.
[0067] In the embodiment of the present disclosure, when the required source data may or may not exist in the middle-layer cache, multiple application servers can start to start in the same batch to request source data from the middle-layer cache. At this time, when the required source data exists in the middle-layer cache, each application server can directly obtain the corresponding source data and write it to their respective local caches to complete the startup; when the required source data does not exist in the middle-layer cache, multiple application servers fail to request source data from the middle-layer cache and can compete for distributed locks. Distributed locks are a mechanism for coordinating multiple nodes in a distributed system so that only one node accesses shared resources at the same time. Multiple application servers compete for distributed locks, among which the third application server successfully competes for the distributed lock, and the fourth application server fails to compete for the distributed lock. On this basis, the third application server obtains the source data from the source database, writes the source data to the local cache to complete the startup, writes the source data to the middle-layer cache, and releases the distributed lock. The fourth application server waits for the first time period before obtaining the source data from the middle-layer cache and writes the source data to the local cache to complete the startup. The length of the first preset time period can be set according to actual configuration conditions, response requirements, etc., and can be greater than the statistical startup time of the application server, so that the fourth application server accesses the middle-tier cache after the third application server is started.
[0068] In an optional embodiment of the present disclosure, it is also possible to Figure 2 , 3 Combine the steps of creating a middle-tier cache in the application server startup shown in the figure, as mentioned above Figure 2 In the process of step 1, due to possible failure or other reasons, the first application server may fail to write the source data into the middle-tier cache, causing the second application server to fail to obtain the source data from the middle-tier cache again. At this time, multiple application servers can execute Figure 3The steps shown in the flow chart enable an application server to obtain and write source data again through distributed lock competition, and the embodiments of the present disclosure do not impose any specific restrictions on this.
[0069] Based on the aforementioned Figure 2 , 3 Any step process creates a middle-tier cache based on Figure 4 This is a second flow chart of a cache update method provided by an embodiment of the present disclosure. The method can be applied to multiple application servers. The flow chart of the method can be shown in steps 401 to 404 as follows:
[0070] Step 401: After each application server is started up, it executes a message timing processing task, and when each cycle of the message timing processing task expires, it pulls at least one update event message published by the source database to the message middleware within a second preset time period.
[0071] In the disclosed embodiment, the application server may have a built-in timed processing task, and a cycle of a certain duration is defined by the task, which is triggered when the cycle timer expires, and the timer is reset and restarted after the trigger. When the cycle is triggered, the application server is driven to pull at least one update event message published by the source database to the message middleware within the second preset time period. Through the timed processing task, the application server can be driven to actively pull the update event message regularly to timely determine the consistency of the source data required to support the business.
[0072] In an optional embodiment of the present disclosure, the duration of the loop can be set according to the historical update records of the source data in the source database, and can also be set in consideration of resource configuration and network conditions; it can be a fixed duration, or a dynamic duration adjusted according to actual conditions, such as a loop can be 1 second, 5 seconds, 10 seconds, etc., and the embodiment of the present disclosure does not impose specific restrictions on this.
[0073] In an optional method embodiment of the present disclosure, the second preset time period is greater than the duration of each cycle of the message timing processing task.
[0074] In the disclosed embodiment, the duration of the second time period may be greater than or equal to the duration of the cycle, so that the application server may be able to pull update event messages published between adjacent cycle triggers, or further pull update event messages that may have been published before the previous cycle trigger, to avoid omission of update event messages.
[0075] For example, when the cycle duration is 5 seconds, the second preset time period may be 1 minute, 2 minutes, etc., and the embodiment of the present disclosure does not impose any specific limitation.
[0076] Step 402: Multiple application servers perform update operations on corresponding source data in local cache based on the update event message, and compete for distributed locks.
[0077] In the embodiment of the present disclosure, multiple application servers can determine that there is an update operation of the source data corresponding to the business based on the update event message, so that the update operation can be performed on the corresponding source data in the local cache based on the update event message. Multiple application servers can also compete for distributed locks to determine an application server that performs the corresponding update operation of the source data to the middle-tier cache.
[0078] Step 403: The fifth application server that successfully competes for the distributed lock performs an update operation on the corresponding source data in the middle-layer cache and releases the distributed lock to determine that the processing of the update event message is completed.
[0079] Among them, the fifth application server successfully competes for the distributed lock among multiple application servers. Therefore, in addition to performing an update operation on the source data in the local cache, an update operation must also be performed on the corresponding source data in the middle-layer cache. After the three-party consistency update, the distributed lock is released, thereby confirming that the local machine has completed processing the update event message.
[0080] In an optional method embodiment of the present disclosure, the middle-tier cache is built based on a Redis database.
[0081] In the disclosed embodiment, the middle-layer cache can be built based on the Redis database. The Redis database is a high-performance non-relational key-value pair database with high read and write performance. It can support access by multiple application servers. When multiple application servers corresponding to the business are started or restarted, the required source data can be directly queried and loaded from the Redis database.
[0082] Furthermore, the source database may be a relational database MySQL, in which data that needs to be queried multiple times may be merged into one entry in the Redis database in the form of key values, so as to further improve the query loading efficiency of the source data.
[0083] For example, 300 pieces of source data related to the policy of business A can be merged into one and written into the middle-tier cache; 800 pieces of source data related to the policy of business B can be merged into one and written into the middle-tier cache.
[0084] Step 404: The sixth application server that fails in competing for the distributed lock determines that the processing of the update event message is completed.
[0085] In the present embodiment, the sixth application server is the one that fails in the competition for the distributed lock among the multiple application servers. Therefore, based on the execution of the update operation on the source data in the local cache, it can be determined that the local machine has completed processing the update event message.
[0086] For example, every 5 seconds, the application server cyclically triggers to pull the update event message published by the source database to the message middleware within 2 minutes. Multiple application servers that pull the update event message can perform update operations on the corresponding source data in the local cache and compete for the distributed lock. Among them, the fifth application server successfully competes for the distributed lock, and the sixth application server fails to compete for the distributed lock. The fifth application server performs an update operation on the corresponding source data in the middle-tier cache and releases the distributed lock, thereby determining that the processing of the update event message is completed, and the sixth application server directly determines that the processing of the update event message is completed.
[0087] In a specific example, the architecture of the cache update method includes multiple application servers, a middle-tier cache, a source database, and a message middleware. In the initial state, the Redis database is an empty collection. For MySQL database, Mysql_policy={1,2,3,4,5}, Mysql_rule={a,b,c}.
[0088] During the startup process, if the middle-tier cache is determined to be an empty set, a preset application server or an application server that successfully competes for a distributed lock obtains source data Mysql_policy = {1,2,3,4,5}, Mysql_rule = {a,b,c} from the MySQL database, writes it to the local cache, and writes it to the Redis database to obtain Redis_policy = {1,2,3,4,5}, Redis_rule = {a,b,c}, thereby completing the startup. Other application servers obtain source data from the Redis database and write it to the local cache, thereby completing the startup.
[0089] The MySQL database receives the update operation of Mysql_policy={1,2,3,4,5}, Mysql_rule={a,b,c} from the page, adds U_policy={6,7,8}, U_rule={d,e,f}, and obtains Mysql_policy={1,2,3,4,5,6,7,8}, Mysql_rule={a,b,c,d,e,f}. On this basis, the MySQL database publishes the update event message corresponding to the added update operation to the message middleware.
[0090] After multiple application servers are started, the built-in timer processing task starts the first cycle timing, and is triggered when the timing reaches 5 seconds, driving the application server to pull the update event message published by the MySQL database within 2 minutes from the message middleware, and perform the addition and update operation on the corresponding source data in the local cache according to the update event message, and compete for the distributed lock. Among them, the application server that successfully competes for the distributed lock also performs the addition and update operation on the corresponding source data in the Redis database, and obtains Redis_policy = {1,2,3,4,5,6,7,8}, Redis_rule = {a,b,c,d,e,f}, so as to keep the consistency of multiple application servers, Redis database, and MySQL database.
[0091] When multiple application servers corresponding to the business are restarted, expanded, or started next time, the required source data can be queried from the Redis database. In addition, online update operations on the source database can be performed by multiple application servers based on cyclic timing processing tasks to update the local and Redis databases, thereby maintaining data consistency and improving business quality.
[0092] The cache update method provided by the present disclosure is applied to multiple application servers, each application server can pull the update event message published by the source data to the message middleware, and the update event message can indicate the update operation of at least one source data in the source data; based on the obtained update event message, the application server can perform an update operation on the corresponding source data in the local cache, and also perform an update operation on the source data corresponding to the middle-layer cache, so as to maintain consistency between the source database, the middle-layer cache and multiple application servers; wherein the middle-layer cache can cache the source data of the source database, and can provide the source data to multiple application servers before the source database, so as to share and reduce the business pressure of the source database. The method is based on event message drive, and can timely update the data of the source database, the middle-layer cache and the application server, avoid inconsistent customer information, untimely updates causing business support errors or failures, maintain service stability, and improve service quality.
[0093] Furthermore, in the embodiments of the present disclosure, through the combined architecture of event messages, scheduled tasks and distributed locks, updates can be automatically driven to be carried out in a timely manner, thereby achieving accurate and efficient consistency updates of the source database, middle-tier cache and application server.
[0094] Figure 5 A structural block diagram of a cache update system is also provided, such as Figure 5As shown, the system may include multiple application servers, source databases, middle-tier caches and message middleware, and each application server 500 includes: a message pulling module 501, which is used to pull the update event message published by the source database to the message middleware, and the update event message indicates an update operation on at least one source data in the source database; a message processing module 502, which is used to perform an update operation on the corresponding source data in the local cache based on the update event message, and to perform an update operation on the corresponding source data in the middle-tier cache; the middle-tier cache is used to cache the source data of the source database, and provide the source data to the application server before the source database.
[0095] In an optional system embodiment of the present disclosure, the application server further includes a data request module and a data writing module, any one of the multiple application servers is a first application server, and the others are second application servers;
[0096] The data request module of the first application server is used to request source data from the middle-tier cache when the first application server starts to start; the data request module of the first application server is also used to obtain source data from the source database when the source data request from the middle-tier cache fails; the data writing module of the first application server is used to write the source data into the local cache to complete the startup, and write the source data into the middle-tier cache;
[0097] The data request module of the second application server is used to obtain source data from the middle-tier cache, and the data writing module is used to write the source data into the local cache to complete the startup.
[0098] In an optional system embodiment of the present disclosure, the application server further includes a data request module and a data writing module, wherein the data request modules of the multiple application servers are used to request source data from the middle-layer cache when the application server starts; the data request modules of the multiple application servers are used to compete for distributed locks when the source data request from the middle-layer cache fails;
[0099] The data request module of the third application server is also used to obtain source data from the source data when the competition for the distributed lock is successful; the data writing module of the third application server is used to write the source data into the local cache to complete the startup, write the source data into the middle-layer cache, and release the distributed lock;
[0100] The data request module of the fourth application server is also used to obtain source data from the middle layer cache after waiting for a first time period in the event of a failure in competing for a distributed lock, and the data writing module is used to write the source data to the local cache to complete the startup; the first preset time period is greater than the startup time of the application server.
[0101] In an optional system embodiment of the present disclosure, a message pulling module 501 of multiple application servers is specifically used to execute a message timing processing task after each application server completes startup, and when each cycle of the message timing task processing task expires, pulls at least one update event message published by the source database to the message middleware within a second preset time period.
[0102] In an optional system embodiment of the present disclosure, the message processing module 502 of the multiple application servers is also used for the multiple application servers to compete for the distributed lock;
[0103] The message processing module 502 of the fifth application server is used to perform an update operation on the corresponding source data in the middle-layer cache and release the distributed lock when the competition for the distributed lock succeeds, so as to determine that the processing of the update event message is completed;
[0104] The message processing module 502 of the sixth application server is used to determine that the processing of the update event message is completed when the competition for the distributed lock fails.
[0105] In an optional system embodiment of the present disclosure, the second preset time period is greater than the duration of each cycle of the message timing processing task.
[0106] In an optional system embodiment of the present disclosure, the middle-layer cache is built based on a Redis database.
[0107] The cache update system provided by the present disclosure includes multiple application servers, source databases, middle-layer caches, and message middleware. Each application server can pull the update event message published by the source data to the message middleware, and the update event message can indicate the update operation of at least one source data in the source data; based on the obtained update event message, the application server can perform an update operation on the corresponding source data in the local cache, and also perform an update operation on the source data corresponding to the middle-layer cache, so as to maintain consistency between the source database, the middle-layer cache, and multiple application servers; wherein the middle-layer cache can cache the source data of the source database, and can provide the source data to multiple application servers before the source database, so as to share and reduce the business pressure of the source database. The method is driven by event messages, and can timely update the data of the source database, the middle-layer cache, and the application server, avoid inconsistent customer information, untimely updates, and business support errors or failures, maintain service stability, and improve service quality.
[0108] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0109] In addition, although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0110] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0111] In an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.
[0112] Those skilled in the art will appreciate that various aspects of the present disclosure may be implemented as systems, methods or program products. Therefore, various aspects of the present disclosure may be specifically implemented in the following forms, namely: complete hardware implementation, complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as "circuits", "modules" or "systems".
[0113] Refer to the following Figure 6 The electronic device 600 according to this embodiment of the present disclosure is described. Figure 6 The electronic device 600 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0114] like Figure 6As shown, the electronic device 600 is in the form of a general computing device. The components of the electronic device 600 may include but are not limited to: at least one processing unit 610, at least one storage unit 620, and a bus 630 connecting different system components (including the storage unit 620 and the processing unit 610).
[0115] The storage unit stores program codes, which can be executed by the processing unit 610, so that the processing unit 610 executes the steps described in the above “Exemplary Method” section of this specification according to various exemplary embodiments of the present disclosure.
[0116] The storage unit 620 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 6201 and / or a cache memory unit 6202 , and may further include a read-only memory unit (ROM) 6203 .
[0117] The storage unit 620 may also include a program / utility 6204 having a set (at least one) of program modules 6205, such program modules 6205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0118] Bus 630 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0119] The electronic device 600 may also communicate with one or more external devices (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 600, and / or communicate with any device that enables the electronic device 600 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed through a display unit 640 and an input / output (I / O) interface 650 connected to the display unit 640. In addition, the electronic device 600 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 660. As shown, the network adapter 660 communicates with other modules of the electronic device 600 through a bus 630. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0120] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0121] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible implementations, various aspects of the present disclosure may also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary implementations of the present disclosure described in the above "Exemplary Method" section of the present specification.
[0122] In the embodiments of the present disclosure, a program product for implementing the above method is also provided, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto, and in this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.
[0123] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0124] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0125] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0126] Program code for performing the operations of the present disclosure may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0127] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0128] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.
Claims
1. A cache update method, characterized in that: The method is applied to multiple application servers, and the method includes: Pull the update event message published by the source database to the message middleware, where the update event message indicates an update operation on at least one source data in the source database; Based on the update event message, an update operation is performed on the corresponding source data in the local cache, and an update operation is performed on the corresponding source data in the middle-tier cache; the middle-tier cache is used to cache the source data of the source database, and provide the source data to multiple application servers before the source database.
2. The method according to claim 1, characterized in that Any one of the multiple application servers is a first application server, and the others are second application servers. The steps for creating the middle-layer cache are as follows: The first application server starts up and requests source data from the middle-tier cache; When the first application server fails to request the source data from the middle-tier cache, the first application server obtains the source data from the source database; The first application server writes the source data into the local cache to complete the startup, and writes the source data into the middle-tier cache; The second application server obtains the source data from the middle-tier cache and writes the source data into the local cache to complete the startup.
3. The method according to claim 1, characterized in that The steps for creating the middle-layer cache are as follows: Multiple application servers start up, requesting source data from the middle-tier cache; When multiple application servers fail to request source data from the middle-tier cache, they compete for distributed locks; The third application server that successfully competes for the distributed lock obtains the source data from the source database; The third application server writes the source data into the local cache to complete the startup, writes the source data into the middle-tier cache, and releases the distributed lock; The fourth application server that fails to compete for the distributed lock waits for the first time period, obtains the source data from the middle-tier cache, and writes the source data into the local cache to complete the startup; The first preset time period is greater than the startup time of the application server.
4. The method according to any one of claims 2 and 3, characterized in that Pull the update event message published by the origin database to the message middleware, including: After each application server is started up, it executes the message timing processing task, and when each cycle of the message timing processing task expires, it pulls at least one update event message published by the source database to the message middleware within the second preset time period.
5. The method according to claim 4, characterized in that The updating operation on the corresponding source data in the intermediate layer cache includes: Multiple application servers compete for distributed locks; The fifth application server that successfully competes for the distributed lock performs an update operation on the corresponding source data in the middle-tier cache and releases the distributed lock to determine that the processing of the update event message is completed; The sixth application server that fails to compete for the distributed lock determines that the processing of the update event message is completed.
6. The method according to claim 1, characterized in that The second preset time period is greater than the duration of each cycle of the message timing processing task.
7. The method according to claim 1, characterized in that The middle-layer cache is built based on the Redis database.
8. A cache update system, characterized in that: The system includes multiple application servers, source databases, middle-tier caches, and message middleware. Each application server includes: A message pulling module is used to pull the update event message published by the source database to the message middleware, where the update event message indicates an update operation on at least one source data in the source database; The message processing module is used to perform update operations on the corresponding source data in the local cache based on the update event message, and to perform update operations on the corresponding source data in the middle-tier cache; the middle-tier cache is used to cache the source data of the source database and provide the source data to the application server before the source database.
9. An electronic device, characterized in that: include: Processor; and a memory for storing a computer program for the processor; The processor is configured to execute the cache updating method of any one of claims 1 to 7 by executing a computer program.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the cache updating method according to any one of claims 1 to 7 is implemented.
